Change inherent overlap error to a warning for now, to ease the breakage.

This commit is contained in:
Aaron Turon
2016-03-17 09:05:24 -07:00
parent abb1515c53
commit e477703bbf
4 changed files with 30 additions and 16 deletions
+8 -1
View File
@@ -154,6 +154,12 @@
"transmute from function item type to pointer-sized type erroneously allowed"
}
declare_lint! {
pub OVERLAPPING_INHERENT_IMPLS,
Warn,
"two overlapping inherent impls define an item with the same name were erroneously allowed"
}
/// Does nothing as a lint pass, but registers some `Lint`s
/// which are used by other parts of the compiler.
#[derive(Copy, Clone)]
@@ -184,7 +190,8 @@ fn get_lints(&self) -> LintArray {
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
CONST_ERR,
RAW_POINTER_DERIVE,
TRANSMUTE_FROM_FN_ITEM_TYPES
TRANSMUTE_FROM_FN_ITEM_TYPES,
OVERLAPPING_INHERENT_IMPLS
)
}
}
+4
View File
@@ -175,6 +175,10 @@ macro_rules! add_lint_group {
id: LintId::of(TRANSMUTE_FROM_FN_ITEM_TYPES),
reference: "issue #19925 <https://github.com/rust-lang/rust/issues/19925>",
},
FutureIncompatibleInfo {
id: LintId::of(OVERLAPPING_INHERENT_IMPLS),
reference: "issue #22889 <https://github.com/rust-lang/rust/issues/22889>",
},
]);
// We have one lint pass defined specially
+7 -11
View File
@@ -18,11 +18,11 @@
use middle::infer;
use middle::ty::{self, TyCtxt};
use syntax::ast;
use syntax::codemap::Span;
use rustc::dep_graph::DepNode;
use rustc_front::hir;
use rustc_front::intravisit;
use util::nodemap::DefIdMap;
use lint;
pub fn check(tcx: &TyCtxt) {
let mut overlap = OverlapChecker { tcx: tcx,
@@ -41,11 +41,6 @@ struct OverlapChecker<'cx, 'tcx:'cx> {
}
impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
fn span_of_def_id(&self, did: DefId) -> Span {
let node_id = self.tcx.map.as_local_node_id(did).unwrap();
self.tcx.map.span(node_id)
}
fn check_for_common_items_in_impls(&self, impl1: DefId, impl2: DefId) {
#[derive(Copy, Clone, PartialEq)]
enum Namespace { Type, Value }
@@ -68,11 +63,12 @@ fn name_and_namespace(tcx: &TyCtxt, item: &ty::ImplOrTraitItemId)
for item2 in &impl_items[&impl2] {
if (name, namespace) == name_and_namespace(&self.tcx, item2) {
let mut err = super::report_duplicate_item(
&self.tcx, self.span_of_def_id(item1.def_id()), name);
span_note!(&mut err, self.span_of_def_id(item2.def_id()),
"conflicting definition is here:");
err.emit();
let msg = format!("duplicate definitions with name `{}`", name);
let node_id = self.tcx.map.as_local_node_id(item1.def_id()).unwrap();
self.tcx.sess.add_lint(lint::builtin::OVERLAPPING_INHERENT_IMPLS,
node_id,
self.tcx.span_of_impl(item1.def_id()).unwrap(),
msg);
}
}
}
+11 -4
View File
@@ -11,10 +11,14 @@
// Test that you cannot define items with the same name in overlapping inherent
// impl blocks.
#![feature(rustc_attrs)]
#![allow(dead_code)]
struct Foo;
impl Foo {
fn id() {} //~ ERROR E0201
fn id() {} //~ WARN duplicate definitions
//~^ WARN previously accepted
}
impl Foo {
@@ -24,7 +28,8 @@ fn id() {}
struct Bar<T>(T);
impl<T> Bar<T> {
fn bar(&self) {} //~ ERROR E0201
fn bar(&self) {} //~ WARN duplicate definitions
//~^ WARN previously accepted
}
impl Bar<u32> {
@@ -34,11 +39,13 @@ fn bar(&self) {}
struct Baz<T>(T);
impl<T: Copy> Baz<T> {
fn baz(&self) {} //~ ERROR E0201
fn baz(&self) {} //~ WARN duplicate definitions
//~^ WARN previously accepted
}
impl<T> Baz<Vec<T>> {
fn baz(&self) {}
}
fn main() {}
#[rustc_error]
fn main() {} //~ ERROR compilation successful