From ecdf7f0524d776347bc9cb8154bb8190d025c8d9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 30 Dec 2022 21:51:12 +0000 Subject: [PATCH 1/2] Reuse ErrorGuaranteed during relation --- compiler/rustc_middle/src/ty/_match.rs | 4 +++- compiler/rustc_middle/src/ty/relate.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/ty/_match.rs b/compiler/rustc_middle/src/ty/_match.rs index cd147d7e55813..b9c5a4e0d0d49 100644 --- a/compiler/rustc_middle/src/ty/_match.rs +++ b/compiler/rustc_middle/src/ty/_match.rs @@ -89,7 +89,9 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> { Err(TypeError::Sorts(relate::expected_found(self, a, b))) } - (&ty::Error(_), _) | (_, &ty::Error(_)) => Ok(self.tcx().ty_error()), + (&ty::Error(guar), _) | (_, &ty::Error(guar)) => { + Ok(self.tcx().ty_error_with_guaranteed(guar)) + } _ => relate::super_relate_tys(self, a, b), } diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 4d34ca3d66b5f..65fd8d9753de1 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -414,7 +414,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( bug!("bound types encountered in super_relate_tys") } - (&ty::Error(_), _) | (_, &ty::Error(_)) => Ok(tcx.ty_error()), + (&ty::Error(guar), _) | (_, &ty::Error(guar)) => Ok(tcx.ty_error_with_guaranteed(guar)), (&ty::Never, _) | (&ty::Char, _) From db6d3b3c019daa22032887ba213e3b7b1c141b36 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 1 Jan 2023 23:48:10 +0000 Subject: [PATCH 2/2] Filter impl and where-clause candidates that reference errors --- .../src/traits/select/candidate_assembly.rs | 3 +- .../src/traits/select/mod.rs | 3 ++ src/test/ui/c-variadic/issue-86053-1.rs | 2 +- src/test/ui/c-variadic/issue-86053-1.stderr | 22 +--------- .../issue-72787.min.stderr | 43 ++----------------- .../generic_const_exprs/issue-72787.rs | 2 - src/test/ui/traits/ignore-err-impls.rs | 9 ++++ src/test/ui/traits/ignore-err-impls.stderr | 11 +++++ .../ui/where-clauses/ignore-err-clauses.rs | 14 ++++++ .../where-clauses/ignore-err-clauses.stderr | 9 ++++ 10 files changed, 54 insertions(+), 64 deletions(-) create mode 100644 src/test/ui/traits/ignore-err-impls.rs create mode 100644 src/test/ui/traits/ignore-err-impls.stderr create mode 100644 src/test/ui/where-clauses/ignore-err-clauses.rs create mode 100644 src/test/ui/where-clauses/ignore-err-clauses.stderr diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index c54d901e9b10a..170c1673dbd77 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -174,7 +174,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .param_env .caller_bounds() .iter() - .filter_map(|o| o.to_opt_poly_trait_pred()); + .filter_map(|p| p.to_opt_poly_trait_pred()) + .filter(|p| !p.references_error()); // Micro-optimization: filter out predicates relating to different traits. let matching_bounds = diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 760b4585f4e19..9a3fafd5d0dc9 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2378,6 +2378,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id); let impl_trait_ref = impl_trait_ref.subst(self.tcx(), impl_substs); + if impl_trait_ref.references_error() { + return Err(()); + } debug!(?impl_trait_ref); diff --git a/src/test/ui/c-variadic/issue-86053-1.rs b/src/test/ui/c-variadic/issue-86053-1.rs index b30548e19f9ff..49d5c0390bc13 100644 --- a/src/test/ui/c-variadic/issue-86053-1.rs +++ b/src/test/ui/c-variadic/issue-86053-1.rs @@ -2,7 +2,7 @@ // error-pattern:unexpected `self` parameter in function // error-pattern:`...` must be the last argument of a C-variadic function // error-pattern:cannot find type `F` in this scope -// error-pattern:in type `&'a &'b usize`, reference has a longer lifetime than the data it references + #![feature(c_variadic)] #![crate_type="lib"] diff --git a/src/test/ui/c-variadic/issue-86053-1.stderr b/src/test/ui/c-variadic/issue-86053-1.stderr index d1f13d52362da..5a02f4aa93a95 100644 --- a/src/test/ui/c-variadic/issue-86053-1.stderr +++ b/src/test/ui/c-variadic/issue-86053-1.stderr @@ -76,24 +76,6 @@ help: you might be missing a type parameter LL | fn ordering4 < 'a , 'b, F > ( a : , self , self , self , | +++ -error[E0491]: in type `&'a &'b usize`, reference has a longer lifetime than the data it references - --> $DIR/issue-86053-1.rs:11:52 - | -LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the pointer is valid for the lifetime `'a` as defined here - --> $DIR/issue-86053-1.rs:10:16 - | -LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , - | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined here - --> $DIR/issue-86053-1.rs:10:21 - | -LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , - | ^^ - -error: aborting due to 12 previous errors +error: aborting due to 11 previous errors -Some errors have detailed explanations: E0412, E0491. -For more information about an error, try `rustc --explain E0412`. +For more information about this error, try `rustc --explain E0412`. diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr index 0af5493f81675..ea6f5f6927659 100644 --- a/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr @@ -17,7 +17,7 @@ LL | Condition<{ LHS <= RHS }>: True = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/issue-72787.rs:25:25 + --> $DIR/issue-72787.rs:23:25 | LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, | ^ cannot perform const operation using `I` @@ -26,7 +26,7 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/issue-72787.rs:25:36 + --> $DIR/issue-72787.rs:23:36 | LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, | ^ cannot perform const operation using `J` @@ -34,42 +34,5 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, = help: const parameters may only be used as standalone arguments, i.e. `J` = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions -error[E0283]: type annotations needed: cannot satisfy `IsLessOrEqual: True` - --> $DIR/issue-72787.rs:21:26 - | -LL | IsLessOrEqual: True, - | ^^^^ - | -note: multiple `impl`s or `where` clauses satisfying `IsLessOrEqual: True` found - --> $DIR/issue-72787.rs:10:1 - | -LL | impl True for IsLessOrEqual where - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | IsLessOrEqual: True, - | ^^^^ -... -LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, - | ^^^^ - -error[E0283]: type annotations needed: cannot satisfy `IsLessOrEqual: True` - --> $DIR/issue-72787.rs:21:26 - | -LL | IsLessOrEqual: True, - | ^^^^ - | -note: multiple `impl`s or `where` clauses satisfying `IsLessOrEqual: True` found - --> $DIR/issue-72787.rs:10:1 - | -LL | impl True for IsLessOrEqual where - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | IsLessOrEqual: True, - | ^^^^ -... -LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, - | ^^^^ - -error: aborting due to 6 previous errors +error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0283`. diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-72787.rs b/src/test/ui/const-generics/generic_const_exprs/issue-72787.rs index c651bf1c8de9d..657fec2e9cb70 100644 --- a/src/test/ui/const-generics/generic_const_exprs/issue-72787.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72787.rs @@ -19,8 +19,6 @@ struct S; impl S where IsLessOrEqual: True, -//[min]~^ Error type annotations needed -//[min]~| Error type annotations needed IsLessOrEqual: True, IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, //[min]~^ Error generic parameters may not be used in const operations diff --git a/src/test/ui/traits/ignore-err-impls.rs b/src/test/ui/traits/ignore-err-impls.rs new file mode 100644 index 0000000000000..67e880b006a7f --- /dev/null +++ b/src/test/ui/traits/ignore-err-impls.rs @@ -0,0 +1,9 @@ +pub struct S; + +trait Generic {} + +impl<'a, T> Generic<&'a T> for S {} +impl Generic for S {} +//~^ ERROR cannot find type `Type` in this scope + +fn main() {} diff --git a/src/test/ui/traits/ignore-err-impls.stderr b/src/test/ui/traits/ignore-err-impls.stderr new file mode 100644 index 0000000000000..1390106a29125 --- /dev/null +++ b/src/test/ui/traits/ignore-err-impls.stderr @@ -0,0 +1,11 @@ +error[E0412]: cannot find type `Type` in this scope + --> $DIR/ignore-err-impls.rs:6:14 + | +LL | impl Generic for S {} + | - ^^^^ not found in this scope + | | + | help: you might be missing a type parameter: `` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/src/test/ui/where-clauses/ignore-err-clauses.rs b/src/test/ui/where-clauses/ignore-err-clauses.rs new file mode 100644 index 0000000000000..c76f0e1a8b2b5 --- /dev/null +++ b/src/test/ui/where-clauses/ignore-err-clauses.rs @@ -0,0 +1,14 @@ +use std::ops::Add; + +fn dbl(x: T) -> ::Output +where + T: Copy + Add, + UUU: Copy, + //~^ ERROR cannot find type `UUU` in this scope +{ + x + x +} + +fn main() { + println!("{}", dbl(3)); +} diff --git a/src/test/ui/where-clauses/ignore-err-clauses.stderr b/src/test/ui/where-clauses/ignore-err-clauses.stderr new file mode 100644 index 0000000000000..cfddc3e10b64a --- /dev/null +++ b/src/test/ui/where-clauses/ignore-err-clauses.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `UUU` in this scope + --> $DIR/ignore-err-clauses.rs:6:5 + | +LL | UUU: Copy, + | ^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`.