diff options
| author | Michael Goulet <michael@errs.io> | 2022-08-13 14:10:07 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-13 14:10:07 -0700 |
| commit | 9ab54df8d7c029fc0bb813028d8fda1e8f75294c (patch) | |
| tree | ead15578de10fc1e6ff8a726020786e076a666fe | |
| parent | 2126cc62fbc97f9bb19d3b6aa3f101955c0a8c8a (diff) | |
| parent | f94220f68eeef7fb0a4a36f7e95f599b56e2b161 (diff) | |
| download | rust-9ab54df8d7c029fc0bb813028d8fda1e8f75294c.tar.gz rust-9ab54df8d7c029fc0bb813028d8fda1e8f75294c.zip | |
Rollup merge of #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 :see_no_evil: Fixes #100360 Fixes #89851
3 files changed, 27 insertions, 7 deletions
diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index ed4d8c95d1e..161c89e3242 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -839,17 +839,12 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let mut promoted_operand = |ty, span| { promoted.span = span; promoted.local_decls[RETURN_PLACE] = LocalDecl::new(ty, span); + let substs = tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def.did)); let _const = tcx.mk_const(ty::ConstS { ty, kind: ty::ConstKind::Unevaluated(ty::Unevaluated { def, - substs: InternalSubsts::for_item(tcx, def.did, |param, _| { - if let ty::GenericParamDefKind::Lifetime = param.kind { - tcx.lifetimes.re_erased.into() - } else { - tcx.mk_param_from_def(param) - } - }), + substs, promoted: Some(promoted_id), }), }); diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-100360.rs b/src/test/ui/const-generics/generic_const_exprs/issue-100360.rs new file mode 100644 index 00000000000..5572f1f88df --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-100360.rs @@ -0,0 +1,13 @@ +// check-pass +// (this requires debug assertions) + +#![feature(adt_const_params)] +#![allow(incomplete_features)] + +fn foo<const B: &'static bool>(arg: &'static bool) -> bool { + B == arg +} + +fn main() { + foo::<{ &true }>(&false); +} diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-89851.rs b/src/test/ui/const-generics/generic_const_exprs/issue-89851.rs new file mode 100644 index 00000000000..cde849d9017 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-89851.rs @@ -0,0 +1,12 @@ +// check-pass +// (this requires debug assertions) + +#![feature(adt_const_params)] +#![allow(incomplete_features)] + +pub const BAR: () = ice::<"">(); +pub const fn ice<const N: &'static str>() { + &10; +} + +fn main() {} |
