Skip to content

Commit 7fea935

Browse files
author
Lukas Markeffsky
committed
don't leave assoc const unnormalized due to unconstrained params
1 parent a825e37 commit 7fea935

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

compiler/rustc_middle/src/traits/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::borrow::Cow;
1212
use std::hash::{Hash, Hasher};
1313
use std::sync::Arc;
1414

15-
use rustc_errors::{Applicability, Diag, EmissionGuarantee};
15+
use rustc_errors::{Applicability, Diag, EmissionGuarantee, ErrorGuaranteed};
1616
use rustc_hir as hir;
1717
use rustc_hir::HirId;
1818
use rustc_hir::def_id::DefId;
@@ -996,4 +996,7 @@ pub enum CodegenObligationError {
996996
/// but was included during typeck due to the trivial_bounds feature.
997997
Unimplemented,
998998
FulfillmentError,
999+
/// The selected impl has unconstrained generic parameters. This will emit an error
1000+
/// during impl WF checking.
1001+
UnconstrainedParam(ErrorGuaranteed),
9991002
}

compiler/rustc_traits/src/codegen.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,14 @@ pub(crate) fn codegen_select_candidate<'tcx>(
8080
// but never resolved, causing the return value of a query to contain inference
8181
// vars. We do not have a concept for this and will in fact ICE in stable hashing
8282
// of the return value. So bail out instead.
83-
match impl_source {
84-
ImplSource::UserDefined(impl_) => {
85-
tcx.dcx().span_delayed_bug(
86-
tcx.def_span(impl_.impl_def_id),
87-
"this impl has unconstrained generic parameters",
88-
);
89-
}
83+
let guar = match impl_source {
84+
ImplSource::UserDefined(impl_) => tcx.dcx().span_delayed_bug(
85+
tcx.def_span(impl_.impl_def_id),
86+
"this impl has unconstrained generic parameters",
87+
),
9088
_ => unreachable!(),
91-
}
92-
return Err(CodegenObligationError::FulfillmentError);
89+
};
90+
return Err(CodegenObligationError::UnconstrainedParam(guar));
9391
}
9492

9593
Ok(&*tcx.arena.alloc(impl_source))

compiler/rustc_ty_utils/src/instance.rs

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ fn resolve_associated_item<'tcx>(
112112
| CodegenObligationError::Unimplemented
113113
| CodegenObligationError::FulfillmentError,
114114
) => return Ok(None),
115+
Err(CodegenObligationError::UnconstrainedParam(guar)) => return Err(guar),
115116
};
116117

117118
// Now that we know which impl is being used, we can dispatch to

tests/ui/layout/unconstrained-param-ice-137308.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ impl<C: ?Sized> A for u8 { //~ ERROR: the type parameter `C` is not constrained
1515
}
1616

1717
#[rustc_layout(debug)]
18-
struct S([u8; <u8 as A>::B]); //~ ERROR: the type `[u8; <u8 as A>::B]` has an unknown layout
18+
struct S([u8; <u8 as A>::B]); //~ ERROR: the type has an unknown layout

tests/ui/layout/unconstrained-param-ice-137308.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0207]: the type parameter `C` is not constrained by the impl trait, self
44
LL | impl<C: ?Sized> A for u8 {
55
| ^ unconstrained type parameter
66

7-
error: the type `[u8; <u8 as A>::B]` has an unknown layout
7+
error: the type has an unknown layout
88
--> $DIR/unconstrained-param-ice-137308.rs:18:1
99
|
1010
LL | struct S([u8; <u8 as A>::B]);

0 commit comments

Comments
 (0)