resolve: Fix bad span arithmetics in import conflict diagnostics

This commit is contained in:
Vadim Petrochenkov 2018-11-25 04:25:59 +03:00
parent d4a78da543
commit e593431bc7
3 changed files with 25 additions and 8 deletions

View file

@ -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)],
@ -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,
);

View file

@ -19,4 +19,7 @@ use foo as self;
use foo::self;
use foo::A;
use foo::{self as A};
fn main() {}

View file

@ -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};
| ^^^^^^^^^^^^^^
Some errors occurred: E0255, E0429.
For more information about an error, try `rustc --explain E0255`.
error: aborting due to 4 previous errors
Some errors occurred: E0252, E0255, E0429.
For more information about an error, try `rustc --explain E0252`.