1
Fork 0

don't leave assoc const unnormalized due to unconstrained params

This commit is contained in:
Lukas Markeffsky 2025-02-21 18:34:14 +01:00
parent a825e37fe4
commit 7fea935ec5
5 changed files with 14 additions and 12 deletions

View file

@ -12,7 +12,7 @@ use std::borrow::Cow;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::sync::Arc; use std::sync::Arc;
use rustc_errors::{Applicability, Diag, EmissionGuarantee}; use rustc_errors::{Applicability, Diag, EmissionGuarantee, ErrorGuaranteed};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::HirId; use rustc_hir::HirId;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
@ -996,4 +996,7 @@ pub enum CodegenObligationError {
/// but was included during typeck due to the trivial_bounds feature. /// but was included during typeck due to the trivial_bounds feature.
Unimplemented, Unimplemented,
FulfillmentError, FulfillmentError,
/// The selected impl has unconstrained generic parameters. This will emit an error
/// during impl WF checking.
UnconstrainedParam(ErrorGuaranteed),
} }

View file

@ -80,16 +80,14 @@ pub(crate) fn codegen_select_candidate<'tcx>(
// but never resolved, causing the return value of a query to contain inference // but never resolved, causing the return value of a query to contain inference
// vars. We do not have a concept for this and will in fact ICE in stable hashing // vars. We do not have a concept for this and will in fact ICE in stable hashing
// of the return value. So bail out instead. // of the return value. So bail out instead.
match impl_source { let guar = match impl_source {
ImplSource::UserDefined(impl_) => { ImplSource::UserDefined(impl_) => tcx.dcx().span_delayed_bug(
tcx.dcx().span_delayed_bug( tcx.def_span(impl_.impl_def_id),
tcx.def_span(impl_.impl_def_id), "this impl has unconstrained generic parameters",
"this impl has unconstrained generic parameters", ),
);
}
_ => unreachable!(), _ => unreachable!(),
} };
return Err(CodegenObligationError::FulfillmentError); return Err(CodegenObligationError::UnconstrainedParam(guar));
} }
Ok(&*tcx.arena.alloc(impl_source)) Ok(&*tcx.arena.alloc(impl_source))

View file

@ -112,6 +112,7 @@ fn resolve_associated_item<'tcx>(
| CodegenObligationError::Unimplemented | CodegenObligationError::Unimplemented
| CodegenObligationError::FulfillmentError, | CodegenObligationError::FulfillmentError,
) => return Ok(None), ) => return Ok(None),
Err(CodegenObligationError::UnconstrainedParam(guar)) => return Err(guar),
}; };
// Now that we know which impl is being used, we can dispatch to // Now that we know which impl is being used, we can dispatch to

View file

@ -15,4 +15,4 @@ impl<C: ?Sized> A for u8 { //~ ERROR: the type parameter `C` is not constrained
} }
#[rustc_layout(debug)] #[rustc_layout(debug)]
struct S([u8; <u8 as A>::B]); //~ ERROR: the type `[u8; <u8 as A>::B]` has an unknown layout struct S([u8; <u8 as A>::B]); //~ ERROR: the type has an unknown layout

View file

@ -4,7 +4,7 @@ error[E0207]: the type parameter `C` is not constrained by the impl trait, self
LL | impl<C: ?Sized> A for u8 { LL | impl<C: ?Sized> A for u8 {
| ^ unconstrained type parameter | ^ unconstrained type parameter
error: the type `[u8; <u8 as A>::B]` has an unknown layout error: the type has an unknown layout
--> $DIR/unconstrained-param-ice-137308.rs:18:1 --> $DIR/unconstrained-param-ice-137308.rs:18:1
| |
LL | struct S([u8; <u8 as A>::B]); LL | struct S([u8; <u8 as A>::B]);