-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Opaque types' generic params do not imply anything about their hidden type's lifetimes #98933
Opaque types' generic params do not imply anything about their hidden type's lifetimes #98933
Conversation
r? @cjgillot (rust-highfive has picked a reviewer for you, use r? to override) |
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.
Looks good. Thanks!
I'm thinking if we should consider forcing the hidden type to constrain all generic params of the type alias in TAIT. If so, we won't have such weird differences between opaque types Adt
s. I'll discuss it further in a zulip stream https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/generic.20TAIT.20problems/near/286519266
r? rust-lang/types |
don't fully understand whether this is the correct fix, not sure whether #97104 has a meaningful relation to impl trait 😅 the ub here doesn't rely on impl trait at all. trait Foo<ARG: 'static>: 'static {
type Assoc: AsRef<str>;
}
fn hr_shit<T: ?Sized, ARG>(x: T::Assoc) -> Box<dyn AsRef<str> + 'static>
where
T: Foo<ARG>
{
Box::new(x)
}
fn extend_lt<'a>(x: &'a str) -> Box<dyn AsRef<str> + 'static> {
type DynTrait = dyn for<'a> Foo<&'a str, Assoc = &'a str>;
hr_shit::<DynTrait, _>(x)
}
fn main() {
let extended = extend_lt(&String::from("hello"));
println!("{}", extended.as_ref().as_ref());
} I think we already have an issue for this? edit: I think that's #44454 |
☔ The latest upstream changes (presumably #98206) made this pull request unmergeable. Please resolve the merge conflicts. |
@lcnr I believe the your reduced example is a separate problem, completely orthogonal to the one in hand. The type Meanwhile, the type from your example |
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.
seems good, so after my nits are dealt with, r=me
| | ||
LL | type MalformedTy = dyn for<'a> Callable<Gal<&'a ()>, Output = &'a str>; | ||
| ^^^^^^^^^^^^^^^^ | ||
|
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.
why is the note "lifetimes appearing in an associated type are not considered constrained" not emitted here?
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.
We're not checking for higher kinded lifetimes in the diagnostic, we're just checking for names. It would be a larger refactoring to handle the difference between lifetimes on the type alias and lifetimes in a binder.
08441cb
to
64d11fc
Compare
@bors r=lcnr |
…times, r=lcnr Opaque types' generic params do not imply anything about their hidden type's lifetimes fixes rust-lang#97104 cc `@aliemjay`
…times, r=lcnr Opaque types' generic params do not imply anything about their hidden type's lifetimes fixes rust-lang#97104 cc ``@aliemjay``
Rollup of 7 pull requests Successful merges: - rust-lang#98933 (Opaque types' generic params do not imply anything about their hidden type's lifetimes) - rust-lang#101041 (translations(rustc_session): migrates rustc_session to use SessionDiagnostic - Pt. 2) - rust-lang#101424 (Adjust and slightly generalize operator error suggestion) - rust-lang#101496 (Allow lower_lifetime_binder receive a closure) - rust-lang#101501 (Allow lint passes to be bound by `TyCtxt`) - rust-lang#101515 (Recover from typo where == is used in place of =) - rust-lang#101545 (Remove unnecessary `PartialOrd` and `Ord`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 7 pull requests Successful merges: - rust-lang#98933 (Opaque types' generic params do not imply anything about their hidden type's lifetimes) - rust-lang#101041 (translations(rustc_session): migrates rustc_session to use SessionDiagnostic - Pt. 2) - rust-lang#101424 (Adjust and slightly generalize operator error suggestion) - rust-lang#101496 (Allow lower_lifetime_binder receive a closure) - rust-lang#101501 (Allow lint passes to be bound by `TyCtxt`) - rust-lang#101515 (Recover from typo where == is used in place of =) - rust-lang#101545 (Remove unnecessary `PartialOrd` and `Ord`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
fixes #97104
cc @aliemjay