mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Auto merge of #94255 - b-naber:use-mir-constant-in-thir, r=oli-obk
Use mir constant in thir instead of ty::Const This is blocked on https://github.com/rust-lang/rust/pull/94059 (does include its changes, the first two commits in this PR correspond to those changes) and https://github.com/rust-lang/rust/pull/93800 being reinstated (which had to be reverted). Mainly opening since `@lcnr` offered to give some feedback and maybe also for a perf-run (if necessary). This currently contains a lot of duplication since some of the logic of `ty::Const` had to be copied to `mir::ConstantKind`, but with the introduction of valtrees a lot of that functionality will disappear from `ty::Const`. Only the last commit contains changes that need to be reviewed here. Did leave some `FIXME` comments regarding future implementation decisions and some things that might be incorrectly implemented. r? `@oli-obk`
This commit is contained in:
commit
27634b03ea
3 changed files with 3 additions and 5 deletions
|
@ -40,10 +40,8 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
|
||||||
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0,
|
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0,
|
||||||
None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?,
|
None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
let lhs_val = lhs_const.int_value(cx, ty)?;
|
let lhs_val = lhs_const.int_value(cx, ty)?;
|
||||||
let rhs_val = rhs_const.int_value(cx, ty)?;
|
let rhs_val = rhs_const.int_value(cx, ty)?;
|
||||||
|
|
||||||
let rhs_bound = match range_end {
|
let rhs_bound = match range_end {
|
||||||
RangeEnd::Included => EndBound::Included(rhs_val),
|
RangeEnd::Included => EndBound::Included(rhs_val),
|
||||||
RangeEnd::Excluded => EndBound::Excluded(rhs_val),
|
RangeEnd::Excluded => EndBound::Excluded(rhs_val),
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for NegMultiply {
|
||||||
fn check_mul(cx: &LateContext<'_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) {
|
fn check_mul(cx: &LateContext<'_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ExprKind::Lit(ref l) = lit.kind;
|
if let ExprKind::Lit(ref l) = lit.kind;
|
||||||
if consts::lit_to_constant(&l.node, cx.typeck_results().expr_ty_opt(lit)) == Constant::Int(1);
|
if consts::lit_to_mir_constant(&l.node, cx.typeck_results().expr_ty_opt(lit)) == Constant::Int(1);
|
||||||
if cx.typeck_results().expr_ty(exp).is_integral();
|
if cx.typeck_results().expr_ty(exp).is_integral();
|
||||||
|
|
||||||
then {
|
then {
|
||||||
|
|
|
@ -179,7 +179,7 @@ impl Constant {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a `LitKind` to a `Constant`.
|
/// Parses a `LitKind` to a `Constant`.
|
||||||
pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
|
pub fn lit_to_mir_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
|
||||||
match *lit {
|
match *lit {
|
||||||
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
|
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
|
||||||
LitKind::Byte(b) => Constant::Int(u128::from(b)),
|
LitKind::Byte(b) => Constant::Int(u128::from(b)),
|
||||||
|
@ -301,7 +301,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
||||||
if is_direct_expn_of(e.span, "cfg").is_some() {
|
if is_direct_expn_of(e.span, "cfg").is_some() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(lit_to_constant(&lit.node, self.typeck_results.expr_ty_opt(e)))
|
Some(lit_to_mir_constant(&lit.node, self.typeck_results.expr_ty_opt(e)))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ExprKind::Array(vec) => self.multi(vec).map(Constant::Vec),
|
ExprKind::Array(vec) => self.multi(vec).map(Constant::Vec),
|
||||||
|
|
Loading…
Reference in a new issue