Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1688719

Browse files
spastorinooli-obk
authored andcommittedJan 10, 2020
Promote Refs to constants instead of static
1 parent a59abfa commit 1688719

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+447
-223
lines changed
 

‎src/librustc/mir/interpret/queries.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ impl<'tcx> TyCtxt<'tcx> {
3636
param_env: ty::ParamEnv<'tcx>,
3737
def_id: DefId,
3838
substs: SubstsRef<'tcx>,
39+
promoted: Option<mir::Promoted>,
3940
span: Option<Span>,
4041
) -> ConstEvalResult<'tcx> {
4142
let instance = ty::Instance::resolve(self, param_env, def_id, substs);
4243
if let Some(instance) = instance {
43-
self.const_eval_instance(param_env, instance, span)
44+
if let Some(promoted) = promoted {
45+
self.const_eval_promoted(instance, promoted)
46+
} else {
47+
self.const_eval_instance(param_env, instance, span)
48+
}
4449
} else {
4550
Err(ErrorHandled::TooGeneric)
4651
}

‎src/librustc/mir/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ pub struct Body<'tcx> {
166166

167167
/// A span representing this MIR, for error reporting.
168168
pub span: Span,
169+
170+
/// The user may be writing e.g. &[(SOME_CELL, 42)][i].1 and this would get promoted, because
171+
/// we'd statically know that no thing with interior mutability will ever be available to the
172+
/// user without some serious unsafe code. Now this means that our promoted is actually
173+
/// &[(SOME_CELL, 42)] and the MIR using it will do the &promoted[i].1 projection because the
174+
/// index may be a runtime value. Such a promoted value is illegal because it has reachable
175+
/// interior mutability. This flag just makes this situation very obvious where the previous
176+
/// implementation without the flag hid this situation silently.
177+
/// FIXME(oli-obk): rewrite the promoted during promotion to eliminate the cell components.
178+
pub ignore_interior_mut_in_const_validation: bool,
169179
}
170180

171181
impl<'tcx> Body<'tcx> {
@@ -202,6 +212,7 @@ impl<'tcx> Body<'tcx> {
202212
spread_arg: None,
203213
var_debug_info,
204214
span,
215+
ignore_interior_mut_in_const_validation: false,
205216
control_flow_destroyed,
206217
}
207218
}

0 commit comments

Comments
 (0)
Please sign in to comment.