-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
leak_check in rustc_const_eval::util::relate_types
#155883
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is more of a const-eval interpreter problem than a transmute problem so IMO putting it in the "consts/const-eval" folder makes more sense. Or at least have "const" somewhere in the name so that it gets picked up by |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //@ check-pass | ||
|
|
||
| // Regression test for #155477. We previously didn't detect higher-ranked region | ||
| // errors when checking whether types are equal in `rustc_const_eval::relate_types`, that | ||
| // then caused us to trigger an assert that equal types have the same layout. | ||
|
|
||
| use std::mem::transmute; | ||
|
|
||
| type F1 = for<'a> fn(&'a ()); | ||
| type F2 = fn(&'static ()); | ||
|
|
||
| trait Trait { | ||
| type Assoc; | ||
| } | ||
|
|
||
| impl Trait for F1 { | ||
| type Assoc = i64; | ||
| } | ||
| #[expect(coherence_leak_check)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do...?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it expects the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, your fix makes this code emit a lint (#56105). That doesn't seem to make much sense but 🤷 sure whatever. |
||
| impl Trait for F2 { | ||
| type Assoc = [i32; 2]; | ||
| } | ||
|
|
||
| struct Thing<T: Trait>(T::Assoc); | ||
|
|
||
| const fn foo(x: Thing<F1>) -> Thing<F2> { | ||
| // This transmute is legal: The two types have the same size. | ||
| unsafe { transmute(x) } | ||
| } | ||
|
|
||
| fn main() { | ||
| const { foo(Thing(1i64)); } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
View changes since the review