Skip to content

Commit 35b2669

Browse files
committed
Check the map for promotable instead for existance of a node (which is always the case)
1 parent 3e108b7 commit 35b2669

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

clippy_lints/src/methods.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,11 +836,10 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir:
836836

837837
// don't lint for constant values
838838
// FIXME: can we `expect` here instead of match?
839-
let owner = cx.tcx.hir.get_parent(arg.id);
840-
let owner_def = cx.tcx.hir.local_def_id(owner);
839+
let owner_def = cx.tcx.hir.get_parent_did(arg.id);
841840
let promotable = cx.tcx
842841
.rvalue_promotable_map(owner_def)
843-
.contains_key(&arg.hir_id.local_id);
842+
[&arg.hir_id.local_id];
844843
if promotable {
845844
return;
846845
}

tests/ui/methods.stderr

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,37 @@ error: unnecessary structure name repetition
318318
263 | fn new() -> Foo { Foo }
319319
| ^^^ help: use the applicable keyword: `Self`
320320

321+
error: use of `unwrap_or` followed by a function call
322+
--> $DIR/methods.rs:281:5
323+
|
324+
281 | with_constructor.unwrap_or(make());
325+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_constructor.unwrap_or_else(make)`
326+
|
327+
= note: `-D or-fun-call` implied by `-D warnings`
328+
321329
error: use of `unwrap_or` followed by a call to `new`
322330
--> $DIR/methods.rs:284:5
323331
|
324332
284 | with_new.unwrap_or(Vec::new());
325333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_new.unwrap_or_default()`
334+
335+
error: use of `unwrap_or` followed by a function call
336+
--> $DIR/methods.rs:287:5
326337
|
327-
= note: `-D or-fun-call` implied by `-D warnings`
338+
287 | with_const_args.unwrap_or(Vec::with_capacity(12));
339+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_const_args.unwrap_or_else(|| Vec::with_capacity(12))`
340+
341+
error: use of `unwrap_or` followed by a function call
342+
--> $DIR/methods.rs:290:5
343+
|
344+
290 | with_err.unwrap_or(make());
345+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_err.unwrap_or_else(|_| make())`
346+
347+
error: use of `unwrap_or` followed by a function call
348+
--> $DIR/methods.rs:293:5
349+
|
350+
293 | with_err_args.unwrap_or(Vec::with_capacity(12));
351+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_err_args.unwrap_or_else(|_| Vec::with_capacity(12))`
328352

329353
error: use of `unwrap_or` followed by a call to `default`
330354
--> $DIR/methods.rs:296:5
@@ -338,6 +362,36 @@ error: use of `unwrap_or` followed by a call to `default`
338362
299 | with_default_type.unwrap_or(u64::default());
339363
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_default_type.unwrap_or_default()`
340364

365+
error: use of `unwrap_or` followed by a function call
366+
--> $DIR/methods.rs:302:5
367+
|
368+
302 | with_vec.unwrap_or(vec![]);
369+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_vec.unwrap_or_else(|| < [ _ ] > :: into_vec ( box [ $ ( $ x ) , * ] ))`
370+
371+
error: use of `unwrap_or` followed by a function call
372+
--> $DIR/methods.rs:307:5
373+
|
374+
307 | without_default.unwrap_or(Foo::new());
375+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `without_default.unwrap_or_else(Foo::new)`
376+
377+
error: use of `or_insert` followed by a function call
378+
--> $DIR/methods.rs:310:5
379+
|
380+
310 | map.entry(42).or_insert(String::new());
381+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `map.entry(42).or_insert_with(String::new)`
382+
383+
error: use of `or_insert` followed by a function call
384+
--> $DIR/methods.rs:313:5
385+
|
386+
313 | btree.entry(42).or_insert(String::new());
387+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `btree.entry(42).or_insert_with(String::new)`
388+
389+
error: use of `unwrap_or` followed by a function call
390+
--> $DIR/methods.rs:316:13
391+
|
392+
316 | let _ = stringy.unwrap_or("".to_owned());
393+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `stringy.unwrap_or_else(|| "".to_owned())`
394+
341395
error: called `.iter().nth()` on a Vec. Calling `.get()` is both faster and more readable
342396
--> $DIR/methods.rs:327:23
343397
|

0 commit comments

Comments
 (0)