-
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
unchecked region constraints for opaque types in dead code #112417
Comments
this unsoundness seems to not work for TAIT: #![feature(type_alias_impl_trait)]
trait CallMeMaybe<'a, 'b> {
fn mk() -> Self;
fn subtype<T>(self, x: &'b T) -> &'a T;
}
struct Foo<'a, 'b: 'a>(&'a (), &'b ());
impl<'a, 'b> CallMeMaybe<'a, 'b> for Foo<'a, 'b> {
fn mk() -> Self {
Foo(&(), &())
}
fn subtype<T>(self, x: &'b T) -> &'a T {
x
}
}
type Alias<'a, 'b> = impl CallMeMaybe<'a, 'b>;
fn foo<'a, 'b>() -> Alias<'a, 'b> {
panic!();
Foo(&(), &())
}
fn subtype<'a, 'b, T>(x: &'b T) -> &'a T {
let proof = Alias::mk();
proof.subtype(x)
}
fn main() {
let y = subtype(&String::from("Hello World"));
println!("{y}");
} instead results in
|
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-high |
Regression in nightly-2022-03-31:
#94081 looks like a juicy target. |
The OP example doesn't reproduce on the Playground (https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d0a7fd2fc4abe6e4ec732c1b6a28bf71). bisect-rustc says 09bc67b |
the underlying issue still exists: https://rust.godbolt.org/z/qK375cseW it seems to get covered by some changes when checking that opaque types are well-formed though. We should not have |
…ode, r=<try> Error for RPIT if they are not defined during MIR borrowck r? `@lcnr` Fixes rust-lang#112417 There are some changes in tests that we would need to properly review. I've left some comments on each of them.
edit: while this tests currently results in an error, the underying issue still exists #112417 (comment)
With the current implementation
foo
only defines the opaque type during HIR typeck and not in MIR typeck as the defining use is in dead code. HIR typeck does not check regions so we use erased regions instead. This hidden type with erased regions is then used as the actual hidden type of the RPIT because there is no hidden type defined by MIR typeck.We then never check that the RPIT is well-formed outside of HIR typeck itself, so we never check that the region constraints hold for the opaque type.
The text was updated successfully, but these errors were encountered: