Untitled Project
Rust support in StrictDoc

Rust support in StrictDoc

RUST-DOC-COMMENT
1. Auto-scoped relation markers in Rust docs
UID: RUST-DOC-COMMENT
RELATIONS (Child):
STATEMENT:

If a StrictDoc relation marker is inside a Rust doc comment, the marker scope shall be set to exact the item the Rust language defines as target of the containing doc comment. The @relation(scope=...) parameter shall therefore be optional and shall be ignored if provided.

1 /// @relation(REQ-1)
2 impl Foo {
3 
4     /// @relation(REQ-2)
5     fn foo() {
6     }
7 }

In the given example, the first marker shall link REQ-1 to the impl Foo implementation, highlighting lines 1 to 7. The second marker shall link REQ-2 to the fn foo() function, highlighting lines 4 to 6.

COMMENT:

Note that doc comments are syntactic sugar for doc attribute s, which shall also be supported. To figure detailed doc comment rules from the rust-lang specification it's sometimes useful to check for general attribute rules, if explicit doc comment rules are missing.

RUST-INNER-DOC-ATTR
2. Inner doc attributes
UID: RUST-INNER-DOC-ATTR
RELATIONS (Parent): RELATIONS (File):
STATEMENT:

StrictDoc shall support relation markers in inner doc attribute s.

RUST-INNER-LINE-DOC
3. Inner line docs
UID: RUST-INNER-LINE-DOC
RELATIONS (Parent): RELATIONS (File):
STATEMENT:

StrictDoc shall support auto-scoped relation relation markers in inner line docs.

RUST-INNER-BLOCK-DOC
4. Inner block docs
UID: RUST-INNER-BLOCK-DOC
RELATIONS (Parent): RELATIONS (File):
STATEMENT:

StrictDoc shall support auto-scoped relation relation markers in inner block docs.

RUST-OUTER-DOC-ATTR
5. Outer doc attributes
UID: RUST-OUTER-DOC-ATTR
RELATIONS (Parent): RELATIONS (File):
STATEMENT:

StrictDoc shall support auto-scoped relation markers in outer doc attribute s.

RUST-OUTER-LINE-DOC
6. Outer line docs
UID: RUST-OUTER-LINE-DOC
RELATIONS (Parent): RELATIONS (File):
STATEMENT:

StrictDoc shall support auto-scoped relation markers in outer line docs.

RUST-OUTER-BLOCK-DOC
7. Outer block docs
UID: RUST-OUTER-BLOCK-DOC
RELATIONS (Parent): RELATIONS (File):
STATEMENT:

StrictDoc shall support auto-scoped relation markers in outer block docs.

RUST-LINE-RANGE
8. File, line and range markers
UID: RUST-LINE-RANGE
RELATIONS (File):
STATEMENT:

It shall be possible to point to lines of Rust code by using file, line and range markers. File, line and range markers shall be parsed from regular line and block comments.

Note: File markers may also result from the inner doc comments of the top-level module.

RUST-SOURCE-NODES
9. Source nodes from doc comments
UID: RUST-SOURCE-NODES
RELATIONS (Child): RELATIONS (File):
STATEMENT:

If a Rust doc comments contains custom tags, and the containing Rust source file matches an entry in the source node configuration, StrictDoc shall create document nodes from the custom tags and automatically link the created node with the Rust item targeted by the doc comment.

RUST-FWD-REL
10. Forward relations to Rust items
UID: RUST-FWD-REL
RELATIONS (Child): RELATIONS (File):
STATEMENT:

It shall be possible to link from a requirement in SDoc to a language item in Rust code by using a FILE relation of type FUNCTION. For example

[REQUIREMENT]
UID: REQ-1
RELATIONS:
- TYPE: File
  VALUE: file.rs
  FUNCTION: file::foo

This shall work for all kinds of Rust items that have a canonical path, including const, enum, fn, mod, static, struct, trait, type, union.

