Skip to content

Commit

Permalink
Rollup merge of #104315 - SparkyPotato:fix-104276, r=cjgillot
Browse files Browse the repository at this point in the history
Improve spans with `use crate::{self}`

Fixes #104276.

The error becomes:
```
error: crate root imports need to be explicitly named: `use crate as name;`
 --> src/lib.rs.rs:1:13
  |
1 | use crate::{self};
  |             ^^^^

warning: unused import: `self`
 --> src/lib.rs:1:13
  |
1 | use crate::{self};
  |             ^^^^
  |
  = note: `#[warn(unused_imports)]` on by default
```
  • Loading branch information
matthiaskrgr authored Nov 13, 2022
2 parents a1b0702 + c7b2891 commit 5c764da
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}

// Replace `use foo::{ self };` with `use foo;`
let self_span = source.ident.span;
source = module_path.pop().unwrap();
if rename.is_none() {
ident = source.ident;
// Keep the span of `self`, but the name of `foo`
ident = Ident { name: source.ident.name, span: self_span };
}
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/use/use-crate-self.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use crate::{self};
//~^ ERROR crate root imports need to be explicitly named: `use crate as name;`

fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/use/use-crate-self.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: crate root imports need to be explicitly named: `use crate as name;`
--> $DIR/use-crate-self.rs:1:13
|
LL | use crate::{self};
| ^^^^

error: aborting due to previous error

0 comments on commit 5c764da

Please sign in to comment.