1
Fork 0

Auto merge of #24818 - tbelaire:double-import, r=nrc

This isn't quite right, but it's interesting.
This commit is contained in:
bors 2015-05-12 08:54:40 +00:00
commit feac9f1c7b
2 changed files with 46 additions and 12 deletions

View file

@ -618,7 +618,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
namespace_name, namespace_name,
name_bindings.def_for_namespace(namespace)); name_bindings.def_for_namespace(namespace));
self.check_for_conflicting_import( self.check_for_conflicting_import(
&import_resolution.target_for_namespace(namespace), &import_resolution,
directive.span, directive.span,
target, target,
namespace); namespace);
@ -755,7 +755,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
// Continue. // Continue.
} }
Some(ref value_target) => { Some(ref value_target) => {
self.check_for_conflicting_import(&dest_import_resolution.value_target, self.check_for_conflicting_import(&dest_import_resolution,
import_directive.span, import_directive.span,
*ident, *ident,
ValueNS); ValueNS);
@ -767,7 +767,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
// Continue. // Continue.
} }
Some(ref type_target) => { Some(ref type_target) => {
self.check_for_conflicting_import(&dest_import_resolution.type_target, self.check_for_conflicting_import(&dest_import_resolution,
import_directive.span, import_directive.span,
*ident, *ident,
TypeNS); TypeNS);
@ -887,24 +887,31 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
/// Checks that imported names and items don't have the same name. /// Checks that imported names and items don't have the same name.
fn check_for_conflicting_import(&mut self, fn check_for_conflicting_import(&mut self,
target: &Option<Target>, import_resolution: &ImportResolution,
import_span: Span, import_span: Span,
name: Name, name: Name,
namespace: Namespace) { namespace: Namespace) {
let target = import_resolution.target_for_namespace(namespace);
debug!("check_for_conflicting_import: {}; target exists: {}", debug!("check_for_conflicting_import: {}; target exists: {}",
&token::get_name(name), &token::get_name(name),
target.is_some()); target.is_some());
match *target { match target {
Some(ref target) if target.shadowable != Shadowable::Always => { Some(ref target) if target.shadowable != Shadowable::Always => {
let msg = format!("a {} named `{}` has already been imported \ let ns_word = match namespace {
in this module", TypeNS => "type",
match namespace { ValueNS => "value",
TypeNS => "type", };
ValueNS => "value", span_err!(self.resolver.session, import_span, E0252,
}, "a {} named `{}` has already been imported \
in this module", ns_word,
&token::get_name(name)); &token::get_name(name));
span_err!(self.resolver.session, import_span, E0252, "{}", &msg[..]); let use_id = import_resolution.id(namespace);
let item = self.resolver.ast_map.expect_item(use_id);
// item is syntax::ast::Item;
span_note!(self.resolver.session, item.span,
"previous import of `{}` here",
token::get_name(name));
} }
Some(_) | None => {} Some(_) | None => {}
} }

View file

@ -0,0 +1,27 @@
// Copyright 2015 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.
#![feature(no_std)]
#![no_std]
// This tests that conflicting imports shows both `use` lines
// when reporting the error.
mod sub1 {
fn foo() {} // implementation 1
}
mod sub2 {
fn foo() {} // implementation 2
}
use sub1::foo; //~ NOTE previous import of `foo` here
use sub2::foo; //~ ERROR a value named `foo` has already been imported in this module [E0252]
fn main() {}