File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1304,6 +1304,14 @@ pub(crate) struct ExpectedStatementAfterOuterAttr {
13041304 pub span : Span ,
13051305}
13061306
1307+ #[ derive( Diagnostic ) ]
1308+ #[ diag( "attribute without where predicates" ) ]
1309+ pub ( crate ) struct AttrWithoutWherePredicates {
1310+ #[ primary_span]
1311+ #[ label( "attributes are only permitted when preceding predicates" ) ]
1312+ pub span : Span ,
1313+ }
1314+
13071315#[ derive( Diagnostic ) ]
13081316#[ diag( "found a documentation comment that doesn't document anything" , code = E0585 ) ]
13091317#[ help( "doc comments must come before what they document, if a comment was intended use `//`" ) ]
Original file line number Diff line number Diff line change @@ -473,6 +473,17 @@ impl<'a> Parser<'a> {
473473 }
474474 }
475475 } else {
476+ if let [ .., last] = & attrs[ ..] {
477+ if last. is_doc_comment ( ) {
478+ this. dcx ( ) . emit_err ( errors:: DocCommentDoesNotDocumentAnything {
479+ span : last. span ,
480+ missing_comma : None ,
481+ } ) ;
482+ } else {
483+ this. dcx ( )
484+ . emit_err ( errors:: AttrWithoutWherePredicates { span : last. span } ) ;
485+ }
486+ }
476487 None
477488 } ;
478489 let predicate = kind. map ( |kind| ast:: WherePredicate {
Original file line number Diff line number Diff line change 1+ // Regression test for <https://github.com/rust-lang/rust/issues/155073>
2+
3+ #![ crate_type = "lib" ]
4+ #![ feature( where_clause_attrs) ]
5+
6+ fn f < T > ( )
7+ where
8+ T : Copy ,
9+ #[ cfg( true ) ]
10+ #[ cfg( false ) ]
11+ //~^ ERROR attribute without where predicates
12+ {
13+ }
14+
15+ fn g < T > ( )
16+ where
17+ T : Copy ,
18+ /// dangling
19+ //~^ ERROR found a documentation comment that doesn't document anything
20+ {
21+ }
Original file line number Diff line number Diff line change 1+ error: attribute without where predicates
2+ --> $DIR/where-clause-attrs-without-predicate.rs:10:5
3+ |
4+ LL | #[cfg(false)]
5+ | ^^^^^^^^^^^^^ attributes are only permitted when preceding predicates
6+
7+ error[E0585]: found a documentation comment that doesn't document anything
8+ --> $DIR/where-clause-attrs-without-predicate.rs:18:5
9+ |
10+ LL | /// dangling
11+ | ^^^^^^^^^^^^
12+ |
13+ = help: doc comments must come before what they document, if a comment was intended use `//`
14+
15+ error: aborting due to 2 previous errors
16+
17+ For more information about this error, try `rustc --explain E0585`.
You can’t perform that action at this time.
0 commit comments