use std::convert::TryInto;
use std::fmt::Display;
use syntax::ast;
-use syntax::parse::token;
use syntax::print::pprust::token_kind_to_string;
use syntax::source_map::{CharPos, Span};
+use syntax::token;
use syntax::util::parser::AssocOp;
use syntax_pos::{BytePos, Pos};
pub fn hir_opt(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> Option<Self> {
snippet_opt(cx, expr.span).map(|snippet| {
let snippet = Cow::Owned(snippet);
- Self::hir_from_snippet(expr, snippet)
+ Self::hir_from_snippet(cx, expr, snippet)
})
}
pub fn hir_with_macro_callsite(cx: &LateContext<'_, '_>, expr: &hir::Expr, default: &'a str) -> Self {
let snippet = snippet_with_macro_callsite(cx, expr.span, default);
- Self::hir_from_snippet(expr, snippet)
+ Self::hir_from_snippet(cx, expr, snippet)
}
/// Generate a suggestion for an expression with the given snippet. This is used by the `hir_*`
/// function variants of `Sugg`, since these use different snippet functions.
- fn hir_from_snippet(expr: &hir::Expr, snippet: Cow<'a, str>) -> Self {
- match expr.node {
+ fn hir_from_snippet(cx: &LateContext<'_, '_>, expr: &hir::Expr, snippet: Cow<'a, str>) -> Self {
+ if let Some(range) = higher::range(cx, expr) {
+ let op = match range.limits {
+ ast::RangeLimits::HalfOpen => AssocOp::DotDot,
+ ast::RangeLimits::Closed => AssocOp::DotDotEq,
+ };
+ return Sugg::BinOp(op, snippet);
+ }
+
+ match expr.kind {
hir::ExprKind::AddrOf(..)
| hir::ExprKind::Box(..)
- | hir::ExprKind::Closure(.., _)
+ | hir::ExprKind::Closure(..)
| hir::ExprKind::Unary(..)
| hir::ExprKind::Match(..) => Sugg::MaybeParen(snippet),
hir::ExprKind::Continue(..)
let snippet = snippet(cx, expr.span, default);
- match expr.node {
+ match expr.kind {
ast::ExprKind::AddrOf(..)
| ast::ExprKind::Box(..)
| ast::ExprKind::Closure(..)
/// Chained `as` and explicit `:` type coercion never need inner parenthesis so
/// they are considered
/// associative.
+#[must_use]
fn associativity(op: &AssocOp) -> Associativity {
use syntax::util::parser::AssocOp::*;
/// Converts a `hir::BinOp` to the corresponding assigning binary operator.
fn hirbinop2assignop(op: hir::BinOp) -> AssocOp {
- use syntax::parse::token::BinOpToken::*;
+ use syntax::token::BinOpToken::*;
AssocOp::AssignOp(match op.node {
hir::BinOpKind::Add => Plus,
/// Converts an `ast::BinOp` to the corresponding assigning binary operator.
fn astbinop2assignop(op: ast::BinOp) -> AssocOp {
use syntax::ast::BinOpKind::*;
- use syntax::parse::token::BinOpToken;
+ use syntax::token::BinOpToken;
AssocOp::AssignOp(match op.node {
Add => BinOpToken::Plus,