Skip to content

Commit b651d5a

Browse files
Fix Inline MIR pass on a function with un-satisfiable bounds
1 parent ee5d8d3 commit b651d5a

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

compiler/rustc_mir_transform/src/inline.rs

Lines changed: 11 additions & 2 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ pub fn codegen_fulfill_obligation<'tcx>(
6565
Err(Unimplemented) => {
6666
// This can trigger when we probe for the source of a `'static` lifetime requirement
6767
// on a trait object: `impl Foo for dyn Trait {}` has an implicit `'static` bound.
68+
// This can also trigger when we have a global bound that is not actually satisfied,
69+
// but was included during typeck due to the trivial_bounds feature.
6870
infcx.tcx.sess.delay_span_bug(
6971
rustc_span::DUMMY_SP,
7072
&format!(
Lines changed: 10 additions & 0 deletions
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() {}
Lines changed: 12 additions & 0 deletions
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)