Skip to content

Commit 41555ab

Browse files
committed
Auto merge of #3298 - rust-lang:rustup-2024-02-13, r=oli-obk
Automatic Rustup
2 parents d2e446d + 43e9411 commit 41555ab

File tree

279 files changed

+5478
-1941
lines changed

Some content is hidden

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

279 files changed

+5478
-1941
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,9 +2107,9 @@ pub enum TyKind {
21072107
/// A tuple (`(A, B, C, D,...)`).
21082108
Tup(ThinVec<P<Ty>>),
21092109
/// An anonymous struct type i.e. `struct { foo: Type }`
2110-
AnonStruct(ThinVec<FieldDef>),
2110+
AnonStruct(NodeId, ThinVec<FieldDef>),
21112111
/// An anonymous union type i.e. `union { bar: Type }`
2112-
AnonUnion(ThinVec<FieldDef>),
2112+
AnonUnion(NodeId, ThinVec<FieldDef>),
21132113
/// A path (`module::module::...::Type`), optionally
21142114
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
21152115
///
@@ -2161,6 +2161,10 @@ impl TyKind {
21612161
None
21622162
}
21632163
}
2164+
2165+
pub fn is_anon_adt(&self) -> bool {
2166+
matches!(self, TyKind::AnonStruct(..) | TyKind::AnonUnion(..))
2167+
}
21642168
}
21652169

21662170
/// Syntax used to declare a trait object.

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
514514
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
515515
}
516516
TyKind::MacCall(mac) => vis.visit_mac_call(mac),
517-
TyKind::AnonStruct(fields) | TyKind::AnonUnion(fields) => {
517+
TyKind::AnonStruct(id, fields) | TyKind::AnonUnion(id, fields) => {
518+
vis.visit_id(id);
518519
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
519520
}
520521
}

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
450450
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
451451
TyKind::MacCall(mac) => visitor.visit_mac_call(mac),
452452
TyKind::Never | TyKind::CVarArgs => {}
453-
TyKind::AnonStruct(ref fields, ..) | TyKind::AnonUnion(ref fields, ..) => {
453+
TyKind::AnonStruct(_, ref fields) | TyKind::AnonUnion(_, ref fields) => {
454454
walk_list!(visitor, visit_field_def, fields)
455455
}
456456
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
720720
}
721721
}
722722

