mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
rustc_hir_analysis
: remove ref
patterns
This commit is contained in:
parent
d60e772e14
commit
09485eaae1
@ -569,17 +569,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
.bindings
|
||||
.iter()
|
||||
.map(|binding| {
|
||||
let kind = match binding.kind {
|
||||
hir::TypeBindingKind::Equality { ref term } => match term {
|
||||
hir::Term::Ty(ref ty) => {
|
||||
let kind = match &binding.kind {
|
||||
hir::TypeBindingKind::Equality { term } => match term {
|
||||
hir::Term::Ty(ty) => {
|
||||
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);
|
||||
ConvertedBindingKind::Equality(c.into())
|
||||
}
|
||||
},
|
||||
hir::TypeBindingKind::Constraint { ref bounds } => {
|
||||
hir::TypeBindingKind::Constraint { bounds } => {
|
||||
ConvertedBindingKind::Constraint(bounds)
|
||||
}
|
||||
};
|
||||
@ -1928,7 +1928,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed> {
|
||||
let tcx = self.tcx();
|
||||
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
|
||||
} else {
|
||||
Res::Err
|
||||
@ -1971,8 +1971,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
return;
|
||||
};
|
||||
let (qself_sugg_span, is_self) = if let hir::TyKind::Path(
|
||||
hir::QPath::Resolved(_, ref path)
|
||||
) = qself.kind {
|
||||
hir::QPath::Resolved(_, path)
|
||||
) = &qself.kind {
|
||||
// If the path segment already has type params, we want to overwrite
|
||||
// them.
|
||||
match &path.segments[..] {
|
||||
@ -2760,7 +2760,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
"generic `Self` types are currently not permitted in anonymous constants",
|
||||
);
|
||||
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)
|
||||
{
|
||||
@ -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> {
|
||||
let tcx = self.tcx();
|
||||
|
||||
let result_ty = match ast_ty.kind {
|
||||
hir::TyKind::Slice(ref ty) => tcx.mk_slice(self.ast_ty_to_ty(ty)),
|
||||
hir::TyKind::Ptr(ref mt) => {
|
||||
let result_ty = match &ast_ty.kind {
|
||||
hir::TyKind::Slice(ty) => tcx.mk_slice(self.ast_ty_to_ty(ty)),
|
||||
hir::TyKind::Ptr(mt) => {
|
||||
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);
|
||||
debug!(?r);
|
||||
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),
|
||||
))
|
||||
}
|
||||
hir::TyKind::TraitObject(bounds, ref lifetime, repr) => {
|
||||
hir::TyKind::TraitObject(bounds, lifetime, repr) => {
|
||||
self.maybe_lint_bare_trait(ast_ty, in_path);
|
||||
let repr = match repr {
|
||||
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)
|
||||
}
|
||||
hir::TyKind::Path(hir::QPath::Resolved(ref maybe_qself, ref path)) => {
|
||||
hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
|
||||
debug!(?maybe_qself, ?path);
|
||||
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)
|
||||
}
|
||||
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();
|
||||
|
||||
match opaque_ty.kind {
|
||||
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),
|
||||
}
|
||||
}
|
||||
hir::TyKind::Path(hir::QPath::TypeRelative(ref qself, ref segment)) => {
|
||||
hir::TyKind::Path(hir::QPath::TypeRelative(qself, segment)) => {
|
||||
debug!(?qself, ?segment);
|
||||
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)
|
||||
.map(|(ty, _, _)| ty)
|
||||
.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 (substs, _) = self.create_substs_for_ast_path(
|
||||
span,
|
||||
@ -2913,7 +2913,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
);
|
||||
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 {
|
||||
&hir::ArrayLen::Infer(_, span) => self.ct_infer(tcx.types.usize, None, span),
|
||||
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))
|
||||
}
|
||||
hir::TyKind::Typeof(ref e) => {
|
||||
hir::TyKind::Typeof(e) => {
|
||||
let ty_erased = tcx.type_of(e.def_id);
|
||||
let ty = tcx.fold_regions(ty_erased, |r, _| {
|
||||
if r.is_erased() { tcx.lifetimes.re_static } else { r }
|
||||
|
@ -531,9 +531,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
||||
DefKind::Fn => {} // entirely within check_item_body
|
||||
DefKind::Impl => {
|
||||
let it = tcx.hir().item(id);
|
||||
let hir::ItemKind::Impl(ref impl_) = it.kind else {
|
||||
return;
|
||||
};
|
||||
let hir::ItemKind::Impl(impl_) = it.kind else { return };
|
||||
debug!("ItemKind::Impl {} with id {:?}", it.ident, it.owner_id);
|
||||
if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.owner_id) {
|
||||
check_impl_items_against_trait(
|
||||
@ -548,15 +546,15 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
||||
}
|
||||
DefKind::Trait => {
|
||||
let it = tcx.hir().item(id);
|
||||
let hir::ItemKind::Trait(_, _, _, _, ref items) = it.kind else {
|
||||
let hir::ItemKind::Trait(_, _, _, _, items) = it.kind else {
|
||||
return;
|
||||
};
|
||||
check_on_unimplemented(tcx, it);
|
||||
|
||||
for item in items.iter() {
|
||||
let item = tcx.hir().trait_item(item.id);
|
||||
match item.kind {
|
||||
hir::TraitItemKind::Fn(ref sig, _) => {
|
||||
match &item.kind {
|
||||
hir::TraitItemKind::Fn(sig, _) => {
|
||||
let abi = sig.header.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);
|
||||
match item.kind {
|
||||
hir::ForeignItemKind::Fn(ref fn_decl, _, _) => {
|
||||
match &item.kind {
|
||||
hir::ForeignItemKind::Fn(fn_decl, _, _) => {
|
||||
require_c_abi_if_c_variadic(tcx, fn_decl, abi, item.span);
|
||||
}
|
||||
hir::ForeignItemKind::Static(..) => {
|
||||
|
@ -1513,8 +1513,7 @@ fn compare_synthetic_generics<'tcx>(
|
||||
impl<'v> intravisit::Visitor<'v> for Visitor {
|
||||
fn visit_ty(&mut self, ty: &'v hir::Ty<'v>) {
|
||||
intravisit::walk_ty(self, ty);
|
||||
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) =
|
||||
ty.kind
|
||||
if let hir::TyKind::Path(hir::QPath::Resolved(None, path)) = ty.kind
|
||||
&& let Res::Def(DefKind::TyParam, def_id) = path.res
|
||||
&& def_id == self.1.to_def_id()
|
||||
{
|
||||
|
@ -351,7 +351,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
match *op {
|
||||
hir::InlineAsmOperand::In { reg, ref expr } => {
|
||||
hir::InlineAsmOperand::In { reg, expr } => {
|
||||
self.check_asm_operand_type(
|
||||
idx,
|
||||
reg,
|
||||
@ -362,7 +362,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
||||
&target_features,
|
||||
);
|
||||
}
|
||||
hir::InlineAsmOperand::Out { reg, late: _, ref expr } => {
|
||||
hir::InlineAsmOperand::Out { reg, late: _, expr } => {
|
||||
if let Some(expr) = expr {
|
||||
self.check_asm_operand_type(
|
||||
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(
|
||||
idx,
|
||||
reg,
|
||||
@ -386,7 +386,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
||||
&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(
|
||||
idx,
|
||||
reg,
|
||||
|
@ -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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -242,8 +242,8 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
|
||||
// This ensures fixed size stacks.
|
||||
hir::ExprKind::Binary(
|
||||
source_map::Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. },
|
||||
ref l,
|
||||
ref r,
|
||||
l,
|
||||
r,
|
||||
) => {
|
||||
// expr is a short circuiting operator (|| or &&). As its
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
hir::ExprKind::If(_, ref then, Some(ref otherwise)) => {
|
||||
hir::ExprKind::If(_, then, Some(otherwise)) => {
|
||||
terminating(then.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);
|
||||
}
|
||||
|
||||
hir::ExprKind::Loop(ref body, _, _, _) => {
|
||||
hir::ExprKind::Loop(body, _, _, _) => {
|
||||
terminating(body.hir_id.local_id);
|
||||
}
|
||||
|
||||
hir::ExprKind::DropTemps(ref expr) => {
|
||||
hir::ExprKind::DropTemps(expr) => {
|
||||
// `DropTemps(expr)` does not denote a conditional scope.
|
||||
// Rather, we want to achieve the same behavior as `{ let _t = expr; _t }`.
|
||||
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);
|
||||
visitor.visit_body(body);
|
||||
}
|
||||
hir::ExprKind::AssignOp(_, ref left_expr, ref right_expr) => {
|
||||
hir::ExprKind::AssignOp(_, left_expr, right_expr) => {
|
||||
debug!(
|
||||
"resolve_expr - enabling pessimistic_yield, was previously {}",
|
||||
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;
|
||||
visitor.enter_scope(Scope { id: then.hir_id.local_id, data: ScopeData::IfThen });
|
||||
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);
|
||||
}
|
||||
|
||||
hir::ExprKind::If(ref cond, ref then, None) => {
|
||||
hir::ExprKind::If(cond, then, None) => {
|
||||
let expr_cx = visitor.cx;
|
||||
visitor.enter_scope(Scope { id: then.hir_id.local_id, data: ScopeData::IfThen });
|
||||
visitor.cx.var_parent = visitor.cx.parent;
|
||||
@ -641,21 +641,21 @@ fn resolve_local<'tcx>(
|
||||
match pat.kind {
|
||||
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))
|
||||
}
|
||||
|
||||
PatKind::Slice(ref pats1, ref pats2, ref pats3) => {
|
||||
PatKind::Slice(pats1, pats2, pats3) => {
|
||||
pats1.iter().any(|p| is_binding_pat(&p))
|
||||
|| pats2.iter().any(|p| is_binding_pat(&p))
|
||||
|| pats3.iter().any(|p| is_binding_pat(&p))
|
||||
}
|
||||
|
||||
PatKind::Or(ref subpats)
|
||||
| PatKind::TupleStruct(_, ref subpats, _)
|
||||
| PatKind::Tuple(ref subpats, _) => subpats.iter().any(|p| is_binding_pat(&p)),
|
||||
PatKind::Or(subpats)
|
||||
| PatKind::TupleStruct(_, subpats, _)
|
||||
| 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::Binding(hir::BindingAnnotation(hir::ByRef::No, _), ..)
|
||||
@ -704,11 +704,11 @@ fn resolve_local<'tcx>(
|
||||
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)
|
||||
}
|
||||
hir::ExprKind::Block(ref block, _) => {
|
||||
if let Some(ref subexpr) = block.expr {
|
||||
hir::ExprKind::Block(block, _) => {
|
||||
if let Some(subexpr) = block.expr {
|
||||
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id);
|
||||
}
|
||||
}
|
||||
|
@ -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`
|
||||
// for `T`
|
||||
hir::ItemKind::Impl(ref impl_) => {
|
||||
hir::ItemKind::Impl(impl_) => {
|
||||
let is_auto = tcx
|
||||
.impl_trait_ref(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, ..) => {
|
||||
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_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_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_variances_for_type_defn(tcx, item, ast_generics);
|
||||
}
|
||||
@ -1247,8 +1247,8 @@ fn check_impl<'tcx>(
|
||||
constness: hir::Constness,
|
||||
) {
|
||||
enter_wf_checking_ctxt(tcx, item.span, item.owner_id.def_id, |wfcx| {
|
||||
match *ast_trait_ref {
|
||||
Some(ref ast_trait_ref) => {
|
||||
match ast_trait_ref {
|
||||
Some(ast_trait_ref) => {
|
||||
// `#[rustc_reservation_impl]` impls are not real impls and
|
||||
// therefore don't need to be WF (the trait's `Self: Trait` predicate
|
||||
// won't hold).
|
||||
|
@ -502,12 +502,11 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
|
||||
return err_info;
|
||||
} else if diff_fields.len() > 1 {
|
||||
let item = tcx.hir().expect_item(impl_did);
|
||||
let span =
|
||||
if let ItemKind::Impl(hir::Impl { of_trait: Some(ref t), .. }) = item.kind {
|
||||
t.path.span
|
||||
} else {
|
||||
tcx.def_span(impl_did)
|
||||
};
|
||||
let span = if let ItemKind::Impl(hir::Impl { of_trait: Some(t), .. }) = &item.kind {
|
||||
t.path.span
|
||||
} else {
|
||||
tcx.def_span(impl_did)
|
||||
};
|
||||
|
||||
struct_span_err!(
|
||||
tcx.sess,
|
||||
|
@ -182,7 +182,7 @@ impl<'tcx> InherentCollect<'tcx> {
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -40,7 +40,7 @@ fn do_orphan_check_impl<'tcx>(
|
||||
let trait_def_id = trait_ref.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);
|
||||
};
|
||||
let sp = tcx.def_span(def_id);
|
||||
|
@ -11,7 +11,7 @@ use rustc_span::def_id::LocalDefId;
|
||||
pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||
debug_assert!(matches!(tcx.def_kind(def_id), DefKind::Impl));
|
||||
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) {
|
||||
let trait_ref = trait_ref.subst_identity();
|
||||
|
@ -560,7 +560,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
||||
debug!("convert: item {} with id {}", it.ident, it.hir_id());
|
||||
let def_id = item_id.owner_id.def_id;
|
||||
|
||||
match it.kind {
|
||||
match &it.kind {
|
||||
// These don't define types.
|
||||
hir::ItemKind::ExternCrate(_)
|
||||
| hir::ItemKind::Use(..)
|
||||
@ -568,7 +568,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
||||
| hir::ItemKind::Mod(_)
|
||||
| hir::ItemKind::GlobalAsm(_) => {}
|
||||
hir::ItemKind::ForeignMod { items, .. } => {
|
||||
for item in items {
|
||||
for item in *items {
|
||||
let item = tcx.hir().foreign_item(item.id);
|
||||
tcx.ensure().generics_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.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().type_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 (kind, variants) = match item.kind {
|
||||
ItemKind::Enum(ref def, _) => {
|
||||
let (kind, variants) = match &item.kind {
|
||||
ItemKind::Enum(def, _) => {
|
||||
let mut distance_from_explicit = 0;
|
||||
let variants = def
|
||||
.variants
|
||||
.iter()
|
||||
.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;
|
||||
ty::VariantDiscr::Explicit(e.def_id.to_def_id())
|
||||
} else {
|
||||
@ -882,7 +882,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AdtDef<'_> {
|
||||
|
||||
(AdtKind::Enum, variants)
|
||||
}
|
||||
ItemKind::Struct(ref def, _) | ItemKind::Union(ref def, _) => {
|
||||
ItemKind::Struct(def, _) | ItemKind::Union(def, _) => {
|
||||
let adt_kind = match item.kind {
|
||||
ItemKind::Struct(..) => AdtKind::Struct,
|
||||
_ => 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()) {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
// `enum` discriminants (i.e. `D` in `enum Foo { Bar = D }`),
|
||||
// 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 =>
|
||||
{
|
||||
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 =>
|
||||
{
|
||||
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 {
|
||||
GenericParamKind::Lifetime { .. } => None,
|
||||
GenericParamKind::Type { ref default, synthetic, .. } => {
|
||||
GenericParamKind::Type { default, synthetic, .. } => {
|
||||
if default.is_some() {
|
||||
match allow_defaults {
|
||||
Defaults::Allowed => {}
|
||||
@ -426,26 +426,22 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
|
||||
}
|
||||
|
||||
match node {
|
||||
Node::TraitItem(item) => match item.kind {
|
||||
hir::TraitItemKind::Fn(ref sig, _) => {
|
||||
has_late_bound_regions(tcx, &item.generics, sig.decl)
|
||||
}
|
||||
Node::TraitItem(item) => match &item.kind {
|
||||
hir::TraitItemKind::Fn(sig, _) => has_late_bound_regions(tcx, &item.generics, sig.decl),
|
||||
_ => None,
|
||||
},
|
||||
Node::ImplItem(item) => match item.kind {
|
||||
hir::ImplItemKind::Fn(ref sig, _) => {
|
||||
has_late_bound_regions(tcx, &item.generics, sig.decl)
|
||||
}
|
||||
Node::ImplItem(item) => match &item.kind {
|
||||
hir::ImplItemKind::Fn(sig, _) => has_late_bound_regions(tcx, &item.generics, sig.decl),
|
||||
_ => None,
|
||||
},
|
||||
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)
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
Node::Item(item) => match item.kind {
|
||||
hir::ItemKind::Fn(ref sig, .., ref generics, _) => {
|
||||
Node::Item(item) => match &item.kind {
|
||||
hir::ItemKind::Fn(sig, .., generics, _) => {
|
||||
has_late_bound_regions(tcx, generics, sig.decl)
|
||||
}
|
||||
_ => None,
|
||||
|
@ -428,7 +428,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
_ => {}
|
||||
}
|
||||
match item.kind {
|
||||
hir::ItemKind::Fn(_, ref generics, _) => {
|
||||
hir::ItemKind::Fn(_, generics, _) => {
|
||||
self.visit_early_late(item.hir_id(), generics, |this| {
|
||||
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))
|
||||
});
|
||||
}
|
||||
hir::ItemKind::TyAlias(_, ref generics)
|
||||
| hir::ItemKind::Enum(_, ref generics)
|
||||
| hir::ItemKind::Struct(_, ref generics)
|
||||
| hir::ItemKind::Union(_, ref generics)
|
||||
| hir::ItemKind::Trait(_, _, ref generics, ..)
|
||||
| hir::ItemKind::TraitAlias(ref generics, ..)
|
||||
| hir::ItemKind::Impl(hir::Impl { ref generics, .. }) => {
|
||||
hir::ItemKind::TyAlias(_, generics)
|
||||
| hir::ItemKind::Enum(_, generics)
|
||||
| hir::ItemKind::Struct(_, generics)
|
||||
| hir::ItemKind::Union(_, generics)
|
||||
| hir::ItemKind::Trait(_, _, generics, ..)
|
||||
| hir::ItemKind::TraitAlias(generics, ..)
|
||||
| hir::ItemKind::Impl(&hir::Impl { generics, .. }) => {
|
||||
// These kinds of items have only early-bound lifetime parameters.
|
||||
let lifetimes = generics
|
||||
.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>) {
|
||||
match item.kind {
|
||||
hir::ForeignItemKind::Fn(_, _, ref generics) => {
|
||||
hir::ForeignItemKind::Fn(_, _, generics) => {
|
||||
self.visit_early_late(item.hir_id(), generics, |this| {
|
||||
intravisit::walk_foreign_item(this, item);
|
||||
})
|
||||
@ -561,7 +561,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
|
||||
match ty.kind {
|
||||
hir::TyKind::BareFn(ref c) => {
|
||||
hir::TyKind::BareFn(c) => {
|
||||
let (lifetimes, binders): (FxIndexMap<LocalDefId, Region>, Vec<_>) = c
|
||||
.generic_params
|
||||
.iter()
|
||||
@ -587,7 +587,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
intravisit::walk_ty(this, ty);
|
||||
});
|
||||
}
|
||||
hir::TyKind::TraitObject(bounds, ref lifetime, _) => {
|
||||
hir::TyKind::TraitObject(bounds, lifetime, _) => {
|
||||
debug!(?bounds, ?lifetime, "TraitObject");
|
||||
let scope = Scope::TraitRefBoundary { s: self.scope };
|
||||
self.with(scope, |this| {
|
||||
@ -617,7 +617,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
LifetimeName::Error => {}
|
||||
}
|
||||
}
|
||||
hir::TyKind::Ref(ref lifetime_ref, ref mt) => {
|
||||
hir::TyKind::Ref(lifetime_ref, ref mt) => {
|
||||
self.visit_lifetime(lifetime_ref);
|
||||
let scope = Scope::ObjectLifetimeDefault {
|
||||
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
|
||||
// the opaque_ty generics
|
||||
let opaque_ty = self.tcx.hir().item(item_id);
|
||||
match opaque_ty.kind {
|
||||
match &opaque_ty.kind {
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin::TyAlias,
|
||||
..
|
||||
@ -655,7 +655,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
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.
|
||||
@ -720,7 +720,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
intravisit::walk_trait_item(this, trait_item)
|
||||
});
|
||||
}
|
||||
Type(bounds, ref ty) => {
|
||||
Type(bounds, ty) => {
|
||||
let generics = &trait_item.generics;
|
||||
let lifetimes = generics
|
||||
.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| {
|
||||
intravisit::walk_impl_item(this, impl_item)
|
||||
}),
|
||||
Type(ref ty) => {
|
||||
Type(ty) => {
|
||||
let generics = &impl_item.generics;
|
||||
let lifetimes: FxIndexMap<LocalDefId, Region> = generics
|
||||
.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) {
|
||||
for (i, segment) in path.segments.iter().enumerate() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -833,7 +833,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
) {
|
||||
let output = match fd.output {
|
||||
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));
|
||||
intravisit::walk_fn_kind(self, fk);
|
||||
@ -846,13 +846,13 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
for param in generics.params {
|
||||
match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {}
|
||||
GenericParamKind::Type { ref default, .. } => {
|
||||
if let Some(ref ty) = default {
|
||||
this.visit_ty(&ty);
|
||||
GenericParamKind::Type { default, .. } => {
|
||||
if let Some(ty) = default {
|
||||
this.visit_ty(ty);
|
||||
}
|
||||
}
|
||||
GenericParamKind::Const { ref ty, default } => {
|
||||
this.visit_ty(&ty);
|
||||
GenericParamKind::Const { ty, default } => {
|
||||
this.visit_ty(ty);
|
||||
if let Some(default) = default {
|
||||
this.visit_body(this.tcx.hir().body(default.body));
|
||||
}
|
||||
@ -863,9 +863,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
match predicate {
|
||||
&hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
|
||||
hir_id,
|
||||
ref bounded_ty,
|
||||
bounded_ty,
|
||||
bounds,
|
||||
ref bound_generic_params,
|
||||
bound_generic_params,
|
||||
origin,
|
||||
..
|
||||
}) => {
|
||||
@ -905,7 +905,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
})
|
||||
}
|
||||
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
||||
ref lifetime,
|
||||
lifetime,
|
||||
bounds,
|
||||
..
|
||||
}) => {
|
||||
@ -914,7 +914,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
|
||||
if lifetime.res != hir::LifetimeName::Static {
|
||||
for bound in bounds {
|
||||
let hir::GenericBound::Outlives(ref lt) = bound else {
|
||||
let hir::GenericBound::Outlives(lt) = bound else {
|
||||
continue;
|
||||
};
|
||||
if lt.res != hir::LifetimeName::Static {
|
||||
@ -939,8 +939,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
&hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
|
||||
ref lhs_ty,
|
||||
ref rhs_ty,
|
||||
lhs_ty,
|
||||
rhs_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 {
|
||||
if let hir::GenericBound::Outlives(ref lifetime) = *bound {
|
||||
if let hir::GenericBound::Outlives(lifetime) = bound {
|
||||
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
|
||||
// segment; I am not sure it's even currently
|
||||
// valid to have them elsewhere, but even if it
|
||||
|
@ -85,30 +85,30 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
||||
Node::ImplItem(item) => item.generics,
|
||||
|
||||
Node::Item(item) => match item.kind {
|
||||
ItemKind::Impl(ref impl_) => {
|
||||
ItemKind::Impl(impl_) => {
|
||||
if impl_.defaultness.is_default() {
|
||||
is_default_impl_trait =
|
||||
tcx.impl_trait_ref(def_id).map(|t| ty::Binder::dummy(t.subst_identity()));
|
||||
}
|
||||
&impl_.generics
|
||||
impl_.generics
|
||||
}
|
||||
ItemKind::Fn(.., ref generics, _)
|
||||
| ItemKind::TyAlias(_, ref generics)
|
||||
| ItemKind::Enum(_, ref generics)
|
||||
| ItemKind::Struct(_, ref generics)
|
||||
| ItemKind::Union(_, ref generics) => *generics,
|
||||
ItemKind::Fn(.., generics, _)
|
||||
| ItemKind::TyAlias(_, generics)
|
||||
| ItemKind::Enum(_, generics)
|
||||
| ItemKind::Struct(_, 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));
|
||||
*generics
|
||||
generics
|
||||
}
|
||||
ItemKind::OpaqueTy(OpaqueTy { ref generics, .. }) => generics,
|
||||
ItemKind::OpaqueTy(OpaqueTy { generics, .. }) => generics,
|
||||
_ => NO_GENERICS,
|
||||
},
|
||||
|
||||
Node::ForeignItem(item) => match item.kind {
|
||||
ForeignItemKind::Static(..) => NO_GENERICS,
|
||||
ForeignItemKind::Fn(_, _, ref generics) => *generics,
|
||||
ForeignItemKind::Fn(_, _, generics) => generics,
|
||||
ForeignItemKind::Type => NO_GENERICS,
|
||||
},
|
||||
|
||||
@ -350,7 +350,7 @@ 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(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 {
|
||||
debug!("const_evaluatable_predicates_of({:?}): visit impl trait_ref", def_id);
|
||||
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 {
|
||||
hir::ItemKind::Trait(.., ref generics, ref supertraits, _) => (generics, supertraits),
|
||||
hir::ItemKind::TraitAlias(ref generics, ref supertraits) => (generics, supertraits),
|
||||
hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits),
|
||||
hir::ItemKind::TraitAlias(generics, supertraits) => (generics, supertraits),
|
||||
_ => span_bug!(item.span, "super_predicates invoked on non-trait"),
|
||||
};
|
||||
|
||||
@ -612,18 +612,18 @@ pub(super) fn type_param_predicates(
|
||||
|
||||
Node::Item(item) => {
|
||||
match item.kind {
|
||||
ItemKind::Fn(.., ref generics, _)
|
||||
| ItemKind::Impl(hir::Impl { ref generics, .. })
|
||||
| ItemKind::TyAlias(_, ref generics)
|
||||
ItemKind::Fn(.., generics, _)
|
||||
| ItemKind::Impl(&hir::Impl { generics, .. })
|
||||
| ItemKind::TyAlias(_, generics)
|
||||
| ItemKind::OpaqueTy(OpaqueTy {
|
||||
ref generics,
|
||||
generics,
|
||||
origin: hir::OpaqueTyOrigin::TyAlias,
|
||||
..
|
||||
})
|
||||
| ItemKind::Enum(_, ref generics)
|
||||
| ItemKind::Struct(_, ref generics)
|
||||
| ItemKind::Union(_, ref generics) => generics,
|
||||
ItemKind::Trait(_, _, ref generics, ..) => {
|
||||
| ItemKind::Enum(_, generics)
|
||||
| ItemKind::Struct(_, generics)
|
||||
| ItemKind::Union(_, generics) => generics,
|
||||
ItemKind::Trait(_, _, generics, ..) => {
|
||||
// Implied `Self: Trait` and supertrait bounds.
|
||||
if param_id == item_hir_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 {
|
||||
ForeignItemKind::Fn(_, _, ref generics) => generics,
|
||||
ForeignItemKind::Fn(_, _, generics) => generics,
|
||||
_ => return result,
|
||||
},
|
||||
|
||||
@ -681,8 +681,8 @@ impl<'tcx> ItemCtxt<'tcx> {
|
||||
ast_generics
|
||||
.predicates
|
||||
.iter()
|
||||
.filter_map(|wp| match *wp {
|
||||
hir::WherePredicate::BoundPredicate(ref bp) => Some(bp),
|
||||
.filter_map(|wp| match wp {
|
||||
hir::WherePredicate::BoundPredicate(bp) => Some(bp),
|
||||
_ => None,
|
||||
})
|
||||
.flat_map(|bp| {
|
||||
|
@ -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()),
|
||||
},
|
||||
|
||||
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(..) => {
|
||||
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(_) => {
|
||||
let parent_node = tcx.hir().get_parent(hir_id);
|
||||
match parent_node {
|
||||
Node::Ty(&Ty { kind: TyKind::Array(_, ref constant), .. })
|
||||
| Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. })
|
||||
Node::Ty(Ty { kind: TyKind::Array(_, constant), .. })
|
||||
| Node::Expr(Expr { kind: ExprKind::Repeat(_, constant), .. })
|
||||
if constant.hir_id() == hir_id =>
|
||||
{
|
||||
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)
|
||||
}
|
||||
|
||||
Node::Expr(&Expr { kind: ExprKind::ConstBlock(ref anon_const), .. })
|
||||
Node::Expr(Expr { kind: ExprKind::ConstBlock(anon_const), .. })
|
||||
if anon_const.hir_id == hir_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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
Node::TypeBinding(
|
||||
binding @ &TypeBinding {
|
||||
TypeBinding {
|
||||
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) =
|
||||
tcx.hir().get_parent(binding_id)
|
||||
tcx.hir().get_parent(*binding_id)
|
||||
&& e.hir_id == hir_id =>
|
||||
{
|
||||
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_item = assoc_items.find_by_name_and_kind(
|
||||
tcx,
|
||||
binding.ident,
|
||||
*ident,
|
||||
ty::AssocKind::Const,
|
||||
def_id.to_def_id(),
|
||||
);
|
||||
@ -470,9 +471,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
||||
}
|
||||
|
||||
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) =
|
||||
tcx.hir().get_parent(binding_id)
|
||||
tcx.hir().get_parent(*binding_id)
|
||||
&& let Some((idx, _)) =
|
||||
gen_args.args.iter().enumerate().find(|(_, 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_item = assoc_items.find_by_name_and_kind(
|
||||
tcx,
|
||||
binding.ident,
|
||||
*ident,
|
||||
match kind {
|
||||
// I think `<A: T>` type bindings requires that `A` is a type
|
||||
TypeBindingKind::Constraint { .. }
|
||||
|
@ -128,7 +128,7 @@ fn diagnostic_hir_wf_check<'tcx>(
|
||||
},
|
||||
hir::Node::Item(item) => match item.kind {
|
||||
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
|
||||
.path
|
||||
.segments
|
||||
|
@ -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());
|
||||
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)
|
||||
}
|
||||
_ => {
|
||||
@ -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());
|
||||
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())
|
||||
}
|
||||
_ => {
|
||||
@ -371,7 +371,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
|
||||
match start_t.kind() {
|
||||
ty::FnDef(..) => {
|
||||
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;
|
||||
if !generics.params.is_empty() {
|
||||
struct_span_err!(
|
||||
|
@ -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)
|
||||
&& let Some(parent_node) = self.tcx.hir().find(parent_node)
|
||||
&& let hir::Node::Expr(expr) = parent_node {
|
||||
match expr.kind {
|
||||
hir::ExprKind::Path(ref qpath) => {
|
||||
match &expr.kind {
|
||||
hir::ExprKind::Path(qpath) => {
|
||||
self.suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path(
|
||||
err,
|
||||
qpath,
|
||||
|
@ -28,8 +28,8 @@ pub fn solve_constraints<'tcx>(
|
||||
let ConstraintContext { terms_cx, constraints, .. } = constraints_cx;
|
||||
|
||||
let mut solutions = vec![ty::Bivariant; terms_cx.inferred_terms.len()];
|
||||
for &(id, ref variances) in &terms_cx.lang_items {
|
||||
let InferredIndex(start) = terms_cx.inferred_starts[&id];
|
||||
for (id, variances) in &terms_cx.lang_items {
|
||||
let InferredIndex(start) = terms_cx.inferred_starts[id];
|
||||
for (i, &variance) in variances.iter().enumerate() {
|
||||
solutions[start + i] = variance;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user