forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make subtyping for projection types stricter. Fixes rust-lang#21726.
- Loading branch information
1 parent
bedd810
commit f1ace34
Showing
5 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![allow(unused_variables)] | ||
|
||
trait Trait<'a> { | ||
type Type; | ||
|
||
fn method(&'a self) { } | ||
} | ||
|
||
fn method1<'a,'b,T>(x: &'a T, y: &'b T) | ||
where T : for<'z> Trait<'z>, 'a : 'b | ||
{ | ||
// Note that &'static T <: &'a T. | ||
let a: <T as Trait<'a>>::Type = loop { }; | ||
let b: <T as Trait<'b>>::Type = loop { }; | ||
let _: <T as Trait<'a>>::Type = a; | ||
} | ||
|
||
fn method2<'a,'b,T>(x: &'a T, y: &'b T) | ||
where T : for<'z> Trait<'z>, 'a : 'b | ||
{ | ||
// Note that &'static T <: &'a T. | ||
let a: <T as Trait<'a>>::Type = loop { }; | ||
let b: <T as Trait<'b>>::Type = loop { }; | ||
let _: <T as Trait<'b>>::Type = a; //~ ERROR mismatched types | ||
} | ||
|
||
fn method3<'a,'b,T>(x: &'a T, y: &'b T) | ||
where T : for<'z> Trait<'z>, 'a : 'b | ||
{ | ||
// Note that &'static T <: &'a T. | ||
let a: <T as Trait<'a>>::Type = loop { }; | ||
let b: <T as Trait<'b>>::Type = loop { }; | ||
let _: <T as Trait<'a>>::Type = b; //~ ERROR mismatched types | ||
} | ||
|
||
fn method4<'a,'b,T>(x: &'a T, y: &'b T) | ||
where T : for<'z> Trait<'z>, 'a : 'b | ||
{ | ||
// Note that &'static T <: &'a T. | ||
let a: <T as Trait<'a>>::Type = loop { }; | ||
let b: <T as Trait<'b>>::Type = loop { }; | ||
let _: <T as Trait<'b>>::Type = b; | ||
} | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test that the variance computation considers types/regions that | ||
// appear in projections to be invariant. | ||
|
||
trait Trait<'a> { | ||
type Type; | ||
|
||
fn method(&'a self) { } | ||
} | ||
|
||
#[rustc_variance] | ||
struct Foo<'a, T : Trait<'a>> { //~ ERROR ItemVariances(types=[[+];[];[]], regions=[[-];[];[]]) | ||
field: (T, &'a ()) | ||
} | ||
|
||
#[rustc_variance] | ||
struct Bar<'a, T : Trait<'a>> { //~ ERROR ItemVariances(types=[[o];[];[]], regions=[[o];[];[]]) | ||
field: <T as Trait<'a>>::Type | ||
} | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Regression test for #21726: an issue arose around the rules for | ||
// subtyping of projection types that resulted in an unconstrained | ||
// region, yielding region inference failures. | ||
|
||
fn main() { } | ||
|
||
fn foo<'a>(s: &'a str) { | ||
let b: B<()> = B::new(s, ()); | ||
b.get_short(); | ||
} | ||
|
||
trait IntoRef<'a> { | ||
type T: Clone; | ||
fn into_ref(self, &'a str) -> Self::T; | ||
} | ||
|
||
impl<'a> IntoRef<'a> for () { | ||
type T = &'a str; | ||
fn into_ref(self, s: &'a str) -> &'a str { | ||
s | ||
} | ||
} | ||
|
||
struct B<'a, P: IntoRef<'a>>(P::T); | ||
|
||
impl<'a, P: IntoRef<'a>> B<'a, P> { | ||
fn new(s: &'a str, i: P) -> B<'a, P> { | ||
B(i.into_ref(s)) | ||
} | ||
|
||
fn get_short(&self) -> P::T { | ||
self.0.clone() | ||
} | ||
} |