1
Fork 0

Instead of modifying the item's span synthesize it

This commit is contained in:
Esteban Küber 2018-01-25 22:40:38 -08:00
parent c39ad4b145
commit 445e404ba4
4 changed files with 12 additions and 6 deletions

View file

@ -4000,7 +4000,13 @@ impl<'a> Resolver<'a> {
binding.is_renamed_extern_crate()) { binding.is_renamed_extern_crate()) {
err.span_suggestion(binding.span, err.span_suggestion(binding.span,
rename_msg, rename_msg,
format!("{} as Other{}", snippet, name)); if snippet.ends_with(';') {
format!("{} as Other{};",
&snippet[..snippet.len()-1],
name)
} else {
format!("{} as Other{}", snippet, name)
});
} else { } else {
err.span_label(binding.span, rename_msg); err.span_label(binding.span, rename_msg);
} }

View file

@ -6128,11 +6128,10 @@ impl<'a> Parser<'a> {
} else { } else {
(None, crate_name) (None, crate_name)
}; };
// We grab this before expecting the `;` so it's not a part of the span
let prev_span = self.prev_span;
self.expect(&token::Semi)?; self.expect(&token::Semi)?;
let prev_span = self.prev_span;
Ok(self.mk_item(lo.to(prev_span), Ok(self.mk_item(lo.to(prev_span),
ident, ident,
ItemKind::ExternCrate(maybe_path), ItemKind::ExternCrate(maybe_path),

View file

@ -10,3 +10,4 @@
extern crate std; extern crate std;
fn main() {} fn main() {}
//~^^ ERROR the name `std` is defined multiple times [E0259]

View file

@ -2,13 +2,13 @@ error[E0259]: the name `std` is defined multiple times
--> $DIR/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs:11:1 --> $DIR/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs:11:1
| |
11 | extern crate std; 11 | extern crate std;
| ^^^^^^^^^^^^^^^^ `std` reimported here | ^^^^^^^^^^^^^^^^^ `std` reimported here
| |
= note: `std` must be defined only once in the type namespace of this module = note: `std` 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 help: You can use `as` to change the binding name of the import
| |
11 | extern crate std as Otherstd; 11 | extern crate std as Otherstd;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
error: aborting due to previous error error: aborting due to previous error