Skip to content

Commit

Permalink
Delay bug to deduplicate diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Nov 22, 2022
1 parent 0a95878 commit df5f247
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
18 changes: 10 additions & 8 deletions compiler/rustc_hir_analysis/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -927,6 +927,7 @@ fn compare_number_of_generics<'tcx>(
impl_: &ty::AssocItem,
trait_: &ty::AssocItem,
trait_span: Option<Span>,
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();
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ LL | fn bar<T>() -> 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<T>() -> 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`.

0 comments on commit df5f247

Please sign in to comment.