Skip to content

Commit cbacdbc

Browse files
committed
auto merge of #16598 : bkoropoff/rust/import-shadow-name, r=alexcrichton
This partially alleviates the confusing behavior in issue #16597
2 parents d398eb7 + 6bbec28 commit cbacdbc

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

src/librustc/middle/resolve.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,9 +2822,10 @@ impl<'a> Resolver<'a> {
28222822
.contains_key(&name) {
28232823
match import_resolution.type_target {
28242824
Some(ref target) if !target.shadowable => {
2825-
self.session.span_err(import_span,
2826-
"import conflicts with imported \
2827-
crate in this module");
2825+
let msg = format!("import `{}` conflicts with imported \
2826+
crate in this module",
2827+
token::get_name(name).get());
2828+
self.session.span_err(import_span, msg.as_slice());
28282829
}
28292830
Some(_) | None => {}
28302831
}
@@ -2845,9 +2846,10 @@ impl<'a> Resolver<'a> {
28452846
match *name_bindings.value_def.borrow() {
28462847
None => {}
28472848
Some(ref value) => {
2848-
self.session.span_err(import_span,
2849-
"import conflicts with value \
2850-
in this module");
2849+
let msg = format!("import `{}` conflicts with value \
2850+
in this module",
2851+
token::get_name(name).get());
2852+
self.session.span_err(import_span, msg.as_slice());
28512853
match value.value_span {
28522854
None => {}
28532855
Some(span) => {
@@ -2867,9 +2869,10 @@ impl<'a> Resolver<'a> {
28672869
match *name_bindings.type_def.borrow() {
28682870
None => {}
28692871
Some(ref ty) => {
2870-
self.session.span_err(import_span,
2871-
"import conflicts with type in \
2872-
this module");
2872+
let msg = format!("import `{}` conflicts with type in \
2873+
this module",
2874+
token::get_name(name).get());
2875+
self.session.span_err(import_span, msg.as_slice());
28732876
match ty.type_span {
28742877
None => {}
28752878
Some(span) => {

src/test/compile-fail/resolve-conflict-import-vs-extern-crate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::slice as std; //~ ERROR import conflicts with imported crate
11+
use std::slice as std; //~ ERROR import `std` conflicts with imported crate
1212

1313
fn main() {
1414
}

src/test/compile-fail/resolve-conflict-item-vs-import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use std::mem::transmute;
12-
//~^ ERROR import conflicts with value in this module
12+
//~^ ERROR import `transmute` conflicts with value in this module
1313

1414
fn transmute() {}
1515

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2014 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+
use std::slice::Items;
12+
//~^ ERROR import `Items` conflicts with type in this module
13+
14+
struct Items;
15+
16+
fn main() {
17+
}
18+

0 commit comments

Comments
 (0)