Skip to content

Commit e593431

Browse files
committed
resolve: Fix bad span arithmetics in import conflict diagnostics
1 parent d4a78da commit e593431

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/librustc_resolve/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4999,10 +4999,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
49994999
err.span_suggestion_with_applicability(
50005000
binding.span,
50015001
&rename_msg,
5002-
match (&directive.subclass, snippet.as_ref()) {
5003-
(ImportDirectiveSubclass::SingleImport { .. }, "self") =>
5002+
match directive.subclass {
5003+
ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } =>
50045004
format!("self as {}", suggested_name),
5005-
(ImportDirectiveSubclass::SingleImport { source, .. }, _) =>
5005+
ImportDirectiveSubclass::SingleImport { source, .. } =>
50065006
format!(
50075007
"{} as {}{}",
50085008
&snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)],
@@ -5013,13 +5013,13 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
50135013
""
50145014
}
50155015
),
5016-
(ImportDirectiveSubclass::ExternCrate { source, target, .. }, _) =>
5016+
ImportDirectiveSubclass::ExternCrate { source, target, .. } =>
50175017
format!(
50185018
"extern crate {} as {};",
50195019
source.unwrap_or(target.name),
50205020
suggested_name,
50215021
),
5022-
(_, _) => unreachable!(),
5022+
_ => unreachable!(),
50235023
},
50245024
Applicability::MaybeIncorrect,
50255025
);

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

+3
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

+17-3
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)