Skip to content

Commit dd7ec37

Browse files
oli-obkfee1-dead
authored andcommitted
Start poking ICEs until they melt
1 parent 69e6e63 commit dd7ec37

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

compiler/rustc_middle/src/ty/fast_reject.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ impl DeepRejectCtxt {
221221
(GenericArgKind::Const(obl), GenericArgKind::Const(imp)) => {
222222
self.consts_may_unify(obl, imp)
223223
}
224+
(GenericArgKind::Constness(obl), GenericArgKind::Constness(imp)) => {
225+
self.constness_may_unify(obl, imp)
226+
}
224227
_ => bug!("kind mismatch: {obligation_arg} {impl_arg}"),
225228
}
226229
}
@@ -402,4 +405,19 @@ impl DeepRejectCtxt {
402405
}
403406
}
404407
}
408+
409+
pub fn constness_may_unify(
410+
self,
411+
obligation_ct: ty::ConstnessArg,
412+
impl_ct: ty::ConstnessArg,
413+
) -> bool {
414+
match (obligation_ct, impl_ct) {
415+
(_, ty::ConstnessArg::Param) => true,
416+
(ty::ConstnessArg::Param, _) => match self.treat_obligation_params {
417+
TreatParams::AsPlaceholder => false,
418+
TreatParams::AsInfer => true,
419+
},
420+
_ => obligation_ct == impl_ct,
421+
}
422+
}
405423
}

compiler/rustc_middle/src/ty/generics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ impl<'tcx> Generics {
238238
}
239239
}
240240

241+
/// Returns the `ConstnessArg`
242+
pub fn has_constness_param(&'tcx self) -> bool {
243+
self.params.iter().any(|param| matches!(param.kind, ty::GenericParamDefKind::Constness))
244+
}
245+
241246
/// Returns `true` if `params` has `impl Trait`.
242247
pub fn has_impl_trait(&'tcx self) -> bool {
243248
self.params.iter().any(|param| {

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
573573
// TODO: fall back to `Not`?
574574
None => ty::ConstnessArg::Param,
575575
Some(context) => {
576-
if tcx.hir().body_const_context(context.expect_local()).is_some() {
577-
ty::ConstnessArg::Required
576+
if tcx.generics_of(context).has_constness_param() {
577+
ty::ConstnessArg::Param
578578
} else {
579+
// TODO: should use `Required` if we're in a const context
580+
// like `const`/`static` item initializers.
579581
ty::ConstnessArg::Not
580582
}
581583
}

0 commit comments

Comments
 (0)