Skip to content

Commit da779a0

Browse files
Rollup merge of rust-lang#152139 - khyperia:mgca-negative-literals, r=BoxyUwU
mGCA: Support directly represented negated literals fixes rust-lang#152123 PatExprKind already awkwardly tacks on a `negated: bool` for the same purpose: https://github.com/rust-lang/rust/blob/8bccf1224deab49b54694c9090e577bfe90a94e6/compiler/rustc_hir/src/hir.rs#L1954-L1959 perhaps one day we should indeed do that FIXME... r? @BoxyUwU
2 parents cec007b + e94a62d commit da779a0

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

clippy_lints/src/utils/author.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
325325
ConstArgKind::Infer(..) => chain!(self, "let ConstArgKind::Infer(..) = {const_arg}.kind"),
326326
ConstArgKind::Error(..) => chain!(self, "let ConstArgKind::Error(..) = {const_arg}.kind"),
327327
ConstArgKind::Tup(..) => chain!(self, "let ConstArgKind::Tup(..) = {const_arg}.kind"),
328-
ConstArgKind::Literal(..) => chain!(self, "let ConstArgKind::Literal(..) = {const_arg}.kind"),
328+
ConstArgKind::Literal { .. } => chain!(self, "let ConstArgKind::Literal {{ .. }} = {const_arg}.kind"),
329329
}
330330
}
331331

clippy_utils/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ pub fn const_item_rhs_to_expr<'tcx>(tcx: TyCtxt<'tcx>, ct_rhs: ConstItemRhs<'tcx
11421142
ConstArgKind::Anon(anon) => Some(tcx.hir_body(anon.body).value),
11431143
ConstArgKind::Struct(..)
11441144
| ConstArgKind::Tup(..)
1145-
| ConstArgKind::Literal(..)
1145+
| ConstArgKind::Literal { .. }
11461146
| ConstArgKind::TupleCall(..)
11471147
| ConstArgKind::Array(..)
11481148
| ConstArgKind::Path(_)

clippy_utils/src/hir_utils.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,16 @@ impl HirEqInterExpr<'_, '_, '_> {
686686
.zip(*args_b)
687687
.all(|(arg_a, arg_b)| self.eq_const_arg(arg_a, arg_b))
688688
},
689-
(ConstArgKind::Literal(kind_l), ConstArgKind::Literal(kind_r)) => kind_l == kind_r,
689+
(
690+
ConstArgKind::Literal {
691+
lit: kind_l,
692+
negated: negated_l,
693+
},
694+
ConstArgKind::Literal {
695+
lit: kind_r,
696+
negated: negated_r,
697+
},
698+
) => kind_l == kind_r && negated_l == negated_r,
690699
(ConstArgKind::Array(l_arr), ConstArgKind::Array(r_arr)) => {
691700
l_arr.elems.len() == r_arr.elems.len()
692701
&& l_arr
@@ -703,7 +712,7 @@ impl HirEqInterExpr<'_, '_, '_> {
703712
| ConstArgKind::TupleCall(..)
704713
| ConstArgKind::Infer(..)
705714
| ConstArgKind::Struct(..)
706-
| ConstArgKind::Literal(..)
715+
| ConstArgKind::Literal { .. }
707716
| ConstArgKind::Array(..)
708717
| ConstArgKind::Error(..),
709718
_,
@@ -1599,7 +1608,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
15991608
}
16001609
},
16011610
ConstArgKind::Infer(..) | ConstArgKind::Error(..) => {},
1602-
ConstArgKind::Literal(lit) => lit.hash(&mut self.s),
1611+
ConstArgKind::Literal { lit, negated } => {
1612+
lit.hash(&mut self.s);
1613+
negated.hash(&mut self.s);
1614+
},
16031615
}
16041616
}
16051617

0 commit comments

Comments
 (0)