Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,14 @@ pub(crate) struct ExpectedStatementAfterOuterAttr {
pub span: Span,
}

#[derive(Diagnostic)]
#[diag("attribute without where predicates")]
pub(crate) struct AttrWithoutWherePredicates {
#[primary_span]
#[label("attributes are only permitted when preceding predicates")]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag("found a documentation comment that doesn't document anything", code = E0585)]
#[help("doc comments must come before what they document, if a comment was intended use `//`")]
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_parse/src/parser/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,17 @@ impl<'a> Parser<'a> {
}
}
} else {
if let [.., last] = &attrs[..] {
if last.is_doc_comment() {
this.dcx().emit_err(errors::DocCommentDoesNotDocumentAnything {
span: last.span,
missing_comma: None,
});
} else {
this.dcx()
.emit_err(errors::AttrWithoutWherePredicates { span: last.span });
}
}
None
};
let predicate = kind.map(|kind| ast::WherePredicate {
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/parser/where-clause-attrs-without-predicate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Regression test for <https://github.com/rust-lang/rust/issues/155073>

#![crate_type = "lib"]
#![feature(where_clause_attrs)]

fn f<T>()
where
T: Copy,
#[cfg(true)]
#[cfg(false)]
//~^ ERROR attribute without where predicates
{
}

fn g<T>()
where
T: Copy,
/// dangling
//~^ ERROR found a documentation comment that doesn't document anything
{
}
17 changes: 17 additions & 0 deletions tests/ui/parser/where-clause-attrs-without-predicate.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: attribute without where predicates
--> $DIR/where-clause-attrs-without-predicate.rs:10:5
|
LL | #[cfg(false)]
| ^^^^^^^^^^^^^ attributes are only permitted when preceding predicates

error[E0585]: found a documentation comment that doesn't document anything
--> $DIR/where-clause-attrs-without-predicate.rs:18:5
|
LL | /// dangling
| ^^^^^^^^^^^^
|
= help: doc comments must come before what they document, if a comment was intended use `//`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0585`.
Loading