Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb619ec

Browse files
committed
FIx ICE while casting a type with error
1 parentee9a9f8 commitfb619ec

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

‎compiler/rustc_hir_typeck/src/cast.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
140140
| ty::Never
141141
| ty::Dynamic(_, _, ty::DynStar)
142142
| ty::Error(_) =>{
143-
self.dcx().span_bug(span,format!("`{t:?}` should be sized but is not?"));
143+
let guar =self
144+
.dcx()
145+
.span_delayed_bug(span,format!("`{t:?}` should be sized but is not?"));
146+
returnErr(guar);
144147
}
145148
})
146149
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Regression test for ICE #124848
2+
// Tests that there is no ICE when a cast
3+
// involves a type with error
4+
5+
use std::cell::Cell;
6+
7+
structMyType<'a>(Cell<Option<&'unpinnedmutMyType<'a>>>,Pin);
8+
//~^ ERROR use of undeclared lifetime name `'unpinned`
9+
//~| ERROR cannot find type `Pin` in this scope
10+
11+
fnmain(){
12+
letmut unpinned =MyType(Cell::new(None));
13+
//~^ ERROR his struct takes 2 arguments but 1 argument was supplied
14+
let bad_addr =&unpinnedas*constCell<Option<&'amutMyType<'a>>>asusize;
15+
//~^ ERROR use of undeclared lifetime name `'a`
16+
//~| ERROR use of undeclared lifetime name `'a`
17+
//~| ERROR casting `&MyType<'_>` as `*const Cell<Option<&mut MyType<'_>>>` is invalid
18+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
error[E0261]: use of undeclared lifetime name `'unpinned`
2+
--> $DIR/ice-cast-type-with-error-124848.rs:7:32
3+
|
4+
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
5+
| - ^^^^^^^^^ undeclared lifetime
6+
| |
7+
| help: consider introducing lifetime `'unpinned` here: `'unpinned,`
8+
9+
error[E0261]: use of undeclared lifetime name `'a`
10+
--> $DIR/ice-cast-type-with-error-124848.rs:14:53
11+
|
12+
LL | fn main() {
13+
| - help: consider introducing lifetime `'a` here: `<'a>`
14+
...
15+
LL | let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
16+
| ^^ undeclared lifetime
17+
18+
error[E0261]: use of undeclared lifetime name `'a`
19+
--> $DIR/ice-cast-type-with-error-124848.rs:14:67
20+
|
21+
LL | fn main() {
22+
| - help: consider introducing lifetime `'a` here: `<'a>`
23+
...
24+
LL | let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
25+
| ^^ undeclared lifetime
26+
27+
error[E0412]: cannot find type `Pin` in this scope
28+
--> $DIR/ice-cast-type-with-error-124848.rs:7:60
29+
|
30+
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
31+
| ^^^ not found in this scope
32+
|
33+
help: consider importing this struct
34+
|
35+
LL + use std::pin::Pin;
36+
|
37+
38+
error[E0061]: this struct takes 2 arguments but 1 argument was supplied
39+
--> $DIR/ice-cast-type-with-error-124848.rs:12:24
40+
|
41+
LL | let mut unpinned = MyType(Cell::new(None));
42+
| ^^^^^^----------------- an argument is missing
43+
|
44+
note: tuple struct defined here
45+
--> $DIR/ice-cast-type-with-error-124848.rs:7:8
46+
|
47+
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
48+
| ^^^^^^
49+
help: provide the argument
50+
|
51+
LL | let mut unpinned = MyType(Cell::new(None), /* value */);
52+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53+
54+
error[E0606]: casting `&MyType<'_>` as `*const Cell<Option<&mut MyType<'_>>>` is invalid
55+
--> $DIR/ice-cast-type-with-error-124848.rs:14:20
56+
|
57+
LL | let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
58+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
59+
60+
error: aborting due to 6 previous errors
61+
62+
Some errors have detailed explanations: E0061, E0261, E0412, E0606.
63+
For more information about an error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp