Skip to content

suggesting for traits to import are not prefaced with crate in Rust 2018 #54559

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
nikomatsakis opened this issue Sep 25, 2018 · 2 comments · Fixed by #54603
Closed

suggesting for traits to import are not prefaced with crate in Rust 2018 #54559

nikomatsakis opened this issue Sep 25, 2018 · 2 comments · Fixed by #54603
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

Consider this test case in Rust 2018 (playground):

mod foo {
    pub(crate) trait Bar {
        fn bar(&self) { }
    } 
    
    impl Bar for u32 { }
}

fn main() {
    let x: u32 = 22;
    x.bar();
}

I get this error:

error[E0599]: no method named `bar` found for type `u32` in the current scope
  --> src/main.rs:11:7
   |
11 |     x.bar();
   |       ^^^
   |
   = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
   |
1  | use foo::Bar;
   |

I would like to see use crate::foo::Bar, however.

@nikomatsakis nikomatsakis added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-rust_2018_preview `#![feature(rust_2018_preview)]` A-edition-2018-lints labels Sep 25, 2018
@nikomatsakis nikomatsakis added this to the Edition 2018 RC 2 milestone Sep 25, 2018
@nikomatsakis
Copy link
Contributor Author

cc @Mark-Simulacrum @Centril — Rust 2018 related bug, not sure how best to label/triage

@Mark-Simulacrum
Copy link
Member

Cc @alexcrichton @eddyb - I think there might already be a similar bug elsewhere, not sure

@davidtwco davidtwco self-assigned this Sep 25, 2018
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 2, 2018
Add `crate::` to trait suggestions in Rust 2018.

Fixes rust-lang#54559.

In the 2018 edition, when suggesting traits to import that implement a
given method that is being invoked, suggestions will now include the
`crate::` prefix if the suggested trait is local to the current crate.

r? @nikomatsakis
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 2, 2018
Add `crate::` to trait suggestions in Rust 2018.

Fixes rust-lang#54559.

In the 2018 edition, when suggesting traits to import that implement a
given method that is being invoked, suggestions will now include the
`crate::` prefix if the suggested trait is local to the current crate.

r? @nikomatsakis
@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-diagnostics Area: Messages for errors, warnings, and lints 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)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants