-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(map_entry): provide explicit type when suggesting None
#15759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,15 @@ use clippy_utils::{ | |
SpanlessEq, can_move_expr_to_closure_no_visit, higher, is_expr_final_block_expr, is_expr_used_or_unified, | ||
peel_hir_expr_while, | ||
}; | ||
use core::fmt::{self, Write}; | ||
use core::fmt::Write; | ||
use rustc_errors::Applicability; | ||
use rustc_hir::hir_id::HirIdSet; | ||
use rustc_hir::intravisit::{Visitor, walk_body, walk_expr}; | ||
use rustc_hir::{Block, Expr, ExprKind, HirId, Pat, Stmt, StmtKind, UnOp}; | ||
use rustc_lint::{LateContext, LateLintPass}; | ||
use rustc_session::declare_lint_pass; | ||
use rustc_span::{DUMMY_SP, Span, SyntaxContext, sym}; | ||
use std::fmt; | ||
use std::ops::ControlFlow; | ||
|
||
declare_clippy_lint! { | ||
|
@@ -628,11 +629,8 @@ impl<'tcx> InsertSearchResults<'tcx> { | |
if is_expr_used_or_unified(cx.tcx, insertion.call) { | ||
write_wrapped(&mut res, insertion, ctxt, app); | ||
} else { | ||
let _: fmt::Result = write!( | ||
res, | ||
"e.insert({})", | ||
snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0 | ||
); | ||
let value_str = snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're cleaning up, "_" would be a better choice than ".." for a single value (even though this is never used…). Same below. |
||
let _: fmt::Result = write!(res, "e.insert({value_str})"); | ||
} | ||
span = span.trim_start(insertion.call.span).unwrap_or(DUMMY_SP); | ||
} | ||
|
@@ -644,11 +642,8 @@ impl<'tcx> InsertSearchResults<'tcx> { | |
( | ||
self.snippet(cx, span, app, |res, insertion, ctxt, app| { | ||
// Insertion into a map would return `Some(&mut value)`, but the entry returns `&mut value` | ||
let _: fmt::Result = write!( | ||
res, | ||
"Some(e.insert({}))", | ||
snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0 | ||
); | ||
let value_str = snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0; | ||
let _: fmt::Result = write!(res, "Some(e.insert({value_str}))"); | ||
}), | ||
"Occupied(mut e)", | ||
) | ||
|
@@ -658,19 +653,15 @@ impl<'tcx> InsertSearchResults<'tcx> { | |
( | ||
self.snippet(cx, span, app, |res, insertion, ctxt, app| { | ||
// Insertion into a map would return `None`, but the entry returns a mutable reference. | ||
let value_str = snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0; | ||
let _: fmt::Result = if is_expr_final_block_expr(cx.tcx, insertion.call) { | ||
write!( | ||
res, | ||
"e.insert({});\n{}None", | ||
snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0, | ||
snippet_indent(cx, insertion.call.span).as_deref().unwrap_or(""), | ||
"e.insert({value_str});\n{indent}None", | ||
indent = snippet_indent(cx, insertion.call.span).as_deref().unwrap_or(""), | ||
) | ||
} else { | ||
write!( | ||
res, | ||
"{{ e.insert({}); None }}", | ||
snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0, | ||
) | ||
write!(res, "{{ e.insert({value_str}); None }}") | ||
}; | ||
}), | ||
"Vacant(e)", | ||
|
@@ -690,7 +681,8 @@ impl<'tcx> InsertSearchResults<'tcx> { | |
"..", | ||
app, | ||
)); | ||
res.push_str(&snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0); | ||
let value_str = snippet_with_context(cx, insertion.value.span, ctxt, "..", app).0; | ||
let _: fmt::Result = write!(res, "{value_str}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not |
||
span = span.trim_start(insertion.call.span).unwrap_or(DUMMY_SP); | ||
}, | ||
Edit::RemoveSemi(semi_span) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, why not use
std::fmt::Write
sincestd::fmt
is also imported?