Skip to content

Commit adb16d5

Browse files
committed
Auto merge of rust-lang#3038 - rust-lang:rustup-2023-08-26, r=RalfJung
Automatic sync from rustc
2 parents 0154f6c + ec91a23 commit adb16d5

File tree

611 files changed

+8939
-3434
lines changed

Some content is hidden

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

611 files changed

+8939
-3434
lines changed

Cargo.lock

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,14 @@
22
# It is not intended for manual editing.
33
version = 3
44

5-
[[package]]
6-
name = "addr2line"
7-
version = "0.20.0"
8-
source = "registry+https://github.com/rust-lang/crates.io-index"
9-
checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3"
10-
dependencies = [
11-
"gimli 0.27.3",
12-
]
13-
145
[[package]]
156
name = "addr2line"
167
version = "0.21.0"
178
source = "registry+https://github.com/rust-lang/crates.io-index"
189
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
1910
dependencies = [
2011
"compiler_builtins",
21-
"gimli 0.28.0",
12+
"gimli",
2213
"rustc-std-workspace-alloc",
2314
"rustc-std-workspace-core",
2415
]
@@ -180,7 +171,7 @@ version = "0.1.5"
180171
source = "registry+https://github.com/rust-lang/crates.io-index"
181172
checksum = "9792d37ca5173d7e7f4fe453739a0671d0557915a030a383d6b866476bbc3e71"
182173
dependencies = [
183-
"object 0.32.0",
174+
"object",
184175
]
185176

186177
[[package]]
@@ -246,16 +237,16 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
246237

247238
[[package]]
248239
name = "backtrace"
249-
version = "0.3.68"
240+
version = "0.3.69"
250241
source = "registry+https://github.com/rust-lang/crates.io-index"
251-
checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12"
242+
checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
252243
dependencies = [
253-
"addr2line 0.20.0",
244+
"addr2line",
254245
"cc",
255246
"cfg-if",
256247
"libc",
257248
"miniz_oxide",
258-
"object 0.31.1",
249+
"object",
259250
"rustc-demangle",
260251
]
261252

@@ -1435,12 +1426,6 @@ dependencies = [
14351426
"wasi",
14361427
]
14371428

1438-
[[package]]
1439-
name = "gimli"
1440-
version = "0.27.3"
1441-
source = "registry+https://github.com/rust-lang/crates.io-index"
1442-
checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e"
1443-
14441429
[[package]]
14451430
name = "gimli"
14461431
version = "0.28.0"
@@ -2430,15 +2415,6 @@ dependencies = [
24302415
"libc",
24312416
]
24322417

