-
Notifications
You must be signed in to change notification settings - Fork 13.3k
2024 edition migration of ref
in patterns suboptimal: fixed up by clippy --fix
#136047
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
Comments
@rustbot modify labels: A-edition-2024 |
That's surprising indeed, the lint shouldn't trigger on that. What the type of the payload of the |
The type here is: #[derive(Clone)]
#[non_exhaustive]
pub enum Selector {
/// Match all lines
All,
/// End of file (useful to insert lines at the very end)
Eof,
/// Match a specific line number (1-indexed)
Line(usize),
/// A range of line numbers (1-indexed, inclusive)
Range(usize, usize),
/// A regex to match the line
Regex(Regex),
/// A custom function, passed the line number and current line
#[allow(clippy::type_complexity)]
Function(Rc<dyn Fn(usize, &str) -> bool>),
} However, this also happens separately with the function variant of this other enum as well: #[derive(Debug, Any)]
#[rune(item = ::patch)]
enum Action {
/// Copy the current line to the output. Only needed when auto-print is
/// disabled.
#[rune(constructor)]
Print,
/// Delete the current line and short circuit the rest of the program
/// (immediately go to the next line)
#[rune(constructor)]
Delete,
// ... [cut out for brevity, there are many more variants] ...
#[rune(constructor)]
RegexReplace(#[rune(get)] String, #[rune(get)] String),
/// Like `RegexReplace` but replaces all matches on the line.
#[rune(constructor)]
RegexReplaceAll(#[rune(get)] String, #[rune(get)] String),
/// A sub-program that is executed. Will share pattern space with parent
/// program
Subprogram(LineEditor),
/// A custom function passed the current pattern buffer, returning a new
/// pattern buffer
#[rune(constructor)]
Function(#[rune(get)] Shared<rune::runtime::Function>),
} As well as this change in --- a/crates/konfigkoll_core/src/save.rs
+++ b/crates/konfigkoll_core/src/save.rs
@@ -28,13 +28,13 @@ pub fn save_fs_changes<'instruction>(
for instruction in instructions {
let comment = match (instruction.pkg, &instruction.comment) {
(None, None) => CompactString::default(),
- (None, Some(ref comment)) => {
+ (None, &Some(ref comment)) => {
format_compact!(" // {comment}")
}
(Some(pkg), None) => {
format_compact!(" // [{}]", pkg.as_str(interner))
}
- (Some(pkg), Some(ref comment)) => {
+ (Some(pkg), &Some(ref comment)) => {
format_compact!(" // [{}] {comment}", pkg.as_str(interner))
}
}; Where And in the third case ( pub enum DiffGoal<'map, 'files> {
Apply(Arc<dyn Files>, &'map PathMap<'files>),
Save,
} I would suggest you take a look at the whole diff of VorpalBlade/paketkoll@7ec3d44 to see what clippy changed back as there are several instances of this, with different types. I don't know which ones should be considered separate bugs and which ones should be the same. They all look related to me. |
I see two issues at play here:
|
Ah, yes it seems you are right looking at VorpalBlade/paketkoll@a715c59. There was an extra ref there. So your point 2 is indeed not an issue. Point 1 remains. Clippy shouldn't have to clean up from the migration being sloppy. When I'm not on mobile I will edit the title and the original post to clarify that clippy didn't actually revert, just clean up. |
ref
in patterns suboptimal: fixed up by clippy --fix
Does anyone know how difficult it would be to make rust_2024_incompatible_pat smarter so that it recommends the more concise syntax? |
FWIW, the original design for editions had two-step "edition lint" + "idiom lint" phases. The first phase took code that compiled on the old edition and turned it into code that compiled on both editions, but was potentially not fully idiomatic. The second phase took code that compiled on both editions and cleaned it up into code that may only compile in the newest edition. This was quite necessary since edition migrations aren't always perfect, and it's not great for the codebase to be in a situation where it's partially migrated but no longer compiles on either edition so you can't easily migrate further So while it's possible that in this specific case the migration could have been smarter, in general Clippy "fixing up after the edition" is fine. Ideally these fixups would be idiom lints, but it's not too bad for Clippy to do it. |
I don't think it'd be too difficult. I've written something very similar for another diagnostic. I'll see what I can do. @rustbot claim |
…fication, r=Nadrieril Pattern Migration 2024: try to suggest eliding redundant binding modifiers This is based on rust-lang#136475. Only the last commit is new. This is a simpler, more restrictive alternative to rust-lang#136496, meant to partially address rust-lang#136047. If a pattern can be migrated to Rust 2024 solely by removing redundant binding modifiers, this will make that suggestion; otherwise, it uses the old suggestion of making the pattern fully explicit. Relevant tracking issue: rust-lang#131414 `@rustbot` label A-diagnostics A-patterns A-edition-2024 r? `@Nadrieril`
…fication, r=Nadrieril Pattern Migration 2024: try to suggest eliding redundant binding modifiers This is based on rust-lang#136475. Only the last commit is new. This is a simpler, more restrictive alternative to rust-lang#136496, meant to partially address rust-lang#136047. If a pattern can be migrated to Rust 2024 solely by removing redundant binding modifiers, this will make that suggestion; otherwise, it uses the old suggestion of making the pattern fully explicit. Relevant tracking issue: rust-lang#131414 ``@rustbot`` label A-diagnostics A-patterns A-edition-2024 r? ``@Nadrieril``
Rollup merge of rust-lang#136577 - dianne:simple-pat-migration-simplification, r=Nadrieril Pattern Migration 2024: try to suggest eliding redundant binding modifiers This is based on rust-lang#136475. Only the last commit is new. This is a simpler, more restrictive alternative to rust-lang#136496, meant to partially address rust-lang#136047. If a pattern can be migrated to Rust 2024 solely by removing redundant binding modifiers, this will make that suggestion; otherwise, it uses the old suggestion of making the pattern fully explicit. Relevant tracking issue: rust-lang#131414 ``@rustbot`` label A-diagnostics A-patterns A-edition-2024 r? ``@Nadrieril``
The 2024 edition migration changed this:
into this:
Then running
cargo +beta clippy --fix
changed itright backtoSelector::Function(f)
.When runing without
--fix
this is the clippy message:I expected to see this happen:
A coherrent decision on what way is the proper way to write this. Rustc and clippy shouldn't fight each other.The edition migration shouldn't be sloppy and need to be fixed up by clippy.Instead, this happened: Clippy has to clean up after rustc.
I have also pushed this to a branch in my repo, in case you need more context for investigating this: https://github.com/VorpalBlade/paketkoll/tree/feature/edition-2024 (the migration and the reversion are each in a separate commit). There seemed to be a few more instances of the same needless_borrowed_reference in other files too, but I think they are the same underlying cause.
Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: