mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
review comments
This commit is contained in:
parent
f483032e97
commit
29be741c9c
@ -13,7 +13,7 @@ use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
|
||||
use rustc_ast::walk_list;
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{error_code, pluralize, struct_span_err, Applicability};
|
||||
use rustc_errors::{error_code, struct_span_err, Applicability};
|
||||
use rustc_parse::validate_attr;
|
||||
use rustc_session::lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY;
|
||||
use rustc_session::lint::LintBuffer;
|
||||
@ -882,64 +882,43 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||
if is_auto == IsAuto::Yes {
|
||||
// Auto traits cannot have generics, super traits nor contain items.
|
||||
if !generics.params.is_empty() {
|
||||
let spans: Vec<_> = generics.params.iter().map(|i| i.ident.span).collect();
|
||||
let last = spans.iter().last().map(|s| *s);
|
||||
let len = spans.len();
|
||||
let mut err = struct_span_err!(
|
||||
self.session,
|
||||
spans,
|
||||
generics.span,
|
||||
E0567,
|
||||
"auto traits cannot have generic parameters"
|
||||
);
|
||||
if let Some(span) = last {
|
||||
err.span_label(
|
||||
span,
|
||||
&format!(
|
||||
"cannot have {these} generic parameter{s}",
|
||||
these = if len == 1 { "this" } else { "these" },
|
||||
s = pluralize!(len)
|
||||
),
|
||||
);
|
||||
}
|
||||
err.span_label(
|
||||
item.ident.span,
|
||||
"auto trait cannot have generic parameters",
|
||||
);
|
||||
err.span_suggestion_verbose(
|
||||
err.span_suggestion(
|
||||
generics.span,
|
||||
"remove the parameters for the auto trait to be valid",
|
||||
"remove the parameters",
|
||||
String::new(),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
err.emit();
|
||||
}
|
||||
if !bounds.is_empty() {
|
||||
let spans: Vec<_> = bounds.iter().map(|b| b.span()).collect();
|
||||
let last = spans.iter().last().map(|s| *s);
|
||||
let len = spans.len();
|
||||
let span = match &bounds[..] {
|
||||
[] => unreachable!(),
|
||||
[single] => single.span(),
|
||||
[first, .., last] => first.span().to(last.span()),
|
||||
};
|
||||
let mut err = struct_span_err!(
|
||||
self.session,
|
||||
spans,
|
||||
span,
|
||||
E0568,
|
||||
"auto traits cannot have super traits"
|
||||
);
|
||||
err.span_label(item.ident.span, "auto trait cannot have super traits");
|
||||
if let Some(span) = last {
|
||||
err.span_label(
|
||||
span,
|
||||
&format!(
|
||||
"cannot have {these} super trait{s}",
|
||||
these = if len == 1 { "this" } else { "these" },
|
||||
s = pluralize!(len)
|
||||
),
|
||||
);
|
||||
err.span_suggestion_verbose(
|
||||
generics.span.shrink_to_hi().to(span),
|
||||
"remove the super traits for the auto trait to be valid",
|
||||
String::new(),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
err.span_suggestion(
|
||||
span,
|
||||
"remove the super traits",
|
||||
String::new(),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
err.emit();
|
||||
}
|
||||
if !trait_items.is_empty() {
|
||||
|
@ -1,28 +1,18 @@
|
||||
error[E0567]: auto traits cannot have generic parameters
|
||||
--> $DIR/auto-trait-validation.rs:3:20
|
||||
--> $DIR/auto-trait-validation.rs:3:19
|
||||
|
|
||||
LL | auto trait Generic<T> {}
|
||||
| ------- ^ cannot have this generic parameter
|
||||
| -------^^^ help: remove the parameters
|
||||
| |
|
||||
| auto trait cannot have generic parameters
|
||||
|
|
||||
help: remove the parameters for the auto trait to be valid
|
||||
|
|
||||
LL | auto trait Generic {}
|
||||
| --
|
||||
|
||||
error[E0568]: auto traits cannot have super traits
|
||||
--> $DIR/auto-trait-validation.rs:5:20
|
||||
|
|
||||
LL | auto trait Bound : Copy {}
|
||||
| ----- ^^^^ cannot have this super trait
|
||||
| ----- ^^^^ help: remove the super traits
|
||||
| |
|
||||
| auto trait cannot have super traits
|
||||
|
|
||||
help: remove the super traits for the auto trait to be valid
|
||||
|
|
||||
LL | auto trait Bound {}
|
||||
| --
|
||||
|
||||
error[E0380]: auto traits cannot have methods or associated items
|
||||
--> $DIR/auto-trait-validation.rs:7:25
|
||||
|
@ -2,14 +2,9 @@ error[E0568]: auto traits cannot have super traits
|
||||
--> $DIR/traits-inductive-overflow-supertrait-oibit.rs:7:19
|
||||
|
|
||||
LL | auto trait Magic: Copy {}
|
||||
| ----- ^^^^ cannot have this super trait
|
||||
| ----- ^^^^ help: remove the super traits
|
||||
| |
|
||||
| auto trait cannot have super traits
|
||||
|
|
||||
help: remove the super traits for the auto trait to be valid
|
||||
|
|
||||
LL | auto trait Magic {}
|
||||
| --
|
||||
|
||||
error[E0277]: the trait bound `NoClone: std::marker::Copy` is not satisfied
|
||||
--> $DIR/traits-inductive-overflow-supertrait-oibit.rs:15:23
|
||||
|
@ -2,14 +2,9 @@ error[E0568]: auto traits cannot have super traits
|
||||
--> $DIR/typeck-auto-trait-no-supertraits-2.rs:3:20
|
||||
|
|
||||
LL | auto trait Magic : Sized where Option<Self> : Magic {}
|
||||
| ----- ^^^^^ cannot have this super trait
|
||||
| ----- ^^^^^ help: remove the super traits
|
||||
| |
|
||||
| auto trait cannot have super traits
|
||||
|
|
||||
help: remove the super traits for the auto trait to be valid
|
||||
|
|
||||
LL | auto trait Magic where Option<Self> : Magic {}
|
||||
| --
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -2,14 +2,9 @@ error[E0568]: auto traits cannot have super traits
|
||||
--> $DIR/typeck-auto-trait-no-supertraits.rs:27:19
|
||||
|
|
||||
LL | auto trait Magic: Copy {}
|
||||
| ----- ^^^^ cannot have this super trait
|
||||
| ----- ^^^^ help: remove the super traits
|
||||
| |
|
||||
| auto trait cannot have super traits
|
||||
|
|
||||
help: remove the super traits for the auto trait to be valid
|
||||
|
|
||||
LL | auto trait Magic {}
|
||||
| --
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user