about summary refs log tree commit diff
path: root/tests/ui/attributes
AgeCommit message (Collapse)AuthorLines
2025-02-25fix #137589Jana Dönszelmann-0/+75
2025-02-25Auto merge of #133832 - madsmtm:apple-symbols.o, r=DianQKbors-0/+50
Make `#[used]` work when linking with `ld64` To make `#[used]` work in static libraries, we use the `symbols.o` trick introduced in https://github.com/rust-lang/rust/pull/95604. However, the linker shipped with Xcode, ld64, works a bit differently from other linkers; in particular, [it completely ignores undefined symbols by themselves](https://github.com/apple-oss-distributions/ld64/blob/ld64-954.16/src/ld/parsers/macho_relocatable_file.cpp#L2455-L2468), and only consider them if they have relocations (something something atoms something fixups, I don't know the details). So to make the `symbols.o` file work on ld64, we need to actually insert a relocation. That's kinda cumbersome to do though, since the relocation must be valid, and hence must point to a valid piece of machine code, and is hence very architecture-specific. Fixes https://github.com/rust-lang/rust/issues/133491, see that for investigation. --- Another option would be to pass `-u _foo` to the final linker invocation. This has the problem that `-u` causes the linker to not be able to dead-strip the symbol, which is undesirable. (If we did this, we would possibly also want to do it by putting the arguments in a file by itself, and passing that file via ``@`,` e.g. ``@undefined_symbols.txt`,` similar to https://github.com/rust-lang/rust/issues/52699, though that [is only supported since Xcode 12](https://developer.apple.com/documentation/xcode-release-notes/xcode-12-release-notes#Linking), and I'm not sure we wanna bump that). Various other options that are probably all undesirable as they affect link time performance: - Pass `-all_load` to the linker. - Pass `-ObjC` to the linker (the Objective-C support in the linker has different code paths that load more of the binary), and instrument the binaries that contain `#[used]` symbols. - Pass `-force_load` to libraries that contain `#[used]` symbols. Failed attempt: Embed `-u _foo` in the object file with `LC_LINKER_OPTION`, akin to https://github.com/rust-lang/rust/issues/121293. Doesn't work, both because `ld64` doesn't read that from archive members unless it already has a reason to load the member (which is what this PR is trying to make it do), and because `ld64` only support the `-l`, `-needed-l`, `-framework` and `-needed_framework` flags in there. --- TODO: - [x] Support all Apple architectures. - [x] Ensure that this works regardless of the actual type of the symbol. - [x] Write up more docs. - [x] Wire up a few proper tests. `@rustbot` label O-apple
2025-02-24add test to verify that #132391 can be closedJana Dönszelmann-0/+16
2025-02-24Fix test output expectationsJana Dönszelmann-22/+42
2025-02-24Make #[used] work when linking with ld64Mads Marquart-0/+50
2025-02-20Reword messageEsteban Küber-12/+12
2025-02-19Specify scope in `out_of_scope_macro_calls` lintEsteban Küber-18/+18
``` warning: cannot find macro `in_root` in the crate root --> $DIR/key-value-expansion-scope.rs:1:10 | LL | #![doc = in_root!()] | ^^^^^^^ not found in the crate root | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535> = help: import `macro_rules` with `use` to make it callable above its definition = note: `#[warn(out_of_scope_macro_calls)]` on by default ```
2025-02-15Reject macro calls inside of `#![crate_name]`León Orell Valerian Liehr-0/+14
2025-02-15Move `#![crate_type]` UI tests into attributes directoryLeón Orell Valerian Liehr-0/+43
Gets rid of two top-level UI tests which is always great. Furthermore, move `need-crate-arg-ignore-tidy$x.rs` from `command/` to `invalid-compile-flags/`. `command/` concerns `std::process::Command` tests, not CLI tests.
2025-02-14Trim suggestion parts to the subset that is purely additiveMichael Goulet-3/+3
2025-02-14Use underline suggestions for purely 'additive' replacementsMichael Goulet-9/+6
2025-02-10Show diff suggestion format on verbose replacementEsteban Küber-26/+39
``` error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> $DIR/attempted-access-non-fatal.rs:7:15 | LL | let _ = 2.l; | ^ | help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix | LL - let _ = 2.l; LL + let _ = 2.0f64; | ```
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 ```