Skip to content

Commit 038f9e6

Browse files
committed
Auto merge of #99948 - Dylan-DPC:rollup-ed5136t, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #99311 (change maybe_body_owned_by to take local def id) - #99862 (Improve type mismatch w/ function signatures) - #99895 (don't call type ascription "cast") - #99900 (remove some manual hash stable impls) - #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

+1-2
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

+1-2
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

+5
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

+1-1
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

+6-3
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

+1-1
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

+11-10
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

+3-2
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

+1-25
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

-40
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) {

compiler/rustc_middle/src/ty/mod.rs

+3-23
Original file line numberDiff line numberDiff line change
@@ -1182,22 +1182,13 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
11821182
/// identified by both a universe, as well as a name residing within that universe. Distinct bound
11831183
/// regions/types/consts within the same universe simply have an unknown relationship to one
11841184
/// another.
1185-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
1185+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
1186+
#[derive(HashStable, TyEncodable, TyDecodable)]
11861187
pub struct Placeholder<T> {
11871188
pub universe: UniverseIndex,
11881189
pub name: T,
11891190
}
11901191

1191-
impl<'a, T> HashStable<StableHashingContext<'a>> for Placeholder<T>
1192-
where
1193-
T: HashStable<StableHashingContext<'a>>,
1194-
{
1195-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
1196-
self.universe.hash_stable(hcx, hasher);
1197-
self.name.hash_stable(hcx, hasher);
1198-
}
1199-
}
1200-
12011192
pub type PlaceholderRegion = Placeholder<BoundRegionKind>;
12021193

12031194
pub type PlaceholderType = Placeholder<BoundVar>;
@@ -1581,6 +1572,7 @@ impl<'tcx> PolyTraitRef<'tcx> {
15811572
}
15821573

15831574
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)]
1575+
#[derive(HashStable)]
15841576
pub struct ParamEnvAnd<'tcx, T> {
15851577
pub param_env: ParamEnv<'tcx>,
15861578
pub value: T,
@@ -1598,18 +1590,6 @@ impl<'tcx, T> ParamEnvAnd<'tcx, T> {
15981590
}
15991591
}
16001592

1601-
impl<'a, 'tcx, T> HashStable<StableHashingContext<'a>> for ParamEnvAnd<'tcx, T>
1602-
where
1603-
T: HashStable<StableHashingContext<'a>>,
1604-
{
1605-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
1606-
let ParamEnvAnd { ref param_env, ref value } = *self;
1607-
1608-
param_env.hash_stable(hcx, hasher);
1609-
value.hash_stable(hcx, hasher);
1610-
}
1611-
}
1612-
16131593
#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)]
16141594
pub struct Destructor {
16151595
/// The `DefId` of the destructor method

compiler/rustc_middle/src/ty/sty.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ impl BoundVariableKind {
10091009
///
10101010
/// `Decodable` and `Encodable` are implemented for `Binder<T>` using the `impl_binder_encode_decode!` macro.
10111011
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1012+
#[derive(HashStable)]
10121013
pub struct Binder<'tcx, T>(T, &'tcx List<BoundVariableKind>);
10131014

10141015
impl<'tcx, T> Binder<'tcx, T>
@@ -1355,6 +1356,7 @@ impl<'tcx> fmt::Debug for Region<'tcx> {
13551356
}
13561357

13571358
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
1359+
#[derive(HashStable)]
13581360
pub struct EarlyBoundRegion {
13591361
pub def_id: DefId,
13601362
pub index: u32,
@@ -1368,14 +1370,16 @@ impl fmt::Debug for EarlyBoundRegion {
13681370
}
13691371

13701372
/// A **`const`** **v**ariable **ID**.
1371-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
1373+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1374+
#[derive(HashStable, TyEncodable, TyDecodable)]
13721375
pub struct ConstVid<'tcx> {
13731376
pub index: u32,
13741377
pub phantom: PhantomData<&'tcx ()>,
13751378
}
13761379

13771380
rustc_index::newtype_index! {
13781381
/// A **region** (lifetime) **v**ariable **ID**.
1382+
#[derive(HashStable)]
13791383
pub struct RegionVid {
13801384
DEBUG_FORMAT = custom,
13811385
}
@@ -1388,6 +1392,7 @@ impl Atom for RegionVid {
13881392
}
13891393

13901394
rustc_index::newtype_index! {
1395+
#[derive(HashStable)]
13911396
pub struct BoundVar { .. }
13921397
}
13931398

compiler/rustc_mir_build/src/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam<LocalD
626626
if tcx.is_closure(def.did.to_def_id()) {
627627
let hir = tcx.hir();
628628
let owner = hir.enclosing_body_owner(hir.local_def_id_to_hir_id(def.did));
629-
tcx.ensure().thir_check_unsafety(hir.local_def_id(owner));
629+
tcx.ensure().thir_check_unsafety(owner);
630630
return;
631631
}
632632

compiler/rustc_mir_build/src/thir/cx/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) fn thir_body<'tcx>(
2121
owner_def: ty::WithOptConstParam<LocalDefId>,
2222
) -> Result<(&'tcx Steal<Thir<'tcx>>, ExprId), ErrorGuaranteed> {
2323
let hir = tcx.hir();
24-
let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(owner_def.did)));
24+
let body = hir.body(hir.body_owned_by(owner_def.did));
2525
let mut cx = Cx::new(tcx, owner_def);
2626
if let Some(reported) = cx.typeck_results.tainted_by_errors {
2727
return Err(reported);

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_span::{BytePos, Span};
2626
pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: DefId) {
2727
let body_id = match def_id.as_local() {
2828
None => return,
29-
Some(id) => tcx.hir().body_owned_by(tcx.hir().local_def_id_to_hir_id(id)),
29+
Some(def_id) => tcx.hir().body_owned_by(def_id),
3030
};
3131

3232
let pattern_arena = TypedArena::default();

compiler/rustc_mir_transform/src/check_unsafety.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -464,15 +464,15 @@ fn check_unused_unsafe(
464464
def_id: LocalDefId,
465465
used_unsafe_blocks: &FxHashMap<HirId, UsedUnsafeBlockData>,
466466
) -> Vec<(HirId, UnusedUnsafe)> {
467-
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
468-
let body_id = tcx.hir().maybe_body_owned_by(hir_id);
467+
let body_id = tcx.hir().maybe_body_owned_by(def_id);
469468

470469
let Some(body_id) = body_id else {
471470
debug!("check_unused_unsafe({:?}) - no body found", def_id);
472471
return vec![];
473472
};
474-
let body = tcx.hir().body(body_id);
475473

474+
let body = tcx.hir().body(body_id);
475+
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
476476
let context = match tcx.hir().fn_sig_by_hir_id(hir_id) {
477477
Some(sig) if sig.header.unsafety == hir::Unsafety::Unsafe => Context::UnsafeFn(hir_id),
478478
_ => Context::Safe,

0 commit comments

Comments
 (0)