Skip to content

Commit 196e4be

Browse files
authored
Update MSRV to 1.85 and toolchain to 1.87 (#18126)
1 parent 6e39250 commit 196e4be

File tree

19 files changed

+82
-54
lines changed

19 files changed

+82
-54
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resolver = "2"
44

55
[workspace.package]
66
edition = "2021"
7-
rust-version = "1.84"
7+
rust-version = "1.85"
88
homepage = "https://docs.astral.sh/ruff"
99
documentation = "https://docs.astral.sh/ruff"
1010
repository = "https://github.com/astral-sh/ruff"
@@ -215,6 +215,7 @@ similar_names = "allow"
215215
single_match_else = "allow"
216216
too_many_lines = "allow"
217217
needless_continue = "allow" # An explicit continue can be more readable, especially if the alternative is an empty block.
218+
unnecessary_debug_formatting = "allow" # too many instances, the display also doesn't quote the path which is often desired in logs where we use them the most often.
218219
# Without the hashes we run into a `rustfmt` bug in some snapshot tests, see #13250
219220
needless_raw_string_hashes = "allow"
220221
# Disallowed restriction lints

crates/ruff_db/src/source.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct SourceTextInner {
133133
#[derive(Eq, PartialEq)]
134134
enum SourceTextKind {
135135
Text(String),
136-
Notebook(Notebook),
136+
Notebook(Box<Notebook>),
137137
}
138138

139139
impl From<String> for SourceTextKind {
@@ -144,7 +144,7 @@ impl From<String> for SourceTextKind {
144144

145145
impl From<Notebook> for SourceTextKind {
146146
fn from(notebook: Notebook) -> Self {
147-
SourceTextKind::Notebook(notebook)
147+
SourceTextKind::Notebook(Box::new(notebook))
148148
}
149149
}
150150

crates/ruff_db/src/system/memory_fs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,17 +463,17 @@ fn not_found() -> std::io::Error {
463463
fn is_a_directory() -> std::io::Error {
464464
// Note: Rust returns `ErrorKind::IsADirectory` for this error but this is a nightly only variant :(.
465465
// So we have to use other for now.
466-
std::io::Error::new(std::io::ErrorKind::Other, "Is a directory")
466+
std::io::Error::other("Is a directory")
467467
}
468468

469469
fn not_a_directory() -> std::io::Error {
470470
// Note: Rust returns `ErrorKind::NotADirectory` for this error but this is a nightly only variant :(.
471471
// So we have to use `Other` for now.
472-
std::io::Error::new(std::io::ErrorKind::Other, "Not a directory")
472+
std::io::Error::other("Not a directory")
473473
}
474474

475475
fn directory_not_empty() -> std::io::Error {
476-
std::io::Error::new(std::io::ErrorKind::Other, "directory not empty")
476+
std::io::Error::other("directory not empty")
477477
}
478478

479479
fn create_dir_all(

crates/ruff_formatter/src/builders.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,22 +1388,22 @@ pub fn soft_space_or_block_indent<Context>(content: &impl Format<Context>) -> Bl
13881388
pub fn group<Context>(content: &impl Format<Context>) -> Group<Context> {
13891389
Group {
13901390
content: Argument::new(content),
1391-
group_id: None,
1391+
id: None,
13921392
should_expand: false,
13931393
}
13941394
}
13951395

13961396
#[derive(Copy, Clone)]
13971397
pub struct Group<'a, Context> {
13981398
content: Argument<'a, Context>,
1399-
group_id: Option<GroupId>,
1399+
id: Option<GroupId>,
14001400
should_expand: bool,
14011401
}
14021402

14031403
impl<Context> Group<'_, Context> {
14041404
#[must_use]
1405-
pub fn with_group_id(mut self, group_id: Option<GroupId>) -> Self {
1406-
self.group_id = group_id;
1405+
pub fn with_id(mut self, group_id: Option<GroupId>) -> Self {
1406+
self.id = group_id;
14071407
self
14081408
}
14091409

@@ -1429,7 +1429,7 @@ impl<Context> Format<Context> for Group<'_, Context> {
14291429
};
14301430

14311431
f.write_element(FormatElement::Tag(StartGroup(
1432-
tag::Group::new().with_id(self.group_id).with_mode(mode),
1432+
tag::Group::new().with_id(self.id).with_mode(mode),
14331433
)));
14341434

14351435
Arguments::from(&self.content).fmt(f)?;
@@ -1443,7 +1443,7 @@ impl<Context> Format<Context> for Group<'_, Context> {
14431443
impl<Context> std::fmt::Debug for Group<'_, Context> {
14441444
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14451445
f.debug_struct("Group")
1446-
.field("group_id", &self.group_id)
1446+
.field("id", &self.id)
14471447
.field("should_expand", &self.should_expand)
14481448
.field("content", &"{{content}}")
14491449
.finish()
@@ -1642,7 +1642,7 @@ impl<Context> std::fmt::Debug for BestFitParenthesize<'_, Context> {
16421642
/// soft_line_break(),
16431643
/// if_group_breaks(&token(")"))
16441644
/// ])
1645-
/// .with_group_id(Some(parentheses_id))
1645+
/// .with_id(Some(parentheses_id))
16461646
/// .fmt(f)
16471647
/// });
16481648
///
@@ -1991,7 +1991,7 @@ impl<Context> IfGroupBreaks<'_, Context> {
19911991
/// })),
19921992
/// token("]")
19931993
/// ],
1994-
/// ).with_group_id(Some(group_id))
1994+
/// ).with_id(Some(group_id))
19951995
/// ])
19961996
/// })])?;
19971997
///
@@ -2046,7 +2046,7 @@ impl<Context> std::fmt::Debug for IfGroupBreaks<'_, Context> {
20462046
/// let id = f.group_id("head");
20472047
///
20482048
/// write!(f, [
2049-
/// group(&token("Head")).with_group_id(Some(id)),
2049+
/// group(&token("Head")).with_id(Some(id)),
20502050
/// if_group_breaks(&indent(&token("indented"))).with_group_id(Some(id)),
20512051
/// if_group_fits_on_line(&token("indented")).with_group_id(Some(id))
20522052
/// ])
@@ -2071,7 +2071,7 @@ impl<Context> std::fmt::Debug for IfGroupBreaks<'_, Context> {
20712071
/// let group_id = f.group_id("header");
20722072
///
20732073
/// write!(f, [
2074-
/// group(&token("(aLongHeaderThatBreaksForSomeReason) =>")).with_group_id(Some(group_id)),
2074+
/// group(&token("(aLongHeaderThatBreaksForSomeReason) =>")).with_id(Some(group_id)),
20752075
/// indent_if_group_breaks(&format_args![hard_line_break(), token("a => b")], group_id)
20762076
/// ])
20772077
/// });
@@ -2101,7 +2101,7 @@ impl<Context> std::fmt::Debug for IfGroupBreaks<'_, Context> {
21012101
/// let group_id = f.group_id("header");
21022102
///
21032103
/// write!(f, [
2104-
/// group(&token("(aLongHeaderThatBreaksForSomeReason) =>")).with_group_id(Some(group_id)),
2104+
/// group(&token("(aLongHeaderThatBreaksForSomeReason) =>")).with_id(Some(group_id)),
21052105
/// indent_if_group_breaks(&format_args![hard_line_break(), token("a => b")], group_id)
21062106
/// ])
21072107
/// });

crates/ruff_formatter/src/printer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ two lines`,
20022002
token("The referenced group breaks."),
20032003
hard_line_break()
20042004
])
2005-
.with_group_id(Some(group_id)),
2005+
.with_id(Some(group_id)),
20062006
group(&format_args![
20072007
token("This group breaks because:"),
20082008
soft_line_break_or_space(),
@@ -2027,15 +2027,15 @@ two lines`,
20272027
write!(
20282028
f,
20292029
[
2030-
group(&token("Group with id-2")).with_group_id(Some(id_2)),
2030+
group(&token("Group with id-2")).with_id(Some(id_2)),
20312031
hard_line_break()
20322032
]
20332033
)?;
20342034

20352035
write!(
20362036
f,
20372037
[
2038-
group(&token("Group with id-1 does not fit on the line because it exceeds the line width of 80 characters by")).with_group_id(Some(id_1)),
2038+
group(&token("Group with id-1 does not fit on the line because it exceeds the line width of 80 characters by")).with_id(Some(id_1)),
20392039
hard_line_break()
20402040
]
20412041
)?;

crates/ruff_linter/src/linter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ mod tests {
940940
#[test_case(Path::new("add_missing_cell_id.ipynb"), true; "add_missing_cell_id")]
941941
fn test_cell_id(path: &Path, has_id: bool) -> Result<()> {
942942
let source_notebook = Notebook::from_path(&notebook_path(path))?;
943-
let source_kind = SourceKind::IpyNotebook(source_notebook);
943+
let source_kind = SourceKind::ipy_notebook(source_notebook);
944944
let (_, transformed) = test_contents(
945945
&source_kind,
946946
path,
@@ -1231,7 +1231,7 @@ mod tests {
12311231
format!("async_comprehension_in_sync_comprehension_notebook_{python_version}");
12321232
let path = Path::new("resources/test/fixtures/syntax_errors/async_comprehension.ipynb");
12331233
let messages = test_contents_syntax_errors(
1234-
&SourceKind::IpyNotebook(Notebook::from_path(path)?),
1234+
&SourceKind::ipy_notebook(Notebook::from_path(path)?),
12351235
path,
12361236
&LinterSettings {
12371237
unresolved_target_version: python_version.into(),

crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn is_explicit_concatenation(expr: &Expr) -> Option<bool> {
198198
.iter()
199199
.map(is_explicit_concatenation)
200200
.collect::<Vec<_>>();
201-
if values.iter().any(|v| *v == Some(true)) {
201+
if values.contains(&Some(true)) {
202202
Some(true)
203203
} else if values.iter().all(|v| *v == Some(false)) {
204204
Some(false)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ struct StringLiteralDisplay<'a> {
174174
/// The elts from the original AST node representing the display.
175175
/// Each elt is the AST representation of a single string literal
176176
/// element in the display
177-
elts: Cow<'a, Vec<ast::Expr>>,
177+
elts: Cow<'a, [ast::Expr]>,
178178
/// The source-code range of the display as a whole
179179
range: TextRange,
180180
/// What kind of a display is it? A dict, set, list or tuple?

crates/ruff_linter/src/source_kind.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,47 @@ use colored::Colorize;
1616
use crate::fs;
1717
use crate::text_helpers::ShowNonprinting;
1818

19-
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
19+
#[derive(Clone, Debug, PartialEq)]
2020
pub enum SourceKind {
2121
/// The source contains Python source code.
2222
Python(String),
2323
/// The source contains a Jupyter notebook.
24-
IpyNotebook(Notebook),
24+
IpyNotebook(Box<Notebook>),
2525
}
2626

2727
impl SourceKind {
28+
pub fn ipy_notebook(notebook: Notebook) -> Self {
29+
SourceKind::IpyNotebook(Box::new(notebook))
30+
}
31+
32+
pub fn as_ipy_notebook(&self) -> Option<&Notebook> {
33+
match self {
34+
SourceKind::IpyNotebook(notebook) => Some(notebook),
35+
SourceKind::Python(_) => None,
36+
}
37+
}
38+
39+
pub fn as_python(&self) -> Option<&str> {
40+
match self {
41+
SourceKind::Python(code) => Some(code),
42+
SourceKind::IpyNotebook(_) => None,
43+
}
44+
}
45+
46+
pub fn expect_python(self) -> String {
47+
match self {
48+
SourceKind::Python(code) => code,
49+
SourceKind::IpyNotebook(_) => panic!("expected python code"),
50+
}
51+
}
52+
53+
pub fn expect_ipy_notebook(self) -> Notebook {
54+
match self {
55+
SourceKind::IpyNotebook(notebook) => *notebook,
56+
SourceKind::Python(_) => panic!("expected ipy notebook"),
57+
}
58+
}
59+
2860
#[must_use]
2961
pub(crate) fn updated(&self, new_source: String, source_map: &SourceMap) -> Self {
3062
match self {
@@ -52,7 +84,7 @@ impl SourceKind {
5284
let notebook = Notebook::from_path(path)?;
5385
Ok(notebook
5486
.is_python_notebook()
55-
.then_some(Self::IpyNotebook(notebook)))
87+
.then_some(Self::IpyNotebook(Box::new(notebook))))
5688
} else {
5789
let contents = std::fs::read_to_string(path)?;
5890
Ok(Some(Self::Python(contents)))
@@ -69,7 +101,7 @@ impl SourceKind {
69101
let notebook = Notebook::from_source_code(&source_code)?;
70102
Ok(notebook
71103
.is_python_notebook()
72-
.then_some(Self::IpyNotebook(notebook)))
104+
.then_some(Self::IpyNotebook(Box::new(notebook))))
73105
} else {
74106
Ok(Some(Self::Python(source_code)))
75107
}

crates/ruff_linter/src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub(crate) fn assert_notebook_path(
6060
) -> Result<TestedNotebook, NotebookError> {
6161
let source_notebook = Notebook::from_path(path.as_ref())?;
6262

63-
let source_kind = SourceKind::IpyNotebook(source_notebook);
63+
let source_kind = SourceKind::ipy_notebook(source_notebook);
6464
let (messages, transformed) = test_contents(&source_kind, path.as_ref(), settings);
6565
let expected_notebook = Notebook::from_path(expected.as_ref())?;
6666
let linted_notebook = transformed.into_owned().expect_ipy_notebook();

0 commit comments

Comments
 (0)