Skip to content

Commit 445e404

Browse files
committed
Instead of modifying the item's span synthesize it
1 parent c39ad4b commit 445e404

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/librustc_resolve/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -4000,7 +4000,13 @@ impl<'a> Resolver<'a> {
40004000
binding.is_renamed_extern_crate()) {
40014001
err.span_suggestion(binding.span,
40024002
rename_msg,
4003-
format!("{} as Other{}", snippet, name));
4003+
if snippet.ends_with(';') {
4004+
format!("{} as Other{};",
4005+
&snippet[..snippet.len()-1],
4006+
name)
4007+
} else {
4008+
format!("{} as Other{}", snippet, name)
4009+
});
40044010
} else {
40054011
err.span_label(binding.span, rename_msg);
40064012
}

src/libsyntax/parse/parser.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6128,10 +6128,9 @@ impl<'a> Parser<'a> {
61286128
} else {
61296129
(None, crate_name)
61306130
};
6131+
self.expect(&token::Semi)?;
61316132

6132-
// We grab this before expecting the `;` so it's not a part of the span
61336133
let prev_span = self.prev_span;
6134-
self.expect(&token::Semi)?;
61356134

61366135
Ok(self.mk_item(lo.to(prev_span),
61376136
ident,

src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010

1111
extern crate std;
1212
fn main() {}
13+
//~^^ ERROR the name `std` is defined multiple times [E0259]

src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error[E0259]: the name `std` is defined multiple times
22
--> $DIR/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs:11:1
33
|
44
11 | extern crate std;
5-
| ^^^^^^^^^^^^^^^^ `std` reimported here
5+
| ^^^^^^^^^^^^^^^^^ `std` reimported here
66
|
77
= note: `std` must be defined only once in the type namespace of this module
88
help: You can use `as` to change the binding name of the import
99
|
1010
11 | extern crate std as Otherstd;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
|
1212

1313
error: aborting due to previous error
1414

0 commit comments

Comments
 (0)