Skip to content

Lint suggesting crate:: makes overlapping suggestions #52754

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

Closed
alexcrichton opened this issue Jul 26, 2018 · 3 comments · Fixed by rust-lang/cargo#5842
Closed

Lint suggesting crate:: makes overlapping suggestions #52754

alexcrichton opened this issue Jul 26, 2018 · 3 comments · Fixed by rust-lang/cargo#5842
Assignees
Labels
A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. F-rust_2018_preview `#![feature(rust_2018_preview)]`

Comments

@alexcrichton
Copy link
Member

First reported at rust-lang/cargo#5797, this code:

#![feature(rust_2018_preview)]
#![warn(rust_2018_compatibility)]

fn generic_return<T>() {
}

pub struct B{}

pub mod submod {
    pub fn test() {
        ::generic_return::<::B>();
    }
}

fn main() {}

yields these warnings:

warning: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
  --> src/main.rs:11:9
   |
11 |         ::generic_return::<::B>();
   |         ^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::generic_return::<::B>`
   |
note: lint level defined here
  --> src/main.rs:2:9
   |
2  | #![warn(rust_2018_compatibility)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^
   = note: #[warn(absolute_paths_not_starting_with_crate)] implied by #[warn(rust_2018_compatibility)]
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
   = note: for more information, see issue TBD

warning: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
  --> src/main.rs:11:28
   |
11 |         ::generic_return::<::B>();
   |                            ^^^ help: use `crate`: `crate::B`
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
   = note: for more information, see issue TBD

unfortunately though, the overlapping suggestions here means that rustfix can't apply a fix!

@alexcrichton
Copy link
Member Author

Carrying over the preview 2 milestone from #51210

@alexcrichton
Copy link
Member Author

The impact of this issue can also be mitigated by rust-lang/cargo#5813

@alexcrichton
Copy link
Member Author

I'm gonna consider this closed with rust-lang/cargo#5842 as it'll be worked around in Cargo

alexcrichton added a commit to alexcrichton/cargo that referenced this issue Jul 31, 2018
This commit updates the `cargo fix` implementation to iteratively apply fixes
from the compiler instead of only once. Currently the compiler can sometimes
emit overlapping suggestions, such as in the case of transitioning

    ::foo::<::Bar>();

to ...

    crate::foo::<crate::Bar>();

and `rustfix` rightfully can't handle overlapping suggestions as there's no
clear way of how to disambiguate the fixes. To fix this problem Cargo will now
run `rustc` and `rustfix` multiple times, attempting to reach a steady state
where no fixes failed to apply.

Naturally this is a pretty tricky thing to do and we want to be sure that Cargo
doesn't loop forever, for example. A number of safeguards are in place to
prevent Cargo from going off into the weeds when fixing files, notably avoiding
to reattempt fixes if no successful fixes ended up being applied.

Closes rust-lang#5813
Closes rust-lang/rust#52754
bors added a commit to rust-lang/cargo that referenced this issue Aug 1, 2018
fix: Iteratively apply suggestions from the compiler

This commit updates the `cargo fix` implementation to iteratively apply fixes
from the compiler instead of only once. Currently the compiler can sometimes
emit overlapping suggestions, such as in the case of transitioning

    ::foo::<::Bar>();

to ...

    crate::foo::<crate::Bar>();

and `rustfix` rightfully can't handle overlapping suggestions as there's no
clear way of how to disambiguate the fixes. To fix this problem Cargo will now
run `rustc` and `rustfix` multiple times, attempting to reach a steady state
where no fixes failed to apply.

Naturally this is a pretty tricky thing to do and we want to be sure that Cargo
doesn't loop forever, for example. A number of safeguards are in place to
prevent Cargo from going off into the weeds when fixing files, notably avoiding
to reattempt fixes if no successful fixes ended up being applied.

Closes #5813
Closes rust-lang/rust#52754
@fmease fmease added A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-edition-2018-lints labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. F-rust_2018_preview `#![feature(rust_2018_preview)]`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants