Skip to content

Commit 34b373d

Browse files
committed
Rename HIR UnOp variants
This renames the variants in HIR UnOp from enum UnOp { UnDeref, UnNot, UnNeg, } to enum UnOp { Deref, Not, Neg, } Motivations: - This is more consistent with the rest of the code base where most enum variants don't have a prefix. - These variants are never used without the `UnOp` prefix so the extra `Un` prefix doesn't help with readability. E.g. we don't have any `UnDeref`s in the code, we only have `UnOp::UnDeref`. - MIR `UnOp` type variants don't have a prefix so this is more consistent with MIR types. - "un" prefix reads like "inverse" or "reverse", so as a beginner in rustc code base when I see "UnDeref" what comes to my mind is something like "&*" instead of just "*".
1 parent a5d442c commit 34b373d

26 files changed

+43
-43
lines changed

clippy_lints/src/arithmetic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic {
9191
match op.node {
9292
hir::BinOpKind::Div | hir::BinOpKind::Rem => match &r.kind {
9393
hir::ExprKind::Lit(_lit) => (),
94-
hir::ExprKind::Unary(hir::UnOp::UnNeg, expr) => {
94+
hir::ExprKind::Unary(hir::UnOp::Neg, expr) => {
9595
if let hir::ExprKind::Lit(lit) = &expr.kind {
9696
if let rustc_ast::ast::LitKind::Int(1, _) = lit.node {
9797
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
@@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic {
114114
self.expr_span = Some(expr.span);
115115
}
116116
},
117-
hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => {
117+
hir::ExprKind::Unary(hir::UnOp::Neg, arg) => {
118118
let ty = cx.typeck_results().expr_ty(arg);
119119
if constant_simple(cx, cx.typeck_results(), expr).is_none() {
120120
if ty.is_integral() {

clippy_lints/src/assertions_on_constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ enum AssertKind {
112112
fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
113113
if_chain! {
114114
if let ExprKind::If(ref cond, ref then, _) = expr.kind;
115-
if let ExprKind::Unary(UnOp::UnNot, ref expr) = cond.kind;
115+
if let ExprKind::Unary(UnOp::Not, ref expr) = cond.kind;
116116
// bind the first argument of the `assert!` macro
117117
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr);
118118
// block

clippy_lints/src/booleans.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
110110
// prevent folding of `cfg!` macros and the like
111111
if !e.span.from_expansion() {
112112
match &e.kind {
113-
ExprKind::Unary(UnOp::UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)),
113+
ExprKind::Unary(UnOp::Not, inner) => return Ok(Bool::Not(box self.run(inner)?)),
114114
ExprKind::Binary(binop, lhs, rhs) => match &binop.node {
115115
BinOpKind::Or => {
116116
return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?));
@@ -454,7 +454,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
454454
ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => {
455455
self.bool_expr(e)
456456
},
457-
ExprKind::Unary(UnOp::UnNot, inner) => {
457+
ExprKind::Unary(UnOp::Not, inner) => {
458458
if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() {
459459
self.bool_expr(e);
460460
} else {
@@ -482,7 +482,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
482482
type Map = Map<'tcx>;
483483

484484
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
485-
if let ExprKind::Unary(UnOp::UnNot, inner) = &expr.kind {
485+
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind {
486486
if let Some(suggestion) = simplify_not(self.cx, inner) {
487487
span_lint_and_sugg(
488488
self.cx,

clippy_lints/src/bytecount.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn check_arg(name: Symbol, arg: Symbol, needle: &Expr<'_>) -> bool {
101101

102102
fn get_path_name(expr: &Expr<'_>) -> Option<Symbol> {
103103
match expr.kind {
104-
ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => {
104+
ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::Deref, ref e) => {
105105
get_path_name(e)
106106
},
107107
ExprKind::Block(ref b, _) => {

clippy_lints/src/collapsible_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn addr_adjusted_binding(mut expr: &Expr<'_>, cx: &LateContext<'_>) -> Option<Hi
186186
Res::Local(binding_id) => break Some(binding_id),
187187
_ => break None,
188188
},
189-
ExprKind::Unary(UnOp::UnDeref, e) if cx.typeck_results().expr_ty(e).is_ref() => expr = e,
189+
ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty(e).is_ref() => expr = e,
190190
_ => break None,
191191
}
192192
}

clippy_lints/src/consts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
242242
self.expr(value).map(|v| Constant::Repeat(Box::new(v), n))
243243
},
244244
ExprKind::Unary(op, ref operand) => self.expr(operand).and_then(|o| match op {
245-
UnOp::UnNot => self.constant_not(&o, self.typeck_results.expr_ty(e)),
246-
UnOp::UnNeg => self.constant_negate(&o, self.typeck_results.expr_ty(e)),
247-
UnOp::UnDeref => Some(if let Constant::Ref(r) = o { *r } else { o }),
245+
UnOp::Not => self.constant_not(&o, self.typeck_results.expr_ty(e)),
246+
UnOp::Neg => self.constant_negate(&o, self.typeck_results.expr_ty(e)),
247+
UnOp::Deref => Some(if let Constant::Ref(r) = o { *r } else { o }),
248248
}),
249249
ExprKind::If(ref cond, ref then, ref otherwise) => self.ifthenelse(cond, then, *otherwise),
250250
ExprKind::Binary(op, ref left, ref right) => self.binop(op, left, right),

clippy_lints/src/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ declare_lint_pass!(HashMapPass => [MAP_ENTRY]);
5555
impl<'tcx> LateLintPass<'tcx> for HashMapPass {
5656
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
5757
if let ExprKind::If(ref check, ref then_block, ref else_block) = expr.kind {
58-
if let ExprKind::Unary(UnOp::UnNot, ref check) = check.kind {
58+
if let ExprKind::Unary(UnOp::Not, ref check) = check.kind {
5959
if let Some((ty, map, key)) = check_cond(cx, check) {
6060
// in case of `if !m.contains_key(&k) { m.insert(k, v); }`
6161
// we can give a better error message

clippy_lints/src/floating_point_arithmetic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn get_specialized_log_method(cx: &LateContext<'_>, base: &Expr<'_>) -> Option<&
129129
fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Sugg<'a> {
130130
let mut suggestion = Sugg::hir(cx, expr, "..");
131131

132-
if let ExprKind::Unary(UnOp::UnNeg, inner_expr) = &expr.kind {
132+
if let ExprKind::Unary(UnOp::Neg, inner_expr) = &expr.kind {
133133
expr = &inner_expr;
134134
}
135135

@@ -541,12 +541,12 @@ fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
541541
/// If the two expressions are not negations of each other, then it
542542
/// returns None.
543543
fn are_negated<'a>(cx: &LateContext<'_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a>) -> Option<(bool, &'a Expr<'a>)> {
544-
if let ExprKind::Unary(UnOp::UnNeg, expr1_negated) = &expr1.kind {
544+
if let ExprKind::Unary(UnOp::Neg, expr1_negated) = &expr1.kind {
545545
if eq_expr_value(cx, expr1_negated, expr2) {
546546
return Some((false, expr2));
547547
}
548548
}
549-
if let ExprKind::Unary(UnOp::UnNeg, expr2_negated) = &expr2.kind {
549+
if let ExprKind::Unary(UnOp::Neg, expr2_negated) = &expr2.kind {
550550
if eq_expr_value(cx, expr1, expr2_negated) {
551551
return Some((true, expr1));
552552
}

clippy_lints/src/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
644644
}
645645
}
646646
},
647-
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref ptr) => self.check_arg(ptr),
647+
hir::ExprKind::Unary(hir::UnOp::Deref, ref ptr) => self.check_arg(ptr),
648648
_ => (),
649649
}
650650

clippy_lints/src/map_clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
7070
},
7171
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, .., name, None) => {
7272
match closure_expr.kind {
73-
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => {
73+
hir::ExprKind::Unary(hir::UnOp::Deref, ref inner) => {
7474
if ident_eq(name, inner) {
7575
if let ty::Ref(.., Mutability::Not) = cx.typeck_results().expr_ty(inner).kind() {
7676
lint(cx, e.span, args[0].span, true);

0 commit comments

Comments
 (0)