diff options
| author | Michael Goulet <michael@errs.io> | 2024-02-11 19:17:42 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-02-11 19:17:42 +0000 |
| commit | 9789e88cfe7f50ac46d04175e32df4329d75024e (patch) | |
| tree | ac1abf10202f57df0e1fa956062a42f110d031ab /compiler/rustc_mir_transform/src/inline.rs | |
| parent | 899c895ba4558737d8e3235b5d864d985bf28e95 (diff) | |
| download | rust-9789e88cfe7f50ac46d04175e32df4329d75024e.tar.gz rust-9789e88cfe7f50ac46d04175e32df4329d75024e.zip | |
Check that the ABI of the instance we are inlining is correct
Diffstat (limited to 'compiler/rustc_mir_transform/src/inline.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/inline.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index be19bd8349e..956d855ab81 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -2,6 +2,7 @@ use crate::deref_separator::deref_finder; use rustc_attr::InlineAttr; use rustc_const_eval::transform::validate::validate_types; +use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_index::bit_set::BitSet; use rustc_index::Idx; @@ -384,6 +385,17 @@ impl<'tcx> Inliner<'tcx> { } let fn_sig = self.tcx.fn_sig(def_id).instantiate(self.tcx, args); + + // Additionally, check that the body that we're inlining actually agrees + // with the ABI of the trait that the item comes from. + if let InstanceDef::Item(instance_def_id) = callee.def + && self.tcx.def_kind(instance_def_id) == DefKind::AssocFn + && let instance_fn_sig = self.tcx.fn_sig(instance_def_id).skip_binder() + && instance_fn_sig.abi() != fn_sig.abi() + { + return None; + } + let source_info = SourceInfo { span: fn_span, ..terminator.source_info }; return Some(CallSite { callee, fn_sig, block: bb, source_info }); |
