-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
166 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// 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. | ||
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> { | ||
//~^ ERROR: cycle detected | ||
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,34 @@ | ||
error[E0391]: cycle detected when computing type of opaque `<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many::{opaque#0}` | ||
--> $DIR/const-fn-cycle.rs:20:47 | ||
| | ||
LL | pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: ...which requires borrow-checking `<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many`... | ||
--> $DIR/const-fn-cycle.rs:20:5 | ||
| | ||
LL | pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
note: ...which requires promoting constants in MIR for `<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many`... | ||
--> $DIR/const-fn-cycle.rs:20:5 | ||
| | ||
LL | pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
note: ...which requires const checking `<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many`... | ||
--> $DIR/const-fn-cycle.rs:20:5 | ||
| | ||
LL | pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: ...which requires computing whether `Parser<<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many::{opaque#0}>` is freeze... | ||
= note: ...which requires evaluating trait selection obligation `Parser<<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many::{opaque#0}>: core::marker::Freeze`... | ||
= note: ...which again requires computing type of opaque `<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many::{opaque#0}`, completing the cycle | ||
note: cycle used when computing type of `<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many::{opaque#0}` | ||
--> $DIR/const-fn-cycle.rs:20:47 | ||
| | ||
LL | pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0391`. |
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,34 @@ | ||
error[E0391]: cycle detected when computing type of opaque `helper::Foo::{opaque#0}` | ||
--> $DIR/const-promoted-opaque.rs:14:20 | ||
| | ||
LL | pub type Foo = impl Sized; | ||
| ^^^^^^^^^^ | ||
| | ||
note: ...which requires borrow-checking `helper::FOO`... | ||
--> $DIR/const-promoted-opaque.rs:21:5 | ||
| | ||
LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
note: ...which requires promoting constants in MIR for `helper::FOO`... | ||
--> $DIR/const-promoted-opaque.rs:21:5 | ||
| | ||
LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
note: ...which requires const checking `helper::FOO`... | ||
--> $DIR/const-promoted-opaque.rs:21:5 | ||
| | ||
LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
= note: ...which requires computing whether `helper::Foo` is freeze... | ||
= note: ...which requires evaluating trait selection obligation `helper::Foo: core::marker::Freeze`... | ||
= note: ...which again requires computing type of opaque `helper::Foo::{opaque#0}`, completing the cycle | ||
note: cycle used when computing type of `helper::Foo::{opaque#0}` | ||
--> $DIR/const-promoted-opaque.rs:14:20 | ||
| | ||
LL | pub type Foo = impl Sized; | ||
| ^^^^^^^^^^ | ||
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0391`. |
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 | ||
|
||
mod helper { | ||
pub type Foo = impl Sized; | ||
//[string,atomic]~^ ERROR cycle detected | ||
|
||
#[cfg(string)] | ||
pub const FOO: Foo = String::new(); | ||
|
||
#[cfg(atomic)] | ||
pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42); | ||
|
||
#[cfg(unit)] | ||
pub const FOO: Foo = (); | ||
} | ||
use helper::*; | ||
|
||
const BAR: () = { | ||
let _: &'static _ = &FOO; | ||
}; | ||
|
||
const BAZ: &Foo = &FOO; | ||
|
||
fn main() { | ||
let _: &'static _ = &FOO; | ||
} |
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,34 @@ | ||
error[E0391]: cycle detected when computing type of opaque `helper::Foo::{opaque#0}` | ||
--> $DIR/const-promoted-opaque.rs:14:20 | ||
| | ||
LL | pub type Foo = impl Sized; | ||
| ^^^^^^^^^^ | ||
| | ||
note: ...which requires borrow-checking `helper::FOO`... | ||
--> $DIR/const-promoted-opaque.rs:18:5 | ||
| | ||
LL | pub const FOO: Foo = String::new(); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
note: ...which requires promoting constants in MIR for `helper::FOO`... | ||
--> $DIR/const-promoted-opaque.rs:18:5 | ||
| | ||
LL | pub const FOO: Foo = String::new(); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
note: ...which requires const checking `helper::FOO`... | ||
--> $DIR/const-promoted-opaque.rs:18:5 | ||
| | ||
LL | pub const FOO: Foo = String::new(); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
= note: ...which requires computing whether `helper::Foo` is freeze... | ||
= note: ...which requires evaluating trait selection obligation `helper::Foo: core::marker::Freeze`... | ||
= note: ...which again requires computing type of opaque `helper::Foo::{opaque#0}`, completing the cycle | ||
note: cycle used when computing type of `helper::Foo::{opaque#0}` | ||
--> $DIR/const-promoted-opaque.rs:14:20 | ||
| | ||
LL | pub type Foo = impl Sized; | ||
| ^^^^^^^^^^ | ||
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0391`. |