forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#90887 - jackh726:issue-90729, r=nikomatsakis
Try to normalize associated types before processing obligations Closes rust-lang#90729 r? `@nikomatsakis`
- Loading branch information
Showing
22 changed files
with
383 additions
and
216 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
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,38 @@ | ||
// check-pass | ||
|
||
#![feature(generic_associated_types)] | ||
|
||
use std::marker::PhantomData; | ||
|
||
pub trait Type { | ||
type Ref<'a>; | ||
} | ||
|
||
pub trait AsBytes {} | ||
|
||
impl AsBytes for &str {} | ||
|
||
pub struct Utf8; | ||
|
||
impl Type for Utf8 { | ||
type Ref<'a> = &'a str; | ||
} | ||
|
||
pub struct Bytes<T: Type> { | ||
_marker: PhantomData<T>, | ||
} | ||
|
||
impl<T: Type> Bytes<T> | ||
where | ||
for<'a> T::Ref<'a>: AsBytes, | ||
{ | ||
pub fn new() -> Self { | ||
Self { | ||
_marker: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
let _b = Bytes::<Utf8>::new(); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/generic-associated-types/issue-91139.migrate.stderr
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,10 @@ | ||
error[E0311]: the parameter type `T` may not live long enough | ||
--> $DIR/issue-91139.rs:27:12 | ||
| | ||
LL | fn foo<T>() { | ||
| - help: consider adding an explicit lifetime bound...: `T: 'a` | ||
LL | let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| (); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds | ||
|
||
error: aborting due to previous error | ||
|
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 @@ | ||
// check-pass | ||
|
||
#![feature(generic_associated_types)] | ||
use std::marker::PhantomData; | ||
|
||
pub struct Id<'id>(PhantomData<fn(&'id ()) -> &'id ()>); | ||
|
||
fn new_id() -> Id<'static> { | ||
Id(PhantomData) | ||
} | ||
|
||
pub trait HasLifetime where { | ||
type AtLifetime<'a>; | ||
} | ||
|
||
pub struct ExistentialLifetime<S: HasLifetime>(S::AtLifetime<'static>); | ||
|
||
impl<S: HasLifetime> ExistentialLifetime<S> { | ||
pub fn new<F>(f: F) -> ExistentialLifetime<S> | ||
where for<'id> F: FnOnce(Id<'id>) -> S::AtLifetime<'id> { | ||
ExistentialLifetime(f(new_id())) | ||
} | ||
} | ||
|
||
|
||
struct ExampleS<'id>(Id<'id>); | ||
|
||
struct ExampleMarker; | ||
|
||
impl HasLifetime for ExampleMarker { | ||
type AtLifetime<'id> = ExampleS<'id>; | ||
} | ||
|
||
|
||
fn broken0() -> ExistentialLifetime<ExampleMarker> { | ||
fn new_helper<'id>(id: Id<'id>) -> ExampleS<'id> { | ||
ExampleS(id) | ||
} | ||
|
||
ExistentialLifetime::<ExampleMarker>::new(new_helper) | ||
} | ||
|
||
fn broken1() -> ExistentialLifetime<ExampleMarker> { | ||
fn new_helper<'id>(id: Id<'id>) -> <ExampleMarker as HasLifetime>::AtLifetime<'id> { | ||
ExampleS(id) | ||
} | ||
|
||
ExistentialLifetime::<ExampleMarker>::new(new_helper) | ||
} | ||
|
||
fn broken2() -> ExistentialLifetime<ExampleMarker> { | ||
ExistentialLifetime::<ExampleMarker>::new(|id| ExampleS(id)) | ||
} | ||
|
||
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,57 @@ | ||
// check-pass | ||
|
||
#![feature(generic_associated_types)] | ||
|
||
use std::marker::PhantomData; | ||
|
||
pub trait Scalar: 'static { | ||
type RefType<'a>: ScalarRef<'a>; | ||
} | ||
|
||
pub trait ScalarRef<'a>: 'a {} | ||
|
||
impl Scalar for i32 { | ||
type RefType<'a> = i32; | ||
} | ||
|
||
impl Scalar for String { | ||
type RefType<'a> = &'a str; | ||
} | ||
|
||
impl Scalar for bool { | ||
type RefType<'a> = i32; | ||
} | ||
|
||
impl<'a> ScalarRef<'a> for bool {} | ||
|
||
impl<'a> ScalarRef<'a> for i32 {} | ||
|
||
impl<'a> ScalarRef<'a> for &'a str {} | ||
|
||
fn str_contains(a: &str, b: &str) -> bool { | ||
a.contains(b) | ||
} | ||
|
||
pub struct BinaryExpression<A: Scalar, B: Scalar, O: Scalar, F> | ||
where | ||
F: Fn(A::RefType<'_>, B::RefType<'_>) -> O, | ||
{ | ||
f: F, | ||
_phantom: PhantomData<(A, B, O)>, | ||
} | ||
|
||
impl<A: Scalar, B: Scalar, O: Scalar, F> BinaryExpression<A, B, O, F> | ||
where | ||
F: Fn(A::RefType<'_>, B::RefType<'_>) -> O, | ||
{ | ||
pub fn new(f: F) -> Self { | ||
Self { | ||
f, | ||
_phantom: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
BinaryExpression::<String, String, bool, _>::new(str_contains); | ||
} |
Oops, something went wrong.