Skip to content

Commit 073fe72

Browse files
author
Ellen Arteca
committed
update to use TyKind directly
1 parent 200c073 commit 073fe72

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/shims/ffi_support.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use libffi::{high::call as ffi, low::CodePtr};
22
use std::ops::Deref;
33

4-
use rustc_middle::ty::{IntTy, Ty, TyKind, UintTy};
4+
use rustc_middle::ty::{self as ty, IntTy, Ty, UintTy};
55
use rustc_span::Symbol;
66
use rustc_target::abi::HasDataLayout;
77

@@ -14,44 +14,44 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1414
/// and convert it to a `CArg`.
1515
fn scalar_to_carg(
1616
k: ScalarMaybeUninit<Provenance>,
17-
arg_type: &Ty<'tcx>,
17+
arg_type: Ty<'tcx>,
1818
cx: &impl HasDataLayout,
1919
) -> InterpResult<'tcx, CArg> {
2020
match arg_type.kind() {
2121
// If the primitive provided can be converted to a type matching the type pattern
2222
// then create a `CArg` of this primitive value with the corresponding `CArg` constructor.
2323
// the ints
24-
TyKind::Int(IntTy::I8) => {
24+
ty::Int(IntTy::I8) => {
2525
return Ok(CArg::Int8(k.to_i8()?));
2626
}
27-
TyKind::Int(IntTy::I16) => {
27+
ty::Int(IntTy::I16) => {
2828
return Ok(CArg::Int16(k.to_i16()?));
2929
}
30-
TyKind::Int(IntTy::I32) => {
30+
ty::Int(IntTy::I32) => {
3131
return Ok(CArg::Int32(k.to_i32()?));
3232
}
33-
TyKind::Int(IntTy::I64) => {
33+
ty::Int(IntTy::I64) => {
3434
return Ok(CArg::Int64(k.to_i64()?));
3535
}
36-
TyKind::Int(IntTy::Isize) => {
36+
ty::Int(IntTy::Isize) => {
3737
// This will fail if host != target, but then the entire FFI thing probably won't work well
3838
// in that situation.
3939
return Ok(CArg::ISize(k.to_machine_isize(cx)?.try_into().unwrap()));
4040
}
4141
// the uints
42-
TyKind::Uint(UintTy::U8) => {
42+
ty::Uint(UintTy::U8) => {
4343
return Ok(CArg::UInt8(k.to_u8()?));
4444
}
45-
TyKind::Uint(UintTy::U16) => {
45+
ty::Uint(UintTy::U16) => {
4646
return Ok(CArg::UInt16(k.to_u16()?));
4747
}
48-
TyKind::Uint(UintTy::U32) => {
48+
ty::Uint(UintTy::U32) => {
4949
return Ok(CArg::UInt32(k.to_u32()?));
5050
}
51-
TyKind::Uint(UintTy::U64) => {
51+
ty::Uint(UintTy::U64) => {
5252
return Ok(CArg::UInt64(k.to_u64()?));
5353
}
54-
TyKind::Uint(UintTy::Usize) => {
54+
ty::Uint(UintTy::Usize) => {
5555
// This will fail if host != target, but then the entire FFI thing probably won't work well
5656
// in that situation.
5757
return Ok(CArg::USize(k.to_machine_usize(cx)?.try_into().unwrap()));
@@ -85,55 +85,55 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
8585
// primitive integer type, and then write this value out to the miri memory as an integer.
8686
match dest.layout.ty.kind() {
8787
// ints
88-
TyKind::Int(IntTy::I8) => {
88+
ty::Int(IntTy::I8) => {
8989
let x = ffi::call::<i8>(ptr, libffi_args.as_slice());
9090
this.write_int(x, dest)?;
9191
return Ok(());
9292
}
93-
TyKind::Int(IntTy::I16) => {
93+
ty::Int(IntTy::I16) => {
9494
let x = ffi::call::<i16>(ptr, libffi_args.as_slice());
9595
this.write_int(x, dest)?;
9696
return Ok(());
9797
}
98-
TyKind::Int(IntTy::I32) => {
98+
ty::Int(IntTy::I32) => {
9999
let x = ffi::call::<i32>(ptr, libffi_args.as_slice());
100100
this.write_int(x, dest)?;
101101
return Ok(());
102102
}
103-
TyKind::Int(IntTy::I64) => {
103+
ty::Int(IntTy::I64) => {
104104
let x = ffi::call::<i64>(ptr, libffi_args.as_slice());
105105
this.write_int(x, dest)?;
106106
return Ok(());
107107
}
108-
TyKind::Int(IntTy::Isize) => {
108+
ty::Int(IntTy::Isize) => {
109109
let x = ffi::call::<isize>(ptr, libffi_args.as_slice());
110110
// `isize` doesn't `impl Into<i128>`, so convert manually.
111111
// Convert to `i64` since this covers both 32- and 64-bit machines.
112112
this.write_int(i64::try_from(x).unwrap(), dest)?;
113113
return Ok(());
114114
}
115115
// uints
116-
TyKind::Uint(UintTy::U8) => {
116+
ty::Uint(UintTy::U8) => {
117117
let x = ffi::call::<u8>(ptr, libffi_args.as_slice());
118118
this.write_int(x, dest)?;
119119
return Ok(());
120120
}
121-
TyKind::Uint(UintTy::U16) => {
121+
ty::Uint(UintTy::U16) => {
122122
let x = ffi::call::<u16>(ptr, libffi_args.as_slice());
123123
this.write_int(x, dest)?;
124124
return Ok(());
125125
}
126-
TyKind::Uint(UintTy::U32) => {
126+
ty::Uint(UintTy::U32) => {
127127
let x = ffi::call::<u32>(ptr, libffi_args.as_slice());
128128
this.write_int(x, dest)?;
129129
return Ok(());
130130
}
131-
TyKind::Uint(UintTy::U64) => {
131+
ty::Uint(UintTy::U64) => {
132132
let x = ffi::call::<u64>(ptr, libffi_args.as_slice());
133133
this.write_int(x, dest)?;
134134
return Ok(());
135135
}
136-
TyKind::Uint(UintTy::Usize) => {
136+
ty::Uint(UintTy::Usize) => {
137137
let x = ffi::call::<usize>(ptr, libffi_args.as_slice());
138138
// `usize` doesn't `impl Into<i128>`, so convert manually.
139139
// Convert to `u64` since this covers both 32- and 64-bit machines.
@@ -142,7 +142,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
142142
}
143143
// Functions with no declared return type (i.e., the default return)
144144
// have the output_type `Tuple([])`.
145-
TyKind::Tuple(t_list) =>
145+
ty::Tuple(t_list) =>
146146
if t_list.len() == 0 {
147147
ffi::call::<()>(ptr, libffi_args.as_slice());
148148
return Ok(());
@@ -226,7 +226,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
226226
for cur_arg in args.iter() {
227227
libffi_args.push(Self::scalar_to_carg(
228228
this.read_scalar(cur_arg)?,
229-
&cur_arg.layout.ty,
229+
cur_arg.layout.ty,
230230
this,
231231
)?);
232232
}

0 commit comments

Comments
 (0)