Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 038f9e6

Browse files
committed
Auto merge of rust-lang#99948 - Dylan-DPC:rollup-ed5136t, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#99311 (change maybe_body_owned_by to take local def id) - rust-lang#99862 (Improve type mismatch w/ function signatures) - rust-lang#99895 (don't call type ascription "cast") - rust-lang#99900 (remove some manual hash stable impls) - rust-lang#99903 (Add diagnostic when using public instead of pub) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1202bba + df2cf97 commit 038f9e6

File tree

55 files changed

+332
-295
lines changed

Some content is hidden

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

55 files changed

+332
-295
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
353353

354354
// We use the statements were the binding was initialized, and inspect the HIR to look
355355
// for the branching codepaths that aren't covered, to point at them.
356-
let hir_id = self.mir_hir_id();
357356
let map = self.infcx.tcx.hir();
358-
let body_id = map.body_owned_by(hir_id);
357+
let body_id = map.body_owned_by(self.mir_def_id());
359358
let body = map.body(body_id);
360359

361360
let mut visitor = ConditionVisitor { spans: &spans, name: &name, errors: vec![] };

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
853853
let closure_id = self.mir_hir_id();
854854
let fn_call_id = hir.get_parent_node(closure_id);
855855
let node = hir.get(fn_call_id);
856-
let item_id = hir.enclosing_body_owner(fn_call_id);
856+
let def_id = hir.enclosing_body_owner(fn_call_id);
857857
let mut look_at_return = true;
858858
// If we can detect the expression to be an `fn` call where the closure was an argument,
859859
// we point at the `fn` definition argument...
@@ -864,7 +864,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
864864
.filter(|(_, arg)| arg.hir_id == closure_id)
865865
.map(|(pos, _)| pos)
866866
.next();
867-
let def_id = hir.local_def_id(item_id);
868867
let tables = self.infcx.tcx.typeck(def_id);
869868
if let Some(ty::FnDef(def_id, _)) =
870869
tables.node_type_opt(func.hir_id).as_ref().map(|ty| ty.kind())

compiler/rustc_data_structures/src/stable_hasher.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc_index::bit_set;
33
use rustc_index::vec;
44
use smallvec::SmallVec;
55
use std::hash::{BuildHasher, Hash, Hasher};
6+
use std::marker::PhantomData;
67
use std::mem;
78

89
#[cfg(test)]
@@ -261,6 +262,10 @@ impl<CTX> HashStable<CTX> for ! {
261262
}
262263
}
263264

