Rollup merge of #105960 - oli-obk:effect_cleanup, r=fee1-dead
Various cleanups This PR pulls changes out of https://github.com/rust-lang/rust/pull/101900 that can land on master immediately r? ``@fee1-dead``
This commit is contained in:
commit
ec7eb5b5ad
7 changed files with 20 additions and 30 deletions
|
@ -170,6 +170,7 @@ impl<'hir> Map<'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[track_caller]
|
||||||
pub fn local_def_id(self, hir_id: HirId) -> LocalDefId {
|
pub fn local_def_id(self, hir_id: HirId) -> LocalDefId {
|
||||||
self.opt_local_def_id(hir_id).unwrap_or_else(|| {
|
self.opt_local_def_id(hir_id).unwrap_or_else(|| {
|
||||||
bug!(
|
bug!(
|
||||||
|
@ -310,6 +311,7 @@ impl<'hir> Map<'hir> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
pub fn get_parent_node(self, hir_id: HirId) -> HirId {
|
pub fn get_parent_node(self, hir_id: HirId) -> HirId {
|
||||||
self.find_parent_node(hir_id)
|
self.find_parent_node(hir_id)
|
||||||
.unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id)))
|
.unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id)))
|
||||||
|
@ -334,12 +336,14 @@ impl<'hir> Map<'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
|
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
|
||||||
|
#[track_caller]
|
||||||
pub fn get(self, id: HirId) -> Node<'hir> {
|
pub fn get(self, id: HirId) -> Node<'hir> {
|
||||||
self.find(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id))
|
self.find(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
|
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[track_caller]
|
||||||
pub fn get_by_def_id(self, id: LocalDefId) -> Node<'hir> {
|
pub fn get_by_def_id(self, id: LocalDefId) -> Node<'hir> {
|
||||||
self.find_by_def_id(id).unwrap_or_else(|| bug!("couldn't find {:?} in the HIR map", id))
|
self.find_by_def_id(id).unwrap_or_else(|| bug!("couldn't find {:?} in the HIR map", id))
|
||||||
}
|
}
|
||||||
|
@ -377,6 +381,7 @@ impl<'hir> Map<'hir> {
|
||||||
self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies[&id.hir_id.local_id]
|
self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies[&id.hir_id.local_id]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
|
pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
|
||||||
if let Some(node) = self.find(hir_id) {
|
if let Some(node) = self.find(hir_id) {
|
||||||
node.fn_decl()
|
node.fn_decl()
|
||||||
|
@ -385,6 +390,7 @@ impl<'hir> Map<'hir> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
|
pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
|
||||||
if let Some(node) = self.find(hir_id) {
|
if let Some(node) = self.find(hir_id) {
|
||||||
node.fn_sig()
|
node.fn_sig()
|
||||||
|
@ -393,6 +399,7 @@ impl<'hir> Map<'hir> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
|
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
|
||||||
for (_, node) in self.parent_iter(hir_id) {
|
for (_, node) in self.parent_iter(hir_id) {
|
||||||
if let Some(body) = associated_body(node) {
|
if let Some(body) = associated_body(node) {
|
||||||
|
@ -408,7 +415,7 @@ impl<'hir> Map<'hir> {
|
||||||
/// item (possibly associated), a closure, or a `hir::AnonConst`.
|
/// item (possibly associated), a closure, or a `hir::AnonConst`.
|
||||||
pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId {
|
pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId {
|
||||||
let parent = self.get_parent_node(hir_id);
|
let parent = self.get_parent_node(hir_id);
|
||||||
assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)));
|
assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)), "{hir_id:?}");
|
||||||
parent
|
parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,10 +426,11 @@ impl<'hir> Map<'hir> {
|
||||||
/// Given a `LocalDefId`, returns the `BodyId` associated with it,
|
/// Given a `LocalDefId`, returns the `BodyId` associated with it,
|
||||||
/// if the node is a body owner, otherwise returns `None`.
|
/// if the node is a body owner, otherwise returns `None`.
|
||||||
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId> {
|
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId> {
|
||||||
self.get_if_local(id.to_def_id()).map(associated_body).flatten()
|
self.find_by_def_id(id).and_then(associated_body)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a body owner's id, returns the `BodyId` associated with it.
|
/// Given a body owner's id, returns the `BodyId` associated with it.
|
||||||
|
#[track_caller]
|
||||||
pub fn body_owned_by(self, id: LocalDefId) -> BodyId {
|
pub fn body_owned_by(self, id: LocalDefId) -> BodyId {
|
||||||
self.maybe_body_owned_by(id).unwrap_or_else(|| {
|
self.maybe_body_owned_by(id).unwrap_or_else(|| {
|
||||||
let hir_id = self.local_def_id_to_hir_id(id);
|
let hir_id = self.local_def_id_to_hir_id(id);
|
||||||
|
|
|
@ -70,14 +70,6 @@ impl GenericParamDef {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_default(&self) -> bool {
|
|
||||||
match self.kind {
|
|
||||||
GenericParamDefKind::Type { has_default, .. }
|
|
||||||
| GenericParamDefKind::Const { has_default } => has_default,
|
|
||||||
GenericParamDefKind::Lifetime => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_anonymous_lifetime(&self) -> bool {
|
pub fn is_anonymous_lifetime(&self) -> bool {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
GenericParamDefKind::Lifetime => {
|
GenericParamDefKind::Lifetime => {
|
||||||
|
|
|
@ -348,7 +348,7 @@ impl<'tcx> InternalSubsts<'tcx> {
|
||||||
substs.reserve(defs.params.len());
|
substs.reserve(defs.params.len());
|
||||||
for param in &defs.params {
|
for param in &defs.params {
|
||||||
let kind = mk_kind(param, substs);
|
let kind = mk_kind(param, substs);
|
||||||
assert_eq!(param.index as usize, substs.len());
|
assert_eq!(param.index as usize, substs.len(), "{substs:#?}, {defs:#?}");
|
||||||
substs.push(kind);
|
substs.push(kind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,9 +88,11 @@ pub trait TypeVisitable<'tcx>: fmt::Debug + Clone {
|
||||||
self.has_vars_bound_at_or_above(ty::INNERMOST)
|
self.has_vars_bound_at_or_above(ty::INNERMOST)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", ret)]
|
|
||||||
fn has_type_flags(&self, flags: TypeFlags) -> bool {
|
fn has_type_flags(&self, flags: TypeFlags) -> bool {
|
||||||
self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags)
|
let res =
|
||||||
|
self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags);
|
||||||
|
trace!(?self, ?flags, ?res, "has_type_flags");
|
||||||
|
res
|
||||||
}
|
}
|
||||||
fn has_projections(&self) -> bool {
|
fn has_projections(&self) -> bool {
|
||||||
self.has_type_flags(TypeFlags::HAS_PROJECTION)
|
self.has_type_flags(TypeFlags::HAS_PROJECTION)
|
||||||
|
@ -560,10 +562,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
|
||||||
type BreakTy = FoundFlags;
|
type BreakTy = FoundFlags;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[instrument(skip(self), level = "trace", ret)]
|
|
||||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
let flags = t.flags();
|
let flags = t.flags();
|
||||||
trace!(t.flags=?t.flags());
|
|
||||||
if flags.intersects(self.flags) {
|
if flags.intersects(self.flags) {
|
||||||
ControlFlow::Break(FoundFlags)
|
ControlFlow::Break(FoundFlags)
|
||||||
} else {
|
} else {
|
||||||
|
@ -572,10 +572,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[instrument(skip(self), level = "trace", ret)]
|
|
||||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
let flags = r.type_flags();
|
let flags = r.type_flags();
|
||||||
trace!(r.flags=?flags);
|
|
||||||
if flags.intersects(self.flags) {
|
if flags.intersects(self.flags) {
|
||||||
ControlFlow::Break(FoundFlags)
|
ControlFlow::Break(FoundFlags)
|
||||||
} else {
|
} else {
|
||||||
|
@ -584,7 +582,6 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[instrument(level = "trace", ret)]
|
|
||||||
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
let flags = FlagComputation::for_const(c);
|
let flags = FlagComputation::for_const(c);
|
||||||
trace!(r.flags=?flags);
|
trace!(r.flags=?flags);
|
||||||
|
@ -596,14 +593,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[instrument(level = "trace", ret)]
|
|
||||||
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
debug!(
|
|
||||||
"HasTypeFlagsVisitor: predicate={:?} predicate.flags={:?} self.flags={:?}",
|
|
||||||
predicate,
|
|
||||||
predicate.flags(),
|
|
||||||
self.flags
|
|
||||||
);
|
|
||||||
if predicate.flags().intersects(self.flags) {
|
if predicate.flags().intersects(self.flags) {
|
||||||
ControlFlow::Break(FoundFlags)
|
ControlFlow::Break(FoundFlags)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -64,7 +64,7 @@ macro_rules! impl_fn_mut_tuple {
|
||||||
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
|
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
|
||||||
FnMut<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
|
FnMut<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
|
||||||
where
|
where
|
||||||
Function: ~const Fn(($(&mut $var),*), ClosureArguments)-> ClosureReturnValue,
|
Function: ~const Fn(($(&mut $var),*), ClosureArguments)-> ClosureReturnValue + ~const Destruct,
|
||||||
{
|
{
|
||||||
extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output {
|
extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output {
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
|
|
@ -199,7 +199,7 @@ pub trait Hash {
|
||||||
/// println!("Hash is {:x}!", hasher.finish());
|
/// println!("Hash is {:x}!", hasher.finish());
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
fn hash<H: Hasher>(&self, state: &mut H);
|
fn hash<H: ~const Hasher>(&self, state: &mut H);
|
||||||
|
|
||||||
/// Feeds a slice of this type into the given [`Hasher`].
|
/// Feeds a slice of this type into the given [`Hasher`].
|
||||||
///
|
///
|
||||||
|
@ -980,7 +980,7 @@ mod impls {
|
||||||
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
#[rustc_const_unstable(feature = "const_hash", issue = "104061")]
|
||||||
impl<T: ?Sized + ~const Hash> const Hash for &mut T {
|
impl<T: ?Sized + ~const Hash> const Hash for &mut T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: ~const Hasher>(&self, state: &mut H) {
|
||||||
(**self).hash(state);
|
(**self).hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@ see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#ind
|
||||||
#[doc(alias = "]")]
|
#[doc(alias = "]")]
|
||||||
#[doc(alias = "[]")]
|
#[doc(alias = "[]")]
|
||||||
#[const_trait]
|
#[const_trait]
|
||||||
pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
|
pub trait IndexMut<Idx: ?Sized>: ~const Index<Idx> {
|
||||||
/// Performs the mutable indexing (`container[index]`) operation.
|
/// Performs the mutable indexing (`container[index]`) operation.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue