-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 type wf check anchor usage is unsound #113278
Comments
#![feature(trivial_bounds, type_alias_impl_trait)]
mod sus {
use super::*;
pub type Sep = impl Sized + std::fmt::Display;
pub fn mk_sep() -> Sep {
String::from("hello")
}
pub trait Proj {
type Assoc;
}
impl Proj for () {
type Assoc = sus::Sep;
}
pub struct Bar<T: Proj> {
pub inner: <T as Proj>::Assoc,
pub _marker: T,
}
impl<T: Proj> Clone for Bar<T> {
fn clone(&self) -> Self {
todo!()
}
}
impl<T: Proj<Assoc = i32> + Copy> Copy for Bar<T> {}
pub type Tait = impl Copy + From<Bar<()>> + Into<Bar<()>>;
pub fn define_tait() -> Tait
where
(): Proj<Assoc = i32>,
{
Bar {
inner: 1i32,
_marker: (),
}
}
}
fn copy_tait(x: sus::Tait) -> (sus::Tait, sus::Tait) {
(x, x)
}
fn main() {
let bar = sus::Bar {
inner: sus::mk_sep(),
_marker: (),
};
let (y, z) = copy_tait(bar.into()); // copy a string
drop(y.into()); // drop one instance
println!("{}", z.into().inner); // print the other
}
The bug is as follows:
tl;dr: checking that opaque types are well-formed can define more opaques than its defining scope. These defining-uses are simply ignored however. sourcesequating the expected term of a rust/compiler/rustc_trait_selection/src/traits/project.rs Lines 288 to 293 in 1623634
we allow defining uses when checking wf and discard them in rust/compiler/rustc_borrowck/src/region_infer/opaque_types.rs Lines 305 to 309 in 1623634
rust/compiler/rustc_borrowck/src/region_infer/opaque_types.rs Lines 342 to 344 in 1623634
and the same in
|
oh, you found a way to do this! I tried and failed. I thought I had built an assertion against that, but maybe I removed it at some point. Should have left comments for myself. Originally we had a |
see the second comment for an explanation: #113278 (comment)
results in
going to minimize this further and explain why it is broken
The text was updated successfully, but these errors were encountered: