Skip to content

Commit cb6a1c8

Browse files
Rollup merge of #122894 - compiler-errors:downgrade, r=lcnr
Move check for error in impl header outside of reporting Fixes #121006 r? lcnr test location kinda sucks, can move it if needed
2 parents 8873ca5 + 5333f2a commit cb6a1c8

File tree

4 files changed

+65
-4
lines changed

4 files changed

+65
-4
lines changed

compiler/rustc_trait_selection/src/traits/specialize/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,6 @@ fn report_conflicting_impls<'tcx>(
407407
impl_span: Span,
408408
err: &mut Diag<'_, G>,
409409
) {
410-
if (overlap.trait_ref, overlap.self_ty).references_error() {
411-
err.downgrade_to_delayed_bug();
412-
}
413-
414410
match tcx.span_of_impl(overlap.with_impl) {
415411
Ok(span) => {
416412
err.span_label(span, "first implementation here");
@@ -463,6 +459,11 @@ fn report_conflicting_impls<'tcx>(
463459
)
464460
});
465461

462+
// Don't report overlap errors if the header references error
463+
if let Err(err) = (overlap.trait_ref, overlap.self_ty).error_reported() {
464+
return Err(err);
465+
}
466+
466467
match used_to_be_allowed {
467468
None => {
468469
let reported = if overlap.with_impl.is_local()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0726]: implicit elided lifetime not allowed here
2+
--> $DIR/skip-reporting-if-references-err.rs:10:9
3+
|
4+
LL | impl<T> ToUnit for T {}
5+
| ^^^^^^ expected lifetime parameter
6+
|
7+
help: indicate the anonymous lifetime
8+
|
9+
LL | impl<T> ToUnit<'_> for T {}
10+
| ++++
11+
12+
error[E0277]: the trait bound `for<'a> (): ToUnit<'a>` is not satisfied
13+
--> $DIR/skip-reporting-if-references-err.rs:15:29
14+
|
15+
LL | impl Overlap for for<'a> fn(<() as ToUnit<'a>>::Unit) {}
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> ToUnit<'a>` is not implemented for `()`
17+
18+
error[E0277]: the trait bound `for<'a> (): ToUnit<'a>` is not satisfied
19+
--> $DIR/skip-reporting-if-references-err.rs:15:18
20+
|
21+
LL | impl Overlap for for<'a> fn(<() as ToUnit<'a>>::Unit) {}
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> ToUnit<'a>` is not implemented for `()`
23+
24+
error: aborting due to 3 previous errors
25+
26+
Some errors have detailed explanations: E0277, E0726.
27+
For more information about an error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0726]: implicit elided lifetime not allowed here
2+
--> $DIR/skip-reporting-if-references-err.rs:10:9
3+
|
4+
LL | impl<T> ToUnit for T {}
5+
| ^^^^^^ expected lifetime parameter
6+
|
7+
help: indicate the anonymous lifetime
8+
|
9+
LL | impl<T> ToUnit<'_> for T {}
10+
| ++++
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0726`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Regression test for #121006.
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
5+
6+
trait ToUnit<'a> {
7+
type Unit;
8+
}
9+
10+
impl<T> ToUnit for T {}
11+
//~^ ERROR implicit elided lifetime not allowed here
12+
13+
trait Overlap {}
14+
impl<U> Overlap for fn(U) {}
15+
impl Overlap for for<'a> fn(<() as ToUnit<'a>>::Unit) {}
16+
//[current]~^ ERROR the trait bound `for<'a> (): ToUnit<'a>` is not satisfied
17+
//[current]~| ERROR the trait bound `for<'a> (): ToUnit<'a>` is not satisfied
18+
19+
fn main() {}

0 commit comments

Comments
 (0)