summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-01-28 07:44:14 +0000
committerbors <bors@rust-lang.org>2018-01-28 07:44:14 +0000
commit7046a406232695b581579f8e2468601260ea2199 (patch)
treeb6c17a098f2035b5ed43d3f7040b8c9047cc8349
parent87990a119aa1ce77f294253cde836518870b8032 (diff)
parent445e404ba4c9782e4f5028eccb7c9473ae33c70a (diff)
downloadrust-7046a406232695b581579f8e2468601260ea2199.tar.gz
Auto merge of #47767 - estebank:as-suggestion, r=petrochenkov
Correctly format `extern crate` conflict resolution help Closes #45799. Follow up to @Cldfire's #45820. If the `extern` statement that will have a suggestion ends on a `;`, synthesize a new span that doesn't include it.
-rw-r--r--src/librustc_resolve/lib.rs12
-rw-r--r--src/libsyntax/parse/parser.rs1
-rw-r--r--src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs13
-rw-r--r--src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr14
4 files changed, 37 insertions, 3 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index f7228fc3314..ecf3c9e42d5 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -3980,14 +3980,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(self.session.codemap().def_span(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
@@ -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 e8e87e2854b..a3de31cc2ea 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -6115,6 +6115,7 @@ impl<'a> Parser<'a> {
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
new file mode 100644
index 00000000000..4d75127b645
--- /dev/null
+++ b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs
@@ -0,0 +1,13 @@
+// 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() {}
+//~^^ 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
new file mode 100644
index 00000000000..d2ac15f7ffc
--- /dev/null
+++ b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr
@@ -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
+