Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Rust 1.78 #11260

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ doc-valid-idents = [
"CodeQL",
"IPython",
"NumPy",
"LibCST",
"SCREAMING_SNAKE_CASE",
"SQLAlchemy",
"McCabe",
"FastAPI",
"..",
]
4 changes: 2 additions & 2 deletions crates/ruff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ pub struct CheckCommand {
/// The name of the file when passing it through stdin.
#[arg(long, help_heading = "Miscellaneous")]
pub stdin_filename: Option<PathBuf>,
/// List of mappings from file extension to language (one of ["python", "ipynb", "pyi"]). For
/// List of mappings from file extension to language (one of `"python"`, `"ipynb"`, `"pyi"`). For
dhruvmanila marked this conversation as resolved.
Show resolved Hide resolved
/// example, to treat `.ipy` files as IPython notebooks, use `--extension ipy:ipynb`.
#[arg(long, value_delimiter = ',')]
pub extension: Option<Vec<ExtensionPair>>,
Expand Down Expand Up @@ -466,7 +466,7 @@ pub struct FormatCommand {
/// The name of the file when passing it through stdin.
#[arg(long, help_heading = "Miscellaneous")]
pub stdin_filename: Option<PathBuf>,
/// List of mappings from file extension to language (one of ["python", "ipynb", "pyi"]). For
/// List of mappings from file extension to language (one of [`"python"`, `"ipynb"`, `"pyi"`]). For
dhruvmanila marked this conversation as resolved.
Show resolved Hide resolved
/// example, to treat `.ipy` files as IPython notebooks, use `--extension ipy:ipynb`.
#[arg(long, value_delimiter = ',')]
pub extension: Option<Vec<ExtensionPair>>,
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_formatter/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ pub struct RemoveSoftLinesBuffer<'a, Context> {

/// Caches the interned elements after the soft line breaks have been removed.
///
/// The `key` is the [Interned] element as it has been passed to [Self::write_element] or the child of another
/// The `key` is the [Interned] element as it has been passed to [`Self::write_element`] or the child of another
/// [Interned] element. The `value` is the matching document of the key where all soft line breaks have been removed.
///
/// It's fine to not snapshot the cache. The worst that can happen is that it holds on interned elements
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_formatter/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ pub enum FormatError {
InvalidDocument(InvalidDocumentError),

/// Formatting failed because some content encountered a situation where a layout
/// choice by an enclosing [crate::Format] resulted in a poor layout for a child [crate::Format].
/// choice by an enclosing [`crate::Format`] resulted in a poor layout for a child [`crate::Format`].
///
/// It's up to an enclosing [crate::Format] to handle the error and pick another layout.
/// This error should not be raised if there's no outer [crate::Format] handling the poor layout error,
/// It's up to an enclosing [`crate::Format`] to handle the error and pick another layout.
/// This error should not be raised if there's no outer [`crate::Format`] handling the poor layout error,
/// avoiding that formatting of the whole document fails.
PoorLayout,
}
Expand Down
12 changes: 6 additions & 6 deletions crates/ruff_formatter/src/format_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use ruff_text_size::TextSize;
/// Use the helper functions like [`crate::builders::space`], [`crate::builders::soft_line_break`] etc. defined in this file to create elements.
#[derive(Clone, Eq, PartialEq)]
pub enum FormatElement {
/// A space token, see [crate::builders::space] for documentation.
/// A space token, see [`crate::builders::space`] for documentation.
Space,

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

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

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum LineMode {
/// See [crate::builders::soft_line_break_or_space] for documentation.
/// See [`crate::builders::soft_line_break_or_space`] for documentation.
SoftOrSpace,
/// See [crate::builders::soft_line_break] for documentation.
/// See [`crate::builders::soft_line_break`] for documentation.
Soft,
/// See [crate::builders::hard_line_break] for documentation.
/// See [`crate::builders::hard_line_break`] for documentation.
Hard,
/// See [crate::builders::empty_line] for documentation.
/// See [`crate::builders::empty_line`] for documentation.
Empty,
}

Expand Down
18 changes: 9 additions & 9 deletions crates/ruff_formatter/src/format_element/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use std::num::NonZeroU8;
/// will be applied to all elements in between the start/end tags.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Tag {
/// Indents the content one level deeper, see [crate::builders::indent] for documentation and examples.
/// Indents the content one level deeper, see [`crate::builders::indent`] for documentation and examples.
StartIndent,
EndIndent,

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

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

Expand All @@ -44,22 +44,22 @@ pub enum Tag {
EndConditionalGroup,

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

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

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

/// Entry inside of a [Tag::StartFill]
/// Entry inside of a [`Tag::StartFill`]
StartEntry,
EndEntry,

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

Expand Down
21 changes: 0 additions & 21 deletions crates/ruff_formatter/src/printer/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,27 +189,6 @@ impl<'a, 'print> Queue<'a> for FitsQueue<'a, 'print> {
}
}

/// Iterator that calls [`Queue::pop`] until it reaches the end of the document.
///
/// The iterator traverses into the content of any [`FormatElement::Interned`].
pub(super) struct QueueIterator<'a, 'q, Q: Queue<'a>> {
queue: &'q mut Q,
lifetime: PhantomData<&'a ()>,
}
dhruvmanila marked this conversation as resolved.
Show resolved Hide resolved

impl<'a, Q> Iterator for QueueIterator<'a, '_, Q>
where
Q: Queue<'a>,
{
type Item = &'a FormatElement;

fn next(&mut self) -> Option<Self::Item> {
self.queue.pop()
}
}

impl<'a, Q> FusedIterator for QueueIterator<'a, '_, Q> where Q: Queue<'a> {}

pub(super) struct QueueContentIterator<'a, 'q, Q: Queue<'a>> {
queue: &'q mut Q,
kind: TagKind,
Expand Down
11 changes: 0 additions & 11 deletions crates/ruff_formatter/src/printer/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ pub(super) trait Stack<T> {

/// Returns the last element if any
fn top(&self) -> Option<&T>;

/// Returns `true` if the stack is empty
fn is_empty(&self) -> bool;
}

impl<T> Stack<T> for Vec<T> {
Expand All @@ -25,10 +22,6 @@ impl<T> Stack<T> for Vec<T> {
fn top(&self) -> Option<&T> {
self.last()
}

fn is_empty(&self) -> bool {
self.is_empty()
}
}

/// A Stack that is stacked on top of another stack. Guarantees that the underlying stack remains unchanged.
Expand Down Expand Up @@ -80,10 +73,6 @@ where
.last()
.or_else(|| self.original.as_slice().last())
}

fn is_empty(&self) -> bool {
self.stack.is_empty() && self.original.len() == 0
}
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ pub(crate) struct TodoComment<'a> {
pub(crate) directive: TodoDirective<'a>,
/// The comment's actual [`TextRange`].
pub(crate) range: TextRange,
/// The comment range's position in [`Indexer`].comment_ranges()
/// The comment range's position in [`Indexer`].`comment_ranges()`
MichaReiser marked this conversation as resolved.
Show resolved Hide resolved
pub(crate) range_index: usize,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/line_width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl CacheKey for LineLength {
pub enum ParseLineWidthError {
/// The string could not be parsed as a valid [u16]
ParseError(ParseIntError),
/// The [u16] value of the string is not a valid [LineLength]
/// The [u16] value of the string is not a valid [`LineLength`]
TryFromIntError(LineLengthFromIntError),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ pub(crate) fn fix_unnecessary_double_cast_or_process(
.find(|argument| argument.keyword.is_none())
{
let mut arg = arg.clone();
arg.comma = first.comma.clone();
arg.comma.clone_from(&first.comma);
arg.whitespace_after_arg = first.whitespace_after_arg.clone();
iter::once(arg)
.chain(rest.iter().cloned())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ pub(crate) fn fix_multiple_with_statements(

outer_with.items.append(&mut inner_with.items);
if outer_with.lpar.is_none() {
outer_with.lpar = inner_with.lpar.clone();
outer_with.rpar = inner_with.rpar.clone();
outer_with.lpar.clone_from(&inner_with.lpar);
outer_with.rpar.clone_from(&inner_with.rpar);
}
outer_with.body = inner_with.body.clone();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) fn redundant_backslash(
let start = locator.line_start(token.start());
start_index = continuation_lines
.binary_search(&start)
.map_or_else(|err_index| err_index, |ok_index| ok_index);
.unwrap_or_else(|err_index| err_index);
}
parens += 1;
}
Expand All @@ -70,7 +70,7 @@ pub(crate) fn redundant_backslash(
let end = locator.line_start(token.start());
let end_index = continuation_lines
.binary_search(&end)
.map_or_else(|err_index| err_index, |ok_index| ok_index);
.unwrap_or_else(|err_index| err_index);
for continuation_line in &continuation_lines[start_index..end_index] {
let backslash_end = locator.line_end(*continuation_line);
let backslash_start = backslash_end - TextSize::new(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl SortingStyle {
/// an "isort-style sort".
///
/// An isort-style sort sorts items first according to their casing:
/// `SCREAMING_SNAKE_CASE` names (conventionally used for global constants)
/// SCREAMING_SNAKE_CASE names (conventionally used for global constants)
/// come first, followed by CamelCase names (conventionally used for
/// classes), followed by anything else. Within each category,
/// a [natural sort](https://en.wikipedia.org/wiki/Natural_sort_order)
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_python_ast/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ impl ConversionFlag {
pub struct DebugText {
/// The text between the `{` and the expression node.
pub leading: String,
/// The text between the expression and the conversion, the format_spec, or the `}`, depending on what's present in the source
/// The text between the expression and the conversion, the `format_spec`, or the `}`, depending on what's present in the source
pub trailing: String,
}

Expand Down
12 changes: 6 additions & 6 deletions crates/ruff_python_formatter/src/comments/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl<K: std::hash::Hash + Eq, V> MultiMap<K, V> {
/// Returns `true` if `key` has any *leading*, *dangling*, or *trailing* parts.
#[allow(unused)]
pub(super) fn has(&self, key: &K) -> bool {
self.index.get(key).is_some()
self.index.contains_key(key)
}

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

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

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

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

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

_count: Count<InOrderEntry>,
Expand Down Expand Up @@ -505,7 +505,7 @@ impl InOrderEntry {

#[derive(Clone, Debug)]
struct OutOfOrderEntry {
/// Index into the [MultiMap::out_of_order] vector at which offset the leaading vec is stored.
/// Index into the [`MultiMap::out_of_order`] vector at which offset the leaading vec is stored.
leading_index: usize,
_count: Count<OutOfOrderEntry>,
}
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_python_formatter/src/comments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ type CommentsMap<'a> = MultiMap<NodeRefEqualityKey<'a>, SourceComment>;
/// Cloning `comments` is cheap as it only involves bumping a reference counter.
#[derive(Debug, Clone)]
pub(crate) struct Comments<'a> {
/// The implementation uses an [Rc] so that [Comments] has a lifetime independent from the [crate::Formatter].
/// Independent lifetimes are necessary to support the use case where a (formattable object)[crate::Format]
/// iterates over all comments, and writes them into the [crate::Formatter] (mutably borrowing the [crate::Formatter] and in turn its context).
/// The implementation uses an [Rc] so that [Comments] has a lifetime independent from the [`crate::Formatter`].
/// Independent lifetimes are necessary to support the use case where a (formattable object)[`crate::Format`]
/// iterates over all comments, and writes them into the [`crate::Formatter`] (mutably borrowing the [`crate::Formatter`] and in turn its context).
///
/// ```block
/// for leading in f.context().comments().leading_comments(node) {
Expand Down
11 changes: 1 addition & 10 deletions crates/ruff_python_formatter/src/expression/expr_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ruff_python_ast::{Expr, ExprAttribute, ExprNumberLiteral, Number};
use ruff_python_trivia::{find_only_token_in_range, SimpleTokenKind};
use ruff_text_size::{Ranged, TextRange};

use crate::comments::{dangling_comments, SourceComment};
use crate::comments::dangling_comments;
use crate::expression::parentheses::{
is_expression_parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
};
Expand Down Expand Up @@ -123,15 +123,6 @@ impl FormatNodeRule<ExprAttribute> for FormatExprAttribute {
write!(f, [format_inner])
}
}

fn fmt_dangling_comments(
&self,
_dangling_comments: &[SourceComment],
_f: &mut PyFormatter,
) -> FormatResult<()> {
// handle in `fmt_fields`
Ok(())
}
}

impl NeedsParentheses for ExprAttribute {
Expand Down
10 changes: 0 additions & 10 deletions crates/ruff_python_formatter/src/expression/expr_bin_op.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprBinOp;

use crate::comments::SourceComment;
use crate::expression::binary_like::BinaryLike;
use crate::expression::has_parentheses;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
Expand All @@ -16,15 +15,6 @@ impl FormatNodeRule<ExprBinOp> for FormatExprBinOp {
fn fmt_fields(&self, item: &ExprBinOp, f: &mut PyFormatter) -> FormatResult<()> {
BinaryLike::Binary(item).fmt(f)
}

fn fmt_dangling_comments(
&self,
_dangling_comments: &[SourceComment],
_f: &mut PyFormatter,
) -> FormatResult<()> {
// Handled inside of `fmt_fields`
Ok(())
}
}

impl NeedsParentheses for ExprBinOp {
Expand Down
Loading
Loading