about summary refs log tree commit diff
path: root/src/test/ui/attributes
AgeCommit message (Collapse)AuthorLines
2021-09-25Move malformed attribute code to a function and fix inner attribute suggestion.Eric Huss-2/+2
Moving to a dedicated function in preparation for other validation. The suggestion given didn't consider if it was an inner attribute.
2021-09-23Rollup merge of #89023 - Wardenfar:issue-85066, r=nagisaJubilee-0/+18
Resolve issue : Somewhat confusing error with extended_key_value_attributes Fixes #85066
2021-09-21Use ZST for fmt unsafetyCameron Steffen-10/+6
This allows the format_args! macro to keep the pre-expansion code out of the unsafe block without doing gymnastics with nested `match` expressions. This reduces codegen.
2021-09-19Resolve issue 85066Theo-0/+18
Fix : use struct_dummy Fix different os messages
2021-08-24Auto merge of #87739 - Aaron1011:remove-used-attrs, r=wesleywiserbors-17/+3
Remove `Session.used_attrs` and move logic to `CheckAttrVisitor` Instead of updating global state to mark attributes as used, we now explicitly emit a warning when an attribute is used in an unsupported position. As a side effect, we are to emit more detailed warning messages (instead of just a generic "unused" message). `Session.check_name` is removed, since its only purpose was to mark the attribute as used. All of the callers are modified to use `Attribute.has_name` Additionally, `AttributeType::AssumedUsed` is removed - an 'assumed used' attribute is implemented by simply not performing any checks in `CheckAttrVisitor` for a particular attribute. We no longer emit unused attribute warnings for the `#[rustc_dummy]` attribute - it's an internal attribute used for tests, so it doesn't mark sense to treat it as 'unused'. With this commit, a large source of global untracked state is removed.
2021-08-21Remove `Session.used_attrs` and move logic to `CheckAttrVisitor`Aaron Hill-17/+3
Instead of updating global state to mark attributes as used, we now explicitly emit a warning when an attribute is used in an unsupported position. As a side effect, we are to emit more detailed warning messages (instead of just a generic "unused" message). `Session.check_name` is removed, since its only purpose was to mark the attribute as used. All of the callers are modified to use `Attribute.has_name` Additionally, `AttributeType::AssumedUsed` is removed - an 'assumed used' attribute is implemented by simply not performing any checks in `CheckAttrVisitor` for a particular attribute. We no longer emit unused attribute warnings for the `#[rustc_dummy]` attribute - it's an internal attribute used for tests, so it doesn't mark sense to treat it as 'unused'. With this commit, a large source of global untracked state is removed.
2021-08-16Make Arguments constructors unsafeCameron Steffen-6/+10
2021-08-11Modify structured suggestion outputEsteban Küber-1/+1
* On suggestions that include deletions, use a diff inspired output format * When suggesting addition, use `+` as underline * Color highlight modified span
2021-07-31Fix invalid suggestions for non-ASCII characters in byte constantsFabian Wolff-4/+6
2021-07-09Enhance well-formedness checks for `#[repr(...)]` attributesFabian Wolff-2/+16
2021-05-18Stabilize extended_key_value_attributesJoshua Nelson-2/+1
# Stabilization report ## Summary This stabilizes using macro expansion in key-value attributes, like so: ```rust #[doc = include_str!("my_doc.md")] struct S; #[path = concat!(env!("OUT_DIR"), "/generated.rs")] mod m; ``` See the changes to the reference for details on what macros are allowed; see Petrochenkov's excellent blog post [on internals](https://internals.rust-lang.org/t/macro-expansion-points-in-attributes/11455) for alternatives that were considered and rejected ("why accept no more and no less?") This has been available on nightly since 1.50 with no major issues. ## Notes ### Accepted syntax The parser accepts arbitrary Rust expressions in this position, but any expression other than a macro invocation will ultimately lead to an error because it is not expected by the built-in expression forms (e.g., `#[doc]`). Note that decorators and the like may be able to observe other expression forms. ### Expansion ordering Expansion of macro expressions in "inert" attributes occurs after decorators have executed, analogously to macro expressions appearing in the function body or other parts of decorator input. There is currently no way for decorators to accept macros in key-value position if macro expansion must be performed before the decorator executes (if the macro can simply be copied into the output for later expansion, that can work). ## Test cases - https://github.com/rust-lang/rust/blob/master/src/test/ui/attributes/key-value-expansion-on-mac.rs - https://github.com/rust-lang/rust/blob/master/src/test/rustdoc/external-doc.rs The feature has also been dogfooded extensively in the compiler and standard library: - https://github.com/rust-lang/rust/pull/83329 - https://github.com/rust-lang/rust/pull/83230 - https://github.com/rust-lang/rust/pull/82641 - https://github.com/rust-lang/rust/pull/80534 ## Implementation history - Initial proposal: https://github.com/rust-lang/rust/issues/55414#issuecomment-554005412 - Experiment to see how much code it would break: https://github.com/rust-lang/rust/pull/67121 - Preliminary work to restrict expansion that would conflict with this feature: https://github.com/rust-lang/rust/pull/77271 - Initial implementation: https://github.com/rust-lang/rust/pull/78837 - Fix for an ICE: https://github.com/rust-lang/rust/pull/80563 ## Unresolved Questions ~~https://github.com/rust-lang/rust/pull/83366#issuecomment-805180738 listed some concerns, but they have been resolved as of this final report.~~ ## Additional Information There are two workarounds that have a similar effect for `#[doc]` attributes on nightly. One is to emulate this behavior by using a limited version of this feature that was stabilized for historical reasons: ```rust macro_rules! forward_inner_docs { ($e:expr => $i:item) => { #[doc = $e] $i }; } forward_inner_docs!(include_str!("lib.rs") => struct S {}); ``` This also works for other attributes (like `#[path = concat!(...)]`). The other is to use `doc(include)`: ```rust #![feature(external_doc)] #[doc(include = "lib.rs")] struct S {} ``` The first works, but is non-trivial for people to discover, and difficult to read and maintain. The second is a strange special-case for a particular use of the macro. This generalizes it to work for any use case, not just including files. I plan to remove `doc(include)` when this is stabilized. The `forward_inner_docs` workaround will still compile without warnings, but I expect it to be used less once it's no longer necessary.
2021-05-12Show macro name in 'this error originates in macro' messageAaron Hill-3/+3
When there are multiple macros in use, it can be difficult to tell which one was responsible for producing an error.
2021-05-08Error on conflicting `#[doc(inline)]`/`#[doc(no_inline)]` attributesLeSeulArtichaut-37/+110
2021-04-05Allow specifying alignment for functionsWesley Norris-14/+1
2021-03-14Tweak diagnosticsCamelid-8/+8
- Tweak lint message - Display multi-segment paths correctly
2021-03-13Add hyphen to "crate level"Camelid-2/+2
"crate level attribute" -> "crate-level attribute"
2021-03-13Add another test caseCamelid-1/+24
2021-03-13Report error for each invalid nested attributeCamelid-1/+12
2021-03-13Lint non-meta doc attributesCamelid-1/+27
E.g., `#[doc(123)]`.
2021-03-05Rollup merge of #82708 - GuillaumeGomez:doc-test-attr-check, r=ManishearthGuillaume Gomez-8/+47
Warn on `#![doc(test(...))]` on items other than the crate root and use future incompatible lint Part of #82672. This PR does multiple things: * Create a new `INVALID_DOC_ATTRIBUTE` lint which is also "future incompatible", allowing us to use it as a warning for the moment until it turns (eventually) into a hard error. * Use this link when `#![doc(test(...))]` isn't used at the crate level. * Make #82702 use this new lint as well. r? ``@jyn514``
2021-03-05Make invalid_doc_attribute lint pluralGuillaume Gomez-2/+2
2021-03-05Auto merge of #71481 - estebank:inherit-stability, r=nikomatsakisbors-0/+33
Inherit `#[stable(..)]` annotations in enum variants and fields from its item Lint changes for #65515. The stdlib will have to be updated once this lands in beta and that version is promoted in master.
2021-03-04Also use INVALID_DOC_ATTRIBUTE for "unknown doc attribute" warningsGuillaume Gomez-8/+10
2021-03-04Add tests for #[doc(test(...)] checkGuillaume Gomez-0/+37
2021-03-03Change error about unknown doc attributes to a warningJoshua Nelson-4/+19
This prevents breakage across the ecosystem, since the error was just introduced recently without first having a warning period.
2021-03-01Add tests for doc attribute checkGuillaume Gomez-0/+19
2021-02-11Add test for "const stability on macro"Esteban Küber-0/+33
2021-02-09Add attr-on-params testRyan Levick-0/+25
2021-02-03Handle `Span`s for byte and raw strings and add more detailEsteban Küber-2/+5
2021-01-24parser: Collect tokens for values in key-value attributesVadim Petrochenkov-0/+12
2021-01-13Update tests for extern block lintingMark Rousskov-25/+20
2021-01-09resolve/expand: Improve attribute expansion on macro definitions and callsVadim Petrochenkov-0/+23
2020-12-09Accept arbitrary expressions in key-value attributes at parse timeVadim Petrochenkov-18/+13
2020-11-03Expand `NtExpr` tokens only in key-value attributesVadim Petrochenkov-0/+153
2020-09-01Clarify message about unresolved useKornel-3/+3
2020-04-23Moving more build-pass tests to check-passVal Markovic-1/+1
One or two tests became build-pass without the FIXME because they really needed build-pass (were failing without it). Helps with #62277
2020-03-01Use `opt_def_id()` over `def_id()`Yuki Okushi-6/+8
2020-01-24Normalise notes with the/isvarkor-1/+1
2020-01-09Update testsVadim Petrochenkov-1/+14
2019-12-09resolve: Make visibility resolution more speculativeVadim Petrochenkov-10/+2
To avoid potential duplicate diagnostics and separate the error reporting logic
2019-12-09resolve: Resolve visibilities on fields with non-builtin attributesVadim Petrochenkov-0/+48
2019-11-24expand: Fully preserve visibilities on unnamed fields with attributesVadim Petrochenkov-0/+11
2019-11-24def_collector: Do not forget to save indices of fields with multiple attributesVadim Petrochenkov-0/+11
2019-11-09Address review commentsVadim Petrochenkov-0/+112
2019-11-09Support registering attributes and attribute tools using crate-level attributesVadim Petrochenkov-0/+74
2019-09-26hir: Disallow `target_feature` on constantsDavid Wood-0/+31
This commit fixes an ICE when `target_feature` is applied to constants. Signed-off-by: David Wood <david@davidtw.co>
2019-09-15resolve: Tweak "cannot find" wording for attributesVadim Petrochenkov-10/+10
2019-09-15Rollup merge of #64471 - Mark-Simulacrum:warn-depr-attr, r=CentrilMazdak Farrokhzad-2/+0
Warn on no_start, crate_id attribute use These attributes are now deprecated; they don't have any use anymore. `no_start` stopped being applicable in 3ee916e50bd86768cb2a9141f9b2c52d2601b412 as part of #18967. Ideally we would've removed it pre-1.0, but since that didn't happen let's at least mark it deprecated. `crate_id` was renamed to `crate_name` in 50ee1ec1b4f107122d8037ac7b0b312afa6eb0ac as part of #15319. Ideally we would've followed that up with a removal of crate_id itself as well, but that didn't happen; this PR finally marks it as deprecated at least. Fixes https://github.com/rust-lang/rust/issues/43142 and resolves https://github.com/rust-lang/rust/issues/43144.
2019-09-14Warn on no_start, crate_id attribute useMark Rousskov-2/+0
These attributes are now deprecated; they don't have any use anymore.
2019-09-14def_collector: Do not ICE on attributes on unnamed fieldsVadim Petrochenkov-0/+9