in which lint reasons are restricted to come last in the attribute

Vadim Petrochenkov suggested this in review ("an error? just to be
conservative"), and it turns out to be convenient from the
implementer's perspective: in the initial proposed implementation (or
`HEAD~2`, as some might prefer to call it), we were doing an entire
whole iteration over the meta items just to find the reason (before
iterating over them to set the actual lint levels). This way, we can
just peek at the end rather than adding that extra loop (or
restructuring the existing code). The RFC doesn't seem to take a
position on this, and there's some precedent for restricting things to
be at the end of a sequence (we only allow `..` at the end of a struct
pattern, even if it would be possible to let it appear anywhere in the
sequence).
This commit is contained in:
Zack M. Davis 2018-10-12 00:21:21 -07:00
parent dc0609c247
commit f90de1110d
3 changed files with 69 additions and 36 deletions

View file

@ -12,7 +12,13 @@
//~^ ERROR malformed lint attribute
#![warn(elided_lifetimes_in_paths, reason("disrespectful to ancestors", "irresponsible to heirs"))]
//~^ ERROR malformed lint attribute
#![warn(ellipsis_inclusive_range_patterns, reason)]
#![warn(ellipsis_inclusive_range_patterns, reason = "born barren", reason = "a freak growth")]
//~^ ERROR malformed lint attribute
//~| HELP reason in lint attribute must come last
#![warn(keyword_idents, reason = "root in rubble", macro_use_extern_crate)]
//~^ ERROR malformed lint attribute
//~| HELP reason in lint attribute must come last
#![warn(missing_copy_implementations, reason)]
//~^ WARN unknown lint
fn main() {}

View file

@ -32,14 +32,30 @@ error[E0452]: malformed lint attribute
LL | #![warn(elided_lifetimes_in_paths, reason("disrespectful to ancestors", "irresponsible to heirs"))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: unknown lint: `reason`
error[E0452]: malformed lint attribute
--> $DIR/reasons-erroneous.rs:15:44
|
LL | #![warn(ellipsis_inclusive_range_patterns, reason)]
| ^^^^^^
LL | #![warn(ellipsis_inclusive_range_patterns, reason = "born barren", reason = "a freak growth")]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: reason in lint attribute must come last
error[E0452]: malformed lint attribute
--> $DIR/reasons-erroneous.rs:18:25
|
LL | #![warn(keyword_idents, reason = "root in rubble", macro_use_extern_crate)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: reason in lint attribute must come last
warning: unknown lint: `reason`
--> $DIR/reasons-erroneous.rs:21:39
|
LL | #![warn(missing_copy_implementations, reason)]
| ^^^^^^
|
= note: #[warn(unknown_lints)] on by default
error: aborting due to 5 previous errors
error: aborting due to 7 previous errors
For more information about this error, try `rustc --explain E0452`.