- // Dereference suggestion
- let sugg = |db: &mut DiagnosticBuilder| {
- let deref_span = spans_need_deref.get(&canonical_id);
- if_let_chain! {[
- match_type(cx, ty, &paths::VEC),
- let Some(clone_spans) =
- get_spans(cx, Some(body.id()), idx, &[("clone", ".to_owned()")]),
- let TyPath(QPath::Resolved(_, ref path)) = input.node,
- let Some(elem_ty) = path.segments.iter()
- .find(|seg| seg.name == "Vec")
- .and_then(|ps| ps.parameters.as_ref())
- .map(|params| ¶ms.types[0]),
- ], {
- let slice_ty = format!("&[{}]", snippet(cx, elem_ty.span, "_"));
- db.span_suggestion(input.span,
- "consider changing the type to",
- slice_ty);
-
- for (span, suggestion) in clone_spans {
- db.span_suggestion(
- span,
- &snippet_opt(cx, span)
- .map_or(
- "change the call to".into(),
- |x| Cow::from(format!("change `{}` to", x)),
- ),
- suggestion.into()
- );
+ // Dereference suggestion
+ let sugg = |db: &mut DiagnosticBuilder| {
+ let deref_span = spans_need_deref.get(&canonical_id);
+ if_chain! {
+ if match_type(cx, ty, &paths::VEC);
+ if let Some(clone_spans) =
+ get_spans(cx, Some(body.id()), idx, &[("clone", ".to_owned()")]);
+ if let TyPath(QPath::Resolved(_, ref path)) = input.node;
+ if let Some(elem_ty) = path.segments.iter()
+ .find(|seg| seg.name == "Vec")
+ .and_then(|ps| ps.parameters.as_ref())
+ .map(|params| ¶ms.types[0]);
+ then {
+ let slice_ty = format!("&[{}]", snippet(cx, elem_ty.span, "_"));
+ db.span_suggestion(input.span,
+ "consider changing the type to",
+ slice_ty);
+
+ for (span, suggestion) in clone_spans {
+ db.span_suggestion(
+ span,
+ &snippet_opt(cx, span)
+ .map_or(
+ "change the call to".into(),
+ |x| Cow::from(format!("change `{}` to", x)),
+ ),
+ suggestion.into()
+ );
+ }
+
+ // cannot be destructured, no need for `*` suggestion
+ assert!(deref_span.is_none());
+ return;
+ }