Skip to content

Commit 627a151

Browse files
Fix tests
1 parent b7d3c5f commit 627a151

File tree

15 files changed

+46
-41
lines changed

15 files changed

+46
-41
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
133133
.expect_const()
134134
.try_to_valtree()
135135
.expect("expected monomorphic const in codegen")
136+
.0
136137
.unwrap_branch();
137138

138139
assert_eq!(x.layout(), y.layout());
@@ -806,8 +807,10 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
806807
ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => m.load_scalar(fx),
807808
ty::Array(elem, len)
808809
if matches!(elem.kind(), ty::Uint(ty::UintTy::U8))
809-
&& len.try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all())
810-
== Some(expected_bytes) =>
810+
&& len
811+
.try_to_target_usize(fx.tcx)
812+
.expect("expected monomorphic const in codegen")
813+
== expected_bytes =>
811814
{
812815
m.force_stack(fx).0.load(
813816
fx,
@@ -907,8 +910,10 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
907910
ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => {}
908911
ty::Array(elem, len)
909912
if matches!(elem.kind(), ty::Uint(ty::UintTy::U8))
910-
&& len.try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all())
911-
== Some(expected_bytes) => {}
913+
&& len
914+
.try_to_target_usize(fx.tcx)
915+
.expect("expected monomorphic const in codegen")
916+
== expected_bytes => {}
912917
_ => {
913918
fx.tcx.dcx().span_fatal(
914919
span,

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
7676
ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => args[0].immediate(),
7777
ty::Array(elem, len)
7878
if matches!(*elem.kind(), ty::Uint(ty::UintTy::U8))
79-
&& len.try_eval_target_usize(bx.tcx, ty::ParamEnv::reveal_all())
80-
== Some(expected_bytes) =>
79+
&& len
80+
.try_to_target_usize(bx.tcx)
81+
.expect("expected monomorphic const in codegen")
82+
== expected_bytes =>
8183
{
8284
let place = PlaceRef::alloca(bx, args[0].layout);
8385
args[0].val.store(bx, place);
@@ -680,8 +682,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
680682
}
681683
ty::Array(elem, len)
682684
if matches!(*elem.kind(), ty::Uint(ty::UintTy::U8))
683-
&& len.try_eval_target_usize(bx.tcx, ty::ParamEnv::reveal_all())
684-
== Some(expected_bytes) =>
685+
&& len
686+
.try_to_target_usize(bx.tcx)
687+
.expect("expected monomorphic const in codegen")
688+
== expected_bytes =>
685689
{
686690
// Zero-extend iN to the array length:
687691
let ze = bx.zext(result, bx.type_ix(expected_bytes * 8));

src/librustdoc/clean/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18171817
// Only anon consts can implicitly capture params.
18181818
// FIXME: is this correct behavior?
18191819
let param_env = cx.tcx.param_env(*def_id);
1820-
ct.normalize(cx.tcx, param_env)
1820+
ct.normalize_internal(cx.tcx, param_env)
18211821
} else {
18221822
ct
18231823
};
@@ -2038,8 +2038,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
20382038
Box::new(clean_middle_ty(bound_ty.rebind(ty), cx, None, None)),
20392039
format!("{pat:?}").into_boxed_str(),
20402040
),
2041-
ty::Array(ty, mut n) => {
2042-
n = n.normalize(cx.tcx, ty::ParamEnv::reveal_all());
2041+
ty::Array(ty, n) => {
2042+
let n = cx.tcx.normalize_erasing_regions(cx.param_env, n);
20432043
let n = print_const(cx, n);
20442044
Array(Box::new(clean_middle_ty(bound_ty.rebind(ty), cx, None, None)), n.into())
20452045
}

src/tools/clippy/clippy_lints/src/indexing_slicing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
114114
if let Some(range) = higher::Range::hir(index) {
115115
// Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..]
116116
if let ty::Array(_, s) = ty.kind() {
117-
let size: u128 = if let Some(size) = s.try_eval_target_usize(cx.tcx, cx.param_env) {
117+
let size: u128 = if let Some(size) = s.try_to_target_usize(cx.tcx) {
118118
size.into()
119119
} else {
120120
return;
@@ -183,7 +183,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
183183
&& let ty::Uint(utype) = cx.typeck_results().expr_ty(index).kind()
184184
&& *utype == ty::UintTy::Usize
185185
&& let ty::Array(_, s) = ty.kind()
186-
&& let Some(size) = s.try_eval_target_usize(cx.tcx, cx.param_env)
186+
&& let Some(size) = s.try_to_target_usize(cx.tcx)
187187
{
188188
// get constant offset and check whether it is in bounds
189189
let off = usize::try_from(off).unwrap();

src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(super) fn check(
3030
return;
3131
}
3232
} else if count
33-
.try_eval_target_usize(cx.tcx, cx.param_env)
33+
.try_to_target_usize(cx.tcx)
3434
.map_or(true, |x| x > 32)
3535
&& !msrv.meets(msrvs::ARRAY_IMPL_ANY_LEN)
3636
{

src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ fn is_array_length_equal_to_range(cx: &LateContext<'_>, start: &Expr<'_>, end: &
472472
let arr_ty = cx.typeck_results().expr_ty(arr).peel_refs();
473473

474474
if let ty::Array(_, s) = arr_ty.kind() {
475-
let size: u128 = if let Some(size) = s.try_eval_target_usize(cx.tcx, cx.param_env) {
475+
let size: u128 = if let Some(size) = s.try_to_target_usize(cx.tcx) {
476476
size.into()
477477
} else {
478478
return false;

src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fn is_end_eq_array_len<'tcx>(
207207
if let ExprKind::Lit(lit) = end.kind
208208
&& let ast::LitKind::Int(end_int, _) = lit.node
209209
&& let ty::Array(_, arr_len_const) = indexed_ty.kind()
210-
&& let Some(arr_len) = arr_len_const.try_eval_target_usize(cx.tcx, cx.param_env)
210+
&& let Some(arr_len) = arr_len_const.try_to_target_usize(cx.tcx)
211211
{
212212
return match limits {
213213
ast::RangeLimits::Closed => end_int.get() + 1 >= arr_len.into(),

src/tools/clippy/clippy_lints/src/matches/single_match.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::def::{DefKind, Res};
1111
use rustc_hir::intravisit::{Visitor, walk_pat};
1212
use rustc_hir::{Arm, Expr, ExprKind, HirId, Node, Pat, PatKind, QPath, StmtKind};
1313
use rustc_lint::LateContext;
14-
use rustc_middle::ty::{self, AdtDef, ParamEnv, TyCtxt, TypeckResults, VariantDef};
14+
use rustc_middle::ty::{self, AdtDef, TyCtxt, TypeckResults, VariantDef};
1515
use rustc_span::{Span, sym};
1616

1717
use super::{MATCH_BOOL, SINGLE_MATCH, SINGLE_MATCH_ELSE};
@@ -67,7 +67,6 @@ pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'_>, arms: &'tc
6767
if v.has_enum {
6868
let cx = PatCtxt {
6969
tcx: cx.tcx,
70-
param_env: cx.param_env,
7170
typeck,
7271
arena: DroplessArena::default(),
7372
};
@@ -185,7 +184,6 @@ impl<'tcx> Visitor<'tcx> for PatVisitor<'tcx> {
185184
/// The context needed to manipulate a `PatState`.
186185
struct PatCtxt<'tcx> {
187186
tcx: TyCtxt<'tcx>,
188-
param_env: ParamEnv<'tcx>,
189187
typeck: &'tcx TypeckResults<'tcx>,
190188
arena: DroplessArena,
191189
}
@@ -334,7 +332,7 @@ impl<'a> PatState<'a> {
334332
if match *cx.typeck.pat_ty(pat).peel_refs().kind() {
335333
ty::Adt(adt, _) => adt.is_enum() || (adt.is_struct() && !adt.non_enum_variant().fields.is_empty()),
336334
ty::Tuple(tys) => !tys.is_empty(),
337-
ty::Array(_, len) => len.try_eval_target_usize(cx.tcx, cx.param_env) != Some(1),
335+
ty::Array(_, len) => len.try_to_target_usize(cx.tcx) != Some(1),
338336
ty::Slice(..) => true,
339337
_ => false,
340338
} =>
@@ -353,7 +351,7 @@ impl<'a> PatState<'a> {
353351
},
354352
PatKind::Slice([sub_pat], _, []) | PatKind::Slice([], _, [sub_pat])
355353
if let ty::Array(_, len) = *cx.typeck.pat_ty(pat).kind()
356-
&& len.try_eval_target_usize(cx.tcx, cx.param_env) == Some(1) =>
354+
&& len.try_to_target_usize(cx.tcx) == Some(1) =>
357355
{
358356
self.add_pat(cx, sub_pat)
359357
},

src/tools/clippy/clippy_lints/src/methods/iter_out_of_bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ fn get_iterator_length<'tcx>(cx: &LateContext<'tcx>, iter: &'tcx Expr<'tcx>) ->
3131
// parameter.
3232
substs
3333
.const_at(1)
34-
.try_eval_target_usize(cx.tcx, cx.param_env)
34+
.try_to_target_usize(cx.tcx)
3535
.map(u128::from)
3636
} else if cx.tcx.is_diagnostic_item(sym::SliceIter, did)
3737
&& let ExprKind::MethodCall(_, recv, ..) = iter.kind
3838
{
3939
if let ty::Array(_, len) = cx.typeck_results().expr_ty(recv).peel_refs().kind() {
4040
// For slice::Iter<'_, T>, the receiver might be an array literal: [1,2,3].iter().skip(..)
41-
len.try_eval_target_usize(cx.tcx, cx.param_env).map(u128::from)
41+
len.try_to_target_usize(cx.tcx).map(u128::from)
4242
} else if let Some(args) = VecArgs::hir(cx, expr_or_init(cx, recv)) {
4343
match args {
4444
VecArgs::Vec(vec) => vec.len().try_into().ok(),

src/tools/clippy/clippy_lints/src/methods/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(super) fn derefs_to_slice<'tcx>(
1818
ty::Slice(_) => true,
1919
ty::Adt(..) if let Some(boxed) = ty.boxed_ty() => may_slice(cx, boxed),
2020
ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym::Vec),
21-
ty::Array(_, size) => size.try_eval_target_usize(cx.tcx, cx.param_env).is_some(),
21+
ty::Array(_, size) => size.try_to_target_usize(cx.tcx).is_some(),
2222
ty::Ref(_, inner, _) => may_slice(cx, *inner),
2323
_ => false,
2424
}

src/tools/clippy/clippy_lints/src/trailing_empty_array.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::has_repr_attr;
33
use rustc_hir::{Item, ItemKind};
44
use rustc_lint::{LateContext, LateLintPass};
5-
use rustc_middle::ty::{Const, FeedConstTy};
5+
use rustc_middle::ty;
66
use rustc_session::declare_lint_pass;
77

88
declare_clippy_lint! {
@@ -55,16 +55,14 @@ impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray {
5555

5656
fn is_struct_with_trailing_zero_sized_array<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool {
5757
if let ItemKind::Struct(data, _) = &item.kind
58-
// First check if last field is an array
5958
&& let Some(last_field) = data.fields().last()
60-
&& let rustc_hir::TyKind::Array(_, rustc_hir::ArrayLen::Body(length)) = last_field.ty.kind
61-
62-
// Then check if that array is zero-sized
63-
&& let length = Const::from_const_arg(cx.tcx, length, FeedConstTy::No)
64-
&& let length = length.try_eval_target_usize(cx.tcx, cx.param_env)
65-
&& let Some(length) = length
59+
&& let field_ty = cx
60+
.tcx
61+
.normalize_erasing_regions(cx.param_env, cx.tcx.type_of(last_field.def_id).instantiate_identity())
62+
&& let ty::Array(_, array_len) = *field_ty.kind()
63+
&& let Some(0) = array_len.try_to_target_usize(cx.tcx)
6664
{
67-
length == 0
65+
true
6866
} else {
6967
false
7068
}

src/tools/clippy/clippy_lints/src/tuple_array_conversions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn all_bindings_are_for_conv<'tcx>(
190190
tys.len() == elements.len() && tys.iter().chain(final_tys.iter().copied()).all_equal()
191191
},
192192
(ToType::Tuple, ty::Array(ty, len)) => {
193-
let Some(len) = len.try_eval_target_usize(cx.tcx, cx.param_env) else { return false };
193+
let Some(len) = len.try_to_target_usize(cx.tcx) else { return false };
194194
len as usize == elements.len() && final_tys.iter().chain(once(ty)).all_equal()
195195
},
196196
_ => false,

src/tools/clippy/clippy_utils/src/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
472472
ExprKind::Tup(tup) => self.multi(tup).map(Constant::Tuple),
473473
ExprKind::Repeat(value, _) => {
474474
let n = match self.typeck.expr_ty(e).kind() {
475-
ty::Array(_, n) => n.try_eval_target_usize(self.tcx, self.param_env)?,
475+
ty::Array(_, n) => n.try_to_target_usize(self.tcx)?,
476476
_ => span_bug!(e.span, "typeck error"),
477477
};
478478
self.expr(value).map(|v| Constant::Repeat(Box::new(v), n))
@@ -554,7 +554,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
554554
ExprKind::Array(vec) => self.multi(vec).map(|v| v.is_empty()),
555555
ExprKind::Repeat(..) => {
556556
if let ty::Array(_, n) = self.typeck.expr_ty(e).kind() {
557-
Some(n.try_eval_target_usize(self.tcx, self.param_env)? == 0)
557+
Some(n.try_to_target_usize(self.tcx)? == 0)
558558
} else {
559559
span_bug!(e.span, "typeck error");
560560
}

src/tools/clippy/clippy_utils/src/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 {
989989
(Ok(size), _) => size,
990990
(Err(_), ty::Tuple(list)) => list.iter().map(|t| approx_ty_size(cx, t)).sum(),
991991
(Err(_), ty::Array(t, n)) => {
992-
n.try_eval_target_usize(cx.tcx, cx.param_env).unwrap_or_default() * approx_ty_size(cx, *t)
992+
n.try_to_target_usize(cx.tcx).unwrap_or_default() * approx_ty_size(cx, *t)
993993
},
994994
(Err(_), ty::Adt(def, subst)) if def.is_struct() => def
995995
.variants()
@@ -1207,7 +1207,7 @@ impl<'tcx> InteriorMut<'tcx> {
12071207
ty::RawPtr(inner_ty, _) if !self.ignore_pointers => self.is_interior_mut_ty(cx, inner_ty),
12081208
ty::Ref(_, inner_ty, _) | ty::Slice(inner_ty) => self.is_interior_mut_ty(cx, inner_ty),
12091209
ty::Array(inner_ty, size) => {
1210-
size.try_eval_target_usize(cx.tcx, cx.param_env)
1210+
size.try_to_target_usize(cx.tcx)
12111211
.map_or(true, |u| u != 0)
12121212
&& self.is_interior_mut_ty(cx, inner_ty)
12131213
},

src/tools/miri/src/intrinsics/simd.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use either::Either;
22

33
use rustc_apfloat::{Float, Round};
4-
use rustc_middle::ty::layout::{HasParamEnv, LayoutOf};
4+
use rustc_middle::ty::layout::LayoutOf;
55
use rustc_middle::{mir, ty, ty::FloatTy};
66
use rustc_span::{Symbol, sym};
77
use rustc_target::abi::{Endian, HasDataLayout};
@@ -633,9 +633,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
633633

634634
let index = generic_args[2]
635635
.expect_const()
636-
.eval(*this.tcx, this.param_env(), this.tcx.span)
636+
.try_to_valtree()
637637
.unwrap()
638-
.1
638+
.0
639639
.unwrap_branch();
640640
let index_len = index.len();
641641

0 commit comments

Comments
 (0)