Skip to content

Commit 67758c0

Browse files
authored
Rollup merge of rust-lang#93024 - compiler-errors:inline-mir-bad-bounds, r=estebank
Do not ICE when inlining a function with un-satisfiable bounds Fixes rust-lang#93008 This is kinda a hack... but it's the fix I thought had the least blast-radius. We use `normalize_param_env_or_error` to verify that the predicates in the param env are self-consistent, since with RevealAll, a bad predicate like `<&'static () as Clone>` will be evaluated with an empty ParamEnv (since it references no generics), and we'll raise an error for it.
2 parents 5194ec6 + b651d5a commit 67758c0

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

compiler/rustc_mir_transform/src/inline.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_index::vec::Idx;
77
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
88
use rustc_middle::mir::visit::*;
99
use rustc_middle::mir::*;
10+
use rustc_middle::traits::ObligationCause;
1011
use rustc_middle::ty::subst::Subst;
1112
use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
1213
use rustc_span::{hygiene::ExpnKind, ExpnData, Span};
@@ -75,10 +76,18 @@ fn inline<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool {
7576
return false;
7677
}
7778

79+
let param_env = tcx.param_env_reveal_all_normalized(def_id);
80+
let param_env = rustc_trait_selection::traits::normalize_param_env_or_error(
81+
tcx,
82+
def_id,
83+
param_env,
84+
ObligationCause::misc(body.span, hir_id),
85+
);
86+
7887
let mut this = Inliner {
7988
tcx,
80-
param_env: tcx.param_env_reveal_all_normalized(body.source.def_id()),
81-
codegen_fn_attrs: tcx.codegen_fn_attrs(body.source.def_id()),
89+
param_env,
90+
codegen_fn_attrs: tcx.codegen_fn_attrs(def_id),
8291
hir_id,
8392
history: Vec::new(),
8493
changed: false,

compiler/rustc_trait_selection/src/traits/codegen.rs

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ pub fn codegen_fulfill_obligation<'tcx>(
6464
Err(Unimplemented) => {
6565
// This can trigger when we probe for the source of a `'static` lifetime requirement
6666
// on a trait object: `impl Foo for dyn Trait {}` has an implicit `'static` bound.
67+
// This can also trigger when we have a global bound that is not actually satisfied,
68+
// but was included during typeck due to the trivial_bounds feature.
6769
infcx.tcx.sess.delay_span_bug(
6870
rustc_span::DUMMY_SP,
6971
&format!(
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-flags: -Zmir-opt-level=4
2+
3+
pub fn bar<T>(s: &'static mut ())
4+
where
5+
&'static mut (): Clone, //~ ERROR the trait bound
6+
{
7+
<&'static mut () as Clone>::clone(&s);
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0277]: the trait bound `&'static mut (): Clone` is not satisfied
2+
--> $DIR/issue-93008.rs:5:5
3+
|
4+
LL | &'static mut (): Clone,
5+
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `&'static mut ()`
6+
|
7+
= help: see issue #48214
8+
= help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)