Skip to content

Commit 74fd001

Browse files
committed
Auto merge of rust-lang#130649 - matthiaskrgr:rollup-57zc7lz, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#129718 (add guarantee about remove_dir and remove_file error kinds) - rust-lang#130598 (Add recursion limit to FFI safety lint) - rust-lang#130642 (Pass the current cargo to `run-make` tests) - rust-lang#130644 (Only expect valtree consts in codegen) - rust-lang#130645 (Normalize consts in writeback when GCE is enabled) - rust-lang#130646 (compiler: factor out `OVERFLOWING_LITERALS` impl) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c0838c8 + 5770ba8 commit 74fd001

File tree

33 files changed

+585
-520
lines changed

33 files changed

+585
-520
lines changed

compiler/rustc_abi/src/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,28 @@ pub enum Integer {
833833
}
834834

835835
impl Integer {
836+
pub fn int_ty_str(self) -> &'static str {
837+
use Integer::*;
838+
match self {
839+
I8 => "i8",
840+
I16 => "i16",
841+
I32 => "i32",
842+
I64 => "i64",
843+
I128 => "i128",
844+
}
845+
}
846+
847+
pub fn uint_ty_str(self) -> &'static str {
848+
use Integer::*;
849+
match self {
850+
I8 => "u8",
851+
I16 => "u16",
852+
I32 => "u32",
853+
I64 => "u64",
854+
I128 => "u128",
855+
}
856+
}
857+
836858
#[inline]
837859
pub fn size(self) -> Size {
838860
use Integer::*;

compiler/rustc_codegen_cranelift/src/base.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,10 @@ fn codegen_stmt<'tcx>(
785785
}
786786
Rvalue::Repeat(ref operand, times) => {
787787
let operand = codegen_operand(fx, operand);
788-
let times =
789-
fx.monomorphize(times).eval_target_usize(fx.tcx, ParamEnv::reveal_all());
788+
let times = fx
789+
.monomorphize(times)
790+
.try_to_target_usize(fx.tcx)
791+
.expect("expected monomorphic const in codegen");
790792
if operand.layout().size.bytes() == 0 {
791793
// Do nothing for ZST's
792794
} else if fx.clif_type(operand.layout().ty) == Some(types::I8) {
@@ -944,7 +946,10 @@ fn codegen_stmt<'tcx>(
944946
fn codegen_array_len<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, place: CPlace<'tcx>) -> Value {
945947
match *place.layout().ty.kind() {
946948
ty::Array(_elem_ty, len) => {
947-
let len = fx.monomorphize(len).eval_target_usize(fx.tcx, ParamEnv::reveal_all()) as i64;
949+
let len = fx
950+
.monomorphize(len)
951+
.try_to_target_usize(fx.tcx)
952+
.expect("expected monomorphic const in codegen") as i64;
948953
fx.bcx.ins().iconst(fx.pointer_type, len)
949954
}
950955
ty::Slice(_elem_ty) => place.to_ptr_unsized().1,

compiler/rustc_codegen_cranelift/src/debuginfo/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl DebugContext {
4444
type_dbg,
4545
ty,
4646
*elem_ty,
47-
len.eval_target_usize(tcx, ty::ParamEnv::reveal_all()),
47+
len.try_to_target_usize(tcx).expect("expected monomorphic const in codegen"),
4848
),
4949
// ty::Slice(_) | ty::Str
5050
// ty::Dynamic

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
131131

132132
let idx = generic_args[2]
133133
.expect_const()
134-
.eval(fx.tcx, ty::ParamEnv::reveal_all(), span)
135-
.unwrap()
136-
.1
134+
.try_to_valtree()
135+
.expect("expected monomorphic const in codegen")
137136
.unwrap_branch();
138137

139138
assert_eq!(x.layout(), y.layout());

compiler/rustc_codegen_cranelift/src/unsize.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ pub(crate) fn unsized_info<'tcx>(
2424
let (source, target) =
2525
fx.tcx.struct_lockstep_tails_for_codegen(source, target, ParamEnv::reveal_all());
2626
match (&source.kind(), &target.kind()) {
27-
(&ty::Array(_, len), &ty::Slice(_)) => fx
28-
.bcx
29-
.ins()
30-
.iconst(fx.pointer_type, len.eval_target_usize(fx.tcx, ParamEnv::reveal_all()) as i64),
27+
(&ty::Array(_, len), &ty::Slice(_)) => fx.bcx.ins().iconst(
28+
fx.pointer_type,
29+
len.try_to_target_usize(fx.tcx).expect("expected monomorphic const in codegen") as i64,
30+
),
3131
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
3232
if src_dyn_kind == target_dyn_kind =>
3333
{

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ fn build_fixed_size_array_di_node<'ll, 'tcx>(
125125

126126
let (size, align) = cx.size_and_align_of(array_type);
127127

128-
let upper_bound = len.eval_target_usize(cx.tcx, ty::ParamEnv::reveal_all()) as c_longlong;
128+
let upper_bound = len
129+
.try_to_target_usize(cx.tcx)
130+
.expect("expected monomorphic const in codegen") as c_longlong;
129131

130132
let subrange =
131133
unsafe { Some(llvm::LLVMRustDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound)) };

compiler/rustc_codegen_ssa/src/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
115115
let (source, target) =
116116
cx.tcx().struct_lockstep_tails_for_codegen(source, target, bx.param_env());
117117
match (source.kind(), target.kind()) {
118-
(&ty::Array(_, len), &ty::Slice(_)) => {
119-
cx.const_usize(len.eval_target_usize(cx.tcx(), ty::ParamEnv::reveal_all()))
120-
}
118+
(&ty::Array(_, len), &ty::Slice(_)) => cx.const_usize(
119+
len.try_to_target_usize(cx.tcx()).expect("expected monomorphic const in codegen"),
120+
),
121121
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
122122
if src_dyn_kind == target_dyn_kind =>
123123
{

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ fn push_debuginfo_type_name<'tcx>(
188188
_ => write!(
189189
output,
190190
",{}>",
191-
len.eval_target_usize(tcx, ty::ParamEnv::reveal_all())
191+
len.try_to_target_usize(tcx)
192+
.expect("expected monomorphic const in codegen")
192193
)
193194
.unwrap(),
194195
}
@@ -200,7 +201,8 @@ fn push_debuginfo_type_name<'tcx>(
200201
_ => write!(
201202
output,
202203
"; {}]",
203-
len.eval_target_usize(tcx, ty::ParamEnv::reveal_all())
204+
len.try_to_target_usize(tcx)
205+
.expect("expected monomorphic const in codegen")
204206
)
205207
.unwrap(),
206208
}

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
114114

115115
let count = self
116116
.monomorphize(count)
117-
.eval_target_usize(bx.cx().tcx(), ty::ParamEnv::reveal_all());
117+
.try_to_target_usize(bx.tcx())
118+
.expect("expected monomorphic const in codegen");
118119

119120
bx.write_operand_repeatedly(cg_elem, count, dest);
120121
}
@@ -803,7 +804,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
803804
if let Some(index) = place.as_local() {
804805
if let LocalRef::Operand(op) = self.locals[index] {
805806
if let ty::Array(_, n) = op.layout.ty.kind() {
806-
let n = n.eval_target_usize(bx.cx().tcx(), ty::ParamEnv::reveal_all());
807+
let n = n
808+
.try_to_target_usize(bx.tcx())
809+
.expect("expected monomorphic const in codegen");
807810
return bx.cx().const_usize(n);
808811
}
809812
}

compiler/rustc_hir_typeck/src/pat.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_hir::def::{CtorKind, DefKind, Res};
1111
use rustc_hir::pat_util::EnumerateAndAdjustIterator;
1212
use rustc_hir::{self as hir, BindingMode, ByRef, HirId, LangItem, Mutability, Pat, PatKind};
1313
use rustc_infer::infer;
14-
use rustc_middle::mir::interpret::ErrorHandled;
1514
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
1615
use rustc_middle::{bug, span_bug};
1716
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
@@ -2413,17 +2412,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24132412
len: ty::Const<'tcx>,
24142413
min_len: u64,
24152414
) -> (Option<Ty<'tcx>>, Ty<'tcx>) {
2416-
let len = match len.eval(self.tcx, self.param_env, span) {
2417-
Ok((_, val)) => val
2418-
.try_to_scalar()
2419-
.and_then(|scalar| scalar.try_to_scalar_int().ok())
2420-
.map(|int| int.to_target_usize(self.tcx)),
2421-
Err(ErrorHandled::Reported(..)) => {
2422-
let guar = self.error_scrutinee_unfixed_length(span);
2423-
return (Some(Ty::new_error(self.tcx, guar)), arr_ty);
2424-
}
2425-
Err(ErrorHandled::TooGeneric(..)) => None,
2426-
};
2415+
let len = len.try_eval_target_usize(self.tcx, self.param_env);
24272416

24282417
let guar = if let Some(len) = len {
24292418
// Now we know the length...

compiler/rustc_hir_typeck/src/writeback.rs

+33-4
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
803803
// We must deeply normalize in the new solver, since later lints
804804
// expect that types that show up in the typeck are fully
805805
// normalized.
806-
let value = if self.should_normalize {
806+
let mut value = if self.should_normalize {
807807
let body_id = tcx.hir().body_owner_def_id(self.body.id());
808808
let cause = ObligationCause::misc(self.span.to_span(tcx), body_id);
809809
let at = self.fcx.at(&cause, self.fcx.param_env);
@@ -818,12 +818,27 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
818818
value
819819
};
820820

821+
// Bail if there are any non-region infer.
821822
if value.has_non_region_infer() {
822823
let guar = self.report_error(value);
823-
new_err(tcx, guar)
824-
} else {
825-
tcx.fold_regions(value, |_, _| tcx.lifetimes.re_erased)
824+
value = new_err(tcx, guar);
825+
}
826+
827+
// Erase the regions from the ty, since it's not really meaningful what
828+
// these region values are; there's not a trivial correspondence between
829+
// regions in the HIR and MIR, so when we turn the body into MIR, there's
830+
// no reason to keep regions around. They will be repopulated during MIR
831+
// borrowck, and specifically region constraints will be populated during
832+
// MIR typeck which is run on the new body.
833+
value = tcx.fold_regions(value, |_, _| tcx.lifetimes.re_erased);
834+
835+
// Normalize consts in writeback, because GCE doesn't normalize eagerly.
836+
if tcx.features().generic_const_exprs {
837+
value =
838+
value.fold_with(&mut EagerlyNormalizeConsts { tcx, param_env: self.fcx.param_env });
826839
}
840+
841+
value
827842
}
828843
}
829844

@@ -858,3 +873,17 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
858873
predicate
859874
}
860875
}
876+
877+
struct EagerlyNormalizeConsts<'tcx> {
878+
tcx: TyCtxt<'tcx>,
879+
param_env: ty::ParamEnv<'tcx>,
880+
}
881+
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EagerlyNormalizeConsts<'tcx> {
882+
fn cx(&self) -> TyCtxt<'tcx> {
883+
self.tcx
884+
}
885+
886+
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
887+
self.tcx.try_normalize_erasing_regions(self.param_env, ct).unwrap_or(ct)
888+
}
889+
}

compiler/rustc_lint/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ lint_improper_ctypes_opaque = opaque types have no C equivalent
395395
lint_improper_ctypes_pat_help = consider using the base type instead
396396
397397
lint_improper_ctypes_pat_reason = pattern types have no C equivalent
398+
399+
lint_improper_ctypes_recursion_limit_reached = type is infinitely recursive
398400
lint_improper_ctypes_slice_help = consider using a raw pointer instead
399401
400402
lint_improper_ctypes_slice_reason = slices have no C equivalent

0 commit comments

Comments
 (0)