Auto merge of #7085 - Jarcho:manual_map_autoderef, r=giraffate

Don't allow adjustments for `manual_map`

fixes: #7077

The other option here would be to add the return type to the closure. It would be fine for simple types, but longer types can be rather unwieldy. Could also implement the adjustment manually.

changelog: Don't lint `manual_map` when type adjustments are added. e.g. autoderef
This commit is contained in:
bors
2021-04-16 03:05:52 +00:00
3 changed files with 20 additions and 0 deletions
+6
View File
@@ -104,12 +104,18 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
None => return,
};
// These two lints will go back and forth with each other.
if cx.typeck_results().expr_ty(some_expr) == cx.tcx.types.unit
&& !is_allowed(cx, OPTION_MAP_UNIT_FN, expr.hir_id)
{
return;
}
// `map` won't perform any adjustments.
if !cx.typeck_results().expr_adjustments(some_expr).is_empty() {
return;
}
if !can_move_expr_to_closure(cx, some_expr) {
return;
}
+7
View File
@@ -146,4 +146,11 @@ fn main() {
None => None,
};
}
// #7077
let s = &String::new();
let _: Option<&str> = match Some(s) {
Some(s) => Some(s),
None => None,
};
}
+7
View File
@@ -212,4 +212,11 @@ const fn f4() {
None => None,
};
}
// #7077
let s = &String::new();
let _: Option<&str> = match Some(s) {
Some(s) => Some(s),
None => None,
};
}