Skip to content

Commit 395f780

Browse files
committed
Auto merge of #123264 - matthiaskrgr:rollup-smyy7j9, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #123189 (Log BOLT args in bootstrap `rustc` shim) - #123211 (Stop calling visitors `V`) - #123242 (pattern analysis: Require enum indices to be contiguous) - #123260 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 688c30d + 9abf4bc commit 395f780

File tree

28 files changed

+260
-265
lines changed

28 files changed

+260
-265
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -540,19 +540,23 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
540540
}
541541
}
542542

543+
/// Suggest `map[k] = v` => `map.insert(k, v)` and the like.
543544
fn suggest_map_index_mut_alternatives(&self, ty: Ty<'tcx>, err: &mut Diag<'tcx>, span: Span) {
544545
let Some(adt) = ty.ty_adt_def() else { return };
545546
let did = adt.did();
546547
if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did)
547548
|| self.infcx.tcx.is_diagnostic_item(sym::BTreeMap, did)
548549
{
549-
struct V<'a, 'tcx> {
550+
/// Walks through the HIR, looking for the corresponding span for this error.
551+
/// When it finds it, see if it corresponds to assignment operator whose LHS
552+
/// is an index expr.
553+
struct SuggestIndexOperatorAlternativeVisitor<'a, 'tcx> {
550554
assign_span: Span,
551555
err: &'a mut Diag<'tcx>,
552556
ty: Ty<'tcx>,
553557
suggested: bool,
554558
}
555-
impl<'a, 'tcx> Visitor<'tcx> for V<'a, 'tcx> {
559+
impl<'a, 'tcx> Visitor<'tcx> for SuggestIndexOperatorAlternativeVisitor<'a, 'tcx> {
556560
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
557561
hir::intravisit::walk_stmt(self, stmt);
558562
let expr = match stmt.kind {
@@ -645,7 +649,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
645649
let Some(body_id) = hir_map.maybe_body_owned_by(local_def_id) else { return };
646650
let body = self.infcx.tcx.hir().body(body_id);
647651

648-
let mut v = V { assign_span: span, err, ty, suggested: false };
652+
let mut v = SuggestIndexOperatorAlternativeVisitor {
653+
assign_span: span,
654+
err,
655+
ty,
656+
suggested: false,
657+
};
649658
v.visit_body(body);
650659
if !v.suggested {
651660
err.help(format!(

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,10 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
418418
{
419419
if let &hir::ClosureBinder::For { span: for_sp, .. } = binder {
420420
fn span_of_infer(ty: &hir::Ty<'_>) -> Option<Span> {
421-
struct V;
422-
impl<'v> Visitor<'v> for V {
421+
/// Look for `_` anywhere in the signature of a `for<> ||` closure.
422+
/// This is currently disallowed.
423+
struct FindInferInClosureWithBinder;
424+
impl<'v> Visitor<'v> for FindInferInClosureWithBinder {
423425
type Result = ControlFlow<Span>;
424426
fn visit_ty(&mut self, t: &'v hir::Ty<'v>) -> Self::Result {
425427
if matches!(t.kind, hir::TyKind::Infer) {
@@ -429,7 +431,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
429431
}
430432
}
431433
}
432-
V.visit_ty(ty).break_value()
434+
FindInferInClosureWithBinder.visit_ty(ty).break_value()
433435
}
434436

435437
let infer_in_rt_sp = match fn_decl.output {

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1916,22 +1916,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19161916
pat: &'tcx hir::Pat<'tcx>,
19171917
ty: Ty<'tcx>,
19181918
) {
1919-
struct V {
1920-
pat_hir_ids: Vec<hir::HirId>,
1921-
}
1922-
1923-
impl<'tcx> Visitor<'tcx> for V {
1924-
fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) {
1925-
self.pat_hir_ids.push(p.hir_id);
1926-
hir::intravisit::walk_pat(self, p);
1927-
}
1928-
}
19291919
if let Err(guar) = ty.error_reported() {
1920+
struct OverwritePatternsWithError {
1921+
pat_hir_ids: Vec<hir::HirId>,
1922+
}
1923+
impl<'tcx> Visitor<'tcx> for OverwritePatternsWithError {
1924+
fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) {
1925+
self.pat_hir_ids.push(p.hir_id);
1926+
hir::intravisit::walk_pat(self, p);
1927+
}
1928+
}
19301929
// Override the types everywhere with `err()` to avoid knock on errors.
19311930
let err = Ty::new_error(self.tcx, guar);
19321931
self.write_ty(hir_id, err);
19331932
self.write_ty(pat.hir_id, err);
1934-
let mut visitor = V { pat_hir_ids: vec![] };
1933+
let mut visitor = OverwritePatternsWithError { pat_hir_ids: vec![] };
19351934
hir::intravisit::walk_pat(&mut visitor, pat);
19361935
// Mark all the subpatterns as `{type error}` as well. This allows errors for specific
19371936
// subpatterns to be silenced.

compiler/rustc_pattern_analysis/src/constructor.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ use std::iter::once;
155155
use smallvec::SmallVec;
156156

157157
use rustc_apfloat::ieee::{DoubleS, IeeeFloat, SingleS};
158-
use rustc_index::bit_set::GrowableBitSet;
158+
use rustc_index::bit_set::{BitSet, GrowableBitSet};
159+
use rustc_index::IndexVec;
159160

160161
use self::Constructor::*;
161162
use self::MaybeInfiniteInt::*;
162163
use self::SliceKind::*;
163164

164-
use crate::index;
165165
use crate::PatCx;
166166

167167
/// Whether we have seen a constructor in the column or not.
@@ -920,10 +920,7 @@ pub enum ConstructorSet<Cx: PatCx> {
920920
Struct { empty: bool },
921921
/// This type has the following list of constructors. If `variants` is empty and
922922
/// `non_exhaustive` is false, don't use this; use `NoConstructors` instead.
923-
Variants {
924-
variants: index::IdxContainer<Cx::VariantIdx, VariantVisibility>,
925-
non_exhaustive: bool,
926-
},
923+
Variants { variants: IndexVec<Cx::VariantIdx, VariantVisibility>, non_exhaustive: bool },
927924
/// The type is `&T`.
928925
Ref,
929926
/// The type is a union.
@@ -1025,7 +1022,7 @@ impl<Cx: PatCx> ConstructorSet<Cx> {
10251022
}
10261023
}
10271024
ConstructorSet::Variants { variants, non_exhaustive } => {
1028-
let mut seen_set = index::IdxSet::new_empty(variants.len());
1025+
let mut seen_set = BitSet::new_empty(variants.len());
10291026
for idx in seen.iter().filter_map(|c| c.as_variant()) {
10301027
seen_set.insert(idx);
10311028
}

compiler/rustc_pattern_analysis/src/lib.rs

+4-45
Original file line numberDiff line numberDiff line change
@@ -25,50 +25,9 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
2525

2626
use std::fmt;
2727

28-
#[cfg(feature = "rustc")]
29-
pub mod index {
30-
// Faster version when the indices of variants are `0..variants.len()`.
31-
pub use rustc_index::bit_set::BitSet as IdxSet;
32-
pub use rustc_index::Idx;
33-
pub use rustc_index::IndexVec as IdxContainer;
34-
}
35-
#[cfg(not(feature = "rustc"))]
36-
pub mod index {
37-
// Slower version when the indices of variants are something else.
38-
pub trait Idx: Copy + PartialEq + Eq + std::hash::Hash {}
39-
impl<T: Copy + PartialEq + Eq + std::hash::Hash> Idx for T {}
40-
41-
#[derive(Debug)]
42-
pub struct IdxContainer<K, V>(pub rustc_hash::FxHashMap<K, V>);
43-
impl<K: Idx, V> IdxContainer<K, V> {
44-
pub fn len(&self) -> usize {
45-
self.0.len()
46-
}
47-
pub fn iter_enumerated(&self) -> impl Iterator<Item = (K, &V)> {
48-
self.0.iter().map(|(k, v)| (*k, v))
49-
}
50-
}
51-
52-
impl<V> FromIterator<V> for IdxContainer<usize, V> {
53-
fn from_iter<T: IntoIterator<Item = V>>(iter: T) -> Self {
54-
Self(iter.into_iter().enumerate().collect())
55-
}
56-
}
57-
58-
#[derive(Debug)]
59-
pub struct IdxSet<T>(pub rustc_hash::FxHashSet<T>);
60-
impl<T: Idx> IdxSet<T> {
61-
pub fn new_empty(_len: usize) -> Self {
62-
Self(Default::default())
63-
}
64-
pub fn contains(&self, elem: T) -> bool {
65-
self.0.contains(&elem)
66-
}
67-
pub fn insert(&mut self, elem: T) {
68-
self.0.insert(elem);
69-
}
70-
}
71-
}
28+
// Re-exports to avoid rustc_index version issues.
29+
pub use rustc_index::Idx;
30+
pub use rustc_index::IndexVec;
7231

7332
#[cfg(feature = "rustc")]
7433
use rustc_middle::ty::Ty;
@@ -96,7 +55,7 @@ pub trait PatCx: Sized + fmt::Debug {
9655
/// Errors that can abort analysis.
9756
type Error: fmt::Debug;
9857
/// The index of an enum variant.
99-
type VariantIdx: Clone + index::Idx + fmt::Debug;
58+
type VariantIdx: Clone + Idx + fmt::Debug;
10059
/// A string literal
10160
type StrLit: Clone + PartialEq + fmt::Debug;
10261
/// Extra data to store in a match arm.

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1128,10 +1128,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
11281128
err: &mut Diag<'_>,
11291129
) -> bool {
11301130
let span = obligation.cause.span;
1131-
struct V {
1131+
/// Look for the (direct) sub-expr of `?`, and return it if it's a `.` method call.
1132+
struct FindMethodSubexprOfTry {
11321133
search_span: Span,
11331134
}
1134-
impl<'v> Visitor<'v> for V {
1135+
impl<'v> Visitor<'v> for FindMethodSubexprOfTry {
11351136
type Result = ControlFlow<&'v hir::Expr<'v>>;
11361137
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) -> Self::Result {
11371138
if let hir::ExprKind::Match(expr, _arms, hir::MatchSource::TryDesugar(_)) = ex.kind
@@ -1149,8 +1150,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
11491150
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. }) => body_id,
11501151
_ => return false,
11511152
};
1152-
let ControlFlow::Break(expr) =
1153-
(V { search_span: span }).visit_body(self.tcx.hir().body(*body_id))
1153+
let ControlFlow::Break(expr) = (FindMethodSubexprOfTry { search_span: span })
1154+
.visit_body(self.tcx.hir().body(*body_id))
11541155
else {
11551156
return false;
11561157
};

src/bootstrap/src/bin/rustc.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ fn main() {
220220
}
221221
}
222222

223+
if env::var_os("RUSTC_BOLT_LINK_FLAGS").is_some() {
224+
if let Some("rustc_driver") = crate_name {
225+
cmd.arg("-Clink-args=-Wl,-q");
226+
}
227+
}
228+
223229
let is_test = args.iter().any(|a| a == "--test");
224230
if verbose > 2 {
225231
let rust_env_vars =
@@ -244,12 +250,6 @@ fn main() {
244250
eprintln!("{prefix} libdir: {libdir:?}");
245251
}
246252

247-
if env::var_os("RUSTC_BOLT_LINK_FLAGS").is_some() {
248-
if let Some("rustc_driver") = crate_name {
249-
cmd.arg("-Clink-args=-Wl,-q");
250-
}
251-
}
252-
253253
bin_helpers::maybe_dump(format!("stage{stage}-rustc"), &cmd);
254254

255255
let start = Instant::now();

src/tools/miri/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ harness = false
5959
[features]
6060
default = ["stack-cache"]
6161
stack-cache = []
62+
stack-cache-consistency-check = ["stack-cache"]
6263

6364
# Be aware that this file is inside a workspace when used via the
6465
# submodule in the rustc repo. That means there are many cargo features

0 commit comments

Comments
 (0)