Rollup merge of #93024 - compiler-errors:inline-mir-bad-bounds, r=estebank
Do not ICE when inlining a function with un-satisfiable bounds Fixes #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.
This commit is contained in:
commit
cf3cd4c48a
@ -7,6 +7,7 @@
|
|||||||
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
|
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
|
||||||
use rustc_middle::mir::visit::*;
|
use rustc_middle::mir::visit::*;
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
|
use rustc_middle::traits::ObligationCause;
|
||||||
use rustc_middle::ty::subst::Subst;
|
use rustc_middle::ty::subst::Subst;
|
||||||
use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
|
use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
|
||||||
use rustc_span::{hygiene::ExpnKind, ExpnData, Span};
|
use rustc_span::{hygiene::ExpnKind, ExpnData, Span};
|
||||||
@ -75,10 +76,18 @@ fn inline<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let param_env = tcx.param_env_reveal_all_normalized(def_id);
|
||||||
|
let param_env = rustc_trait_selection::traits::normalize_param_env_or_error(
|
||||||
|
tcx,
|
||||||
|
def_id,
|
||||||
|
param_env,
|
||||||
|
ObligationCause::misc(body.span, hir_id),
|
||||||
|
);
|
||||||
|
|
||||||
let mut this = Inliner {
|
let mut this = Inliner {
|
||||||
tcx,
|
tcx,
|
||||||
param_env: tcx.param_env_reveal_all_normalized(body.source.def_id()),
|
param_env,
|
||||||
codegen_fn_attrs: tcx.codegen_fn_attrs(body.source.def_id()),
|
codegen_fn_attrs: tcx.codegen_fn_attrs(def_id),
|
||||||
hir_id,
|
hir_id,
|
||||||
history: Vec::new(),
|
history: Vec::new(),
|
||||||
changed: false,
|
changed: false,
|
||||||
|
@ -64,6 +64,8 @@ pub fn codegen_fulfill_obligation<'tcx>(
|
|||||||
Err(Unimplemented) => {
|
Err(Unimplemented) => {
|
||||||
// This can trigger when we probe for the source of a `'static` lifetime requirement
|
// This can trigger when we probe for the source of a `'static` lifetime requirement
|
||||||
// on a trait object: `impl Foo for dyn Trait {}` has an implicit `'static` bound.
|
// on a trait object: `impl Foo for dyn Trait {}` has an implicit `'static` bound.
|
||||||
|
// This can also trigger when we have a global bound that is not actually satisfied,
|
||||||
|
// but was included during typeck due to the trivial_bounds feature.
|
||||||
infcx.tcx.sess.delay_span_bug(
|
infcx.tcx.sess.delay_span_bug(
|
||||||
rustc_span::DUMMY_SP,
|
rustc_span::DUMMY_SP,
|
||||||
&format!(
|
&format!(
|
||||||
|
10
src/test/ui/trait-bounds/issue-93008.rs
Normal file
10
src/test/ui/trait-bounds/issue-93008.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// compile-flags: -Zmir-opt-level=4
|
||||||
|
|
||||||
|
pub fn bar<T>(s: &'static mut ())
|
||||||
|
where
|
||||||
|
&'static mut (): Clone, //~ ERROR the trait bound
|
||||||
|
{
|
||||||
|
<&'static mut () as Clone>::clone(&s);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
12
src/test/ui/trait-bounds/issue-93008.stderr
Normal file
12
src/test/ui/trait-bounds/issue-93008.stderr
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
error[E0277]: the trait bound `&'static mut (): Clone` is not satisfied
|
||||||
|
--> $DIR/issue-93008.rs:5:5
|
||||||
|
|
|
||||||
|
LL | &'static mut (): Clone,
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `&'static mut ()`
|
||||||
|
|
|
||||||
|
= help: see issue #48214
|
||||||
|
= help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Reference in New Issue
Block a user