RUST-FWD-REL-CANONICAL-PATH
11. Forward relation by canonical path
UID: RUST-FWD-REL-CANONICAL-PATH
RELATIONS (Parent):
STATEMENT:

The identifier for forward relations shall be the canonical path as the rustc compiler would set it when invoked for a single file like

rustc --crate-type rlib --emit=obj src/lib.rs

Note: cargo build usually result in a different canonical path, since it considers the file position relative to the crate root. Using a single file as root is a simplification, needed because StrictDoc is unaware of the Rust file and directory-based module hierarchy.

COMMENT:

The canonical path of an item can be observed with objdump -t lib.o --demangle=rust. For example, given this source file

 1 pub mod foo {
 2 
 3     pub trait Foo {
 4         fn foo(&self) {}
 5     }
 6 
 7     pub struct Bar(i32);
 8 
 9     impl Foo for Bar {
10         fn foo(&self) {}
11     }
12 }

objdump will show

<lib::foo::Bar as lib::foo::Foo>::foo

Alas, a forward relation would be

[REQUIREMENT]
UID: REQ-1
RELATIONS:
- TYPE: File
  VALUE: file.rs
  FUNCTION: <lib::foo::Bar as lib::foo::Foo>::foo
RUST-COLLAPSE-COMMENTS
12. Collapse doc comments
UID: RUST-COLLAPSE-COMMENTS
STATEMENT:

Multiple scattered doc comments should be collapsed as done by the rustdoc tool when using the collapse-docs option to determine the highlight range(s).

For example, rustdoc would collapse alle these comments into the description of fn foo()

 1 /// Some
 2 /// line
 3 
 4 /// doc,
 5 
 6 /**
 7   * and some
 8   * block dock,
 9   */
10 
11 #[doc = "and some"]
12 
13 #[doc = "doc attr."]
14 
15 fn foo() {
16 }

In the given example, the StrictDoc highlight range for the relation marker shall be from line 1 to line 16.

RUST-MARKER-DESCRIPTION
13. Rust marker descriptions
UID: RUST-MARKER-DESCRIPTION
STATEMENT:

StrictDoc should use the marker labels as rustdoc would set them in the description of a documented node.

RUST-INNER-DOC-POS
14. Allowed position for inner doc Comment
UID: RUST-INNER-DOC-POS
RELATIONS (Child):
STATEMENT:

StrictDoc shall find inner doc comments and parse markers from it in those syntax positions, and only in those positions, where the Rust language allows inner doc comments. >>> COMMENT: >>> Inner doc comments are syntactic sugar for doc attributes. Thus, the allowed positions rule for attributes applies.

RUST-INNER-DOC-POS-FN
15. Inner doc comments for functions
UID: RUST-INNER-DOC-POS-FN
RELATIONS (Parent): RELATIONS (File):
STATEMENT:

StrictDoc shall find inner doc comments in function blocks.

RUST-INNER-DOC-POS-MOD
16. Inner doc comments for modules
UID: RUST-INNER-DOC-POS-MOD
RELATIONS (File):
STATEMENT:

StrictDoc shall find inner doc comments in module blocks.

RUST-INNER-DOC-POS-EXT
17. Inner doc comments for external blocks
UID: RUST-INNER-DOC-POS-EXT
RELATIONS (File):
STATEMENT:

StrictDoc shall find inner doc comments in external blocks.

RUST-INNER-DOC-POS-IMPL
18. Inner doc comments for implementation blocks
UID: RUST-INNER-DOC-POS-IMPL
STATEMENT:

StrictDoc shall find inner doc comments in implementation blocks.

RUST-OUTER-DOC-POS
19. Allowed position for outer docs
UID: RUST-OUTER-DOC-POS
STATEMENT:

Consider allowed position s for outer doc comments:

  • All item declarations
  • Most statements
  • Block expressions, but only when they are the outer expression of an expression statement or the final expression of another block expression.
  • Enum variants, struct and union fields
  • Generic lifetime or type parameter
  • Expressions in limited situations
  • Function, closure and function pointer parameters