Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 17a19e6

Browse files
committedOct 14, 2024
Auto merge of #131672 - matthiaskrgr:rollup-gyzysj4, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #128967 (std::fs::get_path freebsd update.) - #130629 (core/net: add Ipv[46]Addr::from_octets, Ipv6Addr::from_segments.) - #131274 (library: Const-stabilize `MaybeUninit::assume_init_mut`) - #131473 (compiler: `{TyAnd,}Layout` comes home) - #131533 (emscripten: Use the latest emsdk 3.1.68) - #131593 (miri: avoid cloning AllocExtra) - #131616 (merge const_ipv4 / const_ipv6 feature gate into 'ip' feature gate) - #131660 (Also use outermost const-anon for impl items in `non_local_defs` lint) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f6648f2 + d34b932 commit 17a19e6

Some content is hidden

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

49 files changed

+469
-338
lines changed
 

‎compiler/rustc_const_eval/src/const_eval/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<K: Hash + Eq, V> interpret::AllocMap<K, V> for FxIndexMap<K, V> {
140140

141141
#[inline(always)]
142142
fn filter_map_collect<T>(&self, mut f: impl FnMut(&K, &V) -> Option<T>) -> Vec<T> {
143-
self.iter().filter_map(move |(k, v)| f(k, &*v)).collect()
143+
self.iter().filter_map(move |(k, v)| f(k, v)).collect()
144144
}
145145

146146
#[inline(always)]

‎compiler/rustc_const_eval/src/interpret/memory.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -993,11 +993,14 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
993993
bytes
994994
}
995995

996-
/// Find leaked allocations. Allocations reachable from `static_roots` or a `Global` allocation
997-
/// are not considered leaked, as well as leaks whose kind's `may_leak()` returns true.
998-
pub fn find_leaked_allocations(
999-
&self,
1000-
static_roots: &[AllocId],
996+
/// Find leaked allocations, remove them from memory and return them. Allocations reachable from
997+
/// `static_roots` or a `Global` allocation are not considered leaked, as well as leaks whose
998+
/// kind's `may_leak()` returns true.
999+
///
1000+
/// This is highly destructive, no more execution can happen after this!
1001+
pub fn take_leaked_allocations(
1002+
&mut self,
1003+
static_roots: impl FnOnce(&Self) -> &[AllocId],
10011004
) -> Vec<(AllocId, MemoryKind<M::MemoryKind>, Allocation<M::Provenance, M::AllocExtra, M::Bytes>)>
10021005
{
10031006
// Collect the set of allocations that are *reachable* from `Global` allocations.
@@ -1008,7 +1011,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
10081011
self.memory.alloc_map.filter_map_collect(move |&id, &(kind, _)| {
10091012
if Some(kind) == global_kind { Some(id) } else { None }
10101013
});
1011-
todo.extend(static_roots);
1014+
todo.extend(static_roots(self));
10121015
while let Some(id) = todo.pop() {
10131016
if reachable.insert(id) {
10141017
// This is a new allocation, add the allocation it points to `todo`.
@@ -1023,13 +1026,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
10231026
};
10241027

10251028
// All allocations that are *not* `reachable` and *not* `may_leak` are considered leaking.
1026-
self.memory.alloc_map.filter_map_collect(|id, (kind, alloc)| {
1027-
if kind.may_leak() || reachable.contains(id) {
1028-
None
1029-
} else {
1030-
Some((*id, *kind, alloc.clone()))
1031-
}
1032-
})
1029+
let leaked: Vec<_> = self.memory.alloc_map.filter_map_collect(|&id, &(kind, _)| {
1030+
if kind.may_leak() || reachable.contains(&id) { None } else { Some(id) }
1031+
});
1032+
let mut result = Vec::new();
1033+
for &id in leaked.iter() {
1034+
let (kind, alloc) = self.memory.alloc_map.remove(&id).unwrap();
1035+
result.push((id, kind, alloc));
1036+
}
1037+
result
10331038
}
10341039

10351040
/// Runs the closure in "validation" mode, which means the machine's memory read hooks will be

‎compiler/rustc_lint/src/non_local_def.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,13 @@ fn did_has_local_parent(
301301
return false;
302302
};
303303

304-
peel_parent_while(tcx, parent_did, |tcx, did| tcx.def_kind(did) == DefKind::Mod)
305-
.map(|parent_did| parent_did == impl_parent || Some(parent_did) == outermost_impl_parent)
306-
.unwrap_or(false)
304+
peel_parent_while(tcx, parent_did, |tcx, did| {
305+
tcx.def_kind(did) == DefKind::Mod
306+
|| (tcx.def_kind(did) == DefKind::Const
307+
&& tcx.opt_item_name(did) == Some(kw::Underscore))
308+
})
309+
.map(|parent_did| parent_did == impl_parent || Some(parent_did) == outermost_impl_parent)
310+
.unwrap_or(false)
307311
}
308312

309313
/// Given a `DefId` checks if it satisfies `f` if it does check with it's parent and continue
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.