Remove 'static requirement on try_as_dyn#150161
Remove 'static requirement on try_as_dyn#150161oli-obk wants to merge 2 commits intorust-lang:mainfrom
Conversation
|
r? @SparrowLii rustbot has assigned @SparrowLii. Use |
This comment has been minimized.
This comment has been minimized.
e7ef1ee to
29f1dba
Compare
|
r? BoxyUwU |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
29f1dba to
fe33b0c
Compare
This comment has been minimized.
This comment has been minimized.
dfa5c33 to
30f5641
Compare
This comment has been minimized.
This comment has been minimized.
|
The hacky solution is obviously not a general fix. But I think it's progress. As a next step I will add the input type as a generic parameter on |
This comment was marked as resolved.
This comment was marked as resolved.
d2cc847 to
c6abcad
Compare
This comment has been minimized.
This comment has been minimized.
|
Thanks @danielhenrymantilla for writing down this summary. I haven't addressed the concern about the restriction yet, but I included your summary mostly verbatim in the unstable book |
This comment has been minimized.
This comment has been minimized.
|
|
||
| ### Each trait `where` bound with an associated type equality (`Type: Trait<Assoc = Type2>`) does not mention lifetime-infected parameters. | ||
|
|
||
| Checking whether `Option<&'? str>: IntoIterator<Item = &'static str>` holds discriminates `'?` against `'static`. |
There was a problem hiding this comment.
This would already run into the "no 'static rule". I'm unsure if this rule is needed or not.
There was a problem hiding this comment.
Very true, let's go with the following example, then:
impl<'a, 'b> Trait<'b> for &'a str
where
Option<&'a str>: IntoIterator<Item = &'b str>,
{}which amounts to having done:
impl<'a> Trait<'a> for &'a str {}which brings us back to "no repetitions in header" (&'? str: Trait<'static> discriminates '? against 'static).
| Checking whether `Option<&'? str>: IntoIterator<Item = &'static str>` holds discriminates `'?` against `'static`. | |
| Associated-type equality bounds can very much amount to lifetime-infected parameter equality constraints, which are problematic as per the "at most one mention of each lifetime-infected parameter in header" rule. | |
| To illustrate, with the following definitions, `&'? str: Trait<'static>` discriminates `'?` against `'static`: | |
| ```rust | |
| impl<'a, 'b> Trait<'b> for &'a str | |
| where | |
| // &'a str = &'b str, | |
| Option<&'a str>: IntoIterator<Item = &'b str>, | |
| {} | |
| impl<'a> Trait<'a> for &'a str {} | |
| ``` |
|
|
||
| The most obvious one: if you have `impl IsStatic for &'static str`, then determining whether `&'? str : IsStatic` does hold amounts to discriminating `'? : 'static`. | ||
|
|
||
| ### Each outlives `where` bound (`Type: 'a` and `'a: 'b`) does not mention lifetime-infected parameters. |
There was a problem hiding this comment.
This page doesn't define "lifetime-infected parameter" anywhere.
This comment has been minimized.
This comment has been minimized.
|
This PR's I'm unsure whether The following code performs a use-after-free with this PR. #![feature(type_info, ptr_metadata, arbitrary_self_types_pointers)]
use std::{
any::TypeId,
ptr::{self, DynMetadata},
};
type Payload = Box<i32>;
trait Trait {
type Assoc;
fn method(self: *const Self, value: Self::Assoc) -> &'static Payload;
}
struct Thing;
impl Trait for Thing {
type Assoc = &'static Payload;
fn method(self: *const Self, value: Self::Assoc) -> &'static Payload {
value
}
}
fn extend<'a>(payload: &'a Payload) -> &'static Payload {
let metadata: DynMetadata<dyn Trait<Assoc = &'a Payload>> = const {
TypeId::of::<Thing>()
.trait_info_of::<dyn Trait<Assoc = &'a Payload>>()
.unwrap()
.get_vtable()
};
let ptr: *const dyn Trait<Assoc = &'a Payload> =
ptr::from_raw_parts(std::ptr::null::<()>(), metadata);
ptr.method(payload)
}
fn main() {
let payload: Box<Payload> = Box::new(Box::new(1i32));
let wrong: &'static Payload = extend(&*payload);
drop(payload);
println!("{wrong}");
}Potential solutions include:
|
hmm... and desugar |
ae17524 to
ceb4679
Compare
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ceb4679 to
9aba3c3
Compare
This comment has been minimized.
This comment has been minimized.
9aba3c3 to
a85463d
Compare
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
a85463d to
0b2da7a
Compare
This comment has been minimized.
This comment has been minimized.
0b2da7a to
676173f
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
676173f to
67f7c3d
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
View all comments
tracking issue: #144361
cc @ivarflakstad @izagawd