about summary refs log tree commit diff
path: root/src/test/ui/attributes
AgeCommit message (Collapse)AuthorLines
2022-02-25`check_used` should only look at actual `used` attributescynecx-0/+9
2022-02-09Rollup merge of #93753 - jeremyBanks:main-conflict, r=petrochenkovMatthias Krüger-0/+35
Complete removal of #[main] attribute from compiler resolves #93786 --- The `#[main]` attribute was mostly removed from the language in #84217, but not completely. It is still recognized as a builtin attribute by the compiler, but it has no effect. However, this no-op attribute is no longer gated by `#[feature(main)]` (which no longer exists), so it's possible to include it in code *on stable* without any errors, which seems unintentional. For example, the following code is accepted ([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=%23%5Bmain%5D%0Afn%20main()%20%7B%0A%20%20%20%20println!(%22hello%20world%22)%3B%0A%7D%0A)). ```rust #[main] fn main() { println!("hello world"); } ``` Aside from that oddity, the existence of this attribute causes code like the following to fail ([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=use%20tokio%3A%3Amain%3B%0A%0A%23%5Bmain%5D%0Afn%20main()%20%7B%0A%20%20%20%20println!(%22hello%20world%22)%3B%0A%7D%0A)). According https://github.com/rust-lang/rust/pull/84062#issuecomment-825038275, the removal of `#[main]` was expected to eliminate this conflict (previously reported as #62127). ```rust use tokio::main; #[main] fn main() { println!("hello world"); } ``` ``` error[E0659]: `main` is ambiguous --> src/main.rs:3:3 | 3 | #[main] | ^^^^ ambiguous name | = note: ambiguous because of a name conflict with a builtin attribute = note: `main` could refer to a built-in attribute ``` [This error message can be confusing](https://stackoverflow.com/q/71024443/1114), as the mostly-removed `#[main]` attribute is not mentioned in any documentation. Since the current availability of `#[main]` on stable seems unintentional, and to needlessly block use of the `main` identifier in the attribute namespace, this PR finishes removing the `#[main]` attribute as described in https://github.com/rust-lang/rust/issues/29634#issuecomment-274951753 by deleting it from `builtin_attrs.rs`, and adds two test cases to ensure that the attribute is no longer accepted and no longer conflicts with other attributes imported as `main`.
2022-02-09Move tests into attributes directory to pacify tidyNikita Popov-0/+51
2022-02-08Remove obsolete no-op #[main] attribute from compiler.Jeremy Banks-0/+35
2022-01-30Bless all pretty printer tests and ui testsDavid Tolnay-5/+5
2022-01-29Create `core::fmt::ArgumentV1` with generics instead of fn pointerGary Guo-2/+1
2022-01-17Emit simpler code from format_argsDavid Tolnay-5/+2
2021-12-15Add a lint for duplicated attributes.Ethiraric-0/+63
2021-12-01Pretty print empty blocks as {}David Tolnay-1/+1
2021-11-25Do not visit attributes in `LateResolutionVisitor`.Camille GILLOT-3/+27
2021-11-23Do not visit attributes in `ItemLowerer`.Camille GILLOT-0/+35
By default, AST visitors visit expressions that appear in key-value attributes. Those expressions should not be lowered to HIR, as they do not correspond to actually compiled code. Since an attribute cannot produce meaningful HIR, just skip them altogether.
2021-11-20Align multiline messages to their label (add left margin)Esteban Kuber-9/+9
2021-11-18Move some tests to more reasonable directoriesCaio-0/+113
2021-11-14Move some tests to more reasonable directoriesCaio-0/+23
2021-11-09Auto merge of #90485 - camsteffen:fmt-args-less-bind, r=m-ou-sebors-2/+2
Don't destructure args tuple in format_args! This allows Clippy to parse the HIR more simply since `arg0` is changed to `_args.0`. (cc rust-lang/rust-clippy#7843). From rustc's perspective, I think this is something between a lateral move and a tiny improvement since there are fewer bindings. r? `@m-ou-se`
2021-11-06Don't destructure args tuple in format_args!Cameron Steffen-2/+2
2021-11-06Move some tests to more reasonable directoriesCaio-0/+19
2021-10-29Unify titles in rustdoc book doc attributes chapterGuillaume Gomez-2/+2
2021-10-15Bless testsCameron Steffen-4/+4
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