Skip to content

Commit be9e80d

Browse files
committed
Auto merge of #118892 - matthiaskrgr:rollup-vqeqhsf, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #117050 ([`RFC 3086`] Attempt to try to resolve blocking concerns ) - #118500 (Move some methods from `tcx.hir()` to `tcx`) - #118871 (Coroutine variant fields can be uninitialized) - #118872 (Add rustX check to codeblock attributes lint) - #118884 (NFC: simplify merging of two vecs) - #118885 (clippy::complexity fixes) - #118886 (Clean up variables in `search.js`) - #118887 (Typo) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3340d49 + 755df90 commit be9e80d

File tree

158 files changed

+1317
-758
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+1317
-758
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::mir::{
1818
PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
1919
VarBindingForm,
2020
};
21-
use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty};
21+
use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty, TyCtxt};
2222
use rustc_middle::util::CallKind;
2323
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
2424
use rustc_span::def_id::LocalDefId;
@@ -398,7 +398,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
398398
}
399399
let typeck = self.infcx.tcx.typeck(self.mir_def_id());
400400
let hir_id = hir.parent_id(expr.hir_id);
401-
if let Some(parent) = hir.find(hir_id) {
401+
if let Some(parent) = self.infcx.tcx.opt_hir_node(hir_id) {
402402
let (def_id, args, offset) = if let hir::Node::Expr(parent_expr) = parent
403403
&& let hir::ExprKind::MethodCall(_, _, args, _) = parent_expr.kind
404404
&& let Some(def_id) = typeck.type_dependent_def_id(parent_expr.hir_id)
@@ -413,7 +413,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
413413
(None, &[][..], 0)
414414
};
415415
if let Some(def_id) = def_id
416-
&& let Some(node) = hir.find(self.infcx.tcx.local_def_id_to_hir_id(def_id))
416+
&& let Some(node) = self
417+
.infcx
418+
.tcx
419+
.opt_hir_node(self.infcx.tcx.local_def_id_to_hir_id(def_id))
417420
&& let Some(fn_sig) = node.fn_sig()
418421
&& let Some(ident) = node.ident()
419422
&& let Some(pos) = args.iter().position(|arg| arg.hir_id == expr.hir_id)
@@ -1317,7 +1320,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13171320
let tcx = self.infcx.tcx;
13181321
let hir = tcx.hir();
13191322

1320-
let Some(body_id) = hir.get(self.mir_hir_id()).body_id() else { return };
1323+
let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return };
13211324
let typeck_results = tcx.typeck(self.mir_def_id());
13221325

13231326
struct ExprFinder<'hir> {
@@ -1509,7 +1512,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15091512
let local_ty = self.body.local_decls[local].ty;
15101513

15111514
// Get the body the error happens in
1512-
let Some(body_id) = hir.get(self.mir_hir_id()).body_id() else { return };
1515+
let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return };
15131516

15141517
let body_expr = hir.body(body_id).value;
15151518

