Skip to content

Commit 6a1e555

Browse files
authored
Upgrade to Rust 1.78 (#11260)
1 parent 349a4cf commit 6a1e555

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+67
-549
lines changed

clippy.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@ doc-valid-idents = [
33
"CodeQL",
44
"IPython",
55
"NumPy",
6+
"LibCST",
7+
"SCREAMING_SNAKE_CASE",
8+
"SQLAlchemy",
9+
"McCabe",
10+
"FastAPI",
611
"..",
712
]

crates/ruff/src/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ pub struct CheckCommand {
338338
/// The name of the file when passing it through stdin.
339339
#[arg(long, help_heading = "Miscellaneous")]
340340
pub stdin_filename: Option<PathBuf>,
341-
/// List of mappings from file extension to language (one of ["python", "ipynb", "pyi"]). For
341+
/// List of mappings from file extension to language (one of `python`, `ipynb`, `pyi`). For
342342
/// example, to treat `.ipy` files as IPython notebooks, use `--extension ipy:ipynb`.
343343
#[arg(long, value_delimiter = ',')]
344344
pub extension: Option<Vec<ExtensionPair>>,
@@ -466,7 +466,7 @@ pub struct FormatCommand {
466466
/// The name of the file when passing it through stdin.
467467
#[arg(long, help_heading = "Miscellaneous")]
468468
pub stdin_filename: Option<PathBuf>,
469-
/// List of mappings from file extension to language (one of ["python", "ipynb", "pyi"]). For
469+
/// List of mappings from file extension to language (one of `python`, `ipynb`, `pyi`). For
470470
/// example, to treat `.ipy` files as IPython notebooks, use `--extension ipy:ipynb`.
471471
#[arg(long, value_delimiter = ',')]
472472
pub extension: Option<Vec<ExtensionPair>>,

crates/ruff_formatter/src/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub struct RemoveSoftLinesBuffer<'a, Context> {
344344

345345
/// Caches the interned elements after the soft line breaks have been removed.
346346
///
347-
/// The `key` is the [Interned] element as it has been passed to [Self::write_element] or the child of another
347+
/// The `key` is the [Interned] element as it has been passed to [`Self::write_element`] or the child of another
348348
/// [Interned] element. The `value` is the matching document of the key where all soft line breaks have been removed.
349349
///
350350
/// It's fine to not snapshot the cache. The worst that can happen is that it holds on interned elements

crates/ruff_formatter/src/diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ pub enum FormatError {
1818
InvalidDocument(InvalidDocumentError),
1919

2020
/// Formatting failed because some content encountered a situation where a layout
21-
/// choice by an enclosing [crate::Format] resulted in a poor layout for a child [crate::Format].
21+
/// choice by an enclosing [`crate::Format`] resulted in a poor layout for a child [`crate::Format`].
2222
///
23-
/// It's up to an enclosing [crate::Format] to handle the error and pick another layout.
24-
/// This error should not be raised if there's no outer [crate::Format] handling the poor layout error,
23+
/// It's up to an enclosing [`crate::Format`] to handle the error and pick another layout.
24+
/// This error should not be raised if there's no outer [`crate::Format`] handling the poor layout error,
2525
/// avoiding that formatting of the whole document fails.
2626
PoorLayout,
2727
}

crates/ruff_formatter/src/format_element.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use ruff_text_size::TextSize;
1919
/// Use the helper functions like [`crate::builders::space`], [`crate::builders::soft_line_break`] etc. defined in this file to create elements.
2020
#[derive(Clone, Eq, PartialEq)]
2121
pub enum FormatElement {
22-
/// A space token, see [crate::builders::space] for documentation.
22+
/// A space token, see [`crate::builders::space`] for documentation.
2323
Space,
2424

25-
/// A new line, see [crate::builders::soft_line_break], [crate::builders::hard_line_break], and [crate::builders::soft_line_break_or_space] for documentation.
25+
/// A new line, see [`crate::builders::soft_line_break`], [`crate::builders::hard_line_break`], and [`crate::builders::soft_line_break_or_space`] for documentation.
2626
Line(LineMode),
2727

2828
/// Forces the parent group to print in expanded mode.
@@ -108,13 +108,13 @@ impl std::fmt::Debug for FormatElement {
108108

109109
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
110110
pub enum LineMode {
111-
/// See [crate::builders::soft_line_break_or_space] for documentation.
111+
/// See [`crate::builders::soft_line_break_or_space`] for documentation.
112112
SoftOrSpace,
113-
/// See [crate::builders::soft_line_break] for documentation.
113+
/// See [`crate::builders::soft_line_break`] for documentation.
114114
Soft,
115-
/// See [crate::builders::hard_line_break] for documentation.
115+
/// See [`crate::builders::hard_line_break`] for documentation.
116116
Hard,
117-
/// See [crate::builders::empty_line] for documentation.
117+
/// See [`crate::builders::empty_line`] for documentation.
118118
Empty,
119119
}
120120

crates/ruff_formatter/src/format_element/tag.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use std::num::NonZeroU8;
99
/// will be applied to all elements in between the start/end tags.
1010
#[derive(Clone, Debug, Eq, PartialEq)]
1111
pub enum Tag {
12-
/// Indents the content one level deeper, see [crate::builders::indent] for documentation and examples.
12+
/// Indents the content one level deeper, see [`crate::builders::indent`] for documentation and examples.
1313
StartIndent,
1414
EndIndent,
1515

16-
/// Variant of [TagKind::Indent] that indents content by a number of spaces. For example, `Align(2)`
16+
/// Variant of [`TagKind::Indent`] that indents content by a number of spaces. For example, `Align(2)`
1717
/// indents any content following a line break by an additional two spaces.
1818
///
19-
/// Nesting (Aligns)[TagKind::Align] has the effect that all except the most inner align are handled as (Indent)[TagKind::Indent].
19+
/// Nesting (Aligns)[`TagKind::Align`] has the effect that all except the most inner align are handled as (Indent)[`TagKind::Indent`].
2020
StartAlign(Align),
2121
EndAlign,
2222

@@ -29,7 +29,7 @@ pub enum Tag {
2929
/// - on a single line: Omitting `LineMode::Soft` line breaks and printing spaces for `LineMode::SoftOrSpace`
3030
/// - on multiple lines: Printing all line breaks
3131
///
32-
/// See [crate::builders::group] for documentation and examples.
32+
/// See [`crate::builders::group`] for documentation and examples.
3333
StartGroup(Group),
3434
EndGroup,
3535

@@ -44,22 +44,22 @@ pub enum Tag {
4444
EndConditionalGroup,
4545

4646
/// Allows to specify content that gets printed depending on whatever the enclosing group
47-
/// is printed on a single line or multiple lines. See [crate::builders::if_group_breaks] for examples.
47+
/// is printed on a single line or multiple lines. See [`crate::builders::if_group_breaks`] for examples.
4848
StartConditionalContent(Condition),
4949
EndConditionalContent,
5050

51-
/// Optimized version of [Tag::StartConditionalContent] for the case where some content
51+
/// Optimized version of [`Tag::StartConditionalContent`] for the case where some content
5252
/// should be indented if the specified group breaks.
5353
StartIndentIfGroupBreaks(GroupId),
5454
EndIndentIfGroupBreaks,
5555

5656
/// Concatenates multiple elements together with a given separator printed in either
5757
/// flat or expanded mode to fill the print width. Expect that the content is a list of alternating
58-
/// [element, separator] See [crate::Formatter::fill].
58+
/// [element, separator] See [`crate::Formatter::fill`].
5959
StartFill,
6060
EndFill,
6161

62-
/// Entry inside of a [Tag::StartFill]
62+
/// Entry inside of a [`Tag::StartFill`]
6363
StartEntry,
6464
EndEntry,
6565

@@ -77,7 +77,7 @@ pub enum Tag {
7777
/// Special semantic element marking the content with a label.
7878
/// This does not directly influence how the content will be printed.
7979
///
80-
/// See [crate::builders::labelled] for documentation.
80+
/// See [`crate::builders::labelled`] for documentation.
8181
StartLabelled(LabelId),
8282
EndLabelled,
8383

crates/ruff_formatter/src/printer/queue.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -189,27 +189,6 @@ impl<'a, 'print> Queue<'a> for FitsQueue<'a, 'print> {
189189
}
190190
}
191191

192-
/// Iterator that calls [`Queue::pop`] until it reaches the end of the document.
193-
///
194-
/// The iterator traverses into the content of any [`FormatElement::Interned`].
195-
pub(super) struct QueueIterator<'a, 'q, Q: Queue<'a>> {
196-
queue: &'q mut Q,
197-
lifetime: PhantomData<&'a ()>,
198-
}
199-
200-
impl<'a, Q> Iterator for QueueIterator<'a, '_, Q>
201-
where
202-
Q: Queue<'a>,
203-
{
204-
type Item = &'a FormatElement;
205-
206-
fn next(&mut self) -> Option<Self::Item> {
207-
self.queue.pop()
208-
}
209-
}
210-
211-
impl<'a, Q> FusedIterator for QueueIterator<'a, '_, Q> where Q: Queue<'a> {}
212-
213192
pub(super) struct QueueContentIterator<'a, 'q, Q: Queue<'a>> {
214193
queue: &'q mut Q,
215194
kind: TagKind,

crates/ruff_formatter/src/printer/stack.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ pub(super) trait Stack<T> {
88

99
/// Returns the last element if any
1010
fn top(&self) -> Option<&T>;
11-
12-
/// Returns `true` if the stack is empty
13-
fn is_empty(&self) -> bool;
1411
}
1512

1613
impl<T> Stack<T> for Vec<T> {
@@ -25,10 +22,6 @@ impl<T> Stack<T> for Vec<T> {
2522
fn top(&self) -> Option<&T> {
2623
self.last()
2724
}
28-
29-
fn is_empty(&self) -> bool {
30-
self.is_empty()
31-
}
3225
}
3326

3427
/// A Stack that is stacked on top of another stack. Guarantees that the underlying stack remains unchanged.
@@ -80,10 +73,6 @@ where
8073
.last()
8174
.or_else(|| self.original.as_slice().last())
8275
}
83-
84-
fn is_empty(&self) -> bool {
85-
self.stack.is_empty() && self.original.len() == 0
86-
}
8776
}
8877

8978
#[cfg(test)]

crates/ruff_linter/src/directives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ pub(crate) struct TodoComment<'a> {
273273
pub(crate) directive: TodoDirective<'a>,
274274
/// The comment's actual [`TextRange`].
275275
pub(crate) range: TextRange,
276-
/// The comment range's position in [`Indexer`].comment_ranges()
276+
/// The comment range's position in [`Indexer::comment_ranges`]
277277
pub(crate) range_index: usize,
278278
}
279279

crates/ruff_linter/src/line_width.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl CacheKey for LineLength {
5656
pub enum ParseLineWidthError {
5757
/// The string could not be parsed as a valid [u16]
5858
ParseError(ParseIntError),
59-
/// The [u16] value of the string is not a valid [LineLength]
59+
/// The [u16] value of the string is not a valid [`LineLength`]
6060
TryFromIntError(LineLengthFromIntError),
6161
}
6262

crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ pub(crate) fn fix_unnecessary_double_cast_or_process(
531531
.find(|argument| argument.keyword.is_none())
532532
{
533533
let mut arg = arg.clone();
534-
arg.comma = first.comma.clone();
534+
arg.comma.clone_from(&first.comma);
535535
arg.whitespace_after_arg = first.whitespace_after_arg.clone();
536536
iter::once(arg)
537537
.chain(rest.iter().cloned())

crates/ruff_linter/src/rules/flake8_simplify/rules/fix_with.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ pub(crate) fn fix_multiple_with_statements(
6767

6868
outer_with.items.append(&mut inner_with.items);
6969
if outer_with.lpar.is_none() {
70-
outer_with.lpar = inner_with.lpar.clone();
71-
outer_with.rpar = inner_with.rpar.clone();
70+
outer_with.lpar.clone_from(&inner_with.lpar);
71+
outer_with.rpar.clone_from(&inner_with.rpar);
7272
}
7373
outer_with.body = inner_with.body.clone();
7474

crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/redundant_backslash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub(crate) fn redundant_backslash(
6060
let start = locator.line_start(token.start());
6161
start_index = continuation_lines
6262
.binary_search(&start)
63-
.map_or_else(|err_index| err_index, |ok_index| ok_index);
63+
.unwrap_or_else(|err_index| err_index);
6464
}
6565
parens += 1;
6666
}
@@ -70,7 +70,7 @@ pub(crate) fn redundant_backslash(
7070
let end = locator.line_start(token.start());
7171
let end_index = continuation_lines
7272
.binary_search(&end)
73-
.map_or_else(|err_index| err_index, |ok_index| ok_index);
73+
.unwrap_or_else(|err_index| err_index);
7474
for continuation_line in &continuation_lines[start_index..end_index] {
7575
let backslash_end = locator.line_end(*continuation_line);
7676
let backslash_start = backslash_end - TextSize::new(1);

crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl SortingStyle {
4848
/// an "isort-style sort".
4949
///
5050
/// An isort-style sort sorts items first according to their casing:
51-
/// `SCREAMING_SNAKE_CASE` names (conventionally used for global constants)
51+
/// SCREAMING_SNAKE_CASE names (conventionally used for global constants)
5252
/// come first, followed by CamelCase names (conventionally used for
5353
/// classes), followed by anything else. Within each category,
5454
/// a [natural sort](https://en.wikipedia.org/wiki/Natural_sort_order)

crates/ruff_python_ast/src/nodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ impl ConversionFlag {
10061006
pub struct DebugText {
10071007
/// The text between the `{` and the expression node.
10081008
pub leading: String,
1009-
/// The text between the expression and the conversion, the format_spec, or the `}`, depending on what's present in the source
1009+
/// The text between the expression and the conversion, the `format_spec`, or the `}`, depending on what's present in the source
10101010
pub trailing: String,
10111011
}
10121012

crates/ruff_python_formatter/src/comments/map.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<K: std::hash::Hash + Eq, V> MultiMap<K, V> {
246246
/// Returns `true` if `key` has any *leading*, *dangling*, or *trailing* parts.
247247
#[allow(unused)]
248248
pub(super) fn has(&self, key: &K) -> bool {
249-
self.index.get(key).is_some()
249+
self.index.contains_key(key)
250250
}
251251

252252
/// Returns the *leading*, *dangling*, and *trailing* parts of `key`.
@@ -382,16 +382,16 @@ where
382382

383383
#[derive(Clone, Debug)]
384384
struct InOrderEntry {
385-
/// Index into the [MultiMap::parts] vector where the leading parts of this entry start
385+
/// Index into the [`MultiMap::parts`] vector where the leading parts of this entry start
386386
leading_start: PartIndex,
387387

388-
/// Index into the [MultiMap::parts] vector where the dangling parts (and, thus, the leading parts end) start.
388+
/// Index into the [`MultiMap::parts`] vector where the dangling parts (and, thus, the leading parts end) start.
389389
dangling_start: PartIndex,
390390

391-
/// Index into the [MultiMap::parts] vector where the trailing parts (and, thus, the dangling parts end) of this entry start
391+
/// Index into the [`MultiMap::parts`] vector where the trailing parts (and, thus, the dangling parts end) of this entry start
392392
trailing_start: Option<PartIndex>,
393393

394-
/// Index into the [MultiMap::parts] vector where the trailing parts of this entry end
394+
/// Index into the [`MultiMap::parts`] vector where the trailing parts of this entry end
395395
trailing_end: Option<PartIndex>,
396396

397397
_count: Count<InOrderEntry>,
@@ -505,7 +505,7 @@ impl InOrderEntry {
505505

506506
#[derive(Clone, Debug)]
507507
struct OutOfOrderEntry {
508-
/// Index into the [MultiMap::out_of_order] vector at which offset the leaading vec is stored.
508+
/// Index into the [`MultiMap::out_of_order`] vector at which offset the leaading vec is stored.
509509
leading_index: usize,
510510
_count: Count<OutOfOrderEntry>,
511511
}

crates/ruff_python_formatter/src/comments/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ type CommentsMap<'a> = MultiMap<NodeRefEqualityKey<'a>, SourceComment>;
195195
/// Cloning `comments` is cheap as it only involves bumping a reference counter.
196196
#[derive(Debug, Clone)]
197197
pub(crate) struct Comments<'a> {
198-
/// The implementation uses an [Rc] so that [Comments] has a lifetime independent from the [crate::Formatter].
199-
/// Independent lifetimes are necessary to support the use case where a (formattable object)[crate::Format]
200-
/// iterates over all comments, and writes them into the [crate::Formatter] (mutably borrowing the [crate::Formatter] and in turn its context).
198+
/// The implementation uses an [Rc] so that [Comments] has a lifetime independent from the [`crate::Formatter`].
199+
/// Independent lifetimes are necessary to support the use case where a (formattable object)[`crate::Format`]
200+
/// iterates over all comments, and writes them into the [`crate::Formatter`] (mutably borrowing the [`crate::Formatter`] and in turn its context).
201201
///
202202
/// ```block
203203
/// for leading in f.context().comments().leading_comments(node) {

crates/ruff_python_formatter/src/expression/expr_attribute.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ruff_python_ast::{Expr, ExprAttribute, ExprNumberLiteral, Number};
44
use ruff_python_trivia::{find_only_token_in_range, SimpleTokenKind};
55
use ruff_text_size::{Ranged, TextRange};
66

7-
use crate::comments::{dangling_comments, SourceComment};
7+
use crate::comments::dangling_comments;
88
use crate::expression::parentheses::{
99
is_expression_parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
1010
};
@@ -123,15 +123,6 @@ impl FormatNodeRule<ExprAttribute> for FormatExprAttribute {
123123
write!(f, [format_inner])
124124
}
125125
}
126-
127-
fn fmt_dangling_comments(
128-
&self,
129-
_dangling_comments: &[SourceComment],
130-
_f: &mut PyFormatter,
131-
) -> FormatResult<()> {
132-
// handle in `fmt_fields`
133-
Ok(())
134-
}
135126
}
136127

137128
impl NeedsParentheses for ExprAttribute {

crates/ruff_python_formatter/src/expression/expr_bin_op.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use ruff_python_ast::AnyNodeRef;
22
use ruff_python_ast::ExprBinOp;
33

4-
use crate::comments::SourceComment;
54
use crate::expression::binary_like::BinaryLike;
65
use crate::expression::has_parentheses;
76
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
@@ -16,15 +15,6 @@ impl FormatNodeRule<ExprBinOp> for FormatExprBinOp {
1615
fn fmt_fields(&self, item: &ExprBinOp, f: &mut PyFormatter) -> FormatResult<()> {
1716
BinaryLike::Binary(item).fmt(f)
1817
}
19-
20-
fn fmt_dangling_comments(
21-
&self,
22-
_dangling_comments: &[SourceComment],
23-
_f: &mut PyFormatter,
24-
) -> FormatResult<()> {
25-
// Handled inside of `fmt_fields`
26-
Ok(())
27-
}
2818
}
2919

3020
impl NeedsParentheses for ExprBinOp {

0 commit comments

Comments
 (0)