Re-format let-else per rustfmt update

This commit is contained in:
Mark Rousskov 2023-07-12 21:49:27 -04:00
parent 67b0cfc761
commit cc907f80b9
162 changed files with 1404 additions and 947 deletions

View file

@ -352,7 +352,8 @@ pub(crate) fn lower_inline_asm(
let idx2 = *o.get();
let (ref op2, op_sp2) = operands[idx2];
let Some(asm::InlineAsmRegOrRegClass::Reg(reg2)) = op2.reg() else {
let Some(asm::InlineAsmRegOrRegClass::Reg(reg2)) = op2.reg()
else {
unreachable!();
};
@ -368,7 +369,7 @@ pub(crate) fn lower_inline_asm(
assert!(!*late);
let out_op_sp = if input { op_sp2 } else { op_sp };
Some(out_op_sp)
},
}
_ => None,
};
@ -377,7 +378,7 @@ pub(crate) fn lower_inline_asm(
op_span2: op_sp2,
reg1_name: reg.name(),
reg2_name: reg2.name(),
in_out
in_out,
});
}
Entry::Vacant(v) => {

View file

@ -714,7 +714,9 @@ fn suggest_borrow_fn_like(
_ => None,
};
let Some(borrow_level) = borrow_level else { return false; };
let Some(borrow_level) = borrow_level else {
return false;
};
let sugg = move_sites
.iter()
.map(|move_site| {
@ -763,7 +765,9 @@ fn suggest_adding_copy_bounds(&self, err: &mut Diagnostic, ty: Ty<'tcx>, span: S
.typeck_root_def_id(self.mir_def_id().to_def_id())
.as_local()
.and_then(|def_id| tcx.hir().get_generics(def_id))
else { return; };
else {
return;
};
// Try to find predicates on *generic params* that would allow copying `ty`
let ocx = ObligationCtxt::new(&self.infcx);
let copy_did = tcx.require_lang_item(LangItem::Copy, Some(span));
@ -1220,18 +1224,20 @@ fn suggest_using_local_if_applicable(
return;
};
let inner_param_uses = find_all_local_uses::find(self.body, inner_param.local);
let Some((inner_call_loc, inner_call_term)) = inner_param_uses.into_iter().find_map(|loc| {
let Either::Right(term) = self.body.stmt_at(loc) else {
debug!("{:?} is a statement, so it can't be a call", loc);
return None;
};
let TerminatorKind::Call { args, .. } = &term.kind else {
debug!("not a call: {:?}", term);
return None;
};
debug!("checking call args for uses of inner_param: {:?}", args);
args.contains(&Operand::Move(inner_param)).then_some((loc, term))
}) else {
let Some((inner_call_loc, inner_call_term)) =
inner_param_uses.into_iter().find_map(|loc| {
let Either::Right(term) = self.body.stmt_at(loc) else {
debug!("{:?} is a statement, so it can't be a call", loc);
return None;
};
let TerminatorKind::Call { args, .. } = &term.kind else {
debug!("not a call: {:?}", term);
return None;
};
debug!("checking call args for uses of inner_param: {:?}", args);
args.contains(&Operand::Move(inner_param)).then_some((loc, term))
})
else {
debug!("no uses of inner_param found as a by-move call arg");
return;
};
@ -1442,21 +1448,24 @@ fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) {
}
// Get closure's arguments
let ty::Closure(_, substs) = typeck_results.expr_ty(closure_expr).kind() else { /* hir::Closure can be a generator too */ return };
let ty::Closure(_, substs) = typeck_results.expr_ty(closure_expr).kind() else {
/* hir::Closure can be a generator too */
return;
};
let sig = substs.as_closure().sig();
let tupled_params =
tcx.erase_late_bound_regions(sig.inputs().iter().next().unwrap().map_bound(|&b| b));
let ty::Tuple(params) = tupled_params.kind() else { return };
// Find the first argument with a matching type, get its name
let Some((_, this_name)) = params
.iter()
.zip(hir.body_param_names(closure.body))
.find(|(param_ty, name)|{
let Some((_, this_name)) =
params.iter().zip(hir.body_param_names(closure.body)).find(|(param_ty, name)| {
// FIXME: also support deref for stuff like `Rc` arguments
param_ty.peel_refs() == local_ty && name != &Ident::empty()
})
else { return };
else {
return;
};
let spans;
if let Some((_path_expr, qpath)) = finder.error_path
@ -2899,7 +2908,9 @@ fn annotate_argument_and_return_for_borrow(
{
let def_id = def_id.expect_local();
for operand in operands {
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) = operand else {
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) =
operand
else {
continue;
};
debug!(
@ -2908,7 +2919,9 @@ fn annotate_argument_and_return_for_borrow(
);
// Find the local from the operand.
let Some(assigned_from_local) = assigned_from.local_or_deref_local() else {
let Some(assigned_from_local) =
assigned_from.local_or_deref_local()
else {
continue;
};
@ -2961,7 +2974,9 @@ fn annotate_argument_and_return_for_borrow(
);
// Find the local from the rvalue.
let Some(assigned_from_local) = assigned_from.local_or_deref_local() else { continue };
let Some(assigned_from_local) = assigned_from.local_or_deref_local() else {
continue;
};
debug!(
"annotate_argument_and_return_for_borrow: \
assigned_from_local={:?}",
@ -3009,7 +3024,8 @@ fn annotate_argument_and_return_for_borrow(
assigned_to, args
);
for operand in args {
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) = operand else {
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) = operand
else {
continue;
};
debug!(

View file

@ -847,14 +847,12 @@ pub(super) fn move_spans(
kind: TerminatorKind::Call { fn_span, call_source, .. }, ..
}) = &self.body[location.block].terminator
{
let Some((method_did, method_substs)) =
rustc_middle::util::find_self_call(
self.infcx.tcx,
&self.body,
target_temp,
location.block,
)
else {
let Some((method_did, method_substs)) = rustc_middle::util::find_self_call(
self.infcx.tcx,
&self.body,
target_temp,
location.block,
) else {
return normal_ret;
};

View file

@ -184,7 +184,9 @@ fn append_binding_error(
}
// Error with the pattern
LookupResult::Exact(_) => {
let LookupResult::Parent(Some(mpi)) = self.move_data.rev_lookup.find(move_from.as_ref()) else {
let LookupResult::Parent(Some(mpi)) =
self.move_data.rev_lookup.find(move_from.as_ref())
else {
// move_from should be a projection from match_place.
unreachable!("Probably not unreachable...");
};
@ -494,8 +496,10 @@ fn add_move_error_suggestions(&self, err: &mut Diagnostic, binds_to: &[Local]) {
if let LocalInfo::User(BindingForm::Var(VarBindingForm { pat_span, .. })) =
*bind_to.local_info()
{
let Ok(pat_snippet) =
self.infcx.tcx.sess.source_map().span_to_snippet(pat_span) else { continue; };
let Ok(pat_snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(pat_span)
else {
continue;
};
let Some(stripped) = pat_snippet.strip_prefix('&') else {
suggestions.push((
bind_to.source_info.span.shrink_to_lo(),

View file

@ -648,8 +648,12 @@ fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
let def_id = self.body.source.def_id();
let hir_id = hir_map.local_def_id_to_hir_id(def_id.as_local().unwrap());
let node = hir_map.find(hir_id);
let Some(hir::Node::Item(item)) = node else { return; };
let hir::ItemKind::Fn(.., body_id) = item.kind else { return; };
let Some(hir::Node::Item(item)) = node else {
return;
};
let hir::ItemKind::Fn(.., body_id) = item.kind else {
return;
};
let body = self.infcx.tcx.hir().body(body_id);
let mut v = V { assign_span: span, err, ty, suggested: false };

View file

@ -224,12 +224,10 @@ fn suggest_static_lifetime_for_gat_from_hrtb(
let mut hrtb_bounds = vec![];
gat_id_and_generics.iter().flatten().for_each(|(gat_hir_id, generics)| {
for pred in generics.predicates {
let BoundPredicate(
WhereBoundPredicate {
bound_generic_params,
bounds,
..
}) = pred else { continue; };
let BoundPredicate(WhereBoundPredicate { bound_generic_params, bounds, .. }) = pred
else {
continue;
};
if bound_generic_params
.iter()
.rfind(|bgp| hir.local_def_id_to_hir_id(bgp.def_id) == *gat_hir_id)
@ -813,7 +811,9 @@ fn add_static_impl_trait_suggestion(
return;
}
let suitable_region = self.infcx.tcx.is_suitable_region(f);
let Some(suitable_region) = suitable_region else { return; };
let Some(suitable_region) = suitable_region else {
return;
};
let fn_returns = self.infcx.tcx.return_type_impl_or_dyn_traits(suitable_region.def_id);
@ -848,7 +848,10 @@ fn add_static_impl_trait_suggestion(
let Some((alias_tys, alias_span, lt_addition_span)) = self
.infcx
.tcx
.return_type_impl_or_dyn_traits_with_type_alias(suitable_region.def_id) else { return; };
.return_type_impl_or_dyn_traits_with_type_alias(suitable_region.def_id)
else {
return;
};
// in case the return type of the method is a type alias
let mut spans_suggs: Vec<_> = Vec::new();
@ -932,8 +935,13 @@ fn maybe_suggest_constrain_dyn_trait_impl(
let mut visitor = TraitObjectVisitor(FxIndexSet::default());
visitor.visit_ty(param.param_ty);
let Some((ident, self_ty)) =
NiceRegionError::get_impl_ident_and_self_ty_from_trait(tcx, instance.def_id(), &visitor.0) else { return; };
let Some((ident, self_ty)) = NiceRegionError::get_impl_ident_and_self_ty_from_trait(
tcx,
instance.def_id(),
&visitor.0,
) else {
return;
};
self.suggest_constrain_dyn_trait_in_impl(diag, &visitor.0, ident, self_ty);
}
@ -981,23 +989,25 @@ fn suggest_adding_lifetime_params(
sup: RegionVid,
) {
let (Some(sub), Some(sup)) = (self.to_error_region(sub), self.to_error_region(sup)) else {
return
return;
};
let Some((ty_sub, _)) = self
.infcx
.tcx
.is_suitable_region(sub)
.and_then(|anon_reg| find_anon_type(self.infcx.tcx, sub, &anon_reg.boundregion)) else {
return
.and_then(|anon_reg| find_anon_type(self.infcx.tcx, sub, &anon_reg.boundregion))
else {
return;
};
let Some((ty_sup, _)) = self
.infcx
.tcx
.is_suitable_region(sup)
.and_then(|anon_reg| find_anon_type(self.infcx.tcx, sup, &anon_reg.boundregion)) else {
return
.and_then(|anon_reg| find_anon_type(self.infcx.tcx, sup, &anon_reg.boundregion))
else {
return;
};
suggest_adding_lifetime_params(self.infcx.tcx, sub, ty_sup, ty_sub, diag);

View file

@ -325,8 +325,8 @@ fn give_name_from_error_region(&self, fr: RegionVid) -> Option<RegionName> {
// Can't have BrEnv in functions, constants or generators.
bug!("BrEnv outside of closure.");
};
let hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. })
= tcx.hir().expect_expr(self.mir_hir_id()).kind
let hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }) =
tcx.hir().expect_expr(self.mir_hir_id()).kind
else {
bug!("Closure is not defined by a closure expr");
};

View file

@ -2058,10 +2058,17 @@ pub(crate) fn best_blame_constraint(
let mut extra_info = vec![];
for constraint in path.iter() {
let outlived = constraint.sub;
let Some(origin) = self.var_infos.get(outlived) else { continue; };
let RegionVariableOrigin::Nll(NllRegionVariableOrigin::Placeholder(p)) = origin.origin else { continue; };
let Some(origin) = self.var_infos.get(outlived) else {
continue;
};
let RegionVariableOrigin::Nll(NllRegionVariableOrigin::Placeholder(p)) = origin.origin
else {
continue;
};
debug!(?constraint, ?p);
let ConstraintCategory::Predicate(span) = constraint.category else { continue; };
let ConstraintCategory::Predicate(span) = constraint.category else {
continue;
};
extra_info.push(ExtraConstraintInfo::PlaceholderFromPredicate(span));
// We only want to point to one
break;

View file

@ -2039,28 +2039,16 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L
}
CastKind::PointerCoercion(PointerCoercion::MutToConstPointer) => {
let ty::RawPtr(ty::TypeAndMut {
ty: ty_from,
mutbl: hir::Mutability::Mut,
}) = op.ty(body, tcx).kind() else {
span_mirbug!(
self,
rvalue,
"unexpected base type for cast {:?}",
ty,
);
let ty::RawPtr(ty::TypeAndMut { ty: ty_from, mutbl: hir::Mutability::Mut }) =
op.ty(body, tcx).kind()
else {
span_mirbug!(self, rvalue, "unexpected base type for cast {:?}", ty,);
return;
};
let ty::RawPtr(ty::TypeAndMut {
ty: ty_to,
mutbl: hir::Mutability::Not,
}) = ty.kind() else {
span_mirbug!(
self,
rvalue,
"unexpected target type for cast {:?}",
ty,
);
let ty::RawPtr(ty::TypeAndMut { ty: ty_to, mutbl: hir::Mutability::Not }) =
ty.kind()
else {
span_mirbug!(self, rvalue, "unexpected target type for cast {:?}", ty,);
return;
};
if let Err(terr) = self.sub_types(

View file

@ -929,7 +929,9 @@ fn for_each_late_bound_region_in_item<'tcx>(
}
for bound_var in tcx.late_bound_vars(tcx.hir().local_def_id_to_hir_id(mir_def_id)) {
let ty::BoundVariableKind::Region(bound_region) = bound_var else { continue; };
let ty::BoundVariableKind::Region(bound_region) = bound_var else {
continue;
};
let liberated_region = ty::Region::new_free(tcx, mir_def_id.to_def_id(), bound_region);
f(liberated_region);
}

View file

@ -157,8 +157,7 @@ pub fn parse_asm_args<'a>(
} else if p.eat_keyword(sym::sym) {
let expr = p.parse_expr()?;
let ast::ExprKind::Path(qself, path) = &expr.kind else {
let err = diag
.create_err(errors::AsmSymNoPath { span: expr.span });
let err = diag.create_err(errors::AsmSymNoPath { span: expr.span });
return Err(err);
};
let sym = ast::InlineAsmSym {

View file

@ -61,8 +61,8 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> Bl
|cx, fold| match fold {
CsFold::Single(field) => {
let [other_expr] = &field.other_selflike_exprs[..] else {
cx.span_bug(field.span, "not exactly 2 arguments in `derive(Ord)`");
};
cx.span_bug(field.span, "not exactly 2 arguments in `derive(Ord)`");
};
let args = thin_vec![field.self_expr.clone(), other_expr.clone()];
cx.expr_call_global(field.span, cmp_path.clone(), args)
}

View file

@ -94,8 +94,8 @@ fn cs_partial_cmp(
|cx, fold| match fold {
CsFold::Single(field) => {
let [other_expr] = &field.other_selflike_exprs[..] else {
cx.span_bug(field.span, "not exactly 2 arguments in `derive(Ord)`");
};
cx.span_bug(field.span, "not exactly 2 arguments in `derive(Ord)`");
};
let args = thin_vec![field.self_expr.clone(), other_expr.clone()];
cx.expr_call_global(field.span, partial_cmp_path.clone(), args)
}

View file

@ -83,7 +83,12 @@ pub fn expand_env<'cx>(
None => {
// Use the string literal in the code in the diagnostic to avoid confusing diagnostics,
// e.g. when the literal contains escape sequences.
let ast::ExprKind::Lit(ast::token::Lit { kind: ast::token::LitKind::Str, symbol: original_var, ..}) = &var_expr.kind else {
let ast::ExprKind::Lit(ast::token::Lit {
kind: ast::token::LitKind::Str,
symbol: original_var,
..
}) = &var_expr.kind
else {
unreachable!("`expr_to_string` ensures this is a string lit")
};
cx.emit_err(errors::EnvNotDefined {

View file

@ -89,7 +89,9 @@ fn check_not_pub_in_root(&self, vis: &ast::Visibility, sp: Span) {
}
fn collect_custom_derive(&mut self, item: &'a ast::Item, attr: &'a ast::Attribute) {
let Some((trait_name, proc_attrs)) = parse_macro_name_and_helper_attrs(self.handler, attr, "derive") else {
let Some((trait_name, proc_attrs)) =
parse_macro_name_and_helper_attrs(self.handler, attr, "derive")
else {
return;
};

View file

@ -739,7 +739,10 @@ fn build_foreign_type_di_node<'ll, 'tcx>(
debug!("build_foreign_type_di_node: {:?}", t);
let &ty::Foreign(def_id) = unique_type_id.expect_ty().kind() else {
bug!("build_foreign_type_di_node() called with unexpected type: {:?}", unique_type_id.expect_ty());
bug!(
"build_foreign_type_di_node() called with unexpected type: {:?}",
unique_type_id.expect_ty()
);
};
build_type_with_children(

View file

@ -199,7 +199,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
let enum_type = unique_type_id.expect_ty();
let &ty::Adt(enum_adt_def, _) = enum_type.kind() else {
bug!("build_enum_type_di_node() called with non-enum type: `{:?}`", enum_type)
};
};
let enum_type_and_layout = cx.layout_of(enum_type);
let enum_type_name = compute_debuginfo_type_name(cx.tcx, enum_type, false);
@ -667,7 +667,9 @@ fn build_union_fields_for_direct_tag_generator<'ll, 'tcx>(
generator_type_and_layout: TyAndLayout<'tcx>,
generator_type_di_node: &'ll DIType,
) -> SmallVec<&'ll DIType> {
let Variants::Multiple { tag_encoding: TagEncoding::Direct, tag_field, .. } = generator_type_and_layout.variants else {
let Variants::Multiple { tag_encoding: TagEncoding::Direct, tag_field, .. } =
generator_type_and_layout.variants
else {
bug!("This function only supports layouts with directly encoded tags.")
};

View file

@ -51,7 +51,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
let enum_type = unique_type_id.expect_ty();
let &ty::Adt(enum_adt_def, _) = enum_type.kind() else {
bug!("build_enum_type_di_node() called with non-enum type: `{:?}`", enum_type)
};
};
let enum_type_and_layout = cx.layout_of(enum_type);

View file

@ -57,7 +57,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
let enum_type = unique_type_id.expect_ty();
let &ty::Adt(enum_adt_def, _) = enum_type.kind() else {
bug!("build_enum_type_di_node() called with non-enum type: `{:?}`", enum_type)
};
};
let containing_scope = get_namespace_for_item(cx, enum_adt_def.did());
let enum_type_and_layout = cx.layout_of(enum_type);
@ -132,9 +132,9 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>(
unique_type_id: UniqueTypeId<'tcx>,
) -> DINodeCreationResult<'ll> {
let generator_type = unique_type_id.expect_ty();
let &ty::Generator(generator_def_id, _, _ ) = generator_type.kind() else {
let &ty::Generator(generator_def_id, _, _) = generator_type.kind() else {
bug!("build_generator_di_node() called with non-generator type: `{:?}`", generator_type)
};
};
let containing_scope = get_namespace_for_item(cx, generator_def_id);
let generator_type_and_layout = cx.layout_of(generator_type);
@ -158,7 +158,9 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>(
let generator_layout =
cx.tcx.optimized_mir(generator_def_id).generator_layout().unwrap();
let Variants::Multiple { tag_encoding: TagEncoding::Direct, ref variants, .. } = generator_type_and_layout.variants else {
let Variants::Multiple { tag_encoding: TagEncoding::Direct, ref variants, .. } =
generator_type_and_layout.variants
else {
bug!(
"Encountered generator with non-direct-tag layout: {:?}",
generator_type_and_layout

View file

@ -186,7 +186,11 @@ fn calculate_debuginfo_offset<
} => {
let offset = indirect_offsets.last_mut().unwrap_or(&mut direct_offset);
let FieldsShape::Array { stride, count: _ } = place.layout().fields else {
span_bug!(var.source_info.span, "ConstantIndex on non-array type {:?}", place.layout())
span_bug!(
var.source_info.span,
"ConstantIndex on non-array type {:?}",
place.layout()
)
};
*offset += stride * index;
place = place.project_constant_index(bx, index);

View file

@ -369,13 +369,9 @@ pub fn from_target_feature(
// We allow comma separation to enable multiple features.
target_features.extend(value.as_str().split(',').filter_map(|feature| {
let Some(feature_gate) = supported_target_features.get(feature) else {
let msg =
format!("the feature named `{}` is not valid for this target", feature);
let msg = format!("the feature named `{}` is not valid for this target", feature);
let mut err = tcx.sess.struct_span_err(item.span(), msg);
err.span_label(
item.span(),
format!("`{}` is not valid for this target", feature),
);
err.span_label(item.span(), format!("`{}` is not valid for this target", feature));
if let Some(stripped) = feature.strip_prefix('+') {
let valid = supported_target_features.contains_key(stripped);
if valid {

View file

@ -150,8 +150,8 @@ pub(super) fn report<'tcx, C, F, E>(
tcx.sess.create_err(Spanned { span, node: layout_error.into_diagnostic() });
err.code(rustc_errors::error_code!(E0080));
let Some((mut err, handler)) = err.into_diagnostic() else {
panic!("did not emit diag");
};
panic!("did not emit diag");
};
for frame in frames {
err.eager_subdiagnostic(handler, frame);
}

View file

@ -604,7 +604,9 @@ pub(super) fn size_and_align_of(
// the last field). Can't have foreign types here, how would we
// adjust alignment and size for them?
let field = layout.field(self, layout.fields.count() - 1);
let Some((unsized_size, mut unsized_align)) = self.size_and_align_of(metadata, &field)? else {
let Some((unsized_size, mut unsized_align)) =
self.size_and_align_of(metadata, &field)?
else {
// A field with an extern type. We don't know the actual dynamic size
// or the alignment.
return Ok(None);

View file

@ -1060,11 +1060,7 @@ pub fn write_bytes_ptr(
let size = Size::from_bytes(len);
let Some(alloc_ref) = self.get_ptr_alloc_mut(ptr, size, Align::ONE)? else {
// zero-sized access
assert_matches!(
src.next(),
None,
"iterator said it was empty but returned an element"
);
assert_matches!(src.next(), None, "iterator said it was empty but returned an element");
return Ok(());
};

View file

@ -545,14 +545,17 @@ fn write_immediate_to_mplace_no_validate(
// wrong type.
let tcx = *self.tcx;
let Some(mut alloc) = self.get_place_alloc_mut(&MPlaceTy { mplace: dest, layout, align })? else {
let Some(mut alloc) =
self.get_place_alloc_mut(&MPlaceTy { mplace: dest, layout, align })?
else {
// zero-sized access
return Ok(());
};
match value {
Immediate::Scalar(scalar) => {
let Abi::Scalar(s) = layout.abi else { span_bug!(
let Abi::Scalar(s) = layout.abi else {
span_bug!(
self.cur_span(),
"write_immediate_to_mplace: invalid Scalar layout: {layout:#?}",
)
@ -565,7 +568,8 @@ fn write_immediate_to_mplace_no_validate(
// We checked `ptr_align` above, so all fields will have the alignment they need.
// We would anyway check against `ptr_align.restrict_for_offset(b_offset)`,
// which `ptr.offset(b_offset)` cannot possibly fail to satisfy.
let Abi::ScalarPair(a, b) = layout.abi else { span_bug!(
let Abi::ScalarPair(a, b) = layout.abi else {
span_bug!(
self.cur_span(),
"write_immediate_to_mplace: invalid ScalarPair layout: {:#?}",
layout

View file

@ -390,7 +390,10 @@ fn pass_argument<'x, 'y>(
));
// Allocate enough memory to hold `src`.
let Some((size, align)) = self.size_and_align_of_mplace(&src)? else {
span_bug!(self.cur_span(), "unsized fn arg with `extern` type tail should not be allowed")
span_bug!(
self.cur_span(),
"unsized fn arg with `extern` type tail should not be allowed"
)
};
let ptr = self.allocate_ptr(size, align, MemoryKind::Stack)?;
let dest_place =
@ -468,10 +471,18 @@ pub(crate) fn eval_fn_call(
| ty::InstanceDef::ThreadLocalShim(..)
| ty::InstanceDef::Item(_) => {
// We need MIR for this fn
let Some((body, instance)) =
M::find_mir_or_eval_fn(self, instance, caller_abi, args, destination, target, unwind)? else {
return Ok(());
};
let Some((body, instance)) = M::find_mir_or_eval_fn(
self,
instance,
caller_abi,
args,
destination,
target,
unwind,
)?
else {
return Ok(());
};
// Compute callee information using the `instance` returned by
// `find_mir_or_eval_fn`.
@ -702,8 +713,12 @@ pub(crate) fn eval_fn_call(
.tcx
.struct_tail_erasing_lifetimes(receiver_place.layout.ty, self.param_env);
let ty::Dynamic(data, _, ty::Dyn) = receiver_tail.kind() else {
span_bug!(self.cur_span(), "dynamic call on non-`dyn` type {}", receiver_tail)
};
span_bug!(
self.cur_span(),
"dynamic call on non-`dyn` type {}",
receiver_tail
)
};
assert!(receiver_place.layout.is_unsized());
// Get the required information from the vtable.
@ -721,7 +736,9 @@ pub(crate) fn eval_fn_call(
// Now determine the actual method to call. We can do that in two different ways and
// compare them to ensure everything fits.
let Some(ty::VtblEntry::Method(fn_inst)) = self.get_vtable_entries(vptr)?.get(idx).copied() else {
let Some(ty::VtblEntry::Method(fn_inst)) =
self.get_vtable_entries(vptr)?.get(idx).copied()
else {
// FIXME(fee1-dead) these could be variants of the UB info enum instead of this
throw_ub_custom!(fluent::const_eval_dyn_call_not_a_method);
};

View file

@ -778,8 +778,7 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
if trait_ref.self_ty().is_closure()
&& tcx.fn_trait_kind_from_def_id(trait_id).is_some() =>
{
let ty::Closure(closure_def_id, substs) =
*trait_ref.self_ty().kind()
let ty::Closure(closure_def_id, substs) = *trait_ref.self_ty().kind()
else {
unreachable!()
};

View file

@ -759,11 +759,7 @@ fn promote_temp(&mut self, temp: Local) -> Local {
let (mut rvalue, source_info) = {
let statement = &mut self.source[loc.block].statements[loc.statement_index];
let StatementKind::Assign(box (_, rhs)) = &mut statement.kind else {
span_bug!(
statement.source_info.span,
"{:?} is not an assignment",
statement
);
span_bug!(statement.source_info.span, "{:?} is not an assignment", statement);
};
(
@ -859,7 +855,9 @@ fn promote_candidate(mut self, candidate: Candidate, next_promoted_id: usize) ->
let local_decls = &mut self.source.local_decls;
let loc = candidate.location;
let statement = &mut blocks[loc.block].statements[loc.statement_index];
let StatementKind::Assign(box (_, Rvalue::Ref(region, borrow_kind, place))) = &mut statement.kind else {
let StatementKind::Assign(box (_, Rvalue::Ref(region, borrow_kind, place))) =
&mut statement.kind
else {
bug!()
};

View file

@ -214,9 +214,7 @@ fn check_cleanup_control_flow(&self) {
stack.clear();
stack.insert(bb);
loop {
let Some(parent)= parent[bb].take() else {
break
};
let Some(parent) = parent[bb].take() else { break };
let no_cycle = stack.insert(parent);
if !no_cycle {
self.fail(
@ -399,7 +397,10 @@ fn visit_projection_elem(
};
let Some(layout) = gen_body.generator_layout() else {
self.fail(location, format!("No generator layout for {:?}", parent_ty));
self.fail(
location,
format!("No generator layout for {:?}", parent_ty),
);
return;
};
@ -409,13 +410,17 @@ fn visit_projection_elem(
};
let Some(f_ty) = layout.field_tys.get(local) else {
self.fail(location, format!("Out of bounds local {:?} for {:?}", local, parent_ty));
self.fail(
location,
format!("Out of bounds local {:?} for {:?}", local, parent_ty),
);
return;
};
f_ty.ty
} else {
let Some(f_ty) = substs.as_generator().prefix_tys().nth(f.index()) else {
let Some(f_ty) = substs.as_generator().prefix_tys().nth(f.index())
else {
fail_out_of_bounds(self, location);
return;
};

View file

@ -176,9 +176,7 @@ pub fn dominators<G: ControlFlowGraph>(graph: &G) -> Dominators<G::Node> {
//
// ...this may be the case if a MirPass modifies the CFG to remove
// or rearrange certain blocks/edges.
let Some(v) = real_to_pre_order[v] else {
continue
};
let Some(v) = real_to_pre_order[v] else { continue };
// eval returns a vertex x from which semi[x] is minimum among
// vertices semi[v] +> x *> v.

View file

@ -272,7 +272,7 @@ fn parse_ordered_li(buf: &[u8]) -> Parsed<'_> {
fn get_indented_section(buf: &[u8]) -> (&[u8], &[u8]) {
let mut end = buf.len();
for (idx, window) in buf.windows(2).enumerate() {
let &[ch, next_ch] = window else {unreachable!("always 2 elements")};
let &[ch, next_ch] = window else { unreachable!("always 2 elements") };
if idx >= buf.len().saturating_sub(2) && next_ch == b'\n' {
// End of stream
end = buf.len().saturating_sub(1);

View file

@ -149,7 +149,7 @@ fn write_wrapping<B: io::Write>(
let Some((end_idx, _ch)) = iter.nth(ch_count) else {
// Write entire line
buf.write_all(to_write.as_bytes())?;
cur.set(cur.get()+to_write.chars().count());
cur.set(cur.get() + to_write.chars().count());
break;
};

View file

@ -1366,7 +1366,7 @@ pub fn parse_macro_name_and_helper_attrs(
return None;
}
let Some(trait_attr) = list[0].meta_item() else {
diag.emit_err(errors::NotAMetaItem {span: list[0].span()});
diag.emit_err(errors::NotAMetaItem { span: list[0].span() });
return None;
};
let trait_ident = match trait_attr.ident() {

View file

@ -313,9 +313,10 @@ fn process_cfg_attr(&self, attr: &Attribute) -> Vec<Attribute> {
/// the attribute is incorrect.
pub(crate) fn expand_cfg_attr(&self, attr: &Attribute, recursive: bool) -> Vec<Attribute> {
let Some((cfg_predicate, expanded_attrs)) =
rustc_parse::parse_cfg_attr(attr, &self.sess.parse_sess) else {
return vec![];
};
rustc_parse::parse_cfg_attr(attr, &self.sess.parse_sess)
else {
return vec![];
};
// Lint on zero attributes in source.
if expanded_attrs.is_empty() {
@ -365,7 +366,9 @@ fn expand_cfg_attr_item(
// Use the `#` in `#[cfg_attr(pred, attr)]` as the `#` token
// for `attr` when we expand it to `#[attr]`
let mut orig_trees = orig_tokens.into_trees();
let TokenTree::Token(pound_token @ Token { kind: TokenKind::Pound, .. }, _) = orig_trees.next().unwrap() else {
let TokenTree::Token(pound_token @ Token { kind: TokenKind::Pound, .. }, _) =
orig_trees.next().unwrap()
else {
panic!("Bad tokens for attribute {:?}", attr);
};
let pound_span = pound_token.span;
@ -373,7 +376,9 @@ fn expand_cfg_attr_item(
let mut trees = vec![AttrTokenTree::Token(pound_token, Spacing::Alone)];
if attr.style == AttrStyle::Inner {
// For inner attributes, we do the same thing for the `!` in `#![some_attr]`
let TokenTree::Token(bang_token @ Token { kind: TokenKind::Not, .. }, _) = orig_trees.next().unwrap() else {
let TokenTree::Token(bang_token @ Token { kind: TokenKind::Not, .. }, _) =
orig_trees.next().unwrap()
else {
panic!("Bad tokens for attribute {:?}", attr);
};
trees.push(AttrTokenTree::Token(bang_token, Spacing::Alone));

View file

@ -651,7 +651,8 @@ fn expand_invoc(
ExpandResult::Ready(match invoc.kind {
InvocationKind::Bang { mac, .. } => match ext {
SyntaxExtensionKind::Bang(expander) => {
let Ok(tok_result) = expander.expand(self.cx, span, mac.args.tokens.clone()) else {
let Ok(tok_result) = expander.expand(self.cx, span, mac.args.tokens.clone())
else {
return ExpandResult::Ready(fragment_kind.dummy(span));
};
self.parse_ast_fragment(tok_result, fragment_kind, &mac.path, span)
@ -704,7 +705,8 @@ fn expand_invoc(
self.cx.emit_err(UnsupportedKeyValue { span });
}
let inner_tokens = attr_item.args.inner_tokens();
let Ok(tok_result) = expander.expand(self.cx, span, inner_tokens, tokens) else {
let Ok(tok_result) = expander.expand(self.cx, span, inner_tokens, tokens)
else {
return ExpandResult::Ready(fragment_kind.dummy(span));
};
self.parse_ast_fragment(tok_result, fragment_kind, &attr_item.path, span)
@ -1087,9 +1089,7 @@ fn wrap_flat_map_node_noop_flat_map(
// Work around borrow checker not seeing through `P`'s deref.
let (ident, span, mut attrs) = (node.ident, node.span, mem::take(&mut node.attrs));
let ItemKind::Mod(_, mod_kind) = &mut node.kind else {
unreachable!()
};
let ItemKind::Mod(_, mod_kind) = &mut node.kind else { unreachable!() };
let ecx = &mut collector.cx;
let (file_path, dir_path, dir_ownership) = match mod_kind {

View file

@ -42,7 +42,8 @@ pub(super) fn failed_to_match_macro<'cx>(
return result;
}
let Some(BestFailure { token, msg: label, remaining_matcher, .. }) = tracker.best_failure else {
let Some(BestFailure { token, msg: label, remaining_matcher, .. }) = tracker.best_failure
else {
return DummyResult::any(sp);
};

View file

@ -104,13 +104,10 @@ fn parse_depth<'sess>(
span: Span,
) -> PResult<'sess, usize> {
let Some(tt) = iter.next() else { return Ok(0) };
let TokenTree::Token(token::Token {
kind: token::TokenKind::Literal(lit), ..
}, _) = tt else {
return Err(sess.span_diagnostic.struct_span_err(
span,
"meta-variable expression depth must be a literal"
));
let TokenTree::Token(token::Token { kind: token::TokenKind::Literal(lit), .. }, _) = tt else {
return Err(sess
.span_diagnostic
.struct_span_err(span, "meta-variable expression depth must be a literal"));
};
if let Ok(lit_kind) = LitKind::from_token_lit(*lit)
&& let LitKind::Int(n_u128, LitIntType::Unsuffixed) = lit_kind

View file

@ -182,9 +182,7 @@ pub(super) fn transcribe<'a>(
LockstepIterSize::Constraint(len, _) => {
// We do this to avoid an extra clone above. We know that this is a
// sequence already.
let mbe::TokenTree::Sequence(sp, seq) = seq else {
unreachable!()
};
let mbe::TokenTree::Sequence(sp, seq) = seq else { unreachable!() };
// Is the repetition empty?
if len == 0 {
@ -399,7 +397,9 @@ fn lockstep_iter_size(
}
TokenTree::MetaVarExpr(_, expr) => {
let default_rslt = LockstepIterSize::Unconstrained;
let Some(ident) = expr.ident() else { return default_rslt; };
let Some(ident) = expr.ident() else {
return default_rslt;
};
let name = MacroRulesNormalizedIdent::new(ident);
match lookup_cur_matched(name, interpolations, repeats) {
Some(MatchedSeq(ads)) => {

View file

@ -3150,7 +3150,9 @@ pub fn expect_mod(&self) -> &'hir Mod<'hir> {
/// Expect an [`ItemKind::ForeignMod`] or panic.
#[track_caller]
pub fn expect_foreign_mod(&self) -> (Abi, &'hir [ForeignItemRef]) {
let ItemKind::ForeignMod { abi, items } = self.kind else { self.expect_failed("a foreign module") };
let ItemKind::ForeignMod { abi, items } = self.kind else {
self.expect_failed("a foreign module")
};
(abi, items)
}
@ -3201,14 +3203,18 @@ pub fn expect_union(&self) -> (&VariantData<'hir>, &'hir Generics<'hir>) {
pub fn expect_trait(
self,
) -> (IsAuto, Unsafety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]) {
let ItemKind::Trait(is_auto, unsafety, gen, bounds, items) = self.kind else { self.expect_failed("a trait") };
let ItemKind::Trait(is_auto, unsafety, gen, bounds, items) = self.kind else {
self.expect_failed("a trait")
};
(is_auto, unsafety, gen, bounds, items)
}
/// Expect an [`ItemKind::TraitAlias`] or panic.
#[track_caller]
pub fn expect_trait_alias(&self) -> (&'hir Generics<'hir>, GenericBounds<'hir>) {
let ItemKind::TraitAlias(gen, bounds) = self.kind else { self.expect_failed("a trait alias") };
let ItemKind::TraitAlias(gen, bounds) = self.kind else {
self.expect_failed("a trait alias")
};
(gen, bounds)
}

View file

@ -1267,9 +1267,12 @@ pub fn associated_path_to_ty(
"you might have meant to specify type parameters on enum \
`{type_name}`"
);
let Some(args) = assoc_segment.args else { return; };
let Some(args) = assoc_segment.args else {
return;
};
// Get the span of the generics args *including* the leading `::`.
let args_span = assoc_segment.ident.span.shrink_to_hi().to(args.span_ext);
let args_span =
assoc_segment.ident.span.shrink_to_hi().to(args.span_ext);
if tcx.generics_of(adt_def.did()).count() == 0 {
// FIXME(estebank): we could also verify that the arguments being
// work for the `enum`, instead of just looking if it takes *any*.
@ -1281,49 +1284,56 @@ pub fn associated_path_to_ty(
);
return;
}
let Ok(snippet) = tcx.sess.source_map().span_to_snippet(args_span) else {
let Ok(snippet) = tcx.sess.source_map().span_to_snippet(args_span)
else {
err.note(msg);
return;
};
let (qself_sugg_span, is_self) = if let hir::TyKind::Path(
hir::QPath::Resolved(_, path)
) = &qself.kind {
// If the path segment already has type params, we want to overwrite
// them.
match &path.segments {
// `segment` is the previous to last element on the path,
// which would normally be the `enum` itself, while the last
// `_` `PathSegment` corresponds to the variant.
[.., hir::PathSegment {
ident,
args,
res: Res::Def(DefKind::Enum, _),
..
}, _] => (
// We need to include the `::` in `Type::Variant::<Args>`
// to point the span to `::<Args>`, not just `<Args>`.
ident.span.shrink_to_hi().to(args.map_or(
ident.span.shrink_to_hi(),
|a| a.span_ext)),
false,
),
[segment] => (
// We need to include the `::` in `Type::Variant::<Args>`
// to point the span to `::<Args>`, not just `<Args>`.
segment.ident.span.shrink_to_hi().to(segment.args.map_or(
segment.ident.span.shrink_to_hi(),
|a| a.span_ext)),
kw::SelfUpper == segment.ident.name,
),
_ => {
err.note(msg);
return;
let (qself_sugg_span, is_self) =
if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) =
&qself.kind
{
// If the path segment already has type params, we want to overwrite
// them.
match &path.segments {
// `segment` is the previous to last element on the path,
// which would normally be the `enum` itself, while the last
// `_` `PathSegment` corresponds to the variant.
[
..,
hir::PathSegment {
ident,
args,
res: Res::Def(DefKind::Enum, _),
..
},
_,
] => (
// We need to include the `::` in `Type::Variant::<Args>`
// to point the span to `::<Args>`, not just `<Args>`.
ident.span.shrink_to_hi().to(args
.map_or(ident.span.shrink_to_hi(), |a| a.span_ext)),
false,
),
[segment] => (
// We need to include the `::` in `Type::Variant::<Args>`
// to point the span to `::<Args>`, not just `<Args>`.
segment.ident.span.shrink_to_hi().to(segment
.args
.map_or(segment.ident.span.shrink_to_hi(), |a| {
a.span_ext
})),
kw::SelfUpper == segment.ident.name,
),
_ => {
err.note(msg);
return;
}
}
}
} else {
err.note(msg);
return;
};
} else {
err.note(msg);
return;
};
let suggestion = vec![
if is_self {
// Account for people writing `Self::Variant::<Args>`, where
@ -1455,7 +1465,8 @@ pub fn associated_path_to_ty(
};
let trait_did = bound.def_id();
let Some(assoc_ty_did) = self.lookup_assoc_ty(assoc_ident, hir_ref_id, span, trait_did) else {
let Some(assoc_ty_did) = self.lookup_assoc_ty(assoc_ident, hir_ref_id, span, trait_did)
else {
// Assume that if it's not matched, there must be a const defined with the same name
// but it was used in a type position.
let msg = format!("found associated const `{assoc_ident}` when type was expected");
@ -1814,7 +1825,9 @@ fn qpath_to_ty(
debug!("qpath_to_ty: self.item_def_id()={:?}", def_id);
let parent_def_id = def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
let parent_def_id = def_id
.as_local()
.map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
.map(|hir_id| tcx.hir().get_parent_item(hir_id).to_def_id());
debug!("qpath_to_ty: parent_def_id={:?}", parent_def_id);
@ -1850,7 +1863,7 @@ fn qpath_to_ty(
&[path_str],
item_segment.ident.name,
);
return Ty::new_error(tcx,reported)
return Ty::new_error(tcx, reported);
};
debug!("qpath_to_ty: self_type={:?}", self_ty);
@ -2688,7 +2701,10 @@ fn suggest_trait_fn_ty_for_impl_fn_infer(
let hir = tcx.hir();
let hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), ident, .. }) =
hir.get(fn_hir_id) else { return None };
hir.get(fn_hir_id)
else {
return None;
};
let i = hir.get_parent(fn_hir_id).expect_item().expect_impl();
let trait_ref = self.instantiate_mono_trait_ref(

View file

@ -81,8 +81,9 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
self_type_did: DefId,
adt_to_impl_substs: SubstsRef<'tcx>,
) -> Result<(), ErrorGuaranteed> {
let Err(arg) = tcx.uses_unique_generic_params(adt_to_impl_substs, CheckRegions::OnlyEarlyBound) else {
return Ok(())
let Err(arg) = tcx.uses_unique_generic_params(adt_to_impl_substs, CheckRegions::OnlyEarlyBound)
else {
return Ok(());
};
let drop_impl_span = tcx.def_span(drop_impl_did);

View file

@ -186,18 +186,14 @@ fn check_asm_operand_type(
let Some((_, feature)) = supported_tys.iter().find(|&&(t, _)| t == asm_ty) else {
let msg = format!("type `{ty}` cannot be used with this register class");
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
let supported_tys: Vec<_> =
supported_tys.iter().map(|(t, _)| t.to_string()).collect();
let supported_tys: Vec<_> = supported_tys.iter().map(|(t, _)| t.to_string()).collect();
err.note(format!(
"register class `{}` supports these types: {}",
reg_class.name(),
supported_tys.join(", "),
));
if let Some(suggest) = reg_class.suggest_class(asm_arch, asm_ty) {
err.help(format!(
"consider using the `{}` register class instead",
suggest.name()
));
err.help(format!("consider using the `{}` register class instead", suggest.name()));
}
err.emit();
return Some(asm_ty);

View file

@ -1282,7 +1282,9 @@ fn suggest_impl_trait<'tcx>(
item_ty: Ty<'tcx>| {
let trait_name = tcx.item_name(trait_def_id);
let args_tuple = substs.type_at(1);
let ty::Tuple(types) = *args_tuple.kind() else { return None; };
let ty::Tuple(types) = *args_tuple.kind() else {
return None;
};
let types = types.make_suggestable(tcx, false)?;
let maybe_ret =
if item_ty.is_unit() { String::new() } else { format!(" -> {item_ty}") };
@ -1315,8 +1317,12 @@ fn suggest_impl_trait<'tcx>(
format_as_parenthesized,
),
] {
let Some(trait_def_id) = trait_def_id else { continue; };
let Some(assoc_item_def_id) = assoc_item_def_id else { continue; };
let Some(trait_def_id) = trait_def_id else {
continue;
};
let Some(assoc_item_def_id) = assoc_item_def_id else {
continue;
};
if tcx.def_kind(assoc_item_def_id) != DefKind::AssocTy {
continue;
}

View file

@ -66,7 +66,11 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
Some(ImplTraitInTraitData::Trait { opaque_def_id, fn_def_id }) => {
let opaque_ty_id = tcx.hir().local_def_id_to_hir_id(opaque_def_id.expect_local());
let opaque_ty_node = tcx.hir().get(opaque_ty_id);
let Node::Item(&Item { kind: ItemKind::OpaqueTy(OpaqueTy { lifetime_mapping, .. }), .. }) = opaque_ty_node else {
let Node::Item(&Item {
kind: ItemKind::OpaqueTy(OpaqueTy { lifetime_mapping, .. }),
..
}) = opaque_ty_node
else {
bug!("unexpected {opaque_ty_node:?}")
};
@ -397,7 +401,9 @@ fn compute_bidirectional_outlives_predicates<'tcx>(
continue;
}
let Some(dup_index) = generics.param_def_id_to_index(icx.tcx, dup_def.to_def_id()) else { bug!() };
let Some(dup_index) = generics.param_def_id_to_index(icx.tcx, dup_def.to_def_id()) else {
bug!()
};
let dup_region = ty::Region::new_early_bound(
tcx,

View file

@ -749,9 +749,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
// `fn foo<'a>() -> MyAnonTy<'a> { ... }`
// ^ ^this gets resolved in the current scope
for lifetime in lifetimes {
let hir::GenericArg::Lifetime(lifetime) = lifetime else {
continue
};
let hir::GenericArg::Lifetime(lifetime) = lifetime else { continue };
self.visit_lifetime(lifetime);
// Check for predicates like `impl for<'a> Trait<impl OtherTrait<'a>>`
@ -759,12 +757,8 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
// well-supported at the moment, so this doesn't work.
// In the future, this should be fixed and this error should be removed.
let def = self.map.defs.get(&lifetime.hir_id).cloned();
let Some(ResolvedArg::LateBound(_, _, def_id)) = def else {
continue
};
let Some(def_id) = def_id.as_local() else {
continue
};
let Some(ResolvedArg::LateBound(_, _, def_id)) = def else { continue };
let Some(def_id) = def_id.as_local() else { continue };
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
// Ensure that the parent of the def is an item, not HRTB
let parent_id = self.tcx.hir().parent_id(hir_id);

View file

@ -360,9 +360,11 @@ fn get_lifetime_args_suggestions_from_param_names(
&[]
};
ret.extend(params.iter().filter_map(|p| {
let hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit }
= p.kind
else { return None };
let hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit } =
p.kind
else {
return None;
};
let hir::ParamName::Plain(name) = p.name else { return None };
Some(name.to_string())
}));
@ -793,29 +795,36 @@ fn suggest_moving_args_from_assoc_fn_to_trait_for_method_call(
num_trait_generics_except_self: usize,
) {
let sm = self.tcx.sess.source_map();
let hir::ExprKind::MethodCall(_, rcvr, args, _) = expr.kind else { return; };
let hir::ExprKind::MethodCall(_, rcvr, args, _) = expr.kind else {
return;
};
if num_assoc_fn_excess_args != num_trait_generics_except_self {
return;
}
let Some(gen_args) = self.gen_args.span_ext() else { return; };
let Ok(generics) = sm.span_to_snippet(gen_args) else { return; };
let Ok(rcvr) = sm.span_to_snippet(
rcvr.span.find_ancestor_inside(expr.span).unwrap_or(rcvr.span)
) else { return; };
let Ok(rest) =
(match args {
[] => Ok(String::new()),
[arg] => sm.span_to_snippet(
arg.span.find_ancestor_inside(expr.span).unwrap_or(arg.span),
),
[first, .., last] => {
let first_span =
first.span.find_ancestor_inside(expr.span).unwrap_or(first.span);
let last_span =
last.span.find_ancestor_inside(expr.span).unwrap_or(last.span);
sm.span_to_snippet(first_span.to(last_span))
}
}) else { return; };
let Some(gen_args) = self.gen_args.span_ext() else {
return;
};
let Ok(generics) = sm.span_to_snippet(gen_args) else {
return;
};
let Ok(rcvr) =
sm.span_to_snippet(rcvr.span.find_ancestor_inside(expr.span).unwrap_or(rcvr.span))
else {
return;
};
let Ok(rest) = (match args {
[] => Ok(String::new()),
[arg] => {
sm.span_to_snippet(arg.span.find_ancestor_inside(expr.span).unwrap_or(arg.span))
}
[first, .., last] => {
let first_span = first.span.find_ancestor_inside(expr.span).unwrap_or(first.span);
let last_span = last.span.find_ancestor_inside(expr.span).unwrap_or(last.span);
sm.span_to_snippet(first_span.to(last_span))
}
}) else {
return;
};
let comma = if args.len() > 0 { ", " } else { "" };
let trait_path = self.tcx.def_path_str(trait_def_id);
let method_name = self.tcx.item_name(self.def_id);

View file

@ -188,11 +188,18 @@ fn suggest_removing_semicolon_for_coerce(
let hir = self.tcx.hir();
// First, check that we're actually in the tail of a function.
let Some(body_id) = hir.maybe_body_owned_by(self.body_id) else { return; };
let Some(body_id) = hir.maybe_body_owned_by(self.body_id) else {
return;
};
let body = hir.body(body_id);
let hir::ExprKind::Block(block, _) = body.value.kind else { return; };
let Some(hir::Stmt { kind: hir::StmtKind::Semi(last_expr), .. })
= block.innermost_block().stmts.last() else { return; };
let hir::ExprKind::Block(block, _) = body.value.kind else {
return;
};
let Some(hir::Stmt { kind: hir::StmtKind::Semi(last_expr), .. }) =
block.innermost_block().stmts.last()
else {
return;
};
if last_expr.hir_id != expr.hir_id {
return;
}
@ -201,7 +208,10 @@ fn suggest_removing_semicolon_for_coerce(
let Some(ret) = hir
.find_by_def_id(self.body_id)
.and_then(|owner| owner.fn_decl())
.map(|decl| decl.output.span()) else { return; };
.map(|decl| decl.output.span())
else {
return;
};
let Expectation::IsLast(stmt) = expectation else {
return;
};
@ -508,9 +518,14 @@ pub(crate) fn opt_suggest_box_span(
span,
kind: TypeVariableOriginKind::OpaqueTypeInference(rpit_def_id),
..
} = self.type_var_origin(expected)? else { return None; };
} = self.type_var_origin(expected)?
else {
return None;
};
let Some(rpit_local_def_id) = rpit_def_id.as_local() else { return None; };
let Some(rpit_local_def_id) = rpit_def_id.as_local() else {
return None;
};
if !matches!(
self.tcx.hir().expect_item(rpit_local_def_id).expect_opaque_ty().origin,
hir::OpaqueTyOrigin::FnReturn(..)

View file

@ -499,15 +499,15 @@ fn suggest_call_as_method(
expected: Expectation<'tcx>,
) {
if let [callee_expr, rest @ ..] = arg_exprs {
let Some(callee_ty) = self.typeck_results.borrow().expr_ty_adjusted_opt(callee_expr) else {
let Some(callee_ty) = self.typeck_results.borrow().expr_ty_adjusted_opt(callee_expr)
else {
return;
};
// First, do a probe with `IsSuggestion(true)` to avoid emitting
// any strange errors. If it's successful, then we'll do a true
// method lookup.
let Ok(pick) = self
.lookup_probe_for_diagnostic(
let Ok(pick) = self.lookup_probe_for_diagnostic(
segment.ident,
callee_ty,
call_expr,

View file

@ -1670,7 +1670,9 @@ fn note_unreachable_loop_return(
expr: &hir::Expr<'tcx>,
ret_exprs: &Vec<&'tcx hir::Expr<'tcx>>,
) {
let hir::ExprKind::Loop(_, _, _, loop_span) = expr.kind else { return;};
let hir::ExprKind::Loop(_, _, _, loop_span) = expr.kind else {
return;
};
let mut span: MultiSpan = vec![loop_span].into();
span.push_span_label(loop_span, "this might have zero elements to iterate on");
const MAXITER: usize = 3;

View file

@ -102,7 +102,9 @@ fn adjust_expr_for_assert_eq_macro(
found_expr: &mut &'tcx hir::Expr<'tcx>,
expected_expr: &mut Option<&'tcx hir::Expr<'tcx>>,
) {
let Some(expected_expr) = expected_expr else { return; };
let Some(expected_expr) = expected_expr else {
return;
};
if !found_expr.span.eq_ctxt(expected_expr.span) {
return;
@ -121,11 +123,17 @@ fn adjust_expr_for_assert_eq_macro(
let hir::ExprKind::Unary(
hir::UnOp::Deref,
hir::Expr { kind: hir::ExprKind::Path(found_path), .. },
) = found_expr.kind else { return; };
) = found_expr.kind
else {
return;
};
let hir::ExprKind::Unary(
hir::UnOp::Deref,
hir::Expr { kind: hir::ExprKind::Path(expected_path), .. },
) = expected_expr.kind else { return; };
) = expected_expr.kind
else {
return;
};
for (path, name, idx, var) in [
(expected_path, "left_val", 0, expected_expr),
@ -285,16 +293,26 @@ pub fn note_source_of_type_mismatch_constraint(
) -> bool {
let hir = self.tcx.hir();
let hir::ExprKind::Path(hir::QPath::Resolved(None, p)) = expr.kind else { return false; };
let [hir::PathSegment { ident, args: None, .. }] = p.segments else { return false; };
let hir::def::Res::Local(local_hir_id) = p.res else { return false; };
let hir::Node::Pat(pat) = hir.get(local_hir_id) else { return false; };
let hir::ExprKind::Path(hir::QPath::Resolved(None, p)) = expr.kind else {
return false;
};
let [hir::PathSegment { ident, args: None, .. }] = p.segments else {
return false;
};
let hir::def::Res::Local(local_hir_id) = p.res else {
return false;
};
let hir::Node::Pat(pat) = hir.get(local_hir_id) else {
return false;
};
let (init_ty_hir_id, init) = match hir.get_parent(pat.hir_id) {
hir::Node::Local(hir::Local { ty: Some(ty), init, .. }) => (ty.hir_id, *init),
hir::Node::Local(hir::Local { init: Some(init), .. }) => (init.hir_id, Some(*init)),
_ => return false,
};
let Some(init_ty) = self.node_ty_opt(init_ty_hir_id) else { return false; };
let Some(init_ty) = self.node_ty_opt(init_ty_hir_id) else {
return false;
};
// Locate all the usages of the relevant binding.
struct FindExprs<'tcx> {
@ -413,14 +431,18 @@ fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
// Bindings always update their recorded type after the fact, so we
// need to look at the *following* usage's type to see when the
// binding became incompatible.
let [binding, next_usage] = *window else { continue; };
let [binding, next_usage] = *window else {
continue;
};
// Don't go past the binding (always gonna be a nonsense label if so)
if binding.hir_id == expr.hir_id {
break;
}
let Some(next_use_ty) = self.node_ty_opt(next_usage.hir_id) else { continue; };
let Some(next_use_ty) = self.node_ty_opt(next_usage.hir_id) else {
continue;
};
// If the type is not constrained in a way making it not possible to
// equate with `expected_ty` by this point, skip.
@ -634,27 +656,36 @@ fn annotate_alternative_method_deref(
error: Option<TypeError<'tcx>>,
) {
let parent = self.tcx.hir().parent_id(expr.hir_id);
let Some(TypeError::Sorts(ExpectedFound { expected, .. })) = error else {return;};
let Some(hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Assign(lhs, rhs, _), ..
})) = self.tcx.hir().find(parent) else {return; };
let Some(TypeError::Sorts(ExpectedFound { expected, .. })) = error else {
return;
};
let Some(hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Assign(lhs, rhs, _), .. })) =
self.tcx.hir().find(parent)
else {
return;
};
if rhs.hir_id != expr.hir_id || expected.is_closure() {
return;
}
let hir::ExprKind::Unary(hir::UnOp::Deref, deref) = lhs.kind else { return; };
let hir::ExprKind::MethodCall(path, base, args, _) = deref.kind else { return; };
let Some(self_ty) = self.typeck_results.borrow().expr_ty_adjusted_opt(base) else { return; };
let hir::ExprKind::Unary(hir::UnOp::Deref, deref) = lhs.kind else {
return;
};
let hir::ExprKind::MethodCall(path, base, args, _) = deref.kind else {
return;
};
let Some(self_ty) = self.typeck_results.borrow().expr_ty_adjusted_opt(base) else {
return;
};
let Ok(pick) = self
.lookup_probe_for_diagnostic(
path.ident,
self_ty,
deref,
probe::ProbeScope::TraitsInScope,
None,
) else {
return;
};
let Ok(pick) = self.lookup_probe_for_diagnostic(
path.ident,
self_ty,
deref,
probe::ProbeScope::TraitsInScope,
None,
) else {
return;
};
let in_scope_methods = self.probe_for_name_many(
probe::Mode::MethodCall,
path.ident,
@ -793,8 +824,12 @@ pub(crate) fn suggest_coercing_result_via_try_operator(
expected: Ty<'tcx>,
found: Ty<'tcx>,
) -> bool {
let ty::Adt(e, substs_e) = expected.kind() else { return false; };
let ty::Adt(f, substs_f) = found.kind() else { return false; };
let ty::Adt(e, substs_e) = expected.kind() else {
return false;
};
let ty::Adt(f, substs_f) = found.kind() else {
return false;
};
if e.did() != f.did() {
return false;
}
@ -1039,7 +1074,9 @@ fn suggest_non_zero_new_unwrap(
// In case Option<NonZero*> is wanted, but * is provided, suggest calling new
ty::Adt(adt, substs) if tcx.is_diagnostic_item(sym::Option, adt.did()) => {
// Unwrap option
let ty::Adt(adt, _) = substs.type_at(0).kind() else { return false; };
let ty::Adt(adt, _) = substs.type_at(0).kind() else {
return false;
};
(adt, "")
}
@ -1061,10 +1098,11 @@ fn suggest_non_zero_new_unwrap(
(sym::NonZeroI128, tcx.types.i128),
];
let Some((s, _)) = map
.iter()
.find(|&&(s, t)| self.tcx.is_diagnostic_item(s, adt.did()) && self.can_coerce(expr_ty, t))
else { return false; };
let Some((s, _)) = map.iter().find(|&&(s, t)| {
self.tcx.is_diagnostic_item(s, adt.did()) && self.can_coerce(expr_ty, t)
}) else {
return false;
};
let path = self.tcx.def_path_str(adt.non_enum_variant().def_id);
@ -1152,7 +1190,9 @@ fn can_use_as_ref(&self, expr: &hir::Expr<'_>) -> Option<(Vec<(Span, String)>, &
};
let local_parent = self.tcx.hir().parent_id(local_id);
let Some(Node::Param(hir::Param { hir_id: param_hir_id, .. })) = self.tcx.hir().find(local_parent) else {
let Some(Node::Param(hir::Param { hir_id: param_hir_id, .. })) =
self.tcx.hir().find(local_parent)
else {
return None;
};
@ -1161,7 +1201,8 @@ fn can_use_as_ref(&self, expr: &hir::Expr<'_>) -> Option<(Vec<(Span, String)>, &
hir_id: expr_hir_id,
kind: hir::ExprKind::Closure(hir::Closure { fn_decl: closure_fn_decl, .. }),
..
})) = self.tcx.hir().find(param_parent) else {
})) = self.tcx.hir().find(param_parent)
else {
return None;
};
@ -1174,7 +1215,8 @@ fn can_use_as_ref(&self, expr: &hir::Expr<'_>) -> Option<(Vec<(Span, String)>, &
..
})),
1,
) = (hir, closure_params_len) else {
) = (hir, closure_params_len)
else {
return None;
};
@ -2028,11 +2070,11 @@ pub fn suggest_method_call_on_range_literal(
if !hir::is_range_literal(expr) {
return;
}
let hir::ExprKind::Struct(
hir::QPath::LangItem(LangItem::Range, ..),
[start, end],
_,
) = expr.kind else { return; };
let hir::ExprKind::Struct(hir::QPath::LangItem(LangItem::Range, ..), [start, end], _) =
expr.kind
else {
return;
};
let parent = self.tcx.hir().parent_id(expr.hir_id);
if let Some(hir::Node::ExprField(_)) = self.tcx.hir().find(parent) {
// Ignore `Foo { field: a..Default::default() }`
@ -2048,8 +2090,12 @@ pub fn suggest_method_call_on_range_literal(
// cannot guide the method probe.
expectation = None;
}
let hir::ExprKind::Call(method_name, _) = expr.kind else { return; };
let ty::Adt(adt, _) = checked_ty.kind() else { return; };
let hir::ExprKind::Call(method_name, _) = expr.kind else {
return;
};
let ty::Adt(adt, _) = checked_ty.kind() else {
return;
};
if self.tcx.lang_items().range_struct() != Some(adt.did()) {
return;
}
@ -2059,8 +2105,12 @@ pub fn suggest_method_call_on_range_literal(
return;
}
// Check if start has method named end.
let hir::ExprKind::Path(hir::QPath::Resolved(None, p)) = method_name.kind else { return; };
let [hir::PathSegment { ident, .. }] = p.segments else { return; };
let hir::ExprKind::Path(hir::QPath::Resolved(None, p)) = method_name.kind else {
return;
};
let [hir::PathSegment { ident, .. }] = p.segments else {
return;
};
let self_ty = self.typeck_results.borrow().expr_ty(start.expr);
let Ok(_pick) = self.lookup_probe_for_diagnostic(
*ident,
@ -2068,7 +2118,9 @@ pub fn suggest_method_call_on_range_literal(
expr,
probe::ProbeScope::AllTraits,
expectation,
) else { return; };
) else {
return;
};
let mut sugg = ".";
let mut span = start.expr.span.between(end.expr.span);
if span.lo() + BytePos(2) == span.hi() {
@ -2097,17 +2149,23 @@ fn suggest_return_binding_for_missing_tail_expr(
if !checked_ty.is_unit() {
return;
}
let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind else { return; };
let hir::def::Res::Local(hir_id) = path.res else { return; };
let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind else {
return;
};
let hir::def::Res::Local(hir_id) = path.res else {
return;
};
let Some(hir::Node::Pat(pat)) = self.tcx.hir().find(hir_id) else {
return;
};
let Some(hir::Node::Local(hir::Local {
ty: None,
init: Some(init),
..
})) = self.tcx.hir().find_parent(pat.hir_id) else { return; };
let hir::ExprKind::Block(block, None) = init.kind else { return; };
let Some(hir::Node::Local(hir::Local { ty: None, init: Some(init), .. })) =
self.tcx.hir().find_parent(pat.hir_id)
else {
return;
};
let hir::ExprKind::Block(block, None) = init.kind else {
return;
};
if block.expr.is_some() {
return;
}
@ -2115,8 +2173,12 @@ fn suggest_return_binding_for_missing_tail_expr(
err.span_label(block.span, "this empty block is missing a tail expression");
return;
};
let hir::StmtKind::Semi(tail_expr) = stmt.kind else { return; };
let Some(ty) = self.node_ty_opt(tail_expr.hir_id) else { return; };
let hir::StmtKind::Semi(tail_expr) = stmt.kind else {
return;
};
let Some(ty) = self.node_ty_opt(tail_expr.hir_id) else {
return;
};
if self.can_eq(self.param_env, expected_ty, ty) {
err.span_suggestion_short(
stmt.span.with_lo(tail_expr.span.hi()),
@ -2135,7 +2197,9 @@ fn note_wrong_return_ty_due_to_generic_arg(
expr: &hir::Expr<'_>,
checked_ty: Ty<'tcx>,
) {
let Some(hir::Node::Expr(parent_expr)) = self.tcx.hir().find_parent(expr.hir_id) else { return; };
let Some(hir::Node::Expr(parent_expr)) = self.tcx.hir().find_parent(expr.hir_id) else {
return;
};
enum CallableKind {
Function,
Method,
@ -2151,7 +2215,12 @@ enum CallableKind {
return;
}
let fn_sig = fn_ty.fn_sig(self.tcx).skip_binder();
let Some(&arg) = fn_sig.inputs().get(arg_idx + if matches!(kind, CallableKind::Method) { 1 } else { 0 }) else { return; };
let Some(&arg) = fn_sig
.inputs()
.get(arg_idx + if matches!(kind, CallableKind::Method) { 1 } else { 0 })
else {
return;
};
if matches!(arg.kind(), ty::Param(_))
&& fn_sig.output().contains(arg)
&& self.node_ty(args[arg_idx].hir_id) == checked_ty
@ -2185,8 +2254,12 @@ enum CallableKind {
};
match parent_expr.kind {
hir::ExprKind::Call(fun, args) => {
let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = fun.kind else { return; };
let hir::def::Res::Def(kind, def_id) = path.res else { return; };
let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = fun.kind else {
return;
};
let hir::def::Res::Def(kind, def_id) = path.res else {
return;
};
let callable_kind = if matches!(kind, hir::def::DefKind::Ctor(_, _)) {
CallableKind::Constructor
} else {
@ -2195,7 +2268,11 @@ enum CallableKind {
maybe_emit_help(def_id, path.segments[0].ident, args, callable_kind);
}
hir::ExprKind::MethodCall(method, _receiver, args, _span) => {
let Some(def_id) = self.typeck_results.borrow().type_dependent_def_id(parent_expr.hir_id) else { return; };
let Some(def_id) =
self.typeck_results.borrow().type_dependent_def_id(parent_expr.hir_id)
else {
return;
};
maybe_emit_help(def_id, method.ident, args, CallableKind::Method)
}
_ => return,

View file

@ -650,7 +650,8 @@ fn check_expr_break(
let mut enclosing_breakables = self.enclosing_breakables.borrow_mut();
let Some(ctxt) = enclosing_breakables.opt_find_breakable(target_id) else {
// Avoid ICE when `break` is inside a closure (#65383).
return Ty::new_error_with_message(tcx,
return Ty::new_error_with_message(
tcx,
expr.span,
"break was outside loop, but no error was emitted",
);
@ -1390,11 +1391,13 @@ fn suggest_array_len(&self, expr: &'tcx hir::Expr<'tcx>, array_len: u64) {
let parent_node = self.tcx.hir().parent_iter(expr.hir_id).find(|(_, node)| {
!matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::AddrOf(..), .. }))
});
let Some((_,
let Some((
_,
hir::Node::Local(hir::Local { ty: Some(ty), .. })
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _), .. }))
) = parent_node else {
return
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _), .. }),
)) = parent_node
else {
return;
};
if let hir::TyKind::Array(_, length) = ty.peel_refs().kind
&& let hir::ArrayLen::Body(hir::AnonConst { hir_id, .. }) = length
@ -2416,7 +2419,9 @@ fn suggest_await_on_field_access(
base: &'tcx hir::Expr<'tcx>,
ty: Ty<'tcx>,
) {
let Some(output_ty) = self.get_impl_future_output_ty(ty) else { return; };
let Some(output_ty) = self.get_impl_future_output_ty(ty) else {
return;
};
let mut add_label = true;
if let ty::Adt(def, _) = output_ty.kind() {
// no field access on enum type

View file

@ -14,14 +14,27 @@ pub fn adjust_fulfillment_error_for_expr_obligation(
&self,
error: &mut traits::FulfillmentError<'tcx>,
) -> bool {
let (traits::ExprItemObligation(def_id, hir_id, idx) | traits::ExprBindingObligation(def_id, _, hir_id, idx))
= *error.obligation.cause.code().peel_derives() else { return false; };
let (traits::ExprItemObligation(def_id, hir_id, idx)
| traits::ExprBindingObligation(def_id, _, hir_id, idx)) =
*error.obligation.cause.code().peel_derives()
else {
return false;
};
let hir = self.tcx.hir();
let hir::Node::Expr(expr) = hir.get(hir_id) else { return false; };
let hir::Node::Expr(expr) = hir.get(hir_id) else {
return false;
};
let Some(unsubstituted_pred) =
self.tcx.predicates_of(def_id).instantiate_identity(self.tcx).predicates.into_iter().nth(idx)
else { return false; };
let Some(unsubstituted_pred) = self
.tcx
.predicates_of(def_id)
.instantiate_identity(self.tcx)
.predicates
.into_iter()
.nth(idx)
else {
return false;
};
let generics = self.tcx.generics_of(def_id);
let predicate_substs = match unsubstituted_pred.kind().skip_binder() {
@ -229,14 +242,14 @@ fn point_at_generic_if_possible(
.tcx
.generics_of(def_id)
.own_substs(ty::InternalSubsts::identity_for_item(self.tcx, def_id));
let Some((index, _)) = own_substs
.iter()
.enumerate()
.find(|(_, arg)| **arg == param_to_point_at) else { return false };
let Some(arg) = segment
.args()
.args
.get(index) else { return false; };
let Some((index, _)) =
own_substs.iter().enumerate().find(|(_, arg)| **arg == param_to_point_at)
else {
return false;
};
let Some(arg) = segment.args().args.get(index) else {
return false;
};
error.obligation.cause.span = arg
.span()
.find_ancestor_in_same_ctxt(error.obligation.cause.span)
@ -573,9 +586,11 @@ fn blame_specific_part_of_expr_corresponding_to_generic_param(
// Find out which of `in_ty_elements` refer to `param`.
// FIXME: It may be better to take the first if there are multiple,
// just so that the error points to a smaller expression.
let Some((drill_expr, drill_ty)) = is_iterator_singleton(expr_elements.iter().zip( in_ty_elements.iter()).filter(|(_expr_elem, in_ty_elem)| {
find_param_in_ty((*in_ty_elem).into(), param)
})) else {
let Some((drill_expr, drill_ty)) =
is_iterator_singleton(expr_elements.iter().zip(in_ty_elements.iter()).filter(
|(_expr_elem, in_ty_elem)| find_param_in_ty((*in_ty_elem).into(), param),
))
else {
// The param is not mentioned, or it is mentioned in multiple indexes.
return Err(expr);
};
@ -594,7 +609,9 @@ fn blame_specific_part_of_expr_corresponding_to_generic_param(
{
// First, confirm that this struct is the same one as in the types, and if so,
// find the right variant.
let Res::Def(expr_struct_def_kind, expr_struct_def_id) = self.typeck_results.borrow().qpath_res(expr_struct_path, expr.hir_id) else {
let Res::Def(expr_struct_def_kind, expr_struct_def_id) =
self.typeck_results.borrow().qpath_res(expr_struct_path, expr.hir_id)
else {
return Err(expr);
};
@ -621,16 +638,14 @@ fn blame_specific_part_of_expr_corresponding_to_generic_param(
// We need to know which of the generic parameters mentions our target param.
// We expect that at least one of them does, since it is expected to be mentioned.
let Some((drill_generic_index, generic_argument_type)) =
is_iterator_singleton(
in_ty_adt_generic_args.iter().enumerate().filter(
|(_index, in_ty_generic)| {
find_param_in_ty(*in_ty_generic, param)
},
),
) else {
return Err(expr);
};
let Some((drill_generic_index, generic_argument_type)) = is_iterator_singleton(
in_ty_adt_generic_args
.iter()
.enumerate()
.filter(|(_index, in_ty_generic)| find_param_in_ty(*in_ty_generic, param)),
) else {
return Err(expr);
};
let struct_generic_parameters: &ty::Generics = self.tcx.generics_of(in_ty_adt.did());
if drill_generic_index >= struct_generic_parameters.params.len() {
@ -703,7 +718,9 @@ fn blame_specific_part_of_expr_corresponding_to_generic_param(
};
// This is (possibly) a constructor call, like `Some(...)` or `MyStruct(a, b, c)`.
let Res::Def(expr_struct_def_kind, expr_ctor_def_id) = self.typeck_results.borrow().qpath_res(expr_callee_path, expr_callee.hir_id) else {
let Res::Def(expr_struct_def_kind, expr_ctor_def_id) =
self.typeck_results.borrow().qpath_res(expr_callee_path, expr_callee.hir_id)
else {
return Err(expr);
};
@ -744,16 +761,14 @@ fn blame_specific_part_of_expr_corresponding_to_generic_param(
// We need to know which of the generic parameters mentions our target param.
// We expect that at least one of them does, since it is expected to be mentioned.
let Some((drill_generic_index, generic_argument_type)) =
is_iterator_singleton(
in_ty_adt_generic_args.iter().enumerate().filter(
|(_index, in_ty_generic)| {
find_param_in_ty(*in_ty_generic, param)
},
),
) else {
return Err(expr);
};
let Some((drill_generic_index, generic_argument_type)) = is_iterator_singleton(
in_ty_adt_generic_args
.iter()
.enumerate()
.filter(|(_index, in_ty_generic)| find_param_in_ty(*in_ty_generic, param)),
) else {
return Err(expr);
};
let struct_generic_parameters: &ty::Generics = self.tcx.generics_of(in_ty_adt.did());
if drill_generic_index >= struct_generic_parameters.params.len() {
@ -794,7 +809,7 @@ fn blame_specific_part_of_expr_corresponding_to_generic_param(
.iter()
.map(|field| field.ty(self.tcx, *in_ty_adt_generic_args))
.enumerate()
.filter(|(_index, field_type)| find_param_in_ty((*field_type).into(), param))
.filter(|(_index, field_type)| find_param_in_ty((*field_type).into(), param)),
) else {
return Err(expr);
};

View file

@ -753,11 +753,11 @@ fn has_error_or_infer<'tcx>(tys: impl IntoIterator<Item = Ty<'tcx>>) -> bool {
}
errors.retain(|error| {
let Error::Invalid(
provided_idx,
expected_idx,
Compatibility::Incompatible(Some(e)),
) = error else { return true };
let Error::Invalid(provided_idx, expected_idx, Compatibility::Incompatible(Some(e))) =
error
else {
return true;
};
let (provided_ty, provided_span) = provided_arg_tys[*provided_idx];
let trace =
mk_trace(provided_span, formal_and_expected_inputs[*expected_idx], provided_ty);

View file

@ -97,8 +97,9 @@ pub(crate) fn suggest_fn_call(
found: Ty<'tcx>,
can_satisfy: impl FnOnce(Ty<'tcx>) -> bool,
) -> bool {
let Some((def_id_or_name, output, inputs)) = self.extract_callable_info(found)
else { return false; };
let Some((def_id_or_name, output, inputs)) = self.extract_callable_info(found) else {
return false;
};
if can_satisfy(output) {
let (sugg_call, mut applicability) = match inputs.len() {
0 => ("".to_string(), Applicability::MachineApplicable),
@ -180,10 +181,12 @@ pub fn suggest_two_fn_call(
rhs_ty: Ty<'tcx>,
can_satisfy: impl FnOnce(Ty<'tcx>, Ty<'tcx>) -> bool,
) -> bool {
let Some((_, lhs_output_ty, lhs_inputs)) = self.extract_callable_info(lhs_ty)
else { return false; };
let Some((_, rhs_output_ty, rhs_inputs)) = self.extract_callable_info(rhs_ty)
else { return false; };
let Some((_, lhs_output_ty, lhs_inputs)) = self.extract_callable_info(lhs_ty) else {
return false;
};
let Some((_, rhs_output_ty, rhs_inputs)) = self.extract_callable_info(rhs_ty) else {
return false;
};
if can_satisfy(lhs_output_ty, rhs_output_ty) {
let mut sugg = vec![];
@ -635,7 +638,9 @@ pub(in super::super) fn suggest_calling_boxed_future_when_appropriate(
// is and we were expecting a Box, ergo Pin<Box<expected>>, we
// can suggest Box::pin.
let parent = self.tcx.hir().parent_id(expr.hir_id);
let Some(Node::Expr(Expr { kind: ExprKind::Call(fn_name, _), .. })) = self.tcx.hir().find(parent) else {
let Some(Node::Expr(Expr { kind: ExprKind::Call(fn_name, _), .. })) =
self.tcx.hir().find(parent)
else {
return false;
};
match fn_name.kind {
@ -850,12 +855,18 @@ fn try_suggest_return_impl_trait(
let Some(hir::Node::Item(hir::Item {
kind:
hir::ItemKind::Fn(
hir::FnSig { decl: hir::FnDecl { inputs: fn_parameters, output: fn_return, .. }, .. },
hir::FnSig {
decl: hir::FnDecl { inputs: fn_parameters, output: fn_return, .. },
..
},
hir::Generics { params, predicates, .. },
_body_id,
),
..
})) = fn_node else { return };
})) = fn_node
else {
return;
};
if params.get(expected_ty_as_param.index as usize).is_none() {
return;
@ -1081,8 +1092,12 @@ pub(crate) fn suggest_copied_or_cloned(
expr_ty: Ty<'tcx>,
expected_ty: Ty<'tcx>,
) -> bool {
let ty::Adt(adt_def, substs) = expr_ty.kind() else { return false; };
let ty::Adt(expected_adt_def, expected_substs) = expected_ty.kind() else { return false; };
let ty::Adt(adt_def, substs) = expr_ty.kind() else {
return false;
};
let ty::Adt(expected_adt_def, expected_substs) = expected_ty.kind() else {
return false;
};
if adt_def != expected_adt_def {
return false;
}
@ -1205,7 +1220,9 @@ pub(crate) fn suggest_option_to_bool(
return false;
}
let ty::Adt(def, _) = expr_ty.peel_refs().kind() else { return false; };
let ty::Adt(def, _) = expr_ty.peel_refs().kind() else {
return false;
};
if !self.tcx.is_diagnostic_item(sym::Option, def.did()) {
return false;
}
@ -1327,7 +1344,9 @@ pub(crate) fn suggest_floating_point_literal(
node: rustc_ast::LitKind::Int(lit, rustc_ast::LitIntType::Unsuffixed),
span,
}) => {
let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(*span) else { return false; };
let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(*span) else {
return false;
};
if !(snippet.starts_with("0x") || snippet.starts_with("0X")) {
return false;
}
@ -1367,10 +1386,7 @@ pub(crate) fn suggest_null_ptr_for_literal_zero_given_to_ptr_arg(
};
// Provided expression needs to be a literal `0`.
let ExprKind::Lit(Spanned {
node: rustc_ast::LitKind::Int(0, _),
span,
}) = expr.kind else {
let ExprKind::Lit(Spanned { node: rustc_ast::LitKind::Int(0, _), span }) = expr.kind else {
return false;
};
@ -1401,7 +1417,9 @@ pub(crate) fn suggest_associated_const(
expr: &hir::Expr<'_>,
expected_ty: Ty<'tcx>,
) -> bool {
let Some((DefKind::AssocFn, old_def_id)) = self.typeck_results.borrow().type_dependent_def(expr.hir_id) else {
let Some((DefKind::AssocFn, old_def_id)) =
self.typeck_results.borrow().type_dependent_def(expr.hir_id)
else {
return false;
};
let old_item_name = self.tcx.item_name(old_def_id);
@ -1494,8 +1512,12 @@ pub(crate) fn note_type_is_not_clone(
found_ty: Ty<'tcx>,
expr: &hir::Expr<'_>,
) {
let hir::ExprKind::MethodCall(segment, callee_expr, &[], _) = expr.kind else { return; };
let Some(clone_trait_did) = self.tcx.lang_items().clone_trait() else { return; };
let hir::ExprKind::MethodCall(segment, callee_expr, &[], _) = expr.kind else {
return;
};
let Some(clone_trait_did) = self.tcx.lang_items().clone_trait() else {
return;
};
let ty::Ref(_, pointee_ty, _) = found_ty.kind() else { return };
let results = self.typeck_results.borrow();
// First, look for a `Clone::clone` call

View file

@ -171,7 +171,8 @@ fn adjust_self_ty(
// time writing the results into the various typeck results.
let mut autoderef = self.autoderef(self.call_expr.span, unadjusted_self_ty);
let Some((ty, n)) = autoderef.nth(pick.autoderefs) else {
return Ty::new_error_with_message(self.tcx,
return Ty::new_error_with_message(
self.tcx,
rustc_span::DUMMY_SP,
format!("failed autoderef {}", pick.autoderefs),
);

View file

@ -1938,13 +1938,21 @@ fn is_relevant_kind_for_mode(&self, kind: ty::AssocKind) -> bool {
/// Determine if the associated item withe the given DefId matches
/// the desired name via a doc alias.
fn matches_by_doc_alias(&self, def_id: DefId) -> bool {
let Some(name) = self.method_name else { return false; };
let Some(local_def_id) = def_id.as_local() else { return false; };
let Some(name) = self.method_name else {
return false;
};
let Some(local_def_id) = def_id.as_local() else {
return false;
};
let hir_id = self.fcx.tcx.hir().local_def_id_to_hir_id(local_def_id);
let attrs = self.fcx.tcx.hir().attrs(hir_id);
for attr in attrs {
let sym::doc = attr.name_or_empty() else { continue; };
let Some(values) = attr.meta_item_list() else { continue; };
let sym::doc = attr.name_or_empty() else {
continue;
};
let Some(values) = attr.meta_item_list() else {
continue;
};
for v in values {
if v.name_or_empty() != sym::alias {
continue;

View file

@ -1699,10 +1699,14 @@ fn suggest_constraining_numerical_ty(
/// we try to suggest `rect.area()`
pub(crate) fn suggest_assoc_method_call(&self, segs: &[PathSegment<'_>]) {
debug!("suggest_assoc_method_call segs: {:?}", segs);
let [seg1, seg2] = segs else { return; };
let [seg1, seg2] = segs else {
return;
};
let Some(mut diag) =
self.tcx.sess.diagnostic().steal_diagnostic(seg1.ident.span, StashKey::CallAssocMethod)
else { return };
self.tcx.sess.diagnostic().steal_diagnostic(seg1.ident.span, StashKey::CallAssocMethod)
else {
return;
};
let map = self.infcx.tcx.hir();
let body_id = self.tcx.hir().body_owned_by(self.body_id);
@ -1839,17 +1843,23 @@ fn suggest_unwrapping_inner_self(
item_name: Ident,
) {
let tcx = self.tcx;
let SelfSource::MethodCall(expr) = source else { return; };
let SelfSource::MethodCall(expr) = source else {
return;
};
let call_expr = tcx.hir().expect_expr(tcx.hir().parent_id(expr.hir_id));
let ty::Adt(kind, substs) = actual.kind() else { return; };
let ty::Adt(kind, substs) = actual.kind() else {
return;
};
match kind.adt_kind() {
ty::AdtKind::Enum => {
let matching_variants: Vec<_> = kind
.variants()
.iter()
.flat_map(|variant| {
let [field] = &variant.fields.raw[..] else { return None; };
let [field] = &variant.fields.raw[..] else {
return None;
};
let field_ty = field.ty(tcx, substs);
// Skip `_`, since that'll just lead to ambiguity.
@ -1927,15 +1937,21 @@ fn suggest_unwrapping_inner_self(
// Target wrapper types - types that wrap or pretend to wrap another type,
// perhaps this inner type is meant to be called?
ty::AdtKind::Struct | ty::AdtKind::Union => {
let [first] = ***substs else { return; };
let ty::GenericArgKind::Type(ty) = first.unpack() else { return; };
let [first] = ***substs else {
return;
};
let ty::GenericArgKind::Type(ty) = first.unpack() else {
return;
};
let Ok(pick) = self.lookup_probe_for_diagnostic(
item_name,
ty,
call_expr,
ProbeScope::TraitsInScope,
None,
) else { return; };
) else {
return;
};
let name = self.ty_to_value_string(actual);
let inner_id = kind.did();
@ -2100,7 +2116,7 @@ pub fn suggest_derive(
let Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred))) =
pred.kind().no_bound_vars()
else {
continue
continue;
};
let adt = match trait_pred.self_ty().ty_adt_def() {
Some(adt) if adt.did().is_local() => adt,
@ -2197,7 +2213,9 @@ fn note_derefed_ty_has_method(
item_name: Ident,
expected: Expectation<'tcx>,
) {
let SelfSource::QPath(ty) = self_source else { return; };
let SelfSource::QPath(ty) = self_source else {
return;
};
for (deref_ty, _) in self.autoderef(rustc_span::DUMMY_SP, rcvr_ty).skip(1) {
if let Ok(pick) = self.probe_for_name(
Mode::Path,
@ -2834,9 +2852,8 @@ pub(crate) fn suggest_else_fn_with_closure(
found: Ty<'tcx>,
expected: Ty<'tcx>,
) -> bool {
let Some((_def_id_or_name, output, _inputs)) =
self.extract_callable_info(found) else {
return false;
let Some((_def_id_or_name, output, _inputs)) = self.extract_callable_info(found) else {
return false;
};
if !self.can_coerce(output, expected) {

View file

@ -74,9 +74,7 @@ pub fn resolve_rvalue_scopes<'a, 'tcx>(
debug!("start resolving rvalue scopes, def_id={def_id:?}");
debug!("rvalue_scope: rvalue_candidates={:?}", scope_tree.rvalue_candidates);
for (&hir_id, candidate) in &scope_tree.rvalue_candidates {
let Some(Node::Expr(expr)) = hir_map.find(hir_id) else {
bug!("hir node does not exist")
};
let Some(Node::Expr(expr)) = hir_map.find(hir_id) else { bug!("hir node does not exist") };
record_rvalue_scope(&mut rvalue_scopes, expr, candidate);
}
rvalue_scopes

View file

@ -644,7 +644,9 @@ fn compute_min_captures(
for capture in captures {
match capture.info.capture_kind {
ty::UpvarCapture::ByRef(_) => {
let PlaceBase::Upvar(upvar_id) = capture.place.base else { bug!("expected upvar") };
let PlaceBase::Upvar(upvar_id) = capture.place.base else {
bug!("expected upvar")
};
let origin = UpvarRegion(upvar_id, closure_span);
let upvar_region = self.next_region_var(origin);
capture.region = Some(upvar_region);
@ -1064,14 +1066,15 @@ fn compute_2229_migrations_for_drop(
// ```
debug!("no path starting from it is used");
match closure_clause {
// Only migrate if closure is a move closure
hir::CaptureBy::Value => {
let mut diagnostics_info = FxHashSet::default();
let upvars = self.tcx.upvars_mentioned(closure_def_id).expect("must be an upvar");
let upvars =
self.tcx.upvars_mentioned(closure_def_id).expect("must be an upvar");
let upvar = upvars[&var_hir_id];
diagnostics_info.insert(UpvarMigrationInfo::CapturingNothing { use_span: upvar.span });
diagnostics_info
.insert(UpvarMigrationInfo::CapturingNothing { use_span: upvar.span });
return Some(diagnostics_info);
}
hir::CaptureBy::Ref => {}

View file

@ -730,13 +730,13 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
debug!("garbage_collect_session_directories() - inspecting: {}", directory_name);
let Ok(timestamp) = extract_timestamp_from_session_dir(directory_name) else {
debug!(
"found session-dir with malformed timestamp: {}",
crate_directory.join(directory_name).display()
);
// Ignore it
return None;
};
debug!(
"found session-dir with malformed timestamp: {}",
crate_directory.join(directory_name).display()
);
// Ignore it
return None;
};
if is_finalized(directory_name) {
let lock_file_path = crate_directory.join(lock_file_name);

View file

@ -804,9 +804,7 @@ fn fold<B, F>(mut self, mut init: B, mut f: F) -> B
// advance the iterator to the start of the next chunk, before proceeding in chunk sized
// steps.
while self.index % CHUNK_BITS != 0 {
let Some(item) = self.next() else {
return init
};
let Some(item) = self.next() else { return init };
init = f(init, item);
}
let start_chunk = self.index / CHUNK_BITS;

View file

@ -363,7 +363,8 @@ fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
let (
hir::Ty { kind: hir::TyKind::Ref(lifetime_sub, _), .. },
hir::Ty { kind: hir::TyKind::Ref(lifetime_sup, _), .. },
) = (self.ty_sub, self.ty_sup) else {
) = (self.ty_sub, self.ty_sup)
else {
return false;
};

View file

@ -2109,14 +2109,13 @@ fn suggest_wrap_to_build_a_tuple(
found: Ty<'tcx>,
expected_fields: &List<Ty<'tcx>>,
) -> Option<TypeErrorAdditionalDiags> {
let [expected_tup_elem] = expected_fields[..] else { return None};
let [expected_tup_elem] = expected_fields[..] else { return None };
if !self.same_type_modulo_infer(expected_tup_elem, found) {
return None;
}
let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
else { return None };
let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) else { return None };
let sugg = if code.starts_with('(') && code.ends_with(')') {
let before_close = span.hi() - BytePos::from_u32(1);

View file

@ -419,7 +419,7 @@ pub fn emit_inference_failure_err(
}
let Some(InferSource { span, kind }) = local_visitor.infer_source else {
return self.bad_inference_failure_err(failure_span, arg_data, error_code)
return self.bad_inference_failure_err(failure_span, arg_data, error_code);
};
let (source_kind, name) = kind.ty_localized_msg(self);
@ -1157,9 +1157,7 @@ fn visit_body(&mut self, body: &'tcx Body<'tcx>) {
continue;
}
let Some(param_ty) = self.opt_node_type(param.hir_id) else {
continue
};
let Some(param_ty) = self.opt_node_type(param.hir_id) else { continue };
if self.generic_arg_contains_target(param_ty.into()) {
self.update_infer_source(InferSource {

View file

@ -38,8 +38,9 @@ pub(super) fn try_report_mismatched_static_lifetime(&self) -> Option<ErrorGuaran
let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else {
return None;
};
let (ObligationCauseCode::BindingObligation(_, binding_span) | ObligationCauseCode::ExprBindingObligation(_, binding_span, ..))
= *parent.code() else {
let (ObligationCauseCode::BindingObligation(_, binding_span)
| ObligationCauseCode::ExprBindingObligation(_, binding_span, ..)) = *parent.code()
else {
return None;
};
@ -67,7 +68,8 @@ pub(super) fn try_report_mismatched_static_lifetime(&self) -> Option<ErrorGuaran
let hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl(hir::Impl { self_ty: impl_self_ty, .. }),
..
}) = impl_node else {
}) = impl_node
else {
bug!("Node not an impl.");
};

View file

@ -503,7 +503,9 @@ fn find_impl_on_dyn_trait(
// Get the `Ident` of the method being called and the corresponding `impl` (to point at
// `Bar` in `impl Foo for dyn Bar {}` and the definition of the method being called).
let Some((ident, self_ty)) = NiceRegionError::get_impl_ident_and_self_ty_from_trait(tcx, instance.def_id(), &v.0) else {
let Some((ident, self_ty)) =
NiceRegionError::get_impl_ident_and_self_ty_from_trait(tcx, instance.def_id(), &v.0)
else {
return false;
};

View file

@ -295,12 +295,13 @@ pub fn suggest_copy_trait_method_bounds(
// but right now it's not really very smart when it comes to implicit `Sized`
// predicates and bounds on the trait itself.
let Some(impl_def_id) =
self.tcx.associated_item(impl_item_def_id).impl_container(self.tcx) else { return; };
let Some(trait_ref) = self
.tcx
.impl_trait_ref(impl_def_id)
else { return; };
let Some(impl_def_id) = self.tcx.associated_item(impl_item_def_id).impl_container(self.tcx)
else {
return;
};
let Some(trait_ref) = self.tcx.impl_trait_ref(impl_def_id) else {
return;
};
let trait_substs = trait_ref
.subst_identity()
// Replace the explicit self type with `Self` for better suggestion rendering
@ -309,20 +310,25 @@ pub fn suggest_copy_trait_method_bounds(
let trait_item_substs = ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id)
.rebase_onto(self.tcx, impl_def_id, trait_substs);
let Ok(trait_predicates) = self
.tcx
.explicit_predicates_of(trait_item_def_id)
.instantiate_own(self.tcx, trait_item_substs)
.map(|(pred, _)| {
if pred.is_suggestable(self.tcx, false) {
Ok(pred.to_string())
} else {
Err(())
}
})
.collect::<Result<Vec<_>, ()>>() else { return; };
let Ok(trait_predicates) =
self.tcx
.explicit_predicates_of(trait_item_def_id)
.instantiate_own(self.tcx, trait_item_substs)
.map(|(pred, _)| {
if pred.is_suggestable(self.tcx, false) {
Ok(pred.to_string())
} else {
Err(())
}
})
.collect::<Result<Vec<_>, ()>>()
else {
return;
};
let Some(generics) = self.tcx.hir().get_generics(impl_item_def_id) else { return; };
let Some(generics) = self.tcx.hir().get_generics(impl_item_def_id) else {
return;
};
let suggestion = if trait_predicates.is_empty() {
WhereClauseSuggestions::Remove { span: generics.where_clause_span }

View file

@ -526,13 +526,23 @@ pub(super) fn suggest_for_all_lifetime_closure(
diag: &mut Diagnostic,
) {
// 0. Extract fn_decl from hir
let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(hir::Closure { body, fn_decl, .. }), .. }) = hir else { return; };
let hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Closure(hir::Closure { body, fn_decl, .. }),
..
}) = hir
else {
return;
};
let hir::Body { params, .. } = self.tcx.hir().body(*body);
// 1. Get the substs of the closure.
// 2. Assume exp_found is FnOnce / FnMut / Fn, we can extract function parameters from [1].
let Some(expected) = exp_found.expected.skip_binder().substs.get(1) else { return; };
let Some(found) = exp_found.found.skip_binder().substs.get(1) else { return; };
let Some(expected) = exp_found.expected.skip_binder().substs.get(1) else {
return;
};
let Some(found) = exp_found.found.skip_binder().substs.get(1) else {
return;
};
let expected = expected.unpack();
let found = found.unpack();
// 3. Extract the tuple type from Fn trait and suggest the change.
@ -711,7 +721,9 @@ pub fn consider_returning_binding_diag(
let hir = self.tcx.hir();
for stmt in blk.stmts.iter().rev() {
let hir::StmtKind::Local(local) = &stmt.kind else { continue; };
let hir::StmtKind::Local(local) = &stmt.kind else {
continue;
};
local.pat.walk(&mut find_compatible_candidates);
}
match hir.find_parent(blk.hir_id) {

View file

@ -190,7 +190,8 @@ macro_rules! error {
ExpectedValues::Some(FxHashSet::default())
});
let ExpectedValues::Some(expected_values) = expected_values else {
let ExpectedValues::Some(expected_values) = expected_values
else {
bug!("`expected_values` should be a list a values")
};

View file

@ -81,7 +81,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
let adjustments = cx.typeck_results().expr_adjustments(receiver_arg);
let Some(Adjustment { kind: Adjust::Borrow(_), target }) = adjustments.last() else {
return
return;
};
let types =

View file

@ -793,9 +793,7 @@ fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
_ => return,
}
let Some(debug) = cx.tcx.get_diagnostic_item(sym::Debug) else {
return
};
let Some(debug) = cx.tcx.get_diagnostic_item(sym::Debug) else { return };
if self.impling_types.is_none() {
let mut impls = LocalDefIdSet::default();
@ -1458,9 +1456,7 @@ pub(crate) fn is_type_variable_assoc(qpath: &hir::QPath<'_>) -> bool {
impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
let hir::ItemKind::TyAlias(ty, type_alias_generics) = &item.kind else {
return
};
let hir::ItemKind::TyAlias(ty, type_alias_generics) = &item.kind else { return };
if cx.tcx.type_of(item.owner_id.def_id).skip_binder().has_opaque_types() {
// Bounds are respected for `type X = impl Trait` and `type X = (impl Trait, Y);`
return;
@ -2147,8 +2143,8 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
match predicate.bounded_ty.kind {
hir::TyKind::Path(hir::QPath::Resolved(None, path)) => {
let Res::Def(DefKind::TyParam, def_id) = path.res else {
continue;
};
continue;
};
let index = ty_generics.param_def_id_to_index[&def_id];
(
Self::lifetimes_outliving_type(inferred_outlives, index),
@ -2570,7 +2566,10 @@ fn ty_find_init_error<'tcx>(
Some((variant, definitely_inhabited))
});
let Some(first_variant) = potential_variants.next() else {
return Some(InitError::from("enums with no inhabited variants have no valid value").spanned(span));
return Some(
InitError::from("enums with no inhabited variants have no valid value")
.spanned(span),
);
};
// So we have at least one potentially inhabited variant. Might we have two?
let Some(second_variant) = potential_variants.next() else {
@ -3181,7 +3180,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
let mut chars = possible_label.chars();
let Some(c) = chars.next() else {
// Empty string means a leading ':' in this section, which is not a label
break
break;
};
// A label starts with an alphabetic character or . or _ and continues with alphanumeric characters, _, or $
if (c.is_alphabetic() || matches!(c, '.' | '_'))

View file

@ -37,7 +37,9 @@
impl<'tcx> LateLintPass<'tcx> for CastRefToMut {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
let ExprKind::Unary(UnOp::Deref, e) = &expr.kind else { return; };
let ExprKind::Unary(UnOp::Deref, e) = &expr.kind else {
return;
};
let e = e.peel_blocks();
let e = if let ExprKind::Cast(e, t) = e.kind

View file

@ -119,7 +119,9 @@ fn suggest_question_mark<'tcx>(
span: Span,
) -> bool {
let Some(body_id) = cx.enclosing_body else { return false };
let Some(into_iterator_did) = cx.tcx.get_diagnostic_item(sym::IntoIterator) else { return false };
let Some(into_iterator_did) = cx.tcx.get_diagnostic_item(sym::IntoIterator) else {
return false;
};
if !cx.tcx.is_diagnostic_item(sym::Result, adt.did()) {
return false;

View file

@ -265,7 +265,10 @@ fn get_lint_level(&self, lint: &'static Lint, _: &Session) -> LevelAndSource {
self.specs.lint_level_id_at_node(self.tcx, LintId::of(lint), self.cur)
}
fn push_expectation(&mut self, id: LintExpectationId, expectation: LintExpectation) {
let LintExpectationId::Stable { attr_id: Some(attr_id), hir_id, attr_index, .. } = id else { bug!("unstable expectation id should already be mapped") };
let LintExpectationId::Stable { attr_id: Some(attr_id), hir_id, attr_index, .. } = id
else {
bug!("unstable expectation id should already be mapped")
};
let key = LintExpectationId::Unstable { attr_id, lint_index: None };
self.unstable_to_stable_ids.entry(key).or_insert(LintExpectationId::Stable {
@ -542,7 +545,7 @@ fn add_command_line(&mut self) {
let Ok(ids) = self.store.find_lints(&lint_name) else {
// errors handled in check_lint_name_cmdline above
continue
continue;
};
for id in ids {
// ForceWarn and Forbid cannot be overridden
@ -685,9 +688,7 @@ fn add(&mut self, attrs: &[ast::Attribute], is_crate_node: bool, source_hir_id:
Some(lvl) => lvl,
};
let Some(mut metas) = attr.meta_item_list() else {
continue
};
let Some(mut metas) = attr.meta_item_list() else { continue };
if metas.is_empty() {
// This emits the unused_attributes lint for `#[level()]`
@ -956,8 +957,9 @@ fn add(&mut self, attrs: &[ast::Attribute], is_crate_node: bool, source_hir_id:
continue;
}
let LintLevelSource::Node { name: lint_attr_name, span: lint_attr_span, .. } = *src else {
continue
let LintLevelSource::Node { name: lint_attr_name, span: lint_attr_span, .. } = *src
else {
continue;
};
self.emit_spanned_lint(

View file

@ -79,8 +79,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
// We only care about method calls corresponding to the `Clone`, `Deref` and `Borrow`
// traits and ignore any other method call.
let Some((DefKind::AssocFn, did)) =
cx.typeck_results().type_dependent_def(expr.hir_id)
let Some((DefKind::AssocFn, did)) = cx.typeck_results().type_dependent_def(expr.hir_id)
else {
return;
};
@ -98,9 +97,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
.tcx
.normalize_erasing_regions(cx.param_env, cx.typeck_results().node_substs(expr.hir_id));
// Resolve the trait method instance.
let Ok(Some(i)) = ty::Instance::resolve(cx.tcx, cx.param_env, did, substs) else {
return
};
let Ok(Some(i)) = ty::Instance::resolve(cx.tcx, cx.param_env, did, substs) else { return };
// (Re)check that it implements the noop diagnostic.
let Some(name) = cx.tcx.get_diagnostic_name(i.def_id()) else { return };

View file

@ -68,7 +68,9 @@
impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
let hir::ItemKind::OpaqueTy(opaque) = &item.kind else { return; };
let hir::ItemKind::OpaqueTy(opaque) = &item.kind else {
return;
};
let def_id = item.owner_id.def_id.to_def_id();
let infcx = &cx.tcx.infer_ctxt().build();
// For every projection predicate in the opaque type's explicit bounds,
@ -116,7 +118,12 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
.subst_iter_copied(cx.tcx, &proj.projection_ty.substs)
{
let assoc_pred = assoc_pred.fold_with(proj_replacer);
let Ok(assoc_pred) = traits::fully_normalize(infcx, traits::ObligationCause::dummy(), cx.param_env, assoc_pred) else {
let Ok(assoc_pred) = traits::fully_normalize(
infcx,
traits::ObligationCause::dummy(),
cx.param_env,
assoc_pred,
) else {
continue;
};
// If that predicate doesn't hold modulo regions (but passed during type-check),

View file

@ -92,7 +92,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
let predicates = cx.tcx.explicit_predicates_of(item.owner_id);
for &(predicate, span) in predicates.predicates {
let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() else {
continue
continue;
};
let def_id = trait_predicate.trait_ref.def_id;
if cx.tcx.lang_items().drop_trait() == Some(def_id) {
@ -100,9 +100,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
if trait_predicate.trait_ref.self_ty().is_impl_trait() {
continue;
}
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else {
return
};
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
cx.emit_spanned_lint(
DROP_BOUNDS,
span,
@ -113,15 +111,11 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
}
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &'tcx hir::Ty<'tcx>) {
let hir::TyKind::TraitObject(bounds, _lifetime, _syntax) = &ty.kind else {
return
};
let hir::TyKind::TraitObject(bounds, _lifetime, _syntax) = &ty.kind else { return };
for bound in &bounds[..] {
let def_id = bound.trait_ref.trait_def_id();
if cx.tcx.lang_items().drop_trait() == def_id {
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else {
return
};
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
cx.emit_spanned_lint(DYN_DROP, bound.span, DropGlue { tcx: cx.tcx, def_id });
}
}

View file

@ -560,7 +560,10 @@ fn is_nan(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
let expr = expr.peel_blocks().peel_borrows();
match expr.kind {
ExprKind::Path(qpath) => {
let Some(def_id) = cx.typeck_results().qpath_res(&qpath, expr.hir_id).opt_def_id() else { return false; };
let Some(def_id) = cx.typeck_results().qpath_res(&qpath, expr.hir_id).opt_def_id()
else {
return false;
};
matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::f32_nan | sym::f64_nan))
}
@ -1584,10 +1587,10 @@ fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
let t = cx.tcx.type_of(it.owner_id).subst_identity();
let ty = cx.tcx.erase_regions(t);
let Ok(layout) = cx.layout_of(ty) else { return };
let Variants::Multiple {
tag_encoding: TagEncoding::Direct, tag, ref variants, ..
} = &layout.variants else {
return
let Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, ref variants, .. } =
&layout.variants
else {
return;
};
let tag_size = tag.size(&cx.tcx).bytes();
@ -1760,8 +1763,13 @@ fn check_memory_fence(cx: &LateContext<'_>, expr: &Expr<'_>) {
}
fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) {
let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak])
else {return };
let Some((method, args)) = Self::inherent_atomic_method_call(
cx,
expr,
&[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak],
) else {
return;
};
let fail_order_arg = match method {
sym::fetch_update => &args[1],

View file

@ -94,7 +94,9 @@
impl<'tcx> LateLintPass<'tcx> for UnusedResults {
fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) {
let hir::StmtKind::Semi(mut expr) = s.kind else { return; };
let hir::StmtKind::Semi(mut expr) = s.kind else {
return;
};
let mut expr_is_from_block = false;
while let hir::ExprKind::Block(blk, ..) = expr.kind

View file

@ -203,14 +203,18 @@ fn generate_structure_code_for_attr(
if first && (nested.input.is_empty() || nested.input.peek(Token![,])) {
self.slug.set_once(path.clone(), path.span().unwrap());
first = false;
return Ok(())
return Ok(());
}
first = false;
let Ok(nested) = nested.value() else {
span_err(nested.input.span().unwrap(), "diagnostic slug must be the first argument").emit();
return Ok(())
span_err(
nested.input.span().unwrap(),
"diagnostic slug must be the first argument",
)
.emit();
return Ok(());
};
if path.is_ident("code") {
@ -221,7 +225,9 @@ fn generate_structure_code_for_attr(
#diag.code(rustc_errors::DiagnosticId::Error(#code.to_string()));
});
} else {
span_err(path.span().unwrap(), "unknown argument").note("only the `code` parameter is valid after the slug").emit();
span_err(path.span().unwrap(), "unknown argument")
.note("only the `code` parameter is valid after the slug")
.emit();
// consume the buffer so we don't have syntax errors from syn
let _ = nested.parse::<TokenStream>();

View file

@ -188,7 +188,9 @@ fn identify_kind(
let mut kind_slugs = vec![];
for attr in self.variant.ast().attrs {
let Some(SubdiagnosticVariant { kind, slug, no_span }) = SubdiagnosticVariant::from_attr(attr, self)? else {
let Some(SubdiagnosticVariant { kind, slug, no_span }) =
SubdiagnosticVariant::from_attr(attr, self)?
else {
// Some attributes aren't errors - like documentation comments - but also aren't
// subdiagnostics.
continue;

View file

@ -36,7 +36,8 @@ fn parse(input: ParseStream<'_>) -> Result<Self> {
false
}
"max" => {
let Meta::NameValue(MetaNameValue { value: Expr::Lit(lit), .. }) = &attr.meta else {
let Meta::NameValue(MetaNameValue { value: Expr::Lit(lit), .. }) = &attr.meta
else {
panic!("#[max = NUMBER] attribute requires max value");
};
@ -47,7 +48,8 @@ fn parse(input: ParseStream<'_>) -> Result<Self> {
false
}
"debug_format" => {
let Meta::NameValue(MetaNameValue { value: Expr::Lit(lit), .. }) = &attr.meta else {
let Meta::NameValue(MetaNameValue { value: Expr::Lit(lit), .. }) = &attr.meta
else {
panic!("#[debug_format = FMT] attribute requires a format");
};

View file

@ -741,7 +741,9 @@ fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
};
info!("panic runtime not found -- loading {}", name);
let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; };
let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else {
return;
};
let data = self.cstore.get_crate_data(cnum);
// Sanity check the loaded crate to ensure it is indeed a panic runtime
@ -774,7 +776,9 @@ fn inject_profiler_runtime(&mut self, krate: &ast::Crate) {
self.sess.emit_err(errors::ProfilerBuiltinsNeedsCore);
}
let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else { return; };
let Some(cnum) = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit) else {
return;
};
let data = self.cstore.get_crate_data(cnum);
// Sanity check the loaded crate to ensure it is indeed a profiler runtime

View file

@ -804,8 +804,12 @@ fn get_metadata_section<'p>(
}
// Length of the compressed stream - this allows linkers to pad the section if they want
let Ok(len_bytes) = <[u8; 4]>::try_from(&buf[header_len..cmp::min(data_start, buf.len())]) else {
return Err(MetadataError::LoadFailure("invalid metadata length found".to_string()));
let Ok(len_bytes) =
<[u8; 4]>::try_from(&buf[header_len..cmp::min(data_start, buf.len())])
else {
return Err(MetadataError::LoadFailure(
"invalid metadata length found".to_string(),
));
};
let compressed_len = u32::from_be_bytes(len_bytes) as usize;

View file

@ -311,8 +311,10 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
#[inline]
fn tcx(&self) -> TyCtxt<'tcx> {
let Some(tcx) = self.tcx else {
bug!("No TyCtxt found for decoding. \
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.");
bug!(
"No TyCtxt found for decoding. \
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
);
};
tcx
}
@ -448,8 +450,10 @@ fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> SyntaxContext {
let cdata = decoder.cdata();
let Some(sess) = decoder.sess else {
bug!("Cannot decode SyntaxContext without Session.\
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.");
bug!(
"Cannot decode SyntaxContext without Session.\
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
);
};
let cname = cdata.root.name();
@ -470,8 +474,10 @@ fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> ExpnId {
let local_cdata = decoder.cdata();
let Some(sess) = decoder.sess else {
bug!("Cannot decode ExpnId without Session. \
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.");
bug!(
"Cannot decode ExpnId without Session. \
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
);
};
let cnum = CrateNum::decode(decoder);
@ -521,8 +527,10 @@ fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> Span {
let hi = lo + len;
let Some(sess) = decoder.sess else {
bug!("Cannot decode Span without Session. \
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.")
bug!(
"Cannot decode Span without Session. \
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
)
};
// Index of the file in the corresponding crate's list of encoded files.

View file

@ -1671,7 +1671,9 @@ fn encode_rendered_const_for_body(&mut self, body_id: hir::BodyId) -> String {
fn encode_info_for_macro(&mut self, def_id: LocalDefId) {
let tcx = self.tcx;
let hir::ItemKind::Macro(ref macro_def, _) = tcx.hir().expect_item(def_id).kind else { bug!() };
let hir::ItemKind::Macro(ref macro_def, _) = tcx.hir().expect_item(def_id).kind else {
bug!()
};
self.tables.is_macro_rules.set(def_id.local_def_index, macro_def.macro_rules);
record!(self.tables.macro_definition[def_id.to_def_id()] <- &*macro_def.body);
}
@ -1911,7 +1913,9 @@ fn encode_impls(&mut self) -> LazyArray<TraitImpls> {
FxHashMap::default();
for id in tcx.hir().items() {
let DefKind::Impl { of_trait } = tcx.def_kind(id.owner_id) else { continue; };
let DefKind::Impl { of_trait } = tcx.def_kind(id.owner_id) else {
continue;
};
let def_id = id.owner_id.to_def_id();
self.tables.defaultness.set_some(def_id.index, tcx.defaultness(def_id));

View file

@ -323,7 +323,7 @@ impl<T> FixedSizeEncoding for Option<LazyValue<T>> {
impl<T> LazyArray<T> {
#[inline]
fn write_to_bytes_impl(self, b: &mut [u8; 8]) {
let ([position_bytes, meta_bytes],[])= b.as_chunks_mut::<4>() else { panic!() };
let ([position_bytes, meta_bytes], []) = b.as_chunks_mut::<4>() else { panic!() };
let position = self.position.get();
let position: u32 = position.try_into().unwrap();
@ -346,7 +346,7 @@ impl<T> FixedSizeEncoding for LazyArray<T> {
#[inline]
fn from_bytes(b: &[u8; 8]) -> Self {
let ([position_bytes, meta_bytes],[])= b.as_chunks::<4>() else { panic!() };
let ([position_bytes, meta_bytes], []) = b.as_chunks::<4>() else { panic!() };
if *meta_bytes == [0; 4] {
return Default::default();
}
@ -365,7 +365,7 @@ impl<T> FixedSizeEncoding for Option<LazyArray<T>> {
#[inline]
fn from_bytes(b: &[u8; 8]) -> Self {
let ([position_bytes, meta_bytes],[])= b.as_chunks::<4>() else { panic!() };
let ([position_bytes, meta_bytes], []) = b.as_chunks::<4>() else { panic!() };
LazyArray::from_bytes_impl(position_bytes, meta_bytes)
}

View file

@ -418,7 +418,7 @@ impl TryFrom<ScalarInt> for char {
#[inline]
fn try_from(int: ScalarInt) -> Result<Self, Self::Error> {
let Ok(bits) = int.to_bits(Size::from_bytes(std::mem::size_of::<char>())) else {
let Ok(bits) = int.to_bits(Size::from_bytes(std::mem::size_of::<char>())) else {
return Err(CharTryFromScalarInt);
};
match char::from_u32(bits.try_into().unwrap()) {

View file

@ -2713,12 +2713,16 @@ pub fn impl_method_has_trait_impl_trait_tys(self, def_id: DefId) -> bool {
return false;
}
let Some(item) = self.opt_associated_item(def_id) else { return false; };
let Some(item) = self.opt_associated_item(def_id) else {
return false;
};
if item.container != ty::AssocItemContainer::ImplContainer {
return false;
}
let Some(trait_item_def_id) = item.trait_item_def_id else { return false; };
let Some(trait_item_def_id) = item.trait_item_def_id else {
return false;
};
return !self
.associated_types_for_impl_traits_in_associated_fn(trait_item_def_id)

View file

@ -358,7 +358,8 @@ pub fn calculate_dtor(
}
let Some(item_id) = self.associated_item_def_ids(impl_did).first() else {
self.sess.delay_span_bug(self.def_span(impl_did), "Drop impl without drop function");
self.sess
.delay_span_bug(self.def_span(impl_did), "Drop impl without drop function");
return;
};

View file

@ -241,9 +241,7 @@ fn parse_block_def(&self, expr_id: ExprId) -> PResult<BasicBlockData<'tcx>> {
});
}
let Some(trailing) = block.expr else {
return Err(self.expr_error(expr_id, "terminator"))
};
let Some(trailing) = block.expr else { return Err(self.expr_error(expr_id, "terminator")) };
let span = self.thir[trailing].span;
let terminator = self.parse_terminator(trailing)?;
data.terminator = Some(Terminator {

View file

@ -78,7 +78,7 @@ fn parse_match(&self, arms: &[ArmId], span: Span) -> PResult<SwitchTargets> {
span,
item_description: "no arms".to_string(),
expected: "at least one arm".to_string(),
})
});
};
let otherwise = &self.thir[*otherwise];
@ -87,7 +87,7 @@ fn parse_match(&self, arms: &[ArmId], span: Span) -> PResult<SwitchTargets> {
span: otherwise.span,
item_description: format!("{:?}", otherwise.pattern.kind),
expected: "wildcard pattern".to_string(),
})
});
};
let otherwise = self.parse_block(otherwise.body)?;
@ -100,7 +100,7 @@ fn parse_match(&self, arms: &[ArmId], span: Span) -> PResult<SwitchTargets> {
span: arm.pattern.span,
item_description: format!("{:?}", arm.pattern.kind),
expected: "constant pattern".to_string(),
})
});
};
values.push(value.eval_bits(self.tcx, self.param_env, arm.pattern.ty));
targets.push(self.parse_block(arm.body)?);

View file

@ -175,11 +175,8 @@ fn to_upvars_resolved_place_builder<'tcx>(
projection: &[PlaceElem<'tcx>],
) -> Option<PlaceBuilder<'tcx>> {
let Some((capture_index, capture)) =
find_capture_matching_projections(
&cx.upvars,
var_hir_id,
&projection,
) else {
find_capture_matching_projections(&cx.upvars, var_hir_id, &projection)
else {
let closure_span = cx.tcx.def_span(closure_def_id);
if !enable_precise_capture(closure_span) {
bug!(
@ -189,10 +186,7 @@ fn to_upvars_resolved_place_builder<'tcx>(
projection
)
} else {
debug!(
"No associated capture found for {:?}[{:#?}]",
var_hir_id, projection,
);
debug!("No associated capture found for {:?}[{:#?}]", var_hir_id, projection,);
}
return None;
};

View file

@ -607,9 +607,11 @@ pub(crate) fn place_into_pattern(
// };
// ```
if let Some(place) = initializer.try_to_place(self) {
let LocalInfo::User(BindingForm::Var(
VarBindingForm { opt_match_place: Some((ref mut match_place, _)), .. },
)) = **self.local_decls[local].local_info.as_mut().assert_crate_local() else {
let LocalInfo::User(BindingForm::Var(VarBindingForm {
opt_match_place: Some((ref mut match_place, _)),
..
})) = **self.local_decls[local].local_info.as_mut().assert_crate_local()
else {
bug!("Let binding to non-user variable.")
};
*match_place = Some(place);

View file

@ -88,7 +88,8 @@ pub(super) fn add_cases_to_switch<'pat>(
switch_ty: Ty<'tcx>,
options: &mut FxIndexMap<ConstantKind<'tcx>, u128>,
) -> bool {
let Some(match_pair) = candidate.match_pairs.iter().find(|mp| mp.place == *test_place) else {
let Some(match_pair) = candidate.match_pairs.iter().find(|mp| mp.place == *test_place)
else {
return false;
};
@ -126,7 +127,8 @@ pub(super) fn add_variants_to_switch<'pat>(
candidate: &Candidate<'pat, 'tcx>,
variants: &mut BitSet<VariantIdx>,
) -> bool {
let Some(match_pair) = candidate.match_pairs.iter().find(|mp| mp.place == *test_place) else {
let Some(match_pair) = candidate.match_pairs.iter().find(|mp| mp.place == *test_place)
else {
return false;
};

View file

@ -712,9 +712,7 @@ pub fn thir_check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
return;
}
let Ok((thir, expr)) = tcx.thir_body(def) else {
return
};
let Ok((thir, expr)) = tcx.thir_body(def) else { return };
let thir = &thir.borrow();
// If `thir` is empty, a type error occurred, skip this body.
if thir.exprs.is_empty() {

View file

@ -942,7 +942,9 @@ fn maybe_point_at_variant<'a, 'p: 'a, 'tcx: 'a>(
/// This analysis is *not* subsumed by NLL.
fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, '_, 'tcx>, pat: &Pat<'tcx>) {
// Extract `sub` in `binding @ sub`.
let PatKind::Binding { name, mode, ty, subpattern: Some(box ref sub), .. } = pat.kind else { return };
let PatKind::Binding { name, mode, ty, subpattern: Some(box ref sub), .. } = pat.kind else {
return;
};
let is_binding_by_move = |ty: Ty<'tcx>| !ty.is_copy_modulo_regions(cx.tcx, cx.param_env);

View file

@ -321,7 +321,9 @@ fn statement_effect(
// Mark all places as "maybe init" if they are mutably borrowed. See #90752.
for_each_mut_borrow(statement, location, |place| {
let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref()) else { return };
let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref()) else {
return;
};
on_all_children_bits(self.tcx, self.body, self.move_data(), mpi, |child| {
trans.gen(child);
})
@ -343,7 +345,9 @@ fn terminator_effect(
}
for_each_mut_borrow(terminator, location, |place| {
let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref()) else { return };
let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref()) else {
return;
};
on_all_children_bits(self.tcx, self.body, self.move_data(), mpi, |child| {
trans.gen(child);
})

View file

@ -76,9 +76,11 @@ fn fully_moved_locals(ssa: &SsaLocals, body: &Body<'_>) -> BitSet<Local> {
let mut fully_moved = BitSet::new_filled(body.local_decls.len());
for (_, rvalue, _) in ssa.assignments(body) {
let (Rvalue::Use(Operand::Copy(place) | Operand::Move(place)) | Rvalue::CopyForDeref(place))
= rvalue
else { continue };
let (Rvalue::Use(Operand::Copy(place) | Operand::Move(place))
| Rvalue::CopyForDeref(place)) = rvalue
else {
continue;
};
let Some(rhs) = place.as_local() else { continue };
if !ssa.is_ssa(rhs) {

View file

@ -281,7 +281,7 @@ fn handle_switch_int(
let FlatSet::Elem(choice) = discr_value else {
// Do nothing if we don't know which branch will be taken.
return
return;
};
if target.value.map(|n| n == choice).unwrap_or(!handled) {

Some files were not shown because too many files have changed in this diff Show more