Skip to content

Commit

Permalink
Rollup merge of rust-lang#80944 - LingMan:map_or, r=nagisa
Browse files Browse the repository at this point in the history
Use Option::map_or instead of `.map(..).unwrap_or(..)`

`@rustbot` modify labels +C-cleanup +T-compiler
  • Loading branch information
JohnTitor authored Jan 15, 2021
2 parents fdeb2f2 + a56bffb commit 9053e65
Show file tree
Hide file tree
Showing 50 changed files with 67 additions and 79 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
if !generic_args.parenthesized && !has_lifetimes {
generic_args.args = self
.elided_path_lifetimes(
first_generic_span.map(|s| s.shrink_to_lo()).unwrap_or(segment.ident.span),
first_generic_span.map_or(segment.ident.span, |s| s.shrink_to_lo()),
expected_lifetimes,
)
.map(GenericArg::Lifetime)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
gate_feature_post!(
&self,
negative_impls,
span.to(of_trait.as_ref().map(|t| t.path.span).unwrap_or(span)),
span.to(of_trait.as_ref().map_or(span, |t| t.path.span)),
"negative trait bounds are not yet fully implemented; \
use marker types for now"
);
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,7 @@ pub unsafe fn with_llvm_pmb(
// reasonable defaults and prepare it to actually populate the pass
// manager.
let builder = llvm::LLVMPassManagerBuilderCreate();
let opt_size =
config.opt_size.map(|x| to_llvm_opt_settings(x).1).unwrap_or(llvm::CodeGenOptSizeNone);
let opt_size = config.opt_size.map_or(llvm::CodeGenOptSizeNone, |x| to_llvm_opt_settings(x).1);
let inline_threshold = config.inline_threshold;
let pgo_gen_path = get_pgo_gen_path(config);
let pgo_use_path = get_pgo_use_path(config);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn get_linker(
_ => match flavor {
LinkerFlavor::Lld(f) => Command::lld(linker, f),
LinkerFlavor::Msvc if sess.opts.cg.linker.is_none() && sess.target.linker.is_none() => {
Command::new(msvc_tool.as_ref().map(|t| t.path()).unwrap_or(linker))
Command::new(msvc_tool.as_ref().map_or(linker, |t| t.path()))
}
_ => Command::new(linker),
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl SelfProfilerRef {
// If there is no SelfProfiler then the filter mask is set to NONE,
// ensuring that nothing ever tries to actually access it.
let event_filter_mask =
profiler.as_ref().map(|p| p.event_filter_mask).unwrap_or(EventFilter::empty());
profiler.as_ref().map_or(EventFilter::empty(), |p| p.event_filter_mask);

SelfProfilerRef {
profiler,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
}

// If backtraces are enabled, also print the query stack
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0");

let num_frames = if backtrace { None } else { Some(2) };

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ impl HandlerInner {
}

fn treat_err_as_bug(&self) -> bool {
self.flags.treat_err_as_bug.map(|c| self.err_count() >= c).unwrap_or(false)
self.flags.treat_err_as_bug.map_or(false, |c| self.err_count() >= c)
}

fn print_error_count(&mut self, registry: &Registry) {
Expand Down Expand Up @@ -913,7 +913,7 @@ impl HandlerInner {
// This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
// incrementing `err_count` by one, so we need to +1 the comparing.
// FIXME: Would be nice to increment err_count in a more coherent way.
if self.flags.treat_err_as_bug.map(|c| self.err_count() + 1 >= c).unwrap_or(false) {
if self.flags.treat_err_as_bug.map_or(false, |c| self.err_count() + 1 >= c) {
// FIXME: don't abort here if report_delayed_bugs is off
self.span_bug(sp, msg);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ impl<'a> StripUnconfigured<'a> {

/// If attributes are not allowed on expressions, emit an error for `attr`
pub fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
if !self.features.map(|features| features.stmt_expr_attributes).unwrap_or(true) {
if !self.features.map_or(true, |features| features.stmt_expr_attributes) {
let mut err = feature_err(
&self.sess.parse_sess,
sym::stmt_expr_attributes,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ fn inner_parse_loop<'root, 'tt>(
if idx == len && item.sep.is_some() {
// We have a separator, and it is the current token. We can advance past the
// separator token.
if item.sep.as_ref().map(|sep| token_name_eq(token, sep)).unwrap_or(false) {
if item.sep.as_ref().map_or(false, |sep| token_name_eq(token, sep)) {
item.idx += 1;
next_items.push(item);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn macro_rules_dummy_expander<'cx>(
}

fn trace_macros_note(cx_expansions: &mut FxHashMap<Span, Vec<String>>, sp: Span, message: String) {
let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp);
let sp = sp.macro_backtrace().last().map_or(sp, |trace| trace.call_site);
cx_expansions.entry(sp).or_default().push(message);
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_expand/src/mbe/quoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ pub(super) fn parse(
}
_ => token.span,
},
tree => tree.as_ref().map(tokenstream::TokenTree::span).unwrap_or(span),
tree => tree.as_ref().map_or(span, tokenstream::TokenTree::span),
}
}
tree => tree.as_ref().map(tokenstream::TokenTree::span).unwrap_or(start_sp),
tree => tree.as_ref().map_or(start_sp, tokenstream::TokenTree::span),
};
if node_id != DUMMY_NODE_ID {
// Macros loaded from other crates have dummy node ids.
Expand Down Expand Up @@ -250,7 +250,7 @@ fn parse_kleene_op(
Some(op) => Ok(Ok((op, token.span))),
None => Ok(Err(token)),
},
tree => Err(tree.as_ref().map(tokenstream::TokenTree::span).unwrap_or(span)),
tree => Err(tree.as_ref().map_or(span, tokenstream::TokenTree::span)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ impl WhereClause<'_> {
/// in `fn foo<T>(t: T) where T: Foo,` so we don't suggest two trailing commas.
pub fn tail_span_for_suggestion(&self) -> Span {
let end = self.span_for_predicates_or_empty_place().shrink_to_hi();
self.predicates.last().map(|p| p.span()).unwrap_or(end).shrink_to_hi().to(end)
self.predicates.last().map_or(end, |p| p.span()).shrink_to_hi().to(end)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let consider = format!(
"{} {}...",
msg,
if type_param_span.map(|(_, _, is_impl_trait)| is_impl_trait).unwrap_or(false) {
if type_param_span.map_or(false, |(_, _, is_impl_trait)| is_impl_trait) {
format!(" `{}` to `{}`", sub, bound_kind)
} else {
format!("`{}: {}`", bound_kind, sub)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// Note: if these two lines are combined into one we get
// dynamic borrow errors on `self.inner`.
let known = self.inner.borrow_mut().type_variables().probe(v).known();
known.map(|t| self.shallow_resolve_ty(t)).unwrap_or(typ)
known.map_or(typ, |t| self.shallow_resolve_ty(t))
}

ty::Infer(ty::IntVar(v)) => self
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,7 @@ pub fn transparent_newtype_field<'a, 'tcx>(
let param_env = tcx.param_env(variant.def_id);
for field in &variant.fields {
let field_ty = tcx.type_of(field.did);
let is_zst =
tcx.layout_of(param_env.and(field_ty)).map(|layout| layout.is_zst()).unwrap_or(false);
let is_zst = tcx.layout_of(param_env.and(field_ty)).map_or(false, |layout| layout.is_zst());

if !is_zst {
return Some(field);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ trait UnusedDelimLint {
pprust::expr_to_string(value)
};
let keep_space = (
left_pos.map(|s| s >= value.span.lo()).unwrap_or(false),
right_pos.map(|s| s <= value.span.hi()).unwrap_or(false),
left_pos.map_or(false, |s| s >= value.span.lo()),
right_pos.map_or(false, |s| s <= value.span.hi()),
);
self.emit_unused_delims(cx, value.span, &expr_text, ctx.into(), keep_space);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ fn add_query_description_impl(
};

let (tcx, desc) = modifiers.desc;
let tcx = tcx.as_ref().map(|t| quote! { #t }).unwrap_or(quote! { _ });
let tcx = tcx.as_ref().map_or(quote! { _ }, |t| quote! { #t });

let desc = quote! {
#[allow(unused_variables)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl<'a> CrateLoader<'a> {
self.verify_no_symbol_conflicts(&crate_root)?;

let private_dep =
self.sess.opts.externs.get(&name.as_str()).map(|e| e.is_private_dep).unwrap_or(false);
self.sess.opts.externs.get(&name.as_str()).map_or(false, |e| e.is_private_dep);

// Claim this crate number and cache it
let cnum = self.cstore.alloc_new_crate_num();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {

impl Collector<'tcx> {
fn register_native_lib(&mut self, span: Option<Span>, lib: NativeLib) {
if lib.name.as_ref().map(|&s| s == kw::Empty).unwrap_or(false) {
if lib.name.as_ref().map_or(false, |&s| s == kw::Empty) {
match span {
Some(span) => {
struct_span_err!(
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ impl<'hir> Map<'hir> {
/// Given a node ID, gets a list of attributes associated with the AST
/// corresponding to the node-ID.
pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] {
let attrs = self.find_entry(id).map(|entry| match entry.node {
self.find_entry(id).map_or(&[], |entry| match entry.node {
Node::Param(a) => &a.attrs[..],
Node::Local(l) => &l.attrs[..],
Node::Item(i) => &i.attrs[..],
Expand All @@ -842,8 +842,7 @@ impl<'hir> Map<'hir> {
| Node::Block(..)
| Node::Lifetime(..)
| Node::Visibility(..) => &[],
});
attrs.unwrap_or(&[])
})
}

/// Gets the span of the definition of the specified HIR node.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/consts/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'tcx> ConstKind<'tcx> {
/// Tries to evaluate the constant if it is `Unevaluated`. If that doesn't succeed, return the
/// unevaluated constant.
pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Self {
self.try_eval(tcx, param_env).and_then(Result::ok).map(ConstKind::Value).unwrap_or(self)
self.try_eval(tcx, param_env).and_then(Result::ok).map_or(self, ConstKind::Value)
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ impl<'tcx> TyCtxt<'tcx> {
}

pub fn serialize_query_result_cache(self, encoder: &mut FileEncoder) -> FileEncodeResult {
self.queries.on_disk_cache.as_ref().map(|c| c.serialize(self, encoder)).unwrap_or(Ok(()))
self.queries.on_disk_cache.as_ref().map_or(Ok(()), |c| c.serialize(self, encoder))
}

/// If `true`, we should use the MIR-based borrowck, but also
Expand Down Expand Up @@ -2601,7 +2601,7 @@ impl<'tcx> TyCtxt<'tcx> {
}

pub fn is_late_bound(self, id: HirId) -> bool {
self.is_late_bound_map(id.owner).map(|set| set.contains(&id.local_id)).unwrap_or(false)
self.is_late_bound_map(id.owner).map_or(false, |set| set.contains(&id.local_id))
}

pub fn object_lifetime_defaults(self, id: HirId) -> Option<&'tcx [ObjectLifetimeDefault]> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ fn polymorphize<'tcx>(
} else {
None
};
let has_upvars = upvars_ty.map(|ty| ty.tuple_fields().count() > 0).unwrap_or(false);
let has_upvars = upvars_ty.map_or(false, |ty| ty.tuple_fields().count() > 0);
debug!("polymorphize: upvars_ty={:?} has_upvars={:?}", upvars_ty, has_upvars);

struct PolymorphizationFolder<'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/borrow_check/borrow_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'tcx> BorrowSet<'tcx> {
}

crate fn activations_at_location(&self, location: Location) -> &[BorrowIndex] {
self.activation_map.get(&location).map(|activations| &activations[..]).unwrap_or(&[])
self.activation_map.get(&location).map_or(&[], |activations| &activations[..])
}

crate fn len(&self) -> usize {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl BorrowExplanation {
LaterUseKind::FakeLetRead => "stored here",
LaterUseKind::Other => "used here",
};
if !borrow_span.map(|sp| sp.overlaps(var_or_use_span)).unwrap_or(false) {
if !borrow_span.map_or(false, |sp| sp.overlaps(var_or_use_span)) {
err.span_label(
var_or_use_span,
format!("{}borrow later {}", borrow_desc, message),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

#[inline(always)]
pub fn cur_span(&self) -> Span {
self.stack().last().map(|f| f.current_span()).unwrap_or(self.tcx.span)
self.stack().last().map_or(self.tcx.span, |f| f.current_span())
}

#[inline(always)]
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir/src/interpret/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ where
let index = index
.try_into()
.expect("more generic parameters than can fit into a `u32`");
let is_used =
unused_params.contains(index).map(|unused| !unused).unwrap_or(true);
let is_used = unused_params.contains(index).map_or(true, |unused| !unused);
// Only recurse when generic parameters in fns, closures and generators
// are used and require substitution.
match (is_used, subst.needs_subst()) {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir/src/monomorphize/partitioning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ where
for (mono_item, linkage) in cgu.items() {
let symbol_name = mono_item.symbol_name(tcx).name;
let symbol_hash_start = symbol_name.rfind('h');
let symbol_hash =
symbol_hash_start.map(|i| &symbol_name[i..]).unwrap_or("<no hash>");
let symbol_hash = symbol_hash_start.map_or("<no hash>", |i| &symbol_name[i..]);

debug!(
" - {} [{:?}] [{}] estimated size {}",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir/src/transform/simplify_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn get_arm_identity_info<'a, 'tcx>(
test: impl Fn(&'a Statement<'tcx>) -> bool,
mut action: impl FnMut(usize, &'a Statement<'tcx>),
) {
while stmt_iter.peek().map(|(_, stmt)| test(stmt)).unwrap_or(false) {
while stmt_iter.peek().map_or(false, |(_, stmt)| test(stmt)) {
let (idx, stmt) = stmt_iter.next().unwrap();

action(idx, stmt);
Expand Down Expand Up @@ -635,7 +635,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
})
.peekable();

let bb_first = iter_bbs_reachable.peek().map(|(idx, _)| *idx).unwrap_or(&targets_and_values[0]);
let bb_first = iter_bbs_reachable.peek().map_or(&targets_and_values[0], |(idx, _)| *idx);
let mut all_successors_equivalent = StatementEquality::TrivialEqual;

// All successor basic blocks must be equal or contain statements that are pairwise considered equal.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ fn is_useful<'p, 'tcx>(
assert!(rows.iter().all(|r| r.len() == v.len()));

// FIXME(Nadrieril): Hack to work around type normalization issues (see #72476).
let ty = matrix.heads().next().map(|r| r.ty).unwrap_or(v.head().ty);
let ty = matrix.heads().next().map_or(v.head().ty, |r| r.ty);
let pcx = PatCtxt { cx, ty, span: v.head().span, is_top_level };

debug!("is_useful_expand_first_col: ty={:#?}, expanding {:#?}", pcx.ty, v.head());
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ impl<'a> Parser<'a> {
//
// `x.foo::<u32>>>(3)`
let parsed_angle_bracket_args =
segment.args.as_ref().map(|args| args.is_angle_bracketed()).unwrap_or(false);
segment.args.as_ref().map_or(false, |args| args.is_angle_bracketed());

debug!(
"check_trailing_angle_brackets: parsed_angle_bracket_args={:?}",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<'a> Parser<'a> {
let mut pos = pos;
// This handles the raw string case, the raw argument is the number of #
// in r###"..."### (we need to add one because of the `r`).
let raw = self.style.map(|raw| raw + 1).unwrap_or(0);
let raw = self.style.map_or(0, |raw| raw + 1);
for skip in &self.skips {
if pos > *skip {
pos += 1;
Expand Down Expand Up @@ -814,7 +814,7 @@ fn find_skips_from_snippet(
skips
}

let r_start = str_style.map(|r| r + 1).unwrap_or(0);
let r_start = str_style.map_or(0, |r| r + 1);
let r_end = str_style.unwrap_or(0);
let s = &snippet[r_start + 1..snippet.len() - r_end - 1];
(find_skips(s, str_style.is_some()), true)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ impl<K: DepKind> DepGraph<K> {
// Returns true if the given node has been marked as green during the
// current compilation session. Used in various assertions
pub fn is_green(&self, dep_node: &DepNode<K>) -> bool {
self.node_color(dep_node).map(|c| c.is_green()).unwrap_or(false)
self.node_color(dep_node).map_or(false, |c| c.is_green())
}

// This method loads all on-disk cacheable query results into memory, so
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
{
// Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
let item_span =
path.iter().last().map(|segment| segment.ident.span).unwrap_or(span);
path.iter().last().map_or(span, |segment| segment.ident.span);

let mut hm = self.r.session.confused_type_with_std_module.borrow_mut();
hm.insert(item_span, span);
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
// The current function has a `self' parameter, but we were unable to resolve
// a reference to `self`. This can only happen if the `self` identifier we
// are resolving came from a different hygiene context.
if fn_kind.decl().inputs.get(0).map(|p| p.is_self()).unwrap_or(false) {
if fn_kind.decl().inputs.get(0).map_or(false, |p| p.is_self()) {
err.span_label(*span, "this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters");
} else {
let doesnt = if is_assoc_fn {
Expand Down Expand Up @@ -1452,8 +1452,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
}
} else {
let needs_placeholder = |def_id: DefId, kind: CtorKind| {
let has_no_fields =
self.r.field_names.get(&def_id).map(|f| f.is_empty()).unwrap_or(false);
let has_no_fields = self.r.field_names.get(&def_id).map_or(false, |f| f.is_empty());
match kind {
CtorKind::Const => false,
CtorKind::Fn | CtorKind::Fictive if has_no_fields => false,
Expand Down
Loading

0 comments on commit 9053e65

Please sign in to comment.