Format all the let chains in compiler
This commit is contained in:
@@ -169,8 +169,8 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTyToOpaque<'tcx> {
|
||||
|
||||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
if let ty::Alias(ty::Projection, projection_ty) = ty.kind()
|
||||
&& let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. })
|
||||
= self.tcx.opt_rpitit_info(projection_ty.def_id)
|
||||
&& let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) =
|
||||
self.tcx.opt_rpitit_info(projection_ty.def_id)
|
||||
&& fn_def_id == self.fn_def_id
|
||||
{
|
||||
self.tcx.type_of(projection_ty.def_id).instantiate(self.tcx, projection_ty.args)
|
||||
|
||||
@@ -389,7 +389,9 @@ fn const_evaluatable_predicates_of(
|
||||
let node = tcx.hir().get(hir_id);
|
||||
|
||||
let mut collector = ConstCollector { tcx, preds: FxIndexSet::default() };
|
||||
if let hir::Node::Item(item) = node && let hir::ItemKind::Impl(impl_) = item.kind {
|
||||
if let hir::Node::Item(item) = node
|
||||
&& let hir::ItemKind::Impl(impl_) = item.kind
|
||||
{
|
||||
if let Some(of_trait) = &impl_.of_trait {
|
||||
debug!("const_evaluatable_predicates_of({:?}): visit impl trait_ref", def_id);
|
||||
collector.visit_trait_ref(of_trait);
|
||||
|
||||
@@ -1190,7 +1190,9 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
||||
Scope::Root { opt_parent_item } => {
|
||||
if let Some(parent_item) = opt_parent_item
|
||||
&& let parent_generics = self.tcx.generics_of(parent_item)
|
||||
&& parent_generics.param_def_id_to_index(self.tcx, region_def_id.to_def_id()).is_some()
|
||||
&& parent_generics
|
||||
.param_def_id_to_index(self.tcx, region_def_id.to_def_id())
|
||||
.is_some()
|
||||
{
|
||||
break Some(ResolvedArg::EarlyBound(region_def_id.to_def_id()));
|
||||
}
|
||||
@@ -1209,13 +1211,14 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
||||
// regular fns.
|
||||
if let Some(hir::PredicateOrigin::ImplTrait) = where_bound_origin
|
||||
&& let hir::LifetimeName::Param(param_id) = lifetime_ref.res
|
||||
&& let Some(generics) = self.tcx.hir().get_generics(self.tcx.local_parent(param_id))
|
||||
&& let Some(generics) =
|
||||
self.tcx.hir().get_generics(self.tcx.local_parent(param_id))
|
||||
&& let Some(param) = generics.params.iter().find(|p| p.def_id == param_id)
|
||||
&& param.is_elided_lifetime()
|
||||
&& !self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id).is_async()
|
||||
&& !self.tcx.features().anonymous_lifetime_in_impl_trait
|
||||
{
|
||||
let mut diag = rustc_session::parse::feature_err(
|
||||
let mut diag = rustc_session::parse::feature_err(
|
||||
&self.tcx.sess.parse_sess,
|
||||
sym::anonymous_lifetime_in_impl_trait,
|
||||
lifetime_ref.ident.span,
|
||||
@@ -1225,25 +1228,31 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
||||
if let Some(generics) =
|
||||
self.tcx.hir().get_generics(lifetime_ref.hir_id.owner.def_id)
|
||||
{
|
||||
let new_param_sugg = if let Some(span) =
|
||||
generics.span_for_lifetime_suggestion()
|
||||
{
|
||||
(span, "'a, ".to_owned())
|
||||
} else {
|
||||
(generics.span, "<'a>".to_owned())
|
||||
};
|
||||
let new_param_sugg =
|
||||
if let Some(span) = generics.span_for_lifetime_suggestion() {
|
||||
(span, "'a, ".to_owned())
|
||||
} else {
|
||||
(generics.span, "<'a>".to_owned())
|
||||
};
|
||||
|
||||
let lifetime_sugg = match lifetime_ref.suggestion_position() {
|
||||
(hir::LifetimeSuggestionPosition::Normal, span) => (span, "'a".to_owned()),
|
||||
(hir::LifetimeSuggestionPosition::Ampersand, span) => (span, "'a ".to_owned()),
|
||||
(hir::LifetimeSuggestionPosition::ElidedPath, span) => (span, "<'a>".to_owned()),
|
||||
(hir::LifetimeSuggestionPosition::ElidedPathArgument, span) => (span, "'a, ".to_owned()),
|
||||
(hir::LifetimeSuggestionPosition::ObjectDefault, span) => (span, "+ 'a".to_owned()),
|
||||
(hir::LifetimeSuggestionPosition::Normal, span) => {
|
||||
(span, "'a".to_owned())
|
||||
}
|
||||
(hir::LifetimeSuggestionPosition::Ampersand, span) => {
|
||||
(span, "'a ".to_owned())
|
||||
}
|
||||
(hir::LifetimeSuggestionPosition::ElidedPath, span) => {
|
||||
(span, "<'a>".to_owned())
|
||||
}
|
||||
(hir::LifetimeSuggestionPosition::ElidedPathArgument, span) => {
|
||||
(span, "'a, ".to_owned())
|
||||
}
|
||||
(hir::LifetimeSuggestionPosition::ObjectDefault, span) => {
|
||||
(span, "+ 'a".to_owned())
|
||||
}
|
||||
};
|
||||
let suggestions = vec![
|
||||
lifetime_sugg,
|
||||
new_param_sugg,
|
||||
];
|
||||
let suggestions = vec![lifetime_sugg, new_param_sugg];
|
||||
|
||||
diag.span_label(
|
||||
lifetime_ref.ident.span,
|
||||
@@ -1378,7 +1387,9 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
||||
Scope::Root { opt_parent_item } => {
|
||||
if let Some(parent_item) = opt_parent_item
|
||||
&& let parent_generics = self.tcx.generics_of(parent_item)
|
||||
&& parent_generics.param_def_id_to_index(self.tcx, param_def_id.to_def_id()).is_some()
|
||||
&& parent_generics
|
||||
.param_def_id_to_index(self.tcx, param_def_id.to_def_id())
|
||||
.is_some()
|
||||
{
|
||||
break Some(ResolvedArg::EarlyBound(param_def_id.to_def_id()));
|
||||
}
|
||||
@@ -1689,14 +1700,12 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
||||
if binding.gen_args.parenthesized == hir::GenericArgsParentheses::ReturnTypeNotation {
|
||||
let bound_vars = if let Some(type_def_id) = type_def_id
|
||||
&& self.tcx.def_kind(type_def_id) == DefKind::Trait
|
||||
&& let Some((mut bound_vars, assoc_fn)) =
|
||||
BoundVarContext::supertrait_hrtb_vars(
|
||||
self.tcx,
|
||||
type_def_id,
|
||||
binding.ident,
|
||||
ty::AssocKind::Fn,
|
||||
)
|
||||
{
|
||||
&& let Some((mut bound_vars, assoc_fn)) = BoundVarContext::supertrait_hrtb_vars(
|
||||
self.tcx,
|
||||
type_def_id,
|
||||
binding.ident,
|
||||
ty::AssocKind::Fn,
|
||||
) {
|
||||
bound_vars.extend(self.tcx.generics_of(assoc_fn.def_id).params.iter().map(
|
||||
|param| match param.kind {
|
||||
ty::GenericParamDefKind::Lifetime => ty::BoundVariableKind::Region(
|
||||
@@ -1708,14 +1717,14 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
||||
ty::GenericParamDefKind::Const { .. } => ty::BoundVariableKind::Const,
|
||||
},
|
||||
));
|
||||
bound_vars
|
||||
.extend(self.tcx.fn_sig(assoc_fn.def_id).instantiate_identity().bound_vars());
|
||||
bound_vars.extend(
|
||||
self.tcx.fn_sig(assoc_fn.def_id).instantiate_identity().bound_vars(),
|
||||
);
|
||||
bound_vars
|
||||
} else {
|
||||
self.tcx.sess.delay_span_bug(
|
||||
binding.ident.span,
|
||||
"bad return type notation here",
|
||||
);
|
||||
self.tcx
|
||||
.sess
|
||||
.delay_span_bug(binding.ident.span, "bad return type notation here");
|
||||
vec![]
|
||||
};
|
||||
self.with(scope, |this| {
|
||||
|
||||
@@ -30,10 +30,10 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
||||
| Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. })
|
||||
if constant.hir_id() == hir_id =>
|
||||
{
|
||||
return tcx.types.usize
|
||||
return tcx.types.usize;
|
||||
}
|
||||
Node::Ty(&hir::Ty { kind: TyKind::Typeof(ref e), .. }) if e.hir_id == hir_id => {
|
||||
return tcx.typeck(def_id).node_type(e.hir_id)
|
||||
return tcx.typeck(def_id).node_type(e.hir_id);
|
||||
}
|
||||
Node::Expr(&Expr { kind: ExprKind::InlineAsm(asm), .. })
|
||||
| Node::Item(&Item { kind: ItemKind::GlobalAsm(asm), .. })
|
||||
@@ -43,36 +43,38 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
||||
_ => false,
|
||||
}) =>
|
||||
{
|
||||
return tcx.typeck(def_id).node_type(hir_id)
|
||||
return tcx.typeck(def_id).node_type(hir_id);
|
||||
}
|
||||
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => {
|
||||
return tcx
|
||||
.adt_def(tcx.hir().get_parent_item(hir_id))
|
||||
.repr()
|
||||
.discr_type()
|
||||
.to_ty(tcx)
|
||||
return tcx.adt_def(tcx.hir().get_parent_item(hir_id)).repr().discr_type().to_ty(tcx);
|
||||
}
|
||||
Node::GenericParam(&GenericParam {
|
||||
def_id: param_def_id,
|
||||
kind: GenericParamKind::Const { default: Some(ct), .. },
|
||||
..
|
||||
}) if ct.hir_id == hir_id => {
|
||||
return tcx.type_of(param_def_id)
|
||||
return tcx
|
||||
.type_of(param_def_id)
|
||||
.no_bound_vars()
|
||||
.expect("const parameter types cannot be generic")
|
||||
.expect("const parameter types cannot be generic");
|
||||
}
|
||||
|
||||
Node::TypeBinding(binding @ &TypeBinding { hir_id: binding_id, .. })
|
||||
if let Node::TraitRef(trait_ref) = tcx.hir().get(
|
||||
tcx.hir().parent_id(binding_id)
|
||||
) =>
|
||||
Node::TypeBinding(binding @ &TypeBinding { hir_id: binding_id, .. })
|
||||
if let Node::TraitRef(trait_ref) = tcx.hir().get(tcx.hir().parent_id(binding_id)) =>
|
||||
{
|
||||
let Some(trait_def_id) = trait_ref.trait_def_id() else {
|
||||
return Ty::new_error_with_message(tcx,tcx.def_span(def_id), "Could not find trait");
|
||||
return Ty::new_error_with_message(
|
||||
tcx,
|
||||
tcx.def_span(def_id),
|
||||
"Could not find trait",
|
||||
);
|
||||
};
|
||||
let assoc_items = tcx.associated_items(trait_def_id);
|
||||
let assoc_item = assoc_items.find_by_name_and_kind(
|
||||
tcx, binding.ident, ty::AssocKind::Const, def_id.to_def_id(),
|
||||
tcx,
|
||||
binding.ident,
|
||||
ty::AssocKind::Const,
|
||||
def_id.to_def_id(),
|
||||
);
|
||||
return if let Some(assoc_item) = assoc_item {
|
||||
tcx.type_of(assoc_item.def_id)
|
||||
@@ -80,8 +82,12 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
||||
.expect("const parameter types cannot be generic")
|
||||
} else {
|
||||
// FIXME(associated_const_equality): add a useful error message here.
|
||||
Ty::new_error_with_message(tcx,tcx.def_span(def_id), "Could not find associated const on trait")
|
||||
}
|
||||
Ty::new_error_with_message(
|
||||
tcx,
|
||||
tcx.def_span(def_id),
|
||||
"Could not find associated const on trait",
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
// This match arm is for when the def_id appears in a GAT whose
|
||||
@@ -138,7 +144,8 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
||||
(generics, arg_index)
|
||||
} else {
|
||||
// I dont think it's possible to reach this but I'm not 100% sure - BoxyUwU
|
||||
return Ty::new_error_with_message(tcx,
|
||||
return Ty::new_error_with_message(
|
||||
tcx,
|
||||
tcx.def_span(def_id),
|
||||
"unexpected non-GAT usage of an anon const",
|
||||
);
|
||||
@@ -155,7 +162,8 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
||||
// As there is no relevant param for `def_id`, we simply return
|
||||
// `None` here.
|
||||
let Some(type_dependent_def) = tables.type_dependent_def_id(parent_node_id) else {
|
||||
return Ty::new_error_with_message(tcx,
|
||||
return Ty::new_error_with_message(
|
||||
tcx,
|
||||
tcx.def_span(def_id),
|
||||
format!("unable to find type-dependent def for {parent_node_id:?}"),
|
||||
);
|
||||
@@ -196,14 +204,16 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
||||
if let Some(path) = get_path_containing_arg_in_pat(pat, hir_id) {
|
||||
path
|
||||
} else {
|
||||
return Ty::new_error_with_message(tcx,
|
||||
return Ty::new_error_with_message(
|
||||
tcx,
|
||||
tcx.def_span(def_id),
|
||||
format!("unable to find const parent for {hir_id} in pat {pat:?}"),
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Ty::new_error_with_message(tcx,
|
||||
return Ty::new_error_with_message(
|
||||
tcx,
|
||||
tcx.def_span(def_id),
|
||||
format!("unexpected const parent path {parent_node:?}"),
|
||||
);
|
||||
@@ -216,16 +226,20 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
||||
let Some((arg_index, segment)) = path.segments.iter().find_map(|seg| {
|
||||
let args = seg.args?;
|
||||
args.args
|
||||
.iter()
|
||||
.filter(|arg| arg.is_ty_or_const())
|
||||
.position(|arg| arg.hir_id() == hir_id)
|
||||
.map(|index| (index, seg)).or_else(|| args.bindings
|
||||
.iter()
|
||||
.filter_map(TypeBinding::opt_const)
|
||||
.position(|ct| ct.hir_id == hir_id)
|
||||
.map(|idx| (idx, seg)))
|
||||
.filter(|arg| arg.is_ty_or_const())
|
||||
.position(|arg| arg.hir_id() == hir_id)
|
||||
.map(|index| (index, seg))
|
||||
.or_else(|| {
|
||||
args.bindings
|
||||
.iter()
|
||||
.filter_map(TypeBinding::opt_const)
|
||||
.position(|ct| ct.hir_id == hir_id)
|
||||
.map(|idx| (idx, seg))
|
||||
})
|
||||
}) else {
|
||||
return Ty::new_error_with_message(tcx,
|
||||
return Ty::new_error_with_message(
|
||||
tcx,
|
||||
tcx.def_span(def_id),
|
||||
"no arg matching AnonConst in path",
|
||||
);
|
||||
@@ -234,7 +248,8 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
||||
let generics = match tcx.res_generics_def_id(segment.res) {
|
||||
Some(def_id) => tcx.generics_of(def_id),
|
||||
None => {
|
||||
return Ty::new_error_with_message(tcx,
|
||||
return Ty::new_error_with_message(
|
||||
tcx,
|
||||
tcx.def_span(def_id),
|
||||
format!("unexpected anon const res {:?} in path: {:?}", segment.res, path),
|
||||
);
|
||||
@@ -244,10 +259,13 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
||||
(generics, arg_index)
|
||||
}
|
||||
|
||||
_ => return Ty::new_error_with_message(tcx,
|
||||
tcx.def_span(def_id),
|
||||
format!("unexpected const parent in type_of(): {parent_node:?}"),
|
||||
),
|
||||
_ => {
|
||||
return Ty::new_error_with_message(
|
||||
tcx,
|
||||
tcx.def_span(def_id),
|
||||
format!("unexpected const parent in type_of(): {parent_node:?}"),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
debug!(?parent_node);
|
||||
|
||||
Reference in New Issue
Block a user