forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#123051 - matthiaskrgr:casetest, r=workingjubilee did I mention that tests are super cool? Fixes rust-lang#81974 Fixes rust-lang#84727 Fixes rust-lang#92979
- Loading branch information
Showing
6 changed files
with
316 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
tests/ui/layout/failed-to-get-layout-for-type-error-ice-92979.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,78 @@ | ||
// ICE: failed to get layout for [type error] | ||
// issue: rust-lang/rust#92979 | ||
|
||
use std::fs; | ||
use std::fs::File; | ||
use std::io::Read; | ||
use std::convert::TryInto; | ||
|
||
fn get_file_as_byte_vec(filename: &String) -> Vec<u8> { | ||
let mut f = File::open(&filename).expect("no file found"); | ||
let metadata = fs::metadata(&filename).expect("unable to read metadata"); | ||
let mut buffer = vec![0; metadata.len() as usize]; | ||
f.read(&mut buffer).expect("buffer overflow"); | ||
|
||
buffer | ||
} | ||
|
||
|
||
|
||
fn demo<T, const N: usize>(v: Vec<T>) -> [T; N] { | ||
v.try_into() | ||
.unwrap_or_else(|v: Vec<T>| panic!("Expected a Vec of length {} but it was {}", N, v.len())) | ||
} | ||
|
||
|
||
fn main() { | ||
|
||
// Specify filepath | ||
let file: &String = &String::from("SomeBinaryDataFileWith4ByteHeaders_f32s_and_u32s"); | ||
|
||
// Read file into a vector of bytes | ||
let file_data = get_file_as_byte_vec(file); | ||
|
||
// Print length of vector and first few values | ||
let length = file_data.len(); | ||
println!("The read function read {} bytes", length); | ||
println!("The first few bytes:"); | ||
for i in 0..20{ | ||
println!("{}", file_data[i]); | ||
} | ||
|
||
// Manually count just to make sure | ||
let mut n: u64 = 0; | ||
for data in file_data{ | ||
n += 1; | ||
} | ||
println!("We counted {} bytes", n); | ||
assert!(n as usize == length, "Manual counting does not equal len method"); | ||
|
||
// Simulation parameters | ||
const N: usize = 49627502; // Number of Particles | ||
const bs: f64 = 125.0; // Box Size | ||
const HEADER_INCREMENT: u64 = 4*1; | ||
|
||
// Initialize index and counter variables | ||
let (mut j, mut pos, mut vel, mut id, mut mass): (u64, u64, u64, u64, u64) = (0, 0, 0, 0, 0); | ||
|
||
// Unpack Position Data | ||
j += HEADER_INCREMENT; | ||
let mut position: Vec<f32> = Vec::new(); | ||
while position.len() < N*3 { | ||
|
||
let p: Vec<u8> = Vec::new(); | ||
for item in 0i8..4 { | ||
let item = item; | ||
p.push(file_data[j as usize]); | ||
j += 1; | ||
} | ||
&mut position[position.len()] = f32::from_be_bytes(demo(p)); | ||
//~^ ERROR invalid left-hand side of assignment | ||
} | ||
|
||
// Ensure position data is indeed position by checking values | ||
for p in position { | ||
assert!((p > 0.) & (p < 125.), "Not in box") | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/layout/failed-to-get-layout-for-type-error-ice-92979.stderr
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 @@ | ||
error[E0070]: invalid left-hand side of assignment | ||
--> $DIR/failed-to-get-layout-for-type-error-ice-92979.rs:69:39 | ||
| | ||
LL | &mut position[position.len()] = f32::from_be_bytes(demo(p)); | ||
| ----------------------------- ^ | ||
| | | ||
| cannot assign to this expression | ||
| | ||
help: consider dereferencing here to assign to the mutably borrowed value | ||
| | ||
LL | *&mut position[position.len()] = f32::from_be_bytes(demo(p)); | ||
| + | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0070`. |
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,59 @@ | ||
// ICE argument to function with "rust-call" ABI is not a tuple | ||
// issue: rust-lang/rust#81974 | ||
|
||
#![feature(unboxed_closures)] | ||
#![feature(fn_traits)] | ||
|
||
use std::collections::HashMap; | ||
use std::hash::Hash; | ||
|
||
struct CachedFun<A, B> { | ||
cache: HashMap<A, B>, | ||
fun: fn(&mut CachedFun<A, B>, A) -> B, | ||
} | ||
|
||
impl<A: Eq + Hash, B> CachedFun<A, B> { | ||
fn new(fun: fn(&mut Self, A) -> B) -> Self { | ||
CachedFun { | ||
cache: HashMap::new(), | ||
fun, | ||
} | ||
} | ||
} | ||
|
||
impl<A, B> FnOnce<A> for CachedFun<A, B> | ||
//~^ ERROR type parameter to bare `FnOnce` trait must be a tuple | ||
where | ||
A: Eq + Hash + Clone, | ||
B: Clone, | ||
{ | ||
type Output = B; | ||
extern "rust-call" fn call_once(mut self, a: A) -> Self::Output { | ||
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument | ||
self.call_mut(a) | ||
//~^ ERROR `A` is not a tuple | ||
} | ||
} | ||
|
||
impl<A, B> FnMut<A> for CachedFun<A, B> | ||
//~^ ERROR type parameter to bare `FnMut` trait must be a tuple | ||
where | ||
A: Eq + Hash + Clone, | ||
B: Clone, | ||
{ | ||
extern "rust-call" fn call_mut(&mut self, a: A) -> Self::Output { | ||
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument | ||
self.cache.get(&a).map(|a| a.clone()).unwrap_or_else(|| { | ||
let b = (self.fun)(self, a.clone()); | ||
self.cache.insert(a, b.clone()); | ||
b | ||
}) | ||
} | ||
} | ||
|
||
fn main() -> () { | ||
let pesce = |y: &mut CachedFun<i32, i32>, x| x + 1; | ||
let cachedcoso = CachedFun::new(pesce); | ||
cachedcoso.call_once(1); | ||
//~^ ERROR `i32` is not a tuple | ||
} |
78 changes: 78 additions & 0 deletions
78
tests/ui/layout/rust-call-abi-not-a-tuple-ice-81974.stderr
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,78 @@ | ||
error[E0059]: type parameter to bare `FnOnce` trait must be a tuple | ||
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:24:12 | ||
| | ||
LL | impl<A, B> FnOnce<A> for CachedFun<A, B> | ||
| ^^^^^^^^^ the trait `Tuple` is not implemented for `A` | ||
| | ||
note: required by a bound in `FnOnce` | ||
--> $SRC_DIR/core/src/ops/function.rs:LL:COL | ||
help: consider further restricting this bound | ||
| | ||
LL | A: Eq + Hash + Clone + std::marker::Tuple, | ||
| ++++++++++++++++++++ | ||
|
||
error[E0059]: type parameter to bare `FnMut` trait must be a tuple | ||
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:38:12 | ||
| | ||
LL | impl<A, B> FnMut<A> for CachedFun<A, B> | ||
| ^^^^^^^^ the trait `Tuple` is not implemented for `A` | ||
| | ||
note: required by a bound in `FnMut` | ||
--> $SRC_DIR/core/src/ops/function.rs:LL:COL | ||
help: consider further restricting this bound | ||
| | ||
LL | A: Eq + Hash + Clone + std::marker::Tuple, | ||
| ++++++++++++++++++++ | ||
|
||
error[E0277]: functions with the "rust-call" ABI must take a single non-self tuple argument | ||
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:31:5 | ||
| | ||
LL | extern "rust-call" fn call_once(mut self, a: A) -> Self::Output { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Tuple` is not implemented for `A` | ||
| | ||
help: consider further restricting this bound | ||
| | ||
LL | A: Eq + Hash + Clone + std::marker::Tuple, | ||
| ++++++++++++++++++++ | ||
|
||
error[E0277]: functions with the "rust-call" ABI must take a single non-self tuple argument | ||
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:44:5 | ||
| | ||
LL | extern "rust-call" fn call_mut(&mut self, a: A) -> Self::Output { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Tuple` is not implemented for `A` | ||
| | ||
help: consider further restricting this bound | ||
| | ||
LL | A: Eq + Hash + Clone + std::marker::Tuple, | ||
| ++++++++++++++++++++ | ||
|
||
error[E0277]: `A` is not a tuple | ||
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:33:23 | ||
| | ||
LL | self.call_mut(a) | ||
| -------- ^ the trait `Tuple` is not implemented for `A` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `call_mut` | ||
--> $SRC_DIR/core/src/ops/function.rs:LL:COL | ||
help: consider further restricting this bound | ||
| | ||
LL | A: Eq + Hash + Clone + std::marker::Tuple, | ||
| ++++++++++++++++++++ | ||
|
||
error[E0277]: `i32` is not a tuple | ||
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:57:26 | ||
| | ||
LL | cachedcoso.call_once(1); | ||
| --------- ^ the trait `Tuple` is not implemented for `i32` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `call_once` | ||
--> $SRC_DIR/core/src/ops/function.rs:LL:COL | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
Some errors have detailed explanations: E0059, E0277. | ||
For more information about an error, try `rustc --explain E0059`. |
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,38 @@ | ||
// ICE Where clause `Binder(..)` was applicable to `Obligation(..)` but now is not | ||
// issue: rust-lang/rust#84727 | ||
|
||
struct Cell<Fg, Bg = Fg> { | ||
foreground: Color<Fg>, | ||
//~^ ERROR cannot find type `Color` in this scope | ||
background: Color<Bg>, | ||
//~^ ERROR cannot find type `Color` in this scope | ||
} | ||
|
||
trait Over<Bottom, Output> { | ||
fn over(self) -> Output; | ||
} | ||
|
||
impl<TopFg, TopBg, BottomFg, BottomBg, NewFg, NewBg> | ||
Over<Cell<BottomFg, BottomBg>, Cell<NewFg, NewBg>> for Cell<TopFg, TopBg> | ||
where | ||
Self: Over<Color<BottomBg>, Cell<NewFg>>, | ||
//~^ ERROR cannot find type `Color` in this scope | ||
{ | ||
fn over(self) -> Cell<NewFg> { | ||
//~^ ERROR mismatched types | ||
self.over(); | ||
} | ||
} | ||
|
||
impl<'b, TopFg, TopBg, BottomFg, BottomBg> Over<&Cell<BottomFg, BottomBg>, ()> | ||
for Cell<TopFg, TopBg> | ||
where | ||
Cell<TopFg, TopBg>: Over<Cell<BottomFg>, Cell<BottomFg>>, | ||
{ | ||
fn over(self) -> Cell<NewBg> { | ||
//~^ ERROR cannot find type `NewBg` in this scope | ||
self.over(); | ||
} | ||
} | ||
|
||
pub 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,47 @@ | ||
error[E0412]: cannot find type `Color` in this scope | ||
--> $DIR/trait-selection-ice-84727.rs:5:17 | ||
| | ||
LL | foreground: Color<Fg>, | ||
| ^^^^^ not found in this scope | ||
|
||
error[E0412]: cannot find type `Color` in this scope | ||
--> $DIR/trait-selection-ice-84727.rs:7:17 | ||
| | ||
LL | background: Color<Bg>, | ||
| ^^^^^ not found in this scope | ||
|
||
error[E0412]: cannot find type `Color` in this scope | ||
--> $DIR/trait-selection-ice-84727.rs:18:16 | ||
| | ||
LL | Self: Over<Color<BottomBg>, Cell<NewFg>>, | ||
| ^^^^^ not found in this scope | ||
|
||
error[E0412]: cannot find type `NewBg` in this scope | ||
--> $DIR/trait-selection-ice-84727.rs:32:27 | ||
| | ||
LL | fn over(self) -> Cell<NewBg> { | ||
| ^^^^^ not found in this scope | ||
| | ||
help: you might be missing a type parameter | ||
| | ||
LL | impl<'b, TopFg, TopBg, BottomFg, BottomBg, NewBg> Over<&Cell<BottomFg, BottomBg>, ()> | ||
| +++++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/trait-selection-ice-84727.rs:21:22 | ||
| | ||
LL | fn over(self) -> Cell<NewFg> { | ||
| ---- ^^^^^^^^^^^ expected `Cell<NewFg>`, found `()` | ||
| | | ||
| implicitly returns `()` as its body has no tail or `return` expression | ||
LL | | ||
LL | self.over(); | ||
| - help: remove this semicolon to return this value | ||
| | ||
= note: expected struct `Cell<NewFg>` | ||
found unit type `()` | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0412. | ||
For more information about an error, try `rustc --explain E0308`. |