Skip to content

Commit 85a26a9

Browse files
committed
Auto merge of rust-lang#97989 - Dylan-DPC:rollup-wol1a1y, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#97761 (validating the vtable can lead to Stacked Borrows errors) - rust-lang#97789 (Fix rust-lang#71363's test by adding `-Z translate-remapped-path-to-local-path=no`) - rust-lang#97913 (Wrap `HirId`s of locals into `LocalVarId`s for THIR nodes) - rust-lang#97979 (Fix typos in Provider API docs) - rust-lang#97987 (remove an unnecessary `String`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents fa68e73 + b3c9a2f commit 85a26a9

File tree

14 files changed

+87
-53
lines changed

14 files changed

+87
-53
lines changed

compiler/rustc_const_eval/src/interpret/validity.rs

+8
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
338338
{ "invalid drop function pointer in vtable (not pointing to a function)" },
339339
err_ub!(InvalidVtableDropFn(..)) =>
340340
{ "invalid drop function pointer in vtable (function has incompatible signature)" },
341+
// Stacked Borrows errors can happen here, see https://github.com/rust-lang/miri/issues/2123.
342+
// (We assume there are no other MachineStop errors possible here.)
343+
InterpError::MachineStop(_) =>
344+
{ "vtable pointer does not have permission to read drop function pointer" },
341345
);
342346
try_validation!(
343347
self.ecx.read_size_and_align_from_vtable(vtable),
@@ -347,6 +351,10 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
347351
err_ub!(InvalidVtableAlignment(msg)) =>
348352
{ "invalid vtable: alignment {}", msg },
349353
err_unsup!(ReadPointerAsBytes) => { "invalid size or align in vtable" },
354+
// Stacked Borrows errors can happen here, see https://github.com/rust-lang/miri/issues/2123.
355+
// (We assume there are no other MachineStop errors possible here.)
356+
InterpError::MachineStop(_) =>
357+
{ "vtable pointer does not have permission to read size and alignment" },
350358
);
351359
// FIXME: More checks for the vtable.
352360
}

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
304304
error_code: TypeAnnotationNeeded,
305305
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
306306
let error_code = error_code.into();
307-
let mut err = self.tcx.sess.struct_span_err_with_code(
308-
span,
309-
&format!("type annotations needed"),
310-
error_code,
311-
);
307+
let mut err =
308+
self.tcx.sess.struct_span_err_with_code(span, "type annotations needed", error_code);
312309
err.span_label(span, arg_data.cannot_infer_msg());
313310
err
314311
}

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ fn test_debugging_options_tracking_hash() {
789789
tracked!(thinlto, Some(true));
790790
tracked!(thir_unsafeck, true);
791791
tracked!(tls_model, Some(TlsModel::GeneralDynamic));
792+
tracked!(translate_remapped_path_to_local_path, false);
792793
tracked!(trap_unreachable, Some(false));
793794
tracked!(treat_err_as_bug, NonZeroUsize::new(1));
794795
tracked!(tune_cpu, Some(String::from("abc")));

compiler/rustc_metadata/src/rmeta/decoder.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
14861486
.filter(|_| {
14871487
// Only spend time on further checks if we have what to translate *to*.
14881488
sess.opts.real_rust_source_base_dir.is_some()
1489+
// Some tests need the translation to be always skipped.
1490+
&& sess.opts.debugging_opts.translate_remapped_path_to_local_path
14891491
})
14901492
.filter(|virtual_dir| {
14911493
// Don't translate away `/rustc/$hash` if we're still remapping to it,

compiler/rustc_middle/src/thir.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,20 @@ pub enum StmtKind<'tcx> {
191191
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
192192
rustc_data_structures::static_assert_size!(Expr<'_>, 104);
193193

194+
#[derive(
195+
Clone,
196+
Debug,
197+
Copy,
198+
PartialEq,
199+
Eq,
200+
Hash,
201+
HashStable,
202+
TyEncodable,
203+
TyDecodable,
204+
TypeFoldable
205+
)]
206+
pub struct LocalVarId(pub hir::HirId);
207+
194208
/// A THIR expression.
195209
#[derive(Clone, Debug, HashStable)]
196210
pub struct Expr<'tcx> {
@@ -332,15 +346,15 @@ pub enum ExprKind<'tcx> {
332346
},
333347
/// A local variable.
334348
VarRef {
335-
id: hir::HirId,
349+
id: LocalVarId,
336350
},
337351
/// Used to represent upvars mentioned in a closure/generator
338352
UpvarRef {
339353
/// DefId of the closure/generator
340354
closure_def_id: DefId,
341355

342356
/// HirId of the root variable
343-
var_hir_id: hir::HirId,
357+
var_hir_id: LocalVarId,
344358
},
345359
/// A borrow, e.g. `&arg`.
346360
Borrow {
@@ -596,7 +610,7 @@ pub enum PatKind<'tcx> {
596610
mutability: Mutability,
597611
name: Symbol,
598612
mode: BindingMode,
599-
var: hir::HirId,
613+
var: LocalVarId,
600614
ty: Ty<'tcx>,
601615
subpattern: Option<Pat<'tcx>>,
602616
/// Is this the leftmost occurrence of the binding, i.e., is `var` the

compiler/rustc_mir_build/src/build/expr/as_place.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
use crate::build::expr::category::Category;
44
use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};
55
use crate::build::{BlockAnd, BlockAndExtension, Builder};
6-
use rustc_hir::def_id::DefId;
7-
use rustc_hir::HirId;
6+
use rustc_hir::def_id::{DefId, LocalDefId};
87
use rustc_middle::hir::place::Projection as HirProjection;
98
use rustc_middle::hir::place::ProjectionKind as HirProjectionKind;
109
use rustc_middle::middle::region;
@@ -57,7 +56,7 @@ pub(crate) enum PlaceBase {
5756
/// figure out that it is captured until all the `Field` projections are applied.
5857
Upvar {
5958
/// HirId of the upvar
60-
var_hir_id: HirId,
59+
var_hir_id: LocalVarId,
6160
/// DefId of the closure
6261
closure_def_id: DefId,
6362
/// The trait closure implements, `Fn`, `FnMut`, `FnOnce`
@@ -151,12 +150,12 @@ fn is_ancestor_or_same_capture(
151150
/// `ty::MinCaptureList` of the root variable `var_hir_id`.
152151
fn compute_capture_idx<'tcx>(
153152
closure_min_captures: &ty::RootVariableMinCaptureList<'tcx>,
154-
var_hir_id: HirId,
153+
var_hir_id: LocalVarId,
155154
root_var_idx: usize,
156155
) -> usize {
157156
let mut res = 0;
158157
for (var_id, capture_list) in closure_min_captures {
159-
if *var_id == var_hir_id {
158+
if *var_id == var_hir_id.0 {
160159
res += root_var_idx;
161160
break;
162161
} else {
@@ -176,12 +175,12 @@ fn compute_capture_idx<'tcx>(
176175
/// Returns None, when the ancestor is not found.
177176
fn find_capture_matching_projections<'a, 'tcx>(
178177
typeck_results: &'a ty::TypeckResults<'tcx>,
179-
var_hir_id: HirId,
178+
var_hir_id: LocalVarId,
180179
closure_def_id: DefId,
181180
projections: &[PlaceElem<'tcx>],
182181
) -> Option<(usize, &'a ty::CapturedPlace<'tcx>)> {
183182
let closure_min_captures = typeck_results.closure_min_captures.get(&closure_def_id)?;
184-
let root_variable_min_captures = closure_min_captures.get(&var_hir_id)?;
183+
let root_variable_min_captures = closure_min_captures.get(&var_hir_id.0)?;
185184

186185
let hir_projections = convert_to_hir_projections_and_truncate_for_capture(projections);
187186

@@ -500,8 +499,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
500499
source_info,
501500
),
502501
ExprKind::UpvarRef { closure_def_id, var_hir_id } => {
503-
let upvar_id = ty::UpvarId::new(var_hir_id, closure_def_id.expect_local());
504-
this.lower_captured_upvar(block, upvar_id)
502+
this.lower_captured_upvar(block, closure_def_id.expect_local(), var_hir_id)
505503
}
506504

507505
ExprKind::VarRef { id } => {
@@ -627,11 +625,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
627625
fn lower_captured_upvar(
628626
&mut self,
629627
block: BasicBlock,
630-
upvar_id: ty::UpvarId,
628+
closure_expr_id: LocalDefId,
629+
var_hir_id: LocalVarId,
631630
) -> BlockAnd<PlaceBuilder<'tcx>> {
632-
let closure_ty = self
633-
.typeck_results
634-
.node_type(self.tcx.hir().local_def_id_to_hir_id(upvar_id.closure_expr_id));
631+
let closure_ty =
632+
self.typeck_results.node_type(self.tcx.hir().local_def_id_to_hir_id(closure_expr_id));
635633

636634
let closure_kind = if let ty::Closure(_, closure_substs) = closure_ty.kind() {
637635
self.infcx.closure_kind(closure_substs).unwrap()
@@ -641,8 +639,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
641639
};
642640

643641
block.and(PlaceBuilder::from(PlaceBase::Upvar {
644-
var_hir_id: upvar_id.var_path.hir_id,
645-
closure_def_id: upvar_id.closure_expr_id.to_def_id(),
642+
var_hir_id,
643+
closure_def_id: closure_expr_id.to_def_id(),
646644
closure_kind,
647645
}))
648646
}

compiler/rustc_mir_build/src/build/matches/mod.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_data_structures::{
1414
fx::{FxHashSet, FxIndexMap, FxIndexSet},
1515
stack::ensure_sufficient_stack,
1616
};
17-
use rustc_hir::HirId;
1817
use rustc_index::bit_set::BitSet;
1918
use rustc_middle::middle::region;
2019
use rustc_middle::mir::*;
@@ -690,7 +689,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
690689
pub(crate) fn storage_live_binding(
691690
&mut self,
692691
block: BasicBlock,
693-
var: HirId,
692+
var: LocalVarId,
694693
span: Span,
695694
for_guard: ForGuard,
696695
schedule_drop: bool,
@@ -700,20 +699,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
700699
self.cfg.push(block, Statement { source_info, kind: StatementKind::StorageLive(local_id) });
701700
// Altough there is almost always scope for given variable in corner cases
702701
// like #92893 we might get variable with no scope.
703-
if let Some(region_scope) = self.region_scope_tree.var_scope(var.local_id) && schedule_drop{
702+
if let Some(region_scope) = self.region_scope_tree.var_scope(var.0.local_id) && schedule_drop{
704703
self.schedule_drop(span, region_scope, local_id, DropKind::Storage);
705704
}
706705
Place::from(local_id)
707706
}
708707

709708
pub(crate) fn schedule_drop_for_binding(
710709
&mut self,
711-
var: HirId,
710+
var: LocalVarId,
712711
span: Span,
713712
for_guard: ForGuard,
714713
) {
715714
let local_id = self.var_local_id(var, for_guard);
716-
if let Some(region_scope) = self.region_scope_tree.var_scope(var.local_id) {
715+
if let Some(region_scope) = self.region_scope_tree.var_scope(var.0.local_id) {
717716
self.schedule_drop(span, region_scope, local_id, DropKind::Value);
718717
}
719718
}
@@ -730,7 +729,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
730729
Mutability,
731730
Symbol,
732731
BindingMode,
733-
HirId,
732+
LocalVarId,
734733
Span,
735734
Ty<'tcx>,
736735
UserTypeProjections,
@@ -917,7 +916,7 @@ fn traverse_candidate<'pat, 'tcx: 'pat, C, T, I>(
917916
struct Binding<'tcx> {
918917
span: Span,
919918
source: Place<'tcx>,
920-
var_id: HirId,
919+
var_id: LocalVarId,
921920
binding_mode: BindingMode,
922921
}
923922

@@ -2184,7 +2183,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
21842183
mutability: Mutability,
21852184
name: Symbol,
21862185
mode: BindingMode,
2187-
var_id: HirId,
2186+
var_id: LocalVarId,
21882187
var_ty: Ty<'tcx>,
21892188
user_ty: UserTypeProjections,
21902189
has_guard: ArmHasGuard,

compiler/rustc_mir_build/src/build/mod.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ use crate::build::scope::DropKind;
44
use crate::thir::constant::parse_float;
55
use crate::thir::pattern::pat_from_hir;
66
use rustc_ast as ast;
7+
use rustc_data_structures::fx::FxHashMap;
78
use rustc_errors::ErrorGuaranteed;
89
use rustc_hir as hir;
910
use rustc_hir::def_id::{DefId, LocalDefId};
1011
use rustc_hir::lang_items::LangItem;
11-
use rustc_hir::{GeneratorKind, HirIdMap, Node};
12+
use rustc_hir::{GeneratorKind, Node};
1213
use rustc_index::vec::{Idx, IndexVec};
1314
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
1415
use rustc_middle::hir::place::PlaceBase as HirPlaceBase;
1516
use rustc_middle::middle::region;
1617
use rustc_middle::mir::interpret::Allocation;
1718
use rustc_middle::mir::interpret::{ConstValue, LitToConstError, LitToConstInput, Scalar};
1819
use rustc_middle::mir::*;
19-
use rustc_middle::thir::{BindingMode, Expr, ExprId, LintLevel, PatKind, Thir};
20+
use rustc_middle::thir::{BindingMode, Expr, ExprId, LintLevel, LocalVarId, PatKind, Thir};
2021
use rustc_middle::ty::subst::Subst;
2122
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeckResults};
2223
use rustc_span::symbol::sym;
@@ -445,7 +446,7 @@ struct Builder<'a, 'tcx> {
445446

446447
/// Maps `HirId`s of variable bindings to the `Local`s created for them.
447448
/// (A match binding can have two locals; the 2nd is for the arm's guard.)
448-
var_indices: HirIdMap<LocalsForNode>,
449+
var_indices: FxHashMap<LocalVarId, LocalsForNode>,
449450
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
450451
canonical_user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>,
451452
upvar_mutbls: Vec<Mutability>,
@@ -455,11 +456,11 @@ struct Builder<'a, 'tcx> {
455456
}
456457

457458
impl<'a, 'tcx> Builder<'a, 'tcx> {
458-
fn is_bound_var_in_guard(&self, id: hir::HirId) -> bool {
459+
fn is_bound_var_in_guard(&self, id: LocalVarId) -> bool {
459460
self.guard_context.iter().any(|frame| frame.locals.iter().any(|local| local.id == id))
460461
}
461462

462-
fn var_local_id(&self, id: hir::HirId, for_guard: ForGuard) -> Local {
463+
fn var_local_id(&self, id: LocalVarId, for_guard: ForGuard) -> Local {
463464
self.var_indices[&id].local_id(for_guard)
464465
}
465466
}
@@ -543,11 +544,11 @@ enum LocalsForNode {
543544

544545
#[derive(Debug)]
545546
struct GuardFrameLocal {
546-
id: hir::HirId,
547+
id: LocalVarId,
547548
}
548549

549550
impl GuardFrameLocal {
550-
fn new(id: hir::HirId, _binding_mode: BindingMode) -> Self {
551+
fn new(id: LocalVarId, _binding_mode: BindingMode) -> Self {
551552
GuardFrameLocal { id }
552553
}
553554
}

compiler/rustc_mir_build/src/thir/cx/expr.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,12 @@ impl<'tcx> Cx<'tcx> {
903903
);
904904

905905
if is_upvar {
906-
ExprKind::UpvarRef { closure_def_id: self.body_owner, var_hir_id }
906+
ExprKind::UpvarRef {
907+
closure_def_id: self.body_owner,
908+
var_hir_id: LocalVarId(var_hir_id),
909+
}
907910
} else {
908-
ExprKind::VarRef { id: var_hir_id }
911+
ExprKind::VarRef { id: LocalVarId(var_hir_id) }
909912
}
910913
}
911914

compiler/rustc_mir_build/src/thir/pattern/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_middle::mir::interpret::{get_slice_bytes, ConstValue};
1919
use rustc_middle::mir::interpret::{ErrorHandled, LitToConstError, LitToConstInput};
2020
use rustc_middle::mir::{self, UserTypeProjection};
2121
use rustc_middle::mir::{BorrowKind, Field, Mutability};
22-
use rustc_middle::thir::{Ascription, BindingMode, FieldPat, Pat, PatKind, PatRange};
22+
use rustc_middle::thir::{Ascription, BindingMode, FieldPat, LocalVarId, Pat, PatKind, PatRange};
2323
use rustc_middle::ty::subst::{GenericArg, SubstsRef};
2424
use rustc_middle::ty::CanonicalUserTypeAnnotation;
2525
use rustc_middle::ty::{self, AdtDef, ConstKind, DefIdTree, Region, Ty, TyCtxt, UserType};
@@ -288,7 +288,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
288288
mutability,
289289
mode,
290290
name: ident.name,
291-
var: id,
291+
var: LocalVarId(id),
292292
ty: var_ty,
293293
subpattern: self.lower_opt_pattern(sub),
294294
is_primary: id == pat.hir_id,
@@ -664,7 +664,7 @@ macro_rules! ClonePatternFoldableImpls {
664664
}
665665

666666
ClonePatternFoldableImpls! { <'tcx>
667-
Span, Field, Mutability, Symbol, hir::HirId, usize, ty::Const<'tcx>,
667+
Span, Field, Mutability, Symbol, LocalVarId, usize, ty::Const<'tcx>,
668668
Region<'tcx>, Ty<'tcx>, BindingMode, AdtDef<'tcx>,
669669
SubstsRef<'tcx>, &'tcx GenericArg<'tcx>, UserType<'tcx>,
670670
UserTypeProjection, CanonicalUserTypeAnnotation<'tcx>

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,8 @@ options! {
15411541
"choose the TLS model to use (`rustc --print tls-models` for details)"),
15421542
trace_macros: bool = (false, parse_bool, [UNTRACKED],
15431543
"for every macro invocation, print its name and arguments (default: no)"),
1544+
translate_remapped_path_to_local_path: bool = (true, parse_bool, [TRACKED],
1545+
"translate remapped paths into local paths when possible (default: yes)"),
15441546
trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
15451547
"generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
15461548
treat_err_as_bug: Option<NonZeroUsize> = (None, parse_treat_err_as_bug, [TRACKED],

library/core/src/any.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
//! functions for requesting data from an object which implements `Provider`. Generally, end users
9595
//! should not call `request_*` directly, they are helper functions for intermediate implementers
9696
//! to use to implement a user-facing interface. This is purely for the sake of ergonomics, there is
97-
//! safety concern here; intermediate implementers can typically support methods rather than
97+
//! no safety concern here; intermediate implementers can typically support methods rather than
9898
//! free functions and use more specific names.
9999
//!
100100
//! Typically, a data provider is a trait object of a trait which extends `Provider`. A user will
@@ -1007,7 +1007,7 @@ mod tags {
10071007
type Reified = T;
10081008
}
10091009

1010-
/// Type-based tag similar to [`Value`] but which may be unsized (i.e., has a `'Sized` bound).
1010+
/// Type-based tag similar to [`Value`] but which may be unsized (i.e., has a `?Sized` bound).
10111011
#[derive(Debug)]
10121012
pub struct MaybeSizedValue<T: ?Sized + 'static>(PhantomData<T>);
10131013

0 commit comments

Comments
 (0)