Skip to content

Commit d021c55

Browse files
committed
Restore the coherence visitor and fix fallouts
1 parent 3343e9c commit d021c55

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

src/librustc_typeck/coherence/overlap.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ use middle::infer::{self, new_infer_ctxt};
1717
use syntax::ast::{DefId};
1818
use syntax::ast::{LOCAL_CRATE};
1919
use syntax::ast;
20+
use syntax::ast_util;
21+
use syntax::visit;
2022
use syntax::codemap::Span;
2123
use util::ppaux::Repr;
2224

2325
pub fn check(tcx: &ty::ctxt) {
24-
let overlap = OverlapChecker { tcx: tcx };
26+
let mut overlap = OverlapChecker { tcx: tcx };
2527
overlap.check_for_overlapping_impls();
28+
29+
// this secondary walk specifically checks for impls of defaulted
30+
// traits, for which additional overlap rules exist
31+
visit::walk_crate(&mut overlap, tcx.map.krate());
2632
}
2733

2834
struct OverlapChecker<'cx, 'tcx:'cx> {
@@ -122,3 +128,33 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
122128
self.tcx.map.span(impl_did.node)
123129
}
124130
}
131+
132+
133+
impl<'cx, 'tcx,'v> visit::Visitor<'v> for OverlapChecker<'cx, 'tcx> {
134+
fn visit_item(&mut self, item: &'v ast::Item) {
135+
match item.node {
136+
ast::ItemDefaultImpl(_, _) => {
137+
let impl_def_id = ast_util::local_def(item.id);
138+
match ty::impl_trait_ref(self.tcx, impl_def_id) {
139+
Some(ref trait_ref) => {
140+
match ty::trait_default_impl(self.tcx, trait_ref.def_id) {
141+
Some(other_impl) if other_impl != impl_def_id => {
142+
self.report_overlap_error(trait_ref.def_id,
143+
other_impl,
144+
impl_def_id);
145+
}
146+
Some(_) => {}
147+
None => {
148+
self.tcx.sess.bug(
149+
&format!("no default implementation recorded for `{:?}`",
150+
item)[]);
151+
}
152+
}
153+
}
154+
_ => {}
155+
}
156+
}
157+
_ => {}
158+
}
159+
}
160+
}

src/test/compile-fail/coherence-default-trait-impl.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,4 @@ impl MyTrait for .. {}
2121
impl MyTrait for .. {}
2222
//~^ ERROR conflicting implementations for trait `MyTrait`
2323

24-
impl MyTrait for (i32, i32) {}
25-
//~^ ERROR implementations for traits providing default implementations are only allowed on
26-
2724
fn main() {}

src/test/compile-fail/coherence-impls-builtin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ unsafe impl Send for [MyType] {}
3434

3535
unsafe impl Send for &'static [NotSync] {}
3636
//~^ ERROR builtin traits can only be implemented on structs or enums
37+
//~^^ ERROR conflicting implementations for trait `core::marker::Send`
3738

3839
fn is_send<T: Send>() {}
3940

src/test/compile-fail/recursion_limit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ fn main() {
4747
//~^^^^ ERROR overflow evaluating
4848
//~^^^^^ NOTE consider adding a `#![recursion_limit="20"]` attribute to your crate
4949
//~^^^^^^ NOTE required by `is_send`
50+
//~^^^^^^^ ERROR overflow evaluating
51+
//~^^^^^^^^ NOTE consider adding a `#![recursion_limit="20"]` attribute to your crate
52+
//~^^^^^^^^^ NOTE required by `is_send`
5053
}

src/test/compile-fail/typeck-default-trait-impl-precedence.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ impl Signed for i32 { }
2929
fn main() {
3030
is_defaulted::<&'static i32>();
3131
is_defaulted::<&'static u32>();
32+
//~^ ERROR the trait `Signed` is not implemented for the type `u32`
3233
}

0 commit comments

Comments
 (0)