Skip to content

Commit df5f247

Browse files
Delay bug to deduplicate diagnostics
1 parent 0a95878 commit df5f247

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

compiler/rustc_hir_analysis/src/check/compare_method.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ pub(crate) fn compare_impl_method<'tcx>(
4949
return;
5050
}
5151

52-
if let Err(_) = compare_number_of_generics(tcx, impl_m, trait_m, trait_item_span) {
52+
if let Err(_) = compare_number_of_generics(tcx, impl_m, trait_m, trait_item_span, false) {
5353
return;
5454
}
5555

56-
if let Err(_) = compare_generic_param_kinds(tcx, impl_m, trait_m) {
56+
if let Err(_) = compare_generic_param_kinds(tcx, impl_m, trait_m, false) {
5757
return;
5858
}
5959

@@ -349,8 +349,8 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
349349
let param_env = tcx.param_env(def_id);
350350

351351
// First, check a few of the same thing as `compare_impl_method`, just so we don't ICE during substitutions later.
352-
compare_number_of_generics(tcx, impl_m, trait_m, tcx.hir().span_if_local(impl_m.def_id))?;
353-
compare_generic_param_kinds(tcx, impl_m, trait_m)?;
352+
compare_number_of_generics(tcx, impl_m, trait_m, tcx.hir().span_if_local(impl_m.def_id), true)?;
353+
compare_generic_param_kinds(tcx, impl_m, trait_m, true)?;
354354

355355
let trait_to_impl_substs = impl_trait_ref.substs;
356356

@@ -927,6 +927,7 @@ fn compare_number_of_generics<'tcx>(
927927
impl_: &ty::AssocItem,
928928
trait_: &ty::AssocItem,
929929
trait_span: Option<Span>,
930+
delay: bool,
930931
) -> Result<(), ErrorGuaranteed> {
931932
let trait_own_counts = tcx.generics_of(trait_.def_id).own_counts();
932933
let impl_own_counts = tcx.generics_of(impl_.def_id).own_counts();
@@ -1056,7 +1057,7 @@ fn compare_number_of_generics<'tcx>(
10561057
err.span_label(*span, "`impl Trait` introduces an implicit type parameter");
10571058
}
10581059

1059-
let reported = err.emit();
1060+
let reported = err.emit_unless(delay);
10601061
err_occurred = Some(reported);
10611062
}
10621063
}
@@ -1308,6 +1309,7 @@ fn compare_generic_param_kinds<'tcx>(
13081309
tcx: TyCtxt<'tcx>,
13091310
impl_item: &ty::AssocItem,
13101311
trait_item: &ty::AssocItem,
1312+
delay: bool,
13111313
) -> Result<(), ErrorGuaranteed> {
13121314
assert_eq!(impl_item.kind, trait_item.kind);
13131315

@@ -1365,7 +1367,7 @@ fn compare_generic_param_kinds<'tcx>(
13651367
err.span_label(impl_header_span, "");
13661368
err.span_label(param_impl_span, make_param_message("found", param_impl));
13671369

1368-
let reported = err.emit();
1370+
let reported = err.emit_unless(delay);
13691371
return Err(reported);
13701372
}
13711373
}
@@ -1491,9 +1493,9 @@ pub(crate) fn compare_ty_impl<'tcx>(
14911493
debug!("compare_impl_type(impl_trait_ref={:?})", impl_trait_ref);
14921494

14931495
let _: Result<(), ErrorGuaranteed> = (|| {
1494-
compare_number_of_generics(tcx, impl_ty, trait_ty, trait_item_span)?;
1496+
compare_number_of_generics(tcx, impl_ty, trait_ty, trait_item_span, false)?;
14951497

1496-
compare_generic_param_kinds(tcx, impl_ty, trait_ty)?;
1498+
compare_generic_param_kinds(tcx, impl_ty, trait_ty, false)?;
14971499

14981500
let sp = tcx.def_span(impl_ty.def_id);
14991501
compare_type_predicate_entailment(tcx, impl_ty, sp, trait_ty, impl_trait_ref)?;

src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ trait Foo {
1010
impl Foo for S {
1111
fn bar() -> impl Sized {}
1212
//~^ ERROR method `bar` has 0 type parameters but its trait declaration has 1 type parameter
13-
//~| ERROR method `bar` has 0 type parameters but its trait declaration has 1 type parameter
1413
}
1514

1615
fn main() {

src/test/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ LL | fn bar<T>() -> impl Sized;
77
LL | fn bar() -> impl Sized {}
88
| ^ found 0 type parameters
99

10-
error[E0049]: method `bar` has 0 type parameters but its trait declaration has 1 type parameter
11-
--> $DIR/trait-more-generics-than-impl.rs:11:11
12-
|
13-
LL | fn bar<T>() -> impl Sized;
14-
| - expected 1 type parameter
15-
...
16-
LL | fn bar() -> impl Sized {}
17-
| ^ found 0 type parameters
18-
19-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2011

2112
For more information about this error, try `rustc --explain E0049`.

0 commit comments

Comments
 (0)