Skip to content

Commit f8131a4

Browse files
committed
Auto merge of #121400 - fmease:rollup-8m29g7a, r=fmease
Rollup of 8 pull requests Successful merges: - #121044 (Support async trait bounds in macros) - #121175 (match lowering: test one or pattern at a time) - #121340 (bootstrap: apply most of clippy's suggestions) - #121347 (compiletest: support auxiliaries with auxiliaries) - #121359 (miscellaneous type system improvements) - #121366 (Remove `diagnostic_builder.rs`) - #121379 (Remove an `unchecked_error_guaranteed` call.) - #121396 (make it possible for outside crates to inspect a mir::ConstValue with the interpreter) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1d447a9 + bd7ba27 commit f8131a4

File tree

69 files changed

+1202
-973
lines changed

Some content is hidden

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

69 files changed

+1202
-973
lines changed

Diff for: compiler/rustc_ast_passes/src/ast_validation.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -881,9 +881,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
881881
&item.vis,
882882
errors::VisibilityNotPermittedNote::TraitImpl,
883883
);
884-
// njn: use Dummy here
885-
if let TyKind::Err(_) = self_ty.kind {
886-
this.dcx().emit_err(errors::ObsoleteAuto { span: item.span });
884+
if let TyKind::Dummy = self_ty.kind {
885+
// Abort immediately otherwise the `TyKind::Dummy` will reach HIR lowering,
886+
// which isn't allowed. Not a problem for this obscure, obsolete syntax.
887+
this.dcx().emit_fatal(errors::ObsoleteAuto { span: item.span });
887888
}
888889
if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity)
889890
{

Diff for: compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ use either::{Left, Right};
33
use rustc_hir::def::DefKind;
44
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo};
55
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
6+
use rustc_middle::query::TyCtxtAt;
67
use rustc_middle::traits::Reveal;
78
use rustc_middle::ty::layout::LayoutOf;
89
use rustc_middle::ty::print::with_no_trimmed_paths;
9-
use rustc_middle::ty::{self, TyCtxt};
10+
use rustc_middle::ty::{self, Ty, TyCtxt};
1011
use rustc_span::def_id::LocalDefId;
1112
use rustc_span::Span;
1213
use rustc_target::abi::{self, Abi};
@@ -87,13 +88,16 @@ fn eval_body_using_ecx<'mir, 'tcx>(
8788
}
8889

