-
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
Pessimistically assume opaque types are !Freeze #113617
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![feature(type_alias_impl_trait)] | ||
|
||
//! Test that we pessimistically assume the `Drop` impl of | ||
//! a hidden type is not const. | ||
|
||
pub struct Parser<H>(H); | ||
|
||
type Tait = impl Sized; | ||
|
||
const fn constrain() -> Tait {} | ||
|
||
pub const fn take(_: Tait) {} | ||
//~^ ERROR: destructor of `Tait` cannot be evaluated at compile-time | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0493]: destructor of `Tait` cannot be evaluated at compile-time | ||
--> $DIR/const-fn-cycle-tait.rs:12:19 | ||
| | ||
LL | pub const fn take(_: Tait) {} | ||
| ^ - value is dropped here | ||
| | | ||
| the destructor for this type cannot be evaluated in constant functions | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0493`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//! Discovered in https://github.com/rust-lang/rust/issues/112602. | ||
//! This caused a cycle error, which made no sense. | ||
//! Removing the `const` part of the `many` function would make the | ||
//! test pass again. | ||
//! The issue was that we were running const qualif checks on | ||
//! `const fn`s, but never using them. During const qualif checks we tend | ||
//! to end up revealing opaque types (the RPIT in `many`'s return type), | ||
//! which can quickly lead to cycles. | ||
|
||
// check-pass | ||
|
||
pub struct Parser<H>(H); | ||
|
||
impl<H, T> Parser<H> | ||
where | ||
H: for<'a> Fn(&'a str) -> T, | ||
{ | ||
pub const fn new(handler: H) -> Parser<H> { | ||
Parser(handler) | ||
} | ||
|
||
pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> { | ||
Parser::new(|_| unimplemented!()) | ||
} | ||
} | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
error[E0493]: destructor of `Foo` cannot be evaluated at compile-time | ||
--> $DIR/const-promoted-opaque.rs:25:26 | ||
| | ||
LL | let _: &'static _ = &FOO; | ||
| ^^^ the destructor for this type cannot be evaluated in constants | ||
... | ||
LL | }; | ||
| - value is dropped here | ||
|
||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/const-promoted-opaque.rs:25:26 | ||
| | ||
LL | let _: &'static _ = &FOO; | ||
| ---------- ^^^ creates a temporary value which is freed while still in use | ||
| | | ||
| type annotation requires that borrow lasts for `'static` | ||
... | ||
LL | }; | ||
| - temporary value is freed at the end of this statement | ||
|
||
error[E0492]: constants cannot refer to interior mutable data | ||
--> $DIR/const-promoted-opaque.rs:30:19 | ||
| | ||
LL | const BAZ: &Foo = &FOO; | ||
| ^^^^ this borrow of an interior mutable value may end up in the final value | ||
|
||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/const-promoted-opaque.rs:34:26 | ||
| | ||
LL | let _: &'static _ = &FOO; | ||
| ---------- ^^^ creates a temporary value which is freed while still in use | ||
| | | ||
| type annotation requires that borrow lasts for `'static` | ||
LL | | ||
LL | } | ||
| - temporary value is freed at the end of this statement | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0492, E0493, E0716. | ||
For more information about an error, try `rustc --explain E0492`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// revisions: string unit atomic | ||
#![feature(type_alias_impl_trait)] | ||
|
||
//! Check that we do not cause cycle errors when trying to | ||
//! obtain information about interior mutability of an opaque type. | ||
//! This used to happen, because when the body-analysis failed, we | ||
//! checked the type instead, but the constant was also defining the | ||
//! hidden type of the opaque type. Thus we ended up relying on the | ||
//! result of our analysis to compute the result of our analysis. | ||
|
||
//[unit] check-pass | ||
|
||
type Foo = impl Sized; | ||
|
||
#[cfg(string)] | ||
const FOO: Foo = String::new(); | ||
|
||
#[cfg(atomic)] | ||
const FOO: Foo = std::sync::atomic::AtomicU8::new(42); | ||
|
||
#[cfg(unit)] | ||
const FOO: Foo = (); | ||
|
||
const BAR: () = { | ||
let _: &'static _ = &FOO; | ||
//[string,atomic]~^ ERROR: destructor of `Foo` cannot be evaluated at compile-time | ||
//[string,atomic]~| ERROR: temporary value dropped while borrowed | ||
}; | ||
|
||
const BAZ: &Foo = &FOO; | ||
//[string,atomic]~^ ERROR: constants cannot refer to interior mutable data | ||
|
||
fn main() { | ||
let _: &'static _ = &FOO; | ||
//[string,atomic]~^ ERROR: temporary value dropped while borrowed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
error[E0493]: destructor of `Foo` cannot be evaluated at compile-time | ||
--> $DIR/const-promoted-opaque.rs:25:26 | ||
| | ||
LL | let _: &'static _ = &FOO; | ||
| ^^^ the destructor for this type cannot be evaluated in constants | ||
... | ||
LL | }; | ||
| - value is dropped here | ||
|
||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/const-promoted-opaque.rs:25:26 | ||
| | ||
LL | let _: &'static _ = &FOO; | ||
| ---------- ^^^ creates a temporary value which is freed while still in use | ||
| | | ||
| type annotation requires that borrow lasts for `'static` | ||
... | ||
LL | }; | ||
| - temporary value is freed at the end of this statement | ||
|
||
error[E0492]: constants cannot refer to interior mutable data | ||
--> $DIR/const-promoted-opaque.rs:30:19 | ||
| | ||
LL | const BAZ: &Foo = &FOO; | ||
| ^^^^ this borrow of an interior mutable value may end up in the final value | ||
|
||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/const-promoted-opaque.rs:34:26 | ||
| | ||
LL | let _: &'static _ = &FOO; | ||
| ---------- ^^^ creates a temporary value which is freed while still in use | ||
| | | ||
| type annotation requires that borrow lasts for `'static` | ||
LL | | ||
LL | } | ||
| - temporary value is freed at the end of this statement | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0492, E0493, E0716. | ||
For more information about an error, try `rustc --explain E0492`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This change does not affect any logic and just reduces the number of
mir_const_qualif
calls, and thus hopefully also reduces the cost of caching things