-
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.
Always use RevealAll for const eval queries
- Loading branch information
Showing
32 changed files
with
363 additions
and
108 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
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
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
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
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,16 @@ | ||
//! Check that const eval can use the size of opaque types. | ||
// check-pass | ||
use std::mem; | ||
fn returns_opaque() -> impl Sized { | ||
0u8 | ||
} | ||
|
||
struct NamedOpaqueType { | ||
data: [mem::MaybeUninit<u8>; size_of_fut(returns_opaque)], | ||
} | ||
|
||
const fn size_of_fut<FUT>(x: fn() -> FUT) -> usize { | ||
mem::size_of::<FUT>() | ||
} | ||
|
||
fn main() {} |
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,22 @@ | ||
//! Check that array lengths can observe associated types of opaque types | ||
// check-pass | ||
trait MyTrait: Copy { | ||
const ASSOC: usize; | ||
} | ||
|
||
impl MyTrait for u8 { | ||
const ASSOC: usize = 32; | ||
} | ||
|
||
const fn yeet() -> impl MyTrait { | ||
0u8 | ||
} | ||
|
||
const fn output<T: MyTrait>(_: T) -> usize { | ||
<T as MyTrait>::ASSOC | ||
} | ||
|
||
fn main() { | ||
let x = [0u8; output(yeet())]; | ||
println!("{:?}", x); | ||
} |
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,26 @@ | ||
//! check that const eval can observe associated types of opaque types. | ||
// check-pass | ||
trait MyTrait: Copy { | ||
const ASSOC: usize; | ||
} | ||
|
||
impl MyTrait for u8 { | ||
const ASSOC: usize = 32; | ||
} | ||
|
||
const fn yeet() -> impl MyTrait { | ||
0u8 | ||
} | ||
|
||
const fn output<T: MyTrait>(_: T) -> usize { | ||
<T as MyTrait>::ASSOC | ||
} | ||
|
||
#[repr(usize)] | ||
enum Foo { | ||
Bar = output(yeet()), | ||
} | ||
|
||
fn main() { | ||
println!("{}", Foo::Bar as usize); | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/ui/impl-trait/in-ctfe/fully_monomorphic_const_eval.rs
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 @@ | ||
//! This test ensures that we do look at the hidden types of | ||
//! opaque types during const eval in order to obtain the exact type | ||
//! of associated types. | ||
// check-pass | ||
|
||
trait MyTrait: Copy { | ||
const ASSOC: usize; | ||
} | ||
|
||
impl MyTrait for u8 { | ||
const ASSOC: usize = 32; | ||
} | ||
|
||
const fn yeet() -> impl MyTrait { | ||
0u8 | ||
} | ||
|
||
const fn output<T: MyTrait>(_: T) -> usize { | ||
<T as MyTrait>::ASSOC | ||
} | ||
|
||
struct Foo<'a>(&'a ()); | ||
const NEED_REVEAL_ALL: usize = output(yeet()); | ||
|
||
fn promote_div() -> &'static usize { | ||
&(10 / NEED_REVEAL_ALL) | ||
} | ||
fn main() {} |
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,24 @@ | ||
//! Check that pattern matching can observe the hidden type of opaque types. | ||
// check-pass | ||
trait MyTrait: Copy { | ||
const ASSOC: u8; | ||
} | ||
|
||
impl MyTrait for () { | ||
const ASSOC: u8 = 0; | ||
} | ||
|
||
const fn yeet() -> impl MyTrait {} | ||
|
||
const fn output<T: MyTrait>(_: T) -> u8 { | ||
<T as MyTrait>::ASSOC | ||
} | ||
|
||
const CT: u8 = output(yeet()); | ||
|
||
fn main() { | ||
match 0 { | ||
CT => (), | ||
1.. => (), | ||
} | ||
} |
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,14 @@ | ||
// This causes a query cycle due to using `Reveal::All`, | ||
// in #119821 const eval was changed to always use `Reveal::All` | ||
// | ||
// See that PR for more details. | ||
use std::mem::transmute; | ||
fn foo() -> impl Sized { | ||
//~^ ERROR cycle detected when computing type of | ||
unsafe { | ||
transmute::<_, u8>(foo()); | ||
} | ||
0u8 | ||
} | ||
|
||
fn main() {} |
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 @@ | ||
error[E0391]: cycle detected when computing type of `foo::{opaque#0}` | ||
--> $DIR/in-defining-scope.rs:6:13 | ||
| | ||
LL | fn foo() -> impl Sized { | ||
| ^^^^^^^^^^ | ||
| | ||
note: ...which requires computing type of opaque `foo::{opaque#0}`... | ||
--> $DIR/in-defining-scope.rs:6:13 | ||
| | ||
LL | fn foo() -> impl Sized { | ||
| ^^^^^^^^^^ | ||
note: ...which requires type-checking `foo`... | ||
--> $DIR/in-defining-scope.rs:6:1 | ||
| | ||
LL | fn foo() -> impl Sized { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: ...which requires computing layout of `foo::{opaque#0}`... | ||
= note: ...which requires normalizing `foo::{opaque#0}`... | ||
= note: ...which again requires computing type of `foo::{opaque#0}`, completing the cycle | ||
note: cycle used when checking that `foo::{opaque#0}` is well-formed | ||
--> $DIR/in-defining-scope.rs:6:13 | ||
| | ||
LL | fn 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 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0391`. |
12 changes: 12 additions & 0 deletions
12
tests/ui/impl-trait/transmute/outside-of-defining-scope.rs
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,12 @@ | ||
//! Check that typeck can observe the size of an opaque type. | ||
// check-pass | ||
use std::mem::transmute; | ||
fn foo() -> impl Sized { | ||
0u8 | ||
} | ||
|
||
fn main() { | ||
unsafe { | ||
transmute::<_, u8>(foo()); | ||
} | ||
} |
Oops, something went wrong.