diff --git a/compiler/rustc_codegen_llvm/src/gotoc/intrinsic.rs b/compiler/rustc_codegen_llvm/src/gotoc/intrinsic.rs index 4e09e3c64f9f..88ee89a44a4e 100644 --- a/compiler/rustc_codegen_llvm/src/gotoc/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/gotoc/intrinsic.rs @@ -153,17 +153,11 @@ impl<'tcx> GotocCtx<'tcx> { () => {{ let value = self .tcx - .const_eval_instance(ty::ParamEnv::reveal_all(), instance, None) + .const_eval_instance(ty::ParamEnv::reveal_all(), instance, span) .unwrap(); - // We may have an implicit cast between machine equivalent - // types where CBMC expects a different type than Rust. - let place_type = self.codegen_ty(self.place_ty(p)); - let e = self - .codegen_const_value(value, self.tcx.types.usize, None) - .cast_to_machine_equivalent_type( - &place_type, - &self.symbol_table.machine_model(), - ); + // We assume that the intrinsic has type checked at this point, so + // we can use the place type as the expression type. + let e = self.codegen_const_value(value, self.place_ty(p), span.as_ref()); self.codegen_expr_to_place(p, e) }}; } diff --git a/src/test/cbmc/DynTrait/dyn_fn_param_fail_fixme.rs b/src/test/cbmc/DynTrait/dyn_fn_param_fail_fixme.rs index 72008a5a8d16..1fbcac65bf4d 100644 --- a/src/test/cbmc/DynTrait/dyn_fn_param_fail_fixme.rs +++ b/src/test/cbmc/DynTrait/dyn_fn_param_fail_fixme.rs @@ -15,7 +15,7 @@ include!("../../rmc-prelude.rs"); fn takes_dyn_fun(fun: &dyn Fn() -> u32) { let x = fun(); __VERIFIER_expect_fail(x != 5, "Wrong return"); - + /* The function dynamic object has no associated data */ __VERIFIER_expect_fail(size_from_vtable(vtable!(fun)) != 0, "Wrong size"); } diff --git a/src/test/cbmc/Intrinsics/needs_drop.rs b/src/test/cbmc/Intrinsics/needs_drop.rs new file mode 100644 index 000000000000..808051eadeaf --- /dev/null +++ b/src/test/cbmc/Intrinsics/needs_drop.rs @@ -0,0 +1,26 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 OR MIT + +// Check that we get the expected results for needs_drop intrinsic + +use std::mem; + +pub struct Foo { + _foo: T, +} + +impl Foo { + fn call_needs_drop(&self) -> bool { + return mem::needs_drop::(); + } +} + +fn main() { + // Integers don't need to be dropped + let int_foo = Foo:: { _foo: 0 }; + assert!(!int_foo.call_needs_drop()); + + // But strings do need to be dropped + let string_foo = Foo:: { _foo: "".to_string() }; + assert!(string_foo.call_needs_drop()); +}