about summary refs log tree commit diff
path: root/tests/ui/lint
AgeCommit message (Collapse)AuthorLines
2025-09-26Ignore more failing ui tests for GCC backendGuillaume Gomez-0/+1
2025-09-21Changes to uitests for macro_export portJonathan Brouwer-12/+12
Co-authored-by: Anne Stijns <anstijns@gmail.com>
2025-09-16Auto merge of #138271 - mu001999-contrib:fix-138234, r=jackh726bors-0/+65
Keep space if arg does not follow punctuation when lint unused parens Fixes rust-lang/rust#138234 If the arg follows punctuation, still pass `left_pos` with `None` and no space will be added, else then pass `left_pos` with `Some(arg.span.lo())`, so that we can add the space as expected. And `emit_unused_delims` can make sure no more space will be added if the expr follows space. --- Edited: Directly use the `value_span` to check whether the expr removed parens will follow identifier or be followed by identifier.
2025-09-16Keep space if expr follows identifier when lint unused parensMu001999-0/+65
2025-09-10fixup no_{core,std} handling codeJana Dönszelmann-12/+12
2025-09-08fixup limit handling codeJana Dönszelmann-42/+45
2025-09-06ImproperCTypes: more pre-emptive cleanupniacdoial-26/+16
Mainly, we realise that the non-null assumption on a Box<_> argument does not depend on what side of the FFI boundary the function is on. And anyway, this is not the way to deal with this assumption being maybe violated.
2025-09-06ImproperCTypes: move code and tests into proper directoriesniacdoial-90/+90
2025-09-04Rollup merge of #145827 - estebank:issue-51976, r=jackh726Stuart Cook-3/+29
On unused binding or binding not present in all patterns, suggest potential typo of unit struct/variant or const When encountering an or-pattern with a binding not available in all patterns, look for consts and unit struct/variants that have similar names as the binding to detect typos. ``` error[E0408]: variable `Ban` is not bound in all patterns --> $DIR/binding-typo.rs:22:9 | LL | (Foo, _) | (Ban, Foo) => {} | ^^^^^^^^ --- variable not in all patterns | | | pattern doesn't bind `Ban` | help: you might have meant to use the similarly named unit variant `Bar` | LL - (Foo, _) | (Ban, Foo) => {} LL + (Foo, _) | (Bar, Foo) => {} | ``` For items that are not in the immedate scope, suggest the full path for them: ``` error[E0408]: variable `Non` is not bound in all patterns --> $DIR/binding-typo-2.rs:51:16 | LL | (Non | Some(_))=> {} | --- ^^^^^^^ pattern doesn't bind `Non` | | | variable not in all patterns | help: you might have meant to use the similarly named unit variant `None` | LL - (Non | Some(_))=> {} LL + (core::option::Option::None | Some(_))=> {} | ``` When encountering a typo in a pattern that gets interpreted as an unused binding, look for unit struct/variant of the same type as the binding: ``` error: unused variable: `Non` --> $DIR/binding-typo-2.rs:36:9 | LL | Non => {} | ^^^ | help: if this is intentional, prefix it with an underscore | LL | _Non => {} | + help: you might have meant to pattern match on the similarly named variant `None` | LL - Non => {} LL + std::prelude::v1::None => {} | ``` Suggest constant on unused binding in a pattern ``` error: unused variable: `Batery` --> $DIR/binding-typo-2.rs:110:9 | LL | Batery => {} | ^^^^^^ | help: if this is intentional, prefix it with an underscore | LL | _Batery => {} | + help: you might have meant to pattern match on the similarly named constant `Battery` | LL | Battery => {} | + ``` Fix rust-lang/rust#51976.
2025-08-30On unused binding in pattern, suggest unit struct/variant with similar nameEsteban Küber-3/+29
When encountering a typo in a pattern that gets interpreted as an unused binding, look for unit struct/variant of the same type as the binding: ``` error: unused variable: `Non` --> $DIR/binding-typo-2.rs:36:9 | LL | Non => {} | ^^^ | help: if this is intentional, prefix it with an underscore | LL | _Non => {} | + help: you might have meant to pattern match on the similarly named variant `None` | LL - Non => {} LL + std::prelude::v1::None => {} | ```
2025-08-28Rollup merge of #145941 - Urgau:int_to_ptr_transmutes-unsized, r=lcnrStuart Cook-0/+50
Disable `integer_to_ptr_transmutes` suggestion for unsized types This PR disables the machine-applicable `integer_to_ptr_transmutes` lint suggestion for unsized types, as [`std::ptr::with_exposed_provenance`](https://doc.rust-lang.org/std/ptr/fn.with_exposed_provenance.html) requires sized types. We should probably mention [`std::ptr::from_raw_parts`](https://doc.rust-lang.org/std/ptr/fn.from_raw_parts.html) when it becomes stable. Related to https://github.com/rust-lang/rust/issues/145935
2025-08-28Rollup merge of #144864 - Muscraft:no-source-fixes, r=jieyouxuStuart Cook-3/+7
No source fixes This PR started as a fix for a rendering bug that [got noticed in #143661](https://github.com/rust-lang/rust/pull/143661#discussion_r2199109530), but turned into a fix for any rendering bugs related to files with no source. - Don't add an end column separator after a file with no source - Add column separator before secondary messages with no source - Render continuation between no source labels Before ``` error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap` ╭▸ $DIR/multi-suggestion.rs:17:13 │ LL │ let _ = std::collections::HashMap(); │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━ ╭▸ $SRC_DIR/std/src/collections/hash/map.rs:LL:COL │ ╰ note: `std::collections::HashMap` defined here ╰╴ note: constructor is not visible here due to private fields ╭▸ $SRC_DIR/alloc/src/boxed.rs:LL:COL │ ╰ note: private field │ ╰ note: private field ``` After ``` error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap` ╭▸ $DIR/multi-suggestion.rs:17:13 │ LL │ let _ = std::collections::HashMap(); │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━ ╰╴ ╭▸ $SRC_DIR/std/src/collections/hash/map.rs:LL:COL │ ╰ note: `std::collections::HashMap` defined here note: constructor is not visible here due to private fields ╭▸ $SRC_DIR/alloc/src/boxed.rs:LL:COL │ ├ note: private field │ ╰ note: private field ``` Note: This PR also makes it so `rustc` and `annotate-snippets` match in these cases
2025-08-27Disable `int_to_ptr_transmutes` suggestion for unsized typesUrgau-0/+50
2025-08-26Rollup merge of #145792 - scrabsha:push-umpytyxunpxq, r=jdonszelmannSamuel Tardieu-5/+26
Use attribute name in message for "outer attr used as inner attr" errors
2025-08-26fix: Add col separator before secondary messages with no sourceScott Schafer-0/+7
2025-08-26fix: Don't add an end column separator after a file with no sourceScott Schafer-3/+0
2025-08-25Use attribute name in message for "outer attr used as inner attr" errorsSasha Pourcelot-5/+26
2025-08-24Regression test for attributes on macro callsJonathan Brouwer-42/+24
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-24fix ICE on stable related to attrs on macrosJana Dönszelmann-0/+38
2025-08-24Port crate name to the new attribute systemJana Dönszelmann-60/+78
2025-08-24Support lints in early attribute parsingJana Dönszelmann-27/+40
2025-08-24Prefer verbose suggestions for `integer_to_ptr_transmutes` lintUrgau-36/+72
2025-08-24Add lint against integer to pointer transmutesUrgau-0/+265
2025-08-22Updated uitests for new parserJonathan Brouwer-26/+27
2025-08-21Rollup merge of #145672 - compiler-errors:query-instab-ice, r=lcnrJacob Pratt-0/+11
Instantiate higher-ranked binder with erased when checking `IntoIterator` predicate for query instability Fixes https://github.com/rust-lang/rust/issues/145652 which was introduced by https://github.com/rust-lang/rust/pull/139345 because we were skipping a binder before calling `Instance::try_resolve`. r? lcnr
2025-08-21split up context.rsJana Dönszelmann-21/+21
2025-08-21refactor target checking, move out of context.rs and rename MaybeWarn to PolicyJana Dönszelmann-3/+3
2025-08-20Instantiate higher-ranked binder with erased when checking IntoIterator ↵Michael Goulet-0/+11
predicate query instability
2025-08-20Rollup merge of #140794 - karolzwolak:allow-unused-doc-65464, r=davidtwcoJacob Pratt-16/+61
mention lint group in default level lint note ### Summary This PR updates lint diagnostics so that default-level notes now mention the lint group they belong to, if any. Fixes: rust-lang/rust#65464. ### Example ```rust fn main() { let x = 5; } ``` Before: ``` = note: `#[warn(unused_variables)]` on by default ``` After: ``` = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default ``` ### Unchanged Cases Messages remain the same when the lint level is explicitly set, e.g.: * Attribute on the lint `#[warn(unused_variables)]`: ``` note: the lint level is defined here LL | #[warn(unused_variables)] | ^^^^^^^^^^^^^^^^ ``` * Attribute on the group `#[warn(unused)]:`: ``` = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]` ``` * CLI option `-W unused`: ``` = note: `-W unused-variables` implied by `-W unused` = help: to override `-W unused` add `#[allow(unused_variables)]` ``` * CLI option `-W unused-variables`: ``` = note: requested on the command line with `-W unused-variables` ```
2025-08-19bless tests with new lint messagesKarol Zwolak-16/+16
2025-08-19mention lint group in default level lint noteKarol Zwolak-0/+45
2025-08-19Update uitestsJonathan Brouwer-107/+212
2025-08-15Fix wrong spans with external macros in the `dropping_copy_types` lintUrgau-1/+21
2025-08-14Update uitestsJonathan Brouwer-79/+93
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-13Rollup merge of #145274 - compiler-errors:unused-must-use, r=fmeaseJakub Beránek-32/+174
Remove unused `#[must_use]` Self-explanatory Fixes https://github.com/rust-lang/rust/issues/145257
2025-08-12Remove unused must_useMichael Goulet-32/+174
2025-08-12Rollup merge of #145238 - estebank:attr-overhaul, r=jdonszelmannStuart Cook-1/+14
Tweak invalid builtin attribute output - Add link to reference/docs when possible - More accurate suggestions by supporting multiple alternative suggestions ``` error: malformed `crate_type` attribute input --> $DIR/crate-type-macro-call.rs:1:1 | LL | #![crate_type = foo!()] | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html> help: the following are the possible correct uses | LL - #![crate_type = foo!()] LL + #![crate_type = "bin"] | LL - #![crate_type = foo!()] LL + #![crate_type = "cdylib"] | LL - #![crate_type = foo!()] LL + #![crate_type = "dylib"] | LL - #![crate_type = foo!()] LL + #![crate_type = "lib"] | = and 4 other candidates ```
2025-08-12Rollup merge of #145214 - notJoon:fix/enable-self-assignment, r=petrochenkovStuart Cook-10/+51
fix: re-enable self-assignment ## Description Re-enables the self-assignment detection that was previously disabled due to unrelated regressions. The fix detects useless assignments like `x = x` and `foo.field = foo.field`. ## History The original regressions (rust-lang/rust#81626, rust-lang/rust#81658) were specifically about false positives in write-only field detection, not self-assignment detection. Belows are brief history for the rule that I understand. - Self-assignment detection was originally implemented in rust-lang/rust#87129 to address rust-lang/rust#75356 - The implementation was disabled alongside the revert of rust-lang/rust#81473's "write-only fields" detection - rust-lang/rust#81473 was reverted via rust-lang/rust#86212 and rust-lang/rust#83171 due to false positives in write-only field detection (rust-lang/rust#81626, rust-lang/rust#81658) - The self-assignment detection feature got removed, even though it wasn't the reason for the problems This PR only re-enables the self-assignment checks, which are orthogonal to the problematic write-only field analysis. ## Changes - Removed `#[allow(dead_code)]` from `compiler/rustc_passes/src/dead.rs` file - `handle_assign` and - `check_for_self_assign` - Added `ExprKind::Assign` handling in `visit_expr` to call both methods - Updated test expectations in `tests/ui/lint/dead-code/self-assign.rs`
2025-08-11Add link to docs on malformed attributesEsteban Küber-0/+1
2025-08-11Allow attr entries to declare list of alternatives for `List` and ↵Esteban Küber-1/+13
`NamedValueStr` Modify `AttributeTemplate` to support list of alternatives for list and name value attribute styles. Suggestions now provide more correct suggested code: ``` error[E0805]: malformed `used` attribute input --> $DIR/used_with_multi_args.rs:3:1 | LL | #[used(compiler, linker)] | ^^^^^^------------------^ | | | expected a single argument here | help: try changing it to one of the following valid forms of the attribute | LL - #[used(compiler, linker)] LL + #[used(compiler)] | LL - #[used(compiler, linker)] LL + #[used(linker)] | LL - #[used(compiler, linker)] LL + #[used] | ``` instead of the prior "masking" of the lack of this feature by suggesting pipe-separated lists: ``` error[E0805]: malformed `used` attribute input --> $DIR/used_with_multi_args.rs:3:1 | LL | #[used(compiler, linker)] | ^^^^^^------------------^ | | | expected a single argument here | help: try changing it to one of the following valid forms of the attribute | LL - #[used(compiler, linker)] LL + #[used(compiler|linker)] | LL - #[used(compiler, linker)] LL + #[used] | ```
2025-08-10Rollup merge of #144553 - Oneirical:uncountable-integer-4, r=jieyouxuJacob Pratt-0/+12
Rehome 32 `tests/ui/issues/` tests to other subdirectories under `tests/ui/` rust-lang/rust#143902 divided into smaller, easier to review chunks. Part of rust-lang/rust#133895 Methodology: 1. Refer to the previously written `tests/ui/SUMMARY.md` 2. Find an appropriate category for the test, using the original issue thread and the test contents. 3. Add the issue URL at the bottom (not at the top, as that would mess up stderr line numbers) 4. Rename the tests to make their purpose clearer Inspired by the methodology that `@Kivooeo` was using. r? `@jieyouxu`
2025-08-10Rehome tests/ui/issues/ tests [4/?]Oneirical-0/+12
2025-08-10fix: re-enable self-assignmentLee ByeongJun-10/+51
2025-08-07Rollup merge of #144369 - joshtriplett:mbe-expr-semi-deny-by-default, ↵Stuart Cook-12/+11
r=petrochenkov Upgrade semicolon_in_expressions_from_macros from warn to deny This is already warn-by-default, and a future compatibility warning (FCW) that warns in dependencies. Upgrade it to deny-by-default, as the next step towards hard error. Per https://github.com/rust-lang/rust/issues/79813#issuecomment-3109105631
2025-08-06Changes to the tests for the `#[should_panic]` portJonathan Brouwer-13/+13
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-04Rollup merge of #144322 - Urgau:dangling-ptr-from-locals, r=oli-obkStuart Cook-0/+435
Add lint against dangling pointers from local variables ## `dangling_pointers_from_locals` *warn-by-default* The `dangling_pointers_from_locals` lint detects getting a pointer to data of a local that will be dropped at the end of the function. ### Example ```rust fn f() -> *const u8 { let x = 0; &x // returns a dangling ptr to `x` } ``` ```text warning: a dangling pointer will be produced because the local variable `x` will be dropped --> $DIR/dangling-pointers-from-locals.rs:10:5 | LL | fn simple() -> *const u8 { | --------- return type of the function is `*const u8` LL | let x = 0; | - `x` is defined inside the function and will be drop at the end of the function LL | &x | ^^ | = note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned = note: `#[warn(dangling_pointers_from_locals)]` on by default ``` ### Explanation Returning a pointer from a local value will not prolong its lifetime, which means that the value can be dropped and the allocation freed while the pointer still exists, making the pointer dangling. If you need stronger guarantees, consider using references instead, as they are statically verified by the borrow-checker to never dangle. ------ This is related to GitHub codeql [CWE-825](https://github.com/github/codeql/blob/main/rust/ql/src/queries/security/CWE-825/AccessAfterLifetimeBad.rs) which shows examples of such simple miss-use. It should be noted that C compilers warns against such patterns even without `-Wall`, https://godbolt.org/z/P7z98arrc. ------ `@rustbot` labels +I-lang-nominated +T-lang cc `@traviscross` r? compiler
2025-08-01Rollup merge of #144691 - xizheyin:suggest-confuse, r=estebankJacob Pratt-1/+1
Extend `is_case_difference` to handle digit-letter confusables This PR extends `is_case_difference` to handle digit-letter confusables Add support for detecting 0/O, 1/l, 5/S, 8/B, 9/g confusables in error suggestions. r? `@estebank`
2025-07-31Add lint against dangling pointers form local variablesUrgau-0/+435
2025-07-31Extend `is_case_difference` to handle digit-letter confusablesxizheyin-1/+1
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-31Consider operator's span when computing binop expr spanMichael Goulet-11/+11