Skip to content

Commit 29be741

Browse files
committed
review comments
1 parent f483032 commit 29be741

5 files changed

+22
-68
lines changed

src/librustc_ast_passes/ast_validation.rs

+16-37
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
1313
use rustc_ast::walk_list;
1414
use rustc_ast_pretty::pprust;
1515
use rustc_data_structures::fx::FxHashMap;
16-
use rustc_errors::{error_code, pluralize, struct_span_err, Applicability};
16+
use rustc_errors::{error_code, struct_span_err, Applicability};
1717
use rustc_parse::validate_attr;
1818
use rustc_session::lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY;
1919
use rustc_session::lint::LintBuffer;
@@ -882,64 +882,43 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
882882
if is_auto == IsAuto::Yes {
883883
// Auto traits cannot have generics, super traits nor contain items.
884884
if !generics.params.is_empty() {
885-
let spans: Vec<_> = generics.params.iter().map(|i| i.ident.span).collect();
886-
let last = spans.iter().last().map(|s| *s);
887-
let len = spans.len();
888885
let mut err = struct_span_err!(
889886
self.session,
890-
spans,
887+
generics.span,
891888
E0567,
892889
"auto traits cannot have generic parameters"
893890
);
894-
if let Some(span) = last {
895-
err.span_label(
896-
span,
897-
&format!(
898-
"cannot have {these} generic parameter{s}",
899-
these = if len == 1 { "this" } else { "these" },
900-
s = pluralize!(len)
901-
),
902-
);
903-
}
904891
err.span_label(
905892
item.ident.span,
906893
"auto trait cannot have generic parameters",
907894
);
908-
err.span_suggestion_verbose(
895+
err.span_suggestion(
909896
generics.span,
910-
"remove the parameters for the auto trait to be valid",
897+
"remove the parameters",
911898
String::new(),
912899
Applicability::MachineApplicable,
913900
);
914901
err.emit();
915902
}
916903
if !bounds.is_empty() {
917-
let spans: Vec<_> = bounds.iter().map(|b| b.span()).collect();
918-
let last = spans.iter().last().map(|s| *s);
919-
let len = spans.len();
904+
let span = match &bounds[..] {
905+
[] => unreachable!(),
906+
[single] => single.span(),
907+
[first, .., last] => first.span().to(last.span()),
908+
};
920909
let mut err = struct_span_err!(
921910
self.session,
922-
spans,
911+
span,
923912
E0568,
924913
"auto traits cannot have super traits"
925914
);
926915
err.span_label(item.ident.span, "auto trait cannot have super traits");
927-
if let Some(span) = last {
928-
err.span_label(
929-
span,
930-
&format!(
931-
"cannot have {these} super trait{s}",
932-
these = if len == 1 { "this" } else { "these" },
933-
s = pluralize!(len)
934-
),
935-
);
936-
err.span_suggestion_verbose(
937-
generics.span.shrink_to_hi().to(span),
938-
"remove the super traits for the auto trait to be valid",
939-
String::new(),
940-
Applicability::MachineApplicable,
941-
);
942-
}
916+
err.span_suggestion(
917+
span,
918+
"remove the super traits",
919+
String::new(),
920+
Applicability::MachineApplicable,
921+
);
943922
err.emit();
944923
}
945924
if !trait_items.is_empty() {

src/test/ui/auto-trait-validation.stderr

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
error[E0567]: auto traits cannot have generic parameters
2-
--> $DIR/auto-trait-validation.rs:3:20
2+
--> $DIR/auto-trait-validation.rs:3:19
33
|
44
LL | auto trait Generic<T> {}
5-
| ------- ^ cannot have this generic parameter
5+
| -------^^^ help: remove the parameters
66
| |
77
| auto trait cannot have generic parameters
8-
|
9-
help: remove the parameters for the auto trait to be valid
10-
|
11-
LL | auto trait Generic {}
12-
| --
138

149
error[E0568]: auto traits cannot have super traits
1510
--> $DIR/auto-trait-validation.rs:5:20
1611
|
1712
LL | auto trait Bound : Copy {}
18-
| ----- ^^^^ cannot have this super trait
13+
| ----- ^^^^ help: remove the super traits
1914
| |
2015
| auto trait cannot have super traits
21-
|
22-
help: remove the super traits for the auto trait to be valid
23-
|
24-
LL | auto trait Bound {}
25-
| --
2616

2717
error[E0380]: auto traits cannot have methods or associated items
2818
--> $DIR/auto-trait-validation.rs:7:25

src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ error[E0568]: auto traits cannot have super traits
22
--> $DIR/traits-inductive-overflow-supertrait-oibit.rs:7:19
33
|
44
LL | auto trait Magic: Copy {}
5-
| ----- ^^^^ cannot have this super trait
5+
| ----- ^^^^ help: remove the super traits
66
| |
77
| auto trait cannot have super traits
8-
|
9-
help: remove the super traits for the auto trait to be valid
10-
|
11-
LL | auto trait Magic {}
12-
| --
138

149
error[E0277]: the trait bound `NoClone: std::marker::Copy` is not satisfied
1510
--> $DIR/traits-inductive-overflow-supertrait-oibit.rs:15:23

src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ error[E0568]: auto traits cannot have super traits
22
--> $DIR/typeck-auto-trait-no-supertraits-2.rs:3:20
33
|
44
LL | auto trait Magic : Sized where Option<Self> : Magic {}
5-
| ----- ^^^^^ cannot have this super trait
5+
| ----- ^^^^^ help: remove the super traits
66
| |
77
| auto trait cannot have super traits
8-
|
9-
help: remove the super traits for the auto trait to be valid
10-
|
11-
LL | auto trait Magic where Option<Self> : Magic {}
12-
| --
138

149
error: aborting due to previous error
1510

src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ error[E0568]: auto traits cannot have super traits
22
--> $DIR/typeck-auto-trait-no-supertraits.rs:27:19
33
|
44
LL | auto trait Magic: Copy {}
5-
| ----- ^^^^ cannot have this super trait
5+
| ----- ^^^^ help: remove the super traits
66
| |
77
| auto trait cannot have super traits
8-
|
9-
help: remove the super traits for the auto trait to be valid
10-
|
11-
LL | auto trait Magic {}
12-
| --
138

149
error: aborting due to previous error
1510

0 commit comments

Comments
 (0)