Skip to content

Commit

Permalink
Move check for error in impl header outside of reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Mar 22, 2024
1 parent 1447f9d commit c5a1a67
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/rustc_trait_selection/src/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,6 @@ fn report_conflicting_impls<'tcx>(
impl_span: Span,
err: &mut Diag<'_, G>,
) {
if (overlap.trait_ref, overlap.self_ty).references_error() {
err.downgrade_to_delayed_bug();
}

match tcx.span_of_impl(overlap.with_impl) {
Ok(span) => {
err.span_label(span, "first implementation here");
Expand Down Expand Up @@ -458,6 +454,11 @@ fn report_conflicting_impls<'tcx>(
)
});

// Don't report overlap errors if the header references error
if let Err(err) = (overlap.trait_ref, overlap.self_ty).error_reported() {
return Err(err);
}

match used_to_be_allowed {
None => {
let reported = if overlap.with_impl.is_local()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ compile-flags: -Znext-solver

trait ToUnit<'a> {
type Unit;
}

impl<T> ToUnit for *const T {}
//~^ ERROR implicit elided lifetime not allowed here

trait Overlap<T> {}

impl<T> Overlap<T> for T {}
impl<T> Overlap<for<'a> fn(<*const T as ToUnit<'a>>::Unit)> for T {}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0726]: implicit elided lifetime not allowed here
--> $DIR/skip-reporting-if-references-err.rs:7:9
|
LL | impl<T> ToUnit for *const T {}
| ^^^^^^ expected lifetime parameter
|
help: indicate the anonymous lifetime
|
LL | impl<T> ToUnit<'_> for *const T {}
| ++++

WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:14 ~ skip_reporting_if_references_err[c8da]::{impl#2}::'a), "'a")], def_id: DefId(0:5 ~ skip_reporting_if_references_err[c8da]::ToUnit::Unit) }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:14 ~ skip_reporting_if_references_err[c8da]::{impl#2}::'a), "'a")], def_id: DefId(0:5 ~ skip_reporting_if_references_err[c8da]::ToUnit::Unit) }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:14 ~ skip_reporting_if_references_err[c8da]::{impl#2}::'a), "'a")], def_id: DefId(0:5 ~ skip_reporting_if_references_err[c8da]::ToUnit::Unit) }
error: aborting due to 1 previous error

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

0 comments on commit c5a1a67

Please sign in to comment.