Attribute documentation for used, expect, should_panic, cfg_attr, and path#158664
Attribute documentation for used, expect, should_panic, cfg_attr, and path#158664kantnero wants to merge 5 commits into
used, expect, should_panic, cfg_attr, and path#158664Conversation
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| /// Used for conditional application of attributes. | ||
| /// | ||
| /// The `cfg_attr` attribute applies one or more attributes to an item only if a given | ||
| /// configuration predicate is true. If the condition is false, the attributes are ignored. |
There was a problem hiding this comment.
| /// configuration predicate is true. If the condition is false, the attributes are ignored. |
| /// | ||
| /// ```rust | ||
| /// // This function is annotated with `#[test]` only when testing is active. | ||
| /// #[cfg_attr(test, test)] |
There was a problem hiding this comment.
It's neat, but I think it's a bit too complex (test is present twice). I suggest instead to make it a test only on linux for example. Like that we have a clear predicate, completely different than the applied attribute.
| /// } | ||
| /// ``` | ||
| /// | ||
| /// The predicate uses the same syntax as [`cfg`]. For complex conditions, you can combine |
There was a problem hiding this comment.
Does it link to the right cfg page?
There was a problem hiding this comment.
You still didn't answer this question. When you generate doc locally, what is the link of this item?
There was a problem hiding this comment.
/rust/build/x86_64-unknown-linux-gnu/doc/core/attribute.cfg.html
There was a problem hiding this comment.
I just checked it links to macro cfg
There was a problem hiding this comment.
So it's not the right link.
There was a problem hiding this comment.
Yes, I have removed it
| /// ``` | ||
| /// | ||
| /// The predicate uses the same syntax as [`cfg`]. For complex conditions, you can combine | ||
| /// `all(...)`, `any(...)`, and `not(...)` just like with [`cfg`]. |
There was a problem hiding this comment.
Add the same listing and example you added for cfg.
| /// from optimizing them away even if they are not referenced anywhere else in the code. | ||
| /// | ||
| /// It tells the compiler that an item is still in use or needed elsewhere and, because of this, | ||
| /// it is kept in the output object. |
There was a problem hiding this comment.
"output object"?
There was a problem hiding this comment.
Ah ok I got it, so instead:
| /// it is kept in the output object. | |
| /// it is kept in the generated object files (files generated by `rustc` when compiling). |
| // | ||
| /// The `ignore` attribute is used with the `test` attribute to stop the test harness from | ||
| /// executing a function as a test. The `ignore` attribute may only be applied to functions | ||
| /// annotated with the test attribute. |
There was a problem hiding this comment.
| /// annotated with the test attribute. | |
| /// annotated with the `test` attribute. |
| #[doc(attribute = "expect")] | ||
| // | ||
| /// The `#[expect]` attribute declares that a particular lint is expected to be emitted. | ||
| /// It is an equivalent of the `allow` attribute, except that it will fail compilation if the `expect`ed lint |
There was a problem hiding this comment.
It just warns by default; it doesn't fail compilation.
| /// ```rust,compile_fail | ||
| /// #[expect(unused_variables)] | ||
| /// let name = "rust-lang"; | ||
| /// println!("{name}"); | ||
| /// ```` |
There was a problem hiding this comment.
The rendering of compile_fail to the reader will be misleading since this only fails due to the harness defaults. Maybe it's worth adding an explicit #[deny(unfulfilled_lint_expectations)] so this will make sense to the reader.
There was a problem hiding this comment.
CI fails at this point that's the reason for the compile_fail
| /// // The lint group is fulfilled as the variables are unused. | ||
| /// #[expect(unused)] | ||
| /// let x = 10; | ||
| /// let y = 12; |
There was a problem hiding this comment.
The expect does not apply to let y = 12 here.
| /// println!("{name}"); | ||
| /// ```` | ||
| /// | ||
| /// In the example above the variable is used, so the `expect` is unfufilled this warning is emitted: |
There was a problem hiding this comment.
| /// In the example above the variable is used, so the `expect` is unfufilled this warning is emitted: | |
| /// In the example above the variable is used, so the `expect` is unfulfilled this warning is emitted: |
| /// #[expect(unused_variables)] | ||
| /// let name = "rust-lang"; | ||
| /// println!("{name}"); | ||
| /// ```` |
There was a problem hiding this comment.
| /// ```` | |
| /// ``` |
| /// It is an equivalent of the `allow` attribute, except that it will fail compilation if the `expect`ed lint | ||
| /// wasn't emitted. | ||
| /// | ||
| /// `expect` can be overridden by `warn`, `allow`, `deny`, and `forbid`. |
There was a problem hiding this comment.
The behavior of this should probably be discussed; i.e., it doesn't cancel the expect.
There was a problem hiding this comment.
Yeah, this still warn on compilation I should probably remove that line.
#[expect(unused)]
fn lang() {
#[allow(unused)]
let name = "rust-lang";
}| /// } | ||
| /// ``` | ||
| /// | ||
| /// For complex conditions, you can combine `all(...)`, `any(...)`, and, `not(...)`. |
There was a problem hiding this comment.
| /// For complex conditions, you can combine `all(...)`, `any(...)`, and, `not(...)`. | |
| /// For complex conditions, you can combine `all(...)`, `any(...)`, and `not(...)`. |
| /// ```rust | ||
| /// #[cfg_attr( | ||
| /// all(feature = "system", feature = "disk"), | ||
| /// doc = "For module documentation, both `system`, and `disk` need to be enabled.", |
There was a problem hiding this comment.
| /// doc = "For module documentation, both `system`, and `disk` need to be enabled.", | |
| /// doc = "For module documentation, both `system` and `disk` need to be enabled.", |
| /// | ||
| /// For more information, see the Reference on [the `cfg_attr` attribute]. | ||
| /// | ||
| /// [the `cfg` attribute]: ../reference/conditional-compilation.html#the-cfg-attribute |
There was a problem hiding this comment.
Is this unused?
|
|
||
| #[doc(attribute = "ignore")] | ||
| // | ||
| /// The `ignore` attribute is used alongside the `test` attribute to prevent this test to be run by default. |
There was a problem hiding this comment.
| /// The `ignore` attribute is used alongside the `test` attribute to prevent this test to be run by default. | |
| /// The `ignore` attribute is used alongside the `test` attribute to prevent this test from being run by default. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
|
@rustbot author Not all review comments have been addressed, e.g., https://github.com/rust-lang/rust/pull/158664/changes#r3513255509, https://github.com/rust-lang/rust/pull/158664/changes#r3557842583, etc. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…h, and ignore Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
View all comments
Attribute documentation for
used,expect,should_panic,cfg_attr, andpathusing the#[doc(attribute = "")]mechanismTested with: ./x test library/std --doc
r? @GuillaumeGomez
cc @traviscross @fmease