@@ -1558,7 +1561,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15581561
// Check that the parent of the closure is a method call,
15591562
// with receiver matching with local's type (modulo refs)
15601563
let parent = hir.parent_id(closure_expr.hir_id);
1561-
if let hir::Node::Expr(parent) = hir.get(parent) {
1564+
if let hir::Node::Expr(parent) = tcx.hir_node(parent) {
15621565
if let hir::ExprKind::MethodCall(_, recv, ..) = parent.kind {
15631566
let recv_ty = typeck_results.expr_ty(recv);
15641567

@@ -1635,15 +1638,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16351638
issued_spans: &UseSpans<'tcx>,
16361639
) {
16371640
let UseSpans::ClosureUse { capture_kind_span, .. } = issued_spans else { return };
1638-
let hir = self.infcx.tcx.hir();
16391641

1640-
struct ExpressionFinder<'hir> {
1642+
struct ExpressionFinder<'tcx> {
16411643
capture_span: Span,
16421644
closure_change_spans: Vec<Span>,
16431645
closure_arg_span: Option<Span>,
16441646
in_closure: bool,
16451647
suggest_arg: String,
1646-
hir: rustc_middle::hir::map::Map<'hir>,
1648+
tcx: TyCtxt<'tcx>,
16471649
closure_local_id: Option<hir::HirId>,
16481650
closure_call_changes: Vec<(Span, String)>,
16491651
}
@@ -1657,7 +1659,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16571659
fn_decl: hir::FnDecl { inputs, .. },
16581660
..
16591661
}) = e.kind
1660-
&& let Some(hir::Node::Expr(body)) = self.hir.find(body.hir_id)
1662+
&& let Some(hir::Node::Expr(body)) = self.tcx.opt_hir_node(body.hir_id)
16611663
{
16621664
self.suggest_arg = "this: &Self".to_string();
16631665
if inputs.len() > 0 {
@@ -1722,8 +1724,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17221724
if let Some(hir::Node::ImplItem(hir::ImplItem {
17231725
kind: hir::ImplItemKind::Fn(_fn_sig, body_id),
17241726
..
1725-
})) = hir.find(self.mir_hir_id())
1726-
&& let Some(hir::Node::Expr(expr)) = hir.find(body_id.hir_id)
1727+
})) = self.infcx.tcx.opt_hir_node(self.mir_hir_id())
1728+
&& let Some(hir::Node::Expr(expr)) = self.infcx.tcx.opt_hir_node(body_id.hir_id)
17271729
{
17281730
let mut finder = ExpressionFinder {
17291731
capture_span: *capture_kind_span,
@@ -1733,7 +1735,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17331735
suggest_arg: String::new(),
17341736
closure_local_id: None,
17351737
closure_call_changes: vec![],
1736-
hir,
1738+
tcx: self.infcx.tcx,
17371739
};
17381740
finder.visit_expr(expr);
17391741

@@ -2294,7 +2296,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22942296
let proper_span = proper_span.source_callsite();
22952297
if let Some(scope) = self.body.source_scopes.get(source_info.scope)
22962298
&& let ClearCrossCrate::Set(scope_data) = &scope.local_data
2297-
&& let Some(node) = self.infcx.tcx.hir().find(scope_data.lint_root)
2299+
&& let Some(node) = self.infcx.tcx.opt_hir_node(scope_data.lint_root)
22982300
&& let Some(id) = node.body_id()
22992301
&& let hir::ExprKind::Block(block, _) = self.infcx.tcx.hir().body(id).value.kind
23002302
{

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
8787
if let hir::ExprKind::Path(hir::QPath::Resolved(None, p)) = expr.kind
8888
&& let [hir::PathSegment { ident, args: None, .. }] = p.segments
8989
&& let hir::def::Res::Local(hir_id) = p.res
90-
&& let Some(hir::Node::Pat(pat)) = tcx.hir().find(hir_id)
90+
&& let Some(hir::Node::Pat(pat)) = tcx.opt_hir_node(hir_id)
9191
{
9292
err.span_label(pat.span, format!("binding `{ident}` declared here"));
9393
}

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+26-27
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
396396

397397
let upvar_hir_id = captured_place.get_root_variable();
398398

399-
if let Some(Node::Pat(pat)) = self.infcx.tcx.hir().find(upvar_hir_id)
399+
if let Some(Node::Pat(pat)) = self.infcx.tcx.opt_hir_node(upvar_hir_id)
400400
&& let hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, upvar_ident, _) =
401401
pat.kind
402402
{
@@ -661,7 +661,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
661661
if self.body.local_kind(local) != LocalKind::Arg {
662662
return (false, None);
663663
}
664-
let hir_map = self.infcx.tcx.hir();
665664
let my_def = self.body.source.def_id();
666665
let my_hir = self.infcx.tcx.local_def_id_to_hir_id(my_def.as_local().unwrap());
667666
let Some(td) =
@@ -671,7 +670,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
671670
};
672671
(
673672
true,
674-
td.as_local().and_then(|tld| match hir_map.find_by_def_id(tld) {
673+
td.as_local().and_then(|tld| match self.infcx.tcx.opt_hir_node_by_def_id(tld) {
675674
Some(Node::Item(hir::Item {
676675
kind: hir::ItemKind::Trait(_, _, _, _, items),
677676
..
@@ -682,25 +681,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
682681
if !matches!(k, hir::AssocItemKind::Fn { .. }) {
683682
continue;
684683
}
685-
if hir_map.name(hi) != hir_map.name(my_hir) {
684+
if self.infcx.tcx.hir().name(hi) != self.infcx.tcx.hir().name(my_hir) {
686685
continue;
687686
}
688687
f_in_trait_opt = Some(hi);
689688
break;
690689
}
691-
f_in_trait_opt.and_then(|f_in_trait| match hir_map.find(f_in_trait) {
692-
Some(Node::TraitItem(hir::TraitItem {
693-
kind:
694-
hir::TraitItemKind::Fn(
695-
hir::FnSig { decl: hir::FnDecl { inputs, .. }, .. },
696-
_,
697-
),
698-
..
699-
})) => {
700-
let hir::Ty { span, .. } = inputs[local.index() - 1];
701-
Some(span)
690+
f_in_trait_opt.and_then(|f_in_trait| {
691+
match self.infcx.tcx.opt_hir_node(f_in_trait) {
692+
Some(Node::TraitItem(hir::TraitItem {
693+
kind:
694+
hir::TraitItemKind::Fn(
695+
hir::FnSig { decl: hir::FnDecl { inputs, .. }, .. },
696+
_,
697+
),
698+
..
699+
})) => {
700+
let hir::Ty { span, .. } = inputs[local.index() - 1];
701+
Some(span)
702+
}
703+
_ => None,
702704
}
703-
_ => None,
704705
})
705706
}
706707
_ => None,
@@ -741,12 +742,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
741742
}
742743
}
743744

744-
let hir_map = self.infcx.tcx.hir();
745745
let def_id = self.body.source.def_id();
746746
let hir_id = if let Some(local_def_id) = def_id.as_local()
747-
&& let Some(body_id) = hir_map.maybe_body_owned_by(local_def_id)
747+
&& let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
748748
{
749-
let body = hir_map.body(body_id);
749+
let body = self.infcx.tcx.hir().body(body_id);
750750
let mut v = BindingFinder { span: pat_span, hir_id: None };
751751
v.visit_body(body);
752752
v.hir_id
@@ -762,7 +762,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
762762
&& let Some(hir::Node::Local(hir::Local {
763763
pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
764764
..
765-
})) = hir_map.find(hir_id)
765+
})) = self.infcx.tcx.opt_hir_node(hir_id)
766766
&& let Ok(name) =
767767
self.infcx.tcx.sess.source_map().span_to_snippet(local_decl.source_info.span)
768768
{
@@ -942,7 +942,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
942942
let closure_id = self.mir_hir_id();
943943
let closure_span = self.infcx.tcx.def_span(self.mir_def_id());
944944
let fn_call_id = hir.parent_id(closure_id);
945-
let node = hir.get(fn_call_id);
945+
let node = self.infcx.tcx.hir_node(fn_call_id);
946946
let def_id = hir.enclosing_body_owner(fn_call_id);
947947
let mut look_at_return = true;
948948
// If we can detect the expression to be an `fn` call where the closure was an argument,
@@ -1001,7 +1001,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10011001
if look_at_return && hir.get_return_block(closure_id).is_some() {
10021002
// ...otherwise we are probably in the tail expression of the function, point at the
10031003
// return type.
1004-
match hir.get_by_def_id(hir.get_parent_item(fn_call_id).def_id) {
1004+
match self.infcx.tcx.hir_node_by_def_id(hir.get_parent_item(fn_call_id).def_id) {
10051005
hir::Node::Item(hir::Item { ident, kind: hir::ItemKind::Fn(sig, ..), .. })
10061006
| hir::Node::TraitItem(hir::TraitItem {
10071007
ident,
@@ -1199,12 +1199,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11991199
hir::intravisit::walk_stmt(self, s);
12001200
}
12011201
}
1202-
let hir_map = self.infcx.tcx.hir();
12031202
let def_id = self.body.source.def_id();
12041203
let hir_id = if let Some(local_def_id) = def_id.as_local()
1205-
&& let Some(body_id) = hir_map.maybe_body_owned_by(local_def_id)
1204+
&& let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
12061205
{
1207-
let body = hir_map.body(body_id);
1206+
let body = self.infcx.tcx.hir().body(body_id);
12081207
let mut v = BindingFinder { span: err_label_span, hir_id: None };
12091208
v.visit_body(body);
12101209
v.hir_id
@@ -1213,7 +1212,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
12131212
};
12141213

12151214
if let Some(hir_id) = hir_id
1216-
&& let Some(hir::Node::Local(local)) = hir_map.find(hir_id)
1215+
&& let Some(hir::Node::Local(local)) = self.infcx.tcx.opt_hir_node(hir_id)
12171216
{
12181217
let tables = self.infcx.tcx.typeck(def_id.as_local().unwrap());
12191218
if let Some(clone_trait) = self.infcx.tcx.lang_items().clone_trait()
@@ -1496,7 +1495,7 @@ fn get_mut_span_in_struct_field<'tcx>(
14961495
&& let ty::Adt(def, _) = ty.kind()
14971496
&& let field = def.all_fields().nth(field.index())?
14981497
// Use the HIR types to construct the diagnostic message.
1499-
&& let node = tcx.hir().find_by_def_id(field.did.as_local()?)?
1498+
&& let node = tcx.opt_hir_node_by_def_id(field.did.as_local()?)?
15001499
// Now we're dealing with the actual struct that we're going to suggest a change to,
15011500
// we can expect a field that is an immutable reference to a type.
15021501
&& let hir::Node::Field(field) = node

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
672672

673673
let mir_hir_id = self.mir_hir_id();
674674

675-
let (return_span, mir_description, hir_ty) = match hir.get(mir_hir_id) {
675+
let (return_span, mir_description, hir_ty) = match tcx.hir_node(mir_hir_id) {
676676
hir::Node::Expr(hir::Expr {
677677
kind: hir::ExprKind::Closure(&hir::Closure { fn_decl, body, fn_decl_span, .. }),
678678
..
@@ -689,7 +689,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
689689
hir::CoroutineSource::Closure => " of async closure",
690690
hir::CoroutineSource::Fn => {
691691
let parent_item =
692-
hir.get_by_def_id(hir.get_parent_item(mir_hir_id).def_id);
692+
tcx.hir_node_by_def_id(hir.get_parent_item(mir_hir_id).def_id);
693693
let output = &parent_item
694694
.fn_decl()
695695
.expect("coroutine lowered from async fn should be in fn")
@@ -706,7 +706,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
706706
hir::CoroutineSource::Closure => " of gen closure",
707707
hir::CoroutineSource::Fn => {
708708
let parent_item =
709-
hir.get_by_def_id(hir.get_parent_item(mir_hir_id).def_id);
709+
tcx.hir_node_by_def_id(hir.get_parent_item(mir_hir_id).def_id);
710710
let output = &parent_item
711711
.fn_decl()
712712
.expect("coroutine lowered from gen fn should be in fn")
@@ -721,7 +721,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
721721
hir::CoroutineSource::Closure => " of async gen closure",
722722
hir::CoroutineSource::Fn => {
723723
let parent_item =
724-
hir.get_by_def_id(hir.get_parent_item(mir_hir_id).def_id);
724+
tcx.hir_node_by_def_id(hir.get_parent_item(mir_hir_id).def_id);
725725
let output = &parent_item
726726
.fn_decl()
727727
.expect("coroutine lowered from async gen fn should be in fn")
@@ -841,7 +841,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
841841
let type_name =
842842
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;
843843

844-
let yield_span = match tcx.hir().get(self.mir_hir_id()) {
844+
let yield_span = match tcx.hir_node(self.mir_hir_id()) {
845845
hir::Node::Expr(hir::Expr {
846846
kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
847847
..

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
3333
/// return if it has a `const` modifier. If it is an intrinsic, report whether said intrinsic
3434
/// has a `rustc_const_{un,}stable` attribute. Otherwise, return `Constness::NotConst`.
3535
fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
36-
let node = tcx.hir().get_by_def_id(def_id);
36+
let node = tcx.hir_node_by_def_id(def_id);
3737

3838
match node {
3939
hir::Node::Ctor(_)

compiler/rustc_const_eval/src/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
227227
// Sometimes the index is beyond the number of upvars (seen
228228
// for a coroutine).
229229
let var_hir_id = captured_place.get_root_variable();
230-
let node = self.ecx.tcx.hir().get(var_hir_id);
230+
let node = self.ecx.tcx.hir_node(var_hir_id);
231231
if let hir::Node::Pat(pat) = node {
232232
if let hir::PatKind::Binding(_, _, ident, _) = pat.kind {
233233
name = Some(ident.name);

compiler/rustc_const_eval/src/interpret/visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
2121
/// `read_discriminant` can be hooked for better error messages.
2222
#[inline(always)]
2323
fn read_discriminant(&mut self, v: &Self::V) -> InterpResult<'tcx, VariantIdx> {
24-
Ok(self.ecx().read_discriminant(&v.to_op(self.ecx())?)?)
24+
self.ecx().read_discriminant(&v.to_op(self.ecx())?)
2525
}
2626

2727
/// This function provides the chance to reorder the order in which fields are visited for

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
119119
match self_ty.kind() {
120120
Param(param_ty) => {
121121
debug!(?param_ty);
122-
let caller_hir_id = tcx.local_def_id_to_hir_id(caller);
123-
if let Some(generics) = tcx.hir().get(caller_hir_id).generics() {
122+
if let Some(generics) = tcx.hir_node_by_def_id(caller).generics() {
124123
let constraint = with_no_trimmed_paths!(format!(
125124
"~const {}",
126125
trait_ref.print_only_trait_path()

0 commit comments

Comments
 (0)