Skip to content

Commit 2daee96

Browse files
committed
resolve: Fix bad span arithmetics in import conflict diagnostics
1 parent 1c16fa4 commit 2daee96

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/librustc_resolve/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5001,10 +5001,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
50015001
err.span_suggestion_with_applicability(
50025002
binding.span,
50035003
&rename_msg,
5004-
match (&directive.subclass, snippet.as_ref()) {
5005-
(ImportDirectiveSubclass::SingleImport { .. }, "self") =>
5004+
match directive.subclass {
5005+
ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } =>
50065006
format!("self as {}", suggested_name),
5007-
(ImportDirectiveSubclass::SingleImport { source, .. }, _) =>
5007+
ImportDirectiveSubclass::SingleImport { source, .. } =>
50085008
format!(
50095009
"{} as {}{}",
50105010
&snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)],
@@ -5015,13 +5015,13 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
50155015
""
50165016
}
50175017
),
5018-
(ImportDirectiveSubclass::ExternCrate { source, target, .. }, _) =>
5018+
ImportDirectiveSubclass::ExternCrate { source, target, .. } =>
50195019
format!(
50205020
"extern crate {} as {};",
50215021
source.unwrap_or(target.name),
50225022
suggested_name,
50235023
),
5024-
(_, _) => unreachable!(),
5024+
_ => unreachable!(),
50255025
},
50265026
Applicability::MaybeIncorrect,
50275027
);

src/test/ui/issues/issue-45829/import-self.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ use foo as self;
1919

2020
use foo::self;
2121

22+
use foo::A;
23+
use foo::{self as A};
24+
2225
fn main() {}

src/test/ui/issues/issue-45829/import-self.stderr

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,21 @@ help: you can use `as` to change the binding name of the import
2525
LL | use foo::{self as other_foo};
2626
| ^^^^^^^^^^^^^^^^^
2727

28-
error: aborting due to 3 previous errors
28+
error[E0252]: the name `A` is defined multiple times
29+
--> $DIR/import-self.rs:23:11
30+
|
31+
LL | use foo::A;
32+
| ------ previous import of the type `A` here
33+
LL | use foo::{self as A};
34+
| ^^^^^^^^^ `A` reimported here
35+
|
36+
= note: `A` must be defined only once in the type namespace of this module
37+
help: you can use `as` to change the binding name of the import
38+
|
39+
LL | use foo::{self as OtherA};
40+
| ^^^^^^^^^^^^^^
41+
42+
error: aborting due to 4 previous errors
2943

30-
Some errors occurred: E0255, E0429.
31-
For more information about an error, try `rustc --explain E0255`.
44+
Some errors occurred: E0252, E0255, E0429.
45+
For more information about an error, try `rustc --explain E0252`.

0 commit comments

Comments
 (0)