Rollup merge of #152139 - khyperia:mgca-negative-literals, r=BoxyUwU

mGCA: Support directly represented negated literals

fixes rust-lang/rust#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
This commit is contained in:
Jonathan Brouwer
2026-02-06 18:04:40 +01:00
committed by GitHub
3 changed files with 17 additions and 5 deletions
+1 -1
View File
@@ -325,7 +325,7 @@ fn const_arg(&self, const_arg: &Binding<&ConstArg<'_>>) {
ConstArgKind::Infer(..) => chain!(self, "let ConstArgKind::Infer(..) = {const_arg}.kind"),
ConstArgKind::Error(..) => chain!(self, "let ConstArgKind::Error(..) = {const_arg}.kind"),
ConstArgKind::Tup(..) => chain!(self, "let ConstArgKind::Tup(..) = {const_arg}.kind"),
ConstArgKind::Literal(..) => chain!(self, "let ConstArgKind::Literal(..) = {const_arg}.kind"),
ConstArgKind::Literal { .. } => chain!(self, "let ConstArgKind::Literal {{ .. }} = {const_arg}.kind"),
}
}
+1 -1
View File
@@ -1142,7 +1142,7 @@ pub fn const_item_rhs_to_expr<'tcx>(tcx: TyCtxt<'tcx>, ct_rhs: ConstItemRhs<'tcx
ConstArgKind::Anon(anon) => Some(tcx.hir_body(anon.body).value),
ConstArgKind::Struct(..)
| ConstArgKind::Tup(..)
| ConstArgKind::Literal(..)
| ConstArgKind::Literal { .. }
| ConstArgKind::TupleCall(..)
| ConstArgKind::Array(..)
| ConstArgKind::Path(_)
+15 -3
View File
@@ -686,7 +686,16 @@ fn eq_const_arg(&mut self, left: &ConstArg<'_>, right: &ConstArg<'_>) -> bool {
.zip(*args_b)
.all(|(arg_a, arg_b)| self.eq_const_arg(arg_a, arg_b))
},
(ConstArgKind::Literal(kind_l), ConstArgKind::Literal(kind_r)) => kind_l == kind_r,
(
ConstArgKind::Literal {
lit: kind_l,
negated: negated_l,
},
ConstArgKind::Literal {
lit: kind_r,
negated: negated_r,
},
) => kind_l == kind_r && negated_l == negated_r,
(ConstArgKind::Array(l_arr), ConstArgKind::Array(r_arr)) => {
l_arr.elems.len() == r_arr.elems.len()
&& l_arr
@@ -703,7 +712,7 @@ fn eq_const_arg(&mut self, left: &ConstArg<'_>, right: &ConstArg<'_>) -> bool {
| ConstArgKind::TupleCall(..)
| ConstArgKind::Infer(..)
| ConstArgKind::Struct(..)
| ConstArgKind::Literal(..)
| ConstArgKind::Literal { .. }
| ConstArgKind::Array(..)
| ConstArgKind::Error(..),
_,
@@ -1599,7 +1608,10 @@ fn hash_const_arg(&mut self, const_arg: &ConstArg<'_>) {
}
},
ConstArgKind::Infer(..) | ConstArgKind::Error(..) => {},
ConstArgKind::Literal(lit) => lit.hash(&mut self.s),
ConstArgKind::Literal { lit, negated } => {
lit.hash(&mut self.s);
negated.hash(&mut self.s);
},
}
}