Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly format extern crate conflict resolution help #45820

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3684,14 +3684,14 @@ impl<'a> Resolver<'a> {
container));

err.span_label(span, format!("`{}` re{} here", name, new_participle));
if old_binding.span != syntax_pos::DUMMY_SP {
if old_binding.span != DUMMY_SP {
err.span_label(old_binding.span, format!("previous {} of the {} `{}` here",
old_noun, old_kind, name));
}

// See https://github.com/rust-lang/rust/issues/32354
if old_binding.is_import() || new_binding.is_import() {
let binding = if new_binding.is_import() {
let binding = if new_binding.is_import() && new_binding.span != DUMMY_SP {
new_binding
} else {
old_binding
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5739,9 +5739,11 @@ impl<'a> Parser<'a> {
} else {
(None, crate_name)
};
self.expect(&token::Semi)?;

// 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)?;

Ok(self.mk_item(lo.to(prev_span),
ident,
ItemKind::ExternCrate(maybe_path),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate std;
fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
|
= 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