Replaced some unwrap_or and map_or with lazy variants#82456
Replaced some unwrap_or and map_or with lazy variants#82456bors merged 3 commits intorust-lang:masterfrom
Conversation
|
r? @estebank (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
There's a bug in rust-log-analyzer, it shows: but here actually: |
estebank
left a comment
There was a problem hiding this comment.
You can always pass any callable to a place that expects a closure, as long as the number of arguments matches. I'm surprised we don't lint about this.
| let mut names = generics | ||
| .parent | ||
| .map_or(vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id))); | ||
| .map_or_else(|| vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id))); |
There was a problem hiding this comment.
| .map_or_else(|| vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id))); | |
| .map_or_else(Vec::new, |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id))); |
| .parent | ||
| .map_or(vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id))); | ||
| let mut names = generics.parent.map_or_else( | ||
| || vec![], |
There was a problem hiding this comment.
| || vec![], | |
| Vec::new, |
| let name = name_buf.map_or( | ||
| String::new(), // We got a NULL ptr, ignore `name_len`. | ||
| let name = name_buf.map_or_else( | ||
| || String::new(), // We got a NULL ptr, ignore `name_len`. |
There was a problem hiding this comment.
| || String::new(), // We got a NULL ptr, ignore `name_len`. | |
| String::new, // We got a NULL ptr, ignore `name_len`. |
| let name = | ||
| with_no_trimmed_paths(|| ty::tls::with(|tcx| tcx.def_path_str(cid.instance.def_id()))); | ||
| let prom = cid.promoted.map_or(String::new(), |p| format!("::promoted[{:?}]", p)); | ||
| let prom = cid.promoted.map_or_else(|| String::new(), |p| format!("::promoted[{:?}]", p)); |
There was a problem hiding this comment.
| let prom = cid.promoted.map_or_else(|| String::new(), |p| format!("::promoted[{:?}]", p)); | |
| let prom = cid.promoted.map_or_else(String::new, |p| format!("::promoted[{:?}]", p)); |
| let mut i = tokens.iter(); | ||
| // This might be a sign we need a connect method on `Iterator`. | ||
| let b = i.next().map_or(String::new(), |t| t.to_string()); | ||
| let b = i.next().map_or_else(|| String::new(), |t| t.to_string()); |
There was a problem hiding this comment.
| let b = i.next().map_or_else(|| String::new(), |t| t.to_string()); | |
| let b = i.next().map_or_else(String::new, |t| t.to_string()); |
| overlap.self_desc.map_or(String::new(), |ty| format!(" for `{}`", ty)) | ||
| overlap | ||
| .self_desc | ||
| .map_or_else(|| String::new(), |ty| format!(" for `{}`", ty)) |
There was a problem hiding this comment.
| .map_or_else(|| String::new(), |ty| format!(" for `{}`", ty)) | |
| .map_or_else(String::new, |ty| format!(" for `{}`", ty)) |
| self.fcx | ||
| .associated_item(def_id, name, Namespace::ValueNS) | ||
| .map_or(Vec::new(), |x| vec![x]) | ||
| .map_or_else(|| Vec::new(), |x| vec![x]) |
There was a problem hiding this comment.
| .map_or_else(|| Vec::new(), |x| vec![x]) | |
| .map_or_else(Vec::new, |x| vec![x]) |
| tcx.sess | ||
| .source_map() | ||
| .span_to_snippet(span) | ||
| .map_or_else(|_| String::new(), |s| format!(" `{}`", s)), |
There was a problem hiding this comment.
| .map_or_else(|_| String::new(), |s| format!(" `{}`", s)), | |
| .map_or_else(String::new, |s| format!(" `{}`", s)), |
There was a problem hiding this comment.
as long as the number of arguments matches
You catched me here and with next 2 suggestions )
| let path_str = sm | ||
| .span_to_snippet(sm.span_until_char(pat.span, '(')) | ||
| .map_or(String::new(), |s| format!(" `{}`", s.trim_end())); | ||
| .map_or_else(|_| String::new(), |s| format!(" `{}`", s.trim_end())); |
There was a problem hiding this comment.
| .map_or_else(|_| String::new(), |s| format!(" `{}`", s.trim_end())); | |
| .map_or_else(String::new, |s| format!(" `{}`", s.trim_end())); |
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
|
📌 Commit 08b1e80 has been approved by |
Replaced some unwrap_or and map_or with lazy variants Replaced some `unwrap_or` and `map_or` with `unwrap_or_else` and `map_or_else`.
Replaced some unwrap_or and map_or with lazy variants Replaced some `unwrap_or` and `map_or` with `unwrap_or_else` and `map_or_else`.
…laumeGomez Rollup of 8 pull requests Successful merges: - rust-lang#81940 (Stabilize str_split_once) - rust-lang#82165 (Reword labels on E0308 involving async fn return type) - rust-lang#82456 (Replaced some unwrap_or and map_or with lazy variants) - rust-lang#82491 (Consider inexpensive inlining criteria first) - rust-lang#82506 (Properly account for non-shorthand pattern field in unused variable lint) - rust-lang#82535 (Set codegen thread names) - rust-lang#82545 (rustdoc: add optional woff2 versions of FiraSans.) - rust-lang#82549 (Revert "Update normalize.css to 8.0.1") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Replaced some
unwrap_orandmap_orwithunwrap_or_elseandmap_or_else.