8990
/// The `InterpCx` is only meant to be used to do field and index projections into constants for
90-
/// `simd_shuffle` and const patterns in match arms. It never performs alignment checks.
91+
/// `simd_shuffle` and const patterns in match arms.
92+
///
93+
/// This should *not* be used to do any actual interpretation. In particular, alignment checks are
94+
/// turned off!
9195
///
9296
/// The function containing the `match` that is currently being analyzed may have generic bounds
9397
/// that inform us about the generic bounds of the constant. E.g., using an associated constant
9498
/// of a function's generic parameter will require knowledge about the bounds on the generic
9599
/// parameter. These bounds are passed to `mk_eval_cx` via the `ParamEnv` argument.
96-
pub(crate) fn mk_eval_cx<'mir, 'tcx>(
100+
pub(crate) fn mk_eval_cx_to_read_const_val<'mir, 'tcx>(
97101
tcx: TyCtxt<'tcx>,
98102
root_span: Span,
99103
param_env: ty::ParamEnv<'tcx>,
@@ -108,6 +112,19 @@ pub(crate) fn mk_eval_cx<'mir, 'tcx>(
108112
)
109113
}
110114

115+
/// Create an interpreter context to inspect the given `ConstValue`.
116+
/// Returns both the context and an `OpTy` that represents the constant.
117+
pub fn mk_eval_cx_for_const_val<'mir, 'tcx>(
118+
tcx: TyCtxtAt<'tcx>,
119+
param_env: ty::ParamEnv<'tcx>,
120+
val: mir::ConstValue<'tcx>,
121+
ty: Ty<'tcx>,
122+
) -> Option<(CompileTimeEvalContext<'mir, 'tcx>, OpTy<'tcx>)> {
123+
let ecx = mk_eval_cx_to_read_const_val(tcx.tcx, tcx.span, param_env, CanAccessMutGlobal::No);
124+
let op = ecx.const_val_to_op(val, ty, None).ok()?;
125+
Some((ecx, op))
126+
}
127+
111128
/// This function converts an interpreter value into a MIR constant.
112129
///
113130
/// The `for_diagnostics` flag turns the usual rules for returning `ConstValue::Scalar` into a
@@ -203,7 +220,7 @@ pub(crate) fn turn_into_const_value<'tcx>(
203220
let def_id = cid.instance.def.def_id();
204221
let is_static = tcx.is_static(def_id);
205222
// This is just accessing an already computed constant, so no need to check alignment here.
206-
let ecx = mk_eval_cx(
223+
let ecx = mk_eval_cx_to_read_const_val(
207224
tcx,
208225
tcx.def_span(key.value.instance.def_id()),
209226
key.param_env,

Diff for: compiler/rustc_const_eval/src/const_eval/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>(
4747
ty: Ty<'tcx>,
4848
) -> Option<mir::DestructuredConstant<'tcx>> {
4949
let param_env = ty::ParamEnv::reveal_all();
50-
let ecx = mk_eval_cx(tcx.tcx, tcx.span, param_env, CanAccessMutGlobal::No);
51-
let op = ecx.const_val_to_op(val, ty, None).ok()?;
50+
let (ecx, op) = mk_eval_cx_for_const_val(tcx, param_env, val, ty)?;
5251

5352
// We go to `usize` as we cannot allocate anything bigger anyway.
5453
let (field_count, variant, down) = match ty.kind() {

Diff for: compiler/rustc_const_eval/src/const_eval/valtrees.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
55
use rustc_span::DUMMY_SP;
66
use rustc_target::abi::{Abi, VariantIdx};
77

8-
use super::eval_queries::{mk_eval_cx, op_to_const};
8+
use super::eval_queries::{mk_eval_cx_to_read_const_val, op_to_const};
99
use super::machine::CompileTimeEvalContext;
1010
use super::{ValTreeCreationError, ValTreeCreationResult, VALTREE_MAX_NODES};
1111
use crate::const_eval::CanAccessMutGlobal;
@@ -223,7 +223,7 @@ pub(crate) fn eval_to_valtree<'tcx>(
223223
let const_alloc = tcx.eval_to_allocation_raw(param_env.and(cid))?;
224224

225225
// FIXME Need to provide a span to `eval_to_valtree`
226-
let ecx = mk_eval_cx(
226+
let ecx = mk_eval_cx_to_read_const_val(
227227
tcx,
228228
DUMMY_SP,
229229
param_env,
@@ -287,7 +287,8 @@ pub fn valtree_to_const_value<'tcx>(
287287
}
288288
}
289289
ty::Ref(_, inner_ty, _) => {
290-
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, CanAccessMutGlobal::No);
290+
let mut ecx =
291+
mk_eval_cx_to_read_const_val(tcx, DUMMY_SP, param_env, CanAccessMutGlobal::No);
291292
let imm = valtree_to_ref(&mut ecx, valtree, *inner_ty);
292293
let imm = ImmTy::from_immediate(imm, tcx.layout_of(param_env_ty).unwrap());
293294
op_to_const(&ecx, &imm.into(), /* for diagnostics */ false)
@@ -314,7 +315,8 @@ pub fn valtree_to_const_value<'tcx>(
314315
bug!("could not find non-ZST field during in {layout:#?}");
315316
}
316317

317-
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, CanAccessMutGlobal::No);
318+
let mut ecx =
319+
mk_eval_cx_to_read_const_val(tcx, DUMMY_SP, param_env, CanAccessMutGlobal::No);
318320

319321
// Need to create a place for this valtree.
320322
let place = create_valtree_place(&mut ecx, layout, valtree);

Diff for: compiler/rustc_const_eval/src/util/caller_location.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::ty::layout::LayoutOf;
66
use rustc_span::symbol::Symbol;
77
use rustc_type_ir::Mutability;
88

9-
use crate::const_eval::{mk_eval_cx, CanAccessMutGlobal, CompileTimeEvalContext};
9+
use crate::const_eval::{mk_eval_cx_to_read_const_val, CanAccessMutGlobal, CompileTimeEvalContext};
1010
use crate::interpret::*;
1111

1212
/// Allocate a `const core::panic::Location` with the provided filename and line/column numbers.
@@ -57,7 +57,12 @@ pub(crate) fn const_caller_location_provider(
5757
col: u32,
5858
) -> mir::ConstValue<'_> {
5959
trace!("const_caller_location: {}:{}:{}", file, line, col);
60-
let mut ecx = mk_eval_cx(tcx.tcx, tcx.span, ty::ParamEnv::reveal_all(), CanAccessMutGlobal::No);
60+
let mut ecx = mk_eval_cx_to_read_const_val(
61+
tcx.tcx,
62+
tcx.span,
63+
ty::ParamEnv::reveal_all(),
64+
CanAccessMutGlobal::No,
65+
);
6166

6267
let loc_place = alloc_caller_location(&mut ecx, file, line, col);
6368
if intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &loc_place).is_err() {

0 commit comments

Comments
 (0)