Skip to content

Commit ddba967

Browse files
authored
Rollup merge of #93853 - steffahn:map_by_value, r=wesleywiser
Make all `hir::Map` methods consistently by-value `hir::Map` only consists of a single reference (as part of the contained `TyCtxt`) anyways, so copying is literally zero overhead compared to passing a reference
2 parents b97cceb + 7eff2fe commit ddba967

File tree

8 files changed

+108
-111
lines changed

8 files changed

+108
-111
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
763763
HirId, ImplItem, ImplItemKind, Item, ItemKind,
764764
};
765765

766-
fn maybe_body_id_of_fn(hir_map: &Map<'_>, id: HirId) -> Option<BodyId> {
766+
fn maybe_body_id_of_fn(hir_map: Map<'_>, id: HirId) -> Option<BodyId> {
767767
match hir_map.find(id) {
768768
Some(Node::Item(Item { kind: ItemKind::Fn(_, _, body_id), .. }))
769769
| Some(Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(_, body_id), .. })) => {
@@ -774,7 +774,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
774774
}
775775
let hir_map = self.infcx.tcx.hir();
776776
let mir_body_hir_id = self.mir_hir_id();
777-
if let Some(fn_body_id) = maybe_body_id_of_fn(&hir_map, mir_body_hir_id) {
777+
if let Some(fn_body_id) = maybe_body_id_of_fn(hir_map, mir_body_hir_id) {
778778
if let Block(
779779
hir::Block {
780780
expr:

compiler/rustc_hir/src/intravisit.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,22 @@ pub trait Map<'hir> {
141141
// Used when no map is actually available, forcing manual implementation of nested visitors.
142142
impl<'hir> Map<'hir> for ! {
143143
fn find(&self, _: HirId) -> Option<Node<'hir>> {
144-
unreachable!()
144+
*self;
145145
}
146146
fn body(&self, _: BodyId) -> &'hir Body<'hir> {
147-
unreachable!()
147+
*self;
148148
}
149149
fn item(&self, _: ItemId) -> &'hir Item<'hir> {
150-
unreachable!()
150+
*self;
151151
}
152152
fn trait_item(&self, _: TraitItemId) -> &'hir TraitItem<'hir> {
153-
unreachable!()
153+
*self;
154154
}
155155
fn impl_item(&self, _: ImplItemId) -> &'hir ImplItem<'hir> {
156-
unreachable!()
156+
*self;
157157
}
158158
fn foreign_item(&self, _: ForeignItemId) -> &'hir ForeignItem<'hir> {
159-
unreachable!()
159+
*self;
160160
}
161161
}
162162

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2226,7 +2226,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
22262226
bound_kind: GenericKind<'tcx>,
22272227
sub: Region<'tcx>,
22282228
) -> DiagnosticBuilder<'a> {
2229-
let hir = &self.tcx.hir();
2229+
let hir = self.tcx.hir();
22302230
// Attempt to obtain the span of the parameter so we can
22312231
// suggest adding an explicit lifetime bound to it.
22322232
let generics = self

0 commit comments

Comments
 (0)