2433-
[[package]]
2434-
name = "object"
2435-
version = "0.31.1"
2436-
source = "registry+https://github.com/rust-lang/crates.io-index"
2437-
checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1"
2438-
dependencies = [
2439-
"memchr",
2440-
]
2441-
24422418
[[package]]
24432419
name = "object"
24442420
version = "0.32.0"
@@ -3357,7 +3333,7 @@ dependencies = [
33573333
"cstr",
33583334
"libc",
33593335
"measureme",
3360-
"object 0.32.0",
3336+
"object",
33613337
"rustc-demangle",
33623338
"rustc_ast",
33633339
"rustc_attr",
@@ -3393,7 +3369,7 @@ dependencies = [
33933369
"itertools",
33943370
"jobserver",
33953371
"libc",
3396-
"object 0.32.0",
3372+
"object",
33973373
"pathdiff",
33983374
"regex",
33993375
"rustc_arena",
@@ -4327,7 +4303,7 @@ name = "rustc_target"
43274303
version = "0.0.0"
43284304
dependencies = [
43294305
"bitflags 1.3.2",
4330-
"object 0.32.0",
4306+
"object",
43314307
"rustc_abi",
43324308
"rustc_data_structures",
43334309
"rustc_feature",
@@ -4856,7 +4832,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
48564832
name = "std"
48574833
version = "0.0.0"
48584834
dependencies = [
4859-
"addr2line 0.21.0",
4835+
"addr2line",
48604836
"alloc",
48614837
"cfg-if",
48624838
"compiler_builtins",
@@ -4867,7 +4843,7 @@ dependencies = [
48674843
"hermit-abi 0.3.2",
48684844
"libc",
48694845
"miniz_oxide",
4870-
"object 0.32.0",
4846+
"object",
48714847
"panic_abort",
48724848
"panic_unwind",
48734849
"profiler_builtins",
@@ -5171,9 +5147,9 @@ version = "0.7.0"
51715147
source = "registry+https://github.com/rust-lang/crates.io-index"
51725148
checksum = "4db52ee8fec06e119b692ef3dd2c4cf621a99204c1b8c47407870ed050305b9b"
51735149
dependencies = [
5174-
"gimli 0.28.0",
5150+
"gimli",
51755151
"hashbrown 0.14.0",
5176-
"object 0.32.0",
5152+
"object",
51775153
"tracing",
51785154
]
51795155

RELEASES.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ Rustdoc
6565
Stabilized APIs
6666
---------------
6767

68-
- [`impl<T: Send> Sync for mpsc::Sender<T>`](https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html#impl-Sync-for-Sender%3CT%3E)
69-
- [`impl TryFrom<&OsStr> for &str`](https://doc.rust-lang.org/nightly/std/primitive.str.html#impl-TryFrom%3C%26'a+OsStr%3E-for-%26'a+str)
70-
- [`String::leak`](https://doc.rust-lang.org/nightly/alloc/string/struct.String.html#method.leak)
68+
- [`impl<T: Send> Sync for mpsc::Sender<T>`](https://doc.rust-lang.org/stable/std/sync/mpsc/struct.Sender.html#impl-Sync-for-Sender%3CT%3E)
69+
- [`impl TryFrom<&OsStr> for &str`](https://doc.rust-lang.org/stable/std/primitive.str.html#impl-TryFrom%3C%26'a+OsStr%3E-for-%26'a+str)
70+
- [`String::leak`](https://doc.rust-lang.org/stable/alloc/string/struct.String.html#method.leak)
7171

7272
These APIs are now stable in const contexts:
7373

74-
- [`CStr::from_bytes_with_nul`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul)
75-
- [`CStr::to_bytes`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul)
76-
- [`CStr::to_bytes_with_nul`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul)
77-
- [`CStr::to_str`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul)
74+
- [`CStr::from_bytes_with_nul`](https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.from_bytes_with_nul)
75+
- [`CStr::to_bytes`](https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.to_bytes)
76+
- [`CStr::to_bytes_with_nul`](https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.to_bytes_with_nul)
77+
- [`CStr::to_str`](https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.to_str)
7878

7979
<a id="1.72.0-Cargo"></a>
8080

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![cfg_attr(feature = "nightly", feature(step_trait, rustc_attrs, min_specialization))]
2-
#![cfg_attr(all(not(bootstrap), feature = "nightly"), allow(internal_features))]
2+
#![cfg_attr(feature = "nightly", allow(internal_features))]
33

44
use std::fmt;
55
#[cfg(feature = "nightly")]

compiler/rustc_arena/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#![deny(unsafe_op_in_unsafe_fn)]
2525
#![deny(rustc::untranslatable_diagnostic)]
2626
#![deny(rustc::diagnostic_outside_of_impl)]
27-
#![cfg_attr(not(bootstrap), allow(internal_features))]
27+
#![allow(internal_features)]
2828
#![allow(clippy::mut_from_ref)] // Arena allocators are one of the places where this pattern is fine.
2929

3030
use smallvec::SmallVec;

compiler/rustc_ast/src/ast.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,10 @@ pub enum TyKind {
20922092
Never,
20932093
/// A tuple (`(A, B, C, D,...)`).
20942094
Tup(ThinVec<P<Ty>>),
2095+
/// An anonymous struct type i.e. `struct { foo: Type }`
2096+
AnonStruct(ThinVec<FieldDef>),
2097+
/// An anonymous union type i.e. `union { bar: Type }`
2098+
AnonUnion(ThinVec<FieldDef>),
20952099
/// A path (`module::module::...::Type`), optionally
20962100
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
20972101
///

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,9 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
510510
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
511511
}
512512
TyKind::MacCall(mac) => vis.visit_mac_call(mac),
513+
TyKind::AnonStruct(fields) | TyKind::AnonUnion(fields) => {
514+
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
515+
}
513516
}
514517
vis.visit_span(span);
515518
visit_lazy_tts(tokens, vis);

compiler/rustc_ast/src/token.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ impl Token {
486486
Lt | BinOp(Shl) | // associated path
487487
ModSep => true, // global path
488488
Interpolated(ref nt) => matches!(**nt, NtTy(..) | NtPath(..)),
489+
// For anonymous structs or unions, which only appear in specific positions
490+
// (type of struct fields or union fields), we don't consider them as regular types
489491
_ => false,
490492
}
491493
}

compiler/rustc_ast/src/visit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
438438
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
439439
TyKind::MacCall(mac) => visitor.visit_mac_call(mac),
440440
TyKind::Never | TyKind::CVarArgs => {}
441+
TyKind::AnonStruct(ref fields, ..) | TyKind::AnonUnion(ref fields, ..) => {
442+
walk_list!(visitor, visit_field_def, fields)
443+
}
441444
}
442445
}
443446

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12931293
TyKind::Err => {
12941294
hir::TyKind::Err(self.tcx.sess.delay_span_bug(t.span, "TyKind::Err lowered"))
12951295
}
1296+
// FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
1297+
#[allow(rustc::untranslatable_diagnostic)]
1298+
#[allow(rustc::diagnostic_outside_of_impl)]
1299+
TyKind::AnonStruct(ref _fields) => hir::TyKind::Err(
1300+
self.tcx.sess.span_err(t.span, "anonymous structs are unimplemented"),
1301+
),
1302+
// FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
1303+
#[allow(rustc::untranslatable_diagnostic)]
1304+
#[allow(rustc::diagnostic_outside_of_impl)]
1305+
TyKind::AnonUnion(ref _fields) => hir::TyKind::Err(
1306+
self.tcx.sess.span_err(t.span, "anonymous unions are unimplemented"),
1307+
),
12961308
TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
12971309
TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
12981310
TyKind::Ref(region, mt) => {

compiler/rustc_ast_passes/messages.ftl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
ast_passes_anon_struct_or_union_not_allowed =
2+
anonymous {$struct_or_union}s are not allowed outside of unnamed struct or union fields
3+
.label = anonymous {$struct_or_union} declared here
4+
15
ast_passes_assoc_const_without_body =
26
associated constant in `impl` without body
37
.suggestion = provide a definition for the constant
@@ -162,6 +166,14 @@ ast_passes_inherent_cannot_be = inherent impls cannot be {$annotation}
162166
ast_passes_invalid_label =
163167
invalid label name `{$name}`
164168
169+
ast_passes_invalid_unnamed_field =
170+
unnamed fields are not allowed outside of structs or unions
171+
.label = unnamed field declared here
172+
173+
ast_passes_invalid_unnamed_field_ty =
174+
unnamed fields can only have struct or union types
175+
.label = not a struct or union
176+
165177
ast_passes_item_underscore = `{$kind}` items in this context need a name
166178
.label = `_` is not a valid name for this `{$kind}` item
167179

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,27 @@ impl<'a> AstValidator<'a> {
223223
}
224224
}
225225
}
226+
TyKind::AnonStruct(ref fields, ..) | TyKind::AnonUnion(ref fields, ..) => {
227+
walk_list!(self, visit_field_def, fields)
228+
}
226229
_ => visit::walk_ty(self, t),
227230
}
228231
}
229232

233+
fn visit_struct_field_def(&mut self, field: &'a FieldDef) {
234+
if let Some(ident) = field.ident &&
235+
ident.name == kw::Underscore {
236+
self.check_unnamed_field_ty(&field.ty, ident.span);
237+
self.visit_vis(&field.vis);
238+
self.visit_ident(ident);
239+
self.visit_ty_common(&field.ty);
240+
self.walk_ty(&field.ty);
241+
walk_list!(self, visit_attribute, &field.attrs);
242+
} else {
243+
self.visit_field_def(field);
244+
}
245+
}
246+
230247
fn err_handler(&self) -> &rustc_errors::Handler {
231248
&self.session.diagnostic()
232249
}
@@ -264,6 +281,42 @@ impl<'a> AstValidator<'a> {
264281
}
265282
}
266283

284+
fn check_unnamed_field_ty(&self, ty: &Ty, span: Span) {
285+
if matches!(
286+
&ty.kind,
287+
// We already checked for `kw::Underscore` before calling this function,
288+
// so skip the check
289+
TyKind::AnonStruct(..) | TyKind::AnonUnion(..)
290+
// If the anonymous field contains a Path as type, we can't determine
291+
// if the path is a valid struct or union, so skip the check
292+
| TyKind::Path(..)
293+
) {
294+
return;
295+
}
296+
self.err_handler().emit_err(errors::InvalidUnnamedFieldTy { span, ty_span: ty.span });
297+
}
298+
299+
fn deny_anon_struct_or_union(&self, ty: &Ty) {
300+
let struct_or_union = match &ty.kind {
301+
TyKind::AnonStruct(..) => "struct",
302+
TyKind::AnonUnion(..) => "union",
303+
_ => return,
304+
};
305+
self.err_handler()
306+
.emit_err(errors::AnonStructOrUnionNotAllowed { struct_or_union, span: ty.span });
307+
}
308+
309+
fn deny_unnamed_field(&self, field: &FieldDef) {
310+
if let Some(ident) = field.ident &&
311+
ident.name == kw::Underscore {
312+
self.err_handler()
313+
.emit_err(errors::InvalidUnnamedField {
314+
span: field.span,
315+
ident_span: ident.span
316+
});
317+
}
318+
}
319+
267320
fn check_trait_fn_not_const(&self, constness: Const) {
268321
if let Const::Yes(span) = constness {
269322
self.session.emit_err(errors::TraitFnConst { span });
@@ -789,6 +842,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
789842

790843
fn visit_ty(&mut self, ty: &'a Ty) {
791844
self.visit_ty_common(ty);
845+
self.deny_anon_struct_or_union(ty);
792846
self.walk_ty(ty)
793847
}
794848

@@ -803,6 +857,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
803857
}
804858

805859
fn visit_field_def(&mut self, field: &'a FieldDef) {
860+
self.deny_unnamed_field(field);
806861
visit::walk_field_def(self, field)
807862
}
808863

@@ -995,10 +1050,38 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
9951050
self.check_mod_file_item_asciionly(item.ident);
9961051
}
9971052
}
998-
ItemKind::Union(vdata, ..) => {
1053+
ItemKind::Struct(vdata, generics) => match vdata {
1054+
// Duplicating the `Visitor` logic allows catching all cases
1055+
// of `Anonymous(Struct, Union)` outside of a field struct or union.
1056+
//
1057+
// Inside `visit_ty` the validator catches every `Anonymous(Struct, Union)` it
1058+
// encounters, and only on `ItemKind::Struct` and `ItemKind::Union`
1059+
// it uses `visit_ty_common`, which doesn't contain that specific check.
1060+
VariantData::Struct(fields, ..) => {
1061+
self.visit_vis(&item.vis);
1062+
self.visit_ident(item.ident);
1063+
self.visit_generics(generics);
1064+
walk_list!(self, visit_struct_field_def, fields);
1065+
walk_list!(self, visit_attribute, &item.attrs);
1066+
return;
1067+
}
1068+
_ => {}
1069+
},
1070+
ItemKind::Union(vdata, generics) => {
9991071
if vdata.fields().is_empty() {
10001072
self.err_handler().emit_err(errors::FieldlessUnion { span: item.span });
10011073
}
1074+
match vdata {
1075+
VariantData::Struct(fields, ..) => {
1076+
self.visit_vis(&item.vis);
1077+
self.visit_ident(item.ident);
1078+
self.visit_generics(generics);
1079+
walk_list!(self, visit_struct_field_def, fields);
1080+
walk_list!(self, visit_attribute, &item.attrs);
1081+
return;
1082+
}
1083+
_ => {}
1084+
}
10021085
}
10031086
ItemKind::Const(box ConstItem { defaultness, expr: None, .. }) => {
10041087
self.check_defaultness(item.span, *defaultness);

0 commit comments

Comments
 (0)