explicitly handle errors in select
This commit is contained in:
parent
e873eef1e3
commit
479968b812
1 changed files with 19 additions and 13 deletions
|
@ -38,6 +38,7 @@ use crate::traits::project::ProjectionCacheKeyExt;
|
||||||
use rustc_ast::attr;
|
use rustc_ast::attr;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
|
use rustc_errors::ErrorReported;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::lang_items;
|
use rustc_hir::lang_items;
|
||||||
|
@ -514,17 +515,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
|
|
||||||
let evaluate = |c: &'tcx ty::Const<'tcx>| {
|
let evaluate = |c: &'tcx ty::Const<'tcx>| {
|
||||||
if let ty::ConstKind::Unevaluated(def_id, substs, promoted) = c.val {
|
if let ty::ConstKind::Unevaluated(def_id, substs, promoted) = c.val {
|
||||||
match self.infcx.const_eval_resolve(
|
self.infcx
|
||||||
obligation.param_env,
|
.const_eval_resolve(
|
||||||
def_id,
|
obligation.param_env,
|
||||||
substs,
|
def_id,
|
||||||
promoted,
|
substs,
|
||||||
Some(obligation.cause.span),
|
promoted,
|
||||||
) {
|
Some(obligation.cause.span),
|
||||||
Ok(val) => Ok(ty::Const::from_value(self.tcx(), val, c.ty)),
|
)
|
||||||
Err(ErrorHandled::TooGeneric) => Err(EvaluatedToAmbig),
|
.map(|val| ty::Const::from_value(self.tcx(), val, c.ty))
|
||||||
Err(_) => Err(EvaluatedToErr),
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Ok(c)
|
Ok(c)
|
||||||
}
|
}
|
||||||
|
@ -537,8 +536,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
Err(_) => Ok(EvaluatedToErr),
|
Err(_) => Ok(EvaluatedToErr),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Err(EvaluatedToErr), _) | (_, Err(EvaluatedToErr)) => Ok(EvaluatedToErr),
|
(Err(ErrorHandled::Reported(ErrorReported)), _)
|
||||||
_ => Ok(EvaluatedToAmbig),
|
| (_, Err(ErrorHandled::Reported(ErrorReported))) => Ok(EvaluatedToErr),
|
||||||
|
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => span_bug!(
|
||||||
|
obligation.cause.span(self.tcx()),
|
||||||
|
"ConstEquate: const_eval_resolve returned an unexpected error"
|
||||||
|
),
|
||||||
|
(Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
|
||||||
|
Ok(EvaluatedToAmbig)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue