Skip to content

Commit 7eaa758

Browse files
committed
Correctly format extern crate conflict resolution help
1 parent bd0e45a commit 7eaa758

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

src/librustc_resolve/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3684,14 +3684,14 @@ impl<'a> Resolver<'a> {
36843684
container));
36853685

36863686
err.span_label(span, format!("`{}` re{} here", name, new_participle));
3687-
if old_binding.span != syntax_pos::DUMMY_SP {
3687+
if old_binding.span != DUMMY_SP {
36883688
err.span_label(old_binding.span, format!("previous {} of the {} `{}` here",
36893689
old_noun, old_kind, name));
36903690
}
36913691

36923692
// See https://github.com/rust-lang/rust/issues/32354
36933693
if old_binding.is_import() || new_binding.is_import() {
3694-
let binding = if new_binding.is_import() {
3694+
let binding = if new_binding.is_import() && new_binding.span != DUMMY_SP {
36953695
new_binding
36963696
} else {
36973697
old_binding

src/libsyntax/parse/parser.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5739,9 +5739,11 @@ impl<'a> Parser<'a> {
57395739
} else {
57405740
(None, crate_name)
57415741
};
5742-
self.expect(&token::Semi)?;
57435742

5743+
// We grab this before expecting the `;` so it's not a part of the span
57445744
let prev_span = self.prev_span;
5745+
self.expect(&token::Semi)?;
5746+
57455747
Ok(self.mk_item(lo.to(prev_span),
57465748
ident,
57475749
ItemKind::ExternCrate(maybe_path),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern crate std;
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0259]: the name `std` is defined multiple times
2+
--> $DIR/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs:11:1
3+
|
4+
11 | extern crate std;
5+
| ^^^^^^^^^^^^^^^^ `std` reimported here
6+
|
7+
= note: `std` must be defined only once in the type namespace of this module
8+
help: You can use `as` to change the binding name of the import
9+
|
10+
11 | extern crate std as Otherstd;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)