Re-format let-else per rustfmt update
This commit is contained in:
parent
67b0cfc761
commit
cc907f80b9
162 changed files with 1404 additions and 947 deletions
|
@ -1267,9 +1267,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
"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 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
);
|
||||
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 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
};
|
||||
|
||||
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 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
|
||||
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 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
&[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 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
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(
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -186,18 +186,14 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -749,9 +749,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, '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 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, '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);
|
||||
|
|
|
@ -360,9 +360,11 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
&[]
|
||||
};
|
||||
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 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue