-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turn eager normalization errors to delayed errors #82039
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ use rustc_infer::infer::TyCtxtInferExt; | |
use rustc_middle::traits::query::NoSolution; | ||
use rustc_middle::ty::query::Providers; | ||
use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt, TypeFoldable}; | ||
use rustc_span::DUMMY_SP; | ||
use rustc_trait_selection::traits::query::normalize::AtExt; | ||
use rustc_trait_selection::traits::{Normalized, ObligationCause}; | ||
use std::sync::atomic::Ordering; | ||
|
@@ -51,7 +52,13 @@ fn normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + Cop | |
debug_assert!(!erased.needs_infer(), "{:?}", erased); | ||
erased | ||
} | ||
Err(NoSolution) => bug!("could not fully normalize `{:?}`", value), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this We pretty much only emit a bug here if the type is not well formed, and I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think having There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We get there with const evaluatable bounds when emitting errors, but these errors should be silent when encountered during selection, so just always causing an ICE here is preferable for me. We shouldn't hit this, even after having a compilation error. Having a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow. Could you rephrase your position? It reads to me like
means
which to me is saying two different things? Would it be reasonable to only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what @lcnr means is that the error we get here would be silenced by trait selection, but we don't want that and should ICE. I would be extremely wary of having different behavior on stable vs nightly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
it is an implementation error for const evaluatable bounds to reach this |
||
Err(NoSolution) => { | ||
infcx | ||
.tcx | ||
.sess | ||
.delay_span_bug(DUMMY_SP, &format!("could not fully normalize `{:?}`", value)); | ||
value | ||
} | ||
} | ||
}) | ||
} | ||
|
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() {} |
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() {} |
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`. |
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() {} |
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`. |
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() {} |
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this actually reachable? Do we have a test case where
hir::ItemKind::Union
ends up asty::Error
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also curious about this. Was this getting hit? If not, can you revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, I added this because it is reached after removing the other ICE.