Skip to content

Commit 00d739b

Browse files
committed
Migrate AutoTraitWith(GenericParam/SuperTraitOrWhereClause/AssocItem)
1 parent 2aea631 commit 00d739b

File tree

3 files changed

+55
-46
lines changed

3 files changed

+55
-46
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -531,71 +531,35 @@ impl<'a> AstValidator<'a> {
531531

532532
fn deny_generic_params(&self, generics: &Generics, ident_span: Span) {
533533
if !generics.params.is_empty() {
534-
struct_span_err!(
535-
self.session,
536-
generics.span,
537-
E0567,
538-
"auto traits cannot have generic parameters"
539-
)
540-
.span_label(ident_span, "auto trait cannot have generic parameters")
541-
.span_suggestion(
542-
generics.span,
543-
"remove the parameters",
544-
"",
545-
Applicability::MachineApplicable,
546-
)
547-
.emit();
534+
self.session.emit_err(AutoTraitWithGenericParam { span: generics.span, ident_span });
548535
}
549536
}
550537

551-
fn emit_e0568(&self, span: Span, ident_span: Span) {
552-
struct_span_err!(
553-
self.session,
554-
span,
555-
E0568,
556-
"auto traits cannot have super traits or lifetime bounds"
557-
)
558-
.span_label(ident_span, "auto trait cannot have super traits or lifetime bounds")
559-
.span_suggestion(
560-
span,
561-
"remove the super traits or lifetime bounds",
562-
"",
563-
Applicability::MachineApplicable,
564-
)
565-
.emit();
566-
}
567-
568538
fn deny_super_traits(&self, bounds: &GenericBounds, ident_span: Span) {
569539
if let [.., last] = &bounds[..] {
570540
let span = ident_span.shrink_to_hi().to(last.span());
571-
self.emit_e0568(span, ident_span);
541+
self.session.emit_err(AutoTraitWithSuperTraitOrWhereClause { span, ident_span });
572542
}
573543
}
574544

575545
fn deny_where_clause(&self, where_clause: &WhereClause, ident_span: Span) {
576546
if !where_clause.predicates.is_empty() {
577-
self.emit_e0568(where_clause.span, ident_span);
547+
self.session.emit_err(AutoTraitWithSuperTraitOrWhereClause {
548+
span: where_clause.span,
549+
ident_span,
550+
});
578551
}
579552
}
580553

581554
fn deny_items(&self, trait_items: &[P<AssocItem>], ident_span: Span) {
582555
if !trait_items.is_empty() {
583556
let spans: Vec<_> = trait_items.iter().map(|i| i.ident.span).collect();
584557
let total_span = trait_items.first().unwrap().span.to(trait_items.last().unwrap().span);
585-
struct_span_err!(
586-
self.session,
558+
self.session.emit_err(AutoTraitWithAssocItem {
587559
spans,
588-
E0380,
589-
"auto traits cannot have associated items"
590-
)
591-
.span_suggestion(
592-
total_span,
593-
"remove these associated items",
594-
"",
595-
Applicability::MachineApplicable,
596-
)
597-
.span_label(ident_span, "auto trait cannot have associated items")
598-
.emit();
560+
replace_span: total_span,
561+
ident_span,
562+
});
599563
}
600564
}
601565

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,33 @@ pub struct ModFileItemNonAscii {
359359
pub span: Span,
360360
pub name: Symbol,
361361
}
362+
363+
#[derive(SessionDiagnostic)]
364+
#[diag(ast_passes::auto_trait_with_generic_param, code = "E0567")]
365+
pub struct AutoTraitWithGenericParam {
366+
#[primary_span]
367+
#[suggestion(code = "", applicability = "machine-applicable")]
368+
pub span: Span,
369+
#[label(ast_passes::ident_label)]
370+
pub ident_span: Span,
371+
}
372+
373+
#[derive(SessionDiagnostic)]
374+
#[diag(ast_passes::auto_trait_with_super_trait_or_where_clause, code = "E0568")]
375+
pub struct AutoTraitWithSuperTraitOrWhereClause {
376+
#[primary_span]
377+
pub span: Span,
378+
#[label(ast_passes::ident_label)]
379+
pub ident_span: Span,
380+
}
381+
382+
#[derive(SessionDiagnostic)]
383+
#[diag(ast_passes::auto_trait_with_assoc_item)]
384+
pub struct AutoTraitWithAssocItem {
385+
#[primary_span]
386+
pub spans: Vec<Span>,
387+
#[suggestion(code = "", applicability = "machine-applicable")]
388+
pub replace_span: Span,
389+
#[label(ast_passes::ident_label)]
390+
pub ident_span: Span,
391+
}

compiler/rustc_error_messages/locales/en-US/ast_passes.ftl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,18 @@ ast_passes_nomangle_item_non_ascii =
160160
ast_passes_mod_file_item_non_ascii =
161161
trying to load file for module `{$name}` with non-ascii identifier name
162162
.help = consider using `#[path]` attribute to specify filesystem path
163+
164+
ast_passes_auto_trait_with_generic_param =
165+
auto traits cannot have generic parameters
166+
.ident_label = auto trait cannot have generic parameters
167+
.suggestion = remove the parameters
168+
169+
ast_passes_auto_trait_with_super_trait_or_where_clause =
170+
auto traits cannot have super traits or lifetime bounds
171+
.ident_label = auto trait cannot have super traits or lifetime bounds
172+
.suggestion = remove the super traits or lifetime bounds
173+
174+
ast_passes_auto_trait_with_assoc_item =
175+
auto traits cannot have associated items
176+
.suggestion = remove these associated items
177+
.ident_label = auto trait cannot have associated items

0 commit comments

Comments
 (0)