about summary refs log tree commit diff
path: root/tests/ui/attributes
AgeCommit message (Collapse)AuthorLines
2025-01-24Reword "crate not found" resolve messageEsteban Küber-38/+38
``` error[E0432]: unresolved import `some_novel_crate` --> file.rs:1:5 | 1 | use some_novel_crate::Type; | ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate` ``` On resolve errors where there might be a missing crate, mention `cargo add foo`: ``` error[E0433]: failed to resolve: use of unresolved module or unlinked crate `nope` --> $DIR/conflicting-impl-with-err.rs:4:11 | LL | impl From<nope::Thing> for Error { | ^^^^ use of unresolved module or unlinked crate `nope` | = help: if you wanted to use a crate named `nope`, use `cargo add nope` to add it to your `Cargo.toml` ```
2025-01-07Update tests.Mara Bos-1/+1
2025-01-03turn rustc_box into an intrinsicRalf Jung-52/+0
2024-12-27Remove the `-test` suffix from normalize directivesZalathar-3/+3
2024-12-17Adjust `tests/ui/attr-usage-inline.rs`许杰友 Jieyou Xu (Joe)-0/+43
- Move `tests/ui/attr-usage-inline.rs` to `tests/ui/attributes/inline/`. - Briefly document test intent. - Drop unnecessary `#[allow(dead_code)]` as this is allowed-by-default for ui test suite.
2024-12-17Adjust `tests/ui/attr-shebang.rs`许杰友 Jieyou Xu (Joe)-0/+7
- Move `tests/ui/attr-shebang.rs` to `tests/ui/attributes/`. - Downgrade test to `check-pass`, this would fail very early if the parser did not accept `#![..]` attributes. - Briefly document test intent.
2024-12-17Adjust `tests/ui/attr-bad-crate-attr.rs`许杰友 Jieyou Xu (Joe)-0/+17
- Move `tests/ui/attr-bad-crate-attr.rs` to `tests/ui/attributes/`. - Briefly document test intent add link to relevant Reference docs.
2024-12-12Filter empty lines, comments and delimiters from previous to last multiline ↵Esteban Küber-5/+0
span rendering
2024-12-10Rollup merge of #131558 - ↵León Orell Valerian Liehr-0/+69
sassman:feat/warnin-for-no-mangle-together-with-export-name, r=Urgau Lint on combining `#[no_mangle]` and `#[export_name]` This is my very first contribution to the compiler, even though I read the [chapter about lints](https://rustc-dev-guide.rust-lang.org/diagnostics.html) I'm not very certain that this ~~new lint is done right as a builtin lint~~ PR is right. I appreciate any guidance on how to improve the code. - Add test for issue #47446 - ~~Implement the new lint `mixed_export_name_and_no_mangle` as a builtin lint (not sure if that is the right way to go)~~ Extend `unused_attributes` lint - Add suggestion how to fix it <details> <summary>Old proposed new lint</summary> > The `mixed_export_name_and_no_mangle` lint detects usage of both `#[export_name]` and `#[no_mangle]` on the same item which results on `#[no_mangle]` being ignored. > > *warn-by-default* > > ### Example > > ```rust > #[no_mangle] // ignored > #[export_name = "foo"] // takes precedences > pub fn bar() {} > ``` > > ### Explanation > > The compiler will not respect the `#[no_mangle]` attribute when generating the symbol name for the function, as the `#[export_name]` attribute takes precedence. This can lead to confusion and is unnecessary. </details>
2024-12-02Move `Const::{from_anon_const,try_from_lit}` to hir_ty_loweringNoah Lev-12/+66
These operations are much more about lowering the HIR than about `Const`s themselves. They fit better in hir_ty_lowering with `lower_const_arg` (formerly `Const::from_const_arg`) and the rest. To accomplish this, `const_evaluatable_predicates_of` had to be changed to not use `from_anon_const` anymore. Instead of visiting the HIR and lowering anon consts on the fly, it now visits the `rustc_middle::ty` data structures instead and directly looks for `UnevaluatedConst`s. This approach was proposed in: https://github.com/rust-lang/rust/pull/131081#discussion_r1821189257
2024-11-27Update tests to use new proc-macro headerEric Huss-12/+2
2024-11-26tests: remove `//@ pretty-expanded` usages许杰友 Jieyou Xu (Joe)-5/+0
Done with ```bash sd '//@ pretty-expanded.*\n' '' tests/ui/**/*.rs ``` and ``` sd '//@pretty-expanded.*\n' '' tests/ui/**/*.rs ```
2024-11-23Rollup merge of #127483 - BertalanD:no_sanitize-global-var, r=rcvalle许杰友 Jieyou Xu (Joe)-31/+45
Allow disabling ASan instrumentation for globals AddressSanitizer adds instrumentation to global variables unless the [`no_sanitize_address`](https://llvm.org/docs/LangRef.html#global-attributes) attribute is set on them. This commit extends the existing `#[no_sanitize(address)]` attribute to set this; previously it only had the desired effect on functions. (cc https://github.com/rust-lang/rust/issues/39699)
2024-11-22Stabilize the 2024 editionEric Huss-11/+10
2024-11-15fix: rust-lang/rust#47446Sven Kanoldt-0/+69
- Add test for issue 47446 - Implement the new lint lint_builtin_mixed_export_name_and_no_mangle - Add suggestion how to fix it
2024-11-02Allow disabling ASan instrumentation for globalsDaniel Bertalan-31/+45
AddressSanitizer adds instrumentation to global variables unless the [`no_sanitize_address`](https://llvm.org/docs/LangRef.html#global-attributes) attribute is set on them. This commit extends the existing `#[no_sanitize(address)]` attribute to set this; previously it only had the desired effect on functions.
2024-10-20misapplied optimize attribute throws a compilation error (#128488)ash-15/+45
2024-10-02Add `get_line` confusable to `Stdin::read_line()`Jaken Herman-1/+16
Add tests for addition of `#[rustc_confusables("get_line")]`
2024-09-30Reject leading unsafe in `cfg!(...)` and `--check-cfg`.Urgau-2/+24
2024-09-21remove `#[cmse_nonsecure_entry]`Folkert-24/+3
2024-08-24New `#[rustc_pub_transparent]` attributePavel Grigorenko-0/+48
2024-08-18Check that `#[may_dangle]` is properly appliedGoldstein-0/+103
It's only valid when applied to a type or lifetime parameter in `Drop` trait implementation.
2024-08-17Auto merge of #128771 - carbotaniuman:stabilize_unsafe_attr, r=nnethercotebors-48/+35
Stabilize `unsafe_attributes` # Stabilization report ## Summary This is a tracking issue for the RFC 3325: unsafe attributes We are stabilizing `#![feature(unsafe_attributes)]`, which makes certain attributes considered 'unsafe', meaning that they must be surrounded by an `unsafe(...)`, as in `#[unsafe(no_mangle)]`. RFC: rust-lang/rfcs#3325 Tracking issue: #123757 ## What is stabilized ### Summary of stabilization Certain attributes will now be designated as unsafe attributes, namely, `no_mangle`, `export_name`, and `link_section` (stable only), and these attributes will need to be called by surrounding them in `unsafe(...)` syntax. On editions prior to 2024, this is simply an edition lint, but it will become a hard error in 2024. This also works in `cfg_attr`, but `unsafe` is not allowed for any other attributes, including proc-macros ones. ```rust #[unsafe(no_mangle)] fn a() {} #[cfg_attr(any(), unsafe(export_name = "c"))] fn b() {} ``` For a table showing the attributes that were considered to be included in the list to require unsafe, and subsequent reasoning about why each such attribute was or was not included, see [this comment here](https://github.com/rust-lang/rust/pull/124214#issuecomment-2124753464) ## Tests The relevant tests are in `tests/ui/rust-2024/unsafe-attributes` and `tests/ui/attributes/unsafe`.
2024-08-17Rollup merge of #128989 - s7tya:check-linkage-attribute-pos, r=petrochenkovMatthias Krüger-0/+97
Emit an error for invalid use of the linkage attribute fixes #128486 Currently, the use of the linkage attribute for Mod, Impl,... is incorrectly permitted. This PR will correct this issue by generating errors, and I've also added some UI test cases for it. Related: #128552.
2024-08-17Emit an error for invalid use of the linkage attributeShina-0/+97
2024-08-16Overhaul token collection.Nicholas Nethercote-0/+42
This commit does the following. - Renames `collect_tokens_trailing_token` as `collect_tokens`, because (a) it's annoying long, and (b) the `_trailing_token` bit is less accurate now that its types have changed. - In `collect_tokens`, adds a `Option<CollectPos>` argument and a `UsePreAttrPos` in the return type of `f`. These are used in `parse_expr_force_collect` (for vanilla expressions) and in `parse_stmt_without_recovery` (for two different cases of expression statements). Together these ensure are enough to fix all the problems with token collection and assoc expressions. The changes to the `stringify.rs` test demonstrate some of these. - Adds a new test. The code in this test was causing an assertion failure prior to this commit, due to an invalid `NodeRange`. The extra complexity is annoying, but necessary to fix the existing problems.
2024-08-07Rollup merge of #128552 - s7tya:check-no-sanitize-attribute-pos, r=BoxyUwUTrevor Gross-0/+89
Emit an error for invalid use of the `#[no_sanitize]` attribute fixes #128487. Currently, the use of the `#[no_sanitize]` attribute for Mod, Impl,... is incorrectly permitted. This PR will correct this issue by generating errors, and I've also added some UI test cases for it. Referenced #128458. As far as I know, the `#[no_sanitize]` attribute can only be used with functions, so I changed that part to `Fn` and `Method` using `check_applied_to_fn_or_method`. However, I couldn't find explicit documentation on this, so I could be mistaken...
2024-08-07Stabilize `unsafe_attributes`carbotaniuman-48/+35
2024-08-06tests: add regression test to make sure `cfg_attr` isn't considered unhandled许杰友 Jieyou Xu (Joe)-0/+169
2024-08-05Emit an error for invalid use of the `#[no_sanitize]` attributeShina-0/+89
2024-08-04tests: add regression test for incorrect "builtin attribute is checked" ↵许杰友 Jieyou Xu (Joe)-0/+79
assertion ICE See <https://github.com/rust-lang/rust/issues/128622>.
2024-08-01Auto merge of #127543 - carbotaniuman:more_unsafe_attr_verification, ↵bors-6/+331
r=estebank,traviscross More unsafe attr verification This code denies unsafe on attributes such as `#[test]` and `#[ignore]`, while also changing the `MetaItem` parsing so `unsafe` in args like `#[allow(unsafe(dead_code))]` is not accidentally allowed. Tracking: - https://github.com/rust-lang/rust/issues/123757
2024-07-31Emit an error if `#[optimize]` is applied to an incompatible itemclubby789-0/+48
2024-07-30Add toggle for `parse_meta_item` unsafe parsingcarbotaniuman-25/+157
This makes it possible for the `unsafe(...)` syntax to only be valid at the top level, and the `NestedMetaItem`s will automatically reject `unsafe(...)`.
2024-07-29Deny unsafe on more builtin attributescarbotaniuman-1/+194
2024-07-29Structured suggestion for `extern crate foo` when `foo` isn't resolved in importEsteban Küber-2/+8
When encountering a name in an import that could have come from a crate that wasn't imported, use a structured suggestion to suggest `extern crate foo;` pointing at the right place in the crate. When encountering `_` in an import, do not suggest `extern crate _;`. ``` error[E0432]: unresolved import `spam` --> $DIR/import-from-missing-star-3.rs:2:9 | LL | use spam::*; | ^^^^ maybe a missing crate `spam`? | help: consider importing the `spam` crate | LL + extern crate spam; | ```
2024-07-25Auto merge of #127042 - GrigorenkoPV:derivative, r=compiler-errorsbors-1/+1
Switch from `derivative` to `derive-where` This is a part of the effort to get rid of `syn 1.*` in compiler's dependencies: #109302 Derivative has not been maintained in nearly 3 years[^1]. It also depends on `syn 1.*`. This PR replaces `derivative` with `derive-where`[^2], a not dead alternative, which uses `syn 2.*`. A couple of `Debug` formats have changed around the skipped fields[^3], but I doubt this is an issue. [^1]: https://github.com/mcarton/rust-derivative/issues/117 [^2]: https://lib.rs/crates/derive-where [^3]: See the changes in `tests/ui`
2024-07-24Do not use question as labelEsteban Küber-4/+4
We don't want to have questions in the diagnostic output. Instead, we use wording that communicates uncertainty, like "might": ``` error[E0432]: unresolved import `spam` --> $DIR/import-from-missing-star-3.rs:2:9 | LL | use spam::*; | ^^^^ you might be missing crate `spam` | = help: consider adding `extern crate spam` to use the `spam` crate ```
2024-07-12rustc_type_ir: derivative -> derive-wherePavel Grigorenko-1/+1
2024-07-12Make parse error suggestions verbose and fix spansEsteban Küber-1/+6
Go over all structured parser suggestions and make them verbose style. When suggesting to add or remove delimiters, turn them into multiple suggestion parts.
2024-07-11Always use a colon in `//@ normalize-*:` headersZalathar-2/+2
2024-06-30add `rustc_dump_def_parents` attributeBoxy-0/+162
2024-06-29Rollup merge of #127118 - surechen:fix_126789, r=jieyouxuMatthias Krüger-0/+16
Show `used attribute`'s kind for user when find it isn't applied to a `static` variable. For example : ```rust extern "C" { #[used] //~ ERROR attribute must be applied to a `static` variable static FOO: i32; // show the kind of this item to help user understand why the error is reported. } ``` fixes #126789
2024-06-29Show `used attribute`'s kind for user when find it isn't applied to a ↵surechen-0/+16
`static` variable. fixes #126789
2024-06-24resolve: Implement a lint for out-of-scope use of `macro_rules`Vadim Petrochenkov-49/+113
2024-06-24ast: Standardize visiting order for attributes and node IDsVadim Petrochenkov-5/+37
2024-06-23Add hard error and migration lint for unsafe attrscarbotaniuman-6/+6
2024-06-22Add `#[rustc_dump_{predicates,item_bounds}]`León Orell Valerian Liehr-0/+59
2024-06-06Add double unsafe testcarbotaniuman-0/+36
2024-06-06Error on unsafe on non-unsafe attributecarbotaniuman-0/+34