-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try to normalize associated types before processing obligations #90887
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another optimization here might be to not
return
ifobligations.is_empty()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we always will have at least one obligation because we push one on the next line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but if that's the only obligation (and we have no nested obligations that we need to check due to the normalization), then we can just update
obligation.predicate = predicate
like the shallow-resolve code above*.*edit = above, not below