Rollup merge of #81913 - osa1:rename_unop_variants, r=matthewjasper
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 `*`.
This commit is contained in:
commit
a58feb9282
41 changed files with 80 additions and 80 deletions
|
@ -773,7 +773,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
if let hir::ExprKind::Lit(lit) = &expr.kind { lit.node.is_suffixed() } else { false }
|
||||
};
|
||||
let is_negative_int =
|
||||
|expr: &hir::Expr<'_>| matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::UnNeg, ..));
|
||||
|expr: &hir::Expr<'_>| matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::Neg, ..));
|
||||
let is_uint = |ty: Ty<'_>| matches!(ty.kind(), ty::Uint(..));
|
||||
|
||||
let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id);
|
||||
|
|
|
@ -321,15 +321,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
) -> Ty<'tcx> {
|
||||
let tcx = self.tcx;
|
||||
let expected_inner = match unop {
|
||||
hir::UnOp::UnNot | hir::UnOp::UnNeg => expected,
|
||||
hir::UnOp::UnDeref => NoExpectation,
|
||||
hir::UnOp::Not | hir::UnOp::Neg => expected,
|
||||
hir::UnOp::Deref => NoExpectation,
|
||||
};
|
||||
let mut oprnd_t = self.check_expr_with_expectation(&oprnd, expected_inner);
|
||||
|
||||
if !oprnd_t.references_error() {
|
||||
oprnd_t = self.structurally_resolved_type(expr.span, oprnd_t);
|
||||
match unop {
|
||||
hir::UnOp::UnDeref => {
|
||||
hir::UnOp::Deref => {
|
||||
if let Some(ty) = self.lookup_derefing(expr, oprnd, oprnd_t) {
|
||||
oprnd_t = ty;
|
||||
} else {
|
||||
|
@ -351,14 +351,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
oprnd_t = tcx.ty_error();
|
||||
}
|
||||
}
|
||||
hir::UnOp::UnNot => {
|
||||
hir::UnOp::Not => {
|
||||
let result = self.check_user_unop(expr, oprnd_t, unop);
|
||||
// If it's builtin, we can reuse the type, this helps inference.
|
||||
if !(oprnd_t.is_integral() || *oprnd_t.kind() == ty::Bool) {
|
||||
oprnd_t = result;
|
||||
}
|
||||
}
|
||||
hir::UnOp::UnNeg => {
|
||||
hir::UnOp::Neg => {
|
||||
let result = self.check_user_unop(expr, oprnd_t, unop);
|
||||
// If it's builtin, we can reuse the type, this helps inference.
|
||||
if !oprnd_t.is_numeric() {
|
||||
|
|
|
@ -681,7 +681,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
format!("cannot apply unary operator `{}`", op.as_str()),
|
||||
);
|
||||
match actual.kind() {
|
||||
Uint(_) if op == hir::UnOp::UnNeg => {
|
||||
Uint(_) if op == hir::UnOp::Neg => {
|
||||
err.note("unsigned values cannot be negated");
|
||||
|
||||
if let hir::ExprKind::Unary(
|
||||
|
@ -711,9 +711,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
Ref(_, ref lty, _) if *lty.kind() == Str => {}
|
||||
_ => {
|
||||
let missing_trait = match op {
|
||||
hir::UnOp::UnNeg => "std::ops::Neg",
|
||||
hir::UnOp::UnNot => "std::ops::Not",
|
||||
hir::UnOp::UnDeref => "std::ops::UnDerf",
|
||||
hir::UnOp::Neg => "std::ops::Neg",
|
||||
hir::UnOp::Not => "std::ops::Not",
|
||||
hir::UnOp::Deref => "std::ops::UnDerf",
|
||||
};
|
||||
suggest_impl_missing(&mut err, operand_ty, &missing_trait);
|
||||
}
|
||||
|
@ -782,9 +782,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
span_bug!(span, "&& and || are not overloadable")
|
||||
}
|
||||
}
|
||||
} else if let Op::Unary(hir::UnOp::UnNot, _) = op {
|
||||
} else if let Op::Unary(hir::UnOp::Not, _) = op {
|
||||
(sym::not, lang.not_trait())
|
||||
} else if let Op::Unary(hir::UnOp::UnNeg, _) = op {
|
||||
} else if let Op::Unary(hir::UnOp::Neg, _) = op {
|
||||
(sym::neg, lang.neg_trait())
|
||||
} else {
|
||||
bug!("lookup_op_method: op not supported: {:?}", op)
|
||||
|
|
|
@ -203,7 +203,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
|
||||
while let hir::ExprKind::Field(ref expr, _)
|
||||
| hir::ExprKind::Index(ref expr, _)
|
||||
| hir::ExprKind::Unary(hir::UnOp::UnDeref, ref expr) = exprs.last().unwrap().kind
|
||||
| hir::ExprKind::Unary(hir::UnOp::Deref, ref expr) = exprs.last().unwrap().kind
|
||||
{
|
||||
exprs.push(&expr);
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
debug!("convert_place_derefs_to_mutable: i={} expr={:?}", i, expr);
|
||||
|
||||
let mut source = self.node_ty(expr.hir_id);
|
||||
if matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::UnDeref, _)) {
|
||||
if matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::Deref, _)) {
|
||||
// Clear previous flag; after a pointer indirection it does not apply any more.
|
||||
inside_union = false;
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
hir::ExprKind::Index(ref base_expr, ..) => {
|
||||
self.convert_place_op_to_mutable(PlaceOp::Index, expr, base_expr);
|
||||
}
|
||||
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref base_expr) => {
|
||||
hir::ExprKind::Unary(hir::UnOp::Deref, ref base_expr) => {
|
||||
self.convert_place_op_to_mutable(PlaceOp::Deref, expr, base_expr);
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
@ -138,7 +138,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||
// operating on scalars, we clear the overload.
|
||||
fn fix_scalar_builtin_expr(&mut self, e: &hir::Expr<'_>) {
|
||||
match e.kind {
|
||||
hir::ExprKind::Unary(hir::UnOp::UnNeg | hir::UnOp::UnNot, ref inner) => {
|
||||
hir::ExprKind::Unary(hir::UnOp::Neg | hir::UnOp::Not, ref inner) => {
|
||||
let inner_ty = self.fcx.node_ty(inner.hir_id);
|
||||
let inner_ty = self.fcx.resolve_vars_if_possible(inner_ty);
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
|
||||
hir::ExprKind::Type(ref subexpr, _) => self.walk_expr(subexpr),
|
||||
|
||||
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref base) => {
|
||||
hir::ExprKind::Unary(hir::UnOp::Deref, ref base) => {
|
||||
// *base
|
||||
self.select_from_expr(base);
|
||||
}
|
||||
|
|
|
@ -303,7 +303,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||
|
||||
let expr_ty = self.expr_ty(expr)?;
|
||||
match expr.kind {
|
||||
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref e_base) => {
|
||||
hir::ExprKind::Unary(hir::UnOp::Deref, ref e_base) => {
|
||||
if self.typeck_results.is_method_call(expr) {
|
||||
self.cat_overloaded_place(expr, e_base)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue