Skip to content

Commit 72d7897

Browse files
committed
Auto merge of rust-lang#122555 - GuillaumeGomez:rollup-tr6wu54, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - rust-lang#114651 (rustdoc: add `--test-builder-wrapper` arg to support wrappers such as RUSTC_WRAPPER when building doctests) - rust-lang#122468 (Cleanup `MirBorrowckCtxt::prefixes`) - rust-lang#122496 (Greatly reduce GCC build logs) - rust-lang#122512 (Cursor.rs documentation fix) - rust-lang#122513 (hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id`) - rust-lang#122530 (less symbol interner locks) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c5b5713 + 6ec4092 commit 72d7897

File tree

50 files changed

+248
-303
lines changed

Some content is hidden

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

50 files changed

+248
-303
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::diagnostics::conflict_errors::StorageDeadOrDrop::LocalStorageDead;
3939
use crate::diagnostics::{find_all_local_uses, CapturedMessageOpt};
4040
use crate::{
4141
borrow_set::BorrowData, diagnostics::Instance, prefixes::IsPrefixOf,
42-
InitializationRequiringAction, MirBorrowckCtxt, PrefixSet, WriteKind,
42+
InitializationRequiringAction, MirBorrowckCtxt, WriteKind,
4343
};
4444

4545
use super::{
@@ -114,7 +114,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
114114
self.buffer_error(err);
115115
} else {
116116
if let Some((reported_place, _)) = self.has_move_error(&move_out_indices) {
117-
if self.prefixes(*reported_place, PrefixSet::All).any(|p| p == used_place) {
117+
if used_place.is_prefix_of(*reported_place) {
118118
debug!(
119119
"report_use_of_moved_or_uninitialized place: error suppressed mois={:?}",
120120
move_out_indices
@@ -422,8 +422,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
422422
(None, &[][..], 0)
423423
};
424424
if let Some(def_id) = def_id
425-
&& let node =
426-
self.infcx.tcx.hir_node(self.infcx.tcx.local_def_id_to_hir_id(def_id))
425+
&& let node = self.infcx.tcx.hir_node_by_def_id(def_id)
427426
&& let Some(fn_sig) = node.fn_sig()
428427
&& let Some(ident) = node.ident()
429428
&& let Some(pos) = args.iter().position(|arg| arg.hir_id == expr.hir_id)
@@ -1995,34 +1994,23 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19951994
kind: Option<WriteKind>,
19961995
) {
19971996
let drop_span = place_span.1;
1998-
let root_place =
1999-
self.prefixes(borrow.borrowed_place.as_ref(), PrefixSet::All).last().unwrap();
1997+
let borrowed_local = borrow.borrowed_place.local;
20001998

20011999
let borrow_spans = self.retrieve_borrow_spans(borrow);
20022000
let borrow_span = borrow_spans.var_or_use_path_span();
20032001

2004-
assert!(root_place.projection.is_empty());
2005-
let proper_span = self.body.local_decls[root_place.local].source_info.span;
2006-
2007-
let root_place_projection = self.infcx.tcx.mk_place_elems(root_place.projection);
2002+
let proper_span = self.body.local_decls[borrowed_local].source_info.span;
20082003

2009-
if self.access_place_error_reported.contains(&(
2010-
Place { local: root_place.local, projection: root_place_projection },
2011-
borrow_span,
2012-
)) {
2004+
if self.access_place_error_reported.contains(&(Place::from(borrowed_local), borrow_span)) {
20132005
debug!(
20142006
"suppressing access_place error when borrow doesn't live long enough for {:?}",
20152007
borrow_span
20162008
);
20172009
return;
20182010
}
20192011

2020-
self.access_place_error_reported.insert((
2021-
Place { local: root_place.local, projection: root_place_projection },
2022-
borrow_span,
2023-
));
2012+
self.access_place_error_reported.insert((Place::from(borrowed_local), borrow_span));
20242013

2025-
let borrowed_local = borrow.borrowed_place.local;
20262014
if self.body.local_decls[borrowed_local].is_ref_to_thread_local() {
20272015
let err =
20282016
self.report_thread_local_value_does_not_live_long_enough(drop_span, borrow_span);
@@ -2544,9 +2532,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
25442532
};
25452533
(format!("{local_kind}`{place_desc}`"), format!("`{place_desc}` is borrowed here"))
25462534
} else {
2547-
let root_place =
2548-
self.prefixes(borrow.borrowed_place.as_ref(), PrefixSet::All).last().unwrap();
2549-
let local = root_place.local;
2535+
let local = borrow.borrowed_place.local;
25502536
match self.body.local_kind(local) {
25512537
LocalKind::Arg => (
25522538
"function parameter".to_string(),

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -672,11 +672,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
672672
};
673673
(
674674
true,
675-
td.as_local().and_then(|tld| match self.infcx.tcx.opt_hir_node_by_def_id(tld) {
676-
Some(Node::Item(hir::Item {
677-
kind: hir::ItemKind::Trait(_, _, _, _, items),
678-
..
679-
})) => {
675+
td.as_local().and_then(|tld| match self.infcx.tcx.hir_node_by_def_id(tld) {
676+
Node::Item(hir::Item { kind: hir::ItemKind::Trait(_, _, _, _, items), .. }) => {
680677
let mut f_in_trait_opt = None;
681678
for hir::TraitItemRef { id: fi, kind: k, .. } in *items {
682679
let hi = fi.hir_id();
@@ -1475,11 +1472,9 @@ fn get_mut_span_in_struct_field<'tcx>(
14751472
if let ty::Ref(_, ty, _) = ty.kind()
14761473
&& let ty::Adt(def, _) = ty.kind()
14771474
&& let field = def.all_fields().nth(field.index())?
1478-
// Use the HIR types to construct the diagnostic message.
1479-
&& let node = tcx.opt_hir_node_by_def_id(field.did.as_local()?)?
14801475
// Now we're dealing with the actual struct that we're going to suggest a change to,
14811476
// we can expect a field that is an immutable reference to a type.
1482-
&& let hir::Node::Field(field) = node
1477+
&& let hir::Node::Field(field) = tcx.hir_node_by_def_id(field.did.as_local()?)
14831478
&& let hir::TyKind::Ref(lt, hir::MutTy { mutbl: hir::Mutability::Not, ty }) = field.ty.kind
14841479
{
14851480
return Some(lt.ident.span.between(ty.span));

compiler/rustc_borrowck/src/prefixes.rs

+21-68
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
//! From the NLL RFC: "The deep [aka 'supporting'] prefixes for an
2-
//! place are formed by stripping away fields and derefs, except that
3-
//! we stop when we reach the deref of a shared reference. [...] "
4-
//!
1+
//! From the NLL RFC:
52
//! "Shallow prefixes are found by stripping away fields, but stop at
63
//! any dereference. So: writing a path like `a` is illegal if `a.b`
74
//! is borrowed. But: writing `a` is legal if `*a` is borrowed,
85
//! whether or not `a` is a shared or mutable reference. [...] "
96
107
use super::MirBorrowckCtxt;
118

12-
use rustc_hir as hir;
13-
use rustc_middle::mir::{Body, PlaceRef, ProjectionElem};
14-
use rustc_middle::ty::{self, TyCtxt};
9+
use rustc_middle::mir::{PlaceRef, ProjectionElem};
1510

1611
pub trait IsPrefixOf<'tcx> {
1712
fn is_prefix_of(&self, other: PlaceRef<'tcx>) -> bool;
@@ -25,9 +20,7 @@ impl<'tcx> IsPrefixOf<'tcx> for PlaceRef<'tcx> {
2520
}
2621
}
2722

28-
pub(super) struct Prefixes<'cx, 'tcx> {
29-
body: &'cx Body<'tcx>,
30-
tcx: TyCtxt<'tcx>,
23+
pub(super) struct Prefixes<'tcx> {
3124
kind: PrefixSet,
3225
next: Option<PlaceRef<'tcx>>,
3326
}
@@ -39,24 +32,18 @@ pub(super) enum PrefixSet {
3932
All,
4033
/// Stops at any dereference.
4134
Shallow,
42-
/// Stops at the deref of a shared reference.
43-
Supporting,
4435
}
4536

4637
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
4738
/// Returns an iterator over the prefixes of `place`
4839
/// (inclusive) from longest to smallest, potentially
4940
/// terminating the iteration early based on `kind`.
50-
pub(super) fn prefixes(
51-
&self,
52-
place_ref: PlaceRef<'tcx>,
53-
kind: PrefixSet,
54-
) -> Prefixes<'cx, 'tcx> {
55-
Prefixes { next: Some(place_ref), kind, body: self.body, tcx: self.infcx.tcx }
41+
pub(super) fn prefixes(&self, place_ref: PlaceRef<'tcx>, kind: PrefixSet) -> Prefixes<'tcx> {
42+
Prefixes { next: Some(place_ref), kind }
5643
}
5744
}
5845

59-
impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
46+
impl<'tcx> Iterator for Prefixes<'tcx> {
6047
type Item = PlaceRef<'tcx>;
6148
fn next(&mut self) -> Option<Self::Item> {
6249
let mut cursor = self.next?;
@@ -91,57 +78,23 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
9178
panic!("Subtype projection is not allowed before borrow check")
9279
}
9380
ProjectionElem::Deref => {
94-
// (handled below)
81+
match self.kind {
82+
PrefixSet::Shallow => {
83+
// Shallow prefixes are found by stripping away
84+
// fields, but stop at *any* dereference.
85+
// So we can just stop the traversal now.
86+
self.next = None;
87+
return Some(cursor);
88+
}
89+
PrefixSet::All => {
90+
// All prefixes: just blindly enqueue the base
91+
// of the projection.
92+
self.next = Some(cursor_base);
93+
return Some(cursor);
94+
}
95+
}
9596
}
9697
}
97-
98-
assert_eq!(elem, ProjectionElem::Deref);
99-
100-
match self.kind {
101-
PrefixSet::Shallow => {
102-
// Shallow prefixes are found by stripping away
103-
// fields, but stop at *any* dereference.
104-
// So we can just stop the traversal now.
105-
self.next = None;
106-
return Some(cursor);
107-
}
108-
PrefixSet::All => {
109-
// All prefixes: just blindly enqueue the base
110-
// of the projection.
111-
self.next = Some(cursor_base);
112-
return Some(cursor);
113-
}
114-
PrefixSet::Supporting => {
115-
// Fall through!
116-
}
117-
}
118-
119-
assert_eq!(self.kind, PrefixSet::Supporting);
120-
// Supporting prefixes: strip away fields and
121-
// derefs, except we stop at the deref of a shared
122-
// reference.
123-
124-
let ty = cursor_base.ty(self.body, self.tcx).ty;
125-
match ty.kind() {
126-
ty::RawPtr(_) | ty::Ref(_ /*rgn*/, _ /*ty*/, hir::Mutability::Not) => {
127-
// don't continue traversing over derefs of raw pointers or shared
128-
// borrows.
129-
self.next = None;
130-
return Some(cursor);
131-
}
132-
133-
ty::Ref(_ /*rgn*/, _ /*ty*/, hir::Mutability::Mut) => {
134-
self.next = Some(cursor_base);
135-
return Some(cursor);
136-
}
137-
138-
ty::Adt(..) if ty.is_box() => {
139-
self.next = Some(cursor_base);
140-
return Some(cursor);
141-
}
142-
143-
_ => panic!("unknown type fed to Projection Deref."),
144-
}
14598
}
14699
}
147100
}

compiler/rustc_hir_analysis/src/check/entry.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
4242
if !def_id.is_local() {
4343
return None;
4444
}
45-
let hir_id = tcx.local_def_id_to_hir_id(def_id.expect_local());
46-
match tcx.hir_node(hir_id) {
45+
match tcx.hir_node_by_def_id(def_id.expect_local()) {
4746
Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. }) => {
4847
generics.params.is_empty().not().then_some(generics.span)
4948
}
@@ -57,8 +56,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
5756
if !def_id.is_local() {
5857
return None;
5958
}
60-
let hir_id = tcx.local_def_id_to_hir_id(def_id.expect_local());
61-
match tcx.hir_node(hir_id) {
59+
match tcx.hir_node_by_def_id(def_id.expect_local()) {
6260
Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. }) => {
6361
Some(generics.where_clause_span)
6462
}
@@ -79,8 +77,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
7977
if !def_id.is_local() {
8078
return None;
8179
}
82-
let hir_id = tcx.local_def_id_to_hir_id(def_id.expect_local());
83-
match tcx.hir_node(hir_id) {
80+
match tcx.hir_node_by_def_id(def_id.expect_local()) {
8481
Node::Item(hir::Item { kind: hir::ItemKind::Fn(fn_sig, _, _), .. }) => {
8582
Some(fn_sig.decl.output.span())
8683
}

compiler/rustc_hir_analysis/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn get_owner_return_paths(
130130
) -> Option<(LocalDefId, ReturnsVisitor<'_>)> {
131131
let hir_id = tcx.local_def_id_to_hir_id(def_id);
132132
let parent_id = tcx.hir().get_parent_item(hir_id).def_id;
133-
tcx.opt_hir_node_by_def_id(parent_id).and_then(|node| node.body_id()).map(|body_id| {
133+
tcx.hir_node_by_def_id(parent_id).body_id().map(|body_id| {
134134
let body = tcx.hir().body(body_id);
135135
let mut visitor = ReturnsVisitor::default();
136136
visitor.visit_body(body);

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1969,13 +1969,10 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
19691969
// Match the existing behavior.
19701970
if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) {
19711971
let pred = self.normalize(span, None, pred);
1972-
let hir_node = tcx.opt_hir_node_by_def_id(self.body_def_id);
19731972

19741973
// only use the span of the predicate clause (#90869)
1975-
1976-
if let Some(hir::Generics { predicates, .. }) =
1977-
hir_node.and_then(|node| node.generics())
1978-
{
1974+
let hir_node = tcx.hir_node_by_def_id(self.body_def_id);
1975+
if let Some(hir::Generics { predicates, .. }) = hir_node.generics() {
19791976
span = predicates
19801977
.iter()
19811978
// There seems to be no better way to find out which predicate we are in

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,8 @@ pub(super) fn implied_predicates_with_filter(
609609
return tcx.super_predicates_of(trait_def_id);
610610
};
611611

612-
let trait_hir_id = tcx.local_def_id_to_hir_id(trait_def_id);
613-
614-
let Node::Item(item) = tcx.hir_node(trait_hir_id) else {
615-
bug!("trait_node_id {} is not an item", trait_hir_id);
612+
let Node::Item(item) = tcx.hir_node_by_def_id(trait_def_id) else {
613+
bug!("trait_def_id {trait_def_id:?} is not an item");
616614
};
617615

618616
let (generics, bounds) = match item.kind {

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,10 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
371371
return mir_opaque_ty.ty;
372372
}
373373

374-
let scope = tcx.local_def_id_to_hir_id(owner_def_id);
375-
debug!(?scope);
374+
debug!(?owner_def_id);
376375
let mut locator = RpitConstraintChecker { def_id, tcx, found: mir_opaque_ty };
377376

378-
match tcx.hir_node(scope) {
377+
match tcx.hir_node_by_def_id(owner_def_id) {
379378
Node::Item(it) => intravisit::walk_item(&mut locator, it),
380379
Node::ImplItem(it) => intravisit::walk_impl_item(&mut locator, it),
381380
Node::TraitItem(it) => intravisit::walk_trait_item(&mut locator, it),

compiler/rustc_hir_typeck/src/_match.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
234234
}
235235

236236
// Next, make sure that we have no type expectation.
237-
let Some(ret) = self
238-
.tcx
239-
.opt_hir_node_by_def_id(self.body_id)
240-
.and_then(|owner| owner.fn_decl())
241-
.map(|decl| decl.output.span())
237+
let Some(ret) =
238+
self.tcx.hir_node_by_def_id(self.body_id).fn_decl().map(|decl| decl.output.span())
242239
else {
243240
return;
244241
};

compiler/rustc_hir_typeck/src/expr.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -890,21 +890,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
890890

891891
let encl_item_id = self.tcx.hir().get_parent_item(expr.hir_id);
892892

893-
if let Some(hir::Node::Item(hir::Item {
894-
kind: hir::ItemKind::Fn(..),
895-
span: encl_fn_span,
896-
..
897-
}))
898-
| Some(hir::Node::TraitItem(hir::TraitItem {
893+
if let hir::Node::Item(hir::Item {
894+
kind: hir::ItemKind::Fn(..), span: encl_fn_span, ..
895+
})
896+
| hir::Node::TraitItem(hir::TraitItem {
899897
kind: hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)),
900898
span: encl_fn_span,
901899
..
902-
}))
903-
| Some(hir::Node::ImplItem(hir::ImplItem {
900+
})
901+
| hir::Node::ImplItem(hir::ImplItem {
904902
kind: hir::ImplItemKind::Fn(..),
905903
span: encl_fn_span,
906904
..
907-
})) = self.tcx.opt_hir_node_by_def_id(encl_item_id.def_id)
905+
}) = self.tcx.hir_node_by_def_id(encl_item_id.def_id)
908906
{
909907
// We are inside a function body, so reporting "return statement
910908
// outside of function body" needs an explanation.

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -2172,16 +2172,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21722172
// Try to find earlier invocations of this closure to find if the type mismatch
21732173
// is because of inference. If we find one, point at them.
21742174
let mut call_finder = FindClosureArg { tcx: self.tcx, calls: vec![] };
2175-
let node = self
2176-
.tcx
2177-
.opt_local_def_id_to_hir_id(
2178-
self.tcx.hir().get_parent_item(call_expr.hir_id).def_id,
2179-
)
2180-
.map(|hir_id| self.tcx.hir_node(hir_id));
2181-
match node {
2182-
Some(hir::Node::Item(item)) => call_finder.visit_item(item),
2183-
Some(hir::Node::TraitItem(item)) => call_finder.visit_trait_item(item),
2184-
Some(hir::Node::ImplItem(item)) => call_finder.visit_impl_item(item),
2175+
let parent_def_id = self.tcx.hir().get_parent_item(call_expr.hir_id).def_id;
2176+
match self.tcx.hir_node_by_def_id(parent_def_id) {
2177+
hir::Node::Item(item) => call_finder.visit_item(item),
2178+
hir::Node::TraitItem(item) => call_finder.visit_trait_item(item),
2179+
hir::Node::ImplItem(item) => call_finder.visit_impl_item(item),
21852180
_ => {}
21862181
}
21872182
let typeck = self.typeck_results.borrow();

0 commit comments

Comments
 (0)