Skip to content

Commit fc9e1d0

Browse files
committed
Auto merge of #32309 - aturon:overlap-warning, r=nikomatsakis
Change inherent overlap error to a warning for now, to ease the breakage Closes #32247 r? @nikomatsakis
2 parents 24bb607 + e477703 commit fc9e1d0

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

src/librustc/lint/builtin.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ declare_lint! {
154154
"transmute from function item type to pointer-sized type erroneously allowed"
155155
}
156156

157+
declare_lint! {
158+
pub OVERLAPPING_INHERENT_IMPLS,
159+
Warn,
160+
"two overlapping inherent impls define an item with the same name were erroneously allowed"
161+
}
162+
157163
/// Does nothing as a lint pass, but registers some `Lint`s
158164
/// which are used by other parts of the compiler.
159165
#[derive(Copy, Clone)]
@@ -184,7 +190,8 @@ impl LintPass for HardwiredLints {
184190
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
185191
CONST_ERR,
186192
RAW_POINTER_DERIVE,
187-
TRANSMUTE_FROM_FN_ITEM_TYPES
193+
TRANSMUTE_FROM_FN_ITEM_TYPES,
194+
OVERLAPPING_INHERENT_IMPLS
188195
)
189196
}
190197
}

src/librustc_lint/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
175175
id: LintId::of(TRANSMUTE_FROM_FN_ITEM_TYPES),
176176
reference: "issue #19925 <https://github.com/rust-lang/rust/issues/19925>",
177177
},
178+
FutureIncompatibleInfo {
179+
id: LintId::of(OVERLAPPING_INHERENT_IMPLS),
180+
reference: "issue #22889 <https://github.com/rust-lang/rust/issues/22889>",
181+
},
178182
]);
179183

180184
// We have one lint pass defined specially

src/librustc_typeck/coherence/overlap.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ use middle::traits::{self, ProjectionMode};
1818
use middle::infer;
1919
use middle::ty::{self, TyCtxt};
2020
use syntax::ast;
21-
use syntax::codemap::Span;
2221
use rustc::dep_graph::DepNode;
2322
use rustc_front::hir;
2423
use rustc_front::intravisit;
2524
use util::nodemap::DefIdMap;
25+
use lint;
2626

2727
pub fn check(tcx: &TyCtxt) {
2828
let mut overlap = OverlapChecker { tcx: tcx,
@@ -41,11 +41,6 @@ struct OverlapChecker<'cx, 'tcx:'cx> {
4141
}
4242

4343
impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
44-
fn span_of_def_id(&self, did: DefId) -> Span {
45-
let node_id = self.tcx.map.as_local_node_id(did).unwrap();
46-
self.tcx.map.span(node_id)
47-
}
48-
4944
fn check_for_common_items_in_impls(&self, impl1: DefId, impl2: DefId) {
5045
#[derive(Copy, Clone, PartialEq)]
5146
enum Namespace { Type, Value }
@@ -68,11 +63,12 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
6863

6964
for item2 in &impl_items[&impl2] {
7065
if (name, namespace) == name_and_namespace(&self.tcx, item2) {
71-
let mut err = super::report_duplicate_item(
72-
&self.tcx, self.span_of_def_id(item1.def_id()), name);
73-
span_note!(&mut err, self.span_of_def_id(item2.def_id()),
74-
"conflicting definition is here:");
75-
err.emit();
66+
let msg = format!("duplicate definitions with name `{}`", name);
67+
let node_id = self.tcx.map.as_local_node_id(item1.def_id()).unwrap();
68+
self.tcx.sess.add_lint(lint::builtin::OVERLAPPING_INHERENT_IMPLS,
69+
node_id,
70+
self.tcx.span_of_impl(item1.def_id()).unwrap(),
71+
msg);
7672
}
7773
}
7874
}

src/test/compile-fail/inherent-overlap.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
// Test that you cannot define items with the same name in overlapping inherent
1212
// impl blocks.
1313

14+
#![feature(rustc_attrs)]
15+
#![allow(dead_code)]
16+
1417
struct Foo;
1518

1619
impl Foo {
17-
fn id() {} //~ ERROR E0201
20+
fn id() {} //~ WARN duplicate definitions
21+
//~^ WARN previously accepted
1822
}
1923

2024
impl Foo {
@@ -24,7 +28,8 @@ impl Foo {
2428
struct Bar<T>(T);
2529

2630
impl<T> Bar<T> {
27-
fn bar(&self) {} //~ ERROR E0201
31+
fn bar(&self) {} //~ WARN duplicate definitions
32+
//~^ WARN previously accepted
2833
}
2934

3035
impl Bar<u32> {
@@ -34,11 +39,13 @@ impl Bar<u32> {
3439
struct Baz<T>(T);
3540

3641
impl<T: Copy> Baz<T> {
37-
fn baz(&self) {} //~ ERROR E0201
42+
fn baz(&self) {} //~ WARN duplicate definitions
43+
//~^ WARN previously accepted
3844
}
3945

4046
impl<T> Baz<Vec<T>> {
4147
fn baz(&self) {}
4248
}
4349

44-
fn main() {}
50+
#[rustc_error]
51+
fn main() {} //~ ERROR compilation successful

0 commit comments

Comments
 (0)