Auto merge of #115748 - RalfJung:post-mono, r=oli-obk
move required_consts check to general post-mono-check function This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same `eval` functions as everyone else to get the evaluated MIR constants. Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) https://github.com/rust-lang/rust/issues/115709: ensuring that all locals are dynamically sized. I didn't expect this to change diagnostics, but it's just cycle errors that change. r? `@oli-obk`
This commit is contained in:
commit
cebb9cfd4f
76 changed files with 385 additions and 361 deletions
|
@ -956,8 +956,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
match self.infcx.try_const_eval_resolve(param_env, unevaluated, ty, None) {
|
||||
Ok(ct) => Some(ct),
|
||||
Err(ErrorHandled::Reported(e)) => Some(ty::Const::new_error(self.tcx(), e.into(), ty)),
|
||||
Err(ErrorHandled::TooGeneric) => None,
|
||||
Err(ErrorHandled::Reported(e, _)) => {
|
||||
Some(ty::Const::new_error(self.tcx(), e.into(), ty))
|
||||
}
|
||||
Err(ErrorHandled::TooGeneric(_)) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -793,7 +793,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
|||
span: tcx.def_span(unevaluated.def),
|
||||
unevaluated: unevaluated,
|
||||
});
|
||||
Err(ErrorHandled::Reported(reported.into()))
|
||||
Err(ErrorHandled::Reported(reported.into(), tcx.def_span(unevaluated.def)))
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
|
|
|
@ -73,13 +73,13 @@ pub fn is_const_evaluatable<'tcx>(
|
|||
ty::ConstKind::Unevaluated(uv) => {
|
||||
let concrete = infcx.const_eval_resolve(param_env, uv, Some(span));
|
||||
match concrete {
|
||||
Err(ErrorHandled::TooGeneric) => {
|
||||
Err(ErrorHandled::TooGeneric(_)) => {
|
||||
Err(NotConstEvaluatable::Error(infcx.tcx.sess.delay_span_bug(
|
||||
span,
|
||||
"Missing value for constant, but no error reported?",
|
||||
)))
|
||||
}
|
||||
Err(ErrorHandled::Reported(e)) => Err(NotConstEvaluatable::Error(e.into())),
|
||||
Err(ErrorHandled::Reported(e, _)) => Err(NotConstEvaluatable::Error(e.into())),
|
||||
Ok(_) => Ok(()),
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ pub fn is_const_evaluatable<'tcx>(
|
|||
.emit()
|
||||
}
|
||||
|
||||
Err(ErrorHandled::TooGeneric) => {
|
||||
Err(ErrorHandled::TooGeneric(_)) => {
|
||||
let err = if uv.has_non_region_infer() {
|
||||
NotConstEvaluatable::MentionsInfer
|
||||
} else if uv.has_non_region_param() {
|
||||
|
@ -147,7 +147,7 @@ pub fn is_const_evaluatable<'tcx>(
|
|||
|
||||
Err(err)
|
||||
}
|
||||
Err(ErrorHandled::Reported(e)) => Err(NotConstEvaluatable::Error(e.into())),
|
||||
Err(ErrorHandled::Reported(e, _)) => Err(NotConstEvaluatable::Error(e.into())),
|
||||
Ok(_) => Ok(()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -560,30 +560,31 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
|||
|
||||
let stalled_on = &mut pending_obligation.stalled_on;
|
||||
|
||||
let mut evaluate =
|
||||
|c: Const<'tcx>| {
|
||||
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
|
||||
match self.selcx.infcx.try_const_eval_resolve(
|
||||
obligation.param_env,
|
||||
unevaluated,
|
||||
c.ty(),
|
||||
Some(obligation.cause.span),
|
||||
) {
|
||||
Ok(val) => Ok(val),
|
||||
Err(e) => match e {
|
||||
ErrorHandled::TooGeneric => {
|
||||
let mut evaluate = |c: Const<'tcx>| {
|
||||
if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
|
||||
match self.selcx.infcx.try_const_eval_resolve(
|
||||
obligation.param_env,
|
||||
unevaluated,
|
||||
c.ty(),
|
||||
Some(obligation.cause.span),
|
||||
) {
|
||||
Ok(val) => Ok(val),
|
||||
Err(e) => {
|
||||
match e {
|
||||
ErrorHandled::TooGeneric(..) => {
|
||||
stalled_on.extend(unevaluated.args.iter().filter_map(
|
||||
TyOrConstInferVar::maybe_from_generic_arg,
|
||||
));
|
||||
Err(ErrorHandled::TooGeneric)
|
||||
}
|
||||
_ => Err(e),
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
Err(e)
|
||||
}
|
||||
} else {
|
||||
Ok(c)
|
||||
}
|
||||
};
|
||||
} else {
|
||||
Ok(c)
|
||||
}
|
||||
};
|
||||
|
||||
match (evaluate(c1), evaluate(c2)) {
|
||||
(Ok(c1), Ok(c2)) => {
|
||||
|
@ -603,13 +604,14 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
|||
),
|
||||
}
|
||||
}
|
||||
(Err(ErrorHandled::Reported(reported)), _)
|
||||
| (_, Err(ErrorHandled::Reported(reported))) => ProcessResult::Error(
|
||||
(Err(ErrorHandled::Reported(reported, _)), _)
|
||||
| (_, Err(ErrorHandled::Reported(reported, _))) => ProcessResult::Error(
|
||||
CodeSelectionError(SelectionError::NotConstEvaluatable(
|
||||
NotConstEvaluatable::Error(reported.into()),
|
||||
)),
|
||||
),
|
||||
(Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
|
||||
(Err(ErrorHandled::TooGeneric(_)), _)
|
||||
| (_, Err(ErrorHandled::TooGeneric(_))) => {
|
||||
if c1.has_non_region_infer() || c2.has_non_region_infer() {
|
||||
ProcessResult::Unchanged
|
||||
} else {
|
||||
|
|
|
@ -989,9 +989,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
Err(_) => Ok(EvaluatedToErr),
|
||||
}
|
||||
}
|
||||
(Err(ErrorHandled::Reported(_)), _)
|
||||
| (_, Err(ErrorHandled::Reported(_))) => Ok(EvaluatedToErr),
|
||||
(Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
|
||||
(Err(ErrorHandled::Reported(..)), _)
|
||||
| (_, Err(ErrorHandled::Reported(..))) => Ok(EvaluatedToErr),
|
||||
(Err(ErrorHandled::TooGeneric(..)), _)
|
||||
| (_, Err(ErrorHandled::TooGeneric(..))) => {
|
||||
if c1.has_non_region_infer() || c2.has_non_region_infer() {
|
||||
Ok(EvaluatedToAmbig)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue