+ if let Some(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_string()"), ("as_str", "")]) {
+ span_lint_and_then(
+ cx,
+ PTR_ARG,
+ arg.span,
+ "writing `&String` instead of `&str` involves a new object where a slice will do.",
+ |db| {
+ db.span_suggestion(arg.span, "change this to", "&str".into());
+ for (clonespan, suggestion) in spans {
+ db.span_suggestion_short(
+ clonespan,
+ &snippet_opt(cx, clonespan).map_or(
+ "change the call to".into(),
+ |x| Cow::Owned(format!("change `{}` to", x)),
+ ),
+ suggestion.into(),
+ );
+ }
+ },
+ );
+ }
+ } else if match_type(cx, ty, &paths::COW) {
+ if_chain! {
+ if let TyRptr(_, MutTy { ref ty, ..} ) = arg.node;
+ if let TyPath(ref path) = ty.node;
+ if let QPath::Resolved(None, ref pp) = *path;
+ if let [ref bx] = *pp.segments;
+ if let Some(ref params) = bx.args;
+ if !params.parenthesized;
+ if let Some(inner) = params.args.iter().find_map(|arg| match arg {
+ GenericArg::Type(ty) => Some(ty),
+ GenericArg::Lifetime(_) => None,
+ });
+ then {
+ let replacement = snippet_opt(cx, inner.span);
+ if let Some(r) = replacement {
+ span_lint_and_then(
+ cx,
+ PTR_ARG,
+ arg.span,
+ "using a reference to `Cow` is not recommended.",
+ |db| {
+ db.span_suggestion(arg.span, "change this to", "&".to_owned() + &r);
+ },
+ );
+ }
+ }
+ }