Skip to content

Commit 3a01614

Browse files
committed
---
yaml --- r: 273159 b: refs/heads/beta c: 386f8ee h: refs/heads/master i: 273157: 483068d 273155: 141e97b 273151: 2e9fba5
1 parent 5255f84 commit 3a01614

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 2651f8c14748bf4598841471329ca260f5860ec0
26+
refs/heads/beta: 386f8eefc0a0775b228740cc5f682b6d10050e04
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc/middle/traits/specialize/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub struct Overlap<'a, 'tcx: 'a> {
4141
/// Given a subst for the requested impl, translate it to a subst
4242
/// appropriate for the actual item definition (whether it be in that impl,
4343
/// a parent impl, or the trait).
44+
//
4445
// When we have selected one impl, but are actually using item definitions from
4546
// a parent impl providing a default, we need a way to translate between the
4647
// type parameters of the two impls. Here the `source_impl` is the one we've
@@ -153,6 +154,11 @@ pub fn specializes(tcx: &ty::ctxt, impl1_def_id: DefId, impl2_def_id: DefId) ->
153154
//
154155
// See RFC 1210 for more details and justification.
155156

157+
// Currently we do not allow e.g. a negative impl to specialize a positive one
158+
if tcx.trait_impl_polarity(impl1_def_id) != tcx.trait_impl_polarity(impl2_def_id) {
159+
return false
160+
}
161+
156162
let mut infcx = infer::normalizing_infer_ctxt(tcx, &tcx.tables);
157163

158164
// Skiolemize impl1: we want to prove that "for all types matched by impl1,

branches/beta/src/test/compile-fail/specialization-negative-impl.rs renamed to branches/beta/src/test/compile-fail/specialization-polarity.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// Make sure specialization cannot change impl polarity
12+
1113
#![feature(optin_builtin_traits)]
1214
#![feature(specialization)]
1315

14-
struct TestType<T>(T);
16+
trait Foo {}
17+
18+
impl Foo for .. {}
19+
20+
impl<T> Foo for T {}
21+
impl !Foo for u8 {} //~ ERROR E0119
1522

16-
// TODO: nail down the rules here with @nikomatsakis
23+
trait Bar {}
1724

18-
unsafe impl<T> Send for TestType<T> {}
19-
impl !Send for TestType<u8> {}
25+
impl Bar for .. {}
2026

21-
fn assert_send<T: Send>() {}
27+
impl<T> !Bar for T {}
28+
impl Bar for u8 {} //~ ERROR E0119
2229

23-
fn main() {
24-
assert_send::<TestType<()>>();
25-
assert_send::<TestType<u8>>(); //~ ERROR
26-
}
30+
fn main() {}

0 commit comments

Comments
 (0)