-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn eager normalization errors to delayed errors
When normalizing `union`s with fields coming from associated types that don't satisfy trait bounds, avoid ICEing by using `delay_span_bug()` instead of `bug!()`. Fix #81199.
- Loading branch information
Showing
9 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
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
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
21 changes: 21 additions & 0 deletions
21
src/test/ui/union/normalization-failure-issue-81199-autofix.fixed
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,21 @@ | ||
// run-rustfix | ||
#[allow(dead_code)] | ||
#[repr(C)] | ||
union PtrRepr<T: ?Sized + Pointee> { | ||
const_ptr: *const T, | ||
mut_ptr: *mut T, | ||
components: std::mem::ManuallyDrop<PtrComponents<T>>, | ||
//~^ ERROR the trait bound `T: Pointee` is not satisfied | ||
} | ||
|
||
#[repr(C)] | ||
struct PtrComponents<T: Pointee + ?Sized> { | ||
data_address: *const (), | ||
metadata: <T as Pointee>::Metadata, | ||
} | ||
|
||
pub trait Pointee { | ||
type Metadata; | ||
} | ||
|
||
fn main() {} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/union/normalization-failure-issue-81199-autofix.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,21 @@ | ||
// run-rustfix | ||
#[allow(dead_code)] | ||
#[repr(C)] | ||
union PtrRepr<T: ?Sized> { | ||
const_ptr: *const T, | ||
mut_ptr: *mut T, | ||
components: std::mem::ManuallyDrop<PtrComponents<T>>, | ||
//~^ ERROR the trait bound `T: Pointee` is not satisfied | ||
} | ||
|
||
#[repr(C)] | ||
struct PtrComponents<T: Pointee + ?Sized> { | ||
data_address: *const (), | ||
metadata: <T as Pointee>::Metadata, | ||
} | ||
|
||
pub trait Pointee { | ||
type Metadata; | ||
} | ||
|
||
fn main() {} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/union/normalization-failure-issue-81199-autofix.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,19 @@ | ||
error[E0277]: the trait bound `T: Pointee` is not satisfied | ||
--> $DIR/normalization-failure-issue-81199-autofix.rs:7:40 | ||
| | ||
LL | components: std::mem::ManuallyDrop<PtrComponents<T>>, | ||
| ^^^^^^^^^^^^^^^^ the trait `Pointee` is not implemented for `T` | ||
| | ||
note: required by a bound in `PtrComponents` | ||
--> $DIR/normalization-failure-issue-81199-autofix.rs:12:25 | ||
| | ||
LL | struct PtrComponents<T: Pointee + ?Sized> { | ||
| ^^^^^^^ required by this bound in `PtrComponents` | ||
help: consider further restricting this bound | ||
| | ||
LL | union PtrRepr<T: ?Sized + Pointee> { | ||
| +++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
12 changes: 12 additions & 0 deletions
12
src/test/ui/union/normalization-failure-issue-81199-min.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,12 @@ | ||
union PtrRepr<T: ?Sized> { | ||
const_ptr: *const T, | ||
mut_ptr: *mut T, | ||
components: <T as Pointee>::Metadata | ||
//~^ ERROR the trait bound `T: Pointee` is not satisfied | ||
} | ||
|
||
pub trait Pointee { | ||
type Metadata; | ||
} | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/union/normalization-failure-issue-81199-min.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,14 @@ | ||
error[E0277]: the trait bound `T: Pointee` is not satisfied | ||
--> $DIR/normalization-failure-issue-81199-min.rs:4:17 | ||
| | ||
LL | components: <T as Pointee>::Metadata | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Pointee` is not implemented for `T` | ||
| | ||
help: consider further restricting this bound | ||
| | ||
LL | union PtrRepr<T: ?Sized + Pointee> { | ||
| +++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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,19 @@ | ||
#[repr(C)] | ||
union PtrRepr<T: ?Sized> { | ||
const_ptr: *const T, | ||
mut_ptr: *mut T, | ||
components: PtrComponents<T>, | ||
//~^ ERROR the trait bound `T: Pointee` is not satisfied in `PtrComponents<T>` | ||
} | ||
|
||
#[repr(C)] | ||
struct PtrComponents<T: Pointee + ?Sized> { | ||
data_address: *const (), | ||
metadata: <T as Pointee>::Metadata, | ||
} | ||
|
||
pub trait Pointee { | ||
type Metadata; | ||
} | ||
|
||
fn main() {} |
29 changes: 29 additions & 0 deletions
29
src/test/ui/union/normalization-failure-issue-81199.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,29 @@ | ||
error[E0277]: the trait bound `T: Pointee` is not satisfied in `PtrComponents<T>` | ||
--> $DIR/normalization-failure-issue-81199.rs:5:17 | ||
| | ||
LL | components: PtrComponents<T>, | ||
| ^^^^^^^^^^^^^^^^ within `PtrComponents<T>`, the trait `Pointee` is not implemented for `T` | ||
| | ||
note: required because it appears within the type `PtrComponents<T>` | ||
--> $DIR/normalization-failure-issue-81199.rs:10:8 | ||
| | ||
LL | struct PtrComponents<T: Pointee + ?Sized> { | ||
| ^^^^^^^^^^^^^ | ||
= note: no field of a union may have a dynamically sized type | ||
= help: change the field's type to have a statically known size | ||
help: consider further restricting this bound | ||
| | ||
LL | union PtrRepr<T: ?Sized + Pointee> { | ||
| +++++++++ | ||
help: borrowed types always have a statically known size | ||
| | ||
LL | components: &PtrComponents<T>, | ||
| + | ||
help: the `Box` type always has a statically known size and allocates its contents in the heap | ||
| | ||
LL | components: Box<PtrComponents<T>>, | ||
| ++++ + | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |