Skip to content

Commit 56e8f67

Browse files
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
2 parents 77de550 + a3c2d75 commit 56e8f67

6 files changed

+316
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// ICE: failed to get layout for [type error]
2+
// issue: rust-lang/rust#92979
3+
4+
use std::fs;
5+
use std::fs::File;
6+
use std::io::Read;
7+
use std::convert::TryInto;
8+
9+
fn get_file_as_byte_vec(filename: &String) -> Vec<u8> {
10+
let mut f = File::open(&filename).expect("no file found");
11+
let metadata = fs::metadata(&filename).expect("unable to read metadata");
12+
let mut buffer = vec![0; metadata.len() as usize];
13+
f.read(&mut buffer).expect("buffer overflow");
14+
15+
buffer
16+
}
17+
18+
19+
20+
fn demo<T, const N: usize>(v: Vec<T>) -> [T; N] {
21+
v.try_into()
22+
.unwrap_or_else(|v: Vec<T>| panic!("Expected a Vec of length {} but it was {}", N, v.len()))
23+
}
24+
25+
26+
fn main() {
27+
28+
// Specify filepath
29+
let file: &String = &String::from("SomeBinaryDataFileWith4ByteHeaders_f32s_and_u32s");
30+
31+
// Read file into a vector of bytes
32+
let file_data = get_file_as_byte_vec(file);
33+
34+
// Print length of vector and first few values
35+
let length = file_data.len();
36+
println!("The read function read {} bytes", length);
37+
println!("The first few bytes:");
38+
for i in 0..20{
39+
println!("{}", file_data[i]);
40+
}
41+
42+
// Manually count just to make sure
43+
let mut n: u64 = 0;
44+
for data in file_data{
45+
n += 1;
46+
}
47+
println!("We counted {} bytes", n);
48+
assert!(n as usize == length, "Manual counting does not equal len method");
49+
50+
// Simulation parameters
51+
const N: usize = 49627502; // Number of Particles
52+
const bs: f64 = 125.0; // Box Size
53+
const HEADER_INCREMENT: u64 = 4*1;
54+
55+
// Initialize index and counter variables
56+
let (mut j, mut pos, mut vel, mut id, mut mass): (u64, u64, u64, u64, u64) = (0, 0, 0, 0, 0);
57+
58+
// Unpack Position Data
59+
j += HEADER_INCREMENT;
60+
let mut position: Vec<f32> = Vec::new();
61+
while position.len() < N*3 {
62+
63+
let p: Vec<u8> = Vec::new();
64+
for item in 0i8..4 {
65+
let item = item;
66+
p.push(file_data[j as usize]);
67+
j += 1;
68+
}
69+
&mut position[position.len()] = f32::from_be_bytes(demo(p));
70+
//~^ ERROR invalid left-hand side of assignment
71+
}
72+
73+
// Ensure position data is indeed position by checking values
74+
for p in position {
75+
assert!((p > 0.) & (p < 125.), "Not in box")
76+
}
77+
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0070]: invalid left-hand side of assignment
2+
--> $DIR/failed-to-get-layout-for-type-error-ice-92979.rs:69:39
3+
|
4+
LL | &mut position[position.len()] = f32::from_be_bytes(demo(p));
5+
| ----------------------------- ^
6+
| |
7+
| cannot assign to this expression
8+
|
9+
help: consider dereferencing here to assign to the mutably borrowed value
10+
|
11+
LL | *&mut position[position.len()] = f32::from_be_bytes(demo(p));
12+
| +
13+
14+
error: aborting due to 1 previous error
15+
16+
For more information about this error, try `rustc --explain E0070`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// ICE argument to function with "rust-call" ABI is not a tuple
2+
// issue: rust-lang/rust#81974
3+
4+
#![feature(unboxed_closures)]
5+
#![feature(fn_traits)]
6+
7+
use std::collections::HashMap;
8+
use std::hash::Hash;
9+
10+
struct CachedFun<A, B> {
11+
cache: HashMap<A, B>,
12+
fun: fn(&mut CachedFun<A, B>, A) -> B,
13+
}
14+
15+
impl<A: Eq + Hash, B> CachedFun<A, B> {
16+
fn new(fun: fn(&mut Self, A) -> B) -> Self {
17+
CachedFun {
18+
cache: HashMap::new(),
19+
fun,
20+
}
21+
}
22+
}
23+
24+
impl<A, B> FnOnce<A> for CachedFun<A, B>
25+
//~^ ERROR type parameter to bare `FnOnce` trait must be a tuple
26+
where
27+
A: Eq + Hash + Clone,
28+
B: Clone,
29+
{
30+
type Output = B;
31+
extern "rust-call" fn call_once(mut self, a: A) -> Self::Output {
32+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
33+
self.call_mut(a)
34+
//~^ ERROR `A` is not a tuple
35+
}
36+
}
37+
38+
impl<A, B> FnMut<A> for CachedFun<A, B>
39+
//~^ ERROR type parameter to bare `FnMut` trait must be a tuple
40+
where
41+
A: Eq + Hash + Clone,
42+
B: Clone,
43+
{
44+
extern "rust-call" fn call_mut(&mut self, a: A) -> Self::Output {
45+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
46+
self.cache.get(&a).map(|a| a.clone()).unwrap_or_else(|| {
47+
let b = (self.fun)(self, a.clone());
48+
self.cache.insert(a, b.clone());
49+
b
50+
})
51+
}
52+
}
53+
54+
fn main() -> () {
55+
let pesce = |y: &mut CachedFun<i32, i32>, x| x + 1;
56+
let cachedcoso = CachedFun::new(pesce);
57+
cachedcoso.call_once(1);
58+
//~^ ERROR `i32` is not a tuple
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
error[E0059]: type parameter to bare `FnOnce` trait must be a tuple
2+
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:24:12
3+
|
4+
LL | impl<A, B> FnOnce<A> for CachedFun<A, B>
5+
| ^^^^^^^^^ the trait `Tuple` is not implemented for `A`
6+
|
7+
note: required by a bound in `FnOnce`
8+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
9+
help: consider further restricting this bound
10+
|
11+
LL | A: Eq + Hash + Clone + std::marker::Tuple,
12+
| ++++++++++++++++++++
13+
14+
error[E0059]: type parameter to bare `FnMut` trait must be a tuple
15+
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:38:12
16+
|
17+
LL | impl<A, B> FnMut<A> for CachedFun<A, B>
18+
| ^^^^^^^^ the trait `Tuple` is not implemented for `A`
19+
|
20+
note: required by a bound in `FnMut`
21+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
22+
help: consider further restricting this bound
23+
|
24+
LL | A: Eq + Hash + Clone + std::marker::Tuple,
25+
| ++++++++++++++++++++
26+
27+
error[E0277]: functions with the "rust-call" ABI must take a single non-self tuple argument
28+
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:31:5
29+
|
30+
LL | extern "rust-call" fn call_once(mut self, a: A) -> Self::Output {
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Tuple` is not implemented for `A`
32+
|
33+
help: consider further restricting this bound
34+
|
35+
LL | A: Eq + Hash + Clone + std::marker::Tuple,
36+
| ++++++++++++++++++++
37+
38+
error[E0277]: functions with the "rust-call" ABI must take a single non-self tuple argument
39+
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:44:5
40+
|
41+
LL | extern "rust-call" fn call_mut(&mut self, a: A) -> Self::Output {
42+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Tuple` is not implemented for `A`
43+
|
44+
help: consider further restricting this bound
45+
|
46+
LL | A: Eq + Hash + Clone + std::marker::Tuple,
47+
| ++++++++++++++++++++
48+
49+
error[E0277]: `A` is not a tuple
50+
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:33:23
51+
|
52+
LL | self.call_mut(a)
53+
| -------- ^ the trait `Tuple` is not implemented for `A`
54+
| |
55+
| required by a bound introduced by this call
56+
|
57+
note: required by a bound in `call_mut`
58+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
59+
help: consider further restricting this bound
60+
|
61+
LL | A: Eq + Hash + Clone + std::marker::Tuple,
62+
| ++++++++++++++++++++
63+
64+
error[E0277]: `i32` is not a tuple
65+
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:57:26
66+
|
67+
LL | cachedcoso.call_once(1);
68+
| --------- ^ the trait `Tuple` is not implemented for `i32`
69+
| |
70+
| required by a bound introduced by this call
71+
|
72+
note: required by a bound in `call_once`
73+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
74+
75+
error: aborting due to 6 previous errors
76+
77+
Some errors have detailed explanations: E0059, E0277.
78+
For more information about an error, try `rustc --explain E0059`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// ICE Where clause `Binder(..)` was applicable to `Obligation(..)` but now is not
2+
// issue: rust-lang/rust#84727
3+
4+
struct Cell<Fg, Bg = Fg> {
5+
foreground: Color<Fg>,
6+
//~^ ERROR cannot find type `Color` in this scope
7+
background: Color<Bg>,
8+
//~^ ERROR cannot find type `Color` in this scope
9+
}
10+
11+
trait Over<Bottom, Output> {
12+
fn over(self) -> Output;
13+
}
14+
15+
impl<TopFg, TopBg, BottomFg, BottomBg, NewFg, NewBg>
16+
Over<Cell<BottomFg, BottomBg>, Cell<NewFg, NewBg>> for Cell<TopFg, TopBg>
17+
where
18+
Self: Over<Color<BottomBg>, Cell<NewFg>>,
19+
//~^ ERROR cannot find type `Color` in this scope
20+
{
21+
fn over(self) -> Cell<NewFg> {
22+
//~^ ERROR mismatched types
23+
self.over();
24+
}
25+
}
26+
27+
impl<'b, TopFg, TopBg, BottomFg, BottomBg> Over<&Cell<BottomFg, BottomBg>, ()>
28+
for Cell<TopFg, TopBg>
29+
where
30+
Cell<TopFg, TopBg>: Over<Cell<BottomFg>, Cell<BottomFg>>,
31+
{
32+
fn over(self) -> Cell<NewBg> {
33+
//~^ ERROR cannot find type `NewBg` in this scope
34+
self.over();
35+
}
36+
}
37+
38+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
error[E0412]: cannot find type `Color` in this scope
2+
--> $DIR/trait-selection-ice-84727.rs:5:17
3+
|
4+
LL | foreground: Color<Fg>,
5+
| ^^^^^ not found in this scope
6+
7+
error[E0412]: cannot find type `Color` in this scope
8+
--> $DIR/trait-selection-ice-84727.rs:7:17
9+
|
10+
LL | background: Color<Bg>,
11+
| ^^^^^ not found in this scope
12+
13+
error[E0412]: cannot find type `Color` in this scope
14+
--> $DIR/trait-selection-ice-84727.rs:18:16
15+
|
16+
LL | Self: Over<Color<BottomBg>, Cell<NewFg>>,
17+
| ^^^^^ not found in this scope
18+
19+
error[E0412]: cannot find type `NewBg` in this scope
20+
--> $DIR/trait-selection-ice-84727.rs:32:27
21+
|
22+
LL | fn over(self) -> Cell<NewBg> {
23+
| ^^^^^ not found in this scope
24+
|
25+
help: you might be missing a type parameter
26+
|
27+
LL | impl<'b, TopFg, TopBg, BottomFg, BottomBg, NewBg> Over<&Cell<BottomFg, BottomBg>, ()>
28+
| +++++++
29+
30+
error[E0308]: mismatched types
31+
--> $DIR/trait-selection-ice-84727.rs:21:22
32+
|
33+
LL | fn over(self) -> Cell<NewFg> {
34+
| ---- ^^^^^^^^^^^ expected `Cell<NewFg>`, found `()`
35+
| |
36+
| implicitly returns `()` as its body has no tail or `return` expression
37+
LL |
38+
LL | self.over();
39+
| - help: remove this semicolon to return this value
40+
|
41+
= note: expected struct `Cell<NewFg>`
42+
found unit type `()`
43+
44+
error: aborting due to 5 previous errors
45+
46+
Some errors have detailed explanations: E0308, E0412.
47+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)