Skip to content

Commit 1ef14d9

Browse files
committed
Auto merge of #26358 - nham:fix_24081, r=alexcrichton
Previously, it said "import `Foo` conflicts with existing submodule" even when it was a type alias, enum, or trait. The message now says the conflict is with "type in this module" in the case of the first two, and "trait in this module" for the last one. Fixes #24081.
2 parents 941af7b + 0c22cd7 commit 1ef14d9

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/librustc_resolve/resolve_imports.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use self::ImportDirectiveSubclass::*;
1212

1313
use DefModifiers;
1414
use Module;
15+
use ModuleKind;
1516
use Namespace::{self, TypeNS, ValueNS};
1617
use NameBindings;
1718
use NamespaceResult::{BoundResult, UnboundResult, UnknownResult};
@@ -980,10 +981,14 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
980981
match import_resolution.type_target {
981982
Some(ref target) if target.shadowable != Shadowable::Always => {
982983
if let Some(ref ty) = *name_bindings.type_def.borrow() {
983-
let (what, note) = if ty.module_def.is_some() {
984-
("existing submodule", "note conflicting module here")
985-
} else {
986-
("type in this module", "note conflicting type here")
984+
let (what, note) = match ty.module_def {
985+
Some(ref module)
986+
if module.kind.get() == ModuleKind::NormalModuleKind =>
987+
("existing submodule", "note conflicting module here"),
988+
Some(ref module)
989+
if module.kind.get() == ModuleKind::TraitModuleKind =>
990+
("trait in this module", "note conflicting trait here"),
991+
_ => ("type in this module", "note conflicting type here"),
987992
};
988993
span_err!(self.resolver.session, import_span, E0256,
989994
"import `{}` conflicts with {}",

src/test/compile-fail/issue-24081.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 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::ops::Add; //~ ERROR import `Add` conflicts with type in this module
12+
use std::ops::Sub; //~ ERROR import `Sub` conflicts with type in this module
13+
use std::ops::Mul; //~ ERROR import `Mul` conflicts with type in this module
14+
use std::ops::Div; //~ ERROR import `Div` conflicts with existing submodule
15+
use std::ops::Rem; //~ ERROR import `Rem` conflicts with trait in this module
16+
17+
type Add = bool;
18+
struct Sub { x: f32 }
19+
enum Mul { A, B }
20+
mod Div { }
21+
trait Rem { }
22+
23+
fn main() {}

0 commit comments

Comments
 (0)