Skip to content

Commit 74648b5

Browse files
committed
First attempt at fixing rust-lang#20591
This isn't quite right, but it's interesting.
1 parent f9e53c7 commit 74648b5

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,17 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
903903
},
904904
&token::get_name(name));
905905
span_err!(self.resolver.session, import_span, E0252, "{}", &msg[..]);
906+
if let Some(sp) = target.bindings.span_for_namespace(namespace) {
907+
span_note!(self.resolver.session, sp,
908+
"first import of {} `{}` here",
909+
match namespace {
910+
TypeNS => "type",
911+
ValueNS => "value",
912+
},
913+
token::get_name(name));
914+
} else {
915+
span_note!(self.resolver.session, import_span, "I can't find where it was previously imported");
916+
}
906917
}
907918
Some(_) | None => {}
908919
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2013 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+
#![feature(no_std)]
11+
#![no_std]
12+
13+
14+
mod sub1 {
15+
fn foo() {} // Implementation 1
16+
}
17+
18+
mod sub2 {
19+
fn foo() {} // Implementation 2
20+
}
21+
22+
use sub1::foo; //~ NOTE first imported here
23+
use sub2::foo; //~ ERROR a value named `foo` has already been imported in this module [E0252]
24+
25+
fn main() {}

0 commit comments

Comments
 (0)