723-
fn lower_field_def(&mut self, (index, f): (usize, &FieldDef)) -> hir::FieldDef<'hir> {
723+
pub(super) fn lower_field_def(
724+
&mut self,
725+
(index, f): (usize, &FieldDef),
726+
) -> hir::FieldDef<'hir> {
724727
let ty = if let TyKind::Path(qself, path) = &f.ty.kind {
725728
let t = self.lower_path_ty(
726729
&f.ty,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,17 +1288,44 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12881288
TyKind::Err => {
12891289
hir::TyKind::Err(self.dcx().span_delayed_bug(t.span, "TyKind::Err lowered"))
12901290
}
1291-
// FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
1292-
#[allow(rustc::untranslatable_diagnostic)]
1293-
#[allow(rustc::diagnostic_outside_of_impl)]
1294-
TyKind::AnonStruct(ref _fields) => {
1295-
hir::TyKind::Err(self.dcx().span_err(t.span, "anonymous structs are unimplemented"))
1296-
}
1297-
// FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
1298-
#[allow(rustc::untranslatable_diagnostic)]
1299-
#[allow(rustc::diagnostic_outside_of_impl)]
1300-
TyKind::AnonUnion(ref _fields) => {
1301-
hir::TyKind::Err(self.dcx().span_err(t.span, "anonymous unions are unimplemented"))
1291+
// Lower the anonymous structs or unions in a nested lowering context.
1292+
//
1293+
// ```
1294+
// struct Foo {
1295+
// _: union {
1296+
// // ^__________________ <-- within the nested lowering context,
1297+
// /* fields */ // | we lower all fields defined into an
1298+
// } // | owner node of struct or union item
1299+
// // ^_____________________|
1300+
// }
1301+
// ```
1302+
TyKind::AnonStruct(node_id, fields) | TyKind::AnonUnion(node_id, fields) => {
1303+
// Here its `def_id` is created in `build_reduced_graph`.
1304+
let def_id = self.local_def_id(*node_id);
1305+
debug!(?def_id);
1306+
let owner_id = hir::OwnerId { def_id };
1307+
self.with_hir_id_owner(*node_id, |this| {
1308+
let fields = this.arena.alloc_from_iter(
1309+
fields.iter().enumerate().map(|f| this.lower_field_def(f)),
1310+
);
1311+
let span = t.span;
1312+
let variant_data = hir::VariantData::Struct { fields, recovered: false };
1313+
// FIXME: capture the generics from the outer adt.
1314+
let generics = hir::Generics::empty();
1315+
let kind = match t.kind {
1316+
TyKind::AnonStruct(..) => hir::ItemKind::Struct(variant_data, generics),
1317+
TyKind::AnonUnion(..) => hir::ItemKind::Union(variant_data, generics),
1318+
_ => unreachable!(),
1319+
};
1320+
hir::OwnerNode::Item(this.arena.alloc(hir::Item {
1321+
ident: Ident::new(kw::Empty, span),
1322+
owner_id,
1323+
kind,
1324+
span: this.lower_span(span),
1325+
vis_span: this.lower_span(span.shrink_to_lo()),
1326+
}))
1327+
});
1328+
hir::TyKind::AnonAdt(hir::ItemId { owner_id })
13021329
}
13031330
TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
13041331
TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ impl<'a> AstValidator<'a> {
219219
}
220220
}
221221
}
222-
TyKind::AnonStruct(ref fields, ..) | TyKind::AnonUnion(ref fields, ..) => {
223-
walk_list!(self, visit_field_def, fields)
222+
TyKind::AnonStruct(_, ref fields) | TyKind::AnonUnion(_, ref fields) => {
223+
walk_list!(self, visit_struct_field_def, fields)
224224
}
225225
_ => visit::walk_ty(self, t),
226226
}

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,11 +1003,11 @@ impl<'a> State<'a> {
10031003
}
10041004
self.pclose();
10051005
}
1006-
ast::TyKind::AnonStruct(fields) => {
1006+
ast::TyKind::AnonStruct(_, fields) => {
10071007
self.head("struct");
10081008
self.print_record_struct_body(fields, ty.span);
10091009
}
1010-
ast::TyKind::AnonUnion(fields) => {
1010+
ast::TyKind::AnonUnion(_, fields) => {
10111011
self.head("union");
10121012
self.print_record_struct_body(fields, ty.span);
10131013
}

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
691691

692692
// If the type is opaque/param/closure, and it is Fn or FnMut, let's suggest (mutably)
693693
// borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`.
694-
// These types seem reasonably opaque enough that they could be substituted with their
694+
// These types seem reasonably opaque enough that they could be instantiated with their
695695
// borrowed variants in a function body when we see a move error.
696696
let borrow_level = match *ty.kind() {
697697
ty::Param(_) => tcx
@@ -3018,7 +3018,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
30183018
/// assignment to `x.f`).
30193019
pub(crate) fn report_illegal_reassignment(
30203020
&mut self,
3021-
_location: Location,
30223021
(place, span): (Place<'tcx>, Span),
30233022
assigned_span: Span,
30243023
err_place: Place<'tcx>,
@@ -3159,7 +3158,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
31593158
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
31603159
// Define a fallback for when we can't match a closure.
31613160
let fallback = || {
3162-
let is_closure = self.infcx.tcx.is_closure_or_coroutine(self.mir_def_id().to_def_id());
3161+
let is_closure = self.infcx.tcx.is_closure_like(self.mir_def_id().to_def_id());
31633162
if is_closure {
31643163
None
31653164
} else {
@@ -3370,7 +3369,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
33703369
sig: ty::PolyFnSig<'tcx>,
33713370
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
33723371
debug!("annotate_fn_sig: did={:?} sig={:?}", did, sig);
3373-
let is_closure = self.infcx.tcx.is_closure_or_coroutine(did.to_def_id());
3372+
let is_closure = self.infcx.tcx.is_closure_like(did.to_def_id());
33743373
let fn_hir_id = self.infcx.tcx.local_def_id_to_hir_id(did);
33753374
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(fn_hir_id)?;
33763375

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
6767
local,
6868
projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
6969
} => {
70-
debug_assert!(is_closure_or_coroutine(
70+
debug_assert!(is_closure_like(
7171
Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty
7272
));
7373

@@ -126,9 +126,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
126126
{
127127
item_msg = access_place_desc;
128128
debug_assert!(self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_ref());
129-
debug_assert!(is_closure_or_coroutine(
130-
the_place_err.ty(self.body, self.infcx.tcx).ty
131-
));
129+
debug_assert!(is_closure_like(the_place_err.ty(self.body, self.infcx.tcx).ty));
132130

133131
reason = if self.is_upvar_field_projection(access_place.as_ref()).is_some() {
134132
", as it is a captured variable in a `Fn` closure".to_string()
@@ -389,7 +387,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
389387
local,
390388
projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
391389
} => {
392-
debug_assert!(is_closure_or_coroutine(
390+
debug_assert!(is_closure_like(
393391
Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty
394392
));
395393

@@ -1474,7 +1472,8 @@ fn suggest_ampmut<'tcx>(
14741472
}
14751473
}
14761474

1477-
fn is_closure_or_coroutine(ty: Ty<'_>) -> bool {
1475+
/// If the type is a `Coroutine`, `Closure`, or `CoroutineClosure`
1476+
fn is_closure_like(ty: Ty<'_>) -> bool {
14781477
ty.is_closure() || ty.is_coroutine() || ty.is_coroutine_closure()
14791478
}
14801479

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10361036
self,
10371037
self.infcx.tcx,
10381038
self.body,
1039-
location,
10401039
(sd, place_span.0),
10411040
&borrow_set,
10421041
|borrow_index| borrows_in_scope.contains(borrow_index),
@@ -2174,7 +2173,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21742173
// report the error as an illegal reassignment
21752174
let init = &self.move_data.inits[init_index];
21762175
let assigned_span = init.span(self.body);
2177-
self.report_illegal_reassignment(location, (place, span), assigned_span, place);
2176+
self.report_illegal_reassignment((place, span), assigned_span, place);
21782177
} else {
21792178
self.report_mutability_error(place, span, the_place_err, error_access, location)
21802179
}

0 commit comments

Comments
 (0)