/// ```
/// opt.map(|arg| { takes_ref(arg) });
/// ```
- fn can_use_as_ref(&self, expr: &hir::Expr) -> Option<(Span, &'static str, String)> {
+ fn can_use_as_ref(
+ &self,
+ expr: &hir::Expr,
+ ) -> Option<(Span, &'static str, String)> {
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = expr.node {
if let hir::def::Def::Local(id) = path.def {
let parent = self.tcx.hir().get_parent_node(id);
self_ty.starts_with("std::option::Option") ||
self_ty.starts_with("std::result::Result")
) && (name == "map" || name == "and_then");
- if is_as_ref_able {
- return Some((span.shrink_to_lo(),
- "consider using `as_ref` instead",
- "as_ref().".into()));
+ match (is_as_ref_able, self.sess().source_map().span_to_snippet(*span)) {
+ (true, Ok(src)) => {
+ return Some((*span, "consider using `as_ref` instead",
+ format!("as_ref().{}", src)));
+ },
+ _ => ()
}
}
}
--> $DIR/as-ref.rs:6:27
|
LL | opt.map(|arg| takes_ref(arg));
- | - ^^^ expected &Foo, found struct `Foo`
+ | --- ^^^ expected &Foo, found struct `Foo`
| |
- | help: consider using `as_ref` instead: `as_ref().`
+ | help: consider using `as_ref` instead: `as_ref().map`
|
= note: expected type `&Foo`
found type `Foo`
--> $DIR/as-ref.rs:8:37
|
LL | opt.and_then(|arg| Some(takes_ref(arg)));
- | - ^^^ expected &Foo, found struct `Foo`
+ | -------- ^^^ expected &Foo, found struct `Foo`
| |
- | help: consider using `as_ref` instead: `as_ref().`
+ | help: consider using `as_ref` instead: `as_ref().and_then`
|
= note: expected type `&Foo`
found type `Foo`
--> $DIR/as-ref.rs:11:27
|
LL | opt.map(|arg| takes_ref(arg));
- | - ^^^ expected &Foo, found struct `Foo`
+ | --- ^^^ expected &Foo, found struct `Foo`
| |
- | help: consider using `as_ref` instead: `as_ref().`
+ | help: consider using `as_ref` instead: `as_ref().map`
|
= note: expected type `&Foo`
found type `Foo`
--> $DIR/as-ref.rs:13:35
|
LL | opt.and_then(|arg| Ok(takes_ref(arg)));
- | - ^^^ expected &Foo, found struct `Foo`
+ | -------- ^^^ expected &Foo, found struct `Foo`
| |
- | help: consider using `as_ref` instead: `as_ref().`
+ | help: consider using `as_ref` instead: `as_ref().and_then`
|
= note: expected type `&Foo`
found type `Foo`