Skip to content

Commit 41555ab

Browse files
committed
Auto merge of rust-lang#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

+6-2
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

+2-1
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

+1-1
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

+4-1
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

+38-11
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

+2-2
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

+2-2
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

+3-4
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

+5-6
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

+1-2
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
}

compiler/rustc_borrowck/src/path_utils.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub(super) fn each_borrow_involving_path<'tcx, F, I, S>(
2727
s: &mut S,
2828
tcx: TyCtxt<'tcx>,
2929
body: &Body<'tcx>,
30-
_location: Location,
3130
access_place: (AccessDepth, Place<'tcx>),
3231
borrow_set: &BorrowSet<'tcx>,
3332
is_candidate: I,

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ impl<'cx, 'tcx> LoanInvalidationsGenerator<'cx, 'tcx> {
340340
self,
341341
self.tcx,
342342
self.body,
343-
location,
344343
(sd, place),
345344
self.borrow_set,
346345
|_| true,

compiler/rustc_borrowck/src/region_infer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
662662
polonius_output: Option<Rc<PoloniusOutput>>,
663663
) -> (Option<ClosureRegionRequirements<'tcx>>, RegionErrors<'tcx>) {
664664
let mir_def_id = body.source.def_id();
665-
self.propagate_constraints(body);
665+
self.propagate_constraints();
666666

667667
let mut errors_buffer = RegionErrors::new(infcx.tcx);
668668

@@ -716,8 +716,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
716716
/// for each region variable until all the constraints are
717717
/// satisfied. Note that some values may grow **too** large to be
718718
/// feasible, but we check this later.
719-
#[instrument(skip(self, _body), level = "debug")]
720-
fn propagate_constraints(&mut self, _body: &Body<'tcx>) {
719+
#[instrument(skip(self), level = "debug")]
720+
fn propagate_constraints(&mut self) {
721721
debug!("constraints={:#?}", {
722722
let mut constraints: Vec<_> = self.outlives_constraints().collect();
723723
constraints.sort_by_key(|c| (c.sup, c.sub));

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
4545
/// be allowed:
4646
/// `fn f<'a: 'b, 'b: 'a>(x: *mut &'b i32) -> impl Sized + 'a { x }`
4747
///
48-
/// Then we map the regions in both the type and the subst to their
48+
/// Then we map the regions in both the type and the generic parameters to their
4949
/// `external_name` giving `concrete_type = &'a i32`,
5050
/// `args = ['static, 'a]`. This will then allow
5151
/// `infer_opaque_definition_from_instantiation` to determine that
@@ -77,9 +77,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
7777
let args = opaque_type_key.args;
7878
debug!(?concrete_type, ?args);
7979

80-
let mut subst_regions = vec![self.universal_regions.fr_static];
80+
let mut arg_regions = vec![self.universal_regions.fr_static];
8181

82-
let to_universal_region = |vid, subst_regions: &mut Vec<_>| {
82+
let to_universal_region = |vid, arg_regions: &mut Vec<_>| {
8383
trace!(?vid);
8484
let scc = self.constraint_sccs.scc(vid);
8585
trace!(?scc);
@@ -88,11 +88,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
8888
}) {
8989
Some(region) => {
9090
let vid = self.universal_regions.to_region_vid(region);
91-
subst_regions.push(vid);
91+
arg_regions.push(vid);
9292
region
9393
}
9494
None => {
95-
subst_regions.push(vid);
95+
arg_regions.push(vid);
9696
ty::Region::new_error_with_message(
9797
infcx.tcx,
9898
concrete_type.span,
@@ -106,10 +106,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
106106
// This will ensure they get precedence when folding the regions in the concrete type.
107107
if let Some(&ci) = member_constraints.get(&opaque_type_key) {
108108
for &vid in self.member_constraints.choice_regions(ci) {
109-
to_universal_region(vid, &mut subst_regions);
109+
to_universal_region(vid, &mut arg_regions);
110110
}
111111
}
112-
debug!(?subst_regions);
112+
debug!(?arg_regions);
113113

114114
// Next, insert universal regions from args, so we can translate regions that appear
115115
// in them but are not subject to member constraints, for instance closure args.
@@ -119,18 +119,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
119119
return region;
120120
}
121121
let vid = self.to_region_vid(region);
122-
to_universal_region(vid, &mut subst_regions)
122+
to_universal_region(vid, &mut arg_regions)
123123
});
124124
debug!(?universal_args);
125-
debug!(?subst_regions);
125+
debug!(?arg_regions);
126126

127127
// Deduplicate the set of regions while keeping the chosen order.
128-
let subst_regions = subst_regions.into_iter().collect::<FxIndexSet<_>>();
129-
debug!(?subst_regions);
128+
let arg_regions = arg_regions.into_iter().collect::<FxIndexSet<_>>();
129+
debug!(?arg_regions);
130130

131131
let universal_concrete_type =
132132
infcx.tcx.fold_regions(concrete_type, |region, _| match *region {
133-
ty::ReVar(vid) => subst_regions
133+
ty::ReVar(vid) => arg_regions
134134
.iter()
135135
.find(|ur_vid| self.eval_equal(vid, **ur_vid))
136136
.and_then(|ur_vid| self.definitions[*ur_vid].external_name)

compiler/rustc_borrowck/src/type_check/input_output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2929
pub(super) fn check_signature_annotation(&mut self, body: &Body<'tcx>) {
3030
let mir_def_id = body.source.def_id().expect_local();
3131

32-
if !self.tcx().is_closure_or_coroutine(mir_def_id.to_def_id()) {
32+
if !self.tcx().is_closure_like(mir_def_id.to_def_id()) {
3333
return;
3434
}
3535

compiler/rustc_builtin_macros/src/deriving/clone.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ fn cs_clone_simple(
110110
&& !seen_type_names.insert(name)
111111
{
112112
// Already produced an assertion for this type.
113-
} else {
113+
// Anonymous structs or unions must be eliminated as they cannot be
114+
// type parameters.
115+
} else if !field.ty.kind.is_anon_adt() {
114116
// let _: AssertParamIsClone<FieldTy>;
115117
super::assert_ty_bounds(
116118
cx,

compiler/rustc_builtin_macros/src/deriving/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ fn assert_ty_bounds(
123123
span: Span,
124124
assert_path: &[Symbol],
125125
) {
126+
// Deny anonymous structs or unions to avoid wierd errors.
127+
assert!(!ty.kind.is_anon_adt(), "Anonymous structs or unions cannot be type parameters");
126128
// Generate statement `let _: assert_path<ty>;`.
127129
let span = cx.with_def_site_ctxt(span);
128130
let assert_path = cx.path_all(span, true, cx.std_path(assert_path), vec![GenericArg::Type(ty)]);

compiler/rustc_codegen_llvm/src/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
479479
// `+multivalue` feature because the purpose of the wasm abi is to match
480480
// the WebAssembly specification, which has this feature. This won't be
481481
// needed when LLVM enables this `multivalue` feature by default.
482-
if !cx.tcx.is_closure_or_coroutine(instance.def_id()) {
482+
if !cx.tcx.is_closure_like(instance.def_id()) {
483483
let abi = cx.tcx.fn_sig(instance.def_id()).skip_binder().abi();
484484
if abi == Abi::Wasm {
485485
function_features.push("+multivalue".to_string());

compiler/rustc_codegen_llvm/src/llvm_util.rs

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ pub fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> LLVMFeature<'a> {
213213
("x86", "rdrand") => LLVMFeature::new("rdrnd"),
214214
("x86", "bmi1") => LLVMFeature::new("bmi"),
215215
("x86", "cmpxchg16b") => LLVMFeature::new("cx16"),
216+
("x86", "lahfsahf") => LLVMFeature::new("sahf"),
216217
("aarch64", "rcpc2") => LLVMFeature::new("rcpc-immo"),
217218
("aarch64", "dpb") => LLVMFeature::new("ccpp"),
218219
("aarch64", "dpb2") => LLVMFeature::new("ccdp"),

0 commit comments

Comments
 (0)