|
1 | 1 | use crate::prelude::*; |
| 2 | +use rustc_middle::{mir, ty}; |
2 | 3 |
|
3 | 4 | #[derive( |
4 | 5 | Clone, Debug, Serialize, Deserialize, JsonSchema, Hash, PartialEq, Eq, PartialOrd, Ord, |
@@ -188,7 +189,6 @@ pub(crate) fn scalar_int_to_constant_literal<'tcx, S: UnderOwnerState<'tcx>>( |
188 | 189 | x: rustc_middle::ty::ScalarInt, |
189 | 190 | ty: rustc_middle::ty::Ty, |
190 | 191 | ) -> ConstantLiteral { |
191 | | - use rustc_middle::ty; |
192 | 192 | match ty.kind() { |
193 | 193 | ty::Char => ConstantLiteral::Char( |
194 | 194 | char::try_from(x) |
@@ -222,7 +222,6 @@ pub(crate) fn scalar_to_constant_expr<'tcx, S: UnderOwnerState<'tcx>>( |
222 | 222 | span: rustc_span::Span, |
223 | 223 | ) -> ConstantExpr { |
224 | 224 | use rustc_middle::mir::Mutability; |
225 | | - use rustc_middle::ty; |
226 | 225 | let cspan = span.sinto(s); |
227 | 226 | // The documentation explicitly says not to match on a scalar. |
228 | 227 | // We match on the type and use it to convert the value. |
@@ -388,21 +387,23 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug { |
388 | 387 | } |
389 | 388 | } |
390 | 389 | } |
391 | | -impl<'tcx> ConstantExt<'tcx> for rustc_middle::ty::Const<'tcx> { |
| 390 | +impl<'tcx> ConstantExt<'tcx> for ty::Const<'tcx> { |
392 | 391 | fn eval_constant<S: UnderOwnerState<'tcx>>(&self, s: &S) -> Option<Self> { |
393 | | - let evaluated = self.eval(s.base().tcx, s.param_env()); |
| 392 | + let evaluated = self.eval(s.base().tcx, s.param_env(), None).ok()?; |
| 393 | + let evaluated = ty::Const::new(s.base().tcx, ty::ConstKind::Value(evaluated), self.ty()); |
394 | 394 | (&evaluated != self).then_some(evaluated) |
395 | 395 | } |
396 | 396 | } |
397 | | -impl<'tcx> ConstantExt<'tcx> for rustc_middle::mir::ConstantKind<'tcx> { |
| 397 | +impl<'tcx> ConstantExt<'tcx> for mir::ConstantKind<'tcx> { |
398 | 398 | fn eval_constant<S: UnderOwnerState<'tcx>>(&self, s: &S) -> Option<Self> { |
399 | | - let evaluated = self.eval(s.base().tcx, s.param_env()); |
| 399 | + let evaluated = self.eval(s.base().tcx, s.param_env(), None).ok()?; |
| 400 | + let evaluated = mir::ConstantKind::Val(evaluated, self.ty()); |
400 | 401 | (&evaluated != self).then_some(evaluated) |
401 | 402 | } |
402 | 403 | } |
403 | | -impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ConstantExpr> for rustc_middle::ty::Const<'tcx> { |
| 404 | +impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ConstantExpr> for ty::Const<'tcx> { |
404 | 405 | fn sinto(&self, s: &S) -> ConstantExpr { |
405 | | - use rustc_middle::{query::Key, ty}; |
| 406 | + use rustc_middle::query::Key; |
406 | 407 | let span = self.default_span(s.base().tcx); |
407 | 408 | let kind = match self.kind() { |
408 | 409 | ty::ConstKind::Param(p) => ConstantExprKind::ConstRef { id: p.sinto(s) }, |
@@ -434,7 +435,6 @@ pub(crate) fn valtree_to_constant_expr<'tcx, S: UnderOwnerState<'tcx>>( |
434 | 435 | ty: rustc_middle::ty::Ty<'tcx>, |
435 | 436 | span: rustc_span::Span, |
436 | 437 | ) -> ConstantExpr { |
437 | | - use rustc_middle::ty; |
438 | 438 | let kind = match (valtree, ty.kind()) { |
439 | 439 | (_, ty::Ref(_, inner_ty, _)) => { |
440 | 440 | ConstantExprKind::Borrow(valtree_to_constant_expr(s, valtree, *inner_ty, span)) |
@@ -537,7 +537,7 @@ pub fn const_value_to_constant_expr<'tcx, S: UnderOwnerState<'tcx>>( |
537 | 537 | use rustc_middle::mir::interpret::ConstValue; |
538 | 538 | match val { |
539 | 539 | ConstValue::Scalar(scalar) => scalar_to_constant_expr(s, ty, &scalar, span), |
540 | | - ConstValue::ByRef { .. } => const_value_reference_to_constant_expr(s, ty, val, span), |
| 540 | + ConstValue::Indirect { .. } => const_value_reference_to_constant_expr(s, ty, val, span), |
541 | 541 | ConstValue::Slice { data, start, end } => { |
542 | 542 | let start = start.try_into().unwrap(); |
543 | 543 | let end = end.try_into().unwrap(); |
|
0 commit comments