Skip to content

Commit 2fb0e8d

Browse files
committed
Auto merge of #109734 - matthiaskrgr:rollup-oy4nlli, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #107387 (Use random `HashMap` keys on Hermit) - #109511 (Make `EvalCtxt`'s `infcx` private) - #109554 (Suggest ..= when someone tries to create an overflowing range) - #109675 (Do not consider elaborated projection predicates for objects in new solver) - #109693 (Remove ~const from alloc) - #109700 (Lint against escape sequences in Fluent files) - #109716 (Move `mir::Field` → `abi::FieldIdx`) - #109726 (rustdoc: Don't strip crate module) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 17c1167 + 02cb4da commit 2fb0e8d

File tree

77 files changed

+516
-298
lines changed

Some content is hidden

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

77 files changed

+516
-298
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,32 @@ impl Scalar {
10571057
}
10581058
}
10591059

1060+
rustc_index::newtype_index! {
1061+
/// The *source-order* index of a field in a variant.
1062+
///
1063+
/// This is how most code after type checking refers to fields, rather than
1064+
/// using names (as names have hygiene complications and more complex lookup).
1065+
///
1066+
/// Particularly for `repr(Rust)` types, this may not be the same as *layout* order.
1067+
/// (It is for `repr(C)` `struct`s, however.)
1068+
///
1069+
/// For example, in the following types,
1070+
/// ```rust
1071+
/// # enum Never {}
1072+
/// # #[repr(u16)]
1073+
/// enum Demo1 {
1074+
/// Variant0 { a: Never, b: i32 } = 100,
1075+
/// Variant1 { c: u8, d: u64 } = 10,
1076+
/// }
1077+
/// struct Demo2 { e: u8, f: u16, g: u8 }
1078+
/// ```
1079+
/// `b` is `FieldIdx(1)` in `VariantIdx(0)`,
1080+
/// `d` is `FieldIdx(1)` in `VariantIdx(1)`, and
1081+
/// `f` is `FieldIdx(1)` in `VariantIdx(0)`.
1082+
#[derive(HashStable_Generic)]
1083+
pub struct FieldIdx {}
1084+
}
1085+
10601086
/// Describes how the fields of a type are located in memory.
10611087
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
10621088
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ use rustc_hir::GeneratorKind;
99
use rustc_infer::infer::{LateBoundRegionConversionTime, TyCtxtInferExt};
1010
use rustc_middle::mir::tcx::PlaceTy;
1111
use rustc_middle::mir::{
12-
AggregateKind, Constant, FakeReadCause, Field, Local, LocalInfo, LocalKind, Location, Operand,
13-
Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
12+
AggregateKind, Constant, FakeReadCause, Local, LocalInfo, LocalKind, Location, Operand, Place,
13+
PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
1414
};
1515
use rustc_middle::ty::print::Print;
1616
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
1717
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult};
1818
use rustc_span::def_id::LocalDefId;
1919
use rustc_span::{symbol::sym, Span, Symbol, DUMMY_SP};
20-
use rustc_target::abi::VariantIdx;
20+
use rustc_target::abi::{FieldIdx, VariantIdx};
2121
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
2222
use rustc_trait_selection::traits::{
2323
type_known_to_meet_bound_modulo_regions, Obligation, ObligationCause,
@@ -302,7 +302,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
302302
fn describe_field(
303303
&self,
304304
place: PlaceRef<'tcx>,
305-
field: Field,
305+
field: FieldIdx,
306306
including_tuple_field: IncludingTupleField,
307307
) -> Option<String> {
308308
let place_ty = match place {
@@ -331,7 +331,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
331331
fn describe_field_from_ty(
332332
&self,
333333
ty: Ty<'_>,
334-
field: Field,
334+
field: FieldIdx,
335335
variant_index: Option<VariantIdx>,
336336
including_tuple_field: IncludingTupleField,
337337
) -> Option<String> {

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_middle::{
1212
use rustc_span::source_map::DesugaringKind;
1313
use rustc_span::symbol::{kw, Symbol};
1414
use rustc_span::{sym, BytePos, Span};
15+
use rustc_target::abi::FieldIdx;
1516

1617
use crate::diagnostics::BorrowedContentSource;
1718
use crate::MirBorrowckCtxt;
@@ -1275,7 +1276,7 @@ fn is_closure_or_generator(ty: Ty<'_>) -> bool {
12751276
fn get_mut_span_in_struct_field<'tcx>(
12761277
tcx: TyCtxt<'tcx>,
12771278
ty: Ty<'tcx>,
1278-
field: mir::Field,
1279+
field: FieldIdx,
12791280
) -> Option<Span> {
12801281
// Expect our local to be a reference to a struct of some kind.
12811282
if let ty::Ref(_, ty, _) = ty.kind()

compiler/rustc_borrowck/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ use rustc_middle::mir::{
3333
Place, PlaceElem, PlaceRef, VarDebugInfoContents,
3434
};
3535
use rustc_middle::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind};
36-
use rustc_middle::mir::{Field, ProjectionElem, Promoted, Rvalue, Statement, StatementKind};
3736
use rustc_middle::mir::{InlineAsmOperand, Terminator, TerminatorKind};
37+
use rustc_middle::mir::{ProjectionElem, Promoted, Rvalue, Statement, StatementKind};
3838
use rustc_middle::ty::query::Providers;
3939
use rustc_middle::ty::{self, CapturedPlace, ParamEnv, RegionVid, TyCtxt};
4040
use rustc_session::lint::builtin::UNUSED_MUT;
4141
use rustc_span::{Span, Symbol};
42+
use rustc_target::abi::FieldIdx;
4243

4344
use either::Either;
4445
use smallvec::SmallVec;
@@ -597,7 +598,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
597598
used_mut: FxIndexSet<Local>,
598599
/// If the function we're checking is a closure, then we'll need to report back the list of
599600
/// mutable upvars that have been used. This field keeps track of them.
600-
used_mut_upvars: SmallVec<[Field; 8]>,
601+
used_mut_upvars: SmallVec<[FieldIdx; 8]>,
601602
/// Region inference context. This contains the results from region inference and lets us e.g.
602603
/// find out which CFG points are contained in each borrow region.
603604
regioncx: Rc<RegionInferenceContext<'tcx>>,
@@ -2277,7 +2278,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22772278
/// then returns the index of the field being projected. Note that this closure will always
22782279
/// be `self` in the current MIR, because that is the only time we directly access the fields
22792280
/// of a closure type.
2280-
fn is_upvar_field_projection(&self, place_ref: PlaceRef<'tcx>) -> Option<Field> {
2281+
fn is_upvar_field_projection(&self, place_ref: PlaceRef<'tcx>) -> Option<FieldIdx> {
22812282
path_utils::is_upvar_field_projection(self.infcx.tcx, &self.upvars, place_ref, self.body())
22822283
}
22832284

compiler/rustc_borrowck/src/path_utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use crate::BorrowIndex;
77
use crate::Upvar;
88
use rustc_data_structures::graph::dominators::Dominators;
99
use rustc_middle::mir::BorrowKind;
10-
use rustc_middle::mir::{BasicBlock, Body, Field, Location, Place, PlaceRef, ProjectionElem};
10+
use rustc_middle::mir::{BasicBlock, Body, Location, Place, PlaceRef, ProjectionElem};
1111
use rustc_middle::ty::TyCtxt;
12+
use rustc_target::abi::FieldIdx;
1213

1314
/// Returns `true` if the borrow represented by `kind` is
1415
/// allowed to be split into separate Reservation and
@@ -148,7 +149,7 @@ pub(crate) fn is_upvar_field_projection<'tcx>(
148149
upvars: &[Upvar<'tcx>],
149150
place_ref: PlaceRef<'tcx>,
150151
body: &Body<'tcx>,
151-
) -> Option<Field> {
152+
) -> Option<FieldIdx> {
152153
let mut place_ref = place_ref;
153154
let mut by_ref = false;
154155

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_middle::ty::{
3636
};
3737
use rustc_span::def_id::CRATE_DEF_ID;
3838
use rustc_span::{Span, DUMMY_SP};
39-
use rustc_target::abi::FIRST_VARIANT;
39+
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
4040
use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints;
4141
use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp;
4242
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
@@ -786,7 +786,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
786786
&mut self,
787787
parent: &dyn fmt::Debug,
788788
base_ty: PlaceTy<'tcx>,
789-
field: Field,
789+
field: FieldIdx,
790790
location: Location,
791791
) -> Result<Ty<'tcx>, FieldAccessError> {
792792
let tcx = self.tcx();

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
327327
ArgKind::Spread(params) => {
328328
for (i, param) in params.into_iter().enumerate() {
329329
if let Some(param) = param {
330-
place.place_field(fx, mir::Field::new(i)).write_cvalue(fx, param);
330+
place.place_field(fx, FieldIdx::new(i)).write_cvalue(fx, param);
331331
}
332332
}
333333
}
@@ -460,7 +460,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
460460
args.push(self_arg);
461461
for i in 0..tupled_arguments.len() {
462462
args.push(CallArgument {
463-
value: pack_arg.value.value_field(fx, mir::Field::new(i)),
463+
value: pack_arg.value.value_field(fx, FieldIdx::new(i)),
464464
is_owned: pack_arg.is_owned,
465465
});
466466
}

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ fn codegen_stmt<'tcx>(
797797
let index = fx.bcx.ins().iconst(fx.pointer_type, field_index as i64);
798798
variant_dest.place_index(fx, index)
799799
} else {
800-
variant_dest.place_field(fx, mir::Field::new(field_index))
800+
variant_dest.place_field(fx, FieldIdx::new(field_index))
801801
};
802802
to.write_cvalue(fx, operand);
803803
}

compiler/rustc_codegen_cranelift/src/discriminant.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
2626
tag_encoding: TagEncoding::Direct,
2727
variants: _,
2828
} => {
29-
let ptr = place.place_field(fx, mir::Field::new(tag_field));
29+
let ptr = place.place_field(fx, FieldIdx::new(tag_field));
3030
let to = layout.ty.discriminant_for_variant(fx.tcx, variant_index).unwrap().val;
3131
let to = if ptr.layout().abi.is_signed() {
3232
ty::ScalarInt::try_from_int(
@@ -47,7 +47,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
4747
variants: _,
4848
} => {
4949
if variant_index != untagged_variant {
50-
let niche = place.place_field(fx, mir::Field::new(tag_field));
50+
let niche = place.place_field(fx, FieldIdx::new(tag_field));
5151
let niche_type = fx.clif_type(niche.layout().ty).unwrap();
5252
let niche_value = variant_index.as_u32() - niche_variants.start().as_u32();
5353
let niche_value = (niche_value as u128).wrapping_add(niche_start);
@@ -107,7 +107,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
107107
let cast_to = fx.clif_type(dest_layout.ty).unwrap();
108108

109109
// Read the tag/niche-encoded discriminant from memory.
110-
let tag = value.value_field(fx, mir::Field::new(tag_field));
110+
let tag = value.value_field(fx, FieldIdx::new(tag_field));
111111
let tag = tag.load_scalar(fx);
112112

113113
// Decode the discriminant (specifically if it's niche-encoded).

compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ fn llvm_add_sub<'tcx>(
179179

180180
// c + carry -> c + first intermediate carry or borrow respectively
181181
let int0 = crate::num::codegen_checked_int_binop(fx, bin_op, a, b);
182-
let c = int0.value_field(fx, mir::Field::new(0));
183-
let cb0 = int0.value_field(fx, mir::Field::new(1)).load_scalar(fx);
182+
let c = int0.value_field(fx, FieldIdx::new(0));
183+
let cb0 = int0.value_field(fx, FieldIdx::new(1)).load_scalar(fx);
184184

185185
// c + carry -> c + second intermediate carry or borrow respectively
186186
let cb_in_as_u64 = fx.bcx.ins().uextend(types::I64, cb_in);

0 commit comments

Comments
 (0)