Skip to content

Commit 23d652b

Browse files
committed
---
yaml --- r: 187231 b: refs/heads/try c: d021c55 h: refs/heads/master i: 187229: 394aee5 187227: c837b17 187223: 0756f5d 187215: 30a90d6 187199: 00aba5a v: v3
1 parent 88dec94 commit 23d652b

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: b4c965ee803a4521d8b4575f634e036f93e408f3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 3a96d6a9818fe2affc98a187fb1065120458cee9
5-
refs/heads/try: 3343e9c16976aabef9836e61213e64a0552ec051
5+
refs/heads/try: d021c55fb9a18b854cd70a3d67a260d4d71a14c3
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/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+
}

branches/try/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() {}

branches/try/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

branches/try/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
}

branches/try/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)