Skip to content

Commit e28e190

Browse files
Check freeze with right param-env
1 parent 8a778ca commit e28e190

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

compiler/rustc_mir_transform/src/deduce_param_attrs.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def_id::LocalDefId;
99
use rustc_index::bit_set::BitSet;
1010
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
1111
use rustc_middle::mir::{Body, Local, Location, Operand, Terminator, TerminatorKind, RETURN_PLACE};
12-
use rustc_middle::ty::{self, DeducedParamAttrs, ParamEnv, Ty, TyCtxt};
12+
use rustc_middle::ty::{self, DeducedParamAttrs, Ty, TyCtxt};
1313
use rustc_session::config::OptLevel;
1414

1515
/// 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>(
198198
// see [1].
199199
//
200200
// [1]: https://github.com/rust-lang/rust/pull/103172#discussion_r999139997
201+
let param_env = tcx.param_env_reveal_all_normalized(def_id);
201202
let mut deduced_param_attrs = tcx.arena.alloc_from_iter(
202203
body.local_decls.iter().skip(1).take(body.arg_count).enumerate().map(
203204
|(arg_index, local_decl)| DeducedParamAttrs {
204205
read_only: !deduce_read_only.mutable_args.contains(arg_index)
205-
&& local_decl.ty.is_freeze(tcx, ParamEnv::reveal_all()),
206+
&& local_decl.ty.is_freeze(tcx, param_env),
206207
},
207208
),
208209
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// build-pass
2+
// compile-flags: -Copt-level=1 --crate-type=lib
3+
4+
#![feature(specialization)]
5+
//~^ WARN the feature `specialization` is incomplete
6+
7+
pub unsafe trait Storage {
8+
type Handle;
9+
}
10+
11+
pub unsafe trait MultipleStorage: Storage {}
12+
13+
default unsafe impl<S> Storage for S where S: MultipleStorage {}
14+
15+
// Make sure that we call is_freeze on `(S::Handle,)` in the param-env of `ice`,
16+
// instead of in an empty, reveal-all param-env.
17+
pub fn ice<S: Storage>(boxed: (S::Handle,)) -> (S::Handle,) {
18+
boxed
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/freeze-on-polymorphic-projection.rs:4:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
8+
= help: consider using `min_specialization` instead, which is more stable and complete
9+
= note: `#[warn(incomplete_features)]` on by default
10+
11+
warning: 1 warning emitted
12+

0 commit comments

Comments
 (0)