-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
HRTB prevent mem::transmute and mem::MaybeUninit from working #62201
Labels
A-higher-ranked
Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)
A-traits
Area: Trait system
C-bug
Category: This is a bug.
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
jonas-schievink
added
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Jun 28, 2019
As a workaround, make a helper function to coerce the types fn help<'a, T: Ty<'a>, F>(f: &F, t: <T as Ty<'a>>::V)
where
F: Fn(<T as Ty>::V),
{
f(t)
} and swap f(item) for
|
Actually attempting to use this causes an ICE trait Ty<'a> {
type V;
}
trait SIter: for<'a> Ty<'a> {
fn f<F>(&self, f: F)
where
F: for<'r> Fn(<Self as Ty<'r>>::V);
}
struct S<I>(I);
impl<'a, I: Ty<'a>> Ty<'a> for S<I> {
type V = <I as Ty<'a>>::V;
}
impl<I: SIter, Item> SIter for S<I>
where
for<'r> S<I>: Ty<'r, V = Item>,
for<'r> I: Ty<'r, V = Item>,
{
fn f<F>(&self, f: F)
where
F: Fn(<Self as Ty>::V),
{
self.0.f(|item| help(&f, item))
}
}
fn help<'a, T: Ty<'a>, F>(f: &F, t: <T as Ty<'a>>::V)
where
F: Fn(<T as Ty>::V),
{
f(t)
}
struct AA;
impl<'a> Ty<'a> for AA {
type V = ();
}
impl SIter for AA {
fn f<F>(&self, f: F)
where
F: for<'r> Fn(<Self as Ty<'r>>::V),
{
help(&f, ())
}
}
fn main() {
S(AA).f(|_| {})
}
|
The original code seems to compile fine now. |
fmease
added
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
A-higher-ranked
Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)
labels
Sep 24, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-higher-ranked
Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)
A-traits
Area: Trait system
C-bug
Category: This is a bug.
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
The following code prevents
mem::MaybeUninit
andmem::transmute
from creating values.(Playground)
Errors:
The code works fine without any unsafe if I remove all lifetimes from it.
(Playground)
The text was updated successfully, but these errors were encountered: