mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
Fix suggestion for ranges
This commit is contained in:
parent
4578e5e15e
commit
a9cb2b9001
2 changed files with 12 additions and 4 deletions
|
@ -46,7 +46,7 @@ impl<'a> Sugg<'a> {
|
|||
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)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -84,12 +84,20 @@ impl<'a> Sugg<'a> {
|
|||
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 {
|
||||
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(..)
|
||||
|
|
|
@ -40,7 +40,7 @@ error: the variable `count` is used as a loop counter.
|
|||
--> $DIR/explicit_counter_loop.rs:130:9
|
||||
|
|
||||
LL | for _i in 3..10 {
|
||||
| ^^^^^^^^^^^^^^^ help: consider using: `for (count, _i) in 3..10.enumerate()`
|
||||
| ^^^^^^^^^^^^^^^ help: consider using: `for (count, _i) in (3..10).enumerate()`
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue