about summary refs log tree commit diff
path: root/compiler/rustc_lint
AgeCommit message (Collapse)AuthorLines
2024-07-22Rollup merge of #125990 - tbu-:pr_unsafe_env_lint_name, r=ehussTrevor Gross-0/+2
Rename `deprecated_safe` lint to `deprecated_safe_2024` Create a lint group `deprecated_safe` that includes `deprecated_safe_2024`. Addresses https://github.com/rust-lang/rust/issues/124866#issuecomment-2142814375. r? `@ehuss`
2024-07-19Auto merge of #127956 - tgross35:rollup-8ten7pk, r=tgross35bors-21/+45
Rollup of 7 pull requests Successful merges: - #121533 (Handle .init_array link_section specially on wasm) - #127825 (Migrate `macos-fat-archive`, `manual-link` and `archive-duplicate-names` `run-make` tests to rmake) - #127891 (Tweak suggestions when using incorrect type of enum literal) - #127902 (`collect_tokens_trailing_token` cleanups) - #127928 (Migrate `lto-smoke-c` and `link-path-order` `run-make` tests to rmake) - #127935 (Change `binary_asm_labels` to only fire on x86 and x86_64) - #127953 ([compiletest] Search *.a when getting dynamic libraries on AIX) r? `@ghost` `@rustbot` modify labels: rollup
2024-07-19Auto merge of #125915 - camelid:const-arg-refactor, r=BoxyUwUbors-1/+1
Represent type-level consts with new-and-improved `hir::ConstArg` ### Summary This is a step toward `min_generic_const_exprs`. We now represent all const generic arguments using an enum that differentiates between const *paths* (temporarily just bare const params) and arbitrary anon consts that may perform computations. This will enable us to cleanly implement the `min_generic_const_args` plan of allowing the use of generics in paths used as const args, while disallowing their use in arbitrary anon consts. Here is a summary of the salient aspects of this change: - Add `current_def_id_parent` to `LoweringContext` This is needed to track anon const parents properly once we implement `ConstArgKind::Path` (which requires moving anon const def-creation outside of `DefCollector`). - Create `hir::ConstArgKind` enum with `Path` and `Anon` variants. Use it in the existing `hir::ConstArg` struct, replacing the previous `hir::AnonConst` field. - Use `ConstArg` for all instances of const args. Specifically, use it instead of `AnonConst` for assoc item constraints, array lengths, and const param defaults. - Some `ast::AnonConst`s now have their `DefId`s created in rustc_ast_lowering rather than `DefCollector`. This is because in some cases they will end up becoming a `ConstArgKind::Path` instead, which has no `DefId`. We have to solve this in a hacky way where we guess whether the `AnonConst` could end up as a path const since we can't know for sure until after name resolution (`N` could refer to a free const or a nullary struct). If it has no chance as being a const param, then we create a `DefId` in `DefCollector` -- otherwise we decide during ast_lowering. This will have to be updated once all path consts use `ConstArgKind::Path`. - We explicitly use `ConstArgHasType` for array lengths, rather than implicitly relying on anon const type feeding -- this is due to the addition of `ConstArgKind::Path`. - Some tests have their outputs changed, but the changes are for the most part minor (including removing duplicate or almost-duplicate errors). One test now ICEs, but it is for an incomplete, unstable feature and is now tracked at https://github.com/rust-lang/rust/issues/127009. ### Followup items post-merge - Use `ConstArgKind::Path` for all const paths, not just const params. - Fix (no github dont close this issue) #127009 - If a path in generic args doesn't resolve as a type, try to resolve as a const instead (do this in rustc_resolve). Then remove the special-casing from `rustc_ast_lowering`, so that all params will automatically be lowered as `ConstArgKind::Path`. - (?) Consider making `const_evaluatable_unchecked` a hard error, or at least trying it in crater r? `@BoxyUwU`
2024-07-19Rollup merge of #127935 - tgross35:binary_asm_labels-x86-only, r=estebank,UrgauTrevor Gross-21/+45
Change `binary_asm_labels` to only fire on x86 and x86_64 In <https://github.com/rust-lang/rust/pull/126922>, the `binary_asm_labels` lint was added which flags labels such as `0:` and `1:`. Before that change, LLVM was giving a confusing error on x86/x86_64 because of an incorrect interpretation. However, targets other than x86 and x86_64 never had the error message and have not been a problem. This means that the lint was causing code that previously worked to start failing (e.g. `compiler_builtins`), rather than only providing a more clear messages where there has always been an error. Adjust the lint to only fire on x86 and x86_64 assembly to avoid this regression. Also update the help message. Fixes: https://github.com/rust-lang/rust/issues/127821
2024-07-19Update the `binary_asm_label` documentationTrevor Gross-9/+23
Disable a test that now only passes on x86 and make the link point to the new (open) LLVM bug.
2024-07-19Use `#[rustfmt::skip]` on some `use` groups to prevent reordering.Nicholas Nethercote-0/+1
`use` declarations will be reformatted in #125443. Very rarely, there is a desire to force a group of `use` declarations together in a way that auto-formatting will break up. E.g. when you want a single comment to apply to a group. #126776 dealt with all of these in the codebase, ensuring that no comments intended for multiple `use` declarations would end up in the wrong place. But some people were unhappy with it. This commit uses `#[rustfmt::skip]` to create these custom `use` groups in an idiomatic way for a few of the cases changed in #126776. This works because rustfmt treats any `use` item annotated with `#[rustfmt::skip]` as a barrier and won't reorder other `use` items around it.
2024-07-18Update the `binary_asm_label` messageTrevor Gross-3/+6
The link pointed to a closed issue. Create a new one and point the link to it. Also add a help message to hint what change the user could make. Fixes: https://github.com/rust-lang/rust/issues/127821
2024-07-18Change `binary_asm_labels` to only fire on x86 and x86_64Trevor Gross-9/+16
In <https://github.com/rust-lang/rust/pull/126922>, the `binary_asm_labels` lint was added which flags labels such as `0:` and `1:`. Before that change, LLVM was giving a confusing error on x86/x86_64 because of an incorrect interpretation. However, targets other than x86 and x86_64 never had the error message and have not been a problem. This means that the lint was causing code that previously worked to start failing (e.g. `compiler_builtins`), rather than only providing a more clear messages where there has always been an error. Adjust the lint to only fire on x86 and x86_64 assembly to avoid this regression.
2024-07-18Rollup merge of #127854 - fmease:glob-import-type_ir_inherent-lint, ↵Matthias Krüger-1/+59
r=compiler-errors Add internal lint for detecting non-glob imports of `rustc_type_ir::inherent` https://github.com/rust-lang/rust/pull/127627#issuecomment-2225295951 r? compiler-errors
2024-07-18Add internal lint for detecting non-glob imports of `rustc_type_ir::inherent`León Orell Valerian Liehr-1/+59
2024-07-17Rename `deprecated_safe` lint to `deprecated_safe_2024`Tobias Bucher-0/+2
Create a lint group `deprecated_safe` that includes `deprecated_safe_2024`. Addresses https://github.com/rust-lang/rust/issues/124866#issuecomment-2142814375.
2024-07-16hir: Create `hir::ConstArgKind` enumNoah Lev-1/+1
This will allow lowering const params to a dedicated enum variant, rather than to an `AnonConst` that is later examined during `ty` lowering.
2024-07-17Avoid comments that describe multiple `use` items.Nicholas Nethercote-1/+0
There are some comments describing multiple subsequent `use` items. When the big `use` reformatting happens some of these `use` items will be reordered, possibly moving them away from the comment. With this additional level of formatting it's not really feasible to have comments of this type. This commit removes them in various ways: - merging separate `use` items when appropriate; - inserting blank lines between the comment and the first `use` item; - outright deletion (for comments that are relatively low-value); - adding a separate "top-level" comment. We also entirely skip formatting for four library files that contain nothing but `pub use` re-exports, where reordering would be painful.
2024-07-12Rollup merge of #127631 - compiler-errors:yeet-fully-norm, r=lcnrJubilee-13/+14
Remove `fully_normalize` Yeet this function and replace it w/ some `ObligationCtxt` instead. It wasn't called very often anyways. r? lcnr
2024-07-12Rollup merge of #127535 - spastorino:unsafe_code-unsafe_extern_blocks, r=oli-obkJubilee-0/+10
Fire unsafe_code lint on unsafe extern blocks Fixes #126738
2024-07-12Rollup merge of #126922 - asquared31415:asm_binary_label, r=estebankJubilee-38/+142
add lint for inline asm labels that look like binary fixes #94426 Due to a bug/feature in LLVM, labels composed of only the digits `0` and `1` can sometimes be confused with binary literals, even if a binary literal would not be valid in that position. This PR adds detection for such labels and also as a drive-by change, adds a note to cases such as `asm!(include_str!("file"))` that the label that it found came from an expansion of a macro, it wasn't found in the source code. I expect this PR to upset some people that were using labels `0:` or `1:` without issue because they never hit the case where LLVM got it wrong, but adding a heuristic to the lint to prevent this is not feasible - it would involve writing a whole assembly parser for every target that we have assembly support for. [zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-06-20/near/445870628) r? ``@estebank``
2024-07-11Remove fully_normalizeMichael Goulet-13/+14
2024-07-11Auto merge of #127097 - compiler-errors:async-closure-lint, r=oli-obkbors-5/+140
Implement simple, unstable lint to suggest turning closure-of-async-block into async-closure We want to eventually suggest people to turn `|| async {}` to `async || {}`. This begins doing that. It's a pretty rudimentary lint, but I wanted to get something down so I wouldn't lose the code. Tracking: * #62290
2024-07-11Implement `ambiguous_negative_literals` lintUrgau-0/+107
2024-07-10Auto merge of #127549 - jhpratt:rollup-o1mbmhr, r=jhprattbors-0/+168
Rollup of 8 pull requests Successful merges: - #124211 (Bump `elided_lifetimes_in_associated_constant` to deny) - #125627 (migration lint for `expr2024` for the edition 2024) - #127091 (impl FusedIterator and a size hint for the error sources iter) - #127461 (Fixup failing fuchsia tests) - #127484 (`#[doc(alias)]`'s doc: say that ASCII spaces are allowed) - #127508 (small search graph refactor) - #127521 (Remove spastorino from SMIR) - #127532 (documentation: update cmake version) r? `@ghost` `@rustbot` modify labels: rollup
2024-07-10Rollup merge of #125627 - vincenzopalazzo:macros/cargo-fix-expr2024, ↵Jacob Pratt-0/+168
r=compiler-errors,eholk migration lint for `expr2024` for the edition 2024 This is adding a migration lint for the current (in the 2021 edition and previous) to move expr to expr_2021 from expr Issue https://github.com/rust-lang/rust/issues/123742 I created also a repository to test out the migration https://github.com/vincenzopalazzo/expr2024-cargo-fix-migration Co-Developed-by: ``@eholk``
2024-07-10Auto merge of #127496 - tgross35:f16-f128-pattern-fixme, r=Nadrierilbors-1/+2
Update `f16`/`f128` FIXMEs that needed `(NEG_)INFINITY` Just a small fix to the pattern matching tests now that we can. Also contains a small unrelated comment tweak.
2024-07-09Fire unsafe_code lint on unsafe extern blocksSantiago Pastorino-0/+10
2024-07-09Adds expr_2024 migration litVincenzo Palazzo-0/+168
This is adding a migration lint for the current (in the 2021 edition and previous) to move expr to expr_2021 from expr Co-Developed-by: Eric Holk Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-07-09add lint for inline asm labels that look like binaryasquared31415-38/+142
2024-07-08Update a f16/f128 FIXME to be more accurateTrevor Gross-1/+2
2024-07-08Move trait selection error reporting to its own top-level moduleMichael Goulet-3/+3
2024-07-07iter_identity is a better nameMichael Goulet-6/+2
2024-07-05Rollup merge of #127221 - Urgau:check-cfg-std-diag, r=pnkfelixMichael Goulet-6/+12
Improve well known value check-cfg diagnostic for the standard library This PR adjust the current logic for hidding the rustc/Cargo suggestion to add a value to a well-known name to exclude the standard library and rustc crates. This is done in order to improve the contributor experience, in particular when adding a new target, which often requires adding some cfgs like `target_os` which may not be available yet in stage0. <details> The diagnostic code would look like this. ```text error: unexpected `cfg` condition value: `blable` --> library/core/src/lib.rs:369:7 | 369 | #[cfg(target_os = "blable")] | ^^^^^^^^^^^^^^^^^^^^ | = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, and `windows` and 2 more = help: consider using a Cargo feature instead = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint: [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("blable"))'] } = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(target_os, values(\"blable\"))");` to the top of the `build.rs` = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration = note: `-D unexpected-cfgs` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unexpected_cfgs)]` ``` </details>
2024-07-02Instance::resolve -> Instance::try_resolve, and other nitsMichael Goulet-3/+5
2024-07-01Improve well known value check-cfg diagnostic for the standard libraryUrgau-6/+12
2024-06-30Rollup merge of #126018 - nnethercote:rm-box_pointers-lint, r=lcnrMatthias Krüger-88/+7
Remove the `box_pointers` lint. As the comment says, this lint "is mostly historical, and not particularly useful". It's not worth keeping it around. r? ``@estebank``
2024-06-29Rollup merge of #127045 - compiler-errors:explicit, r=oli-obkMatthias Krüger-1/+1
Rename `super_predicates_of` and similar queries to `explicit_*` to note that they're not elaborated Rename: * `super_predicates_of` -> `explicit_super_predicates_of` * `implied_predicates_of` -> `explicit_implied_predicates_of` * `supertraits_containing_assoc_item` -> `explicit_supertraits_containing_assoc_item` This makes it clearer that, unlike (for example) [`TyCtxt::super_traits_of`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.super_traits_of), we don't automatically elaborate this set of predicates. r? ``@lcnr`` or ``@oli-obk`` or someone from t-types idc
2024-06-28Make it into a structured suggestion, maybe-incorrectMichael Goulet-2/+22
2024-06-28Basic lint detecting closure-returning-async-blockMichael Goulet-0/+116
2024-06-28Only require symbol name for @feature_gateMichael Goulet-5/+4
2024-06-28Rollup merge of #127015 - Urgau:non_local_def-tmp-allow, r=lqdMatthias Krüger-1/+1
Switch back `non_local_definitions` lint to allow-by-default This PR switch back (again) the `non_local_definitions` lint to allow-by-default as T-lang is requesting some (major) changes in the lint inner workings in https://github.com/rust-lang/rust/issues/126768#issuecomment-2192634762. This PR will need to be beta-backported, as the lint is currently warn-by-default in beta.
2024-06-27Make queries more explicitMichael Goulet-1/+1
2024-06-27Switch back `non_local_definitions` lint to allow-by-defaultUrgau-1/+1
as request T-lang is requesting some major changes in the lint inner workings in #126768#issuecomment-2192634762
2024-06-27Remove the `box_pointers` lint.Nicholas Nethercote-88/+7
As the comment says, this lint "is mostly historical, and not particularly useful". It's not worth keeping it around.
2024-06-25RFC 2383: Stabilize `lint_reasons` :tada:xFrednet-15/+0
2024-06-25Auto merge of #125741 - petrochenkov:atvisord, r=davidtwcobors-0/+13
ast: Standardize visiting order for attributes and node IDs This should only affect `macro_rules` scopes and order of diagnostics. Also add a deprecation lint for `macro_rules` called outside of their scope, like in https://github.com/rust-lang/rust/issues/124535.
2024-06-24Split out IntoIterator and non-Iterator constructors for ↵Michael Goulet-1/+1
AliasTy/AliasTerm/TraitRef/projection
2024-06-24resolve: Implement a lint for out-of-scope use of `macro_rules`Vadim Petrochenkov-0/+13
2024-06-23Add hard error and migration lint for unsafe attrscarbotaniuman-0/+35
2024-06-21Fix remaining casesMichael Goulet-4/+4
2024-06-21Rename a bunch of thingsMichael Goulet-1/+1
2024-06-19Clarify that anonymous consts still do introduce a new scopeManish Goregaokar-1/+1
2024-06-19Rollup merge of #126422 - Urgau:doctest-impl-non-local-def, r=fmease许杰友 Jieyou Xu (Joe)-46/+56
Suggest using a standalone doctest for non-local impl defs This PR tweaks the lint output of the `non_local_definitions` lint to suggest using a standalone doctest instead of a moving the `impl` def to an impossible place as was already done with `macro_rules!` case in https://github.com/rust-lang/rust/pull/124568. Fixes #126339 r? ```@fmease```
2024-06-18Remove redundant argument from `subdiagnostic` methodOli Scherer-3/+3