Skip to content

Commit ec7eb5b

Browse files
authored
Rollup merge of #105960 - oli-obk:effect_cleanup, r=fee1-dead
Various cleanups This PR pulls changes out of #101900 that can land on master immediately r? ``@fee1-dead``
2 parents 924a1d4 + ed61be6 commit ec7eb5b

File tree

7 files changed

+20
-30
lines changed

7 files changed

+20
-30
lines changed

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ impl<'hir> Map<'hir> {
170170
}
171171

172172
#[inline]
173+
#[track_caller]
173174
pub fn local_def_id(self, hir_id: HirId) -> LocalDefId {
174175
self.opt_local_def_id(hir_id).unwrap_or_else(|| {
175176
bug!(
@@ -310,6 +311,7 @@ impl<'hir> Map<'hir> {
310311
}
311312
}
312313

314+
#[track_caller]
313315
pub fn get_parent_node(self, hir_id: HirId) -> HirId {
314316
self.find_parent_node(hir_id)
315317
.unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id)))
@@ -334,12 +336,14 @@ impl<'hir> Map<'hir> {
334336
}
335337

336338
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
339+
#[track_caller]
337340
pub fn get(self, id: HirId) -> Node<'hir> {
338341
self.find(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id))
339342
}
340343

341344
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
342345
#[inline]
346+
#[track_caller]
343347
pub fn get_by_def_id(self, id: LocalDefId) -> Node<'hir> {
344348
self.find_by_def_id(id).unwrap_or_else(|| bug!("couldn't find {:?} in the HIR map", id))
345349
}
@@ -377,6 +381,7 @@ impl<'hir> Map<'hir> {
377381
self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies[&id.hir_id.local_id]
378382
}
379383

384+
#[track_caller]
380385
pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
381386
if let Some(node) = self.find(hir_id) {
382387
node.fn_decl()
@@ -385,6 +390,7 @@ impl<'hir> Map<'hir> {
385390
}
386391
}
387392

393+
#[track_caller]
388394
pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
389395
if let Some(node) = self.find(hir_id) {
390396
node.fn_sig()
@@ -393,6 +399,7 @@ impl<'hir> Map<'hir> {
393399
}
394400
}
395401

402+
#[track_caller]
396403
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
397404
for (_, node) in self.parent_iter(hir_id) {
398405
if let Some(body) = associated_body(node) {
@@ -408,7 +415,7 @@ impl<'hir> Map<'hir> {
408415
/// item (possibly associated), a closure, or a `hir::AnonConst`.
409416
pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId {
410417
let parent = self.get_parent_node(hir_id);
411-
assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)));
418+
assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)), "{hir_id:?}");
412419
parent
413420
}
414421

@@ -419,10 +426,11 @@ impl<'hir> Map<'hir> {
419426
/// Given a `LocalDefId`, returns the `BodyId` associated with it,
420427
/// if the node is a body owner, otherwise returns `None`.
421428
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId> {
422-
self.get_if_local(id.to_def_id()).map(associated_body).flatten()
429+
self.find_by_def_id(id).and_then(associated_body)
423430
}
424431

425432
/// Given a body owner's id, returns the `BodyId` associated with it.
433+
#[track_caller]
426434
pub fn body_owned_by(self, id: LocalDefId) -> BodyId {
427435
self.maybe_body_owned_by(id).unwrap_or_else(|| {
428436
let hir_id = self.local_def_id_to_hir_id(id);

compiler/rustc_middle/src/ty/generics.rs

-8
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ impl GenericParamDef {
7070
}
7171
}
7272

73-
pub fn has_default(&self) -> bool {
74-
match self.kind {
75-
GenericParamDefKind::Type { has_default, .. }
76-
| GenericParamDefKind::Const { has_default } => has_default,
77-
GenericParamDefKind::Lifetime => false,
78-
}
79-
}
80-
8173
pub fn is_anonymous_lifetime(&self) -> bool {
8274
match self.kind {
8375
GenericParamDefKind::Lifetime => {

compiler/rustc_middle/src/ty/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl<'tcx> InternalSubsts<'tcx> {
348348
substs.reserve(defs.params.len());
349349
for param in &defs.params {
350350
let kind = mk_kind(param, substs);
351-
assert_eq!(param.index as usize, substs.len());
351+
assert_eq!(param.index as usize, substs.len(), "{substs:#?}, {defs:#?}");
352352
substs.push(kind);
353353
}
354354
}

compiler/rustc_middle/src/ty/visit.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ pub trait TypeVisitable<'tcx>: fmt::Debug + Clone {
8888
self.has_vars_bound_at_or_above(ty::INNERMOST)
8989
}
9090

91-
#[instrument(level = "trace", ret)]
9291
fn has_type_flags(&self, flags: TypeFlags) -> bool {
93-
self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags)
92+
let res =
93+
self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags);
94+
trace!(?self, ?flags, ?res, "has_type_flags");
95+
res
9496
}
9597
fn has_projections(&self) -> bool {
9698
self.has_type_flags(TypeFlags::HAS_PROJECTION)
@@ -560,10 +562,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
560562
type BreakTy = FoundFlags;
561563

562564
#[inline]
563-
#[instrument(skip(self), level = "trace", ret)]
564565
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
565566
let flags = t.flags();
566-
trace!(t.flags=?t.flags());
567567
if flags.intersects(self.flags) {
568568
ControlFlow::Break(FoundFlags)
569569
} else {
@@ -572,10 +572,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
572572
}
573573

574574
#[inline]
575-
#[instrument(skip(self), level = "trace", ret)]
576575
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
577576
let flags = r.type_flags();
578-
trace!(r.flags=?flags);
579577
if flags.intersects(self.flags) {
580578
ControlFlow::Break(FoundFlags)
581579
} else {
@@ -584,7 +582,6 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
584582
}
585583

586584
#[inline]
587-
#[instrument(level = "trace", ret)]
588585
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
589586
let flags = FlagComputation::for_const(c);
590587
trace!(r.flags=?flags);
@@ -596,14 +593,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
596593
}
597594

598595
#[inline]
599-
#[instrument(level = "trace", ret)]
600596
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
601-
debug!(
602-
"HasTypeFlagsVisitor: predicate={:?} predicate.flags={:?} self.flags={:?}",
603-
predicate,
604-
predicate.flags(),
605-
self.flags
606-
);
607597
if predicate.flags().intersects(self.flags) {
608598
ControlFlow::Break(FoundFlags)
609599
} else {

library/core/src/const_closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ macro_rules! impl_fn_mut_tuple {
5151
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
5252
FnOnce<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
5353
where
54-
Function: ~const Fn(($(&mut $var),*), ClosureArguments) -> ClosureReturnValue+ ~const Destruct,
54+
Function: ~const Fn(($(&mut $var),*), ClosureArguments) -> ClosureReturnValue + ~const Destruct,
5555
{
5656
type Output = ClosureReturnValue;
5757

@@ -64,7 +64,7 @@ macro_rules! impl_fn_mut_tuple {
6464
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
6565
FnMut<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
6666
where
67-
Function: ~const Fn(($(&mut $var),*), ClosureArguments)-> ClosureReturnValue,
67+
Function: ~const Fn(($(&mut $var),*), ClosureArguments)-> ClosureReturnValue + ~const Destruct,
6868
{
6969
extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output {
7070
#[allow(non_snake_case)]

library/core/src/hash/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub trait Hash {
199199
/// println!("Hash is {:x}!", hasher.finish());
200200
/// ```
201201
#[stable(feature = "rust1", since = "1.0.0")]
202-
fn hash<H: Hasher>(&self, state: &mut H);
202+
fn hash<H: ~const Hasher>(&self, state: &mut H);
203203

204204
/// Feeds a slice of this type into the given [`Hasher`].
205205
///
@@ -980,7 +980,7 @@ mod impls {
980980
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
981981
impl<T: ?Sized + ~const Hash> const Hash for &mut T {
982982
#[inline]
983-
fn hash<H: Hasher>(&self, state: &mut H) {
983+
fn hash<H: ~const Hasher>(&self, state: &mut H) {
984984
(**self).hash(state);
985985
}
986986
}

library/core/src/ops/index.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#ind
165165
#[doc(alias = "]")]
166166
#[doc(alias = "[]")]
167167
#[const_trait]
168-
pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
168+
pub trait IndexMut<Idx: ?Sized>: ~const Index<Idx> {
169169
/// Performs the mutable indexing (`container[index]`) operation.
170170
///
171171
/// # Panics

0 commit comments

Comments
 (0)