Skip to content

Commit 34327f6

Browse files
committed
Auto merge of #88992 - Manishearth:rollup-k9hijii, r=Manishearth
Rollup of 8 pull requests Successful merges: - #87320 (Introduce -Z remap-cwd-prefix switch) - #88690 (Accept `m!{ .. }.method()` and `m!{ .. }?` statements. ) - #88775 (Revert anon union parsing) - #88841 (feat(rustc_typeck): suggest removing bad parens in `(recv.method)()`) - #88907 (Highlight the `const fn` if error happened because of a bound on the impl block) - #88915 (`Wrapping<T>` has the same layout and ABI as `T`) - #88933 (Remove implementation of `min_align_of` intrinsic) - #88951 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4aed1ab + 1da3c1d commit 34327f6

File tree

40 files changed

+275
-628
lines changed

40 files changed

+275
-628
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,10 +1902,6 @@ pub enum TyKind {
19021902
Never,
19031903
/// A tuple (`(A, B, C, D,...)`).
19041904
Tup(Vec<P<Ty>>),
1905-
/// An anonymous struct type i.e. `struct { foo: Type }`
1906-
AnonymousStruct(Vec<FieldDef>, bool),
1907-
/// An anonymous union type i.e. `union { bar: Type }`
1908-
AnonymousUnion(Vec<FieldDef>, bool),
19091905
/// A path (`module::module::...::Type`), optionally
19101906
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
19111907
///

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,6 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
484484
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
485485
}
486486
TyKind::MacCall(mac) => vis.visit_mac_call(mac),
487-
TyKind::AnonymousStruct(fields, ..) | TyKind::AnonymousUnion(fields, ..) => {
488-
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
489-
}
490487
}
491488
vis.visit_span(span);
492489
visit_lazy_tts(tokens, vis);

compiler/rustc_ast/src/visit.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,6 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
407407
TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
408408
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
409409
TyKind::MacCall(ref mac) => visitor.visit_mac_call(mac),
410-
TyKind::AnonymousStruct(ref fields, ..) | TyKind::AnonymousUnion(ref fields, ..) => {
411-
walk_list!(visitor, visit_field_def, fields)
412-
}
413410
TyKind::Never | TyKind::CVarArgs => {}
414411
}
415412
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
748748
}
749749
}
750750

751-
pub(super) fn lower_field_def(
752-
&mut self,
753-
(index, f): (usize, &FieldDef),
754-
) -> hir::FieldDef<'hir> {
751+
fn lower_field_def(&mut self, (index, f): (usize, &FieldDef)) -> hir::FieldDef<'hir> {
755752
let ty = if let TyKind::Path(ref qself, ref path) = f.ty.kind {
756753
let t = self.lower_path_ty(
757754
&f.ty,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,15 +1301,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13011301
let kind = match t.kind {
13021302
TyKind::Infer => hir::TyKind::Infer,
13031303
TyKind::Err => hir::TyKind::Err,
1304-
// FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
1305-
TyKind::AnonymousStruct(ref _fields, _recovered) => {
1306-
self.sess.struct_span_err(t.span, "anonymous structs are unimplemented").emit();
1307-
hir::TyKind::Err
1308-
}
1309-
TyKind::AnonymousUnion(ref _fields, _recovered) => {
1310-
self.sess.struct_span_err(t.span, "anonymous unions are unimplemented").emit();
1311-
hir::TyKind::Err
1312-
}
13131304
TyKind::Slice(ref ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
13141305
TyKind::Ptr(ref mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
13151306
TyKind::Rptr(ref region, ref mt) => {

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,13 @@ impl<'a> AstValidator<'a> {
193193
}
194194
}
195195
}
196-
TyKind::AnonymousStruct(ref fields, ..) | TyKind::AnonymousUnion(ref fields, ..) => {
197-
self.with_banned_assoc_ty_bound(|this| {
198-
walk_list!(this, visit_struct_field_def, fields)
199-
});
200-
}
201196
_ => visit::walk_ty(self, t),
202197
}
203198
}
204199

205200
fn visit_struct_field_def(&mut self, field: &'a FieldDef) {
206201
if let Some(ident) = field.ident {
207202
if ident.name == kw::Underscore {
208-
self.check_anonymous_field(field);
209203
self.visit_vis(&field.vis);
210204
self.visit_ident(ident);
211205
self.visit_ty_common(&field.ty);
@@ -251,66 +245,6 @@ impl<'a> AstValidator<'a> {
251245
err.emit();
252246
}
253247

254-
fn check_anonymous_field(&self, field: &FieldDef) {
255-
let FieldDef { ty, .. } = field;
256-
match &ty.kind {
257-
TyKind::AnonymousStruct(..) | TyKind::AnonymousUnion(..) => {
258-
// We already checked for `kw::Underscore` before calling this function,
259-
// so skip the check
260-
}
261-
TyKind::Path(..) => {
262-
// If the anonymous field contains a Path as type, we can't determine
263-
// if the path is a valid struct or union, so skip the check
264-
}
265-
_ => {
266-
let msg = "unnamed fields can only have struct or union types";
267-
let label = "not a struct or union";
268-
self.err_handler()
269-
.struct_span_err(field.span, msg)
270-
.span_label(ty.span, label)
271-
.emit();
272-
}
273-
}
274-
}
275-
276-
fn deny_anonymous_struct(&self, ty: &Ty) {
277-
match &ty.kind {
278-
TyKind::AnonymousStruct(..) => {
279-
self.err_handler()
280-
.struct_span_err(
281-
ty.span,
282-
"anonymous structs are not allowed outside of unnamed struct or union fields",
283-
)
284-
.span_label(ty.span, "anonymous struct declared here")
285-
.emit();
286-
}
287-
TyKind::AnonymousUnion(..) => {
288-
self.err_handler()
289-
.struct_span_err(
290-
ty.span,
291-
"anonymous unions are not allowed outside of unnamed struct or union fields",
292-
)
293-
.span_label(ty.span, "anonymous union declared here")
294-
.emit();
295-
}
296-
_ => {}
297-
}
298-
}
299-
300-
fn deny_anonymous_field(&self, field: &FieldDef) {
301-
if let Some(ident) = field.ident {
302-
if ident.name == kw::Underscore {
303-
self.err_handler()
304-
.struct_span_err(
305-
field.span,
306-
"anonymous fields are not allowed outside of structs or unions",
307-
)
308-
.span_label(ident.span, "anonymous field declared here")
309-
.emit()
310-
}
311-
}
312-
}
313-
314248
fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>, bool)) {
315249
for Param { pat, .. } in &decl.inputs {
316250
match pat.kind {
@@ -1081,7 +1015,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10811015

10821016
fn visit_ty(&mut self, ty: &'a Ty) {
10831017
self.visit_ty_common(ty);
1084-
self.deny_anonymous_struct(ty);
10851018
self.walk_ty(ty)
10861019
}
10871020

@@ -1096,7 +1029,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10961029
}
10971030

10981031
fn visit_field_def(&mut self, s: &'a FieldDef) {
1099-
self.deny_anonymous_field(s);
11001032
visit::walk_field_def(self, s)
11011033
}
11021034

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
668668
// involved, so we only emit errors where there are no other parsing errors.
669669
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
670670
}
671-
gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented");
672671

673672
// All uses of `gate_all!` below this point were added in #65742,
674673
// and subsequently disabled (with the non-early gating readded).

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -985,14 +985,6 @@ impl<'a> State<'a> {
985985
}
986986
self.pclose();
987987
}
988-
ast::TyKind::AnonymousStruct(ref fields, ..) => {
989-
self.head("struct");
990-
self.print_record_struct_body(&fields, ty.span);
991-
}
992-
ast::TyKind::AnonymousUnion(ref fields, ..) => {
993-
self.head("union");
994-
self.print_record_struct_body(&fields, ty.span);
995-
}
996988
ast::TyKind::Paren(ref typ) => {
997989
self.popen();
998990
self.print_type(typ);
@@ -1413,7 +1405,12 @@ impl<'a> State<'a> {
14131405
}
14141406
}
14151407

1416-
crate fn print_record_struct_body(&mut self, fields: &[ast::FieldDef], span: rustc_span::Span) {
1408+
crate fn print_record_struct_body(
1409+
&mut self,
1410+
fields: &Vec<ast::FieldDef>,
1411+
span: rustc_span::Span,
1412+
) {
1413+
self.nbsp();
14171414
self.bopen();
14181415
self.hardbreak_if_not_bol();
14191416

@@ -1462,7 +1459,6 @@ impl<'a> State<'a> {
14621459
}
14631460
ast::VariantData::Struct(ref fields, ..) => {
14641461
self.print_where_clause(&generics.where_clause);
1465-
self.nbsp();
14661462
self.print_record_struct_body(fields, span);
14671463
}
14681464
}

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,10 @@ crate fn eval_nullary_intrinsic<'tcx>(
6262
ensure_monomorphic_enough(tcx, tp_ty)?;
6363
ConstValue::from_bool(tp_ty.needs_drop(tcx, param_env))
6464
}
65-
sym::min_align_of | sym::pref_align_of => {
65+
sym::pref_align_of => {
6666
// Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough.
6767
let layout = tcx.layout_of(param_env.and(tp_ty)).map_err(|e| err_inval!(Layout(e)))?;
68-
let n = match name {
69-
sym::pref_align_of => layout.align.pref.bytes(),
70-
sym::min_align_of => layout.align.abi.bytes(),
71-
_ => bug!(),
72-
};
73-
ConstValue::from_machine_usize(n, &tcx)
68+
ConstValue::from_machine_usize(layout.align.pref.bytes(), &tcx)
7469
}
7570
sym::type_id => {
7671
ensure_monomorphic_enough(tcx, tp_ty)?;

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,21 @@ pub mod ty {
599599
}
600600

601601
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
602-
feature_err(
602+
let mut builder = feature_err(
603603
&ccx.tcx.sess.parse_sess,
604604
sym::const_fn_trait_bound,
605605
span,
606606
"trait bounds other than `Sized` on const fn parameters are unstable",
607-
)
607+
);
608+
609+
match ccx.fn_sig() {
610+
Some(fn_sig) if !fn_sig.span.contains(span) => {
611+
builder.span_label(fn_sig.span, "function declared as const here");
612+
}
613+
_ => {}
614+
}
615+
616+
builder
608617
}
609618
}
610619

0 commit comments

Comments
 (0)