Skip to content

Commit 43874a2

Browse files
committed
Auto merge of #97742 - matthiaskrgr:rollup-fr3j0t8, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #97609 (Iterate over `maybe_unused_trait_imports` when checking dead trait imports) - #97688 (test const_copy to make sure bytewise pointer copies are working) - #97707 (Improve soundness of rustc_data_structures) - #97731 (Add regresion test for #87142) - #97735 (Don't generate "Impls on Foreign Types" for std) - #97737 (Fix pretty printing named bound regions under -Zverbose) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4e725ba + 1794309 commit 43874a2

File tree

17 files changed

+162
-77
lines changed

17 files changed

+162
-77
lines changed

compiler/rustc_data_structures/src/base_n/tests.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ fn test_encode() {
1515
test(u64::MAX as u128, base);
1616
test(u128::MAX, base);
1717

18-
for i in 0..1_000 {
18+
const N: u128 = if cfg!(miri) { 10 } else { 1000 };
19+
20+
for i in 0..N {
1921
test(i * 983, base);
2022
}
2123
}

compiler/rustc_data_structures/src/graph/scc/tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ fn test_deep_linear() {
156156
v
157157
158158
*/
159+
#[cfg(not(miri))]
159160
const NR_NODES: usize = 1 << 14;
161+
#[cfg(miri)]
162+
const NR_NODES: usize = 1 << 3;
160163
let mut nodes = vec![];
161164
for i in 1..NR_NODES {
162165
nodes.push((i - 1, i));

compiler/rustc_data_structures/src/owning_ref/tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// FIXME: owning_ref is not sound under stacked borrows. Preferably, get rid of it.
2+
#[cfg(not(miri))]
13
mod owning_ref {
24
use super::super::OwningRef;
35
use super::super::{BoxRef, Erased, ErasedBoxRef, RcRef};
@@ -361,6 +363,8 @@ mod owning_handle {
361363
}
362364
}
363365

366+
// FIXME: owning_ref is not sound under stacked borrows. Preferably, get rid of it.
367+
#[cfg(not(miri))]
364368
mod owning_ref_mut {
365369
use super::super::BoxRef;
366370
use super::super::{BoxRefMut, Erased, ErasedBoxRefMut, OwningRefMut};

compiler/rustc_data_structures/src/sip128.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ impl SipHasher128 {
255255
// elements from spill (at most LEN - 1 bytes could have overflowed
256256
// into the spill). The memcpy call is optimized away because the size
257257
// is known. And the whole copy is optimized away for LEN == 1.
258+
let dst = self.buf.as_mut_ptr() as *mut u8;
258259
let src = self.buf.get_unchecked(BUFFER_SPILL_INDEX) as *const _ as *const u8;
259-
ptr::copy_nonoverlapping(src, self.buf.as_mut_ptr() as *mut u8, LEN - 1);
260+
ptr::copy_nonoverlapping(src, dst, LEN - 1);
260261

261262
// This function should only be called when the write fills the buffer.
262263
// Therefore, when LEN == 1, the new `self.nbuf` must be zero.

compiler/rustc_middle/src/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,8 +1728,8 @@ rustc_queries! {
17281728
query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
17291729
desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
17301730
}
1731-
query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
1732-
desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1731+
query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1732+
desc { "fetching potentially unused trait imports" }
17331733
}
17341734
query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
17351735
desc { "looking up all possibly unused extern crates" }

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,8 +2893,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
28932893
assert_eq!(id, LOCAL_CRATE);
28942894
tcx.crate_name
28952895
};
2896-
providers.maybe_unused_trait_import =
2897-
|tcx, id| tcx.resolutions(()).maybe_unused_trait_imports.contains(&id);
2896+
providers.maybe_unused_trait_imports =
2897+
|tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports;
28982898
providers.maybe_unused_extern_crates =
28992899
|tcx, ()| &tcx.resolutions(()).maybe_unused_extern_crates[..];
29002900
providers.names_imported_by_glob_use = |tcx, id| {

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub use generics::*;
2828
use rustc_ast as ast;
2929
use rustc_attr as attr;
3030
use rustc_data_structures::fingerprint::Fingerprint;
31-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
31+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
3232
use rustc_data_structures::intern::{Interned, WithStableHash};
3333
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3434
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
@@ -138,7 +138,7 @@ pub struct ResolverOutputs {
138138
pub has_pub_restricted: bool,
139139
pub access_levels: AccessLevels,
140140
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
141-
pub maybe_unused_trait_imports: FxHashSet<LocalDefId>,
141+
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
142142
pub maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
143143
pub reexport_map: FxHashMap<LocalDefId, Vec<ModChild>>,
144144
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,34 +2190,40 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
21902190
// this is not *quite* right and changes the ordering of some output
21912191
// anyways.
21922192
let (new_value, map) = if self.tcx().sess.verbose() {
2193-
// anon index + 1 (BrEnv takes 0) -> name
2194-
let mut region_map: FxHashMap<_, _> = Default::default();
2195-
let bound_vars = value.bound_vars();
2196-
for var in bound_vars {
2197-
let ty::BoundVariableKind::Region(var) = var else { continue };
2198-
match var {
2199-
ty::BrAnon(_) | ty::BrEnv => {
2200-
start_or_continue(&mut self, "for<", ", ");
2201-
let name = next_name(&self);
2202-
do_continue(&mut self, name);
2203-
region_map.insert(var, ty::BrNamed(CRATE_DEF_ID.to_def_id(), name));
2204-
}
2205-
ty::BrNamed(def_id, kw::UnderscoreLifetime) => {
2206-
start_or_continue(&mut self, "for<", ", ");
2207-
let name = next_name(&self);
2208-
do_continue(&mut self, name);
2209-
region_map.insert(var, ty::BrNamed(def_id, name));
2210-
}
2211-
ty::BrNamed(_, name) => {
2212-
start_or_continue(&mut self, "for<", ", ");
2213-
do_continue(&mut self, name);
2193+
let regions: Vec<_> = value
2194+
.bound_vars()
2195+
.into_iter()
2196+
.map(|var| {
2197+
let ty::BoundVariableKind::Region(var) = var else {
2198+
// This doesn't really matter because it doesn't get used,
2199+
// it's just an empty value
2200+
return ty::BrAnon(0);
2201+
};
2202+
match var {
2203+
ty::BrAnon(_) | ty::BrEnv => {
2204+
start_or_continue(&mut self, "for<", ", ");
2205+
let name = next_name(&self);
2206+
do_continue(&mut self, name);
2207+
ty::BrNamed(CRATE_DEF_ID.to_def_id(), name)
2208+
}
2209+
ty::BrNamed(def_id, kw::UnderscoreLifetime) => {
2210+
start_or_continue(&mut self, "for<", ", ");
2211+
let name = next_name(&self);
2212+
do_continue(&mut self, name);
2213+
ty::BrNamed(def_id, name)
2214+
}
2215+
ty::BrNamed(def_id, name) => {
2216+
start_or_continue(&mut self, "for<", ", ");
2217+
do_continue(&mut self, name);
2218+
ty::BrNamed(def_id, name)
2219+
}
22142220
}
2215-
}
2216-
}
2221+
})
2222+
.collect();
22172223
start_or_continue(&mut self, "", "> ");
22182224

22192225
self.tcx.replace_late_bound_regions(value.clone(), |br| {
2220-
let kind = region_map[&br.kind];
2226+
let kind = regions[br.var.as_usize()];
22212227
self.tcx.mk_region(ty::ReLateBound(
22222228
ty::INNERMOST,
22232229
ty::BoundRegion { var: br.var, kind },

compiler/rustc_middle/src/ty/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, T
3737
use rustc_ast as ast;
3838
use rustc_ast::expand::allocator::AllocatorKind;
3939
use rustc_attr as attr;
40-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
40+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
4141
use rustc_data_structures::steal::Steal;
4242
use rustc_data_structures::svh::Svh;
4343
use rustc_data_structures::sync::Lrc;

compiler/rustc_resolve/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_ast::node_id::NodeMap;
2828
use rustc_ast::{self as ast, NodeId, CRATE_NODE_ID};
2929
use rustc_ast::{AngleBracketedArg, Crate, Expr, ExprKind, GenericArg, GenericArgs, LitKind, Path};
3030
use rustc_ast_lowering::{LifetimeRes, ResolverAstLowering};
31-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
31+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
3232
use rustc_data_structures::intern::Interned;
3333
use rustc_data_structures::sync::Lrc;
3434
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed};
@@ -941,7 +941,7 @@ pub struct Resolver<'a> {
941941
visibilities: FxHashMap<LocalDefId, ty::Visibility>,
942942
has_pub_restricted: bool,
943943
used_imports: FxHashSet<NodeId>,
944-
maybe_unused_trait_imports: FxHashSet<LocalDefId>,
944+
maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
945945
maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
946946

947947
/// Privacy errors are delayed until the end in order to deduplicate them.

0 commit comments

Comments
 (0)