Skip to content

Commit

Permalink
Rollup merge of #110434 - compiler-errors:issue-110171, r=oli-obk
Browse files Browse the repository at this point in the history
Check freeze with right param-env in `deduced_param_attrs`

We're checking if a trait (`Freeze`) holds in a polymorphic function, but not using that function's own (reveal-all) param-env. This causes us to try to eagerly normalize a specializable projection type that has no default value, which causes an ICE.

Fixes #110171
  • Loading branch information
matthiaskrgr committed Apr 17, 2023
2 parents 23dc31f + e28e190 commit c32ab1d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/rustc_mir_transform/src/deduce_param_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
},
),
);
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/codegen/freeze-on-polymorphic-projection.rs
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions tests/ui/codegen/freeze-on-polymorphic-projection.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c32ab1d

Please sign in to comment.