Skip to content

Commit 6219984

Browse files
committed
Last few tweaks
1 parent 2e215b9 commit 6219984

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,6 @@ Released 2018-09-13
14901490
[`large_stack_arrays`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays
14911491
[`len_without_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty
14921492
[`len_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
1493-
[`let_and_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
14941493
[`let_underscore_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_lock
14951494
[`let_underscore_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_must_use
14961495
[`let_unit_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value

clippy_lints/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11521152
LintId::of(&needless_continue::NEEDLESS_CONTINUE),
11531153
LintId::of(&needless_pass_by_value::NEEDLESS_PASS_BY_VALUE),
11541154
LintId::of(&non_expressive_names::SIMILAR_NAMES),
1155+
LintId::of(&option_if_let_else::OPTION_IF_LET_ELSE),
11551156
LintId::of(&ranges::RANGE_PLUS_ONE),
11561157
LintId::of(&shadow::SHADOW_UNRELATED),
11571158
LintId::of(&strings::STRING_ADD_ASSIGN),
@@ -1362,7 +1363,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13621363
LintId::of(&non_expressive_names::MANY_SINGLE_CHAR_NAMES),
13631364
LintId::of(&open_options::NONSENSICAL_OPEN_OPTIONS),
13641365
LintId::of(&option_env_unwrap::OPTION_ENV_UNWRAP),
1365-
LintId::of(&option_if_let_else::OPTION_IF_LET_ELSE),
13661366
LintId::of(&overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL),
13671367
LintId::of(&panic_unimplemented::PANIC_PARAMS),
13681368
LintId::of(&partialeq_ne_impl::PARTIALEQ_NE_IMPL),
@@ -1511,7 +1511,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15111511
LintId::of(&new_without_default::NEW_WITHOUT_DEFAULT),
15121512
LintId::of(&non_expressive_names::JUST_UNDERSCORES_AND_DIGITS),
15131513
LintId::of(&non_expressive_names::MANY_SINGLE_CHAR_NAMES),
1514-
LintId::of(&option_if_let_else::OPTION_IF_LET_ELSE),
15151514
LintId::of(&panic_unimplemented::PANIC_PARAMS),
15161515
LintId::of(&ptr::CMP_NULL),
15171516
LintId::of(&ptr::PTR_ARG),

clippy_lints/src/minmax.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,16 @@ fn fetch_const<'a>(
8787
if args.len() != 2 {
8888
return None;
8989
}
90-
constant_simple(cx, cx.tables, &args[0]).map_or_else(
91-
|| {
92-
constant_simple(cx, cx.tables, &args[1]).map(|c| (c, &args[0]))
93-
},
94-
|c| {
95-
if constant_simple(cx, cx.tables, &args[1]).is_none() {
96-
// otherwise ignore
97-
Some((c, &args[1]))
98-
} else {
99-
None
100-
}
90+
if let Some(c) = constant_simple(cx, cx.tables, &args[0]) {
91+
if constant_simple(cx, cx.tables, &args[1]).is_none() {
92+
// otherwise ignore
93+
Some((m, c, &args[1]))
94+
} else {
95+
None
10196
}
102-
).map(|(c, arg)| (m, c, arg))
97+
} else if let Some(c) = constant_simple(cx, cx.tables, &args[1]) {
98+
Some((m, c, &args[0]))
99+
} else {
100+
None
101+
}
103102
}

clippy_lints/src/option_if_let_else.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ declare_clippy_lint! {
6363
/// }, |foo| foo);
6464
/// ```
6565
pub OPTION_IF_LET_ELSE,
66-
style,
66+
pedantic,
6767
"reimplementation of Option::map_or"
6868
}
6969

clippy_lints/src/returns.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,15 @@ fn is_unit_expr(expr: &ast::Expr) -> bool {
259259

260260
fn lint_unneeded_unit_return(cx: &EarlyContext<'_>, ty: &ast::Ty, span: Span) {
261261
let (ret_span, appl) = if let Ok(fn_source) = cx.sess().source_map().span_to_snippet(span.with_hi(ty.span.hi())) {
262-
fn_source.rfind("->").map_or((ty.span, Applicability::MaybeIncorrect), |rpos| (
262+
if let Some(rpos) = fn_source.rfind("->") {
263+
#[allow(clippy::cast_possible_truncation)]
264+
(
263265
ty.span.with_lo(BytePos(span.lo().0 + rpos as u32)),
264266
Applicability::MachineApplicable,
265-
))
267+
)
268+
} else {
269+
(ty.span, Applicability::MaybeIncorrect)
270+
}
266271
} else {
267272
(ty.span, Applicability::MaybeIncorrect)
268273
};

src/lintlist/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
16151615
},
16161616
Lint {
16171617
name: "option_if_let_else",
1618-
group: "style",
1618+
group: "pedantic",
16191619
desc: "reimplementation of Option::map_or",
16201620
deprecation: None,
16211621
module: "option_if_let_else",

0 commit comments

Comments
 (0)