1
Fork 0

Delay normalization bugs instead of reporting them

This commit is contained in:
Michael Goulet 2023-01-11 20:26:12 +00:00
parent 6ec8c13e15
commit 75074e0e52
4 changed files with 19 additions and 33 deletions

View file

@ -8,8 +8,6 @@ use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
use rustc_infer::{infer::outlives::env::OutlivesEnvironment, traits::FulfillmentError}; use rustc_infer::{infer::outlives::env::OutlivesEnvironment, traits::FulfillmentError};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable};
use crate::traits::error_reporting::TypeErrCtxtExt;
use super::outlives_bounds::InferCtxtExt; use super::outlives_bounds::InferCtxtExt;
pub enum CopyImplementationError<'tcx> { pub enum CopyImplementationError<'tcx> {
@ -60,8 +58,8 @@ pub fn type_allowed_to_implement_copy<'tcx>(
let infcx = tcx.infer_ctxt().build(); let infcx = tcx.infer_ctxt().build();
let ocx = traits::ObligationCtxt::new(&infcx); let ocx = traits::ObligationCtxt::new(&infcx);
let ty = field.ty(tcx, substs); let unnormalized_ty = field.ty(tcx, substs);
if ty.references_error() { if unnormalized_ty.references_error() {
continue; continue;
} }
@ -84,12 +82,10 @@ pub fn type_allowed_to_implement_copy<'tcx>(
} else { } else {
ObligationCause::dummy_with_span(field_ty_span) ObligationCause::dummy_with_span(field_ty_span)
}; };
let ty = ocx.normalize(&normalization_cause, param_env, ty); let ty = ocx.normalize(&normalization_cause, param_env, unnormalized_ty);
let normalization_errors = ocx.select_where_possible(); let normalization_errors = ocx.select_where_possible();
if !normalization_errors.is_empty() { if !normalization_errors.is_empty() {
// Don't report this as a field that doesn't implement Copy, tcx.sess.delay_span_bug(field_span, format!("couldn't normalize struct field `{unnormalized_ty}` when checking Copy implementation"));
// but instead just implement this as a field that isn't WF.
infcx.err_ctxt().report_fulfillment_errors(&normalization_errors, None);
continue; continue;
} }

View file

@ -4,6 +4,16 @@ error[E0277]: the trait bound `T: TraitFoo` is not satisfied
LL | impl<T> Copy for Foo<T> {} LL | impl<T> Copy for Foo<T> {}
| ^^^^^^ the trait `TraitFoo` is not implemented for `T` | ^^^^^^ the trait `TraitFoo` is not implemented for `T`
| |
note: required for `Foo<T>` to implement `Clone`
--> $DIR/copy-impl-cannot-normalize.rs:12:9
|
LL | impl<T> Clone for Foo<T>
| ^^^^^ ^^^^^^
LL | where
LL | T: TraitFoo,
| -------- unsatisfied trait bound introduced here
note: required by a bound in `Copy`
--> $SRC_DIR/core/src/marker.rs:LL:COL
help: consider restricting type parameter `T` help: consider restricting type parameter `T`
| |
LL | impl<T: TraitFoo> Copy for Foo<T> {} LL | impl<T: TraitFoo> Copy for Foo<T> {}

View file

@ -5,13 +5,11 @@ struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
//~| ERROR cannot find type `NotDefined` in this scope //~| ERROR cannot find type `NotDefined` in this scope
//~| ERROR cannot find type `N` in this scope //~| ERROR cannot find type `N` in this scope
//~| ERROR cannot find type `N` in this scope //~| ERROR cannot find type `N` in this scope
//~| ERROR `i32` is not an iterator
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
//~^ ERROR the trait `Copy` may not be implemented for this type //~^ ERROR the trait `Copy` may not be implemented for this type
struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
//~^ ERROR cannot find type `NotDefined` in this scope //~^ ERROR cannot find type `NotDefined` in this scope
//~| ERROR cannot find type `N` in this scope //~| ERROR cannot find type `N` in this scope
//~| ERROR `i32` is not an iterator
fn main() {} fn main() {}

View file

@ -38,7 +38,7 @@ LL | struct Foo<NotDefined>(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, St
| ++++++++++++ | ++++++++++++
error[E0412]: cannot find type `N` in this scope error[E0412]: cannot find type `N` in this scope
--> $DIR/issue-50480.rs:12:18 --> $DIR/issue-50480.rs:11:18
| |
LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| - ^ | - ^
@ -55,20 +55,11 @@ LL | struct Bar<T, N>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, Strin
| +++ | +++
error[E0412]: cannot find type `NotDefined` in this scope error[E0412]: cannot find type `NotDefined` in this scope
--> $DIR/issue-50480.rs:12:21 --> $DIR/issue-50480.rs:11:21
| |
LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| ^^^^^^^^^^ not found in this scope | ^^^^^^^^^^ not found in this scope
error[E0277]: `i32` is not an iterator
--> $DIR/issue-50480.rs:3:27
|
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| ^^^^^^^^^^^^^^^^^^^^^^^ `i32` is not an iterator
|
= help: the trait `Iterator` is not implemented for `i32`
= note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end`
error[E0204]: the trait `Copy` may not be implemented for this type error[E0204]: the trait `Copy` may not be implemented for this type
--> $DIR/issue-50480.rs:1:17 --> $DIR/issue-50480.rs:1:17
| |
@ -82,17 +73,8 @@ LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| |
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: `i32` is not an iterator
--> $DIR/issue-50480.rs:12:33
|
LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| ^^^^^^^^^^^^^^^^^^^^^^^ `i32` is not an iterator
|
= help: the trait `Iterator` is not implemented for `i32`
= note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end`
error[E0204]: the trait `Copy` may not be implemented for this type error[E0204]: the trait `Copy` may not be implemented for this type
--> $DIR/issue-50480.rs:10:17 --> $DIR/issue-50480.rs:9:17
| |
LL | #[derive(Clone, Copy)] LL | #[derive(Clone, Copy)]
| ^^^^ | ^^^^
@ -104,7 +86,7 @@ LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| |
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 10 previous errors error: aborting due to 8 previous errors
Some errors have detailed explanations: E0204, E0277, E0412. Some errors have detailed explanations: E0204, E0412.
For more information about an error, try `rustc --explain E0204`. For more information about an error, try `rustc --explain E0204`.