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
commit faa97568a0
3 changed files with 20 additions and 0 deletions

View File

@ -104,12 +104,18 @@ impl LateLintPass<'_> for ManualMap {
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;
}

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,
};
}

View File

@ -212,4 +212,11 @@ fn main() {
None => None,
};
}
// #7077
let s = &String::new();
let _: Option<&str> = match Some(s) {
Some(s) => Some(s),
None => None,
};
}