From af7f8f9811e71e9b7b1885c6e5567a0b2f7b3d6a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 10 Jan 2024 10:31:06 +0000 Subject: [PATCH] Silence follow up errors if astconv already errored --- .../rustc_hir_analysis/src/astconv/mod.rs | 7 +++ compiler/rustc_hir_analysis/src/collect.rs | 15 ++++- .../rustc_hir_analysis/src/collect/type_of.rs | 6 +- .../issue-109071.no_gate.stderr | 2 +- .../associated-inherent-types/issue-109071.rs | 4 +- .../issue-109071.with_gate.stderr | 23 ++++---- .../issues/issue-71381.full.stderr | 2 +- .../issues/issue-71381.min.stderr | 20 +------ tests/ui/const-generics/issues/issue-71381.rs | 6 +- .../issues/issue-71611.min.stderr | 10 +--- tests/ui/const-generics/issues/issue-71611.rs | 3 +- .../generic-associated-types/issue-71176.rs | 3 - .../issue-71176.stderr | 55 +------------------ tests/ui/issues/issue-3214.rs | 1 - tests/ui/issues/issue-3214.stderr | 10 +--- tests/ui/layout/issue-84108.rs | 2 - tests/ui/layout/issue-84108.stderr | 24 +------- .../issues/issue-103748-ICE-wrong-braces.rs | 1 - .../issue-103748-ICE-wrong-braces.stderr | 17 +----- ...lid-assoc-type-suggestion-in-trait-impl.rs | 1 - ...assoc-type-suggestion-in-trait-impl.stderr | 8 +-- 21 files changed, 56 insertions(+), 164 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 1f47564649eda..cfe9496367f1c 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -390,6 +390,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { infer_args, ); + if let Err(err) = &arg_count.correct + && let Some(reported) = err.reported + { + self.set_tainted_by_errors(reported); + } + // Skip processing if type has no generic parameters. // Traits always have `Self` as a generic parameter, which means they will not return early // here and so associated type bindings will be handled regardless of whether there are any @@ -568,6 +574,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { span, modifier: constness.as_str(), }); + self.set_tainted_by_errors(e); arg_count.correct = Err(GenericArgCountMismatch { reported: Some(e), invalid_args: vec![] }); } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index c9f89a0c3ef32..e557f36037b6c 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -35,6 +35,7 @@ use rustc_target::spec::abi; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::error_reporting::suggestions::NextTypeParamName; use rustc_trait_selection::traits::ObligationCtxt; +use std::cell::Cell; use std::iter; use std::ops::Bound; @@ -119,6 +120,7 @@ pub fn provide(providers: &mut Providers) { pub struct ItemCtxt<'tcx> { tcx: TyCtxt<'tcx>, item_def_id: LocalDefId, + tainted_by_errors: Cell>, } /////////////////////////////////////////////////////////////////////////// @@ -343,7 +345,7 @@ fn bad_placeholder<'tcx>( impl<'tcx> ItemCtxt<'tcx> { pub fn new(tcx: TyCtxt<'tcx>, item_def_id: LocalDefId) -> ItemCtxt<'tcx> { - ItemCtxt { tcx, item_def_id } + ItemCtxt { tcx, item_def_id, tainted_by_errors: Cell::new(None) } } pub fn to_ty(&self, ast_ty: &hir::Ty<'_>) -> Ty<'tcx> { @@ -357,6 +359,13 @@ impl<'tcx> ItemCtxt<'tcx> { pub fn node(&self) -> hir::Node<'tcx> { self.tcx.hir_node(self.hir_id()) } + + fn check_tainted_by_errors(&self) -> Result<(), ErrorGuaranteed> { + match self.tainted_by_errors.get() { + Some(err) => Err(err), + None => Ok(()), + } + } } impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { @@ -492,8 +501,8 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { ty.ty_adt_def() } - fn set_tainted_by_errors(&self, _: ErrorGuaranteed) { - // There's no obvious place to track this, so just let it go. + fn set_tainted_by_errors(&self, err: ErrorGuaranteed) { + self.tainted_by_errors.set(Some(err)); } fn record_ty(&self, _hir_id: hir::HirId, _ty: Ty<'tcx>, _span: Span) { diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 3ceea3dc7ae3f..b936b0c080542 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -513,7 +513,11 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder $DIR/issue-109071.rs:16:22 + --> $DIR/issue-109071.rs:15:22 | LL | fn T() -> Option {} | ^^^^^^^^^^ diff --git a/tests/ui/associated-inherent-types/issue-109071.rs b/tests/ui/associated-inherent-types/issue-109071.rs index a897aaebc58f3..cbe8cce092457 100644 --- a/tests/ui/associated-inherent-types/issue-109071.rs +++ b/tests/ui/associated-inherent-types/issue-109071.rs @@ -9,13 +9,11 @@ impl Windows { //~ ERROR: missing generics for struct `Windows` //[no_gate]~^ ERROR: inherent associated types are unstable fn next() -> Option {} - //[with_gate]~^ ERROR type annotations needed } impl Windows { fn T() -> Option {} - //[no_gate]~^ ERROR: ambiguous associated type - //[with_gate]~^^ ERROR type annotations needed + //~^ ERROR: ambiguous associated type } fn main() {} diff --git a/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr b/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr index d413c65dccb53..a7d17e2d5ebb9 100644 --- a/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr +++ b/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr @@ -20,19 +20,20 @@ help: add missing generic argument LL | impl Windows { | +++ -error[E0282]: type annotations needed - --> $DIR/issue-109071.rs:11:18 - | -LL | fn next() -> Option {} - | ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` - -error[E0282]: type annotations needed - --> $DIR/issue-109071.rs:16:15 +error[E0223]: ambiguous associated type + --> $DIR/issue-109071.rs:15:22 | LL | fn T() -> Option {} - | ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` + | ^^^^^^^^^^ + | +help: use fully-qualified syntax + | +LL | fn T() -> Option< as IntoAsyncIterator>::Item> {} + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | fn T() -> Option< as IntoIterator>::Item> {} + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0107, E0282, E0637. +Some errors have detailed explanations: E0107, E0223, E0637. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/const-generics/issues/issue-71381.full.stderr b/tests/ui/const-generics/issues/issue-71381.full.stderr index b6460e0017fa5..5d7800746961b 100644 --- a/tests/ui/const-generics/issues/issue-71381.full.stderr +++ b/tests/ui/const-generics/issues/issue-71381.full.stderr @@ -7,7 +7,7 @@ LL | pub fn call_me $DIR/issue-71381.rs:23:40 + --> $DIR/issue-71381.rs:22:40 | LL | const FN: unsafe extern "C" fn(Args), | ^^^^ the type must not depend on the parameter `Args` diff --git a/tests/ui/const-generics/issues/issue-71381.min.stderr b/tests/ui/const-generics/issues/issue-71381.min.stderr index e16d3b7a8a469..5d7800746961b 100644 --- a/tests/ui/const-generics/issues/issue-71381.min.stderr +++ b/tests/ui/const-generics/issues/issue-71381.min.stderr @@ -7,29 +7,13 @@ LL | pub fn call_me $DIR/issue-71381.rs:23:40 + --> $DIR/issue-71381.rs:22:40 | LL | const FN: unsafe extern "C" fn(Args), | ^^^^ the type must not depend on the parameter `Args` | = note: type parameters may not be used in the type of const parameters -error: using function pointers as const generic parameters is forbidden - --> $DIR/issue-71381.rs:14:61 - | -LL | pub fn call_me(&self) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the only supported types are integers, `bool` and `char` - -error: using function pointers as const generic parameters is forbidden - --> $DIR/issue-71381.rs:23:19 - | -LL | const FN: unsafe extern "C" fn(Args), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the only supported types are integers, `bool` and `char` - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0770`. diff --git a/tests/ui/const-generics/issues/issue-71381.rs b/tests/ui/const-generics/issues/issue-71381.rs index 8a878efb42a0e..75ad4545371a7 100644 --- a/tests/ui/const-generics/issues/issue-71381.rs +++ b/tests/ui/const-generics/issues/issue-71381.rs @@ -12,8 +12,7 @@ unsafe extern "C" fn pass(args: PassArg) { impl Test { pub fn call_me(&self) { - //[min]~^ ERROR: using function pointers as const generic parameters is forbidden - //~^^ ERROR: the type of const parameters must not depend on other generic parameters + //~^ ERROR: the type of const parameters must not depend on other generic parameters self.0 = Self::trampiline:: as _ } @@ -21,8 +20,7 @@ impl Test { Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args), - //[min]~^ ERROR: using function pointers as const generic parameters is forbidden - //~^^ ERROR: the type of const parameters must not depend on other generic parameters + //~^ ERROR: the type of const parameters must not depend on other generic parameters >( args: Args, ) { diff --git a/tests/ui/const-generics/issues/issue-71611.min.stderr b/tests/ui/const-generics/issues/issue-71611.min.stderr index b01936f4d2513..6f6a9fc21a699 100644 --- a/tests/ui/const-generics/issues/issue-71611.min.stderr +++ b/tests/ui/const-generics/issues/issue-71611.min.stderr @@ -6,14 +6,6 @@ LL | fn func(outer: A) { | = note: type parameters may not be used in the type of const parameters -error: using function pointers as const generic parameters is forbidden - --> $DIR/issue-71611.rs:5:21 - | -LL | fn func(outer: A) { - | ^^^^^^^^^^^^ - | - = note: the only supported types are integers, `bool` and `char` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0770`. diff --git a/tests/ui/const-generics/issues/issue-71611.rs b/tests/ui/const-generics/issues/issue-71611.rs index c917f66818bad..9293009248218 100644 --- a/tests/ui/const-generics/issues/issue-71611.rs +++ b/tests/ui/const-generics/issues/issue-71611.rs @@ -3,8 +3,7 @@ #![cfg_attr(full, allow(incomplete_features))] fn func(outer: A) { - //[min]~^ ERROR: using function pointers as const generic parameters is forbidden - //~^^ ERROR: the type of const parameters must not depend on other generic parameters + //~^ ERROR: the type of const parameters must not depend on other generic parameters F(outer); } diff --git a/tests/ui/generic-associated-types/issue-71176.rs b/tests/ui/generic-associated-types/issue-71176.rs index e58b6f6091e75..f0e162d825f9d 100644 --- a/tests/ui/generic-associated-types/issue-71176.rs +++ b/tests/ui/generic-associated-types/issue-71176.rs @@ -9,9 +9,6 @@ impl Provider for () { struct Holder { inner: Box>, //~^ ERROR: missing generics for associated type - //~| ERROR: missing generics for associated type - //~| ERROR: missing generics for associated type - //~| ERROR: the trait `Provider` cannot be made into an object } fn main() { diff --git a/tests/ui/generic-associated-types/issue-71176.stderr b/tests/ui/generic-associated-types/issue-71176.stderr index a1913bb618bc0..ed837f3475338 100644 --- a/tests/ui/generic-associated-types/issue-71176.stderr +++ b/tests/ui/generic-associated-types/issue-71176.stderr @@ -14,57 +14,6 @@ help: add missing lifetime argument LL | inner: Box = B>>, | ++++ -error[E0107]: missing generics for associated type `Provider::A` - --> $DIR/issue-71176.rs:10:27 - | -LL | inner: Box>, - | ^ expected 1 lifetime argument - | -note: associated type defined here, with 1 lifetime parameter: `'a` - --> $DIR/issue-71176.rs:2:10 - | -LL | type A<'a>; - | ^ -- - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: add missing lifetime argument - | -LL | inner: Box = B>>, - | ++++ - -error[E0107]: missing generics for associated type `Provider::A` - --> $DIR/issue-71176.rs:10:27 - | -LL | inner: Box>, - | ^ expected 1 lifetime argument - | -note: associated type defined here, with 1 lifetime parameter: `'a` - --> $DIR/issue-71176.rs:2:10 - | -LL | type A<'a>; - | ^ -- - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: add missing lifetime argument - | -LL | inner: Box = B>>, - | ++++ - -error[E0038]: the trait `Provider` cannot be made into an object - --> $DIR/issue-71176.rs:10:14 - | -LL | inner: Box>, - | ^^^^^^^^^^^^^^^^^^^ `Provider` cannot be made into an object - | -note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/issue-71176.rs:2:10 - | -LL | trait Provider { - | -------- this trait cannot be made into an object... -LL | type A<'a>; - | ^ ...because it contains the generic associated type `A` - = help: consider moving `A` to another trait - = help: only type `()` implements the trait, consider using it directly instead - -error: aborting due to 4 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0038, E0107. -For more information about an error, try `rustc --explain E0038`. +For more information about this error, try `rustc --explain E0107`. diff --git a/tests/ui/issues/issue-3214.rs b/tests/ui/issues/issue-3214.rs index 03d8d6ba24651..b2c27f5be957c 100644 --- a/tests/ui/issues/issue-3214.rs +++ b/tests/ui/issues/issue-3214.rs @@ -5,7 +5,6 @@ fn foo() { impl Drop for Foo { //~^ ERROR struct takes 0 generic arguments but 1 generic argument - //~| ERROR `T` is not constrained fn drop(&mut self) {} } } diff --git a/tests/ui/issues/issue-3214.stderr b/tests/ui/issues/issue-3214.stderr index 26ac6d39f6014..5b57c1baf90ba 100644 --- a/tests/ui/issues/issue-3214.stderr +++ b/tests/ui/issues/issue-3214.stderr @@ -22,13 +22,7 @@ note: struct defined here, with 0 generic parameters LL | struct Foo { | ^^^ -error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates - --> $DIR/issue-3214.rs:6:10 - | -LL | impl Drop for Foo { - | ^ unconstrained type parameter - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0107, E0207, E0401. +Some errors have detailed explanations: E0107, E0401. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/layout/issue-84108.rs b/tests/ui/layout/issue-84108.rs index af21d1d6210b6..44d6ac8db72f0 100644 --- a/tests/ui/layout/issue-84108.rs +++ b/tests/ui/layout/issue-84108.rs @@ -8,8 +8,6 @@ static FOO: (dyn AsRef, u8) = ("hello", 42); const BAR: (&Path, [u8], usize) = ("hello", [], 42); //~^ ERROR cannot find type `Path` in this scope -//~| ERROR the size for values of type `[u8]` cannot be known at compilation time -//~| ERROR mismatched types static BAZ: ([u8], usize) = ([], 0); //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time diff --git a/tests/ui/layout/issue-84108.stderr b/tests/ui/layout/issue-84108.stderr index d6d7585103469..58bddb069fc7d 100644 --- a/tests/ui/layout/issue-84108.stderr +++ b/tests/ui/layout/issue-84108.stderr @@ -21,25 +21,7 @@ LL + use std::path::Path; | error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/issue-84108.rs:9:12 - | -LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42); - | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: only the last element of a tuple may have a dynamically sized type - -error[E0308]: mismatched types - --> $DIR/issue-84108.rs:9:45 - | -LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42); - | ^^ expected `[u8]`, found `[_; 0]` - | - = note: expected slice `[u8]` - found array `[_; 0]` - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/issue-84108.rs:14:13 + --> $DIR/issue-84108.rs:12:13 | LL | static BAZ: ([u8], usize) = ([], 0); | ^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -48,7 +30,7 @@ LL | static BAZ: ([u8], usize) = ([], 0); = note: only the last element of a tuple may have a dynamically sized type error[E0308]: mismatched types - --> $DIR/issue-84108.rs:14:30 + --> $DIR/issue-84108.rs:12:30 | LL | static BAZ: ([u8], usize) = ([], 0); | ^^ expected `[u8]`, found `[_; 0]` @@ -56,7 +38,7 @@ LL | static BAZ: ([u8], usize) = ([], 0); = note: expected slice `[u8]` found array `[_; 0]` -error: aborting due to 6 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0277, E0308, E0412. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs b/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs index 8012cb652bd88..f6aa39df27d8b 100644 --- a/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs +++ b/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs @@ -5,4 +5,3 @@ struct Apple((Apple, Option(Banana ? Citron))); //~| ERROR expected one of `)` or `,`, found `Citron` //~| ERROR cannot find type `Citron` in this scope [E0412] //~| ERROR parenthesized type parameters may only be used with a `Fn` trait [E0214] -//~| ERROR recursive type `Apple` has infinite size [E0072] diff --git a/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr b/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr index b0d8b03ae08c3..71d2d7b797582 100644 --- a/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr +++ b/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr @@ -34,18 +34,7 @@ help: use angle brackets instead LL | struct Apple((Apple, Option)); | ~ ~ -error[E0072]: recursive type `Apple` has infinite size - --> $DIR/issue-103748-ICE-wrong-braces.rs:3:1 - | -LL | struct Apple((Apple, Option(Banana ? Citron))); - | ^^^^^^^^^^^^ ----- recursive without indirection - | -help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle - | -LL | struct Apple((Box, Option(Banana ? Citron))); - | ++++ + - -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0072, E0214, E0412. -For more information about an error, try `rustc --explain E0072`. +Some errors have detailed explanations: E0214, E0412. +For more information about an error, try `rustc --explain E0214`. diff --git a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs index 4cbc36f4650b9..52ecbcc9e2cb3 100644 --- a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs +++ b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs @@ -39,7 +39,6 @@ impl> Struct {} trait YetAnotherTrait {} impl, U> YetAnotherTrait for Struct {} //~^ ERROR struct takes 1 generic argument but 2 generic arguments were supplied -//~| ERROR `U` is not constrained fn main() { diff --git a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr index 3c2b726fccea4..e7ceb7372bfca 100644 --- a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr +++ b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr @@ -116,13 +116,7 @@ error[E0207]: the type parameter `S` is not constrained by the impl trait, self LL | impl Trait for () {} | ^ unconstrained type parameter -error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates - --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:40:35 - | -LL | impl, U> YetAnotherTrait for Struct {} - | ^ unconstrained type parameter - -error: aborting due to 10 previous errors +error: aborting due to 9 previous errors Some errors have detailed explanations: E0107, E0207. For more information about an error, try `rustc --explain E0107`.