-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix use placement for suggestions near main.
- Loading branch information
Showing
11 changed files
with
167 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// run-rustfix | ||
#![allow(dead_code)] | ||
|
||
use m::A; | ||
|
||
use std::collections::HashMap; | ||
|
||
macro_rules! y { | ||
() => {} | ||
} | ||
|
||
mod m { | ||
pub const A: i32 = 0; | ||
} | ||
|
||
mod foo { | ||
// FIXME: UsePlacementFinder is broken because active attributes are | ||
// removed, and thus the `derive` attribute here is not in the AST. | ||
// An inert attribute should work, though. | ||
// #[derive(Debug)] | ||
use std::path::Path; | ||
|
||
#[allow(warnings)] | ||
pub struct Foo; | ||
|
||
// test whether the use suggestion isn't | ||
// placed into the expansion of `#[derive(Debug)] | ||
type Bar = Path; //~ ERROR cannot find | ||
} | ||
|
||
fn main() { | ||
y!(); | ||
let _ = A; //~ ERROR cannot find | ||
foo(); | ||
} | ||
|
||
fn foo() { | ||
type Dict<K, V> = HashMap<K, V>; //~ ERROR cannot find | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// compile-flags: --test | ||
// run-rustfix | ||
// Checks that the `use` suggestion appears *below* this inner attribute. | ||
// There was an issue where the test synthetic #[allow(dead)] attribute on | ||
// main which has a dummy span caused the suggestion to be placed at the top | ||
// of the file. | ||
#![allow(unused)] | ||
|
||
use std::fmt::Debug; | ||
|
||
fn main() {} | ||
|
||
fn foobar<T: Debug>(x: T) {} //~ ERROR expected trait, found derive macro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// compile-flags: --test | ||
// run-rustfix | ||
// Checks that the `use` suggestion appears *below* this inner attribute. | ||
// There was an issue where the test synthetic #[allow(dead)] attribute on | ||
// main which has a dummy span caused the suggestion to be placed at the top | ||
// of the file. | ||
#![allow(unused)] | ||
|
||
fn main() {} | ||
|
||
fn foobar<T: Debug>(x: T) {} //~ ERROR expected trait, found derive macro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0404]: expected trait, found derive macro `Debug` | ||
--> $DIR/use-placement-resolve.rs:11:14 | ||
| | ||
LL | fn foobar<T: Debug>(x: T) {} | ||
| ^^^^^ not a trait | ||
| | ||
help: consider importing this trait instead | ||
| | ||
LL | use std::fmt::Debug; | ||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0404`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// compile-flags: --test | ||
// run-rustfix | ||
// Checks that the `use` suggestion appears *below* this inner attribute. | ||
// There was an issue where the test synthetic #[allow(dead)] attribute on | ||
// main which has a dummy span caused the suggestion to be placed at the top | ||
// of the file. | ||
#![allow(unused)] | ||
|
||
use m::Foo; | ||
|
||
fn main() { | ||
let s = m::S; | ||
s.abc(); //~ ERROR no method named `abc` | ||
} | ||
|
||
mod m { | ||
pub trait Foo { | ||
fn abc(&self) {} | ||
} | ||
pub struct S; | ||
impl Foo for S{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// compile-flags: --test | ||
// run-rustfix | ||
// Checks that the `use` suggestion appears *below* this inner attribute. | ||
// There was an issue where the test synthetic #[allow(dead)] attribute on | ||
// main which has a dummy span caused the suggestion to be placed at the top | ||
// of the file. | ||
#![allow(unused)] | ||
|
||
fn main() { | ||
let s = m::S; | ||
s.abc(); //~ ERROR no method named `abc` | ||
} | ||
|
||
mod m { | ||
pub trait Foo { | ||
fn abc(&self) {} | ||
} | ||
pub struct S; | ||
impl Foo for S{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0599]: no method named `abc` found for struct `S` in the current scope | ||
--> $DIR/use-placement-typeck.rs:11:7 | ||
| | ||
LL | s.abc(); | ||
| ^^^ method not found in `S` | ||
... | ||
LL | fn abc(&self) {} | ||
| --- the method is available for `S` here | ||
LL | } | ||
LL | pub struct S; | ||
| ------------- method `abc` not found for this | ||
| | ||
= 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 m::Foo; | ||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0599`. |