about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-04-16 23:07:18 +0000
committerMichael Goulet <michael@errs.io>2023-04-16 23:09:57 +0000
commite28e19034ffd49a50499e96da884be3ea9a950aa (patch)
tree74748d055723af2d2ce1ffccf1254083bdb8cf83
parent8a778ca1e35e4a8df95c00d800100d95e63e7722 (diff)
downloadrust-e28e19034ffd49a50499e96da884be3ea9a950aa.tar.gz
rust-e28e19034ffd49a50499e96da884be3ea9a950aa.zip
Check freeze with right param-env
-rw-r--r--compiler/rustc_mir_transform/src/deduce_param_attrs.rs5
-rw-r--r--tests/ui/codegen/freeze-on-polymorphic-projection.rs19
-rw-r--r--tests/ui/codegen/freeze-on-polymorphic-projection.stderr12
3 files changed, 34 insertions, 2 deletions
diff --git a/compiler/rustc_mir_transform/src/deduce_param_attrs.rs b/compiler/rustc_mir_transform/src/deduce_param_attrs.rs
index e5c3fa5646a..8ee08c5be34 100644
--- a/compiler/rustc_mir_transform/src/deduce_param_attrs.rs
+++ b/compiler/rustc_mir_transform/src/deduce_param_attrs.rs
@@ -9,7 +9,7 @@ use rustc_hir::def_id::LocalDefId;
 use rustc_index::bit_set::BitSet;
 use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
 use rustc_middle::mir::{Body, Local, Location, Operand, Terminator, TerminatorKind, RETURN_PLACE};
-use rustc_middle::ty::{self, DeducedParamAttrs, ParamEnv, Ty, TyCtxt};
+use rustc_middle::ty::{self, DeducedParamAttrs, Ty, TyCtxt};
 use rustc_session::config::OptLevel;
 
 /// A visitor that determines which arguments have been mutated. We can't use the mutability field
@@ -198,11 +198,12 @@ pub fn deduced_param_attrs<'tcx>(
     // see [1].
     //
     // [1]: https://github.com/rust-lang/rust/pull/103172#discussion_r999139997
+    let param_env = tcx.param_env_reveal_all_normalized(def_id);
     let mut deduced_param_attrs = tcx.arena.alloc_from_iter(
         body.local_decls.iter().skip(1).take(body.arg_count).enumerate().map(
             |(arg_index, local_decl)| DeducedParamAttrs {
                 read_only: !deduce_read_only.mutable_args.contains(arg_index)
-                    && local_decl.ty.is_freeze(tcx, ParamEnv::reveal_all()),
+                    && local_decl.ty.is_freeze(tcx, param_env),
             },
         ),
     );
diff --git a/tests/ui/codegen/freeze-on-polymorphic-projection.rs b/tests/ui/codegen/freeze-on-polymorphic-projection.rs
new file mode 100644
index 00000000000..edc79f8fd94
--- /dev/null
+++ b/tests/ui/codegen/freeze-on-polymorphic-projection.rs
@@ -0,0 +1,19 @@
+// build-pass
+// compile-flags: -Copt-level=1 --crate-type=lib
+
+#![feature(specialization)]
+//~^ WARN the feature `specialization` is incomplete
+
+pub unsafe trait Storage {
+    type Handle;
+}
+
+pub unsafe trait MultipleStorage: Storage {}
+
+default unsafe impl<S> Storage for S where S: MultipleStorage {}
+
+// Make sure that we call is_freeze on `(S::Handle,)` in the param-env of `ice`,
+// instead of in an empty, reveal-all param-env.
+pub fn ice<S: Storage>(boxed: (S::Handle,)) -> (S::Handle,) {
+    boxed
+}
diff --git a/tests/ui/codegen/freeze-on-polymorphic-projection.stderr b/tests/ui/codegen/freeze-on-polymorphic-projection.stderr
new file mode 100644
index 00000000000..903cb2ff6aa
--- /dev/null
+++ b/tests/ui/codegen/freeze-on-polymorphic-projection.stderr
@@ -0,0 +1,12 @@
+warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
+  --> $DIR/freeze-on-polymorphic-projection.rs:4:12
+   |
+LL | #![feature(specialization)]
+   |            ^^^^^^^^^^^^^^
+   |
+   = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
+   = help: consider using `min_specialization` instead, which is more stable and complete
+   = note: `#[warn(incomplete_features)]` on by default
+
+warning: 1 warning emitted
+