Rollup merge of #54603 - davidtwco:issue-54559, r=nikomatsakis
Add `crate::` to trait suggestions in Rust 2018. Fixes #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
This commit is contained in:
commit
f70f6ec567
8 changed files with 241 additions and 49 deletions
15
src/test/ui/rust-2018/auxiliary/trait-import-suggestions.rs
Normal file
15
src/test/ui/rust-2018/auxiliary/trait-import-suggestions.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pub trait Baz {
|
||||
fn baz(&self) { }
|
||||
}
|
||||
|
||||
impl Baz for u32 { }
|
||||
41
src/test/ui/rust-2018/trait-import-suggestions.rs
Normal file
41
src/test/ui/rust-2018/trait-import-suggestions.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// edition:2018
|
||||
// aux-build:trait-import-suggestions.rs
|
||||
// compile-flags:--extern trait-import-suggestions
|
||||
|
||||
mod foo {
|
||||
mod foobar {
|
||||
pub(crate) trait Foobar {
|
||||
fn foobar(&self) { }
|
||||
}
|
||||
|
||||
impl Foobar for u32 { }
|
||||
}
|
||||
|
||||
pub(crate) trait Bar {
|
||||
fn bar(&self) { }
|
||||
}
|
||||
|
||||
impl Bar for u32 { }
|
||||
|
||||
fn in_foo() {
|
||||
let x: u32 = 22;
|
||||
x.foobar();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x: u32 = 22;
|
||||
x.bar();
|
||||
x.baz();
|
||||
let y = u32::from_str("33");
|
||||
}
|
||||
43
src/test/ui/rust-2018/trait-import-suggestions.stderr
Normal file
43
src/test/ui/rust-2018/trait-import-suggestions.stderr
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
error[E0599]: no method named `foobar` found for type `u32` in the current scope
|
||||
--> $DIR/trait-import-suggestions.rs:32:11
|
||||
|
|
||||
LL | x.foobar();
|
||||
| ^^^^^^
|
||||
|
|
||||
= help: items from traits can only be used if the trait is in scope
|
||||
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:
|
||||
`use crate::foo::foobar::Foobar;`
|
||||
|
||||
error[E0599]: no method named `bar` found for type `u32` in the current scope
|
||||
--> $DIR/trait-import-suggestions.rs:38:7
|
||||
|
|
||||
LL | 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:
|
||||
|
|
||||
LL | use crate::foo::Bar;
|
||||
|
|
||||
|
||||
error[E0599]: no method named `baz` found for type `u32` in the current scope
|
||||
--> $DIR/trait-import-suggestions.rs:39:7
|
||||
|
|
||||
LL | x.baz();
|
||||
| ^^^
|
||||
|
||||
error[E0599]: no function or associated item named `from_str` found for type `u32` in the current scope
|
||||
--> $DIR/trait-import-suggestions.rs:40:13
|
||||
|
|
||||
LL | let y = u32::from_str("33");
|
||||
| ^^^^^^^^^^^^^ function or associated item not found in `u32`
|
||||
|
|
||||
= 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:
|
||||
|
|
||||
LL | use std::str::FromStr;
|
||||
|
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0599`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue