1
Fork 0

Delay bug to deduplicate diagnostics

This commit is contained in:
Michael Goulet 2022-11-22 01:36:35 +00:00
parent 0a95878972
commit df5f247a5c
3 changed files with 11 additions and 19 deletions

View file

@ -49,11 +49,11 @@ pub(crate) fn compare_impl_method<'tcx>(
return; 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; 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; return;
} }
@ -349,8 +349,8 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
let param_env = tcx.param_env(def_id); 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. // 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_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)?; compare_generic_param_kinds(tcx, impl_m, trait_m, true)?;
let trait_to_impl_substs = impl_trait_ref.substs; let trait_to_impl_substs = impl_trait_ref.substs;
@ -927,6 +927,7 @@ fn compare_number_of_generics<'tcx>(
impl_: &ty::AssocItem, impl_: &ty::AssocItem,
trait_: &ty::AssocItem, trait_: &ty::AssocItem,
trait_span: Option<Span>, trait_span: Option<Span>,
delay: bool,
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
let trait_own_counts = tcx.generics_of(trait_.def_id).own_counts(); let trait_own_counts = tcx.generics_of(trait_.def_id).own_counts();
let impl_own_counts = tcx.generics_of(impl_.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"); 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); err_occurred = Some(reported);
} }
} }
@ -1308,6 +1309,7 @@ fn compare_generic_param_kinds<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
impl_item: &ty::AssocItem, impl_item: &ty::AssocItem,
trait_item: &ty::AssocItem, trait_item: &ty::AssocItem,
delay: bool,
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
assert_eq!(impl_item.kind, trait_item.kind); 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(impl_header_span, "");
err.span_label(param_impl_span, make_param_message("found", param_impl)); 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); return Err(reported);
} }
} }
@ -1491,9 +1493,9 @@ pub(crate) fn compare_ty_impl<'tcx>(
debug!("compare_impl_type(impl_trait_ref={:?})", impl_trait_ref); debug!("compare_impl_type(impl_trait_ref={:?})", impl_trait_ref);
let _: Result<(), ErrorGuaranteed> = (|| { 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); let sp = tcx.def_span(impl_ty.def_id);
compare_type_predicate_entailment(tcx, impl_ty, sp, trait_ty, impl_trait_ref)?; compare_type_predicate_entailment(tcx, impl_ty, sp, trait_ty, impl_trait_ref)?;

View file

@ -10,7 +10,6 @@ trait Foo {
impl Foo for S { impl Foo for S {
fn bar() -> impl Sized {} 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
//~| ERROR method `bar` has 0 type parameters but its trait declaration has 1 type parameter
} }
fn main() { fn main() {

View file

@ -7,15 +7,6 @@ LL | fn bar<T>() -> impl Sized;
LL | fn bar() -> impl Sized {} LL | fn bar() -> impl Sized {}
| ^ found 0 type parameters | ^ found 0 type parameters
error[E0049]: method `bar` has 0 type parameters but its trait declaration has 1 type parameter error: aborting due to previous error
--> $DIR/trait-more-generics-than-impl.rs:11:11
|
LL | fn bar<T>() -> impl Sized;
| - expected 1 type parameter
...
LL | fn bar() -> impl Sized {}
| ^ found 0 type parameters
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0049`. For more information about this error, try `rustc --explain E0049`.