mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-29 19:47:38 +00:00
Rollup merge of #137350 - nnethercote:remove-Map-3, r=Zalathar
Move methods from Map to TyCtxt, part 3. A follow-up to #137162. r? `@Zalathar`
This commit is contained in:
commit
a24eb0bae9
@ -386,7 +386,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
let hir = self.infcx.tcx.hir();
|
|
||||||
if let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) {
|
if let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) {
|
||||||
let expr = body.value;
|
let expr = body.value;
|
||||||
let place = &self.move_data.move_paths[mpi].place;
|
let place = &self.move_data.move_paths[mpi].place;
|
||||||
@ -402,7 +401,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
if let Some(span) = span
|
if let Some(span) = span
|
||||||
&& let Some(expr) = finder.expr
|
&& let Some(expr) = finder.expr
|
||||||
{
|
{
|
||||||
for (_, expr) in hir.parent_iter(expr.hir_id) {
|
for (_, expr) in tcx.hir_parent_iter(expr.hir_id) {
|
||||||
if let hir::Node::Expr(expr) = expr {
|
if let hir::Node::Expr(expr) = expr {
|
||||||
if expr.span.contains(span) {
|
if expr.span.contains(span) {
|
||||||
// If the let binding occurs within the same loop, then that
|
// If the let binding occurs within the same loop, then that
|
||||||
@ -969,7 +968,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
let mut parent = None;
|
let mut parent = None;
|
||||||
// The top-most loop where the moved expression could be moved to a new binding.
|
// The top-most loop where the moved expression could be moved to a new binding.
|
||||||
let mut outer_most_loop: Option<&hir::Expr<'_>> = None;
|
let mut outer_most_loop: Option<&hir::Expr<'_>> = None;
|
||||||
for (_, node) in tcx.hir().parent_iter(expr.hir_id) {
|
for (_, node) in tcx.hir_parent_iter(expr.hir_id) {
|
||||||
let e = match node {
|
let e = match node {
|
||||||
hir::Node::Expr(e) => e,
|
hir::Node::Expr(e) => e,
|
||||||
hir::Node::LetStmt(hir::LetStmt { els: Some(els), .. }) => {
|
hir::Node::LetStmt(hir::LetStmt { els: Some(els), .. }) => {
|
||||||
@ -1021,8 +1020,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let loop_count: usize = tcx
|
let loop_count: usize = tcx
|
||||||
.hir()
|
.hir_parent_iter(expr.hir_id)
|
||||||
.parent_iter(expr.hir_id)
|
|
||||||
.map(|(_, node)| match node {
|
.map(|(_, node)| match node {
|
||||||
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Loop(..), .. }) => 1,
|
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Loop(..), .. }) => 1,
|
||||||
_ => 0,
|
_ => 0,
|
||||||
@ -1048,8 +1046,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
.collect::<Vec<Span>>();
|
.collect::<Vec<Span>>();
|
||||||
// All of the spans for the loops above the expression with the move error.
|
// All of the spans for the loops above the expression with the move error.
|
||||||
let loop_spans: Vec<_> = tcx
|
let loop_spans: Vec<_> = tcx
|
||||||
.hir()
|
.hir_parent_iter(expr.hir_id)
|
||||||
.parent_iter(expr.hir_id)
|
|
||||||
.filter_map(|(_, node)| match node {
|
.filter_map(|(_, node)| match node {
|
||||||
hir::Node::Expr(hir::Expr { span, kind: hir::ExprKind::Loop(..), .. }) => {
|
hir::Node::Expr(hir::Expr { span, kind: hir::ExprKind::Loop(..), .. }) => {
|
||||||
Some(*span)
|
Some(*span)
|
||||||
@ -1334,7 +1331,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn in_move_closure(&self, expr: &hir::Expr<'_>) -> bool {
|
fn in_move_closure(&self, expr: &hir::Expr<'_>) -> bool {
|
||||||
for (_, node) in self.infcx.tcx.hir().parent_iter(expr.hir_id) {
|
for (_, node) in self.infcx.tcx.hir_parent_iter(expr.hir_id) {
|
||||||
if let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(closure), .. }) = node
|
if let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(closure), .. }) = node
|
||||||
&& let hir::CaptureBy::Value { .. } = closure.capture_clause
|
&& let hir::CaptureBy::Value { .. } = closure.capture_clause
|
||||||
{
|
{
|
||||||
@ -2118,7 +2115,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
issued_span: Span,
|
issued_span: Span,
|
||||||
) {
|
) {
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
let hir = tcx.hir();
|
|
||||||
|
|
||||||
let has_split_at_mut = |ty: Ty<'tcx>| {
|
let has_split_at_mut = |ty: Ty<'tcx>| {
|
||||||
let ty = ty.peel_refs();
|
let ty = ty.peel_refs();
|
||||||
@ -2171,7 +2167,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(object) = hir.parent_id_iter(index1.hir_id).find_map(|id| {
|
let Some(object) = tcx.hir_parent_id_iter(index1.hir_id).find_map(|id| {
|
||||||
if let hir::Node::Expr(expr) = tcx.hir_node(id)
|
if let hir::Node::Expr(expr) = tcx.hir_node(id)
|
||||||
&& let hir::ExprKind::Index(obj, ..) = expr.kind
|
&& let hir::ExprKind::Index(obj, ..) = expr.kind
|
||||||
{
|
{
|
||||||
@ -2189,7 +2185,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(swap_call) = hir.parent_id_iter(object.hir_id).find_map(|id| {
|
let Some(swap_call) = tcx.hir_parent_id_iter(object.hir_id).find_map(|id| {
|
||||||
if let hir::Node::Expr(call) = tcx.hir_node(id)
|
if let hir::Node::Expr(call) = tcx.hir_node(id)
|
||||||
&& let hir::ExprKind::Call(callee, ..) = call.kind
|
&& let hir::ExprKind::Call(callee, ..) = call.kind
|
||||||
&& let hir::ExprKind::Path(qpath) = callee.kind
|
&& let hir::ExprKind::Path(qpath) = callee.kind
|
||||||
|
@ -117,7 +117,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
|||||||
let local_decl = &body.local_decls[dropped_local];
|
let local_decl = &body.local_decls[dropped_local];
|
||||||
|
|
||||||
if let &LocalInfo::IfThenRescopeTemp { if_then } = local_decl.local_info()
|
if let &LocalInfo::IfThenRescopeTemp { if_then } = local_decl.local_info()
|
||||||
&& let Some((_, hir::Node::Expr(expr))) = tcx.hir().parent_iter(if_then).next()
|
&& let Some((_, hir::Node::Expr(expr))) = tcx.hir_parent_iter(if_then).next()
|
||||||
&& let hir::ExprKind::If(cond, conseq, alt) = expr.kind
|
&& let hir::ExprKind::If(cond, conseq, alt) = expr.kind
|
||||||
&& let hir::ExprKind::Let(&hir::LetExpr {
|
&& let hir::ExprKind::Let(&hir::LetExpr {
|
||||||
span: _,
|
span: _,
|
||||||
@ -522,7 +522,7 @@ fn suggest_rewrite_if_let<G: EmissionGuarantee>(
|
|||||||
);
|
);
|
||||||
if expr.span.can_be_used_for_suggestions() && conseq.span.can_be_used_for_suggestions() {
|
if expr.span.can_be_used_for_suggestions() && conseq.span.can_be_used_for_suggestions() {
|
||||||
let needs_block = if let Some(hir::Node::Expr(expr)) =
|
let needs_block = if let Some(hir::Node::Expr(expr)) =
|
||||||
alt.and_then(|alt| tcx.hir().parent_iter(alt.hir_id).next()).map(|(_, node)| node)
|
alt.and_then(|alt| tcx.hir_parent_iter(alt.hir_id).next()).map(|(_, node)| node)
|
||||||
{
|
{
|
||||||
matches!(expr.kind, hir::ExprKind::If(..))
|
matches!(expr.kind, hir::ExprKind::If(..))
|
||||||
} else {
|
} else {
|
||||||
|
@ -388,7 +388,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
|
|
||||||
// Search for an appropriate place for the structured `.clone()` suggestion to be applied.
|
// Search for an appropriate place for the structured `.clone()` suggestion to be applied.
|
||||||
// If we encounter a statement before the borrow error, we insert a statement there.
|
// If we encounter a statement before the borrow error, we insert a statement there.
|
||||||
for (_, node) in tcx.hir().parent_iter(closure_expr.hir_id) {
|
for (_, node) in tcx.hir_parent_iter(closure_expr.hir_id) {
|
||||||
if let Node::Stmt(stmt) = node {
|
if let Node::Stmt(stmt) = node {
|
||||||
let padding = tcx
|
let padding = tcx
|
||||||
.sess
|
.sess
|
||||||
|
@ -404,7 +404,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
pat.kind
|
pat.kind
|
||||||
{
|
{
|
||||||
if upvar_ident.name == kw::SelfLower {
|
if upvar_ident.name == kw::SelfLower {
|
||||||
for (_, node) in self.infcx.tcx.hir().parent_iter(upvar_hir_id) {
|
for (_, node) in self.infcx.tcx.hir_parent_iter(upvar_hir_id) {
|
||||||
if let Some(fn_decl) = node.fn_decl() {
|
if let Some(fn_decl) = node.fn_decl() {
|
||||||
if !matches!(
|
if !matches!(
|
||||||
fn_decl.implicit_self,
|
fn_decl.implicit_self,
|
||||||
@ -934,7 +934,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
err.span_label(sp, format!("cannot {act}"));
|
err.span_label(sp, format!("cannot {act}"));
|
||||||
|
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
let hir = tcx.hir();
|
|
||||||
let closure_id = self.mir_hir_id();
|
let closure_id = self.mir_hir_id();
|
||||||
let closure_span = tcx.def_span(self.mir_def_id());
|
let closure_span = tcx.def_span(self.mir_def_id());
|
||||||
let fn_call_id = tcx.parent_hir_id(closure_id);
|
let fn_call_id = tcx.parent_hir_id(closure_id);
|
||||||
@ -1017,10 +1016,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if look_at_return && hir.get_fn_id_for_return_block(closure_id).is_some() {
|
if look_at_return && tcx.hir_get_fn_id_for_return_block(closure_id).is_some() {
|
||||||
// ...otherwise we are probably in the tail expression of the function, point at the
|
// ...otherwise we are probably in the tail expression of the function, point at the
|
||||||
// return type.
|
// return type.
|
||||||
match tcx.hir_node_by_def_id(hir.get_parent_item(fn_call_id).def_id) {
|
match tcx.hir_node_by_def_id(tcx.hir_get_parent_item(fn_call_id).def_id) {
|
||||||
hir::Node::Item(hir::Item {
|
hir::Node::Item(hir::Item {
|
||||||
ident, kind: hir::ItemKind::Fn { sig, .. }, ..
|
ident, kind: hir::ItemKind::Fn { sig, .. }, ..
|
||||||
})
|
})
|
||||||
|
@ -671,7 +671,6 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
|||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
fn give_name_if_anonymous_region_appears_in_output(&self, fr: RegionVid) -> Option<RegionName> {
|
fn give_name_if_anonymous_region_appears_in_output(&self, fr: RegionVid) -> Option<RegionName> {
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
let hir = tcx.hir();
|
|
||||||
|
|
||||||
let return_ty = self.regioncx.universal_regions().unnormalized_output_ty;
|
let return_ty = self.regioncx.universal_regions().unnormalized_output_ty;
|
||||||
debug!("give_name_if_anonymous_region_appears_in_output: return_ty = {:?}", return_ty);
|
debug!("give_name_if_anonymous_region_appears_in_output: return_ty = {:?}", return_ty);
|
||||||
@ -711,7 +710,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
|||||||
hir::CoroutineSource::Fn,
|
hir::CoroutineSource::Fn,
|
||||||
)) => {
|
)) => {
|
||||||
let parent_item =
|
let parent_item =
|
||||||
tcx.hir_node_by_def_id(hir.get_parent_item(mir_hir_id).def_id);
|
tcx.hir_node_by_def_id(tcx.hir_get_parent_item(mir_hir_id).def_id);
|
||||||
let output = &parent_item
|
let output = &parent_item
|
||||||
.fn_decl()
|
.fn_decl()
|
||||||
.expect("coroutine lowered from async fn should be in fn")
|
.expect("coroutine lowered from async fn should be in fn")
|
||||||
@ -741,7 +740,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
|||||||
hir::CoroutineSource::Fn,
|
hir::CoroutineSource::Fn,
|
||||||
)) => {
|
)) => {
|
||||||
let parent_item =
|
let parent_item =
|
||||||
tcx.hir_node_by_def_id(hir.get_parent_item(mir_hir_id).def_id);
|
tcx.hir_node_by_def_id(tcx.hir_get_parent_item(mir_hir_id).def_id);
|
||||||
let output = &parent_item
|
let output = &parent_item
|
||||||
.fn_decl()
|
.fn_decl()
|
||||||
.expect("coroutine lowered from gen fn should be in fn")
|
.expect("coroutine lowered from gen fn should be in fn")
|
||||||
@ -768,7 +767,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
|||||||
hir::CoroutineSource::Fn,
|
hir::CoroutineSource::Fn,
|
||||||
)) => {
|
)) => {
|
||||||
let parent_item =
|
let parent_item =
|
||||||
tcx.hir_node_by_def_id(hir.get_parent_item(mir_hir_id).def_id);
|
tcx.hir_node_by_def_id(tcx.hir_get_parent_item(mir_hir_id).def_id);
|
||||||
let output = &parent_item
|
let output = &parent_item
|
||||||
.fn_decl()
|
.fn_decl()
|
||||||
.expect("coroutine lowered from async gen fn should be in fn")
|
.expect("coroutine lowered from async gen fn should be in fn")
|
||||||
|
@ -482,7 +482,7 @@ fn best_definition_site_of_opaque<'tcx>(
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
hir::OpaqueTyOrigin::TyAlias { in_assoc_ty: false, .. } => {
|
hir::OpaqueTyOrigin::TyAlias { in_assoc_ty: false, .. } => {
|
||||||
let scope = tcx.hir().get_defining_scope(tcx.local_def_id_to_hir_id(opaque_def_id));
|
let scope = tcx.hir_get_defining_scope(tcx.local_def_id_to_hir_id(opaque_def_id));
|
||||||
let found = if scope == hir::CRATE_HIR_ID {
|
let found = if scope == hir::CRATE_HIR_ID {
|
||||||
tcx.hir_walk_toplevel_module(&mut locator)
|
tcx.hir_walk_toplevel_module(&mut locator)
|
||||||
} else {
|
} else {
|
||||||
|
@ -127,7 +127,7 @@ fn get_owner_return_paths(
|
|||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
) -> Option<(LocalDefId, ReturnsVisitor<'_>)> {
|
) -> Option<(LocalDefId, ReturnsVisitor<'_>)> {
|
||||||
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||||
let parent_id = tcx.hir().get_parent_item(hir_id).def_id;
|
let parent_id = tcx.hir_get_parent_item(hir_id).def_id;
|
||||||
tcx.hir_node_by_def_id(parent_id).body_id().map(|body_id| {
|
tcx.hir_node_by_def_id(parent_id).body_id().map(|body_id| {
|
||||||
let body = tcx.hir_body(body_id);
|
let body = tcx.hir_body(body_id);
|
||||||
let mut visitor = ReturnsVisitor::default();
|
let mut visitor = ReturnsVisitor::default();
|
||||||
|
@ -853,7 +853,7 @@ fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool {
|
|||||||
/// In such cases, suggest using `Self` instead.
|
/// In such cases, suggest using `Self` instead.
|
||||||
fn check_dyn_incompatible_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
|
fn check_dyn_incompatible_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
|
||||||
let (trait_name, trait_def_id) =
|
let (trait_name, trait_def_id) =
|
||||||
match tcx.hir_node_by_def_id(tcx.hir().get_parent_item(item.hir_id()).def_id) {
|
match tcx.hir_node_by_def_id(tcx.hir_get_parent_item(item.hir_id()).def_id) {
|
||||||
hir::Node::Item(item) => match item.kind {
|
hir::Node::Item(item) => match item.kind {
|
||||||
hir::ItemKind::Trait(..) => (item.ident, item.owner_id),
|
hir::ItemKind::Trait(..) => (item.ident, item.owner_id),
|
||||||
_ => return,
|
_ => return,
|
||||||
|
@ -469,7 +469,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||||||
let item = self
|
let item = self
|
||||||
.tcx
|
.tcx
|
||||||
.hir()
|
.hir()
|
||||||
.expect_item(self.tcx.hir().get_parent_item(self.hir_id()).def_id);
|
.expect_item(self.tcx.hir_get_parent_item(self.hir_id()).def_id);
|
||||||
match &item.kind {
|
match &item.kind {
|
||||||
hir::ItemKind::Enum(_, generics)
|
hir::ItemKind::Enum(_, generics)
|
||||||
| hir::ItemKind::Struct(_, generics)
|
| hir::ItemKind::Struct(_, generics)
|
||||||
@ -1349,7 +1349,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor().is_some() => {
|
Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor().is_some() => {
|
||||||
let adt_def_id = tcx.hir().get_parent_item(hir_id).def_id.to_def_id();
|
let adt_def_id = tcx.hir_get_parent_item(hir_id).def_id.to_def_id();
|
||||||
let ty = tcx.type_of(adt_def_id).instantiate_identity();
|
let ty = tcx.type_of(adt_def_id).instantiate_identity();
|
||||||
let inputs = data.fields().iter().map(|f| tcx.type_of(f.def_id).instantiate_identity());
|
let inputs = data.fields().iter().map(|f| tcx.type_of(f.def_id).instantiate_identity());
|
||||||
// constructors for structs with `layout_scalar_valid_range` are unsafe to call
|
// constructors for structs with `layout_scalar_valid_range` are unsafe to call
|
||||||
|
@ -71,7 +71,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
|
|||||||
| Node::Variant(_)
|
| Node::Variant(_)
|
||||||
| Node::Ctor(..)
|
| Node::Ctor(..)
|
||||||
| Node::Field(_) => {
|
| Node::Field(_) => {
|
||||||
let parent_id = tcx.hir().get_parent_item(hir_id);
|
let parent_id = tcx.hir_get_parent_item(hir_id);
|
||||||
Some(parent_id.to_def_id())
|
Some(parent_id.to_def_id())
|
||||||
}
|
}
|
||||||
// FIXME(#43408) always enable this once `lazy_normalization` is
|
// FIXME(#43408) always enable this once `lazy_normalization` is
|
||||||
@ -90,12 +90,12 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
|
|||||||
let parent_did = if let DefKind::AnonConst = tcx.def_kind(parent_did) {
|
let parent_did = if let DefKind::AnonConst = tcx.def_kind(parent_did) {
|
||||||
parent_did
|
parent_did
|
||||||
} else {
|
} else {
|
||||||
tcx.hir().get_parent_item(hir_id).to_def_id()
|
tcx.hir_get_parent_item(hir_id).to_def_id()
|
||||||
};
|
};
|
||||||
debug!(?parent_did);
|
debug!(?parent_did);
|
||||||
|
|
||||||
let mut in_param_ty = false;
|
let mut in_param_ty = false;
|
||||||
for (_parent, node) in tcx.hir().parent_iter(hir_id) {
|
for (_parent, node) in tcx.hir_parent_iter(hir_id) {
|
||||||
if let Some(generics) = node.generics() {
|
if let Some(generics) = node.generics() {
|
||||||
let mut visitor = AnonConstInParamTyDetector { in_param_ty: false, ct: hir_id };
|
let mut visitor = AnonConstInParamTyDetector { in_param_ty: false, ct: hir_id };
|
||||||
|
|
||||||
|
@ -382,8 +382,7 @@ fn const_evaluatable_predicates_of<'tcx>(
|
|||||||
fn is_const_param_default(tcx: TyCtxt<'_>, def: LocalDefId) -> bool {
|
fn is_const_param_default(tcx: TyCtxt<'_>, def: LocalDefId) -> bool {
|
||||||
let hir_id = tcx.local_def_id_to_hir_id(def);
|
let hir_id = tcx.local_def_id_to_hir_id(def);
|
||||||
let (_, parent_node) = tcx
|
let (_, parent_node) = tcx
|
||||||
.hir()
|
.hir_parent_iter(hir_id)
|
||||||
.parent_iter(hir_id)
|
|
||||||
.skip_while(|(_, n)| matches!(n, Node::ConstArg(..)))
|
.skip_while(|(_, n)| matches!(n, Node::ConstArg(..)))
|
||||||
.next()
|
.next()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -107,7 +107,7 @@ fn anon_const_type_of<'tcx>(icx: &ItemCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => {
|
Node::Variant(Variant { disr_expr: Some(ref 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)
|
||||||
}
|
}
|
||||||
// Sort of affects the type system, but only for the purpose of diagnostics
|
// Sort of affects the type system, but only for the purpose of diagnostics
|
||||||
// so no need for ConstArg.
|
// so no need for ConstArg.
|
||||||
@ -257,7 +257,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImplItemKind::Type(ty) => {
|
ImplItemKind::Type(ty) => {
|
||||||
if tcx.impl_trait_ref(tcx.hir().get_parent_item(hir_id)).is_none() {
|
if tcx.impl_trait_ref(tcx.hir_get_parent_item(hir_id)).is_none() {
|
||||||
check_feature_inherent_assoc_ty(tcx, item.span);
|
check_feature_inherent_assoc_ty(tcx, item.span);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +341,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
|||||||
|
|
||||||
Node::Ctor(def) | Node::Variant(Variant { data: 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)).instantiate_identity()
|
tcx.type_of(tcx.hir_get_parent_item(hir_id)).instantiate_identity()
|
||||||
}
|
}
|
||||||
VariantData::Tuple(_, _, ctor) => {
|
VariantData::Tuple(_, _, ctor) => {
|
||||||
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
|
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
|
||||||
|
@ -83,7 +83,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
|
|||||||
#[instrument(skip(tcx), level = "debug")]
|
#[instrument(skip(tcx), level = "debug")]
|
||||||
pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
|
pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
|
||||||
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||||
let scope = tcx.hir().get_defining_scope(hir_id);
|
let scope = tcx.hir_get_defining_scope(hir_id);
|
||||||
let mut locator = TaitConstraintLocator { def_id, tcx, found: None, typeck_types: vec![] };
|
let mut locator = TaitConstraintLocator { def_id, tcx, found: None, typeck_types: vec![] };
|
||||||
|
|
||||||
debug!(?scope);
|
debug!(?scope);
|
||||||
|
@ -134,9 +134,9 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||||||
// is from the 'of_trait' field of the enclosing impl
|
// is from the 'of_trait' field of the enclosing impl
|
||||||
|
|
||||||
let parent = self.tcx.parent_hir_node(self.path_segment.hir_id);
|
let parent = self.tcx.parent_hir_node(self.path_segment.hir_id);
|
||||||
let parent_item = self.tcx.hir_node_by_def_id(
|
let parent_item = self
|
||||||
self.tcx.hir().get_parent_item(self.path_segment.hir_id).def_id,
|
.tcx
|
||||||
);
|
.hir_node_by_def_id(self.tcx.hir_get_parent_item(self.path_segment.hir_id).def_id);
|
||||||
|
|
||||||
// Get the HIR id of the trait ref
|
// Get the HIR id of the trait ref
|
||||||
let hir::Node::TraitRef(hir::TraitRef { hir_ref_id: trait_ref_id, .. }) = parent else {
|
let hir::Node::TraitRef(hir::TraitRef { hir_ref_id: trait_ref_id, .. }) = parent else {
|
||||||
@ -343,7 +343,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||||||
|
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
let mut ty_id = None;
|
let mut ty_id = None;
|
||||||
for (id, node) in self.tcx.hir().parent_iter(path_hir_id) {
|
for (id, node) in self.tcx.hir_parent_iter(path_hir_id) {
|
||||||
debug!(?id);
|
debug!(?id);
|
||||||
if let hir::Node::Ty(_) = node {
|
if let hir::Node::Ty(_) = node {
|
||||||
ty_id = Some(id);
|
ty_id = Some(id);
|
||||||
@ -437,8 +437,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||||||
) -> String {
|
) -> String {
|
||||||
let is_in_a_method_call = self
|
let is_in_a_method_call = self
|
||||||
.tcx
|
.tcx
|
||||||
.hir()
|
.hir_parent_iter(self.path_segment.hir_id)
|
||||||
.parent_iter(self.path_segment.hir_id)
|
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.find_map(|(_, node)| match node {
|
.find_map(|(_, node)| match node {
|
||||||
hir::Node::Expr(expr) => Some(expr),
|
hir::Node::Expr(expr) => Some(expr),
|
||||||
|
@ -736,8 +736,7 @@ fn check_assoc_const_binding_type<'tcx>(
|
|||||||
.map(|ty| crate::errors::TyOfAssocConstBindingNote { assoc_const, ty });
|
.map(|ty| crate::errors::TyOfAssocConstBindingNote { assoc_const, ty });
|
||||||
|
|
||||||
let enclosing_item_owner_id = tcx
|
let enclosing_item_owner_id = tcx
|
||||||
.hir()
|
.hir_parent_owner_iter(hir_id)
|
||||||
.parent_owner_iter(hir_id)
|
|
||||||
.find_map(|(owner_id, parent)| parent.generics().map(|_| owner_id))
|
.find_map(|(owner_id, parent)| parent.generics().map(|_| owner_id))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let generics = tcx.generics_of(enclosing_item_owner_id);
|
let generics = tcx.generics_of(enclosing_item_owner_id);
|
||||||
|
@ -223,7 +223,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
// inside an opaque type while we're interested in the overarching type alias (TAIT).
|
// inside an opaque type while we're interested in the overarching type alias (TAIT).
|
||||||
// FIXME: However, for trait aliases, this incorrectly returns the enclosing module...
|
// FIXME: However, for trait aliases, this incorrectly returns the enclosing module...
|
||||||
&& let item_def_id =
|
&& let item_def_id =
|
||||||
tcx.hir().get_parent_item(tcx.local_def_id_to_hir_id(ty_param_def_id))
|
tcx.hir_get_parent_item(tcx.local_def_id_to_hir_id(ty_param_def_id))
|
||||||
// FIXME: ...which obviously won't have any generics.
|
// FIXME: ...which obviously won't have any generics.
|
||||||
&& let Some(generics) = tcx.hir_get_generics(item_def_id.def_id)
|
&& let Some(generics) = tcx.hir_get_generics(item_def_id.def_id)
|
||||||
{
|
{
|
||||||
@ -979,7 +979,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
qself: &hir::Ty<'_>,
|
qself: &hir::Ty<'_>,
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
if let Some((_, node)) = tcx.hir().parent_iter(qself.hir_id).skip(1).next()
|
if let Some((_, node)) = tcx.hir_parent_iter(qself.hir_id).skip(1).next()
|
||||||
&& let hir::Node::Expr(hir::Expr {
|
&& let hir::Node::Expr(hir::Expr {
|
||||||
kind:
|
kind:
|
||||||
hir::ExprKind::Path(hir::QPath::TypeRelative(
|
hir::ExprKind::Path(hir::QPath::TypeRelative(
|
||||||
@ -1278,8 +1278,7 @@ pub fn prohibit_assoc_item_constraint(
|
|||||||
// Get the parent impl block based on the binding we have
|
// Get the parent impl block based on the binding we have
|
||||||
// and the trait DefId
|
// and the trait DefId
|
||||||
let impl_block = tcx
|
let impl_block = tcx
|
||||||
.hir()
|
.hir_parent_iter(constraint.hir_id)
|
||||||
.parent_iter(constraint.hir_id)
|
|
||||||
.find_map(|(_, node)| node.impl_block_of_trait(def_id));
|
.find_map(|(_, node)| node.impl_block_of_trait(def_id));
|
||||||
|
|
||||||
let type_with_constraints =
|
let type_with_constraints =
|
||||||
|
@ -542,8 +542,7 @@ pub(crate) fn check_generic_arg_count(
|
|||||||
// ```
|
// ```
|
||||||
let parent_is_impl_block = cx
|
let parent_is_impl_block = cx
|
||||||
.tcx()
|
.tcx()
|
||||||
.hir()
|
.hir_parent_owner_iter(seg.hir_id)
|
||||||
.parent_owner_iter(seg.hir_id)
|
|
||||||
.next()
|
.next()
|
||||||
.is_some_and(|(_, owner_node)| owner_node.is_impl_block());
|
.is_some_and(|(_, owner_node)| owner_node.is_impl_block());
|
||||||
if parent_is_impl_block {
|
if parent_is_impl_block {
|
||||||
|
@ -130,7 +130,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
diag: &mut Diag<'_, G>,
|
diag: &mut Diag<'_, G>,
|
||||||
) {
|
) {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
let parent_id = tcx.hir().get_parent_item(self_ty.hir_id).def_id;
|
let parent_id = tcx.hir_get_parent_item(self_ty.hir_id).def_id;
|
||||||
if let hir::Node::Item(hir::Item {
|
if let hir::Node::Item(hir::Item {
|
||||||
kind: hir::ItemKind::Impl(hir::Impl { self_ty: impl_self_ty, of_trait, generics, .. }),
|
kind: hir::ItemKind::Impl(hir::Impl { self_ty: impl_self_ty, of_trait, generics, .. }),
|
||||||
..
|
..
|
||||||
@ -191,7 +191,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
/// Make sure that we are in the condition to suggest `impl Trait`.
|
/// Make sure that we are in the condition to suggest `impl Trait`.
|
||||||
fn maybe_suggest_impl_trait(&self, self_ty: &hir::Ty<'_>, diag: &mut Diag<'_>) -> bool {
|
fn maybe_suggest_impl_trait(&self, self_ty: &hir::Ty<'_>, diag: &mut Diag<'_>) -> bool {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
let parent_id = tcx.hir().get_parent_item(self_ty.hir_id).def_id;
|
let parent_id = tcx.hir_get_parent_item(self_ty.hir_id).def_id;
|
||||||
// FIXME: If `type_alias_impl_trait` is enabled, also look for `Trait0<Ty = Trait1>`
|
// FIXME: If `type_alias_impl_trait` is enabled, also look for `Trait0<Ty = Trait1>`
|
||||||
// and suggest `Trait0<Ty = impl Trait1>`.
|
// and suggest `Trait0<Ty = impl Trait1>`.
|
||||||
// Functions are found in three different contexts.
|
// Functions are found in three different contexts.
|
||||||
@ -321,7 +321,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_suggest_assoc_ty_bound(&self, self_ty: &hir::Ty<'_>, diag: &mut Diag<'_>) {
|
fn maybe_suggest_assoc_ty_bound(&self, self_ty: &hir::Ty<'_>, diag: &mut Diag<'_>) {
|
||||||
let mut parents = self.tcx().hir().parent_iter(self_ty.hir_id);
|
let mut parents = self.tcx().hir_parent_iter(self_ty.hir_id);
|
||||||
|
|
||||||
if let Some((_, hir::Node::AssocItemConstraint(constraint))) = parents.next()
|
if let Some((_, hir::Node::AssocItemConstraint(constraint))) = parents.next()
|
||||||
&& let Some(obj_ty) = constraint.ty()
|
&& let Some(obj_ty) = constraint.ty()
|
||||||
|
@ -1673,8 +1673,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
debug!(item_def_id = ?def_id);
|
debug!(item_def_id = ?def_id);
|
||||||
|
|
||||||
// FIXME: document why/how this is different from `tcx.local_parent(def_id)`
|
// FIXME: document why/how this is different from `tcx.local_parent(def_id)`
|
||||||
let parent_def_id =
|
let parent_def_id = tcx.hir_get_parent_item(tcx.local_def_id_to_hir_id(def_id)).to_def_id();
|
||||||
tcx.hir().get_parent_item(tcx.local_def_id_to_hir_id(def_id)).to_def_id();
|
|
||||||
debug!(?parent_def_id);
|
debug!(?parent_def_id);
|
||||||
|
|
||||||
// If the trait in segment is the same as the trait defining the item,
|
// If the trait in segment is the same as the trait defining the item,
|
||||||
|
@ -251,7 +251,7 @@ pub fn lower_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
|||||||
// In case there are any projections, etc., find the "environment"
|
// In case there are any projections, etc., find the "environment"
|
||||||
// def-ID that will be used to determine the traits/predicates in
|
// def-ID that will be used to determine the traits/predicates in
|
||||||
// scope. This is derived from the enclosing item-like thing.
|
// scope. This is derived from the enclosing item-like thing.
|
||||||
let env_def_id = tcx.hir().get_parent_item(hir_ty.hir_id);
|
let env_def_id = tcx.hir_get_parent_item(hir_ty.hir_id);
|
||||||
collect::ItemCtxt::new(tcx, env_def_id.def_id).lower_ty(hir_ty)
|
collect::ItemCtxt::new(tcx, env_def_id.def_id).lower_ty(hir_ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,6 +262,6 @@ pub fn lower_const_arg_for_rustdoc<'tcx>(
|
|||||||
hir_ct: &hir::ConstArg<'tcx>,
|
hir_ct: &hir::ConstArg<'tcx>,
|
||||||
feed: FeedConstTy,
|
feed: FeedConstTy,
|
||||||
) -> Const<'tcx> {
|
) -> Const<'tcx> {
|
||||||
let env_def_id = tcx.hir().get_parent_item(hir_ct.hir_id);
|
let env_def_id = tcx.hir_get_parent_item(hir_ct.hir_id);
|
||||||
collect::ItemCtxt::new(tcx, env_def_id.def_id).lowerer().lower_const_arg(hir_ct, feed)
|
collect::ItemCtxt::new(tcx, env_def_id.def_id).lowerer().lower_const_arg(hir_ct, feed)
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clau
|
|||||||
// parent of generics returned by `generics_of`
|
// parent of generics returned by `generics_of`
|
||||||
//
|
//
|
||||||
// In the above code we want the anon const to have predicates in its param env for `'b: 'a`
|
// In the above code we want the anon const to have predicates in its param env for `'b: 'a`
|
||||||
let item_def_id = tcx.hir().get_parent_item(id);
|
let item_def_id = tcx.hir_get_parent_item(id);
|
||||||
// In the above code example we would be calling `inferred_outlives_of(Foo)` here
|
// In the above code example we would be calling `inferred_outlives_of(Foo)` here
|
||||||
tcx.inferred_outlives_of(item_def_id)
|
tcx.inferred_outlives_of(item_def_id)
|
||||||
} else {
|
} else {
|
||||||
|
@ -346,7 +346,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let hir = self.tcx.hir();
|
|
||||||
let fn_decl_span = if let hir::Node::Expr(hir::Expr {
|
let fn_decl_span = if let hir::Node::Expr(hir::Expr {
|
||||||
kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
|
kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
|
||||||
..
|
..
|
||||||
@ -368,7 +367,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}),
|
}),
|
||||||
..
|
..
|
||||||
}),
|
}),
|
||||||
)) = hir.parent_iter(hir_id).nth(3)
|
)) = self.tcx.hir_parent_iter(hir_id).nth(3)
|
||||||
{
|
{
|
||||||
// Actually need to unwrap one more layer of HIR to get to
|
// Actually need to unwrap one more layer of HIR to get to
|
||||||
// the _real_ closure...
|
// the _real_ closure...
|
||||||
|
@ -1752,7 +1752,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let Some((_, hir::Node::Expr(expr))) =
|
let Some((_, hir::Node::Expr(expr))) =
|
||||||
fcx.tcx.hir().parent_iter(id).nth(1)
|
fcx.tcx.hir_parent_iter(id).nth(1)
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
@ -1909,7 +1909,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
|||||||
found,
|
found,
|
||||||
block_or_return_id,
|
block_or_return_id,
|
||||||
);
|
);
|
||||||
if let Some(cond_expr) = fcx.tcx.hir().get_if_cause(expr.hir_id)
|
if let Some(cond_expr) = fcx.tcx.hir_get_if_cause(expr.hir_id)
|
||||||
&& expected.is_unit()
|
&& expected.is_unit()
|
||||||
&& !pointing_at_return_type
|
&& !pointing_at_return_type
|
||||||
// If the block is from an external macro or try (`?`) desugaring, then
|
// If the block is from an external macro or try (`?`) desugaring, then
|
||||||
|
@ -156,7 +156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
&& segment.ident.name.as_str() == name
|
&& segment.ident.name.as_str() == name
|
||||||
&& let Res::Local(hir_id) = path.res
|
&& let Res::Local(hir_id) = path.res
|
||||||
&& let Some((_, hir::Node::Expr(match_expr))) =
|
&& let Some((_, hir::Node::Expr(match_expr))) =
|
||||||
self.tcx.hir().parent_iter(hir_id).nth(2)
|
self.tcx.hir_parent_iter(hir_id).nth(2)
|
||||||
&& let hir::ExprKind::Match(scrutinee, _, _) = match_expr.kind
|
&& let hir::ExprKind::Match(scrutinee, _, _) = match_expr.kind
|
||||||
&& let hir::ExprKind::Tup(exprs) = scrutinee.kind
|
&& let hir::ExprKind::Tup(exprs) = scrutinee.kind
|
||||||
&& let hir::ExprKind::AddrOf(_, _, macro_arg) = exprs[idx].kind
|
&& let hir::ExprKind::AddrOf(_, _, macro_arg) = exprs[idx].kind
|
||||||
@ -841,7 +841,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// The pattern we have is an fn argument.
|
// The pattern we have is an fn argument.
|
||||||
&& let hir::Node::Param(hir::Param { ty_span, .. }) =
|
&& let hir::Node::Param(hir::Param { ty_span, .. }) =
|
||||||
self.tcx.parent_hir_node(pat.hir_id)
|
self.tcx.parent_hir_node(pat.hir_id)
|
||||||
&& let item = self.tcx.hir().get_parent_item(pat.hir_id)
|
&& let item = self.tcx.hir_get_parent_item(pat.hir_id)
|
||||||
&& let item = self.tcx.hir_owner_node(item)
|
&& let item = self.tcx.hir_owner_node(item)
|
||||||
&& let Some(fn_decl) = item.fn_decl()
|
&& let Some(fn_decl) = item.fn_decl()
|
||||||
|
|
||||||
|
@ -1130,7 +1130,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
statement_kind: kind,
|
statement_kind: kind,
|
||||||
};
|
};
|
||||||
|
|
||||||
let encl_item_id = self.tcx.hir().get_parent_item(expr.hir_id);
|
let encl_item_id = self.tcx.hir_get_parent_item(expr.hir_id);
|
||||||
|
|
||||||
if let hir::Node::Item(hir::Item {
|
if let hir::Node::Item(hir::Item {
|
||||||
kind: hir::ItemKind::Fn { .. },
|
kind: hir::ItemKind::Fn { .. },
|
||||||
@ -1279,7 +1279,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// Check if our original expression is a child of the condition of a while loop.
|
// Check if our original expression is a child of the condition of a while loop.
|
||||||
// If it is, then we have a situation like `while Some(0) = value.get(0) {`,
|
// If it is, then we have a situation like `while Some(0) = value.get(0) {`,
|
||||||
// where `while let` was more likely intended.
|
// where `while let` was more likely intended.
|
||||||
if self.tcx.hir().parent_id_iter(original_expr_id).any(|id| id == expr.hir_id) {
|
if self.tcx.hir_parent_id_iter(original_expr_id).any(|id| id == expr.hir_id) {
|
||||||
then(expr);
|
then(expr);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1774,7 +1774,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn suggest_array_len(&self, expr: &'tcx hir::Expr<'tcx>, array_len: u64) {
|
fn suggest_array_len(&self, expr: &'tcx hir::Expr<'tcx>, array_len: u64) {
|
||||||
let parent_node = self.tcx.hir().parent_iter(expr.hir_id).find(|(_, node)| {
|
let parent_node = self.tcx.hir_parent_iter(expr.hir_id).find(|(_, node)| {
|
||||||
!matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::AddrOf(..), .. }))
|
!matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::AddrOf(..), .. }))
|
||||||
});
|
});
|
||||||
let Some((_, hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), .. }))) = parent_node else {
|
let Some((_, hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), .. }))) = parent_node else {
|
||||||
|
@ -856,7 +856,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>)> {
|
) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>)> {
|
||||||
// Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or
|
// Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or
|
||||||
// `while` before reaching it, as block tail returns are not available in them.
|
// `while` before reaching it, as block tail returns are not available in them.
|
||||||
self.tcx.hir().get_fn_id_for_return_block(blk_id).and_then(|item_id| {
|
self.tcx.hir_get_fn_id_for_return_block(blk_id).and_then(|item_id| {
|
||||||
match self.tcx.hir_node(item_id) {
|
match self.tcx.hir_node(item_id) {
|
||||||
Node::Item(&hir::Item {
|
Node::Item(&hir::Item {
|
||||||
kind: hir::ItemKind::Fn { sig, .. }, owner_id, ..
|
kind: hir::ItemKind::Fn { sig, .. }, owner_id, ..
|
||||||
|
@ -2052,7 +2052,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parent_item_span(&self, id: HirId) -> Option<Span> {
|
fn parent_item_span(&self, id: HirId) -> Option<Span> {
|
||||||
let node = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(id).def_id);
|
let node = self.tcx.hir_node_by_def_id(self.tcx.hir_get_parent_item(id).def_id);
|
||||||
match node {
|
match node {
|
||||||
Node::Item(&hir::Item { kind: hir::ItemKind::Fn { body: body_id, .. }, .. })
|
Node::Item(&hir::Item { kind: hir::ItemKind::Fn { body: body_id, .. }, .. })
|
||||||
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(_, body_id), .. }) => {
|
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(_, body_id), .. }) => {
|
||||||
@ -2179,7 +2179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
{
|
{
|
||||||
let mut block_num = 0;
|
let mut block_num = 0;
|
||||||
let mut found_semi = false;
|
let mut found_semi = false;
|
||||||
for (hir_id, node) in self.tcx.hir().parent_iter(binding_hir_id) {
|
for (hir_id, node) in self.tcx.hir_parent_iter(binding_hir_id) {
|
||||||
// Don't proceed into parent bodies
|
// Don't proceed into parent bodies
|
||||||
if hir_id.owner != binding_hir_id.owner {
|
if hir_id.owner != binding_hir_id.owner {
|
||||||
break;
|
break;
|
||||||
@ -2521,7 +2521,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// Try to find earlier invocations of this closure to find if the type mismatch
|
// Try to find earlier invocations of this closure to find if the type mismatch
|
||||||
// is because of inference. If we find one, point at them.
|
// is because of inference. If we find one, point at them.
|
||||||
let mut call_finder = FindClosureArg { tcx: self.tcx, calls: vec![] };
|
let mut call_finder = FindClosureArg { tcx: self.tcx, calls: vec![] };
|
||||||
let parent_def_id = self.tcx.hir().get_parent_item(call_expr.hir_id).def_id;
|
let parent_def_id = self.tcx.hir_get_parent_item(call_expr.hir_id).def_id;
|
||||||
match self.tcx.hir_node_by_def_id(parent_def_id) {
|
match self.tcx.hir_node_by_def_id(parent_def_id) {
|
||||||
hir::Node::Item(item) => call_finder.visit_item(item),
|
hir::Node::Item(item) => call_finder.visit_item(item),
|
||||||
hir::Node::TraitItem(item) => call_finder.visit_trait_item(item),
|
hir::Node::TraitItem(item) => call_finder.visit_trait_item(item),
|
||||||
|
@ -308,7 +308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
};
|
};
|
||||||
let mut tuple_indexes = Vec::new();
|
let mut tuple_indexes = Vec::new();
|
||||||
let mut expr_id = expr.hir_id;
|
let mut expr_id = expr.hir_id;
|
||||||
for (parent_id, node) in self.tcx.hir().parent_iter(expr.hir_id) {
|
for (parent_id, node) in self.tcx.hir_parent_iter(expr.hir_id) {
|
||||||
match node {
|
match node {
|
||||||
Node::Expr(&Expr { kind: ExprKind::Tup(subs), .. }) => {
|
Node::Expr(&Expr { kind: ExprKind::Tup(subs), .. }) => {
|
||||||
tuple_indexes.push(
|
tuple_indexes.push(
|
||||||
@ -565,7 +565,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
// Do not suggest `Box::new` in const context.
|
// Do not suggest `Box::new` in const context.
|
||||||
if self.tcx.hir().is_inside_const_context(hir_id) || !expected.is_box() || found.is_box() {
|
if self.tcx.hir_is_inside_const_context(hir_id) || !expected.is_box() || found.is_box() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if self.may_coerce(Ty::new_box(self.tcx, found), expected) {
|
if self.may_coerce(Ty::new_box(self.tcx, found), expected) {
|
||||||
@ -645,7 +645,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
) -> bool {
|
) -> bool {
|
||||||
// Handle #68197.
|
// Handle #68197.
|
||||||
|
|
||||||
if self.tcx.hir().is_inside_const_context(expr.hir_id) {
|
if self.tcx.hir_is_inside_const_context(expr.hir_id) {
|
||||||
// Do not suggest `Box::new` in const context.
|
// Do not suggest `Box::new` in const context.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1084,8 +1084,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let in_loop = self.is_loop(id)
|
let in_loop = self.is_loop(id)
|
||||||
|| self
|
|| self
|
||||||
.tcx
|
.tcx
|
||||||
.hir()
|
.hir_parent_iter(id)
|
||||||
.parent_iter(id)
|
|
||||||
.take_while(|(_, node)| {
|
.take_while(|(_, node)| {
|
||||||
// look at parents until we find the first body owner
|
// look at parents until we find the first body owner
|
||||||
node.body_id().is_none()
|
node.body_id().is_none()
|
||||||
@ -1095,8 +1094,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let in_local_statement = self.is_local_statement(id)
|
let in_local_statement = self.is_local_statement(id)
|
||||||
|| self
|
|| self
|
||||||
.tcx
|
.tcx
|
||||||
.hir()
|
.hir_parent_iter(id)
|
||||||
.parent_iter(id)
|
|
||||||
.any(|(parent_id, _)| self.is_local_statement(parent_id));
|
.any(|(parent_id, _)| self.is_local_statement(parent_id));
|
||||||
|
|
||||||
if in_loop && in_local_statement {
|
if in_loop && in_local_statement {
|
||||||
@ -1111,7 +1109,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let scope = self.tcx.hir().parent_iter(id).find(|(_, node)| {
|
let scope = self.tcx.hir_parent_iter(id).find(|(_, node)| {
|
||||||
matches!(
|
matches!(
|
||||||
node,
|
node,
|
||||||
Node::Expr(Expr { kind: ExprKind::Closure(..), .. })
|
Node::Expr(Expr { kind: ExprKind::Closure(..), .. })
|
||||||
@ -1168,7 +1166,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// -------------^^^^^^^-
|
// -------------^^^^^^^-
|
||||||
// Don't add semicolon `;` at the end of `dbg!(x)` expr
|
// Don't add semicolon `;` at the end of `dbg!(x)` expr
|
||||||
fn is_in_arm<'tcx>(expr: &'tcx hir::Expr<'tcx>, tcx: TyCtxt<'tcx>) -> bool {
|
fn is_in_arm<'tcx>(expr: &'tcx hir::Expr<'tcx>, tcx: TyCtxt<'tcx>) -> bool {
|
||||||
for (_, node) in tcx.hir().parent_iter(expr.hir_id) {
|
for (_, node) in tcx.hir_parent_iter(expr.hir_id) {
|
||||||
match node {
|
match node {
|
||||||
hir::Node::Block(block) => {
|
hir::Node::Block(block) => {
|
||||||
if let Some(ret) = block.expr
|
if let Some(ret) = block.expr
|
||||||
@ -1411,8 +1409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let hir = self.tcx.hir();
|
let cond_parent = self.tcx.hir_parent_iter(expr.hir_id).find(|(_, node)| {
|
||||||
let cond_parent = hir.parent_iter(expr.hir_id).find(|(_, node)| {
|
|
||||||
!matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(op, _, _), .. }) if op.node == hir::BinOpKind::And)
|
!matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(op, _, _), .. }) if op.node == hir::BinOpKind::And)
|
||||||
});
|
});
|
||||||
// Don't suggest:
|
// Don't suggest:
|
||||||
@ -2048,11 +2045,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let map = self.tcx.hir();
|
|
||||||
let returned = matches!(
|
let returned = matches!(
|
||||||
self.tcx.parent_hir_node(expr.hir_id),
|
self.tcx.parent_hir_node(expr.hir_id),
|
||||||
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Ret(_), .. })
|
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Ret(_), .. })
|
||||||
) || map.get_fn_id_for_return_block(expr.hir_id).is_some();
|
) || self.tcx.hir_get_fn_id_for_return_block(expr.hir_id).is_some();
|
||||||
if returned
|
if returned
|
||||||
&& let ty::Adt(e, args_e) = expected.kind()
|
&& let ty::Adt(e, args_e) = expected.kind()
|
||||||
&& let ty::Adt(f, args_f) = found.kind()
|
&& let ty::Adt(f, args_f) = found.kind()
|
||||||
@ -2095,9 +2091,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let hir = tcx.hir();
|
|
||||||
let enclosing_scope =
|
let enclosing_scope =
|
||||||
hir.get_enclosing_scope(expr.hir_id).map(|hir_id| tcx.hir_node(hir_id));
|
tcx.hir_get_enclosing_scope(expr.hir_id).map(|hir_id| tcx.hir_node(hir_id));
|
||||||
|
|
||||||
// Get tail expr of the enclosing block or body
|
// Get tail expr of the enclosing block or body
|
||||||
let tail_expr = if let Some(Node::Block(hir::Block { expr, .. })) = enclosing_scope
|
let tail_expr = if let Some(Node::Block(hir::Block { expr, .. })) = enclosing_scope
|
||||||
@ -3098,7 +3093,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
|expr: &hir::Expr<'_>| matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::Neg, ..));
|
|expr: &hir::Expr<'_>| matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::Neg, ..));
|
||||||
let is_uint = |ty: Ty<'_>| matches!(ty.kind(), ty::Uint(..));
|
let is_uint = |ty: Ty<'_>| matches!(ty.kind(), ty::Uint(..));
|
||||||
|
|
||||||
let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id);
|
let in_const_context = self.tcx.hir_is_inside_const_context(expr.hir_id);
|
||||||
|
|
||||||
let suggest_fallible_into_or_lhs_from =
|
let suggest_fallible_into_or_lhs_from =
|
||||||
|err: &mut Diag<'_>, exp_to_found_is_fallible: bool| {
|
|err: &mut Diag<'_>, exp_to_found_is_fallible: bool| {
|
||||||
@ -3142,7 +3137,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
let suggest_to_change_suffix_or_into =
|
let suggest_to_change_suffix_or_into =
|
||||||
|err: &mut Diag<'_>, found_to_exp_is_fallible: bool, exp_to_found_is_fallible: bool| {
|
|err: &mut Diag<'_>, found_to_exp_is_fallible: bool, exp_to_found_is_fallible: bool| {
|
||||||
let exp_is_lhs = expected_ty_expr.is_some_and(|e| self.tcx.hir().is_lhs(e.hir_id));
|
let exp_is_lhs = expected_ty_expr.is_some_and(|e| self.tcx.hir_is_lhs(e.hir_id));
|
||||||
|
|
||||||
if exp_is_lhs {
|
if exp_is_lhs {
|
||||||
return;
|
return;
|
||||||
|
@ -2390,7 +2390,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
long_ty_path: &mut Option<PathBuf>,
|
long_ty_path: &mut Option<PathBuf>,
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
if let SelfSource::MethodCall(expr) = source {
|
if let SelfSource::MethodCall(expr) = source {
|
||||||
for (_, parent) in tcx.hir().parent_iter(expr.hir_id).take(5) {
|
for (_, parent) in tcx.hir_parent_iter(expr.hir_id).take(5) {
|
||||||
if let Node::Expr(parent_expr) = parent {
|
if let Node::Expr(parent_expr) = parent {
|
||||||
let lang_item = match parent_expr.kind {
|
let lang_item = match parent_expr.kind {
|
||||||
ExprKind::Struct(qpath, _, _) => match *qpath {
|
ExprKind::Struct(qpath, _, _) => match *qpath {
|
||||||
|
@ -946,7 +946,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let var_ty = self.resolve_vars_if_possible(var_ty);
|
let var_ty = self.resolve_vars_if_possible(var_ty);
|
||||||
let msg = format!("first introduced with type `{var_ty}` here");
|
let msg = format!("first introduced with type `{var_ty}` here");
|
||||||
err.span_label(hir.span(var_id), msg);
|
err.span_label(hir.span(var_id), msg);
|
||||||
let in_match = hir.parent_iter(var_id).any(|(_, n)| {
|
let in_match = self.tcx.hir_parent_iter(var_id).any(|(_, n)| {
|
||||||
matches!(
|
matches!(
|
||||||
n,
|
n,
|
||||||
hir::Node::Expr(hir::Expr {
|
hir::Node::Expr(hir::Expr {
|
||||||
|
@ -1934,7 +1934,7 @@ fn apply_capture_kind_on_capture_ty<'tcx>(
|
|||||||
|
|
||||||
/// Returns the Span of where the value with the provided HirId would be dropped
|
/// Returns the Span of where the value with the provided HirId would be dropped
|
||||||
fn drop_location_span(tcx: TyCtxt<'_>, hir_id: HirId) -> Span {
|
fn drop_location_span(tcx: TyCtxt<'_>, hir_id: HirId) -> Span {
|
||||||
let owner_id = tcx.hir().get_enclosing_scope(hir_id).unwrap();
|
let owner_id = tcx.hir_get_enclosing_scope(hir_id).unwrap();
|
||||||
|
|
||||||
let owner_node = tcx.hir_node(owner_id);
|
let owner_node = tcx.hir_node(owner_id);
|
||||||
let owner_span = match owner_node {
|
let owner_span = match owner_node {
|
||||||
|
@ -466,7 +466,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
|||||||
MethodLateContext::TraitAutoImpl => {}
|
MethodLateContext::TraitAutoImpl => {}
|
||||||
// If the method is an impl for an item with docs_hidden, don't doc.
|
// If the method is an impl for an item with docs_hidden, don't doc.
|
||||||
MethodLateContext::PlainImpl => {
|
MethodLateContext::PlainImpl => {
|
||||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
|
let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id());
|
||||||
let impl_ty = cx.tcx.type_of(parent).instantiate_identity();
|
let impl_ty = cx.tcx.type_of(parent).instantiate_identity();
|
||||||
let outerdef = match impl_ty.kind() {
|
let outerdef = match impl_ty.kind() {
|
||||||
ty::Adt(def, _) => Some(def.did()),
|
ty::Adt(def, _) => Some(def.did()),
|
||||||
|
@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
|
|||||||
let is_copy = cx.type_is_copy_modulo_regions(arg_ty);
|
let is_copy = cx.type_is_copy_modulo_regions(arg_ty);
|
||||||
let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr);
|
let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr);
|
||||||
let let_underscore_ignore_sugg = || {
|
let let_underscore_ignore_sugg = || {
|
||||||
if let Some((_, node)) = cx.tcx.hir().parent_iter(expr.hir_id).nth(0)
|
if let Some((_, node)) = cx.tcx.hir_parent_iter(expr.hir_id).nth(0)
|
||||||
&& let Node::Stmt(stmt) = node
|
&& let Node::Stmt(stmt) = node
|
||||||
&& let StmtKind::Semi(e) = stmt.kind
|
&& let StmtKind::Semi(e) = stmt.kind
|
||||||
&& e.hir_id == expr.hir_id
|
&& e.hir_id == expr.hir_id
|
||||||
|
@ -95,7 +95,7 @@ pub(crate) struct IfLetRescope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn expr_parent_is_else(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
|
fn expr_parent_is_else(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
|
||||||
let Some((_, hir::Node::Expr(expr))) = tcx.hir().parent_iter(hir_id).next() else {
|
let Some((_, hir::Node::Expr(expr))) = tcx.hir_parent_iter(hir_id).next() else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let hir::ExprKind::If(_cond, _conseq, Some(alt)) = expr.kind else { return false };
|
let hir::ExprKind::If(_cond, _conseq, Some(alt)) = expr.kind else { return false };
|
||||||
@ -103,7 +103,7 @@ fn expr_parent_is_else(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn expr_parent_is_stmt(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
|
fn expr_parent_is_stmt(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
|
||||||
let mut parents = tcx.hir().parent_iter(hir_id);
|
let mut parents = tcx.hir_parent_iter(hir_id);
|
||||||
let stmt = match parents.next() {
|
let stmt = match parents.next() {
|
||||||
Some((_, hir::Node::Stmt(stmt))) => stmt,
|
Some((_, hir::Node::Stmt(stmt))) => stmt,
|
||||||
Some((_, hir::Node::Block(_) | hir::Node::Arm(_))) => return true,
|
Some((_, hir::Node::Block(_) | hir::Node::Arm(_))) => return true,
|
||||||
|
@ -497,7 +497,7 @@ impl Diagnostics {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (hir_id, _parent) in cx.tcx.hir().parent_iter(current_id) {
|
for (hir_id, _parent) in cx.tcx.hir_parent_iter(current_id) {
|
||||||
if let Some(owner_did) = hir_id.as_owner()
|
if let Some(owner_did) = hir_id.as_owner()
|
||||||
&& cx.tcx.has_attr(owner_did, sym::rustc_lint_diagnostics)
|
&& cx.tcx.has_attr(owner_did, sym::rustc_lint_diagnostics)
|
||||||
{
|
{
|
||||||
@ -512,7 +512,7 @@ impl Diagnostics {
|
|||||||
//
|
//
|
||||||
// Otherwise, emit a `DIAGNOSTIC_OUTSIDE_OF_IMPL` lint.
|
// Otherwise, emit a `DIAGNOSTIC_OUTSIDE_OF_IMPL` lint.
|
||||||
let mut is_inside_appropriate_impl = false;
|
let mut is_inside_appropriate_impl = false;
|
||||||
for (_hir_id, parent) in cx.tcx.hir().parent_iter(current_id) {
|
for (_hir_id, parent) in cx.tcx.hir_parent_iter(current_id) {
|
||||||
debug!(?parent);
|
debug!(?parent);
|
||||||
if let Node::Item(Item { kind: ItemKind::Impl(impl_), .. }) = parent
|
if let Node::Item(Item { kind: ItemKind::Impl(impl_), .. }) = parent
|
||||||
&& let Impl { of_trait: Some(of_trait), .. } = impl_
|
&& let Impl { of_trait: Some(of_trait), .. } = impl_
|
||||||
|
@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for ShadowedIntoIter {
|
|||||||
// we should just suggest removing the `.into_iter()` or changing it to `.iter()`
|
// we should just suggest removing the `.into_iter()` or changing it to `.iter()`
|
||||||
// to disambiguate if we want to iterate by-value or by-ref.
|
// to disambiguate if we want to iterate by-value or by-ref.
|
||||||
let sub = if let Some((_, hir::Node::Expr(parent_expr))) =
|
let sub = if let Some((_, hir::Node::Expr(parent_expr))) =
|
||||||
cx.tcx.hir().parent_iter(expr.hir_id).nth(1)
|
cx.tcx.hir_parent_iter(expr.hir_id).nth(1)
|
||||||
&& let hir::ExprKind::Match(arg, [_], hir::MatchSource::ForLoopDesugar) =
|
&& let hir::ExprKind::Match(arg, [_], hir::MatchSource::ForLoopDesugar) =
|
||||||
&parent_expr.kind
|
&parent_expr.kind
|
||||||
&& let hir::ExprKind::Call(path, [_]) = &arg.kind
|
&& let hir::ExprKind::Call(path, [_]) = &arg.kind
|
||||||
|
@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for UnqualifiedLocalImports {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let encl_item_id = cx.tcx.hir().get_parent_item(item.hir_id());
|
let encl_item_id = cx.tcx.hir_get_parent_item(item.hir_id());
|
||||||
let encl_item = cx.tcx.hir_node_by_def_id(encl_item_id.def_id);
|
let encl_item = cx.tcx.hir_node_by_def_id(encl_item_id.def_id);
|
||||||
if encl_item.fn_kind().is_some() {
|
if encl_item.fn_kind().is_some() {
|
||||||
// `use` in a method -- don't lint, that leads to too many undesirable lints
|
// `use` in a method -- don't lint, that leads to too many undesirable lints
|
||||||
|
@ -28,22 +28,22 @@ pub struct Map<'hir> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator that walks up the ancestor tree of a given `HirId`.
|
/// An iterator that walks up the ancestor tree of a given `HirId`.
|
||||||
/// Constructed using `tcx.hir().parent_iter(hir_id)`.
|
/// Constructed using `tcx.hir_parent_iter(hir_id)`.
|
||||||
struct ParentHirIterator<'hir> {
|
struct ParentHirIterator<'tcx> {
|
||||||
current_id: HirId,
|
current_id: HirId,
|
||||||
map: Map<'hir>,
|
tcx: TyCtxt<'tcx>,
|
||||||
// Cache the current value of `hir_owner_nodes` to avoid repeatedly calling the same query for
|
// Cache the current value of `hir_owner_nodes` to avoid repeatedly calling the same query for
|
||||||
// the same owner, which will uselessly record many times the same query dependency.
|
// the same owner, which will uselessly record many times the same query dependency.
|
||||||
current_owner_nodes: Option<&'hir OwnerNodes<'hir>>,
|
current_owner_nodes: Option<&'tcx OwnerNodes<'tcx>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'hir> ParentHirIterator<'hir> {
|
impl<'tcx> ParentHirIterator<'tcx> {
|
||||||
fn new(map: Map<'hir>, current_id: HirId) -> ParentHirIterator<'hir> {
|
fn new(tcx: TyCtxt<'tcx>, current_id: HirId) -> ParentHirIterator<'tcx> {
|
||||||
ParentHirIterator { current_id, map, current_owner_nodes: None }
|
ParentHirIterator { current_id, tcx, current_owner_nodes: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'hir> Iterator for ParentHirIterator<'hir> {
|
impl<'tcx> Iterator for ParentHirIterator<'tcx> {
|
||||||
type Item = HirId;
|
type Item = HirId;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
@ -56,10 +56,10 @@ impl<'hir> Iterator for ParentHirIterator<'hir> {
|
|||||||
let parent_id = if local_id == ItemLocalId::ZERO {
|
let parent_id = if local_id == ItemLocalId::ZERO {
|
||||||
// We go from an owner to its parent, so clear the cache.
|
// We go from an owner to its parent, so clear the cache.
|
||||||
self.current_owner_nodes = None;
|
self.current_owner_nodes = None;
|
||||||
self.map.tcx.hir_owner_parent(owner)
|
self.tcx.hir_owner_parent(owner)
|
||||||
} else {
|
} else {
|
||||||
let owner_nodes =
|
let owner_nodes =
|
||||||
self.current_owner_nodes.get_or_insert_with(|| self.map.tcx.hir_owner_nodes(owner));
|
self.current_owner_nodes.get_or_insert_with(|| self.tcx.hir_owner_nodes(owner));
|
||||||
let parent_local_id = owner_nodes.nodes[local_id].parent;
|
let parent_local_id = owner_nodes.nodes[local_id].parent;
|
||||||
// HIR indexing should have checked that.
|
// HIR indexing should have checked that.
|
||||||
debug_assert_ne!(parent_local_id, local_id);
|
debug_assert_ne!(parent_local_id, local_id);
|
||||||
@ -74,33 +74,33 @@ impl<'hir> Iterator for ParentHirIterator<'hir> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator that walks up the ancestor tree of a given `HirId`.
|
/// An iterator that walks up the ancestor tree of a given `HirId`.
|
||||||
/// Constructed using `tcx.hir().parent_owner_iter(hir_id)`.
|
/// Constructed using `tcx.hir_parent_owner_iter(hir_id)`.
|
||||||
pub struct ParentOwnerIterator<'hir> {
|
pub struct ParentOwnerIterator<'tcx> {
|
||||||
current_id: HirId,
|
current_id: HirId,
|
||||||
map: Map<'hir>,
|
tcx: TyCtxt<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'hir> Iterator for ParentOwnerIterator<'hir> {
|
impl<'tcx> Iterator for ParentOwnerIterator<'tcx> {
|
||||||
type Item = (OwnerId, OwnerNode<'hir>);
|
type Item = (OwnerId, OwnerNode<'tcx>);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if self.current_id.local_id.index() != 0 {
|
if self.current_id.local_id.index() != 0 {
|
||||||
self.current_id.local_id = ItemLocalId::ZERO;
|
self.current_id.local_id = ItemLocalId::ZERO;
|
||||||
let node = self.map.tcx.hir_owner_node(self.current_id.owner);
|
let node = self.tcx.hir_owner_node(self.current_id.owner);
|
||||||
return Some((self.current_id.owner, node));
|
return Some((self.current_id.owner, node));
|
||||||
}
|
}
|
||||||
if self.current_id == CRATE_HIR_ID {
|
if self.current_id == CRATE_HIR_ID {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let parent_id = self.map.tcx.hir_def_key(self.current_id.owner.def_id).parent;
|
let parent_id = self.tcx.hir_def_key(self.current_id.owner.def_id).parent;
|
||||||
let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| {
|
let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| {
|
||||||
let def_id = LocalDefId { local_def_index };
|
let def_id = LocalDefId { local_def_index };
|
||||||
self.map.tcx.local_def_id_to_hir_id(def_id).owner
|
self.tcx.local_def_id_to_hir_id(def_id).owner
|
||||||
});
|
});
|
||||||
self.current_id = HirId::make_owner(parent_id.def_id);
|
self.current_id = HirId::make_owner(parent_id.def_id);
|
||||||
|
|
||||||
let node = self.map.tcx.hir_owner_node(self.current_id.owner);
|
let node = self.tcx.hir_owner_node(self.current_id.owner);
|
||||||
Some((self.current_id.owner, node))
|
Some((self.current_id.owner, node))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
/// Returns `HirId` of the parent HIR node of node with this `hir_id`.
|
/// Returns `HirId` of the parent HIR node of node with this `hir_id`.
|
||||||
/// Returns the same `hir_id` if and only if `hir_id == CRATE_HIR_ID`.
|
/// Returns the same `hir_id` if and only if `hir_id == CRATE_HIR_ID`.
|
||||||
///
|
///
|
||||||
/// If calling repeatedly and iterating over parents, prefer [`Map::parent_iter`].
|
/// If calling repeatedly and iterating over parents, prefer [`TyCtxt::hir_parent_iter`].
|
||||||
pub fn parent_hir_id(self, hir_id: HirId) -> HirId {
|
pub fn parent_hir_id(self, hir_id: HirId) -> HirId {
|
||||||
let HirId { owner, local_id } = hir_id;
|
let HirId { owner, local_id } = hir_id;
|
||||||
if local_id == ItemLocalId::ZERO {
|
if local_id == ItemLocalId::ZERO {
|
||||||
@ -242,7 +242,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn hir_enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
|
pub fn hir_enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
|
||||||
for (_, node) in self.hir().parent_iter(hir_id) {
|
for (_, node) in self.hir_parent_iter(hir_id) {
|
||||||
if let Some((def_id, _)) = node.associated_body() {
|
if let Some((def_id, _)) = node.associated_body() {
|
||||||
return def_id;
|
return def_id;
|
||||||
}
|
}
|
||||||
@ -498,33 +498,31 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
f(LocalModDefId::new_unchecked(module.def_id))
|
f(LocalModDefId::new_unchecked(module.def_id))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<'hir> Map<'hir> {
|
|
||||||
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
|
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
|
||||||
/// until the crate root is reached. Prefer this over your own loop using `parent_id`.
|
/// until the crate root is reached. Prefer this over your own loop using `parent_id`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parent_id_iter(self, current_id: HirId) -> impl Iterator<Item = HirId> + 'hir {
|
pub fn hir_parent_id_iter(self, current_id: HirId) -> impl Iterator<Item = HirId> + 'tcx {
|
||||||
ParentHirIterator::new(self, current_id)
|
ParentHirIterator::new(self, current_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
|
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
|
||||||
/// until the crate root is reached. Prefer this over your own loop using `parent_id`.
|
/// until the crate root is reached. Prefer this over your own loop using `parent_id`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parent_iter(self, current_id: HirId) -> impl Iterator<Item = (HirId, Node<'hir>)> {
|
pub fn hir_parent_iter(self, current_id: HirId) -> impl Iterator<Item = (HirId, Node<'tcx>)> {
|
||||||
self.parent_id_iter(current_id).map(move |id| (id, self.tcx.hir_node(id)))
|
self.hir_parent_id_iter(current_id).map(move |id| (id, self.hir_node(id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
|
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
|
||||||
/// until the crate root is reached. Prefer this over your own loop using `parent_id`.
|
/// until the crate root is reached. Prefer this over your own loop using `parent_id`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parent_owner_iter(self, current_id: HirId) -> ParentOwnerIterator<'hir> {
|
pub fn hir_parent_owner_iter(self, current_id: HirId) -> ParentOwnerIterator<'tcx> {
|
||||||
ParentOwnerIterator { current_id, map: self }
|
ParentOwnerIterator { current_id, tcx: self }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if the node is left-hand side of an assignment.
|
/// Checks if the node is left-hand side of an assignment.
|
||||||
pub fn is_lhs(self, id: HirId) -> bool {
|
pub fn hir_is_lhs(self, id: HirId) -> bool {
|
||||||
match self.tcx.parent_hir_node(id) {
|
match self.parent_hir_node(id) {
|
||||||
Node::Expr(expr) => match expr.kind {
|
Node::Expr(expr) => match expr.kind {
|
||||||
ExprKind::Assign(lhs, _rhs, _span) => lhs.hir_id == id,
|
ExprKind::Assign(lhs, _rhs, _span) => lhs.hir_id == id,
|
||||||
_ => false,
|
_ => false,
|
||||||
@ -535,8 +533,8 @@ impl<'hir> Map<'hir> {
|
|||||||
|
|
||||||
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
|
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
|
||||||
/// Used exclusively for diagnostics, to avoid suggestion function calls.
|
/// Used exclusively for diagnostics, to avoid suggestion function calls.
|
||||||
pub fn is_inside_const_context(self, hir_id: HirId) -> bool {
|
pub fn hir_is_inside_const_context(self, hir_id: HirId) -> bool {
|
||||||
self.tcx.hir_body_const_context(self.tcx.hir_enclosing_body_owner(hir_id)).is_some()
|
self.hir_body_const_context(self.hir_enclosing_body_owner(hir_id)).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the `HirId` for `id`'s enclosing function *if* the `id` block or return is
|
/// Retrieves the `HirId` for `id`'s enclosing function *if* the `id` block or return is
|
||||||
@ -561,12 +559,11 @@ impl<'hir> Map<'hir> {
|
|||||||
/// false
|
/// false
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_fn_id_for_return_block(self, id: HirId) -> Option<HirId> {
|
pub fn hir_get_fn_id_for_return_block(self, id: HirId) -> Option<HirId> {
|
||||||
let enclosing_body_owner =
|
let enclosing_body_owner = self.local_def_id_to_hir_id(self.hir_enclosing_body_owner(id));
|
||||||
self.tcx.local_def_id_to_hir_id(self.tcx.hir_enclosing_body_owner(id));
|
|
||||||
|
|
||||||
// Return `None` if the `id` expression is not the returned value of the enclosing body
|
// Return `None` if the `id` expression is not the returned value of the enclosing body
|
||||||
let mut iter = [id].into_iter().chain(self.parent_id_iter(id)).peekable();
|
let mut iter = [id].into_iter().chain(self.hir_parent_id_iter(id)).peekable();
|
||||||
while let Some(cur_id) = iter.next() {
|
while let Some(cur_id) = iter.next() {
|
||||||
if enclosing_body_owner == cur_id {
|
if enclosing_body_owner == cur_id {
|
||||||
break;
|
break;
|
||||||
@ -574,14 +571,16 @@ impl<'hir> Map<'hir> {
|
|||||||
|
|
||||||
// A return statement is always the value returned from the enclosing body regardless of
|
// A return statement is always the value returned from the enclosing body regardless of
|
||||||
// what the parent expressions are.
|
// what the parent expressions are.
|
||||||
if let Node::Expr(Expr { kind: ExprKind::Ret(_), .. }) = self.tcx.hir_node(cur_id) {
|
if let Node::Expr(Expr { kind: ExprKind::Ret(_), .. }) = self.hir_node(cur_id) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the current expression's value doesnt get used as the parent expressions value then return `None`
|
// If the current expression's value doesnt get used as the parent expressions value
|
||||||
|
// then return `None`
|
||||||
if let Some(&parent_id) = iter.peek() {
|
if let Some(&parent_id) = iter.peek() {
|
||||||
match self.tcx.hir_node(parent_id) {
|
match self.hir_node(parent_id) {
|
||||||
// The current node is not the tail expression of the block expression parent expr.
|
// The current node is not the tail expression of the block expression parent
|
||||||
|
// expr.
|
||||||
Node::Block(Block { expr: Some(e), .. }) if cur_id != e.hir_id => return None,
|
Node::Block(Block { expr: Some(e), .. }) if cur_id != e.hir_id => return None,
|
||||||
Node::Block(Block { expr: Some(e), .. })
|
Node::Block(Block { expr: Some(e), .. })
|
||||||
if matches!(e.kind, ExprKind::If(_, _, None)) =>
|
if matches!(e.kind, ExprKind::If(_, _, None)) =>
|
||||||
@ -589,7 +588,8 @@ impl<'hir> Map<'hir> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The current expression's value does not pass up through these parent expressions
|
// The current expression's value does not pass up through these parent
|
||||||
|
// expressions.
|
||||||
Node::Block(Block { expr: None, .. })
|
Node::Block(Block { expr: None, .. })
|
||||||
| Node::Expr(Expr { kind: ExprKind::Loop(..), .. })
|
| Node::Expr(Expr { kind: ExprKind::Loop(..), .. })
|
||||||
| Node::LetStmt(..) => return None,
|
| Node::LetStmt(..) => return None,
|
||||||
@ -606,11 +606,11 @@ impl<'hir> Map<'hir> {
|
|||||||
/// parent item is in this map. The "parent item" is the closest parent node
|
/// parent item is in this map. The "parent item" is the closest parent node
|
||||||
/// in the HIR which is recorded by the map and is an item, either an item
|
/// in the HIR which is recorded by the map and is an item, either an item
|
||||||
/// in a module, trait, or impl.
|
/// in a module, trait, or impl.
|
||||||
pub fn get_parent_item(self, hir_id: HirId) -> OwnerId {
|
pub fn hir_get_parent_item(self, hir_id: HirId) -> OwnerId {
|
||||||
if hir_id.local_id != ItemLocalId::ZERO {
|
if hir_id.local_id != ItemLocalId::ZERO {
|
||||||
// If this is a child of a HIR owner, return the owner.
|
// If this is a child of a HIR owner, return the owner.
|
||||||
hir_id.owner
|
hir_id.owner
|
||||||
} else if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() {
|
} else if let Some((def_id, _node)) = self.hir_parent_owner_iter(hir_id).next() {
|
||||||
def_id
|
def_id
|
||||||
} else {
|
} else {
|
||||||
CRATE_OWNER_ID
|
CRATE_OWNER_ID
|
||||||
@ -622,8 +622,8 @@ impl<'hir> Map<'hir> {
|
|||||||
///
|
///
|
||||||
/// Used by error reporting when there's a type error in an if or match arm caused by the
|
/// Used by error reporting when there's a type error in an if or match arm caused by the
|
||||||
/// expression needing to be unit.
|
/// expression needing to be unit.
|
||||||
pub fn get_if_cause(self, hir_id: HirId) -> Option<&'hir Expr<'hir>> {
|
pub fn hir_get_if_cause(self, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> {
|
||||||
for (_, node) in self.parent_iter(hir_id) {
|
for (_, node) in self.hir_parent_iter(hir_id) {
|
||||||
match node {
|
match node {
|
||||||
Node::Item(_)
|
Node::Item(_)
|
||||||
| Node::ForeignItem(_)
|
| Node::ForeignItem(_)
|
||||||
@ -640,8 +640,8 @@ impl<'hir> Map<'hir> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the nearest enclosing scope. A scope is roughly an item or block.
|
/// Returns the nearest enclosing scope. A scope is roughly an item or block.
|
||||||
pub fn get_enclosing_scope(self, hir_id: HirId) -> Option<HirId> {
|
pub fn hir_get_enclosing_scope(self, hir_id: HirId) -> Option<HirId> {
|
||||||
for (hir_id, node) in self.parent_iter(hir_id) {
|
for (hir_id, node) in self.hir_parent_iter(hir_id) {
|
||||||
if let Node::Item(Item {
|
if let Node::Item(Item {
|
||||||
kind:
|
kind:
|
||||||
ItemKind::Fn { .. }
|
ItemKind::Fn { .. }
|
||||||
@ -667,18 +667,20 @@ impl<'hir> Map<'hir> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the defining scope for an opaque type definition.
|
/// Returns the defining scope for an opaque type definition.
|
||||||
pub fn get_defining_scope(self, id: HirId) -> HirId {
|
pub fn hir_get_defining_scope(self, id: HirId) -> HirId {
|
||||||
let mut scope = id;
|
let mut scope = id;
|
||||||
loop {
|
loop {
|
||||||
scope = self.get_enclosing_scope(scope).unwrap_or(CRATE_HIR_ID);
|
scope = self.hir_get_enclosing_scope(scope).unwrap_or(CRATE_HIR_ID);
|
||||||
if scope == CRATE_HIR_ID || !matches!(self.tcx.hir_node(scope), Node::Block(_)) {
|
if scope == CRATE_HIR_ID || !matches!(self.hir_node(scope), Node::Block(_)) {
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'hir> Map<'hir> {
|
||||||
pub fn get_foreign_abi(self, hir_id: HirId) -> ExternAbi {
|
pub fn get_foreign_abi(self, hir_id: HirId) -> ExternAbi {
|
||||||
let parent = self.get_parent_item(hir_id);
|
let parent = self.tcx.hir_get_parent_item(hir_id);
|
||||||
if let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) =
|
if let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) =
|
||||||
self.tcx.hir_owner_node(parent)
|
self.tcx.hir_owner_node(parent)
|
||||||
{
|
{
|
||||||
|
@ -131,7 +131,7 @@ impl ShallowLintLevelMap {
|
|||||||
let mut owner = start.owner;
|
let mut owner = start.owner;
|
||||||
let mut specs = &self.specs;
|
let mut specs = &self.specs;
|
||||||
|
|
||||||
for parent in tcx.hir().parent_id_iter(start) {
|
for parent in tcx.hir_parent_id_iter(start) {
|
||||||
if parent.owner != owner {
|
if parent.owner != owner {
|
||||||
owner = parent.owner;
|
owner = parent.owner;
|
||||||
specs = &tcx.shallow_lint_levels_on(owner).specs;
|
specs = &tcx.shallow_lint_levels_on(owner).specs;
|
||||||
|
@ -373,7 +373,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
// Deprecated attributes apply in-crate and cross-crate.
|
// Deprecated attributes apply in-crate and cross-crate.
|
||||||
if let Some(id) = id {
|
if let Some(id) = id {
|
||||||
if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
|
if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
|
||||||
let parent_def_id = self.hir().get_parent_item(id);
|
let parent_def_id = self.hir_get_parent_item(id);
|
||||||
let skip = self
|
let skip = self
|
||||||
.lookup_deprecation_entry(parent_def_id.to_def_id())
|
.lookup_deprecation_entry(parent_def_id.to_def_id())
|
||||||
.is_some_and(|parent_depr| parent_depr.same_origin(&depr_entry));
|
.is_some_and(|parent_depr| parent_depr.same_origin(&depr_entry));
|
||||||
|
@ -3019,7 +3019,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
/// Find the crate root and the appropriate span where `use` and outer attributes can be
|
/// Find the crate root and the appropriate span where `use` and outer attributes can be
|
||||||
/// inserted at.
|
/// inserted at.
|
||||||
pub fn crate_level_attribute_injection_span(self, hir_id: HirId) -> Option<Span> {
|
pub fn crate_level_attribute_injection_span(self, hir_id: HirId) -> Option<Span> {
|
||||||
for (_hir_id, node) in self.hir().parent_iter(hir_id) {
|
for (_hir_id, node) in self.hir_parent_iter(hir_id) {
|
||||||
if let hir::Node::Crate(m) = node {
|
if let hir::Node::Crate(m) = node {
|
||||||
return Some(m.spans.inject_use_span.shrink_to_lo());
|
return Some(m.spans.inject_use_span.shrink_to_lo());
|
||||||
}
|
}
|
||||||
|
@ -751,7 +751,7 @@ impl UnsafeOpKind {
|
|||||||
span: Span,
|
span: Span,
|
||||||
suggest_unsafe_block: bool,
|
suggest_unsafe_block: bool,
|
||||||
) {
|
) {
|
||||||
let parent_id = tcx.hir().get_parent_item(hir_id);
|
let parent_id = tcx.hir_get_parent_item(hir_id);
|
||||||
let parent_owner = tcx.hir_owner_node(parent_id);
|
let parent_owner = tcx.hir_owner_node(parent_id);
|
||||||
let should_suggest = parent_owner.fn_sig().is_some_and(|sig| {
|
let should_suggest = parent_owner.fn_sig().is_some_and(|sig| {
|
||||||
// Do not suggest for safe target_feature functions
|
// Do not suggest for safe target_feature functions
|
||||||
@ -921,7 +921,7 @@ impl UnsafeOpKind {
|
|||||||
hir_context: HirId,
|
hir_context: HirId,
|
||||||
unsafe_op_in_unsafe_fn_allowed: bool,
|
unsafe_op_in_unsafe_fn_allowed: bool,
|
||||||
) {
|
) {
|
||||||
let note_non_inherited = tcx.hir().parent_iter(hir_context).find(|(id, node)| {
|
let note_non_inherited = tcx.hir_parent_iter(hir_context).find(|(id, node)| {
|
||||||
if let hir::Node::Expr(block) = node
|
if let hir::Node::Expr(block) = node
|
||||||
&& let hir::ExprKind::Block(block, _) = block.kind
|
&& let hir::ExprKind::Block(block, _) = block.kind
|
||||||
&& let hir::BlockCheckMode::UnsafeBlock(_) = block.rules
|
&& let hir::BlockCheckMode::UnsafeBlock(_) = block.rules
|
||||||
|
@ -1041,7 +1041,7 @@ fn find_fallback_pattern_typo<'tcx>(
|
|||||||
let mut imported = vec![];
|
let mut imported = vec![];
|
||||||
let mut imported_spans = vec![];
|
let mut imported_spans = vec![];
|
||||||
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(cx.typing_env);
|
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(cx.typing_env);
|
||||||
let parent = cx.tcx.hir().get_parent_item(hir_id);
|
let parent = cx.tcx.hir_get_parent_item(hir_id);
|
||||||
|
|
||||||
for item in cx.tcx.hir_crate_items(()).free_items() {
|
for item in cx.tcx.hir_crate_items(()).free_items() {
|
||||||
if let DefKind::Use = cx.tcx.def_kind(item.owner_id) {
|
if let DefKind::Use = cx.tcx.def_kind(item.owner_id) {
|
||||||
@ -1137,7 +1137,7 @@ fn find_fallback_pattern_typo<'tcx>(
|
|||||||
} else {
|
} else {
|
||||||
// Look for local bindings for people that might have gotten confused with how
|
// Look for local bindings for people that might have gotten confused with how
|
||||||
// `let` and `const` works.
|
// `let` and `const` works.
|
||||||
for (_, node) in cx.tcx.hir().parent_iter(hir_id) {
|
for (_, node) in cx.tcx.hir_parent_iter(hir_id) {
|
||||||
match node {
|
match node {
|
||||||
hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Let(let_stmt), .. }) => {
|
hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Let(let_stmt), .. }) => {
|
||||||
if let hir::PatKind::Binding(_, _, binding_name, _) = let_stmt.pat.kind {
|
if let hir::PatKind::Binding(_, _, binding_name, _) = let_stmt.pat.kind {
|
||||||
|
@ -48,7 +48,7 @@ fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>)
|
|||||||
match impl_item.kind {
|
match impl_item.kind {
|
||||||
hir::ImplItemKind::Const(..) => Target::AssocConst,
|
hir::ImplItemKind::Const(..) => Target::AssocConst,
|
||||||
hir::ImplItemKind::Fn(..) => {
|
hir::ImplItemKind::Fn(..) => {
|
||||||
let parent_def_id = tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
|
let parent_def_id = tcx.hir_get_parent_item(impl_item.hir_id()).def_id;
|
||||||
let containing_item = tcx.hir().expect_item(parent_def_id);
|
let containing_item = tcx.hir().expect_item(parent_def_id);
|
||||||
let containing_impl_is_for_trait = match &containing_item.kind {
|
let containing_impl_is_for_trait = match &containing_item.kind {
|
||||||
hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(),
|
hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(),
|
||||||
@ -868,7 +868,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
let span = meta.span();
|
let span = meta.span();
|
||||||
if let Some(location) = match target {
|
if let Some(location) = match target {
|
||||||
Target::AssocTy => {
|
Target::AssocTy => {
|
||||||
let parent_def_id = self.tcx.hir().get_parent_item(hir_id).def_id;
|
let parent_def_id = self.tcx.hir_get_parent_item(hir_id).def_id;
|
||||||
let containing_item = self.tcx.hir().expect_item(parent_def_id);
|
let containing_item = self.tcx.hir().expect_item(parent_def_id);
|
||||||
if Target::from_item(containing_item) == Target::Impl {
|
if Target::from_item(containing_item) == Target::Impl {
|
||||||
Some("type alias in implementation block")
|
Some("type alias in implementation block")
|
||||||
@ -877,7 +877,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Target::AssocConst => {
|
Target::AssocConst => {
|
||||||
let parent_def_id = self.tcx.hir().get_parent_item(hir_id).def_id;
|
let parent_def_id = self.tcx.hir_get_parent_item(hir_id).def_id;
|
||||||
let containing_item = self.tcx.hir().expect_item(parent_def_id);
|
let containing_item = self.tcx.hir().expect_item(parent_def_id);
|
||||||
// We can't link to trait impl's consts.
|
// We can't link to trait impl's consts.
|
||||||
let err = "associated constant in trait implementation block";
|
let err = "associated constant in trait implementation block";
|
||||||
@ -1161,7 +1161,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
// insert a bang between `#` and `[...`
|
// insert a bang between `#` and `[...`
|
||||||
let bang_span = attr.span.lo() + BytePos(1);
|
let bang_span = attr.span.lo() + BytePos(1);
|
||||||
let sugg = (attr.style == AttrStyle::Outer
|
let sugg = (attr.style == AttrStyle::Outer
|
||||||
&& self.tcx.hir().get_parent_item(hir_id) == CRATE_OWNER_ID)
|
&& self.tcx.hir_get_parent_item(hir_id) == CRATE_OWNER_ID)
|
||||||
.then_some(errors::AttrCrateLevelOnlySugg {
|
.then_some(errors::AttrCrateLevelOnlySugg {
|
||||||
attr: attr.span.with_lo(bang_span).with_hi(bang_span),
|
attr: attr.span.with_lo(bang_span).with_hi(bang_span),
|
||||||
});
|
});
|
||||||
@ -1449,7 +1449,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
|
|
||||||
// `#[must_use]` can be applied to a trait method definition with a default body
|
// `#[must_use]` can be applied to a trait method definition with a default body
|
||||||
if let Target::Method(MethodKind::Trait { body: true }) = target
|
if let Target::Method(MethodKind::Trait { body: true }) = target
|
||||||
&& let parent_def_id = self.tcx.hir().get_parent_item(hir_id).def_id
|
&& let parent_def_id = self.tcx.hir_get_parent_item(hir_id).def_id
|
||||||
&& let containing_item = self.tcx.hir().expect_item(parent_def_id)
|
&& let containing_item = self.tcx.hir().expect_item(parent_def_id)
|
||||||
&& let hir::ItemKind::Trait(..) = containing_item.kind
|
&& let hir::ItemKind::Trait(..) = containing_item.kind
|
||||||
{
|
{
|
||||||
@ -2580,7 +2580,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
..
|
..
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
let parent_did = self.tcx.hir().get_parent_item(hir_id).to_def_id();
|
let parent_did = self.tcx.hir_get_parent_item(hir_id).to_def_id();
|
||||||
let parent_span = self.tcx.def_span(parent_did);
|
let parent_span = self.tcx.def_span(parent_did);
|
||||||
let parent_force_inline_attr =
|
let parent_force_inline_attr =
|
||||||
self.tcx.get_attr(parent_did, sym::rustc_force_inline);
|
self.tcx.get_attr(parent_did, sym::rustc_force_inline);
|
||||||
|
@ -1623,7 +1623,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
|
|||||||
&& let hir::Node::Pat(pat) = self.ir.tcx.hir_node(var_hid)
|
&& let hir::Node::Pat(pat) = self.ir.tcx.hir_node(var_hid)
|
||||||
&& let hir::Node::Param(hir::Param { ty_span, .. }) =
|
&& let hir::Node::Param(hir::Param { ty_span, .. }) =
|
||||||
self.ir.tcx.parent_hir_node(pat.hir_id)
|
self.ir.tcx.parent_hir_node(pat.hir_id)
|
||||||
&& let item_id = self.ir.tcx.hir().get_parent_item(pat.hir_id)
|
&& let item_id = self.ir.tcx.hir_get_parent_item(pat.hir_id)
|
||||||
&& let item = self.ir.tcx.hir_owner_node(item_id)
|
&& let item = self.ir.tcx.hir_owner_node(item_id)
|
||||||
&& let Some(fn_decl) = item.fn_decl()
|
&& let Some(fn_decl) = item.fn_decl()
|
||||||
&& let hir::PatKind::Binding(hir::BindingMode::MUT, _hir_id, ident, _) = pat.kind
|
&& let hir::PatKind::Binding(hir::BindingMode::MUT, _hir_id, ident, _) = pat.kind
|
||||||
|
@ -645,7 +645,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
|
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
|
||||||
let impl_def_id = self.tcx.hir().get_parent_item(ii.hir_id());
|
let impl_def_id = self.tcx.hir_get_parent_item(ii.hir_id());
|
||||||
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
|
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
|
||||||
self.check_missing_stability(ii.owner_id.def_id, ii.span);
|
self.check_missing_stability(ii.owner_id.def_id, ii.span);
|
||||||
self.check_missing_const_stability(ii.owner_id.def_id, ii.span);
|
self.check_missing_const_stability(ii.owner_id.def_id, ii.span);
|
||||||
|
@ -146,7 +146,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
if let ObligationCauseCode::ReturnValue(hir_id)
|
if let ObligationCauseCode::ReturnValue(hir_id)
|
||||||
| ObligationCauseCode::BlockTailExpression(hir_id, ..) = cause.code()
|
| ObligationCauseCode::BlockTailExpression(hir_id, ..) = cause.code()
|
||||||
{
|
{
|
||||||
let parent_id = tcx.hir().get_parent_item(*hir_id);
|
let parent_id = tcx.hir_get_parent_item(*hir_id);
|
||||||
if let Some(fn_decl) = tcx.hir_fn_decl_by_hir_id(parent_id.into()) {
|
if let Some(fn_decl) = tcx.hir_fn_decl_by_hir_id(parent_id.into()) {
|
||||||
let mut span: MultiSpan = fn_decl.output.span().into();
|
let mut span: MultiSpan = fn_decl.output.span().into();
|
||||||
let mut spans = Vec::new();
|
let mut spans = Vec::new();
|
||||||
@ -472,7 +472,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
|
) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
|
||||||
match tcx.hir_get_if_local(def_id)? {
|
match tcx.hir_get_if_local(def_id)? {
|
||||||
Node::ImplItem(impl_item) => {
|
Node::ImplItem(impl_item) => {
|
||||||
let impl_did = tcx.hir().get_parent_item(impl_item.hir_id());
|
let impl_did = tcx.hir_get_parent_item(impl_item.hir_id());
|
||||||
if let hir::OwnerNode::Item(Item {
|
if let hir::OwnerNode::Item(Item {
|
||||||
kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
|
kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
|
||||||
..
|
..
|
||||||
@ -484,7 +484,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Node::TraitItem(trait_item) => {
|
Node::TraitItem(trait_item) => {
|
||||||
let trait_id = tcx.hir().get_parent_item(trait_item.hir_id());
|
let trait_id = tcx.hir_get_parent_item(trait_item.hir_id());
|
||||||
debug_assert_eq!(tcx.def_kind(trait_id.def_id), hir::def::DefKind::Trait);
|
debug_assert_eq!(tcx.def_kind(trait_id.def_id), hir::def::DefKind::Trait);
|
||||||
// The method being called is defined in the `trait`, but the `'static`
|
// The method being called is defined in the `trait`, but the `'static`
|
||||||
// obligation comes from the `impl`. Find that `impl` so that we can point
|
// obligation comes from the `impl`. Find that `impl` so that we can point
|
||||||
|
@ -586,7 +586,7 @@ impl<T> Trait<T> for X {
|
|||||||
hir::Node::TraitItem(item) => item.hir_id(),
|
hir::Node::TraitItem(item) => item.hir_id(),
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
let parent = tcx.hir().get_parent_item(hir_id).def_id;
|
let parent = tcx.hir_get_parent_item(hir_id).def_id;
|
||||||
self.suggest_constraint(diag, msg, parent.into(), proj_ty, ty)
|
self.suggest_constraint(diag, msg, parent.into(), proj_ty, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -820,7 +820,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||||||
// When `body_owner` is an `impl` or `trait` item, look in its associated types for
|
// When `body_owner` is an `impl` or `trait` item, look in its associated types for
|
||||||
// `expected` and point at it.
|
// `expected` and point at it.
|
||||||
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||||
let parent_id = tcx.hir().get_parent_item(hir_id);
|
let parent_id = tcx.hir_get_parent_item(hir_id);
|
||||||
let item = tcx.hir_node_by_def_id(parent_id.def_id);
|
let item = tcx.hir_node_by_def_id(parent_id.def_id);
|
||||||
|
|
||||||
debug!("expected_projection parent item {:?}", item);
|
debug!("expected_projection parent item {:?}", item);
|
||||||
|
@ -587,7 +587,7 @@ fn attempt_dyn_to_impl_suggestion(tcx: TyCtxt<'_>, hir_id: Option<hir::HirId>, e
|
|||||||
// `type Alias = Box<dyn DynIncompatibleTrait>;` to
|
// `type Alias = Box<dyn DynIncompatibleTrait>;` to
|
||||||
// `type Alias = Box<impl DynIncompatibleTrait>;`
|
// `type Alias = Box<impl DynIncompatibleTrait>;`
|
||||||
let Some((_id, first_non_type_parent_node)) =
|
let Some((_id, first_non_type_parent_node)) =
|
||||||
tcx.hir().parent_iter(hir_id).find(|(_id, node)| !matches!(node, hir::Node::Ty(_)))
|
tcx.hir_parent_iter(hir_id).find(|(_id, node)| !matches!(node, hir::Node::Ty(_)))
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -1552,7 +1552,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut Diag<'_>,
|
err: &mut Diag<'_>,
|
||||||
) {
|
) {
|
||||||
let hir = self.tcx.hir();
|
|
||||||
if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code().peel_derives()
|
if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code().peel_derives()
|
||||||
&& let hir::Node::Expr(expr) = self.tcx.hir_node(*hir_id)
|
&& let hir::Node::Expr(expr) = self.tcx.hir_node(*hir_id)
|
||||||
{
|
{
|
||||||
@ -1562,7 +1561,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||||||
// it is from the local crate.
|
// it is from the local crate.
|
||||||
|
|
||||||
// use nth(1) to skip one layer of desugaring from `IntoIter::into_iter`
|
// use nth(1) to skip one layer of desugaring from `IntoIter::into_iter`
|
||||||
if let Some((_, hir::Node::Expr(await_expr))) = hir.parent_iter(*hir_id).nth(1)
|
if let Some((_, hir::Node::Expr(await_expr))) = self.tcx.hir_parent_iter(*hir_id).nth(1)
|
||||||
&& let Some(expr_span) = expr.span.find_ancestor_inside_same_ctxt(await_expr.span)
|
&& let Some(expr_span) = expr.span.find_ancestor_inside_same_ctxt(await_expr.span)
|
||||||
{
|
{
|
||||||
let removal_span = self
|
let removal_span = self
|
||||||
@ -4118,8 +4117,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||||||
let ty::Param(..) = ty.kind() else {
|
let ty::Param(..) = ty.kind() else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let hir = tcx.hir();
|
let node =
|
||||||
let node = tcx.hir_node_by_def_id(hir.get_parent_item(expr.hir_id).def_id);
|
tcx.hir_node_by_def_id(tcx.hir_get_parent_item(expr.hir_id).def_id);
|
||||||
|
|
||||||
let pred = ty::Binder::dummy(ty::TraitPredicate {
|
let pred = ty::Binder::dummy(ty::TraitPredicate {
|
||||||
trait_ref: ty::TraitRef::new(
|
trait_ref: ty::TraitRef::new(
|
||||||
|
@ -1880,8 +1880,7 @@ pub fn impl_trait_overcapture_suggestion<'tcx>(
|
|||||||
let opaque_hir_id = tcx.local_def_id_to_hir_id(opaque_def_id);
|
let opaque_hir_id = tcx.local_def_id_to_hir_id(opaque_def_id);
|
||||||
// FIXME: This is a bit too conservative, since it ignores parens already written in AST.
|
// FIXME: This is a bit too conservative, since it ignores parens already written in AST.
|
||||||
let (lparen, rparen) = match tcx
|
let (lparen, rparen) = match tcx
|
||||||
.hir()
|
.hir_parent_iter(opaque_hir_id)
|
||||||
.parent_iter(opaque_hir_id)
|
|
||||||
.nth(1)
|
.nth(1)
|
||||||
.expect("expected ty to have a parent always")
|
.expect("expected ty to have a parent always")
|
||||||
.1
|
.1
|
||||||
|
@ -95,7 +95,7 @@ fn impl_item_implementor_ids(tcx: TyCtxt<'_>, impl_id: DefId) -> DefIdMap<DefId>
|
|||||||
|
|
||||||
fn associated_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AssocItem {
|
fn associated_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AssocItem {
|
||||||
let id = tcx.local_def_id_to_hir_id(def_id);
|
let id = tcx.local_def_id_to_hir_id(def_id);
|
||||||
let parent_def_id = tcx.hir().get_parent_item(id);
|
let parent_def_id = tcx.hir_get_parent_item(id);
|
||||||
let parent_item = tcx.hir().expect_item(parent_def_id.def_id);
|
let parent_item = tcx.hir().expect_item(parent_def_id.def_id);
|
||||||
match parent_item.kind {
|
match parent_item.kind {
|
||||||
hir::ItemKind::Impl(impl_) => {
|
hir::ItemKind::Impl(impl_) => {
|
||||||
|
@ -98,10 +98,10 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
|
|||||||
let opaque_hir_id = self.tcx.local_def_id_to_hir_id(opaque_def_id);
|
let opaque_hir_id = self.tcx.local_def_id_to_hir_id(opaque_def_id);
|
||||||
|
|
||||||
// Named opaque types can be defined by any siblings or children of siblings.
|
// Named opaque types can be defined by any siblings or children of siblings.
|
||||||
let scope = self.tcx.hir().get_defining_scope(opaque_hir_id);
|
let scope = self.tcx.hir_get_defining_scope(opaque_hir_id);
|
||||||
// We walk up the node tree until we hit the root or the scope of the opaque type.
|
// We walk up the node tree until we hit the root or the scope of the opaque type.
|
||||||
while hir_id != scope && hir_id != CRATE_HIR_ID {
|
while hir_id != scope && hir_id != CRATE_HIR_ID {
|
||||||
hir_id = self.tcx.hir().get_parent_item(hir_id).into();
|
hir_id = self.tcx.hir_get_parent_item(hir_id).into();
|
||||||
}
|
}
|
||||||
// Syntactically, we are allowed to define the concrete type if:
|
// Syntactically, we are allowed to define the concrete type if:
|
||||||
hir_id == scope
|
hir_id == scope
|
||||||
|
@ -177,7 +177,7 @@ where
|
|||||||
// If the enclosing item has a span coming from a proc macro, then we also don't want to
|
// If the enclosing item has a span coming from a proc macro, then we also don't want to
|
||||||
// include the example.
|
// include the example.
|
||||||
let enclosing_item_span =
|
let enclosing_item_span =
|
||||||
tcx.hir().span_with_body(tcx.hir().get_parent_item(ex.hir_id).into());
|
tcx.hir().span_with_body(tcx.hir_get_parent_item(ex.hir_id).into());
|
||||||
if enclosing_item_span.from_expansion() {
|
if enclosing_item_span.from_expansion() {
|
||||||
trace!("Rejecting expr ({call_span:?}) from macro item: {enclosing_item_span:?}");
|
trace!("Rejecting expr ({call_span:?}) from macro item: {enclosing_item_span:?}");
|
||||||
return;
|
return;
|
||||||
|
@ -107,7 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
|
|||||||
&& !cx.tcx.is_builtin_derived(resolved_impl)
|
&& !cx.tcx.is_builtin_derived(resolved_impl)
|
||||||
// Don't suggest calling a function we're implementing.
|
// Don't suggest calling a function we're implementing.
|
||||||
&& resolved_impl.as_local().is_none_or(|block_id| {
|
&& resolved_impl.as_local().is_none_or(|block_id| {
|
||||||
cx.tcx.hir().parent_owner_iter(e.hir_id).all(|(id, _)| id.def_id != block_id)
|
cx.tcx.hir_parent_owner_iter(e.hir_id).all(|(id, _)| id.def_id != block_id)
|
||||||
})
|
})
|
||||||
&& let resolved_assoc_items = cx.tcx.associated_items(resolved_impl)
|
&& let resolved_assoc_items = cx.tcx.associated_items(resolved_impl)
|
||||||
// Only suggest if `clone_from`/`clone_into` is explicitly implemented
|
// Only suggest if `clone_from`/`clone_into` is explicitly implemented
|
||||||
|
@ -24,8 +24,7 @@ pub fn check(
|
|||||||
if !check_private_items
|
if !check_private_items
|
||||||
&& cx
|
&& cx
|
||||||
.tcx
|
.tcx
|
||||||
.hir()
|
.hir_parent_iter(owner_id.into())
|
||||||
.parent_iter(owner_id.into())
|
|
||||||
.any(|(id, _node)| is_doc_hidden(cx.tcx.hir().attrs(id)))
|
.any(|(id, _node)| is_doc_hidden(cx.tcx.hir().attrs(id)))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -1057,7 +1057,7 @@ impl<'tcx> Visitor<'tcx> for FindPanicUnwrap<'_, 'tcx> {
|
|||||||
"assert" | "assert_eq" | "assert_ne"
|
"assert" | "assert_eq" | "assert_ne"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
self.is_const = self.cx.tcx.hir().is_inside_const_context(expr.hir_id);
|
self.is_const = self.cx.tcx.hir_is_inside_const_context(expr.hir_id);
|
||||||
self.panic_span = Some(macro_call.span);
|
self.panic_span = Some(macro_call.span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,8 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
|
|||||||
|
|
||||||
let parent_id = cx
|
let parent_id = cx
|
||||||
.tcx
|
.tcx
|
||||||
.hir()
|
.hir_get_parent_item(cx.tcx.local_def_id_to_hir_id(fn_def_id))
|
||||||
.get_parent_item(cx.tcx.local_def_id_to_hir_id(fn_def_id))
|
|
||||||
.def_id;
|
.def_id;
|
||||||
|
|
||||||
let mut trait_self_ty = None;
|
let mut trait_self_ty = None;
|
||||||
|
@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit {
|
|||||||
&& let ExprKind::Path(ref path) = path_expr.kind
|
&& let ExprKind::Path(ref path) = path_expr.kind
|
||||||
&& let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id()
|
&& let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id()
|
||||||
&& cx.tcx.is_diagnostic_item(sym::process_exit, def_id)
|
&& cx.tcx.is_diagnostic_item(sym::process_exit, def_id)
|
||||||
&& let parent = cx.tcx.hir().get_parent_item(e.hir_id)
|
&& let parent = cx.tcx.hir_get_parent_item(e.hir_id)
|
||||||
&& let OwnerNode::Item(Item{kind: ItemKind::Fn{ .. }, ..}) = cx.tcx.hir_owner_node(parent)
|
&& let OwnerNode::Item(Item{kind: ItemKind::Fn{ .. }, ..}) = cx.tcx.hir_owner_node(parent)
|
||||||
// If the next item up is a function we check if it is an entry point
|
// If the next item up is a function we check if it is an entry point
|
||||||
// and only then emit a linter warning
|
// and only then emit a linter warning
|
||||||
|
@ -112,7 +112,7 @@ impl IndexingSlicing {
|
|||||||
impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
|
impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||||
if let ExprKind::Index(array, index, _) = &expr.kind
|
if let ExprKind::Index(array, index, _) = &expr.kind
|
||||||
&& (!self.suppress_restriction_lint_in_const || !cx.tcx.hir().is_inside_const_context(expr.hir_id))
|
&& (!self.suppress_restriction_lint_in_const || !cx.tcx.hir_is_inside_const_context(expr.hir_id))
|
||||||
&& let expr_ty = cx.typeck_results().expr_ty(array)
|
&& let expr_ty = cx.typeck_results().expr_ty(array)
|
||||||
&& let mut deref = deref_chain(cx, expr_ty)
|
&& let mut deref = deref_chain(cx, expr_ty)
|
||||||
&& deref.any(|l| {
|
&& deref.any(|l| {
|
||||||
@ -181,7 +181,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
|
|||||||
span_lint_and_then(cx, INDEXING_SLICING, expr.span, "slicing may panic", |diag| {
|
span_lint_and_then(cx, INDEXING_SLICING, expr.span, "slicing may panic", |diag| {
|
||||||
diag.help(help_msg);
|
diag.help(help_msg);
|
||||||
|
|
||||||
if cx.tcx.hir().is_inside_const_context(expr.hir_id) {
|
if cx.tcx.hir_is_inside_const_context(expr.hir_id) {
|
||||||
diag.note(note);
|
diag.note(note);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -223,7 +223,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
|
|||||||
span_lint_and_then(cx, INDEXING_SLICING, expr.span, "indexing may panic", |diag| {
|
span_lint_and_then(cx, INDEXING_SLICING, expr.span, "indexing may panic", |diag| {
|
||||||
diag.help("consider using `.get(n)` or `.get_mut(n)` instead");
|
diag.help("consider using `.get(n)` or `.get_mut(n)` instead");
|
||||||
|
|
||||||
if cx.tcx.hir().is_inside_const_context(expr.hir_id) {
|
if cx.tcx.hir_is_inside_const_context(expr.hir_id) {
|
||||||
diag.note(note);
|
diag.note(note);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays {
|
|||||||
&& let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind()
|
&& let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind()
|
||||||
&& let Some(element_count) = cst.try_to_target_usize(cx.tcx)
|
&& let Some(element_count) = cst.try_to_target_usize(cx.tcx)
|
||||||
&& let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes())
|
&& let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes())
|
||||||
&& !cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| {
|
&& !cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, node)| {
|
||||||
matches!(
|
matches!(
|
||||||
node,
|
node,
|
||||||
Node::Item(Item {
|
Node::Item(Item {
|
||||||
|
@ -61,7 +61,7 @@ pub(super) fn check<'tcx>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_parent_fn_ret_ty<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option<FnRetTy<'tcx>> {
|
fn get_parent_fn_ret_ty<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option<FnRetTy<'tcx>> {
|
||||||
for (_, parent_node) in cx.tcx.hir().parent_iter(expr.hir_id) {
|
for (_, parent_node) in cx.tcx.hir_parent_iter(expr.hir_id) {
|
||||||
match parent_node {
|
match parent_node {
|
||||||
// Skip `Coroutine` closures, these are the body of `async fn`, not async closures.
|
// Skip `Coroutine` closures, these are the body of `async fn`, not async closures.
|
||||||
// This is because we still need to backtrack one parent node to get the `OpaqueDef` ty.
|
// This is because we still need to backtrack one parent node to get the `OpaqueDef` ty.
|
||||||
|
@ -134,7 +134,7 @@ fn last_stmt_and_ret<'tcx>(
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
let mut parent_iter = cx.tcx.hir().parent_iter(expr.hir_id);
|
let mut parent_iter = cx.tcx.hir_parent_iter(expr.hir_id);
|
||||||
if let Some((node_hir, Node::Stmt(..))) = parent_iter.next()
|
if let Some((node_hir, Node::Stmt(..))) = parent_iter.next()
|
||||||
// This should be the loop
|
// This should be the loop
|
||||||
// This should be the function body
|
// This should be the function body
|
||||||
|
@ -56,7 +56,7 @@ pub(super) fn check<'tcx>(
|
|||||||
|
|
||||||
// ensure that the indexed variable was declared before the loop, see #601
|
// ensure that the indexed variable was declared before the loop, see #601
|
||||||
if let Some(indexed_extent) = indexed_extent {
|
if let Some(indexed_extent) = indexed_extent {
|
||||||
let parent_def_id = cx.tcx.hir().get_parent_item(expr.hir_id);
|
let parent_def_id = cx.tcx.hir_get_parent_item(expr.hir_id);
|
||||||
let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id);
|
let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id);
|
||||||
let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id).unwrap();
|
let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id).unwrap();
|
||||||
if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) {
|
if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) {
|
||||||
@ -256,7 +256,7 @@ impl<'tcx> VarVisitor<'_, 'tcx> {
|
|||||||
let res = self.cx.qpath_res(seqpath, seqexpr.hir_id);
|
let res = self.cx.qpath_res(seqpath, seqexpr.hir_id);
|
||||||
match res {
|
match res {
|
||||||
Res::Local(hir_id) => {
|
Res::Local(hir_id) => {
|
||||||
let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
|
let parent_def_id = self.cx.tcx.hir_get_parent_item(expr.hir_id);
|
||||||
let extent = self
|
let extent = self
|
||||||
.cx
|
.cx
|
||||||
.tcx
|
.tcx
|
||||||
|
@ -199,7 +199,7 @@ fn find_method_sugg_for_if_let<'tcx>(
|
|||||||
// type needs to be considered, not just the inner type of the branch being matched on.
|
// type needs to be considered, not just the inner type of the branch being matched on.
|
||||||
// Note the last expression in a block is dropped after all local bindings.
|
// Note the last expression in a block is dropped after all local bindings.
|
||||||
let check_ty = if has_else
|
let check_ty = if has_else
|
||||||
|| (keyword == "if" && matches!(cx.tcx.hir().parent_iter(expr.hir_id).next(), Some((_, Node::Block(..)))))
|
|| (keyword == "if" && matches!(cx.tcx.hir_parent_iter(expr.hir_id).next(), Some((_, Node::Block(..)))))
|
||||||
{
|
{
|
||||||
op_ty
|
op_ty
|
||||||
} else {
|
} else {
|
||||||
|
@ -40,8 +40,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &'_ Expr<'_>, receiver: &Expr<'_
|
|||||||
|
|
||||||
fn is_under_cfg(cx: &LateContext<'_>, id: HirId) -> bool {
|
fn is_under_cfg(cx: &LateContext<'_>, id: HirId) -> bool {
|
||||||
cx.tcx
|
cx.tcx
|
||||||
.hir()
|
.hir_parent_id_iter(id)
|
||||||
.parent_id_iter(id)
|
|
||||||
.any(|id| cx.tcx.hir().attrs(id).iter().any(|attr| attr.has_name(sym::cfg)))
|
.any(|id| cx.tcx.hir().attrs(id).iter().any(|attr| attr.has_name(sym::cfg)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ use rustc_span::sym;
|
|||||||
use super::ITER_NTH_ZERO;
|
use super::ITER_NTH_ZERO;
|
||||||
|
|
||||||
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) {
|
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) {
|
||||||
if let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id))
|
if let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir_get_parent_item(expr.hir_id))
|
||||||
&& let def_id = item.owner_id.to_def_id()
|
&& let def_id = item.owner_id.to_def_id()
|
||||||
&& is_trait_method(cx, expr, sym::Iterator)
|
&& is_trait_method(cx, expr, sym::Iterator)
|
||||||
&& let Some(Constant::Int(0)) = ConstEvalCtxt::new(cx).eval(arg)
|
&& let Some(Constant::Int(0)) = ConstEvalCtxt::new(cx).eval(arg)
|
||||||
|
@ -187,7 +187,7 @@ fn peel_ptr_cast<'tcx>(e: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
|
|||||||
/// ^ given this `x` expression, returns the `foo(...)` expression
|
/// ^ given this `x` expression, returns the `foo(...)` expression
|
||||||
fn peel_ptr_cast_ancestors<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
|
fn peel_ptr_cast_ancestors<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
|
||||||
let mut prev = e;
|
let mut prev = e;
|
||||||
for (_, node) in cx.tcx.hir().parent_iter(e.hir_id) {
|
for (_, node) in cx.tcx.hir_parent_iter(e.hir_id) {
|
||||||
if let Node::Expr(e) = node
|
if let Node::Expr(e) = node
|
||||||
&& get_cast_target(e).is_some()
|
&& get_cast_target(e).is_some()
|
||||||
{
|
{
|
||||||
|
@ -123,7 +123,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name:
|
|||||||
};
|
};
|
||||||
let mut prev_expr = e;
|
let mut prev_expr = e;
|
||||||
|
|
||||||
for (_, parent) in cx.tcx.hir().parent_iter(e.hir_id) {
|
for (_, parent) in cx.tcx.hir_parent_iter(e.hir_id) {
|
||||||
if let Node::Expr(e) = parent {
|
if let Node::Expr(e) = parent {
|
||||||
match e.kind {
|
match e.kind {
|
||||||
ExprKind::Field(_, name)
|
ExprKind::Field(_, name)
|
||||||
|
@ -4671,7 +4671,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let name = impl_item.ident.name.as_str();
|
let name = impl_item.ident.name.as_str();
|
||||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
|
let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id;
|
||||||
let item = cx.tcx.hir().expect_item(parent);
|
let item = cx.tcx.hir().expect_item(parent);
|
||||||
let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ pub(super) fn check<'tcx>(
|
|||||||
let in_sugg_method_implementation = {
|
let in_sugg_method_implementation = {
|
||||||
matches!(
|
matches!(
|
||||||
suggested_method_def_id.as_local(),
|
suggested_method_def_id.as_local(),
|
||||||
Some(local_def_id) if local_def_id == cx.tcx.hir().get_parent_item(receiver.hir_id).def_id
|
Some(local_def_id) if local_def_id == cx.tcx.hir_get_parent_item(receiver.hir_id).def_id
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
if in_sugg_method_implementation {
|
if in_sugg_method_implementation {
|
||||||
|
@ -35,7 +35,7 @@ pub(super) fn check(
|
|||||||
};
|
};
|
||||||
let manual = count == 2 && msrv.meets(msrvs::STR_SPLIT_ONCE);
|
let manual = count == 2 && msrv.meets(msrvs::STR_SPLIT_ONCE);
|
||||||
|
|
||||||
match parse_iter_usage(cx, expr.span.ctxt(), cx.tcx.hir().parent_iter(expr.hir_id)) {
|
match parse_iter_usage(cx, expr.span.ctxt(), cx.tcx.hir_parent_iter(expr.hir_id)) {
|
||||||
Some(usage) if needless(usage.kind) => lint_needless(cx, method_name, expr, self_arg, pat_arg),
|
Some(usage) if needless(usage.kind) => lint_needless(cx, method_name, expr, self_arg, pat_arg),
|
||||||
Some(usage) if manual => check_manual_split_once(cx, method_name, expr, self_arg, pat_arg, &usage),
|
Some(usage) if manual => check_manual_split_once(cx, method_name, expr, self_arg, pat_arg, &usage),
|
||||||
None if manual => {
|
None if manual => {
|
||||||
@ -127,7 +127,7 @@ fn check_manual_split_once_indirect(
|
|||||||
pat_arg: &Expr<'_>,
|
pat_arg: &Expr<'_>,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let ctxt = expr.span.ctxt();
|
let ctxt = expr.span.ctxt();
|
||||||
let mut parents = cx.tcx.hir().parent_iter(expr.hir_id);
|
let mut parents = cx.tcx.hir_parent_iter(expr.hir_id);
|
||||||
if let (_, Node::LetStmt(local)) = parents.next()?
|
if let (_, Node::LetStmt(local)) = parents.next()?
|
||||||
&& let PatKind::Binding(BindingMode::MUT, iter_binding_id, _, None) = local.pat.kind
|
&& let PatKind::Binding(BindingMode::MUT, iter_binding_id, _, None) = local.pat.kind
|
||||||
&& let (iter_stmt_id, Node::Stmt(_)) = parents.next()?
|
&& let (iter_stmt_id, Node::Stmt(_)) = parents.next()?
|
||||||
@ -220,7 +220,7 @@ fn indirect_usage<'tcx>(
|
|||||||
ControlFlow::Continue(Descend::from(path_to_binding.is_none()))
|
ControlFlow::Continue(Descend::from(path_to_binding.is_none()))
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut parents = cx.tcx.hir().parent_iter(path_to_binding?.hir_id);
|
let mut parents = cx.tcx.hir_parent_iter(path_to_binding?.hir_id);
|
||||||
let iter_usage = parse_iter_usage(cx, ctxt, &mut parents)?;
|
let iter_usage = parse_iter_usage(cx, ctxt, &mut parents)?;
|
||||||
|
|
||||||
let (parent_id, _) = parents.find(|(_, node)| {
|
let (parent_id, _) = parents.find(|(_, node)| {
|
||||||
|
@ -494,7 +494,7 @@ fn get_input_traits_and_projections<'tcx>(
|
|||||||
|
|
||||||
#[expect(clippy::too_many_lines)]
|
#[expect(clippy::too_many_lines)]
|
||||||
fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<'a>) -> bool {
|
fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<'a>) -> bool {
|
||||||
for (_, node) in cx.tcx.hir().parent_iter(expr.hir_id) {
|
for (_, node) in cx.tcx.hir_parent_iter(expr.hir_id) {
|
||||||
match node {
|
match node {
|
||||||
Node::Stmt(_) => return true,
|
Node::Stmt(_) => return true,
|
||||||
Node::Block(..) => {},
|
Node::Block(..) => {},
|
||||||
|
@ -121,9 +121,9 @@ impl Visitor<'_> for IdentVisitor<'_, '_> {
|
|||||||
// Check whether the node is part of a `use` statement. We don't want to emit a warning if the user
|
// Check whether the node is part of a `use` statement. We don't want to emit a warning if the user
|
||||||
// has no control over the type.
|
// has no control over the type.
|
||||||
let usenode = opt_as_use_node(node).or_else(|| {
|
let usenode = opt_as_use_node(node).or_else(|| {
|
||||||
cx.tcx
|
cx
|
||||||
.hir()
|
.tcx
|
||||||
.parent_iter(hir_id)
|
.hir_parent_iter(hir_id)
|
||||||
.find_map(|(_, node)| opt_as_use_node(node))
|
.find_map(|(_, node)| opt_as_use_node(node))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
|
|||||||
|
|
||||||
// Const fns are not allowed as methods in a trait.
|
// Const fns are not allowed as methods in a trait.
|
||||||
{
|
{
|
||||||
let parent = cx.tcx.hir().get_parent_item(hir_id).def_id;
|
let parent = cx.tcx.hir_get_parent_item(hir_id).def_id;
|
||||||
if parent != CRATE_DEF_ID {
|
if parent != CRATE_DEF_ID {
|
||||||
if let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(parent) {
|
if let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(parent) {
|
||||||
if let hir::ItemKind::Trait(..) = &item.kind {
|
if let hir::ItemKind::Trait(..) = &item.kind {
|
||||||
|
@ -81,7 +81,7 @@ fn is_unreachable(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
|||||||
| sym::core_panic_2015_macro
|
| sym::core_panic_2015_macro
|
||||||
| sym::std_panic_2015_macro
|
| sym::std_panic_2015_macro
|
||||||
| sym::core_panic_2021_macro
|
| sym::core_panic_2021_macro
|
||||||
) && !cx.tcx.hir().is_inside_const_context(expr.hir_id))
|
) && !cx.tcx.hir_is_inside_const_context(expr.hir_id))
|
||||||
|| matches!(
|
|| matches!(
|
||||||
diag_name,
|
diag_name,
|
||||||
sym::unimplemented_macro | sym::todo_macro | sym::unreachable_macro | sym::unreachable_2015_macro
|
sym::unimplemented_macro | sym::todo_macro | sym::unreachable_macro | sym::unreachable_2015_macro
|
||||||
|
@ -41,8 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowedRef {
|
|||||||
&& !ref_pat.span.from_expansion()
|
&& !ref_pat.span.from_expansion()
|
||||||
&& cx
|
&& cx
|
||||||
.tcx
|
.tcx
|
||||||
.hir()
|
.hir_parent_iter(ref_pat.hir_id)
|
||||||
.parent_iter(ref_pat.hir_id)
|
|
||||||
.map_while(|(_, parent)| if let Node::Pat(pat) = parent { Some(pat) } else { None })
|
.map_while(|(_, parent)| if let Node::Pat(pat) = parent { Some(pat) } else { None })
|
||||||
// Do not lint patterns that are part of an OR `|` pattern, the binding mode must match in all arms
|
// Do not lint patterns that are part of an OR `|` pattern, the binding mode must match in all arms
|
||||||
.all(|pat| !matches!(pat.kind, PatKind::Or(_)))
|
.all(|pat| !matches!(pat.kind, PatKind::Or(_)))
|
||||||
|
@ -347,7 +347,7 @@ fn check<'tcx>(
|
|||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit {
|
impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit {
|
||||||
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
|
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
|
||||||
let mut parents = cx.tcx.hir().parent_iter(local.hir_id);
|
let mut parents = cx.tcx.hir_parent_iter(local.hir_id);
|
||||||
if let LetStmt {
|
if let LetStmt {
|
||||||
init: None,
|
init: None,
|
||||||
pat:
|
pat:
|
||||||
|
@ -350,8 +350,7 @@ impl MutablyUsedVariablesCtxt<'_> {
|
|||||||
// The goal here is to find if the current scope is unsafe or not. It stops when it finds
|
// The goal here is to find if the current scope is unsafe or not. It stops when it finds
|
||||||
// a function or an unsafe block.
|
// a function or an unsafe block.
|
||||||
fn is_in_unsafe_block(&self, item: HirId) -> bool {
|
fn is_in_unsafe_block(&self, item: HirId) -> bool {
|
||||||
let hir = self.tcx.hir();
|
for (parent, node) in self.tcx.hir_parent_iter(item) {
|
||||||
for (parent, node) in hir.parent_iter(item) {
|
|
||||||
if let Some(fn_sig) = self.tcx.hir_fn_sig_by_hir_id(parent) {
|
if let Some(fn_sig) = self.tcx.hir_fn_sig_by_hir_id(parent) {
|
||||||
return fn_sig.header.is_unsafe();
|
return fn_sig.header.is_unsafe();
|
||||||
} else if let Node::Block(block) = node {
|
} else if let Node::Block(block) = node {
|
||||||
|
@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
|
|||||||
if sig.decl.inputs.is_empty()
|
if sig.decl.inputs.is_empty()
|
||||||
&& name == sym::new
|
&& name == sym::new
|
||||||
&& cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id)
|
&& cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id)
|
||||||
&& let self_def_id = cx.tcx.hir().get_parent_item(id.into())
|
&& let self_def_id = cx.tcx.hir_get_parent_item(id.into())
|
||||||
&& let self_ty = cx.tcx.type_of(self_def_id).instantiate_identity()
|
&& let self_ty = cx.tcx.type_of(self_def_id).instantiate_identity()
|
||||||
&& self_ty == return_ty(cx, id)
|
&& self_ty == return_ty(cx, id)
|
||||||
&& let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default)
|
&& let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default)
|
||||||
|
@ -141,7 +141,7 @@ impl NoEffect {
|
|||||||
stmt.span,
|
stmt.span,
|
||||||
"statement with no effect",
|
"statement with no effect",
|
||||||
|diag| {
|
|diag| {
|
||||||
for parent in cx.tcx.hir().parent_iter(stmt.hir_id) {
|
for parent in cx.tcx.hir_parent_iter(stmt.hir_id) {
|
||||||
if let Node::Item(item) = parent.1
|
if let Node::Item(item) = parent.1
|
||||||
&& let ItemKind::Fn { .. } = item.kind
|
&& let ItemKind::Fn { .. } = item.kind
|
||||||
&& let Node::Block(block) = cx.tcx.parent_hir_node(stmt.hir_id)
|
&& let Node::Block(block) = cx.tcx.parent_hir_node(stmt.hir_id)
|
||||||
|
@ -344,7 +344,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst<'tcx> {
|
|||||||
|
|
||||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) {
|
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) {
|
||||||
if let ImplItemKind::Const(_, body_id) = &impl_item.kind {
|
if let ImplItemKind::Const(_, body_id) = &impl_item.kind {
|
||||||
let item_def_id = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
|
let item_def_id = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id;
|
||||||
let item = cx.tcx.hir().expect_item(item_def_id);
|
let item = cx.tcx.hir().expect_item(item_def_id);
|
||||||
|
|
||||||
match &item.kind {
|
match &item.kind {
|
||||||
|
@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for NonZeroSuggestions {
|
|||||||
check_non_zero_conversion(cx, rhs, Applicability::MachineApplicable);
|
check_non_zero_conversion(cx, rhs, Applicability::MachineApplicable);
|
||||||
} else {
|
} else {
|
||||||
// Check if the parent expression is a binary operation
|
// Check if the parent expression is a binary operation
|
||||||
let parent_is_binary = cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| {
|
let parent_is_binary = cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, node)| {
|
||||||
matches!(node, rustc_hir::Node::Expr(parent_expr) if matches!(parent_expr.kind, ExprKind::Binary(..)))
|
matches!(node, rustc_hir::Node::Expr(parent_expr) if matches!(parent_expr.kind, ExprKind::Binary(..)))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ pub(super) fn check<'tcx>(
|
|||||||
let rty = cx.typeck_results().expr_ty(rhs);
|
let rty = cx.typeck_results().expr_ty(rhs);
|
||||||
if let Some((_, lang_item)) = binop_traits(op.node)
|
if let Some((_, lang_item)) = binop_traits(op.node)
|
||||||
&& let Some(trait_id) = cx.tcx.lang_items().get(lang_item)
|
&& let Some(trait_id) = cx.tcx.lang_items().get(lang_item)
|
||||||
&& let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id).def_id
|
&& let parent_fn = cx.tcx.hir_get_parent_item(e.hir_id).def_id
|
||||||
&& trait_ref_of_method(cx, parent_fn).is_none_or(|t| t.path.res.def_id() != trait_id)
|
&& trait_ref_of_method(cx, parent_fn).is_none_or(|t| t.path.res.def_id() != trait_id)
|
||||||
&& implements_trait(cx, ty, trait_id, &[rty.into()])
|
&& implements_trait(cx, ty, trait_id, &[rty.into()])
|
||||||
{
|
{
|
||||||
|
@ -120,7 +120,7 @@ fn needs_parenthesis(cx: &LateContext<'_>, binary: &Expr<'_>, child: &Expr<'_>)
|
|||||||
// the parent HIR node is an expression, or if the parent HIR node
|
// the parent HIR node is an expression, or if the parent HIR node
|
||||||
// is a Block or Stmt, and the new left hand side would need
|
// is a Block or Stmt, and the new left hand side would need
|
||||||
// parenthesis be treated as a statement rather than an expression.
|
// parenthesis be treated as a statement rather than an expression.
|
||||||
if let Some((_, parent)) = cx.tcx.hir().parent_iter(binary.hir_id).next() {
|
if let Some((_, parent)) = cx.tcx.hir_parent_iter(binary.hir_id).next() {
|
||||||
match parent {
|
match parent {
|
||||||
Node::Expr(_) => return Parens::Needed,
|
Node::Expr(_) => return Parens::Needed,
|
||||||
Node::Block(_) | Node::Stmt(_) => {
|
Node::Block(_) | Node::Stmt(_) => {
|
||||||
@ -142,7 +142,7 @@ fn needs_parenthesis(cx: &LateContext<'_>, binary: &Expr<'_>, child: &Expr<'_>)
|
|||||||
// This would mean that the rustfix suggestion will appear at the start of a line, which causes
|
// This would mean that the rustfix suggestion will appear at the start of a line, which causes
|
||||||
// these expressions to be interpreted as statements if they do not have parenthesis.
|
// these expressions to be interpreted as statements if they do not have parenthesis.
|
||||||
let mut prev_id = binary.hir_id;
|
let mut prev_id = binary.hir_id;
|
||||||
for (_, parent) in cx.tcx.hir().parent_iter(binary.hir_id) {
|
for (_, parent) in cx.tcx.hir_parent_iter(binary.hir_id) {
|
||||||
if let Node::Expr(expr) = parent
|
if let Node::Expr(expr) = parent
|
||||||
&& let ExprKind::Binary(_, lhs, _) | ExprKind::Cast(lhs, _) | ExprKind::Unary(_, lhs) = expr.kind
|
&& let ExprKind::Binary(_, lhs, _) | ExprKind::Cast(lhs, _) | ExprKind::Unary(_, lhs) = expr.kind
|
||||||
&& lhs.hir_id == prev_id
|
&& lhs.hir_id == prev_id
|
||||||
|
@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented {
|
|||||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||||
if let Some(macro_call) = root_macro_call_first_node(cx, expr) {
|
if let Some(macro_call) = root_macro_call_first_node(cx, expr) {
|
||||||
if is_panic(cx, macro_call.def_id) {
|
if is_panic(cx, macro_call.def_id) {
|
||||||
if cx.tcx.hir().is_inside_const_context(expr.hir_id)
|
if cx.tcx.hir_is_inside_const_context(expr.hir_id)
|
||||||
|| self.allow_panic_in_tests && is_in_test(cx.tcx, expr.hir_id)
|
|| self.allow_panic_in_tests && is_in_test(cx.tcx, expr.hir_id)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -139,7 +139,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented {
|
|||||||
&& let Res::Def(DefKind::Fn, def_id) = expr_path.res
|
&& let Res::Def(DefKind::Fn, def_id) = expr_path.res
|
||||||
&& match_def_path(cx, def_id, &paths::PANIC_ANY)
|
&& match_def_path(cx, def_id, &paths::PANIC_ANY)
|
||||||
{
|
{
|
||||||
if cx.tcx.hir().is_inside_const_context(expr.hir_id)
|
if cx.tcx.hir_is_inside_const_context(expr.hir_id)
|
||||||
|| self.allow_panic_in_tests && is_in_test(cx.tcx, expr.hir_id)
|
|| self.allow_panic_in_tests && is_in_test(cx.tcx, expr.hir_id)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -186,8 +186,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
|
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
|
||||||
let hir = cx.tcx.hir();
|
let mut parents = cx.tcx.hir_parent_iter(body.value.hir_id);
|
||||||
let mut parents = hir.parent_iter(body.value.hir_id);
|
|
||||||
let (item_id, sig, is_trait_item) = match parents.next() {
|
let (item_id, sig, is_trait_item) = match parents.next() {
|
||||||
Some((_, Node::Item(i))) => {
|
Some((_, Node::Item(i))) => {
|
||||||
if let ItemKind::Fn { sig, .. } = &i.kind {
|
if let ItemKind::Fn { sig, .. } = &i.kind {
|
||||||
|
@ -122,8 +122,7 @@ fn find_binding(pat: &Pat<'_>, name: Ident) -> Option<BindingMode> {
|
|||||||
|
|
||||||
/// Check if a rebinding of a local changes the effect of assignments to the binding.
|
/// Check if a rebinding of a local changes the effect of assignments to the binding.
|
||||||
fn affects_assignments(cx: &LateContext<'_>, mutability: Mutability, bind: HirId, rebind: HirId) -> bool {
|
fn affects_assignments(cx: &LateContext<'_>, mutability: Mutability, bind: HirId, rebind: HirId) -> bool {
|
||||||
let hir = cx.tcx.hir();
|
|
||||||
|
|
||||||
// the binding is mutable and the rebinding is in a different scope than the original binding
|
// the binding is mutable and the rebinding is in a different scope than the original binding
|
||||||
mutability == Mutability::Mut && hir.get_enclosing_scope(bind) != hir.get_enclosing_scope(rebind)
|
mutability == Mutability::Mut
|
||||||
|
&& cx.tcx.hir_get_enclosing_scope(bind) != cx.tcx.hir_get_enclosing_scope(rebind)
|
||||||
}
|
}
|
||||||
|
@ -177,8 +177,7 @@ declare_lint_pass!(Return => [LET_AND_RETURN, NEEDLESS_RETURN, NEEDLESS_RETURN_W
|
|||||||
/// because of the never-ness of `return` expressions
|
/// because of the never-ness of `return` expressions
|
||||||
fn stmt_needs_never_type(cx: &LateContext<'_>, stmt_hir_id: HirId) -> bool {
|
fn stmt_needs_never_type(cx: &LateContext<'_>, stmt_hir_id: HirId) -> bool {
|
||||||
cx.tcx
|
cx.tcx
|
||||||
.hir()
|
.hir_parent_iter(stmt_hir_id)
|
||||||
.parent_iter(stmt_hir_id)
|
|
||||||
.find_map(|(_, node)| if let Node::Expr(expr) = node { Some(expr) } else { None })
|
.find_map(|(_, node)| if let Node::Expr(expr) = node { Some(expr) } else { None })
|
||||||
.is_some_and(|e| {
|
.is_some_and(|e| {
|
||||||
cx.typeck_results()
|
cx.typeck_results()
|
||||||
@ -203,7 +202,7 @@ impl<'tcx> LateLintPass<'tcx> for Return {
|
|||||||
&& is_res_lang_ctor(cx, path_res(cx, maybe_constr), ResultErr)
|
&& is_res_lang_ctor(cx, path_res(cx, maybe_constr), ResultErr)
|
||||||
|
|
||||||
// Ensure this is not the final stmt, otherwise removing it would cause a compile error
|
// Ensure this is not the final stmt, otherwise removing it would cause a compile error
|
||||||
&& let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id))
|
&& let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir_get_parent_item(expr.hir_id))
|
||||||
&& let ItemKind::Fn { body, .. } = item.kind
|
&& let ItemKind::Fn { body, .. } = item.kind
|
||||||
&& let block = cx.tcx.hir_body(body).value
|
&& let block = cx.tcx.hir_body(body).value
|
||||||
&& let ExprKind::Block(block, _) = block.kind
|
&& let ExprKind::Block(block, _) = block.kind
|
||||||
|
@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors {
|
|||||||
_ => return,
|
_ => return,
|
||||||
}
|
}
|
||||||
|
|
||||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
|
let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id;
|
||||||
let item = cx.tcx.hir().expect_item(parent);
|
let item = cx.tcx.hir().expect_item(parent);
|
||||||
let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||||
let ret_ty = return_ty(cx, impl_item.owner_id);
|
let ret_ty = return_ty(cx, impl_item.owner_id);
|
||||||
|
@ -224,9 +224,9 @@ fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span)
|
|||||||
|
|
||||||
/// Returns true if the expression is a simple transformation of a local binding such as `&x`
|
/// Returns true if the expression is a simple transformation of a local binding such as `&x`
|
||||||
fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_id: HirId) -> bool {
|
fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_id: HirId) -> bool {
|
||||||
let hir = cx.tcx.hir();
|
let is_direct_binding = cx
|
||||||
let is_direct_binding = hir
|
.tcx
|
||||||
.parent_iter(pat.hir_id)
|
.hir_parent_iter(pat.hir_id)
|
||||||
.map_while(|(_id, node)| match node {
|
.map_while(|(_id, node)| match node {
|
||||||
Node::Pat(pat) => Some(pat),
|
Node::Pat(pat) => Some(pat),
|
||||||
_ => None,
|
_ => None,
|
||||||
@ -259,14 +259,14 @@ fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_
|
|||||||
/// For closure arguments passed to a method call, returns the method call, and the `HirId` of the
|
/// For closure arguments passed to a method call, returns the method call, and the `HirId` of the
|
||||||
/// closure (which will later be skipped). This is for <https://github.com/rust-lang/rust-clippy/issues/10780>
|
/// closure (which will later be skipped). This is for <https://github.com/rust-lang/rust-clippy/issues/10780>
|
||||||
fn find_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<(&'tcx Expr<'tcx>, Option<HirId>)> {
|
fn find_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<(&'tcx Expr<'tcx>, Option<HirId>)> {
|
||||||
for (hir_id, node) in cx.tcx.hir().parent_iter(hir_id) {
|
for (hir_id, node) in cx.tcx.hir_parent_iter(hir_id) {
|
||||||
let init = match node {
|
let init = match node {
|
||||||
Node::Arm(_) | Node::Pat(_) | Node::PatField(_) | Node::Param(_) => continue,
|
Node::Arm(_) | Node::Pat(_) | Node::PatField(_) | Node::Param(_) => continue,
|
||||||
Node::Expr(expr) => match expr.kind {
|
Node::Expr(expr) => match expr.kind {
|
||||||
ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some((e, None)),
|
ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some((e, None)),
|
||||||
// If we're a closure argument, then a parent call is also an associated item.
|
// If we're a closure argument, then a parent call is also an associated item.
|
||||||
ExprKind::Closure(_) => {
|
ExprKind::Closure(_) => {
|
||||||
if let Some((_, node)) = cx.tcx.hir().parent_iter(hir_id).next() {
|
if let Some((_, node)) = cx.tcx.hir_parent_iter(hir_id).next() {
|
||||||
match node {
|
match node {
|
||||||
Node::Expr(expr) => match expr.kind {
|
Node::Expr(expr) => match expr.kind {
|
||||||
ExprKind::MethodCall(_, _, _, _) | ExprKind::Call(_, _) => Some((expr, Some(hir_id))),
|
ExprKind::MethodCall(_, _, _, _) | ExprKind::Call(_, _) => Some((expr, Some(hir_id))),
|
||||||
|
@ -232,8 +232,7 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> StmtsChecker<'ap, 'lc, 'others, 'stmt, 'tcx
|
|||||||
let block_is_ancestor = self
|
let block_is_ancestor = self
|
||||||
.cx
|
.cx
|
||||||
.tcx
|
.tcx
|
||||||
.hir()
|
.hir_parent_iter(self.ap.curr_block_hir_id)
|
||||||
.parent_iter(self.ap.curr_block_hir_id)
|
|
||||||
.any(|(id, _)| id == apa.first_block_hir_id);
|
.any(|(id, _)| id == apa.first_block_hir_id);
|
||||||
if last_stmt_is_not_dummy && last_stmt_is_not_curr && (block_equals_curr || block_is_ancestor) {
|
if last_stmt_is_not_dummy && last_stmt_is_not_curr && (block_equals_curr || block_is_ancestor) {
|
||||||
apa.has_expensive_expr_after_last_attr = true;
|
apa.has_expensive_expr_after_last_attr = true;
|
||||||
|
@ -63,11 +63,11 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl {
|
|||||||
|
|
||||||
// Check for more than one binary operation in the implemented function
|
// Check for more than one binary operation in the implemented function
|
||||||
// Linting when multiple operations are involved can result in false positives
|
// Linting when multiple operations are involved can result in false positives
|
||||||
&& let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id
|
&& let parent_fn = cx.tcx.hir_get_parent_item(expr.hir_id).def_id
|
||||||
&& let hir::Node::ImplItem(impl_item) = cx.tcx.hir_node_by_def_id(parent_fn)
|
&& let hir::Node::ImplItem(impl_item) = cx.tcx.hir_node_by_def_id(parent_fn)
|
||||||
&& let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind
|
&& let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind
|
||||||
&& let body = cx.tcx.hir_body(body_id)
|
&& let body = cx.tcx.hir_body(body_id)
|
||||||
&& let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id
|
&& let parent_fn = cx.tcx.hir_get_parent_item(expr.hir_id).def_id
|
||||||
&& let Some(trait_ref) = trait_ref_of_method(cx, parent_fn)
|
&& let Some(trait_ref) = trait_ref_of_method(cx, parent_fn)
|
||||||
&& let trait_id = trait_ref.path.res.def_id()
|
&& let trait_id = trait_ref.path.res.def_id()
|
||||||
&& ![binop_trait_id, op_assign_trait_id].contains(&trait_id)
|
&& ![binop_trait_id, op_assign_trait_id].contains(&trait_id)
|
||||||
|
@ -10,7 +10,7 @@ use rustc_middle::ty::Ty;
|
|||||||
use super::EAGER_TRANSMUTE;
|
use super::EAGER_TRANSMUTE;
|
||||||
|
|
||||||
fn peel_parent_unsafe_blocks<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
|
fn peel_parent_unsafe_blocks<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
|
||||||
for (_, parent) in cx.tcx.hir().parent_iter(expr.hir_id) {
|
for (_, parent) in cx.tcx.hir_parent_iter(expr.hir_id) {
|
||||||
match parent {
|
match parent {
|
||||||
Node::Block(_) => {},
|
Node::Block(_) => {},
|
||||||
Node::Expr(e) if let ExprKind::Block(..) = e.kind => {},
|
Node::Expr(e) if let ExprKind::Block(..) = e.kind => {},
|
||||||
|
@ -7,7 +7,7 @@ use rustc_middle::ty::Ty;
|
|||||||
use crate::transmute::MISSING_TRANSMUTE_ANNOTATIONS;
|
use crate::transmute::MISSING_TRANSMUTE_ANNOTATIONS;
|
||||||
|
|
||||||
fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId) -> Option<LetStmt<'tcx>> {
|
fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId) -> Option<LetStmt<'tcx>> {
|
||||||
let mut parent_iter = cx.tcx.hir().parent_iter(expr_hir_id);
|
let mut parent_iter = cx.tcx.hir_parent_iter(expr_hir_id);
|
||||||
if let Some((_, node)) = parent_iter.next() {
|
if let Some((_, node)) = parent_iter.next() {
|
||||||
match node {
|
match node {
|
||||||
Node::LetStmt(local) => Some(*local),
|
Node::LetStmt(local) => Some(*local),
|
||||||
|
@ -375,8 +375,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
|
|||||||
) {
|
) {
|
||||||
let is_in_trait_impl = if let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(
|
let is_in_trait_impl = if let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(
|
||||||
cx.tcx
|
cx.tcx
|
||||||
.hir()
|
.hir_get_parent_item(cx.tcx.local_def_id_to_hir_id(def_id))
|
||||||
.get_parent_item(cx.tcx.local_def_id_to_hir_id(def_id))
|
|
||||||
.def_id,
|
.def_id,
|
||||||
) {
|
) {
|
||||||
matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }))
|
matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }))
|
||||||
@ -420,7 +419,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
|
|||||||
ImplItemKind::Const(ty, _) => {
|
ImplItemKind::Const(ty, _) => {
|
||||||
let is_in_trait_impl = if let hir::Node::Item(item) = cx
|
let is_in_trait_impl = if let hir::Node::Item(item) = cx
|
||||||
.tcx
|
.tcx
|
||||||
.hir_node_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id()).def_id)
|
.hir_node_by_def_id(cx.tcx.hir_get_parent_item(item.hir_id()).def_id)
|
||||||
{
|
{
|
||||||
matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }))
|
matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }))
|
||||||
} else {
|
} else {
|
||||||
|
@ -111,7 +111,7 @@ fn get_impl_trait_def_id(cx: &LateContext<'_>, method_def_id: LocalDefId) -> Opt
|
|||||||
owner_id,
|
owner_id,
|
||||||
..
|
..
|
||||||
}),
|
}),
|
||||||
)) = cx.tcx.hir().parent_iter(hir_id).next()
|
)) = cx.tcx.hir_parent_iter(hir_id).next()
|
||||||
// We exclude `impl` blocks generated from rustc's proc macros.
|
// We exclude `impl` blocks generated from rustc's proc macros.
|
||||||
&& !cx.tcx.has_attr(*owner_id, sym::automatically_derived)
|
&& !cx.tcx.has_attr(*owner_id, sym::automatically_derived)
|
||||||
// It is a implementation of a trait.
|
// It is a implementation of a trait.
|
||||||
@ -216,7 +216,7 @@ fn check_to_string(cx: &LateContext<'_>, method_span: Span, method_def_id: Local
|
|||||||
owner_id,
|
owner_id,
|
||||||
..
|
..
|
||||||
}),
|
}),
|
||||||
)) = cx.tcx.hir().parent_iter(hir_id).next()
|
)) = cx.tcx.hir_parent_iter(hir_id).next()
|
||||||
// We exclude `impl` blocks generated from rustc's proc macros.
|
// We exclude `impl` blocks generated from rustc's proc macros.
|
||||||
&& !cx.tcx.has_attr(*owner_id, sym::automatically_derived)
|
&& !cx.tcx.has_attr(*owner_id, sym::automatically_derived)
|
||||||
// It is a implementation of a trait.
|
// It is a implementation of a trait.
|
||||||
@ -367,7 +367,7 @@ impl UnconditionalRecursion {
|
|||||||
kind: ItemKind::Impl(impl_),
|
kind: ItemKind::Impl(impl_),
|
||||||
..
|
..
|
||||||
}),
|
}),
|
||||||
)) = cx.tcx.hir().parent_iter(hir_id).next()
|
)) = cx.tcx.hir_parent_iter(hir_id).next()
|
||||||
&& let Some(implemented_ty_id) = get_hir_ty_def_id(cx.tcx, *impl_.self_ty)
|
&& let Some(implemented_ty_id) = get_hir_ty_def_id(cx.tcx, *impl_.self_ty)
|
||||||
&& {
|
&& {
|
||||||
self.init_default_impl_for_type_if_needed(cx);
|
self.init_default_impl_for_type_if_needed(cx);
|
||||||
|
@ -291,7 +291,7 @@ fn expr_has_unnecessary_safety_comment<'tcx>(
|
|||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
comment_pos: BytePos,
|
comment_pos: BytePos,
|
||||||
) -> Option<Span> {
|
) -> Option<Span> {
|
||||||
if cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, ref node)| {
|
if cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, ref node)| {
|
||||||
matches!(
|
matches!(
|
||||||
node,
|
node,
|
||||||
Node::Block(Block {
|
Node::Block(Block {
|
||||||
@ -604,10 +604,9 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span
|
|||||||
|
|
||||||
fn get_body_search_span(cx: &LateContext<'_>) -> Option<Span> {
|
fn get_body_search_span(cx: &LateContext<'_>) -> Option<Span> {
|
||||||
let body = cx.enclosing_body?;
|
let body = cx.enclosing_body?;
|
||||||
let map = cx.tcx.hir();
|
|
||||||
let mut span = cx.tcx.hir_body(body).value.span;
|
let mut span = cx.tcx.hir_body(body).value.span;
|
||||||
let mut maybe_global_var = false;
|
let mut maybe_global_var = false;
|
||||||
for (_, node) in map.parent_iter(body.hir_id) {
|
for (_, node) in cx.tcx.hir_parent_iter(body.hir_id) {
|
||||||
match node {
|
match node {
|
||||||
Node::Expr(e) => span = e.span,
|
Node::Expr(e) => span = e.span,
|
||||||
Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::LetStmt(_) => (),
|
Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::LetStmt(_) => (),
|
||||||
|
@ -224,7 +224,7 @@ fn is_unreachable_or_panic(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
if is_panic(cx, macro_call.def_id) {
|
if is_panic(cx, macro_call.def_id) {
|
||||||
return !cx.tcx.hir().is_inside_const_context(expr.hir_id);
|
return !cx.tcx.hir_is_inside_const_context(expr.hir_id);
|
||||||
}
|
}
|
||||||
matches!(cx.tcx.item_name(macro_call.def_id).as_str(), "unreachable")
|
matches!(cx.tcx.item_name(macro_call.def_id).as_str(), "unreachable")
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
|
|||||||
|
|
||||||
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) -> ControlFlow<()> {
|
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) -> ControlFlow<()> {
|
||||||
if path_to_local_id(ex, self.expected_hir_id) {
|
if path_to_local_id(ex, self.expected_hir_id) {
|
||||||
for (_, node) in self.cx.tcx.hir().parent_iter(ex.hir_id) {
|
for (_, node) in self.cx.tcx.hir_parent_iter(ex.hir_id) {
|
||||||
match node {
|
match node {
|
||||||
Node::Expr(expr) => {
|
Node::Expr(expr) => {
|
||||||
match expr.kind {
|
match expr.kind {
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user