Skip to content

Commit

Permalink
resolve: Fix bad span arithmetics in import conflict diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Nov 25, 2018
1 parent d4a78da commit e593431
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4999,10 +4999,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
err.span_suggestion_with_applicability(
binding.span,
&rename_msg,
match (&directive.subclass, snippet.as_ref()) {
(ImportDirectiveSubclass::SingleImport { .. }, "self") =>
match directive.subclass {
ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } =>
format!("self as {}", suggested_name),
(ImportDirectiveSubclass::SingleImport { source, .. }, _) =>
ImportDirectiveSubclass::SingleImport { source, .. } =>
format!(
"{} as {}{}",
&snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)],
Expand All @@ -5013,13 +5013,13 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
""
}
),
(ImportDirectiveSubclass::ExternCrate { source, target, .. }, _) =>
ImportDirectiveSubclass::ExternCrate { source, target, .. } =>
format!(
"extern crate {} as {};",
source.unwrap_or(target.name),
suggested_name,
),
(_, _) => unreachable!(),
_ => unreachable!(),
},
Applicability::MaybeIncorrect,
);
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/issues/issue-45829/import-self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ use foo as self;

use foo::self;

use foo::A;
use foo::{self as A};

fn main() {}
20 changes: 17 additions & 3 deletions src/test/ui/issues/issue-45829/import-self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,21 @@ help: you can use `as` to change the binding name of the import
LL | use foo::{self as other_foo};
| ^^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors
error[E0252]: the name `A` is defined multiple times
--> $DIR/import-self.rs:23:11
|
LL | use foo::A;
| ------ previous import of the type `A` here
LL | use foo::{self as A};
| ^^^^^^^^^ `A` reimported here
|
= note: `A` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
LL | use foo::{self as OtherA};
| ^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

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

0 comments on commit e593431

Please sign in to comment.