Skip to content

Commit 2d87df1

Browse files
committed
Add a test for a now fixed ICE with offset_of!()
1 parent cf7da0b commit 2d87df1

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ edition:2021
2+
// Regression test for #125805.
3+
// ICE when using `offset_of!` on a field whose type is a bare trait object
4+
// with a missing lifetime parameter.
5+
6+
trait X<'a> {}
7+
8+
use std::mem::offset_of;
9+
10+
struct T {
11+
y: X,
12+
//~^ ERROR missing lifetime specifier [E0106]
13+
//~| ERROR expected a type, found a trait [E0782]
14+
}
15+
16+
fn other() {
17+
offset_of!(T, y);
18+
}
19+
20+
fn main() {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0106]: missing lifetime specifier
2+
--> $DIR/offset-of-unsized-trait-object-missing-lifetime.rs:11:8
3+
|
4+
LL | y: X,
5+
| ^ expected named lifetime parameter
6+
|
7+
help: consider introducing a named lifetime parameter
8+
|
9+
LL ~ struct T<'a> {
10+
LL ~ y: X<'a>,
11+
|
12+
13+
error[E0782]: expected a type, found a trait
14+
--> $DIR/offset-of-unsized-trait-object-missing-lifetime.rs:11:8
15+
|
16+
LL | y: X,
17+
| ^
18+
|
19+
help: you can add the `dyn` keyword if you want a trait object
20+
|
21+
LL | y: dyn X,
22+
| +++
23+
24+
error: aborting due to 2 previous errors
25+
26+
Some errors have detailed explanations: E0106, E0782.
27+
For more information about an error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)