-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix use placement for suggestions near main. #85427
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this look like uncommented in the fixed output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this (after formatting):