Auto merge of #137397 - matthiaskrgr:rollup-ls2pilo, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #132876 (rustdoc book: acknowledge --document-hidden-items) - #136148 (Optionally add type names to `TypeId`s.) - #136609 (libcore/net: `IpAddr::as_octets()`) - #137336 (Stabilise `os_str_display`) - #137350 (Move methods from Map to TyCtxt, part 3.) - #137353 (Implement `read_buf` for WASI stdin) - #137361 (Refactor `OperandRef::extract_field` to prep for MCP838) - #137367 (Do not exempt nonexistent platforms from platform policy) - #137374 (Stacker now handles miri using a noop impl itself) - #137392 (remove few unused fields) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
794c12416b
126 changed files with 422 additions and 351 deletions
|
@ -2751,9 +2751,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "psm"
|
name = "psm"
|
||||||
version = "0.1.24"
|
version = "0.1.25"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "200b9ff220857e53e184257720a14553b2f4aa02577d2ed9842d45d4b9654810"
|
checksum = "f58e5423e24c18cc840e1c98370b3993c6649cd1678b4d24318bcf0a083cbe88"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
@ -4947,9 +4947,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stacker"
|
name = "stacker"
|
||||||
version = "0.1.17"
|
version = "0.1.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "799c883d55abdb5e98af1a7b3f23b9b6de8ecada0ecac058672d7635eb48ca7b"
|
checksum = "1d08feb8f695b465baed819b03c128dc23f57a694510ab1f06c77f763975685e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
|
|
@ -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")
|
||||||
|
|
|
@ -358,19 +358,33 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
|
||||||
let field = self.layout.field(bx.cx(), i);
|
let field = self.layout.field(bx.cx(), i);
|
||||||
let offset = self.layout.fields.offset(i);
|
let offset = self.layout.fields.offset(i);
|
||||||
|
|
||||||
|
if !bx.is_backend_ref(self.layout) && bx.is_backend_ref(field) {
|
||||||
|
if let BackendRepr::Vector { count, .. } = self.layout.backend_repr
|
||||||
|
&& let BackendRepr::Memory { sized: true } = field.backend_repr
|
||||||
|
&& count.is_power_of_two()
|
||||||
|
{
|
||||||
|
assert_eq!(field.size, self.layout.size);
|
||||||
|
// This is being deprecated, but for now stdarch still needs it for
|
||||||
|
// Newtype vector of array, e.g. #[repr(simd)] struct S([i32; 4]);
|
||||||
|
let place = PlaceRef::alloca(bx, field);
|
||||||
|
self.val.store(bx, place.val.with_type(self.layout));
|
||||||
|
return bx.load_operand(place);
|
||||||
|
} else {
|
||||||
|
// Part of https://github.com/rust-lang/compiler-team/issues/838
|
||||||
|
bug!("Non-ref type {self:?} cannot project to ref field type {field:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let val = if field.is_zst() {
|
let val = if field.is_zst() {
|
||||||
OperandValue::ZeroSized
|
OperandValue::ZeroSized
|
||||||
} else if field.size == self.layout.size {
|
} else if field.size == self.layout.size {
|
||||||
assert_eq!(offset.bytes(), 0);
|
assert_eq!(offset.bytes(), 0);
|
||||||
if let Some(field_val) = fx.codegen_transmute_operand(bx, *self, field) {
|
fx.codegen_transmute_operand(bx, *self, field).unwrap_or_else(|| {
|
||||||
field_val
|
bug!(
|
||||||
} else {
|
"Expected `codegen_transmute_operand` to handle equal-size \
|
||||||
// we have to go through memory for things like
|
field {i:?} projection from {self:?} to {field:?}"
|
||||||
// Newtype vector of array, e.g. #[repr(simd)] struct S([i32; 4]);
|
)
|
||||||
let place = PlaceRef::alloca(bx, field);
|
})
|
||||||
self.val.store(bx, place.val.with_type(self.layout));
|
|
||||||
bx.load_operand(place).val
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let (in_scalar, imm) = match (self.val, self.layout.backend_repr) {
|
let (in_scalar, imm) = match (self.val, self.layout.backend_repr) {
|
||||||
// Extract a scalar component from a pair.
|
// Extract a scalar component from a pair.
|
||||||
|
@ -385,11 +399,6 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// `#[repr(simd)]` types are also immediate.
|
|
||||||
(OperandValue::Immediate(llval), BackendRepr::Vector { .. }) => {
|
|
||||||
(None, bx.extract_element(llval, bx.cx().const_usize(i as u64)))
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
span_bug!(fx.mir.span, "OperandRef::extract_field({:?}): not applicable", self)
|
span_bug!(fx.mir.span, "OperandRef::extract_field({:?}): not applicable", self)
|
||||||
}
|
}
|
||||||
|
@ -415,14 +424,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
|
||||||
imm
|
imm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BackendRepr::Memory { sized: true } => {
|
BackendRepr::ScalarPair(_, _) | BackendRepr::Memory { .. } => bug!(),
|
||||||
span_bug!(
|
|
||||||
fx.mir.span,
|
|
||||||
"Projecting into a simd type with padding doesn't work; \
|
|
||||||
See <https://github.com/rust-lang/rust/issues/137108>",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
BackendRepr::ScalarPair(_, _) | BackendRepr::Memory { sized: false } => bug!(),
|
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -17,18 +17,6 @@ const STACK_PER_RECURSION: usize = 16 * 1024 * 1024; // 16MB
|
||||||
///
|
///
|
||||||
/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.
|
/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(not(miri))]
|
|
||||||
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
|
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
|
||||||
stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)
|
stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Grows the stack on demand to prevent stack overflow. Call this in strategic locations
|
|
||||||
/// to "break up" recursive calls. E.g. almost any call to `visit_expr` or equivalent can benefit
|
|
||||||
/// from this.
|
|
||||||
///
|
|
||||||
/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.
|
|
||||||
#[cfg(miri)]
|
|
||||||
#[inline]
|
|
||||||
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
|
|
||||||
f()
|
|
||||||
}
|
|
||||||
|
|
|
@ -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));
|
||||||
|
|
|
@ -1370,7 +1370,6 @@ pub struct GlobalCtxt<'tcx> {
|
||||||
|
|
||||||
// Internal caches for metadata decoding. No need to track deps on this.
|
// Internal caches for metadata decoding. No need to track deps on this.
|
||||||
pub ty_rcache: Lock<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,
|
pub ty_rcache: Lock<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,
|
||||||
pub pred_rcache: Lock<FxHashMap<ty::CReaderCacheKey, Predicate<'tcx>>>,
|
|
||||||
|
|
||||||
/// Caches the results of trait selection. This cache is used
|
/// Caches the results of trait selection. This cache is used
|
||||||
/// for things that do not have to do with the parameters in scope.
|
/// for things that do not have to do with the parameters in scope.
|
||||||
|
@ -1601,7 +1600,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
query_system,
|
query_system,
|
||||||
query_kinds,
|
query_kinds,
|
||||||
ty_rcache: Default::default(),
|
ty_rcache: Default::default(),
|
||||||
pred_rcache: Default::default(),
|
|
||||||
selection_cache: Default::default(),
|
selection_cache: Default::default(),
|
||||||
evaluation_cache: Default::default(),
|
evaluation_cache: Default::default(),
|
||||||
new_solver_evaluation_cache: Default::default(),
|
new_solver_evaluation_cache: Default::default(),
|
||||||
|
@ -3019,7 +3017,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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ pub struct ResolverGlobalCtxt {
|
||||||
pub confused_type_with_std_module: FxIndexMap<Span, Span>,
|
pub confused_type_with_std_module: FxIndexMap<Span, Span>,
|
||||||
pub doc_link_resolutions: FxIndexMap<LocalDefId, DocLinkResMap>,
|
pub doc_link_resolutions: FxIndexMap<LocalDefId, DocLinkResMap>,
|
||||||
pub doc_link_traits_in_scope: FxIndexMap<LocalDefId, Vec<DefId>>,
|
pub doc_link_traits_in_scope: FxIndexMap<LocalDefId, Vec<DefId>>,
|
||||||
pub all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
|
pub all_macro_rules: FxHashSet<Symbol>,
|
||||||
pub stripped_cfg_items: Steal<Vec<StrippedCfgItem>>,
|
pub stripped_cfg_items: Steal<Vec<StrippedCfgItem>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -1241,7 +1241,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
||||||
};
|
};
|
||||||
let binding = (res, vis, span, expansion).to_name_binding(self.r.arenas);
|
let binding = (res, vis, span, expansion).to_name_binding(self.r.arenas);
|
||||||
self.r.set_binding_parent_module(binding, parent_scope.module);
|
self.r.set_binding_parent_module(binding, parent_scope.module);
|
||||||
self.r.all_macro_rules.insert(ident.name, res);
|
self.r.all_macro_rules.insert(ident.name);
|
||||||
if is_macro_export {
|
if is_macro_export {
|
||||||
let import = self.r.arenas.alloc_import(ImportData {
|
let import = self.r.arenas.alloc_import(ImportData {
|
||||||
kind: ImportKind::MacroExport,
|
kind: ImportKind::MacroExport,
|
||||||
|
|
|
@ -1220,7 +1220,7 @@ pub struct Resolver<'ra, 'tcx> {
|
||||||
effective_visibilities: EffectiveVisibilities,
|
effective_visibilities: EffectiveVisibilities,
|
||||||
doc_link_resolutions: FxIndexMap<LocalDefId, DocLinkResMap>,
|
doc_link_resolutions: FxIndexMap<LocalDefId, DocLinkResMap>,
|
||||||
doc_link_traits_in_scope: FxIndexMap<LocalDefId, Vec<DefId>>,
|
doc_link_traits_in_scope: FxIndexMap<LocalDefId, Vec<DefId>>,
|
||||||
all_macro_rules: FxHashMap<Symbol, Res>,
|
all_macro_rules: FxHashSet<Symbol>,
|
||||||
|
|
||||||
/// Invocation ids of all glob delegations.
|
/// Invocation ids of all glob delegations.
|
||||||
glob_delegation_invoc_ids: FxHashSet<LocalExpnId>,
|
glob_delegation_invoc_ids: FxHashSet<LocalExpnId>,
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -23,6 +23,8 @@ optimize_for_size = []
|
||||||
# Make `RefCell` store additional debugging information, which is printed out when
|
# Make `RefCell` store additional debugging information, which is printed out when
|
||||||
# a borrow error occurs
|
# a borrow error occurs
|
||||||
debug_refcell = []
|
debug_refcell = []
|
||||||
|
# Make `TypeId` store a reference to the name of the type, so that it can print that name.
|
||||||
|
debug_typeid = []
|
||||||
|
|
||||||
[lints.rust.unexpected_cfgs]
|
[lints.rust.unexpected_cfgs]
|
||||||
level = "warn"
|
level = "warn"
|
||||||
|
|
|
@ -711,6 +711,8 @@ pub struct TypeId {
|
||||||
// We avoid using `u128` because that imposes higher alignment requirements on many platforms.
|
// We avoid using `u128` because that imposes higher alignment requirements on many platforms.
|
||||||
// See issue #115620 for more information.
|
// See issue #115620 for more information.
|
||||||
t: (u64, u64),
|
t: (u64, u64),
|
||||||
|
#[cfg(feature = "debug_typeid")]
|
||||||
|
name: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
@ -741,10 +743,14 @@ impl TypeId {
|
||||||
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
|
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
|
||||||
pub const fn of<T: ?Sized + 'static>() -> TypeId {
|
pub const fn of<T: ?Sized + 'static>() -> TypeId {
|
||||||
let t: u128 = intrinsics::type_id::<T>();
|
let t: u128 = intrinsics::type_id::<T>();
|
||||||
|
|
||||||
let t1 = (t >> 64) as u64;
|
let t1 = (t >> 64) as u64;
|
||||||
let t2 = t as u64;
|
let t2 = t as u64;
|
||||||
TypeId { t: (t1, t2) }
|
|
||||||
|
TypeId {
|
||||||
|
t: (t1, t2),
|
||||||
|
#[cfg(feature = "debug_typeid")]
|
||||||
|
name: type_name::<T>(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_u128(self) -> u128 {
|
fn as_u128(self) -> u128 {
|
||||||
|
@ -775,7 +781,15 @@ impl hash::Hash for TypeId {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl fmt::Debug for TypeId {
|
impl fmt::Debug for TypeId {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||||
write!(f, "TypeId({:#034x})", self.as_u128())
|
#[cfg(feature = "debug_typeid")]
|
||||||
|
{
|
||||||
|
write!(f, "TypeId({:#034x} = {})", self.as_u128(), self.name)?;
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "debug_typeid"))]
|
||||||
|
{
|
||||||
|
write!(f, "TypeId({:#034x})", self.as_u128())?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -451,6 +451,28 @@ impl IpAddr {
|
||||||
IpAddr::V6(v6) => v6.to_canonical(),
|
IpAddr::V6(v6) => v6.to_canonical(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the eight-bit integers this address consists of as a slice.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// #![feature(ip_as_octets)]
|
||||||
|
///
|
||||||
|
/// use std::net::{Ipv4Addr, Ipv6Addr, IpAddr};
|
||||||
|
///
|
||||||
|
/// assert_eq!(IpAddr::V4(Ipv4Addr::LOCALHOST).as_octets(), &[127, 0, 0, 1]);
|
||||||
|
/// assert_eq!(IpAddr::V6(Ipv6Addr::LOCALHOST).as_octets(),
|
||||||
|
/// &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
|
||||||
|
/// ```
|
||||||
|
#[unstable(feature = "ip_as_octets", issue = "137259")]
|
||||||
|
#[inline]
|
||||||
|
pub const fn as_octets(&self) -> &[u8] {
|
||||||
|
match self {
|
||||||
|
IpAddr::V4(ip) => ip.as_octets().as_slice(),
|
||||||
|
IpAddr::V6(ip) => ip.as_octets().as_slice(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ipv4Addr {
|
impl Ipv4Addr {
|
||||||
|
@ -616,6 +638,25 @@ impl Ipv4Addr {
|
||||||
Ipv4Addr { octets }
|
Ipv4Addr { octets }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the four eight-bit integers that make up this address
|
||||||
|
/// as a slice.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// #![feature(ip_as_octets)]
|
||||||
|
///
|
||||||
|
/// use std::net::Ipv4Addr;
|
||||||
|
///
|
||||||
|
/// let addr = Ipv4Addr::new(127, 0, 0, 1);
|
||||||
|
/// assert_eq!(addr.as_octets(), &[127, 0, 0, 1]);
|
||||||
|
/// ```
|
||||||
|
#[unstable(feature = "ip_as_octets", issue = "137259")]
|
||||||
|
#[inline]
|
||||||
|
pub const fn as_octets(&self) -> &[u8; 4] {
|
||||||
|
&self.octets
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns [`true`] for the special 'unspecified' address (`0.0.0.0`).
|
/// Returns [`true`] for the special 'unspecified' address (`0.0.0.0`).
|
||||||
///
|
///
|
||||||
/// This property is defined in _UNIX Network Programming, Second Edition_,
|
/// This property is defined in _UNIX Network Programming, Second Edition_,
|
||||||
|
@ -2001,6 +2042,25 @@ impl Ipv6Addr {
|
||||||
pub const fn from_octets(octets: [u8; 16]) -> Ipv6Addr {
|
pub const fn from_octets(octets: [u8; 16]) -> Ipv6Addr {
|
||||||
Ipv6Addr { octets }
|
Ipv6Addr { octets }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the sixteen eight-bit integers the IPv6 address consists of
|
||||||
|
/// as a slice.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// #![feature(ip_as_octets)]
|
||||||
|
///
|
||||||
|
/// use std::net::Ipv6Addr;
|
||||||
|
///
|
||||||
|
/// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).as_octets(),
|
||||||
|
/// &[255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
||||||
|
/// ```
|
||||||
|
#[unstable(feature = "ip_as_octets", issue = "137259")]
|
||||||
|
#[inline]
|
||||||
|
pub const fn as_octets(&self) -> &[u8; 16] {
|
||||||
|
&self.octets
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes an Ipv6Addr, conforming to the canonical style described by
|
/// Writes an Ipv6Addr, conforming to the canonical style described by
|
||||||
|
|
|
@ -118,6 +118,14 @@ fn any_unsized() {
|
||||||
is_any::<[i32]>();
|
is_any::<[i32]>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "debug_typeid")]
|
||||||
|
#[test]
|
||||||
|
fn debug_typeid_includes_name() {
|
||||||
|
let type_id = TypeId::of::<[usize; 2]>();
|
||||||
|
let debug_str = format!("{type_id:?}");
|
||||||
|
assert!(debug_str.ends_with("= [usize; 2])"), "{debug_str:?} did not match");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn distinct_type_names() {
|
fn distinct_type_names() {
|
||||||
// https://github.com/rust-lang/rust/issues/84666
|
// https://github.com/rust-lang/rust/issues/84666
|
||||||
|
|
|
@ -110,6 +110,13 @@ panic_immediate_abort = [
|
||||||
# Choose algorithms that are optimized for binary size instead of runtime performance
|
# Choose algorithms that are optimized for binary size instead of runtime performance
|
||||||
optimize_for_size = ["core/optimize_for_size", "alloc/optimize_for_size"]
|
optimize_for_size = ["core/optimize_for_size", "alloc/optimize_for_size"]
|
||||||
|
|
||||||
|
# Make `RefCell` store additional debugging information, which is printed out when
|
||||||
|
# a borrow error occurs
|
||||||
|
debug_refcell = ["core/debug_refcell"]
|
||||||
|
# Make `TypeId` store a reference to the name of the type, so that it can print that name.
|
||||||
|
debug_typeid = ["core/debug_typeid"]
|
||||||
|
|
||||||
|
|
||||||
# Enable std_detect default features for stdarch/crates/std_detect:
|
# Enable std_detect default features for stdarch/crates/std_detect:
|
||||||
# https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml
|
# https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml
|
||||||
std_detect_file_io = ["std_detect/std_detect_file_io"]
|
std_detect_file_io = ["std_detect/std_detect_file_io"]
|
||||||
|
|
|
@ -201,5 +201,5 @@ pub use self::c_str::{CStr, CString};
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use self::os_str::{OsStr, OsString};
|
pub use self::os_str::{OsStr, OsString};
|
||||||
|
|
||||||
#[unstable(feature = "os_str_display", issue = "120048")]
|
#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub mod os_str;
|
pub mod os_str;
|
||||||
|
|
|
@ -1204,13 +1204,12 @@ impl OsStr {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(os_str_display)]
|
|
||||||
/// use std::ffi::OsStr;
|
/// use std::ffi::OsStr;
|
||||||
///
|
///
|
||||||
/// let s = OsStr::new("Hello, world!");
|
/// let s = OsStr::new("Hello, world!");
|
||||||
/// println!("{}", s.display());
|
/// println!("{}", s.display());
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "os_str_display", issue = "120048")]
|
#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[must_use = "this does not display the `OsStr`; \
|
#[must_use = "this does not display the `OsStr`; \
|
||||||
it returns an object that can be displayed"]
|
it returns an object that can be displayed"]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1559,7 +1558,6 @@ impl fmt::Debug for OsStr {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(os_str_display)]
|
|
||||||
/// use std::ffi::OsStr;
|
/// use std::ffi::OsStr;
|
||||||
///
|
///
|
||||||
/// let s = OsStr::new("Hello, world!");
|
/// let s = OsStr::new("Hello, world!");
|
||||||
|
@ -1568,19 +1566,19 @@ impl fmt::Debug for OsStr {
|
||||||
///
|
///
|
||||||
/// [`Display`]: fmt::Display
|
/// [`Display`]: fmt::Display
|
||||||
/// [`format!`]: crate::format
|
/// [`format!`]: crate::format
|
||||||
#[unstable(feature = "os_str_display", issue = "120048")]
|
#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub struct Display<'a> {
|
pub struct Display<'a> {
|
||||||
os_str: &'a OsStr,
|
os_str: &'a OsStr,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "os_str_display", issue = "120048")]
|
#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl fmt::Debug for Display<'_> {
|
impl fmt::Debug for Display<'_> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt::Debug::fmt(&self.os_str, f)
|
fmt::Debug::fmt(&self.os_str, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "os_str_display", issue = "120048")]
|
#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl fmt::Display for Display<'_> {
|
impl fmt::Display for Display<'_> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt::Display::fmt(&self.os_str.inner, f)
|
fmt::Display::fmt(&self.os_str.inner, f)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#![forbid(unsafe_op_in_unsafe_fn)]
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
use super::fd::WasiFd;
|
use super::fd::WasiFd;
|
||||||
use crate::io::{self, IoSlice, IoSliceMut};
|
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
|
||||||
use crate::mem::ManuallyDrop;
|
use crate::mem::ManuallyDrop;
|
||||||
use crate::os::raw;
|
use crate::os::raw;
|
||||||
use crate::os::wasi::io::{AsRawFd, FromRawFd};
|
use crate::os::wasi::io::{AsRawFd, FromRawFd};
|
||||||
|
@ -28,6 +28,10 @@ impl io::Read for Stdin {
|
||||||
self.read_vectored(&mut [IoSliceMut::new(data)])
|
self.read_vectored(&mut [IoSliceMut::new(data)])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> {
|
||||||
|
ManuallyDrop::new(unsafe { WasiFd::from_raw_fd(self.as_raw_fd()) }).read_buf(buf)
|
||||||
|
}
|
||||||
|
|
||||||
fn read_vectored(&mut self, data: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
|
fn read_vectored(&mut self, data: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
|
||||||
ManuallyDrop::new(unsafe { WasiFd::from_raw_fd(self.as_raw_fd()) }).read(data)
|
ManuallyDrop::new(unsafe { WasiFd::from_raw_fd(self.as_raw_fd()) }).read(data)
|
||||||
}
|
}
|
||||||
|
@ -64,6 +68,7 @@ impl io::Write for Stdout {
|
||||||
fn is_write_vectored(&self) -> bool {
|
fn is_write_vectored(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush(&mut self) -> io::Result<()> {
|
fn flush(&mut self) -> io::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,13 @@ compiler-builtins-mem = ["std/compiler-builtins-mem"]
|
||||||
compiler-builtins-no-asm = ["std/compiler-builtins-no-asm"]
|
compiler-builtins-no-asm = ["std/compiler-builtins-no-asm"]
|
||||||
compiler-builtins-no-f16-f128 = ["std/compiler-builtins-no-f16-f128"]
|
compiler-builtins-no-f16-f128 = ["std/compiler-builtins-no-f16-f128"]
|
||||||
compiler-builtins-mangled-names = ["std/compiler-builtins-mangled-names"]
|
compiler-builtins-mangled-names = ["std/compiler-builtins-mangled-names"]
|
||||||
|
debug_refcell = ["std/debug_refcell"]
|
||||||
|
debug_typeid = ["std/debug_typeid"]
|
||||||
llvm-libunwind = ["std/llvm-libunwind"]
|
llvm-libunwind = ["std/llvm-libunwind"]
|
||||||
system-llvm-libunwind = ["std/system-llvm-libunwind"]
|
system-llvm-libunwind = ["std/system-llvm-libunwind"]
|
||||||
|
optimize_for_size = ["std/optimize_for_size"]
|
||||||
panic-unwind = ["std/panic_unwind"]
|
panic-unwind = ["std/panic_unwind"]
|
||||||
panic_immediate_abort = ["std/panic_immediate_abort"]
|
panic_immediate_abort = ["std/panic_immediate_abort"]
|
||||||
optimize_for_size = ["std/optimize_for_size"]
|
|
||||||
profiler = ["dep:profiler_builtins"]
|
profiler = ["dep:profiler_builtins"]
|
||||||
std_detect_file_io = ["std/std_detect_file_io"]
|
std_detect_file_io = ["std/std_detect_file_io"]
|
||||||
std_detect_dlsym_getauxval = ["std/std_detect_dlsym_getauxval"]
|
std_detect_dlsym_getauxval = ["std/std_detect_dlsym_getauxval"]
|
||||||
|
|
|
@ -100,7 +100,8 @@ mod private { // this item is private and will not be documented
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`--document-private-items` documents all items, even if they're not public.
|
`--document-private-items` includes all non-public items in the generated documentation except for `#[doc(hidden)]` items. Private items will be shown with a 🔒 icon.
|
||||||
|
|
||||||
|
|
||||||
## `-L`/`--library-path`: where to look for dependencies
|
## `-L`/`--library-path`: where to look for dependencies
|
||||||
|
|
||||||
|
|
|
@ -262,6 +262,25 @@ themselves marked as unstable. To use any of these options, pass `-Z unstable-op
|
||||||
the flag in question to Rustdoc on the command-line. To do this from Cargo, you can either use the
|
the flag in question to Rustdoc on the command-line. To do this from Cargo, you can either use the
|
||||||
`RUSTDOCFLAGS` environment variable or the `cargo rustdoc` command.
|
`RUSTDOCFLAGS` environment variable or the `cargo rustdoc` command.
|
||||||
|
|
||||||
|
### `--document-hidden-items`: Show items that are `#[doc(hidden)]`
|
||||||
|
<span id="document-hidden-items"></span>
|
||||||
|
|
||||||
|
By default, `rustdoc` does not document items that are annotated with
|
||||||
|
[`#[doc(hidden)]`](write-documentation/the-doc-attribute.html#hidden).
|
||||||
|
|
||||||
|
`--document-hidden-items` causes all items to be documented as if they did not have `#[doc(hidden)]`, except that hidden items will be shown with a 👻 icon.
|
||||||
|
|
||||||
|
Here is a table that fully describes which items are documented with each combination of `--document-hidden-items` and `--document-private-items`:
|
||||||
|
|
||||||
|
|
||||||
|
| rustdoc flags | items that will be documented |
|
||||||
|
|---------------------------------|---------------------------------------|
|
||||||
|
| neither flag | only public items that are not hidden |
|
||||||
|
| only `--document-hidden-items` | all public items |
|
||||||
|
| only `--document-private-items` | all items that are not hidden |
|
||||||
|
| both flags | all items |
|
||||||
|
|
||||||
|
|
||||||
### `--markdown-before-content`: include rendered Markdown before the content
|
### `--markdown-before-content`: include rendered Markdown before the content
|
||||||
|
|
||||||
* Tracking issue: [#44027](https://github.com/rust-lang/rust/issues/44027)
|
* Tracking issue: [#44027](https://github.com/rust-lang/rust/issues/44027)
|
||||||
|
|
|
@ -230,9 +230,8 @@ If you want to know more about inlining rules, take a look at the
|
||||||
|
|
||||||
<span id="dochidden"></span>
|
<span id="dochidden"></span>
|
||||||
|
|
||||||
Any item annotated with `#[doc(hidden)]` will not appear in the documentation, unless
|
Any item annotated with `#[doc(hidden)]` will not appear in the documentation,
|
||||||
the `strip-hidden` pass is removed. Re-exported items where one of its ancestors has
|
unless the [`--document-hidden-items`](../unstable-features.md#document-hidden-items) flag is used.
|
||||||
`#[doc(hidden)]` will be considered the same as private.
|
|
||||||
|
|
||||||
You can find more information in the [`re-exports` chapter](./re-exports.md).
|
You can find more information in the [`re-exports` chapter](./re-exports.md).
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#![feature(iter_intersperse)]
|
#![feature(iter_intersperse)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(os_str_display)]
|
|
||||||
#![feature(round_char_boundary)]
|
#![feature(round_char_boundary)]
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
|
@ -1983,7 +1983,7 @@ fn resolution_failure(
|
||||||
.tcx
|
.tcx
|
||||||
.resolutions(())
|
.resolutions(())
|
||||||
.all_macro_rules
|
.all_macro_rules
|
||||||
.contains_key(&Symbol::intern(path_str))
|
.contains(&Symbol::intern(path_str))
|
||||||
{
|
{
|
||||||
diag.note(format!(
|
diag.note(format!(
|
||||||
"`macro_rules` named `{path_str}` exists in this crate, \
|
"`macro_rules` named `{path_str}` exists in this crate, \
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue