diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 6fcdb1d651f..15ff0bff849 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -4000,7 +4000,13 @@ impl<'a> Resolver<'a> { binding.is_renamed_extern_crate()) { err.span_suggestion(binding.span, 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 { err.span_label(binding.span, rename_msg); } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a7977d5235d..35e89652c99 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6128,11 +6128,10 @@ impl<'a> Parser<'a> { } else { (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)?; + let prev_span = self.prev_span; + Ok(self.mk_item(lo.to(prev_span), ident, ItemKind::ExternCrate(maybe_path), diff --git a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs index 7c55f9c4eb9..4d75127b645 100644 --- a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs +++ b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs @@ -10,3 +10,4 @@ extern crate std; fn main() {} +//~^^ ERROR the name `std` is defined multiple times [E0259] diff --git a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr index a4eadcc8b46..d2ac15f7ffc 100644 --- a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr +++ b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr @@ -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 | 11 | extern crate std; - | ^^^^^^^^^^^^^^^^ `std` reimported here + | ^^^^^^^^^^^^^^^^^ `std` reimported here | = 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 | 11 | extern crate std as Otherstd; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | error: aborting due to previous error