Skip to content

Commit

Permalink
feat: Allow floating doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Dec 4, 2024
1 parent efa685e commit d10a620
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 44 deletions.
16 changes: 7 additions & 9 deletions impl/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ impl Parse for AstErrorSet {
fn parse(input: ParseStream) -> Result<Self> {
let mut set_items = Vec::new();
while !input.is_empty() {
let set_item = input.parse::<AstErrorDeclaration>()?;
let attributes = input.call(Attribute::parse_outer)?;
if input.is_empty() {
return Ok(AstErrorSet { set_items });
}
let mut set_item = input.parse::<AstErrorDeclaration>()?;
set_item.attributes = attributes;
set_items.push(set_item);
if input.parse::<token::Semi>().is_err() {
return Err(syn::Error::new(
Expand All @@ -41,13 +46,6 @@ pub(crate) struct AstErrorDeclaration {

impl Parse for AstErrorDeclaration {
fn parse(input: ParseStream) -> Result<Self> {
let attributes = input.call(Attribute::parse_outer)?;
if input.is_empty() {
return Err(syn::Error::new(
input.span(),
"Expected error definition to be next after attributes. You may a dangling doc comment.",
));
}
let save_position = input.fork();
let error_name: Ident = input.parse()?;
if !input.peek(syn::Token![=]) && !input.peek(syn::Token![<]) {
Expand Down Expand Up @@ -94,7 +92,7 @@ impl Parse for AstErrorDeclaration {
));
}
return Ok(AstErrorDeclaration {
attributes,
attributes: Vec::new(),
error_name,
generics,
parts,
Expand Down
30 changes: 24 additions & 6 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,30 @@ pub mod generics {
}
}

#[cfg(test)]
pub mod floating_attributes {
use std::fmt::Debug;

use error_set::error_set;

error_set! {
/// Doc
// comment
/// Doc
X = {
A,
B
};
/// Doc
// comment
/// Doc
}

#[test]
fn test() {
}
}

#[cfg(test)]
pub mod should_not_compile_tests {

Expand All @@ -733,12 +757,6 @@ pub mod should_not_compile_tests {
t.compile_fail("tests/trybuild/error_sources_of_diffrent_names.rs");
}

#[test]
fn floating_attributes() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/trybuild/floating_attributes.rs");
}

#[test]
fn multiple_different_generics() {
let t = trybuild::TestCases::new();
Expand Down
16 changes: 0 additions & 16 deletions tests/trybuild/floating_attributes.rs

This file was deleted.

13 changes: 0 additions & 13 deletions tests/trybuild/floating_attributes.stderr

This file was deleted.

0 comments on commit d10a620

Please sign in to comment.