Skip to content

Commit 7485f8b

Browse files
authored
Rollup merge of #128616 - compiler-errors:mir-inline-tainted, r=cjgillot
Don't inline tainted MIR bodies Don't inline MIR bodies that are tainted, since they're not necessarily well-formed. Fixes #128601 (I didn't add a new test, just copied one from the crashes, since they're the same root cause). Fixes #122909.
2 parents fac7753 + 65b029b commit 7485f8b

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

compiler/rustc_mir_transform/src/inline.rs

+4
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@ impl<'tcx> Inliner<'tcx> {
505505
) -> Result<(), &'static str> {
506506
let tcx = self.tcx;
507507

508+
if let Some(_) = callee_body.tainted_by_errors {
509+
return Err("Body is tainted");
510+
}
511+
508512
let mut threshold = if self.caller_is_inline_forwarder {
509513
self.tcx.sess.opts.unstable_opts.inline_mir_forwarder_threshold.unwrap_or(30)
510514
} else if cross_crate_inlinable {
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes
2-
//@ known-bug: #122909
32

3+
#![feature(unboxed_closures)]
44

5-
use std::sync::{Arc, Context, Weak};
5+
use std::sync::Arc;
66

77
pub struct WeakOnce<T>();
8+
//~^ ERROR type parameter `T` is never used
9+
810
impl<T> WeakOnce<T> {
911
extern "rust-call" fn try_get(&self) -> Option<Arc<T>> {}
12+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
13+
//~| ERROR mismatched types
1014

1115
pub fn get(&self) -> Arc<T> {
1216
self.try_get()
1317
.unwrap_or_else(|| panic!("Singleton {} not available", std::any::type_name::<T>()))
1418
}
1519
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0392]: type parameter `T` is never used
2+
--> $DIR/inline-tainted-body.rs:7:21
3+
|
4+
LL | pub struct WeakOnce<T>();
5+
| ^ unused type parameter
6+
|
7+
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
8+
= help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead
9+
10+
error: functions with the "rust-call" ABI must take a single non-self tuple argument
11+
--> $DIR/inline-tainted-body.rs:11:35
12+
|
13+
LL | extern "rust-call" fn try_get(&self) -> Option<Arc<T>> {}
14+
| ^^^^^
15+
16+
error[E0308]: mismatched types
17+
--> $DIR/inline-tainted-body.rs:11:45
18+
|
19+
LL | extern "rust-call" fn try_get(&self) -> Option<Arc<T>> {}
20+
| ------- ^^^^^^^^^^^^^^ expected `Option<Arc<T>>`, found `()`
21+
| |
22+
| implicitly returns `()` as its body has no tail or `return` expression
23+
|
24+
= note: expected enum `Option<Arc<T>>`
25+
found unit type `()`
26+
27+
error: aborting due to 3 previous errors
28+
29+
Some errors have detailed explanations: E0308, E0392.
30+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)