mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 11:12:43 +00:00
Integrate suggestion spans
This commit is contained in:
parent
3516d45d7c
commit
cb86c57c5f
@ -132,27 +132,25 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
||||
db.span_suggestion(input.span,
|
||||
&format!("consider changing the type to `{}`", slice_ty),
|
||||
slice_ty);
|
||||
return;
|
||||
return; // `Vec` and `String` cannot be destructured - no need for `*` suggestion
|
||||
}}
|
||||
|
||||
if match_type(cx, ty, &paths::STRING) {
|
||||
db.span_suggestion(input.span,
|
||||
"consider changing the type to `&str`",
|
||||
"&str".to_string());
|
||||
} else {
|
||||
db.span_suggestion(input.span,
|
||||
"consider taking a reference instead",
|
||||
format!("&{}", snippet(cx, input.span, "_")));
|
||||
return;
|
||||
}
|
||||
|
||||
// Suggests adding `*` to dereference the added reference if needed.
|
||||
if let Some(spans) = spans_need_deref.get(&defid) {
|
||||
let mut spans: Vec<_> = spans.iter().cloned()
|
||||
.map(|span| (span, format!("*{}", snippet(cx, span, "<expr>"))))
|
||||
.collect();
|
||||
let mut spans = vec![(input.span, format!("&{}", snippet(cx, input.span, "_")))];
|
||||
|
||||
// Suggests adding `*` to dereference the added reference.
|
||||
if let Some(deref_span) = spans_need_deref.get(&defid) {
|
||||
spans.extend(deref_span.iter().cloned()
|
||||
.map(|span| (span, format!("*{}", snippet(cx, span, "<expr>")))));
|
||||
spans.sort_by_key(|&(span, _)| span);
|
||||
multispan_sugg(db, "...and dereference it here".to_string(), spans);
|
||||
}
|
||||
multispan_sugg(db, "consider taking a reference instead".to_string(), spans);
|
||||
};
|
||||
|
||||
span_lint_and_then(cx,
|
||||
|
@ -47,7 +47,6 @@ error: this argument is passed by value, but not consumed in the function body
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
| fn test_match(x: &Option<Option<String>>, y: Option<Option<String>>) {
|
||||
help: ...and dereference it here
|
||||
| match *x {
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
@ -67,7 +66,7 @@ error: this argument is passed by value, but not consumed in the function body
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
| fn test_destructure(x: Wrapper, y: &Wrapper, z: Wrapper) {
|
||||
help: ...and dereference it here
|
||||
| let Wrapper(s) = z; // moved
|
||||
| let Wrapper(ref t) = *y; // not moved
|
||||
| let Wrapper(_) = *y; // still not moved
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user