265+
impl<CTX, T> HashStable<CTX> for PhantomData<T> {
266+
fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut StableHasher) {}
267+
}
268+
264269
impl<CTX> HashStable<CTX> for ::std::num::NonZeroU32 {
265270
#[inline]
266271
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {

compiler/rustc_driver/src/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<'tcx> pprust_hir::PpAnn for TypedAnnotation<'tcx> {
328328
let typeck_results = self.maybe_typeck_results.get().or_else(|| {
329329
self.tcx
330330
.hir()
331-
.maybe_body_owned_by(self.tcx.hir().local_def_id_to_hir_id(expr.hir_id.owner))
331+
.maybe_body_owned_by(expr.hir_id.owner)
332332
.map(|body_id| self.tcx.typeck_body(body_id))
333333
});
334334

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ pub fn find_param_with_region<'tcx>(
4949
};
5050

5151
let hir = &tcx.hir();
52-
let hir_id = hir.local_def_id_to_hir_id(id.as_local()?);
53-
let body_id = hir.maybe_body_owned_by(hir_id)?;
54-
let body = hir.body(body_id);
52+
let def_id = id.as_local()?;
53+
let hir_id = hir.local_def_id_to_hir_id(def_id);
5554

55+
// FIXME: use def_kind
5656
// Don't perform this on closures
5757
match hir.get(hir_id) {
5858
hir::Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure { .. }, .. }) => {
@@ -61,11 +61,14 @@ pub fn find_param_with_region<'tcx>(
6161
_ => {}
6262
}
6363

64+
let body_id = hir.maybe_body_owned_by(def_id)?;
65+
6466
let owner_id = hir.body_owner(body_id);
6567
let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap();
6668
let poly_fn_sig = tcx.fn_sig(id);
6769

6870
let fn_sig = tcx.liberate_late_bound_regions(id, poly_fn_sig);
71+
let body = hir.body(body_id);
6972
body.params
7073
.iter()
7174
.take(if fn_sig.c_variadic {

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16161616
fn encode_info_for_anon_const(&mut self, id: hir::HirId) {
16171617
let def_id = self.tcx.hir().local_def_id(id);
16181618
debug!("EncodeContext::encode_info_for_anon_const({:?})", def_id);
1619-
let body_id = self.tcx.hir().body_owned_by(id);
1619+
let body_id = self.tcx.hir().body_owned_by(def_id);
16201620
let const_data = self.encode_rendered_const_for_body(body_id);
16211621
let qualifs = self.tcx.mir_const_qualif(def_id);
16221622

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,10 @@ impl<'hir> Map<'hir> {
396396
}
397397
}
398398

399-
pub fn enclosing_body_owner(self, hir_id: HirId) -> HirId {
399+
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
400400
for (parent, _) in self.parent_iter(hir_id) {
401-
if let Some(body) = self.maybe_body_owned_by(parent) {
402-
return self.body_owner(body);
401+
if let Some(body) = self.find(parent).map(associated_body).flatten() {
402+
return self.body_owner_def_id(body);
403403
}
404404
}
405405

@@ -419,19 +419,20 @@ impl<'hir> Map<'hir> {
419419
self.local_def_id(self.body_owner(id))
420420
}
421421

422-
/// Given a `HirId`, returns the `BodyId` associated with it,
422+
/// Given a `LocalDefId`, returns the `BodyId` associated with it,
423423
/// if the node is a body owner, otherwise returns `None`.
424-
pub fn maybe_body_owned_by(self, hir_id: HirId) -> Option<BodyId> {
425-
self.find(hir_id).map(associated_body).flatten()
424+
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId> {
425+
self.get_if_local(id.to_def_id()).map(associated_body).flatten()
426426
}
427427

428428
/// Given a body owner's id, returns the `BodyId` associated with it.
429-
pub fn body_owned_by(self, id: HirId) -> BodyId {
429+
pub fn body_owned_by(self, id: LocalDefId) -> BodyId {
430430
self.maybe_body_owned_by(id).unwrap_or_else(|| {
431+
let hir_id = self.local_def_id_to_hir_id(id);
431432
span_bug!(
432-
self.span(id),
433+
self.span(hir_id),
433434
"body_owned_by: {} has no associated body",
434-
self.node_to_string(id)
435+
self.node_to_string(hir_id)
435436
);
436437
})
437438
}
@@ -670,7 +671,7 @@ impl<'hir> Map<'hir> {
670671
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
671672
/// Used exclusively for diagnostics, to avoid suggestion function calls.
672673
pub fn is_inside_const_context(self, hir_id: HirId) -> bool {
673-
self.body_const_context(self.local_def_id(self.enclosing_body_owner(hir_id))).is_some()
674+
self.body_const_context(self.enclosing_body_owner(hir_id)).is_some()
674675
}
675676

676677
/// Retrieves the `HirId` for `id`'s enclosing method, unless there's a

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ pub fn provide(providers: &mut Providers) {
157157
};
158158
providers.fn_arg_names = |tcx, id| {
159159
let hir = tcx.hir();
160-
let hir_id = hir.local_def_id_to_hir_id(id.expect_local());
161-
if let Some(body_id) = hir.maybe_body_owned_by(hir_id) {
160+
let def_id = id.expect_local();
161+
let hir_id = hir.local_def_id_to_hir_id(def_id);
162+
if let Some(body_id) = hir.maybe_body_owned_by(def_id) {
162163
tcx.arena.alloc_from_iter(hir.body_param_names(body_id))
163164
} else if let Node::TraitItem(&TraitItem {
164165
kind: TraitItemKind::Fn(_, TraitFn::Required(idents)),

compiler/rustc_middle/src/traits/query.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ use crate::infer::canonical::{Canonical, QueryResponse};
99
use crate::ty::error::TypeError;
1010
use crate::ty::subst::GenericArg;
1111
use crate::ty::{self, Ty, TyCtxt};
12-
13-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1412
use rustc_errors::struct_span_err;
15-
use rustc_query_system::ich::StableHashingContext;
1613
use rustc_span::source_map::Span;
1714
use std::iter::FromIterator;
18-
use std::mem;
1915

2016
pub mod type_op {
2117
use crate::ty::fold::TypeFoldable;
@@ -226,29 +222,9 @@ pub struct NormalizationResult<'tcx> {
226222
/// case they are called implied bounds). They are fed to the
227223
/// `OutlivesEnv` which in turn is supplied to the region checker and
228224
/// other parts of the inference system.
229-
#[derive(Clone, Debug, TypeFoldable, TypeVisitable, Lift)]
225+
#[derive(Clone, Debug, TypeFoldable, TypeVisitable, Lift, HashStable)]
230226
pub enum OutlivesBound<'tcx> {
231227
RegionSubRegion(ty::Region<'tcx>, ty::Region<'tcx>),
232228
RegionSubParam(ty::Region<'tcx>, ty::ParamTy),
233229
RegionSubProjection(ty::Region<'tcx>, ty::ProjectionTy<'tcx>),
234230
}
235-
236-
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for OutlivesBound<'tcx> {
237-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
238-
mem::discriminant(self).hash_stable(hcx, hasher);
239-
match *self {
240-
OutlivesBound::RegionSubRegion(ref a, ref b) => {
241-
a.hash_stable(hcx, hasher);
242-
b.hash_stable(hcx, hasher);
243-
}
244-
OutlivesBound::RegionSubParam(ref a, ref b) => {
245-
a.hash_stable(hcx, hasher);
246-
b.hash_stable(hcx, hasher);
247-
}
248-
OutlivesBound::RegionSubProjection(ref a, ref b) => {
249-
a.hash_stable(hcx, hasher);
250-
b.hash_stable(hcx, hasher);
251-
}
252-
}
253-
}
254-
}

compiler/rustc_middle/src/ty/impls_ty.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -101,46 +101,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArgKin
101101
}
102102
}
103103

104-
impl<'a> HashStable<StableHashingContext<'a>> for ty::EarlyBoundRegion {
105-
#[inline]
106-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
107-
self.def_id.hash_stable(hcx, hasher);
108-
self.index.hash_stable(hcx, hasher);
109-
self.name.hash_stable(hcx, hasher);
110-
}
111-
}
112-
113-
impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionVid {
114-
#[inline]
115-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
116-
self.index().hash_stable(hcx, hasher);
117-
}
118-
}
119-
120-
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::ConstVid<'tcx> {
121-
#[inline]
122-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
123-
self.index.hash_stable(hcx, hasher);
124-
}
125-
}
126-
127-
impl<'tcx> HashStable<StableHashingContext<'tcx>> for ty::BoundVar {
128-
#[inline]
129-
fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
130-
self.index().hash_stable(hcx, hasher);
131-
}
132-
}
133-
134-
impl<'a, 'tcx, T> HashStable<StableHashingContext<'a>> for ty::Binder<'tcx, T>
135-
where
136-
T: HashStable<StableHashingContext<'a>>,
137-
{
138-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
139-
self.as_ref().skip_binder().hash_stable(hcx, hasher);
140-
self.bound_vars().hash_stable(hcx, hasher);
141-
}
142-
}
143-
144104
// AllocIds get resolved to whatever they point to (to be stable)
145105
impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
146106
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {

0 commit comments

Comments
 (0)