Skip to content

Commit 9ab54df

Browse files
Rollup merge of rust-lang#100438 - compiler-errors:issue-100360, r=lcnr
Erase regions better in `promote_candidate` Use `tcx.erase_regions` instead of manually walking through the substs.... this also makes the code slightly simpler 🙈 Fixes rust-lang#100360 Fixes rust-lang#89851
2 parents 2126cc6 + f94220f commit 9ab54df

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

compiler/rustc_const_eval/src/transform/promote_consts.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -839,17 +839,12 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
839839
let mut promoted_operand = |ty, span| {
840840
promoted.span = span;
841841
promoted.local_decls[RETURN_PLACE] = LocalDecl::new(ty, span);
842+
let substs = tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def.did));
842843
let _const = tcx.mk_const(ty::ConstS {
843844
ty,
844845
kind: ty::ConstKind::Unevaluated(ty::Unevaluated {
845846
def,
846-
substs: InternalSubsts::for_item(tcx, def.did, |param, _| {
847-
if let ty::GenericParamDefKind::Lifetime = param.kind {
848-
tcx.lifetimes.re_erased.into()
849-
} else {
850-
tcx.mk_param_from_def(param)
851-
}
852-
}),
847+
substs,
853848
promoted: Some(promoted_id),
854849
}),
855850
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-pass
2+
// (this requires debug assertions)
3+
4+
#![feature(adt_const_params)]
5+
#![allow(incomplete_features)]
6+
7+
fn foo<const B: &'static bool>(arg: &'static bool) -> bool {
8+
B == arg
9+
}
10+
11+
fn main() {
12+
foo::<{ &true }>(&false);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-pass
2+
// (this requires debug assertions)
3+
4+
#![feature(adt_const_params)]
5+
#![allow(incomplete_features)]
6+
7+
pub const BAR: () = ice::<"">();
8+
pub const fn ice<const N: &'static str>() {
9+
&10;
10+
}
11+
12+
fn main() {}

0 commit comments

Comments
 (0)