Skip to content

cargo fix: Adjusting a path in a turbofish doesn't work when also adjusting the outer path #5797

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
jtgeibel opened this issue Jul 26, 2018 · 2 comments

Comments

@jtgeibel
Copy link
Member

The following example code is not automatically fixed on the most recent nightly (cargo 1.29.0-nightly (506eea76e 2018-07-17)).

The issue only occurs when both the outer path and the path inside the turbofish need to be adjusted.

Code

#![feature(rust_2018_preview)]

fn generic_return<T>() {
}

pub struct B{}

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

Output

$ cargo fix --prepare-for 2018 --allow-dirty
    Checking cargo-fix-test v0.1.0 (file:///home/jtgeibel/repos/localhost/tmp/cargo-fix-test)                                                                                                                                                                                  
warning: error applying suggestions to `src/lib.rs`

The full error message was:

> Could not replace range 140...162 in file -- maybe parts of it were already replaced?This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see 
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/cargo/issues
quoting the full output of this command we'd be very appreciative!

warning: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
  --> src/lib.rs:11:9
   |
11 |         ::generic_return::<::B>();
   |         ^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::generic_return::<::B>`
   |
   = note: `-W absolute-paths-not-starting-with-crate` implied by `-W 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/lib.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

    Finished dev [unoptimized + debuginfo] target(s) in 0.18s

Manual patches

Either of the following patches allows cargo fix to prefix both (now decoupled) paths with crate and exit succesfully.

@@ -7,7 +7,9 @@ fn generic_return<T>() {
 pub struct B{}
 
 pub mod submod {
+    use generic_return;
+
     pub fn test() {
-        ::generic_return::<::B>();
+        generic_return::<::B>();
     }
 }
@@ -7,7 +7,9 @@ fn generic_return<T>() {
 pub struct B{}
 
 pub mod submod {
+    use B;
+
     pub fn test() {
-        ::generic_return::<::B>();
+        ::generic_return::<B>();
     }
 }
@alexcrichton
Copy link
Member

Thanks for the report! I've split this into rust-lang/rust#52754 and #5813, so I'm going to close this in favor of those issues.

@jtgeibel
Copy link
Member Author

Thanks! It looks to me like those 2 issues would cover this upstream and as a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants