]> git.lizzy.rs Git - rust.git/commitdiff
Erase regions better in promote_candidate
authorMichael Goulet <michael@errs.io>
Fri, 12 Aug 2022 03:48:40 +0000 (03:48 +0000)
committerMichael Goulet <michael@errs.io>
Fri, 12 Aug 2022 03:48:40 +0000 (03:48 +0000)
compiler/rustc_const_eval/src/transform/promote_consts.rs
src/test/ui/const-generics/generic_const_exprs/issue-100360.rs [new file with mode: 0644]
src/test/ui/const-generics/generic_const_exprs/issue-89851.rs [new file with mode: 0644]

index ed4d8c95d1e6178d882bcaef5a3c9b5bad620a39..161c89e3242b9f660336c64da476154e48a9ca24 100644 (file)
@@ -839,17 +839,12 @@ fn promote_candidate(mut self, candidate: Candidate, next_promoted_id: usize) ->
             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 (file)
index 0000000..5572f1f
--- /dev/null
@@ -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 (file)
index 0000000..cde849d
--- /dev/null
@@ -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() {}