Skip to content

Commit 7f279dc

Browse files
committed
Auto merge of #146307 - BennoLossin:field-projections, r=<try>
Add field representing types try-job: test-various
2 parents d34f1f9 + 2b1555f commit 7f279dc

139 files changed

Lines changed: 2040 additions & 57 deletions

File tree

Some content is hidden

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

‎Cargo.lock‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,6 +3431,7 @@ dependencies = [
34313431
"rustc_macros",
34323432
"rustc_serialize",
34333433
"rustc_span",
3434+
"serde",
34343435
"tracing",
34353436
]
34363437

@@ -4250,6 +4251,7 @@ dependencies = [
42504251
"rustc_target",
42514252
"rustc_thread_pool",
42524253
"rustc_type_ir",
4254+
"serde",
42534255
"smallvec",
42544256
"thin-vec",
42554257
"tracing",

‎compiler/rustc_abi/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rustc_index = { path = "../rustc_index", default-features = false }
1515
rustc_macros = { path = "../rustc_macros", optional = true }
1616
rustc_serialize = { path = "../rustc_serialize", optional = true }
1717
rustc_span = { path = "../rustc_span", optional = true }
18+
serde = { version = "1.0.125", features = ["derive"] }
1819
tracing = "0.1"
1920
# tidy-alphabetical-end
2021

‎compiler/rustc_abi/src/layout/ty.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ rustc_index::newtype_index! {
3333
/// `b` is `FieldIdx(1)` in `VariantIdx(0)`,
3434
/// `d` is `FieldIdx(1)` in `VariantIdx(1)`, and
3535
/// `f` is `FieldIdx(1)` in `VariantIdx(0)`.
36-
#[derive(HashStable_Generic)]
36+
#[derive(HashStable_Generic, serde::Serialize)]
3737
#[encodable]
3838
#[orderable]
3939
pub struct FieldIdx {}
@@ -57,7 +57,7 @@ rustc_index::newtype_index! {
5757
///
5858
/// `struct`s, `tuples`, and `unions`s are considered to have a single variant
5959
/// with variant index zero, aka [`FIRST_VARIANT`].
60-
#[derive(HashStable_Generic)]
60+
#[derive(HashStable_Generic, serde::Serialize)]
6161
#[encodable]
6262
#[orderable]
6363
pub struct VariantIdx {

‎compiler/rustc_ast/src/ast.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,6 +2553,11 @@ pub enum TyKind {
25532553
/// Pattern types like `pattern_type!(u32 is 1..=)`, which is the same as `NonZero<u32>`,
25542554
/// just as part of the type system.
25552555
Pat(Box<Ty>, Box<TyPat>),
2556+
/// A `field_of` expression (e.g., `builtin # field_of(Struct, field)`).
2557+
///
2558+
/// Usually not written directly in user code but indirectly via the macro
2559+
/// `core::field::field_of!(...)`.
2560+
FieldOf(Box<Ty>, Option<Ident>, Ident),
25562561
/// Sometimes we need a dummy value when no error has occurred.
25572562
Dummy,
25582563
/// Placeholder for a kind that has failed to be defined.

‎compiler/rustc_ast/src/util/classify.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> {
298298
| ast::TyKind::ImplicitSelf
299299
| ast::TyKind::CVarArgs
300300
| ast::TyKind::Pat(..)
301+
| ast::TyKind::FieldOf(..)
301302
| ast::TyKind::Dummy
302303
| ast::TyKind::Err(..) => break None,
303304
}

‎compiler/rustc_ast_lowering/src/lib.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14971497
TyKind::Pat(ty, pat) => {
14981498
hir::TyKind::Pat(self.lower_ty_alloc(ty, itctx), self.lower_ty_pat(pat, ty.span))
14991499
}
1500+
TyKind::FieldOf(ty, variant, field) => hir::TyKind::FieldOf(
1501+
self.lower_ty_alloc(ty, itctx),
1502+
self.arena.alloc(hir::TyFieldPath {
1503+
variant: variant.map(|variant| self.lower_ident(variant)),
1504+
field: self.lower_ident(*field),
1505+
}),
1506+
),
1507+
15001508
TyKind::MacCall(_) => {
15011509
span_bug!(t.span, "`TyKind::MacCall` should have been expanded by now")
15021510
}

‎compiler/rustc_ast_pretty/src/pprust/state.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,23 @@ impl<'a> State<'a> {
13771377
self.word(" is ");
13781378
self.print_ty_pat(pat);
13791379
}
1380+
ast::TyKind::FieldOf(ty, variant, field) => {
1381+
self.word("builtin # field_of");
1382+
self.popen();
1383+
let ib = self.ibox(0);
1384+
self.print_type(ty);
1385+
self.word(",");
1386+
self.space();
1387+
1388+
if let Some(variant) = variant {
1389+
self.print_ident(*variant);
1390+
self.word(".");
1391+
}
1392+
self.print_ident(*field);
1393+
1394+
self.end(ib);
1395+
self.pclose();
1396+
}
13801397
}
13811398
self.end(ib);
13821399
}

‎compiler/rustc_borrowck/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
18901890
| ty::Str
18911891
| ty::Array(_, _)
18921892
| ty::Pat(_, _)
1893+
| ty::FRT(..)
18931894
| ty::Slice(_)
18941895
| ty::FnDef(_, _)
18951896
| ty::FnPtr(..)
@@ -1934,6 +1935,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
19341935
| ty::Str
19351936
| ty::Array(_, _)
19361937
| ty::Pat(_, _)
1938+
| ty::FRT(..)
19371939
| ty::Slice(_)
19381940
| ty::RawPtr(_, _)
19391941
| ty::Ref(_, _, _)

‎compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ fn push_debuginfo_type_name<'tcx>(
216216
write!(output, "{:?}", t).unwrap();
217217
}
218218
}
219+
// FIXME(FRTs): implement debuginfo for field representing types
220+
ty::FRT(..) => todo!(),
219221
ty::Slice(inner_type) => {
220222
if cpp_like_debuginfo {
221223
output.push_str("slice2$<");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
136136
variant
137137
}
138138
ty::Adt(_, _)
139+
| ty::FRT(_, _)
139140
| ty::Foreign(_)
140141
| ty::Pat(_, _)
141142
| ty::FnDef(..)

0 commit comments

Comments
 (0)