Skip to content

Commit

Permalink
Auto merge of rust-lang#109128 - chenyukang:yukang/remove-type-ascrip…
Browse files Browse the repository at this point in the history
…tion, r=estebank

Remove type ascription from parser and diagnostics

Mostly based on rust-lang#106826

Part of rust-lang#101728

r? `@estebank`
  • Loading branch information
bors committed May 2, 2023
2 parents eac589b + d4baabe commit d36bde7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions clippy_utils/src/sugg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ impl<'a> Sugg<'a> {
get_snippet(rhs.span),
),
hir::ExprKind::Cast(lhs, ty) => Sugg::BinOp(AssocOp::As, get_snippet(lhs.span), get_snippet(ty.span)),
hir::ExprKind::Type(lhs, ty) => Sugg::BinOp(AssocOp::Colon, get_snippet(lhs.span), get_snippet(ty.span)),
//FIXME(chenyukang), remove this after type ascription is removed from AST
hir::ExprKind::Type(lhs, ty) => Sugg::BinOp(AssocOp::As, get_snippet(lhs.span), get_snippet(ty.span)),
}
}

Expand Down Expand Up @@ -258,8 +259,9 @@ impl<'a> Sugg<'a> {
snippet_with_context(cx, lhs.span, ctxt, default, app).0,
snippet_with_context(cx, ty.span, ctxt, default, app).0,
),
//FIXME(chenyukang), remove this after type ascription is removed from AST
ast::ExprKind::Type(ref lhs, ref ty) => Sugg::BinOp(
AssocOp::Colon,
AssocOp::As,
snippet_with_context(cx, lhs.span, ctxt, default, app).0,
snippet_with_context(cx, ty.span, ctxt, default, app).0,
),
Expand Down Expand Up @@ -392,7 +394,6 @@ fn binop_to_string(op: AssocOp, lhs: &str, rhs: &str) -> String {
AssocOp::As => format!("{lhs} as {rhs}"),
AssocOp::DotDot => format!("{lhs}..{rhs}"),
AssocOp::DotDotEq => format!("{lhs}..={rhs}"),
AssocOp::Colon => format!("{lhs}: {rhs}"),
}
}

Expand Down Expand Up @@ -602,13 +603,13 @@ enum Associativity {
#[must_use]
fn associativity(op: AssocOp) -> Associativity {
use rustc_ast::util::parser::AssocOp::{
Add, As, Assign, AssignOp, BitAnd, BitOr, BitXor, Colon, Divide, DotDot, DotDotEq, Equal, Greater,
Add, As, Assign, AssignOp, BitAnd, BitOr, BitXor, Divide, DotDot, DotDotEq, Equal, Greater,
GreaterEqual, LAnd, LOr, Less, LessEqual, Modulus, Multiply, NotEqual, ShiftLeft, ShiftRight, Subtract,
};

match op {
Assign | AssignOp(_) => Associativity::Right,
Add | BitAnd | BitOr | BitXor | LAnd | LOr | Multiply | As | Colon => Associativity::Both,
Add | BitAnd | BitOr | BitXor | LAnd | LOr | Multiply | As => Associativity::Both,
Divide | Equal | Greater | GreaterEqual | Less | LessEqual | Modulus | NotEqual | ShiftLeft | ShiftRight
| Subtract => Associativity::Left,
DotDot | DotDotEq => Associativity::None,
Expand Down

0 comments on commit d36bde7

Please sign in to comment.