Skip to content

Commit 9174edb

Browse files
Delay overlap errors if errors are involved
1 parent 322c7b6 commit 9174edb

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::traits::{
2222
use rustc_data_structures::fx::FxIndexSet;
2323
use rustc_errors::{error_code, DelayDm, Diagnostic};
2424
use rustc_hir::def_id::{DefId, LocalDefId};
25-
use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt};
25+
use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitableExt};
2626
use rustc_middle::ty::{InternalSubsts, SubstsRef};
2727
use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
2828
use rustc_session::lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS;
@@ -350,6 +350,10 @@ fn report_conflicting_impls<'tcx>(
350350
impl_span: Span,
351351
err: &mut Diagnostic,
352352
) {
353+
if (overlap.trait_ref, overlap.self_ty).references_error() {
354+
err.downgrade_to_delayed_bug();
355+
}
356+
353357
match tcx.span_of_impl(overlap.with_impl) {
354358
Ok(span) => {
355359
err.span_label(span, "first implementation here");

tests/ui/specialization/min_specialization/bad-const-wf-doesnt-specialize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
struct S<const L: usize>;
77

88
impl<const N: i32> Copy for S<N> {}
9+
//~^ ERROR the constant `N` is not of type `usize`
910
impl<const M: usize> Copy for S<M> {}
10-
//~^ ERROR conflicting implementations of trait `Copy` for type `S<[const error]>`
1111

1212
fn main() {}

tests/ui/specialization/min_specialization/bad-const-wf-doesnt-specialize.stderr

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
error[E0119]: conflicting implementations of trait `Copy` for type `S<[const error]>`
2-
--> $DIR/bad-const-wf-doesnt-specialize.rs:9:1
1+
error: the constant `N` is not of type `usize`
2+
--> $DIR/bad-const-wf-doesnt-specialize.rs:8:29
33
|
44
LL | impl<const N: i32> Copy for S<N> {}
5-
| -------------------------------- first implementation here
6-
LL | impl<const M: usize> Copy for S<M> {}
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `S<[const error]>`
5+
| ^^^^
6+
|
7+
note: required by a bound in `S`
8+
--> $DIR/bad-const-wf-doesnt-specialize.rs:6:10
9+
|
10+
LL | struct S<const L: usize>;
11+
| ^^^^^^^^^^^^^^ required by this bound in `S`
812

913
error: aborting due to previous error
1014

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

0 commit comments

Comments
 (0)