Skip to content

Commit faa9756

Browse files
committed
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
2 parents 586a993 + 779d98f commit faa9756

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

clippy_lints/src/manual_map.rs

+6
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,18 @@ impl LateLintPass<'_> for ManualMap {
104104
None => return,
105105
};
106106

107+
// These two lints will go back and forth with each other.
107108
if cx.typeck_results().expr_ty(some_expr) == cx.tcx.types.unit
108109
&& !is_allowed(cx, OPTION_MAP_UNIT_FN, expr.hir_id)
109110
{
110111
return;
111112
}
112113

114+
// `map` won't perform any adjustments.
115+
if !cx.typeck_results().expr_adjustments(some_expr).is_empty() {
116+
return;
117+
}
118+
113119
if !can_move_expr_to_closure(cx, some_expr) {
114120
return;
115121
}

tests/ui/manual_map_option.fixed

+7
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,11 @@ fn main() {
146146
None => None,
147147
};
148148
}
149+
150+
// #7077
151+
let s = &String::new();
152+
let _: Option<&str> = match Some(s) {
153+
Some(s) => Some(s),
154+
None => None,
155+
};
149156
}

tests/ui/manual_map_option.rs

+7
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,11 @@ fn main() {
212212
None => None,
213213
};
214214
}
215+
216+
// #7077
217+
let s = &String::new();
218+
let _: Option<&str> = match Some(s) {
219+
Some(s) => Some(s),
220+
None => None,
221+
};
215222
}

0 commit comments

Comments
 (0)