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

Commit18d9c03

Browse files
authored
Rollup merge of#124997 - gurry:124848-ice-should-be-sized, r=Nadrieril
Fix ICE while casting a type with errorFixes#124848The ICE originates here:https://github.com/rust-lang/rust/blob/f9a3fd966162b3c7386d90fe4626471f66ba3b8f/compiler/rustc_hir_typeck/src/cast.rs#L143 The underlying cause is that a type with error, `MyType` was involved in a cast. During cast checks the below method `pointer_kind` was called:https://github.com/rust-lang/rust/blob/f9a3fd966162b3c7386d90fe4626471f66ba3b8f/compiler/rustc_hir_typeck/src/cast.rs#L87-L91 Thanks to the changes in PR#123491, `type_is_sized_modulo_regions` in `pointer_kind` returned `false` which caused control to reach the `span_bug` here:https://github.com/rust-lang/rust/blob/f9a3fd966162b3c7386d90fe4626471f66ba3b8f/compiler/rustc_hir_typeck/src/cast.rs#L143 resulting in an ICE.This PR fixes the issue by changing the `span_bug` to a `span_delayed_bug`.
2 parents74a78af +fb619ec commit18d9c03

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
@@ -141,7 +141,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
141141
| ty::Never
142142
| ty::Dynamic(_, _, ty::DynStar)
143143
| ty::Error(_) =>{
144-
self.dcx().span_bug(span,format!("`{t:?}` should be sized but is not?"));
144+
let guar =self
145+
.dcx()
146+
.span_delayed_bug(span,format!("`{t:?}` should be sized but is not?"));
147+
returnErr(guar);
145148
}
146149
})
147150
}
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