Restore the coherence visitor and fix fallouts
This commit is contained in:
parent
3343e9c169
commit
d021c55fb9
5 changed files with 42 additions and 4 deletions
|
@ -17,12 +17,18 @@ use middle::infer::{self, new_infer_ctxt};
|
|||
use syntax::ast::{DefId};
|
||||
use syntax::ast::{LOCAL_CRATE};
|
||||
use syntax::ast;
|
||||
use syntax::ast_util;
|
||||
use syntax::visit;
|
||||
use syntax::codemap::Span;
|
||||
use util::ppaux::Repr;
|
||||
|
||||
pub fn check(tcx: &ty::ctxt) {
|
||||
let overlap = OverlapChecker { tcx: tcx };
|
||||
let mut overlap = OverlapChecker { tcx: tcx };
|
||||
overlap.check_for_overlapping_impls();
|
||||
|
||||
// this secondary walk specifically checks for impls of defaulted
|
||||
// traits, for which additional overlap rules exist
|
||||
visit::walk_crate(&mut overlap, tcx.map.krate());
|
||||
}
|
||||
|
||||
struct OverlapChecker<'cx, 'tcx:'cx> {
|
||||
|
@ -122,3 +128,33 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
|
|||
self.tcx.map.span(impl_did.node)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'cx, 'tcx,'v> visit::Visitor<'v> for OverlapChecker<'cx, 'tcx> {
|
||||
fn visit_item(&mut self, item: &'v ast::Item) {
|
||||
match item.node {
|
||||
ast::ItemDefaultImpl(_, _) => {
|
||||
let impl_def_id = ast_util::local_def(item.id);
|
||||
match ty::impl_trait_ref(self.tcx, impl_def_id) {
|
||||
Some(ref trait_ref) => {
|
||||
match ty::trait_default_impl(self.tcx, trait_ref.def_id) {
|
||||
Some(other_impl) if other_impl != impl_def_id => {
|
||||
self.report_overlap_error(trait_ref.def_id,
|
||||
other_impl,
|
||||
impl_def_id);
|
||||
}
|
||||
Some(_) => {}
|
||||
None => {
|
||||
self.tcx.sess.bug(
|
||||
&format!("no default implementation recorded for `{:?}`",
|
||||
item)[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,4 @@ impl MyTrait for .. {}
|
|||
impl MyTrait for .. {}
|
||||
//~^ ERROR conflicting implementations for trait `MyTrait`
|
||||
|
||||
impl MyTrait for (i32, i32) {}
|
||||
//~^ ERROR implementations for traits providing default implementations are only allowed on
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -34,6 +34,7 @@ unsafe impl Send for [MyType] {}
|
|||
|
||||
unsafe impl Send for &'static [NotSync] {}
|
||||
//~^ ERROR builtin traits can only be implemented on structs or enums
|
||||
//~^^ ERROR conflicting implementations for trait `core::marker::Send`
|
||||
|
||||
fn is_send<T: Send>() {}
|
||||
|
||||
|
|
|
@ -47,4 +47,7 @@ fn main() {
|
|||
//~^^^^ ERROR overflow evaluating
|
||||
//~^^^^^ NOTE consider adding a `#![recursion_limit="20"]` attribute to your crate
|
||||
//~^^^^^^ NOTE required by `is_send`
|
||||
//~^^^^^^^ ERROR overflow evaluating
|
||||
//~^^^^^^^^ NOTE consider adding a `#![recursion_limit="20"]` attribute to your crate
|
||||
//~^^^^^^^^^ NOTE required by `is_send`
|
||||
}
|
||||
|
|
|
@ -29,4 +29,5 @@ impl Signed for i32 { }
|
|||
fn main() {
|
||||
is_defaulted::<&'static i32>();
|
||||
is_defaulted::<&'static u32>();
|
||||
//~^ ERROR the trait `Signed` is not implemented for the type `u32`
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue