From df5f247a5c5432fc85a84cafb8461fafd01cf6ae Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 22 Nov 2022 01:36:35 +0000 Subject: [PATCH] Delay bug to deduplicate diagnostics --- .../src/check/compare_method.rs | 18 ++++++++++-------- .../in-trait/trait-more-generics-than-impl.rs | 1 - .../trait-more-generics-than-impl.stderr | 11 +---------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/compare_method.rs b/compiler/rustc_hir_analysis/src/check/compare_method.rs index 10089453ed6ca..6a17847875877 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_method.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_method.rs @@ -49,11 +49,11 @@ pub(crate) fn compare_impl_method<'tcx>( return; } - if let Err(_) = compare_number_of_generics(tcx, impl_m, trait_m, trait_item_span) { + if let Err(_) = compare_number_of_generics(tcx, impl_m, trait_m, trait_item_span, false) { return; } - if let Err(_) = compare_generic_param_kinds(tcx, impl_m, trait_m) { + if let Err(_) = compare_generic_param_kinds(tcx, impl_m, trait_m, false) { return; } @@ -349,8 +349,8 @@ pub fn collect_trait_impl_trait_tys<'tcx>( let param_env = tcx.param_env(def_id); // First, check a few of the same thing as `compare_impl_method`, just so we don't ICE during substitutions later. - compare_number_of_generics(tcx, impl_m, trait_m, tcx.hir().span_if_local(impl_m.def_id))?; - compare_generic_param_kinds(tcx, impl_m, trait_m)?; + compare_number_of_generics(tcx, impl_m, trait_m, tcx.hir().span_if_local(impl_m.def_id), true)?; + compare_generic_param_kinds(tcx, impl_m, trait_m, true)?; let trait_to_impl_substs = impl_trait_ref.substs; @@ -927,6 +927,7 @@ fn compare_number_of_generics<'tcx>( impl_: &ty::AssocItem, trait_: &ty::AssocItem, trait_span: Option, + delay: bool, ) -> Result<(), ErrorGuaranteed> { let trait_own_counts = tcx.generics_of(trait_.def_id).own_counts(); let impl_own_counts = tcx.generics_of(impl_.def_id).own_counts(); @@ -1056,7 +1057,7 @@ fn compare_number_of_generics<'tcx>( err.span_label(*span, "`impl Trait` introduces an implicit type parameter"); } - let reported = err.emit(); + let reported = err.emit_unless(delay); err_occurred = Some(reported); } } @@ -1308,6 +1309,7 @@ fn compare_generic_param_kinds<'tcx>( tcx: TyCtxt<'tcx>, impl_item: &ty::AssocItem, trait_item: &ty::AssocItem, + delay: bool, ) -> Result<(), ErrorGuaranteed> { assert_eq!(impl_item.kind, trait_item.kind); @@ -1365,7 +1367,7 @@ fn compare_generic_param_kinds<'tcx>( err.span_label(impl_header_span, ""); err.span_label(param_impl_span, make_param_message("found", param_impl)); - let reported = err.emit(); + let reported = err.emit_unless(delay); return Err(reported); } } @@ -1491,9 +1493,9 @@ pub(crate) fn compare_ty_impl<'tcx>( debug!("compare_impl_type(impl_trait_ref={:?})", impl_trait_ref); let _: Result<(), ErrorGuaranteed> = (|| { - compare_number_of_generics(tcx, impl_ty, trait_ty, trait_item_span)?; + compare_number_of_generics(tcx, impl_ty, trait_ty, trait_item_span, false)?; - compare_generic_param_kinds(tcx, impl_ty, trait_ty)?; + compare_generic_param_kinds(tcx, impl_ty, trait_ty, false)?; let sp = tcx.def_span(impl_ty.def_id); compare_type_predicate_entailment(tcx, impl_ty, sp, trait_ty, impl_trait_ref)?; diff --git a/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs b/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs index 608006203d90b..0bbe50ea6fd37 100644 --- a/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs +++ b/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs @@ -10,7 +10,6 @@ trait Foo { impl Foo for S { fn bar() -> impl Sized {} //~^ ERROR method `bar` has 0 type parameters but its trait declaration has 1 type parameter - //~| ERROR method `bar` has 0 type parameters but its trait declaration has 1 type parameter } fn main() { diff --git a/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr b/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr index acde1f7654b76..8ff54cad95139 100644 --- a/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr +++ b/src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr @@ -7,15 +7,6 @@ LL | fn bar() -> impl Sized; LL | fn bar() -> impl Sized {} | ^ found 0 type parameters -error[E0049]: method `bar` has 0 type parameters but its trait declaration has 1 type parameter - --> $DIR/trait-more-generics-than-impl.rs:11:11 - | -LL | fn bar() -> impl Sized; - | - expected 1 type parameter -... -LL | fn bar() -> impl Sized {} - | ^ found 0 type parameters - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0049`.