about summary refs log tree commit diff
path: root/compiler/rustc_lint
AgeCommit message (Collapse)AuthorLines
2024-01-23Rename `LintContext::lookup_with_diagnostics` as ↵Nicholas Nethercote-3/+9
`LintContext::span_lint_with_diagnostics`.
2024-01-23Rename `LintContext::lookup` as `LintContext::opt_span_lint`.Nicholas Nethercote-8/+8
2024-01-23Rename `LintContext::struct_span_lint` as `LintContext::span_lint`.Nicholas Nethercote-2/+2
2024-01-22Rollup merge of #118639 - fmease:deny-features-in-stable-rustc-crates, ↵Matthias Krüger-8/+28
r=WaffleLapkin Undeprecate lint `unstable_features` and make use of it in the compiler See also #117937. r? compiler
2024-01-22Revert "Auto merge of #118133 - Urgau:stabilize_trait_upcasting, r=WaffleLapkin"Oli Scherer-3/+12
This reverts commit 6d2b84b3ed7848fd91b8d6151d4451b3103ed816, reversing changes made to 73bc12199ea8c7651ed98b069c0dd6b0bb5fabcf.
2024-01-22Auto merge of #120080 - cuviper:128-align-packed, r=nikicbors-5/+5
Pack u128 in the compiler to mitigate new alignment This is based on #116672, adding a new `#[repr(packed(8))]` wrapper on `u128` to avoid changing any of the compiler's size assertions. This is needed in two places: * `SwitchTargets`, otherwise its `SmallVec<[u128; 1]>` gets padded up to 32 bytes. * `LitKind::Int`, so that entire `enum` can stay 24 bytes. * This change definitely has far-reaching effects though, since it's public.
2024-01-22Rollup merge of #119710 - Nilstrieb:let-_-=-oops, r=TaKO8KiMatthias Krüger-37/+68
Improve `let_underscore_lock` - lint if the lock was in a nested pattern - lint if the lock is inside a `Result<Lock, _>` addresses https://github.com/rust-lang/rust/pull/119704#discussion_r1444044745
2024-01-19Pack the u128 in LitKind::IntJosh Stone-5/+5
2024-01-18Rollup merge of #119967 - ShE3py:patkind-err, r=WaffleLapkinMatthias Krüger-1/+1
Add `PatKind::Err` to AST/HIR #116715 added `thir::PatKind::Error`; this PR adds `hir::PatKind::Err` and `ast::PatKind::Err` (see https://github.com/rust-lang/rust/pull/118625#discussion_r1446587901.) --- ``@rustbot`` label +A-patterns r? WaffleLapkin
2024-01-17Auto merge of #119930 - Urgau:check-cfg-empty-values-means-empty, r=petrochenkovbors-0/+11
Add way to express that no values are expected with check-cfg This PR adds way to express no-values (no values expected) with `--check-cfg` by making empty `values()` no longer mean `values(none())` (internal: `&[None]`) and now be an empty list (internal: `&[]`). ### Context Currently `--check-cfg` has a way to express that _any value is expected_ with `values(any())`, but has no way to do the inverse and say that _no value is expected_. This would be particularly useful for build systems that control a config name and it's values as they could always declare a config name as expected and if in the current state they have values pass them and if not pass an empty list. To give a more concrete example, Cargo `--check-cfg` currently needs to generate: - `--check-cfg=cfg(feature, values(...))` for the case with declared features - and `--check-cfg=cfg()` for the case without any features declared This means that when there are no features declared, users will get an `unexpected config name` but from the point of view of Cargo the config name `feature` is expected, it's just that for now there aren't any values for it. See [Cargo `check_cfg_args` function](https://github.com/rust-lang/cargo/blob/92395d90106b3b61bcb68bcf2069052c93771764/src/cargo/core/compiler/mod.rs#L1263-L1281) for more details. ### De-specializing *empty* `values()` To solve this issue I propose that we "de-specialize" empty `values()` to no longer mean `values(none())` but to actually mean empty set/list. This is one of the last source of confusion for my-self and others with the `--check-cfg` syntax. > The confusing part here is that an empty `values()` currently means the same as `values(none())`, i.e. an expected list of values with the _none_ variant (as in `#[cfg(name)]` where the value is none) instead of meaning an empty set. Before the new `cfg()` syntax, defining the _none_ variant was only possible under certain circumstances, so in https://github.com/rust-lang/rust/pull/111068 I decided to make `values()` to mean the _none_ variant, but it is no longer necessary since https://github.com/rust-lang/rust/pull/119473 which introduced the `none()` syntax. A simplified representation of the proposed "de-specialization" would be: | Syntax | List/set of expected values | |-----------------------------------------|-----------------------------| | `cfg(name)`/`cfg(name, values(none()))` | `&[None]` | | `cfg(name, values())` | `&[]` | Note that I have my-self made the mistake of using an empty `values()` as meaning empty set, see https://github.com/rust-lang/cargo/pull/13011. `@rustbot` label +F-check-cfg r? `@petrochenkov` cc `@epage`
2024-01-17Add `PatKind::Err`Lieselotte-1/+1
2024-01-13Add check for ui_testing via promoting parameters from `ParseSess` to `Session`George-lewis-9/+6
2024-01-13Add way to express no-values with check-cfgUrgau-0/+11
2024-01-13Auto merge of #118924 - Urgau:check-cfg-exclude-well-known-from-diag, ↵bors-2/+10
r=petrochenkov Exclude well known names from showing a suggestion in check-cfg This PR adds an exclusion for well known names from showing in suggestions of check-cfg/`unexpected_cfgs`. Follow-up to https://github.com/rust-lang/rust/pull/118213 and fixes https://github.com/rust-lang/rust/pull/118213#issuecomment-1854189934. r? `@petrochenkov`
2024-01-12Improve `let_underscore_lock`Nilstrieb-37/+68
- lint if the lock was in a nested pattern - lint if the lock is inside a `Result<Lock, _>`
2024-01-12Auto merge of #117321 - chenyukang:yukang-fix-117142, r=petrochenkovbors-12/+22
Fix unused_parens issue when cast is followed LT Fixes #117142 The original check only checks `a as (i32) < 0`, this fix extends it to handle `b + a as (i32) < 0`. A better way is maybe we suggest `(a as i32) < 0` instead of suppressing the warning, maybe following PR could improve it.
2024-01-12Exclude well known names from showing a suggestion in check-cfgUrgau-2/+10
2024-01-12Rollup merge of #119819 - chenyukang:yukang-fix-118183-lint, r=davidtwcoGuillaume Gomez-14/+32
Check rust lints when an unknown lint is detected Fixes #118183
2024-01-12check rust lints when an unknown lint is detectedyukang-14/+32
2024-01-10Simplify some redundant namesMichael Goulet-2/+1
2024-01-09Rollup merge of #118649 - compiler-errors:coherence-ambig, r=lcnrMatthias Krüger-0/+5
Make inductive cycles in coherence ambiguous always Logical conclusion of https://github.com/rust-lang/rust/issues/114040 One step after #116493 cc https://github.com/rust-lang/trait-system-refactor-initiative/issues/20 r? lcnr to kick off the FCP after review... maybe we should wait until 1.75 is landed? In that case, I'd still like to get the FCP boxes checked sooner since that'll be near the holidays which means everyone's away.
2024-01-09Rollup merge of #119704 - chenyukang:yukang-fix-let_underscore, r=NilstriebMatthias Krüger-1/+8
Fix two variable binding issues in lint let_underscore Fixes #119696 Fixes #119697
2024-01-08Make inductive cycles in coherence ambiguous alwaysMichael Goulet-0/+5
2024-01-08Fix 2 variable binding issues in let_underscoreyukang-1/+8
2024-01-06rustc_span: Optimize syntax context comparisonsVadim Petrochenkov-3/+6
Including comparisons with root context
2024-01-05Auto merge of #119192 - michaelwoerister:mcp533-push, r=cjgillotbors-10/+11
Replace a number of FxHashMaps/Sets with stable-iteration-order alternatives This PR replaces almost all of the remaining `FxHashMap`s in query results with either `FxIndexMap` or `UnordMap`. The only case that is missing is the `EffectiveVisibilities` struct which turned out to not be straightforward to transform. Once that is done too, we can remove the `HashStable` implementation from `HashMap`. The first commit adds the `StableCompare` trait which is a companion trait to `StableOrd`. Some types like `Symbol` can be compared in a cross-session stable way, but their `Ord` implementation is not stable. In such cases, a `StableCompare` implementation can be provided to offer a lightweight way for stable sorting. The more heavyweight option is to sort via `ToStableHashKey`, but then sorting needs to have access to a stable hashing context and `ToStableHashKey` can also be expensive as in the case of `Symbol` where it has to allocate a `String`. The rest of the commits are rather mechanical and don't overlap, so they are best reviewed individually. Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).
2024-01-05Remove outdated references to `librustc_middle`.Alona Enraght-Moony-1/+1
2024-01-05Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errorsMichael Goulet-80/+53
Cleanup error handlers: round 5 More rustc_errors cleanups. A sequel to https://github.com/rust-lang/rust/pull/119171. r? ````@compiler-errors````
2024-01-05Auto merge of #118297 - shepmaster:warn-dead-tuple-fields, r=WaffleLapkinbors-0/+1
Merge `unused_tuple_struct_fields` into `dead_code` This implicitly upgrades the lint from `allow` to `warn` and places it into the `unused` lint group. [Discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Moving.20.60unused_tuple_struct_fields.60.20from.20allow.20to.20warn)
2024-01-04Replace a number of FxHashMaps/Sets with stable-iteration-order alternatives.Michael Woerister-10/+11
2024-01-04Rollup merge of #119195 - asquared31415:named_asm_labels_fix, r=AmanieuMatthias Krüger-13/+49
Make named_asm_labels lint not trigger on unicode and trigger on format args Someone showed me some cursed code that used format args to create named labels, and rustc wasn't linting on that. Additionally while fixing that, I noticed that Unicode alphabetic characters were being used as part of labels, when they are not actually permitted in labels. r? ```@Amanieu```
2024-01-03Remove lots of `rustc_errors::` qualifiers in `lints.rs`.Nicholas Nethercote-63/+36
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-17/+17
`Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods.
2024-01-02Merge `unused_tuple_struct_fields` into `dead_code`Jake Goulding-0/+1
This implicitly upgrades the lint from `allow` to `warn` and places it into the `unused` lint group.
2023-12-31rustc_lint: Enforce `rustc::potential_query_instability` lintMartin Nordholts-1/+13
Stop allowing `rustc::potential_query_instability` on all of `rustc_lint` and instead allow it on a case-by-case basis if it is safe to do so. In this particular crate, all lints were safe to allow.
2023-12-31rustc_lint: Make `LintLevelsProvider::current_specs()` return `&FxIndexMap`Martin Nordholts-17/+17
So that lint iteration order becomes predicitable. Discovered with `rustc::potential_query_instability`.
2023-12-30Move around the code responsible for decorating builtin diagnosticsUrgau-444/+538
2023-12-30Rollup merge of #119425 - Urgau:check-cfg-fix-cargo-diag-bug, r=NilstriebMatthias Krüger-2/+0
Fix invalid check-cfg Cargo feature diagnostic help #118213 added specialized diagnostic for Cargo `feature` cfg. However when providing an empty `#[cfg(feature)]` condition the suggestion would suggest adding `feature` as a feature in `Cargo.toml` (wtf!). This PR removes the invalid logic, which even brings a nice improvement. ```diff --> $DIR/cargo-feature.rs:18:7 | LL | #[cfg(feature)] - | ^^^^^^^ + | ^^^^^^^- help: specify a config value: `= "bitcode"` | = note: expected values for `feature` are: `bitcode` - = help: consider defining `feature` as feature in `Cargo.toml` ``` The first commit add a test showing the bug and the second commit fixes the bug. `@rustbot` label +F-check-cfg
2023-12-30Fix invalid check-cfg Cargo feature diagnostic helpUrgau-2/+0
2023-12-28rustc_lint: Prevent triplication of 'unknown lint' lintMartin Nordholts-23/+23
2023-12-28rustc_lint: Prevent multiple 'incompatible with previous forbid' lintsMartin Nordholts-1/+1
2023-12-28rustc_lint: Prevent multiple 'lint ignored' lintsMartin Nordholts-1/+1
Prevent multiple 'ignored unless specified at crate level' lints. The multiplication happens because we run the same lint three times: * In BuiltinCombinedEarlyLintPass * In BuiltinCombinedPreExpansionLintPass * In shallow_lint_levels_on Only run the lint one time by checking the `lint_added_lints` bool.
2023-12-28rustc_lint: Rename `warn_about_weird_lints` to `lint_added_lints`Martin Nordholts-8/+8
So we can apply more kinds of lints to added lints without having to add another parameter.
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-14/+17
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-23Auto merge of #119211 - rust-lang:pa-master-1.77, r=Mark-Simulacrumbors-1/+0
Bump stage0 to 1.76 beta r? `@Mark-Simulacrum`
2023-12-22update cfg(bootstrap)sPietro Albini-1/+0
2023-12-21Make named_asm_labels lint not trigger on unicode and trigger on format argsasquared31415-13/+49
2023-12-20Undeprecate and use lint `unstable_features`León Orell Valerian Liehr-8/+28
2023-12-19Plumb awaitness of for loopsEric Holk-3/+3
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-2/+2