1
Fork 0

rustc_hir_analysis: remove ref patterns

This commit is contained in:
Maybe Waffle 2023-01-09 16:30:40 +00:00
parent d60e772e14
commit 09485eaae1
19 changed files with 161 additions and 168 deletions

View file

@ -569,17 +569,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.bindings .bindings
.iter() .iter()
.map(|binding| { .map(|binding| {
let kind = match binding.kind { let kind = match &binding.kind {
hir::TypeBindingKind::Equality { ref term } => match term { hir::TypeBindingKind::Equality { term } => match term {
hir::Term::Ty(ref ty) => { hir::Term::Ty(ty) => {
ConvertedBindingKind::Equality(self.ast_ty_to_ty(ty).into()) ConvertedBindingKind::Equality(self.ast_ty_to_ty(ty).into())
} }
hir::Term::Const(ref c) => { hir::Term::Const(c) => {
let c = Const::from_anon_const(self.tcx(), c.def_id); let c = Const::from_anon_const(self.tcx(), c.def_id);
ConvertedBindingKind::Equality(c.into()) ConvertedBindingKind::Equality(c.into())
} }
}, },
hir::TypeBindingKind::Constraint { ref bounds } => { hir::TypeBindingKind::Constraint { bounds } => {
ConvertedBindingKind::Constraint(bounds) ConvertedBindingKind::Constraint(bounds)
} }
}; };
@ -1928,7 +1928,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed> { ) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed> {
let tcx = self.tcx(); let tcx = self.tcx();
let assoc_ident = assoc_segment.ident; let assoc_ident = assoc_segment.ident;
let qself_res = if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = qself.kind { let qself_res = if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = &qself.kind {
path.res path.res
} else { } else {
Res::Err Res::Err
@ -1971,8 +1971,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
return; return;
}; };
let (qself_sugg_span, is_self) = if let hir::TyKind::Path( let (qself_sugg_span, is_self) = if let hir::TyKind::Path(
hir::QPath::Resolved(_, ref path) hir::QPath::Resolved(_, path)
) = qself.kind { ) = &qself.kind {
// If the path segment already has type params, we want to overwrite // If the path segment already has type params, we want to overwrite
// them. // them.
match &path.segments[..] { match &path.segments[..] {
@ -2760,7 +2760,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
"generic `Self` types are currently not permitted in anonymous constants", "generic `Self` types are currently not permitted in anonymous constants",
); );
if let Some(hir::Node::Item(&hir::Item { if let Some(hir::Node::Item(&hir::Item {
kind: hir::ItemKind::Impl(ref impl_), kind: hir::ItemKind::Impl(impl_),
.. ..
})) = tcx.hir().get_if_local(def_id) })) = tcx.hir().get_if_local(def_id)
{ {
@ -2843,12 +2843,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
fn ast_ty_to_ty_inner(&self, ast_ty: &hir::Ty<'_>, borrowed: bool, in_path: bool) -> Ty<'tcx> { fn ast_ty_to_ty_inner(&self, ast_ty: &hir::Ty<'_>, borrowed: bool, in_path: bool) -> Ty<'tcx> {
let tcx = self.tcx(); let tcx = self.tcx();
let result_ty = match ast_ty.kind { let result_ty = match &ast_ty.kind {
hir::TyKind::Slice(ref ty) => tcx.mk_slice(self.ast_ty_to_ty(ty)), hir::TyKind::Slice(ty) => tcx.mk_slice(self.ast_ty_to_ty(ty)),
hir::TyKind::Ptr(ref mt) => { hir::TyKind::Ptr(mt) => {
tcx.mk_ptr(ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl }) tcx.mk_ptr(ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl })
} }
hir::TyKind::Ref(ref region, ref mt) => { hir::TyKind::Ref(region, mt) => {
let r = self.ast_region_to_region(region, None); let r = self.ast_region_to_region(region, None);
debug!(?r); debug!(?r);
let t = self.ast_ty_to_ty_inner(mt.ty, true, false); let t = self.ast_ty_to_ty_inner(mt.ty, true, false);
@ -2868,7 +2868,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
Some(ast_ty), Some(ast_ty),
)) ))
} }
hir::TyKind::TraitObject(bounds, ref lifetime, repr) => { hir::TyKind::TraitObject(bounds, lifetime, repr) => {
self.maybe_lint_bare_trait(ast_ty, in_path); self.maybe_lint_bare_trait(ast_ty, in_path);
let repr = match repr { let repr = match repr {
TraitObjectSyntax::Dyn | TraitObjectSyntax::None => ty::Dyn, TraitObjectSyntax::Dyn | TraitObjectSyntax::None => ty::Dyn,
@ -2876,30 +2876,30 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}; };
self.conv_object_ty_poly_trait_ref(ast_ty.span, bounds, lifetime, borrowed, repr) self.conv_object_ty_poly_trait_ref(ast_ty.span, bounds, lifetime, borrowed, repr)
} }
hir::TyKind::Path(hir::QPath::Resolved(ref maybe_qself, ref path)) => { hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
debug!(?maybe_qself, ?path); debug!(?maybe_qself, ?path);
let opt_self_ty = maybe_qself.as_ref().map(|qself| self.ast_ty_to_ty(qself)); let opt_self_ty = maybe_qself.as_ref().map(|qself| self.ast_ty_to_ty(qself));
self.res_to_ty(opt_self_ty, path, false) self.res_to_ty(opt_self_ty, path, false)
} }
hir::TyKind::OpaqueDef(item_id, lifetimes, in_trait) => { hir::TyKind::OpaqueDef(item_id, lifetimes, in_trait) => {
let opaque_ty = tcx.hir().item(item_id); let opaque_ty = tcx.hir().item(*item_id);
let def_id = item_id.owner_id.to_def_id(); let def_id = item_id.owner_id.to_def_id();
match opaque_ty.kind { match opaque_ty.kind {
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => { hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => {
self.impl_trait_ty_to_ty(def_id, lifetimes, origin, in_trait) self.impl_trait_ty_to_ty(def_id, lifetimes, origin, *in_trait)
} }
ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i), ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i),
} }
} }
hir::TyKind::Path(hir::QPath::TypeRelative(ref qself, ref segment)) => { hir::TyKind::Path(hir::QPath::TypeRelative(qself, segment)) => {
debug!(?qself, ?segment); debug!(?qself, ?segment);
let ty = self.ast_ty_to_ty_inner(qself, false, true); let ty = self.ast_ty_to_ty_inner(qself, false, true);
self.associated_path_to_ty(ast_ty.hir_id, ast_ty.span, ty, qself, segment, false) self.associated_path_to_ty(ast_ty.hir_id, ast_ty.span, ty, qself, segment, false)
.map(|(ty, _, _)| ty) .map(|(ty, _, _)| ty)
.unwrap_or_else(|_| tcx.ty_error()) .unwrap_or_else(|_| tcx.ty_error())
} }
hir::TyKind::Path(hir::QPath::LangItem(lang_item, span, _)) => { &hir::TyKind::Path(hir::QPath::LangItem(lang_item, span, _)) => {
let def_id = tcx.require_lang_item(lang_item, Some(span)); let def_id = tcx.require_lang_item(lang_item, Some(span));
let (substs, _) = self.create_substs_for_ast_path( let (substs, _) = self.create_substs_for_ast_path(
span, span,
@ -2913,7 +2913,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
); );
EarlyBinder(tcx.at(span).type_of(def_id)).subst(tcx, substs) EarlyBinder(tcx.at(span).type_of(def_id)).subst(tcx, substs)
} }
hir::TyKind::Array(ref ty, ref length) => { hir::TyKind::Array(ty, length) => {
let length = match length { let length = match length {
&hir::ArrayLen::Infer(_, span) => self.ct_infer(tcx.types.usize, None, span), &hir::ArrayLen::Infer(_, span) => self.ct_infer(tcx.types.usize, None, span),
hir::ArrayLen::Body(constant) => { hir::ArrayLen::Body(constant) => {
@ -2923,7 +2923,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.mk_ty(ty::Array(self.ast_ty_to_ty(ty), length)) tcx.mk_ty(ty::Array(self.ast_ty_to_ty(ty), length))
} }
hir::TyKind::Typeof(ref e) => { hir::TyKind::Typeof(e) => {
let ty_erased = tcx.type_of(e.def_id); let ty_erased = tcx.type_of(e.def_id);
let ty = tcx.fold_regions(ty_erased, |r, _| { let ty = tcx.fold_regions(ty_erased, |r, _| {
if r.is_erased() { tcx.lifetimes.re_static } else { r } if r.is_erased() { tcx.lifetimes.re_static } else { r }

View file

@ -531,9 +531,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
DefKind::Fn => {} // entirely within check_item_body DefKind::Fn => {} // entirely within check_item_body
DefKind::Impl => { DefKind::Impl => {
let it = tcx.hir().item(id); let it = tcx.hir().item(id);
let hir::ItemKind::Impl(ref impl_) = it.kind else { let hir::ItemKind::Impl(impl_) = it.kind else { return };
return;
};
debug!("ItemKind::Impl {} with id {:?}", it.ident, it.owner_id); debug!("ItemKind::Impl {} with id {:?}", it.ident, it.owner_id);
if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.owner_id) { if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.owner_id) {
check_impl_items_against_trait( check_impl_items_against_trait(
@ -548,15 +546,15 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
} }
DefKind::Trait => { DefKind::Trait => {
let it = tcx.hir().item(id); let it = tcx.hir().item(id);
let hir::ItemKind::Trait(_, _, _, _, ref items) = it.kind else { let hir::ItemKind::Trait(_, _, _, _, items) = it.kind else {
return; return;
}; };
check_on_unimplemented(tcx, it); check_on_unimplemented(tcx, it);
for item in items.iter() { for item in items.iter() {
let item = tcx.hir().trait_item(item.id); let item = tcx.hir().trait_item(item.id);
match item.kind { match &item.kind {
hir::TraitItemKind::Fn(ref sig, _) => { hir::TraitItemKind::Fn(sig, _) => {
let abi = sig.header.abi; let abi = sig.header.abi;
fn_maybe_err(tcx, item.ident.span, abi); fn_maybe_err(tcx, item.ident.span, abi);
} }
@ -652,8 +650,8 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
} }
let item = tcx.hir().foreign_item(item.id); let item = tcx.hir().foreign_item(item.id);
match item.kind { match &item.kind {
hir::ForeignItemKind::Fn(ref fn_decl, _, _) => { hir::ForeignItemKind::Fn(fn_decl, _, _) => {
require_c_abi_if_c_variadic(tcx, fn_decl, abi, item.span); require_c_abi_if_c_variadic(tcx, fn_decl, abi, item.span);
} }
hir::ForeignItemKind::Static(..) => { hir::ForeignItemKind::Static(..) => {

View file

@ -1513,8 +1513,7 @@ fn compare_synthetic_generics<'tcx>(
impl<'v> intravisit::Visitor<'v> for Visitor { impl<'v> intravisit::Visitor<'v> for Visitor {
fn visit_ty(&mut self, ty: &'v hir::Ty<'v>) { fn visit_ty(&mut self, ty: &'v hir::Ty<'v>) {
intravisit::walk_ty(self, ty); intravisit::walk_ty(self, ty);
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = if let hir::TyKind::Path(hir::QPath::Resolved(None, path)) = ty.kind
ty.kind
&& let Res::Def(DefKind::TyParam, def_id) = path.res && let Res::Def(DefKind::TyParam, def_id) = path.res
&& def_id == self.1.to_def_id() && def_id == self.1.to_def_id()
{ {

View file

@ -351,7 +351,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
} }
match *op { match *op {
hir::InlineAsmOperand::In { reg, ref expr } => { hir::InlineAsmOperand::In { reg, expr } => {
self.check_asm_operand_type( self.check_asm_operand_type(
idx, idx,
reg, reg,
@ -362,7 +362,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
&target_features, &target_features,
); );
} }
hir::InlineAsmOperand::Out { reg, late: _, ref expr } => { hir::InlineAsmOperand::Out { reg, late: _, expr } => {
if let Some(expr) = expr { if let Some(expr) = expr {
self.check_asm_operand_type( self.check_asm_operand_type(
idx, idx,
@ -375,7 +375,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
); );
} }
} }
hir::InlineAsmOperand::InOut { reg, late: _, ref expr } => { hir::InlineAsmOperand::InOut { reg, late: _, expr } => {
self.check_asm_operand_type( self.check_asm_operand_type(
idx, idx,
reg, reg,
@ -386,7 +386,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
&target_features, &target_features,
); );
} }
hir::InlineAsmOperand::SplitInOut { reg, late: _, ref in_expr, ref out_expr } => { hir::InlineAsmOperand::SplitInOut { reg, late: _, in_expr, out_expr } => {
let in_ty = self.check_asm_operand_type( let in_ty = self.check_asm_operand_type(
idx, idx,
reg, reg,

View file

@ -180,7 +180,7 @@ fn resolve_arm<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, arm: &'tcx hir
visitor.terminating_scopes.insert(arm.body.hir_id.local_id); visitor.terminating_scopes.insert(arm.body.hir_id.local_id);
if let Some(hir::Guard::If(ref expr)) = arm.guard { if let Some(hir::Guard::If(expr)) = arm.guard {
visitor.terminating_scopes.insert(expr.hir_id.local_id); visitor.terminating_scopes.insert(expr.hir_id.local_id);
} }
@ -242,8 +242,8 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
// This ensures fixed size stacks. // This ensures fixed size stacks.
hir::ExprKind::Binary( hir::ExprKind::Binary(
source_map::Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. }, source_map::Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. },
ref l, l,
ref r, r,
) => { ) => {
// expr is a short circuiting operator (|| or &&). As its // expr is a short circuiting operator (|| or &&). As its
// functionality can't be overridden by traits, it always // functionality can't be overridden by traits, it always
@ -288,20 +288,20 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
terminating(r.hir_id.local_id); terminating(r.hir_id.local_id);
} }
} }
hir::ExprKind::If(_, ref then, Some(ref otherwise)) => { hir::ExprKind::If(_, then, Some(otherwise)) => {
terminating(then.hir_id.local_id); terminating(then.hir_id.local_id);
terminating(otherwise.hir_id.local_id); terminating(otherwise.hir_id.local_id);
} }
hir::ExprKind::If(_, ref then, None) => { hir::ExprKind::If(_, then, None) => {
terminating(then.hir_id.local_id); terminating(then.hir_id.local_id);
} }
hir::ExprKind::Loop(ref body, _, _, _) => { hir::ExprKind::Loop(body, _, _, _) => {
terminating(body.hir_id.local_id); terminating(body.hir_id.local_id);
} }
hir::ExprKind::DropTemps(ref expr) => { hir::ExprKind::DropTemps(expr) => {
// `DropTemps(expr)` does not denote a conditional scope. // `DropTemps(expr)` does not denote a conditional scope.
// Rather, we want to achieve the same behavior as `{ let _t = expr; _t }`. // Rather, we want to achieve the same behavior as `{ let _t = expr; _t }`.
terminating(expr.hir_id.local_id); terminating(expr.hir_id.local_id);
@ -396,7 +396,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
let body = visitor.tcx.hir().body(body); let body = visitor.tcx.hir().body(body);
visitor.visit_body(body); visitor.visit_body(body);
} }
hir::ExprKind::AssignOp(_, ref left_expr, ref right_expr) => { hir::ExprKind::AssignOp(_, left_expr, right_expr) => {
debug!( debug!(
"resolve_expr - enabling pessimistic_yield, was previously {}", "resolve_expr - enabling pessimistic_yield, was previously {}",
prev_pessimistic prev_pessimistic
@ -447,7 +447,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
} }
} }
hir::ExprKind::If(ref cond, ref then, Some(ref otherwise)) => { hir::ExprKind::If(cond, then, Some(otherwise)) => {
let expr_cx = visitor.cx; let expr_cx = visitor.cx;
visitor.enter_scope(Scope { id: then.hir_id.local_id, data: ScopeData::IfThen }); visitor.enter_scope(Scope { id: then.hir_id.local_id, data: ScopeData::IfThen });
visitor.cx.var_parent = visitor.cx.parent; visitor.cx.var_parent = visitor.cx.parent;
@ -457,7 +457,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
visitor.visit_expr(otherwise); visitor.visit_expr(otherwise);
} }
hir::ExprKind::If(ref cond, ref then, None) => { hir::ExprKind::If(cond, then, None) => {
let expr_cx = visitor.cx; let expr_cx = visitor.cx;
visitor.enter_scope(Scope { id: then.hir_id.local_id, data: ScopeData::IfThen }); visitor.enter_scope(Scope { id: then.hir_id.local_id, data: ScopeData::IfThen });
visitor.cx.var_parent = visitor.cx.parent; visitor.cx.var_parent = visitor.cx.parent;
@ -641,21 +641,21 @@ fn resolve_local<'tcx>(
match pat.kind { match pat.kind {
PatKind::Binding(hir::BindingAnnotation(hir::ByRef::Yes, _), ..) => true, PatKind::Binding(hir::BindingAnnotation(hir::ByRef::Yes, _), ..) => true,
PatKind::Struct(_, ref field_pats, _) => { PatKind::Struct(_, field_pats, _) => {
field_pats.iter().any(|fp| is_binding_pat(&fp.pat)) field_pats.iter().any(|fp| is_binding_pat(&fp.pat))
} }
PatKind::Slice(ref pats1, ref pats2, ref pats3) => { PatKind::Slice(pats1, pats2, pats3) => {
pats1.iter().any(|p| is_binding_pat(&p)) pats1.iter().any(|p| is_binding_pat(&p))
|| pats2.iter().any(|p| is_binding_pat(&p)) || pats2.iter().any(|p| is_binding_pat(&p))
|| pats3.iter().any(|p| is_binding_pat(&p)) || pats3.iter().any(|p| is_binding_pat(&p))
} }
PatKind::Or(ref subpats) PatKind::Or(subpats)
| PatKind::TupleStruct(_, ref subpats, _) | PatKind::TupleStruct(_, subpats, _)
| PatKind::Tuple(ref subpats, _) => subpats.iter().any(|p| is_binding_pat(&p)), | PatKind::Tuple(subpats, _) => subpats.iter().any(|p| is_binding_pat(&p)),
PatKind::Box(ref subpat) => is_binding_pat(&subpat), PatKind::Box(subpat) => is_binding_pat(&subpat),
PatKind::Ref(_, _) PatKind::Ref(_, _)
| PatKind::Binding(hir::BindingAnnotation(hir::ByRef::No, _), ..) | PatKind::Binding(hir::BindingAnnotation(hir::ByRef::No, _), ..)
@ -704,11 +704,11 @@ fn resolve_local<'tcx>(
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id); record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id);
} }
} }
hir::ExprKind::Cast(ref subexpr, _) => { hir::ExprKind::Cast(subexpr, _) => {
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id) record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id)
} }
hir::ExprKind::Block(ref block, _) => { hir::ExprKind::Block(block, _) => {
if let Some(ref subexpr) = block.expr { if let Some(subexpr) = block.expr {
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id); record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id);
} }
} }

View file

@ -178,7 +178,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
// //
// won't be allowed unless there's an *explicit* implementation of `Send` // won't be allowed unless there's an *explicit* implementation of `Send`
// for `T` // for `T`
hir::ItemKind::Impl(ref impl_) => { hir::ItemKind::Impl(impl_) => {
let is_auto = tcx let is_auto = tcx
.impl_trait_ref(def_id) .impl_trait_ref(def_id)
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.skip_binder().def_id)); .map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.skip_binder().def_id));
@ -224,15 +224,15 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
hir::ItemKind::Const(ty, ..) => { hir::ItemKind::Const(ty, ..) => {
check_item_type(tcx, def_id, ty.span, false); check_item_type(tcx, def_id, ty.span, false);
} }
hir::ItemKind::Struct(_, ref ast_generics) => { hir::ItemKind::Struct(_, ast_generics) => {
check_type_defn(tcx, item, false); check_type_defn(tcx, item, false);
check_variances_for_type_defn(tcx, item, ast_generics); check_variances_for_type_defn(tcx, item, ast_generics);
} }
hir::ItemKind::Union(_, ref ast_generics) => { hir::ItemKind::Union(_, ast_generics) => {
check_type_defn(tcx, item, true); check_type_defn(tcx, item, true);
check_variances_for_type_defn(tcx, item, ast_generics); check_variances_for_type_defn(tcx, item, ast_generics);
} }
hir::ItemKind::Enum(_, ref ast_generics) => { hir::ItemKind::Enum(_, ast_generics) => {
check_type_defn(tcx, item, true); check_type_defn(tcx, item, true);
check_variances_for_type_defn(tcx, item, ast_generics); check_variances_for_type_defn(tcx, item, ast_generics);
} }
@ -1247,8 +1247,8 @@ fn check_impl<'tcx>(
constness: hir::Constness, constness: hir::Constness,
) { ) {
enter_wf_checking_ctxt(tcx, item.span, item.owner_id.def_id, |wfcx| { enter_wf_checking_ctxt(tcx, item.span, item.owner_id.def_id, |wfcx| {
match *ast_trait_ref { match ast_trait_ref {
Some(ref ast_trait_ref) => { Some(ast_trait_ref) => {
// `#[rustc_reservation_impl]` impls are not real impls and // `#[rustc_reservation_impl]` impls are not real impls and
// therefore don't need to be WF (the trait's `Self: Trait` predicate // therefore don't need to be WF (the trait's `Self: Trait` predicate
// won't hold). // won't hold).

View file

@ -502,12 +502,11 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
return err_info; return err_info;
} else if diff_fields.len() > 1 { } else if diff_fields.len() > 1 {
let item = tcx.hir().expect_item(impl_did); let item = tcx.hir().expect_item(impl_did);
let span = let span = if let ItemKind::Impl(hir::Impl { of_trait: Some(t), .. }) = &item.kind {
if let ItemKind::Impl(hir::Impl { of_trait: Some(ref t), .. }) = item.kind { t.path.span
t.path.span } else {
} else { tcx.def_span(impl_did)
tcx.def_span(impl_did) };
};
struct_span_err!( struct_span_err!(
tcx.sess, tcx.sess,

View file

@ -182,7 +182,7 @@ impl<'tcx> InherentCollect<'tcx> {
} }
let item = self.tcx.hir().item(id); let item = self.tcx.hir().item(id);
let hir::ItemKind::Impl(hir::Impl { of_trait: None, self_ty: ty, ref items, .. }) = item.kind else { let hir::ItemKind::Impl(hir::Impl { of_trait: None, self_ty: ty, items, .. }) = item.kind else {
return; return;
}; };

View file

@ -40,7 +40,7 @@ fn do_orphan_check_impl<'tcx>(
let trait_def_id = trait_ref.def_id; let trait_def_id = trait_ref.def_id;
let item = tcx.hir().expect_item(def_id); let item = tcx.hir().expect_item(def_id);
let hir::ItemKind::Impl(ref impl_) = item.kind else { let hir::ItemKind::Impl(impl_) = item.kind else {
bug!("{:?} is not an impl: {:?}", def_id, item); bug!("{:?} is not an impl: {:?}", def_id, item);
}; };
let sp = tcx.def_span(def_id); let sp = tcx.def_span(def_id);

View file

@ -11,7 +11,7 @@ use rustc_span::def_id::LocalDefId;
pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) { pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
debug_assert!(matches!(tcx.def_kind(def_id), DefKind::Impl)); debug_assert!(matches!(tcx.def_kind(def_id), DefKind::Impl));
let item = tcx.hir().expect_item(def_id); let item = tcx.hir().expect_item(def_id);
let hir::ItemKind::Impl(ref impl_) = item.kind else { bug!() }; let hir::ItemKind::Impl(impl_) = item.kind else { bug!() };
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) { if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
let trait_ref = trait_ref.subst_identity(); let trait_ref = trait_ref.subst_identity();

View file

@ -560,7 +560,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
debug!("convert: item {} with id {}", it.ident, it.hir_id()); debug!("convert: item {} with id {}", it.ident, it.hir_id());
let def_id = item_id.owner_id.def_id; let def_id = item_id.owner_id.def_id;
match it.kind { match &it.kind {
// These don't define types. // These don't define types.
hir::ItemKind::ExternCrate(_) hir::ItemKind::ExternCrate(_)
| hir::ItemKind::Use(..) | hir::ItemKind::Use(..)
@ -568,7 +568,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
| hir::ItemKind::Mod(_) | hir::ItemKind::Mod(_)
| hir::ItemKind::GlobalAsm(_) => {} | hir::ItemKind::GlobalAsm(_) => {}
hir::ItemKind::ForeignMod { items, .. } => { hir::ItemKind::ForeignMod { items, .. } => {
for item in items { for item in *items {
let item = tcx.hir().foreign_item(item.id); let item = tcx.hir().foreign_item(item.id);
tcx.ensure().generics_of(item.owner_id); tcx.ensure().generics_of(item.owner_id);
tcx.ensure().type_of(item.owner_id); tcx.ensure().type_of(item.owner_id);
@ -618,7 +618,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
tcx.at(it.span).super_predicates_of(def_id); tcx.at(it.span).super_predicates_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure().predicates_of(def_id);
} }
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { hir::ItemKind::Struct(struct_def, _) | hir::ItemKind::Union(struct_def, _) => {
tcx.ensure().generics_of(def_id); tcx.ensure().generics_of(def_id);
tcx.ensure().type_of(def_id); tcx.ensure().type_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure().predicates_of(def_id);
@ -853,14 +853,14 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AdtDef<'_> {
}; };
let repr = tcx.repr_options_of_def(def_id.to_def_id()); let repr = tcx.repr_options_of_def(def_id.to_def_id());
let (kind, variants) = match item.kind { let (kind, variants) = match &item.kind {
ItemKind::Enum(ref def, _) => { ItemKind::Enum(def, _) => {
let mut distance_from_explicit = 0; let mut distance_from_explicit = 0;
let variants = def let variants = def
.variants .variants
.iter() .iter()
.map(|v| { .map(|v| {
let discr = if let Some(ref e) = v.disr_expr { let discr = if let Some(e) = &v.disr_expr {
distance_from_explicit = 0; distance_from_explicit = 0;
ty::VariantDiscr::Explicit(e.def_id.to_def_id()) ty::VariantDiscr::Explicit(e.def_id.to_def_id())
} else { } else {
@ -882,7 +882,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AdtDef<'_> {
(AdtKind::Enum, variants) (AdtKind::Enum, variants)
} }
ItemKind::Struct(ref def, _) | ItemKind::Union(ref def, _) => { ItemKind::Struct(def, _) | ItemKind::Union(def, _) => {
let adt_kind = match item.kind { let adt_kind = match item.kind {
ItemKind::Struct(..) => AdtKind::Struct, ItemKind::Struct(..) => AdtKind::Struct,
_ => AdtKind::Union, _ => AdtKind::Union,
@ -1509,7 +1509,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
for (input, ty) in iter::zip(decl.inputs, fty.inputs().skip_binder()) { for (input, ty) in iter::zip(decl.inputs, fty.inputs().skip_binder()) {
check(input, *ty) check(input, *ty)
} }
if let hir::FnRetTy::Return(ref ty) = decl.output { if let hir::FnRetTy::Return(ty) = decl.output {
check(ty, fty.output().skip_binder()) check(ty, fty.output().skip_binder())
} }
} }

View file

@ -110,12 +110,12 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
// expressions' count (i.e. `N` in `[x; N]`), and explicit // expressions' count (i.e. `N` in `[x; N]`), and explicit
// `enum` discriminants (i.e. `D` in `enum Foo { Bar = D }`), // `enum` discriminants (i.e. `D` in `enum Foo { Bar = D }`),
// as they shouldn't be able to cause query cycle errors. // as they shouldn't be able to cause query cycle errors.
Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. }) Node::Expr(Expr { kind: ExprKind::Repeat(_, constant), .. })
if constant.hir_id() == hir_id => if constant.hir_id() == hir_id =>
{ {
Some(parent_def_id.to_def_id()) Some(parent_def_id.to_def_id())
} }
Node::Variant(Variant { disr_expr: Some(ref constant), .. }) Node::Variant(Variant { disr_expr: Some(constant), .. })
if constant.hir_id == hir_id => if constant.hir_id == hir_id =>
{ {
Some(parent_def_id.to_def_id()) Some(parent_def_id.to_def_id())
@ -259,7 +259,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
params.extend(ast_generics.params.iter().filter_map(|param| match param.kind { params.extend(ast_generics.params.iter().filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => None, GenericParamKind::Lifetime { .. } => None,
GenericParamKind::Type { ref default, synthetic, .. } => { GenericParamKind::Type { default, synthetic, .. } => {
if default.is_some() { if default.is_some() {
match allow_defaults { match allow_defaults {
Defaults::Allowed => {} Defaults::Allowed => {}
@ -426,26 +426,22 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
} }
match node { match node {
Node::TraitItem(item) => match item.kind { Node::TraitItem(item) => match &item.kind {
hir::TraitItemKind::Fn(ref sig, _) => { hir::TraitItemKind::Fn(sig, _) => has_late_bound_regions(tcx, &item.generics, sig.decl),
has_late_bound_regions(tcx, &item.generics, sig.decl)
}
_ => None, _ => None,
}, },
Node::ImplItem(item) => match item.kind { Node::ImplItem(item) => match &item.kind {
hir::ImplItemKind::Fn(ref sig, _) => { hir::ImplItemKind::Fn(sig, _) => has_late_bound_regions(tcx, &item.generics, sig.decl),
has_late_bound_regions(tcx, &item.generics, sig.decl)
}
_ => None, _ => None,
}, },
Node::ForeignItem(item) => match item.kind { Node::ForeignItem(item) => match item.kind {
hir::ForeignItemKind::Fn(fn_decl, _, ref generics) => { hir::ForeignItemKind::Fn(fn_decl, _, generics) => {
has_late_bound_regions(tcx, generics, fn_decl) has_late_bound_regions(tcx, generics, fn_decl)
} }
_ => None, _ => None,
}, },
Node::Item(item) => match item.kind { Node::Item(item) => match &item.kind {
hir::ItemKind::Fn(ref sig, .., ref generics, _) => { hir::ItemKind::Fn(sig, .., generics, _) => {
has_late_bound_regions(tcx, generics, sig.decl) has_late_bound_regions(tcx, generics, sig.decl)
} }
_ => None, _ => None,

View file

@ -428,7 +428,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
_ => {} _ => {}
} }
match item.kind { match item.kind {
hir::ItemKind::Fn(_, ref generics, _) => { hir::ItemKind::Fn(_, generics, _) => {
self.visit_early_late(item.hir_id(), generics, |this| { self.visit_early_late(item.hir_id(), generics, |this| {
intravisit::walk_item(this, item); intravisit::walk_item(this, item);
}); });
@ -508,13 +508,13 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
this.with(scope, |this| intravisit::walk_item(this, item)) this.with(scope, |this| intravisit::walk_item(this, item))
}); });
} }
hir::ItemKind::TyAlias(_, ref generics) hir::ItemKind::TyAlias(_, generics)
| hir::ItemKind::Enum(_, ref generics) | hir::ItemKind::Enum(_, generics)
| hir::ItemKind::Struct(_, ref generics) | hir::ItemKind::Struct(_, generics)
| hir::ItemKind::Union(_, ref generics) | hir::ItemKind::Union(_, generics)
| hir::ItemKind::Trait(_, _, ref generics, ..) | hir::ItemKind::Trait(_, _, generics, ..)
| hir::ItemKind::TraitAlias(ref generics, ..) | hir::ItemKind::TraitAlias(generics, ..)
| hir::ItemKind::Impl(hir::Impl { ref generics, .. }) => { | hir::ItemKind::Impl(&hir::Impl { generics, .. }) => {
// These kinds of items have only early-bound lifetime parameters. // These kinds of items have only early-bound lifetime parameters.
let lifetimes = generics let lifetimes = generics
.params .params
@ -544,7 +544,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) { fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) {
match item.kind { match item.kind {
hir::ForeignItemKind::Fn(_, _, ref generics) => { hir::ForeignItemKind::Fn(_, _, generics) => {
self.visit_early_late(item.hir_id(), generics, |this| { self.visit_early_late(item.hir_id(), generics, |this| {
intravisit::walk_foreign_item(this, item); intravisit::walk_foreign_item(this, item);
}) })
@ -561,7 +561,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
#[instrument(level = "debug", skip(self))] #[instrument(level = "debug", skip(self))]
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) { fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
match ty.kind { match ty.kind {
hir::TyKind::BareFn(ref c) => { hir::TyKind::BareFn(c) => {
let (lifetimes, binders): (FxIndexMap<LocalDefId, Region>, Vec<_>) = c let (lifetimes, binders): (FxIndexMap<LocalDefId, Region>, Vec<_>) = c
.generic_params .generic_params
.iter() .iter()
@ -587,7 +587,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
intravisit::walk_ty(this, ty); intravisit::walk_ty(this, ty);
}); });
} }
hir::TyKind::TraitObject(bounds, ref lifetime, _) => { hir::TyKind::TraitObject(bounds, lifetime, _) => {
debug!(?bounds, ?lifetime, "TraitObject"); debug!(?bounds, ?lifetime, "TraitObject");
let scope = Scope::TraitRefBoundary { s: self.scope }; let scope = Scope::TraitRefBoundary { s: self.scope };
self.with(scope, |this| { self.with(scope, |this| {
@ -617,7 +617,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
LifetimeName::Error => {} LifetimeName::Error => {}
} }
} }
hir::TyKind::Ref(ref lifetime_ref, ref mt) => { hir::TyKind::Ref(lifetime_ref, ref mt) => {
self.visit_lifetime(lifetime_ref); self.visit_lifetime(lifetime_ref);
let scope = Scope::ObjectLifetimeDefault { let scope = Scope::ObjectLifetimeDefault {
lifetime: self.map.defs.get(&lifetime_ref.hir_id).cloned(), lifetime: self.map.defs.get(&lifetime_ref.hir_id).cloned(),
@ -632,7 +632,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
// ^ ^ this gets resolved in the scope of // ^ ^ this gets resolved in the scope of
// the opaque_ty generics // the opaque_ty generics
let opaque_ty = self.tcx.hir().item(item_id); let opaque_ty = self.tcx.hir().item(item_id);
match opaque_ty.kind { match &opaque_ty.kind {
hir::ItemKind::OpaqueTy(hir::OpaqueTy { hir::ItemKind::OpaqueTy(hir::OpaqueTy {
origin: hir::OpaqueTyOrigin::TyAlias, origin: hir::OpaqueTyOrigin::TyAlias,
.. ..
@ -655,7 +655,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
origin: hir::OpaqueTyOrigin::FnReturn(..) | hir::OpaqueTyOrigin::AsyncFn(..), origin: hir::OpaqueTyOrigin::FnReturn(..) | hir::OpaqueTyOrigin::AsyncFn(..),
.. ..
}) => {} }) => {}
ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i), i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i),
}; };
// Resolve the lifetimes that are applied to the opaque type. // Resolve the lifetimes that are applied to the opaque type.
@ -720,7 +720,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
intravisit::walk_trait_item(this, trait_item) intravisit::walk_trait_item(this, trait_item)
}); });
} }
Type(bounds, ref ty) => { Type(bounds, ty) => {
let generics = &trait_item.generics; let generics = &trait_item.generics;
let lifetimes = generics let lifetimes = generics
.params .params
@ -766,7 +766,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
Fn(..) => self.visit_early_late(impl_item.hir_id(), &impl_item.generics, |this| { Fn(..) => self.visit_early_late(impl_item.hir_id(), &impl_item.generics, |this| {
intravisit::walk_impl_item(this, impl_item) intravisit::walk_impl_item(this, impl_item)
}), }),
Type(ref ty) => { Type(ty) => {
let generics = &impl_item.generics; let generics = &impl_item.generics;
let lifetimes: FxIndexMap<LocalDefId, Region> = generics let lifetimes: FxIndexMap<LocalDefId, Region> = generics
.params .params
@ -817,7 +817,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
fn visit_path(&mut self, path: &hir::Path<'tcx>, _: hir::HirId) { fn visit_path(&mut self, path: &hir::Path<'tcx>, _: hir::HirId) {
for (i, segment) in path.segments.iter().enumerate() { for (i, segment) in path.segments.iter().enumerate() {
let depth = path.segments.len() - i - 1; let depth = path.segments.len() - i - 1;
if let Some(ref args) = segment.args { if let Some(args) = segment.args {
self.visit_segment_args(path.res, depth, args); self.visit_segment_args(path.res, depth, args);
} }
} }
@ -833,7 +833,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
) { ) {
let output = match fd.output { let output = match fd.output {
hir::FnRetTy::DefaultReturn(_) => None, hir::FnRetTy::DefaultReturn(_) => None,
hir::FnRetTy::Return(ref ty) => Some(&**ty), hir::FnRetTy::Return(ty) => Some(ty),
}; };
self.visit_fn_like_elision(&fd.inputs, output, matches!(fk, intravisit::FnKind::Closure)); self.visit_fn_like_elision(&fd.inputs, output, matches!(fk, intravisit::FnKind::Closure));
intravisit::walk_fn_kind(self, fk); intravisit::walk_fn_kind(self, fk);
@ -846,13 +846,13 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
for param in generics.params { for param in generics.params {
match param.kind { match param.kind {
GenericParamKind::Lifetime { .. } => {} GenericParamKind::Lifetime { .. } => {}
GenericParamKind::Type { ref default, .. } => { GenericParamKind::Type { default, .. } => {
if let Some(ref ty) = default { if let Some(ty) = default {
this.visit_ty(&ty); this.visit_ty(ty);
} }
} }
GenericParamKind::Const { ref ty, default } => { GenericParamKind::Const { ty, default } => {
this.visit_ty(&ty); this.visit_ty(ty);
if let Some(default) = default { if let Some(default) = default {
this.visit_body(this.tcx.hir().body(default.body)); this.visit_body(this.tcx.hir().body(default.body));
} }
@ -863,9 +863,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
match predicate { match predicate {
&hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate { &hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
hir_id, hir_id,
ref bounded_ty, bounded_ty,
bounds, bounds,
ref bound_generic_params, bound_generic_params,
origin, origin,
.. ..
}) => { }) => {
@ -905,7 +905,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
}) })
} }
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate { &hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
ref lifetime, lifetime,
bounds, bounds,
.. ..
}) => { }) => {
@ -914,7 +914,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
if lifetime.res != hir::LifetimeName::Static { if lifetime.res != hir::LifetimeName::Static {
for bound in bounds { for bound in bounds {
let hir::GenericBound::Outlives(ref lt) = bound else { let hir::GenericBound::Outlives(lt) = bound else {
continue; continue;
}; };
if lt.res != hir::LifetimeName::Static { if lt.res != hir::LifetimeName::Static {
@ -939,8 +939,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
} }
} }
&hir::WherePredicate::EqPredicate(hir::WhereEqPredicate { &hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
ref lhs_ty, lhs_ty,
ref rhs_ty, rhs_ty,
.. ..
}) => { }) => {
this.visit_ty(lhs_ty); this.visit_ty(lhs_ty);
@ -1042,7 +1042,7 @@ fn object_lifetime_default(tcx: TyCtxt<'_>, param_def_id: DefId) -> ObjectLifeti
} }
for bound in bound.bounds { for bound in bound.bounds {
if let hir::GenericBound::Outlives(ref lifetime) = *bound { if let hir::GenericBound::Outlives(lifetime) = bound {
set.insert(lifetime.res); set.insert(lifetime.res);
} }
} }
@ -1828,7 +1828,7 @@ fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet<
} }
} }
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => { hir::TyKind::Path(hir::QPath::Resolved(None, path)) => {
// consider only the lifetimes on the final // consider only the lifetimes on the final
// segment; I am not sure it's even currently // segment; I am not sure it's even currently
// valid to have them elsewhere, but even if it // valid to have them elsewhere, but even if it

View file

@ -85,30 +85,30 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
Node::ImplItem(item) => item.generics, Node::ImplItem(item) => item.generics,
Node::Item(item) => match item.kind { Node::Item(item) => match item.kind {
ItemKind::Impl(ref impl_) => { ItemKind::Impl(impl_) => {
if impl_.defaultness.is_default() { if impl_.defaultness.is_default() {
is_default_impl_trait = is_default_impl_trait =
tcx.impl_trait_ref(def_id).map(|t| ty::Binder::dummy(t.subst_identity())); tcx.impl_trait_ref(def_id).map(|t| ty::Binder::dummy(t.subst_identity()));
} }
&impl_.generics impl_.generics
} }
ItemKind::Fn(.., ref generics, _) ItemKind::Fn(.., generics, _)
| ItemKind::TyAlias(_, ref generics) | ItemKind::TyAlias(_, generics)
| ItemKind::Enum(_, ref generics) | ItemKind::Enum(_, generics)
| ItemKind::Struct(_, ref generics) | ItemKind::Struct(_, generics)
| ItemKind::Union(_, ref generics) => *generics, | ItemKind::Union(_, generics) => generics,
ItemKind::Trait(_, _, ref generics, ..) | ItemKind::TraitAlias(ref generics, _) => { ItemKind::Trait(_, _, generics, ..) | ItemKind::TraitAlias(generics, _) => {
is_trait = Some(ty::TraitRef::identity(tcx, def_id)); is_trait = Some(ty::TraitRef::identity(tcx, def_id));
*generics generics
} }
ItemKind::OpaqueTy(OpaqueTy { ref generics, .. }) => generics, ItemKind::OpaqueTy(OpaqueTy { generics, .. }) => generics,
_ => NO_GENERICS, _ => NO_GENERICS,
}, },
Node::ForeignItem(item) => match item.kind { Node::ForeignItem(item) => match item.kind {
ForeignItemKind::Static(..) => NO_GENERICS, ForeignItemKind::Static(..) => NO_GENERICS,
ForeignItemKind::Fn(_, _, ref generics) => *generics, ForeignItemKind::Fn(_, _, generics) => generics,
ForeignItemKind::Type => NO_GENERICS, ForeignItemKind::Type => NO_GENERICS,
}, },
@ -350,7 +350,7 @@ fn const_evaluatable_predicates_of(
let node = tcx.hir().get(hir_id); let node = tcx.hir().get(hir_id);
let mut collector = ConstCollector { tcx, preds: FxIndexSet::default() }; let mut collector = ConstCollector { tcx, preds: FxIndexSet::default() };
if let hir::Node::Item(item) = node && let hir::ItemKind::Impl(ref 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 { if let Some(of_trait) = &impl_.of_trait {
debug!("const_evaluatable_predicates_of({:?}): visit impl trait_ref", def_id); debug!("const_evaluatable_predicates_of({:?}): visit impl trait_ref", def_id);
collector.visit_trait_ref(of_trait); collector.visit_trait_ref(of_trait);
@ -511,8 +511,8 @@ pub(super) fn super_predicates_that_define_assoc_type(
}; };
let (generics, bounds) = match item.kind { let (generics, bounds) = match item.kind {
hir::ItemKind::Trait(.., ref generics, ref supertraits, _) => (generics, supertraits), hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits),
hir::ItemKind::TraitAlias(ref generics, ref supertraits) => (generics, supertraits), hir::ItemKind::TraitAlias(generics, supertraits) => (generics, supertraits),
_ => span_bug!(item.span, "super_predicates invoked on non-trait"), _ => span_bug!(item.span, "super_predicates invoked on non-trait"),
}; };
@ -612,18 +612,18 @@ pub(super) fn type_param_predicates(
Node::Item(item) => { Node::Item(item) => {
match item.kind { match item.kind {
ItemKind::Fn(.., ref generics, _) ItemKind::Fn(.., generics, _)
| ItemKind::Impl(hir::Impl { ref generics, .. }) | ItemKind::Impl(&hir::Impl { generics, .. })
| ItemKind::TyAlias(_, ref generics) | ItemKind::TyAlias(_, generics)
| ItemKind::OpaqueTy(OpaqueTy { | ItemKind::OpaqueTy(OpaqueTy {
ref generics, generics,
origin: hir::OpaqueTyOrigin::TyAlias, origin: hir::OpaqueTyOrigin::TyAlias,
.. ..
}) })
| ItemKind::Enum(_, ref generics) | ItemKind::Enum(_, generics)
| ItemKind::Struct(_, ref generics) | ItemKind::Struct(_, generics)
| ItemKind::Union(_, ref generics) => generics, | ItemKind::Union(_, generics) => generics,
ItemKind::Trait(_, _, ref generics, ..) => { ItemKind::Trait(_, _, generics, ..) => {
// Implied `Self: Trait` and supertrait bounds. // Implied `Self: Trait` and supertrait bounds.
if param_id == item_hir_id { if param_id == item_hir_id {
let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id); let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id);
@ -637,7 +637,7 @@ pub(super) fn type_param_predicates(
} }
Node::ForeignItem(item) => match item.kind { Node::ForeignItem(item) => match item.kind {
ForeignItemKind::Fn(_, _, ref generics) => generics, ForeignItemKind::Fn(_, _, generics) => generics,
_ => return result, _ => return result,
}, },
@ -681,8 +681,8 @@ impl<'tcx> ItemCtxt<'tcx> {
ast_generics ast_generics
.predicates .predicates
.iter() .iter()
.filter_map(|wp| match *wp { .filter_map(|wp| match wp {
hir::WherePredicate::BoundPredicate(ref bp) => Some(bp), hir::WherePredicate::BoundPredicate(bp) => Some(bp),
_ => None, _ => None,
}) })
.flat_map(|bp| { .flat_map(|bp| {

View file

@ -379,7 +379,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
ForeignItemKind::Type => tcx.mk_foreign(def_id.to_def_id()), ForeignItemKind::Type => tcx.mk_foreign(def_id.to_def_id()),
}, },
Node::Ctor(&ref def) | Node::Variant(Variant { data: ref def, .. }) => match *def { Node::Ctor(def) | Node::Variant(Variant { data: def, .. }) => match def {
VariantData::Unit(..) | VariantData::Struct(..) => { VariantData::Unit(..) | VariantData::Struct(..) => {
tcx.type_of(tcx.hir().get_parent_item(hir_id)) tcx.type_of(tcx.hir().get_parent_item(hir_id))
} }
@ -404,17 +404,17 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
Node::AnonConst(_) => { Node::AnonConst(_) => {
let parent_node = tcx.hir().get_parent(hir_id); let parent_node = tcx.hir().get_parent(hir_id);
match parent_node { match parent_node {
Node::Ty(&Ty { kind: TyKind::Array(_, ref constant), .. }) Node::Ty(Ty { kind: TyKind::Array(_, constant), .. })
| Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. }) | Node::Expr(Expr { kind: ExprKind::Repeat(_, constant), .. })
if constant.hir_id() == hir_id => if constant.hir_id() == hir_id =>
{ {
tcx.types.usize tcx.types.usize
} }
Node::Ty(&Ty { kind: TyKind::Typeof(ref e), .. }) if e.hir_id == hir_id => { Node::Ty(Ty { kind: TyKind::Typeof(e), .. }) if e.hir_id == hir_id => {
tcx.typeck(def_id).node_type(e.hir_id) tcx.typeck(def_id).node_type(e.hir_id)
} }
Node::Expr(&Expr { kind: ExprKind::ConstBlock(ref anon_const), .. }) Node::Expr(Expr { kind: ExprKind::ConstBlock(anon_const), .. })
if anon_const.hir_id == hir_id => if anon_const.hir_id == hir_id =>
{ {
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
@ -434,18 +434,19 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
tcx.typeck(def_id).node_type(hir_id) tcx.typeck(def_id).node_type(hir_id)
} }
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => { Node::Variant(Variant { disr_expr: Some(e), .. }) if e.hir_id == hir_id => {
tcx.adt_def(tcx.hir().get_parent_item(hir_id)).repr().discr_type().to_ty(tcx) tcx.adt_def(tcx.hir().get_parent_item(hir_id)).repr().discr_type().to_ty(tcx)
} }
Node::TypeBinding( Node::TypeBinding(
binding @ &TypeBinding { TypeBinding {
hir_id: binding_id, hir_id: binding_id,
kind: TypeBindingKind::Equality { term: Term::Const(ref e) }, kind: TypeBindingKind::Equality { term: Term::Const(e) },
ident,
.. ..
}, },
) if let Node::TraitRef(trait_ref) = ) if let Node::TraitRef(trait_ref) =
tcx.hir().get_parent(binding_id) tcx.hir().get_parent(*binding_id)
&& e.hir_id == hir_id => && e.hir_id == hir_id =>
{ {
let Some(trait_def_id) = trait_ref.trait_def_id() else { let Some(trait_def_id) = trait_ref.trait_def_id() else {
@ -454,7 +455,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
let assoc_items = tcx.associated_items(trait_def_id); let assoc_items = tcx.associated_items(trait_def_id);
let assoc_item = assoc_items.find_by_name_and_kind( let assoc_item = assoc_items.find_by_name_and_kind(
tcx, tcx,
binding.ident, *ident,
ty::AssocKind::Const, ty::AssocKind::Const,
def_id.to_def_id(), def_id.to_def_id(),
); );
@ -470,9 +471,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
} }
Node::TypeBinding( Node::TypeBinding(
binding @ &TypeBinding { hir_id: binding_id, gen_args, ref kind, .. }, TypeBinding { hir_id: binding_id, gen_args, kind, ident, .. },
) if let Node::TraitRef(trait_ref) = ) if let Node::TraitRef(trait_ref) =
tcx.hir().get_parent(binding_id) tcx.hir().get_parent(*binding_id)
&& let Some((idx, _)) = && let Some((idx, _)) =
gen_args.args.iter().enumerate().find(|(_, arg)| { gen_args.args.iter().enumerate().find(|(_, arg)| {
if let GenericArg::Const(ct) = arg { if let GenericArg::Const(ct) = arg {
@ -488,7 +489,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
let assoc_items = tcx.associated_items(trait_def_id); let assoc_items = tcx.associated_items(trait_def_id);
let assoc_item = assoc_items.find_by_name_and_kind( let assoc_item = assoc_items.find_by_name_and_kind(
tcx, tcx,
binding.ident, *ident,
match kind { match kind {
// I think `<A: T>` type bindings requires that `A` is a type // I think `<A: T>` type bindings requires that `A` is a type
TypeBindingKind::Constraint { .. } TypeBindingKind::Constraint { .. }

View file

@ -128,7 +128,7 @@ fn diagnostic_hir_wf_check<'tcx>(
}, },
hir::Node::Item(item) => match item.kind { hir::Node::Item(item) => match item.kind {
hir::ItemKind::Static(ty, _, _) | hir::ItemKind::Const(ty, _) => vec![ty], hir::ItemKind::Static(ty, _, _) | hir::ItemKind::Const(ty, _) => vec![ty],
hir::ItemKind::Impl(ref impl_) => match &impl_.of_trait { hir::ItemKind::Impl(impl_) => match &impl_.of_trait {
Some(t) => t Some(t) => t
.path .path
.segments .segments

View file

@ -219,7 +219,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
} }
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
match tcx.hir().find(hir_id) { match tcx.hir().find(hir_id) {
Some(Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, ref generics, _), .. })) => { Some(Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. })) => {
Some(generics.where_clause_span) Some(generics.where_clause_span)
} }
_ => { _ => {
@ -241,7 +241,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
} }
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
match tcx.hir().find(hir_id) { match tcx.hir().find(hir_id) {
Some(Node::Item(hir::Item { kind: hir::ItemKind::Fn(ref fn_sig, _, _), .. })) => { Some(Node::Item(hir::Item { kind: hir::ItemKind::Fn(fn_sig, _, _), .. })) => {
Some(fn_sig.decl.output.span()) Some(fn_sig.decl.output.span())
} }
_ => { _ => {
@ -371,7 +371,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
match start_t.kind() { match start_t.kind() {
ty::FnDef(..) => { ty::FnDef(..) => {
if let Some(Node::Item(it)) = tcx.hir().find(start_id) { if let Some(Node::Item(it)) = tcx.hir().find(start_id) {
if let hir::ItemKind::Fn(ref sig, ref generics, _) = it.kind { if let hir::ItemKind::Fn(sig, generics, _) = &it.kind {
let mut error = false; let mut error = false;
if !generics.params.is_empty() { if !generics.params.is_empty() {
struct_span_err!( struct_span_err!(

View file

@ -727,8 +727,8 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
if let Some(parent_node) = self.tcx.hir().opt_parent_id(self.path_segment.hir_id) if let Some(parent_node) = self.tcx.hir().opt_parent_id(self.path_segment.hir_id)
&& let Some(parent_node) = self.tcx.hir().find(parent_node) && let Some(parent_node) = self.tcx.hir().find(parent_node)
&& let hir::Node::Expr(expr) = parent_node { && let hir::Node::Expr(expr) = parent_node {
match expr.kind { match &expr.kind {
hir::ExprKind::Path(ref qpath) => { hir::ExprKind::Path(qpath) => {
self.suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path( self.suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path(
err, err,
qpath, qpath,

View file

@ -28,8 +28,8 @@ pub fn solve_constraints<'tcx>(
let ConstraintContext { terms_cx, constraints, .. } = constraints_cx; let ConstraintContext { terms_cx, constraints, .. } = constraints_cx;
let mut solutions = vec![ty::Bivariant; terms_cx.inferred_terms.len()]; let mut solutions = vec![ty::Bivariant; terms_cx.inferred_terms.len()];
for &(id, ref variances) in &terms_cx.lang_items { for (id, variances) in &terms_cx.lang_items {
let InferredIndex(start) = terms_cx.inferred_starts[&id]; let InferredIndex(start) = terms_cx.inferred_starts[id];
for (i, &variance) in variances.iter().enumerate() { for (i, &variance) in variances.iter().enumerate() {
solutions[start + i] = variance; solutions[start + i] = variance;
} }