summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2024-03-04Improve wording of static_mut_refObei Sideg-0/+1
Rename `static_mut_ref` lint to `static_mut_refs`. (cherry picked from commit 408eeae59d35cbcaab2cfb345d24373954e74fc5)
2024-02-08[Beta 1.77] Fix bootstrapping from 1.76Eric Huss-1/+1
2024-01-31Auto merge of #120346 - petrochenkov:ownodes, r=oli-obkbors-1/+1
hir: Refactor getters for owner nodes
2024-01-30hir: Remove `hir::Map::{owner,expect_owner}`Vadim Petrochenkov-1/+1
2024-01-30add missing potential_query_instability for keys and values in hashmapyukang-6/+9
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-10/+10
Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
2024-01-26Rollup merge of #120360 - compiler-errors:afit-sized-lol, r=lcnrMatthias Krüger-1/+12
Don't fire `OPAQUE_HIDDEN_INFERRED_BOUND` on sized return of AFIT Conceptually, we should probably not fire `OPAQUE_HIDDEN_INFERRED_BOUND` for methods like: ``` trait Foo { async fn bar() -> Self; } ``` Even though we technically cannot prove that `Self: Sized`, which is one of the item bounds of the `Output` type in the `-> impl Future<Output = Sized>` from the async desugaring. This is somewhat justifiable along the same lines as how we allow regular methods to return `-> Self` even though `Self` isn't sized. Fixes #113538 (side-note: some days i wonder if we should just remove the `OPAQUE_HIDDEN_INFERRED_BOUND` lint... it does make me sad that we have non-well-formed types in signatures, though.)
2024-01-25Remove unused featuresclubby789-3/+0
2024-01-25Don't fire OPAQUE_HIDDEN_INFERRED_BOUND on sized return of AFITMichael Goulet-1/+12
2024-01-23address requested changesHTGAzureX1212.-6/+8
2024-01-23add list of characters to uncommon codepoints lintHTGAzureX1212.-2/+13
2024-01-23Auto merge of #120017 - nnethercote:lint-api, r=oli-obkbors-165/+155
Fix naming in the lint API Methods for emit lints are named very inconsistently. This PR fixes that up. r? `@compiler-errors`
2024-01-22Rollup merge of #120233 - oli-obk:revert_trait_obj_upcast_stabilization, r=lcnrMatthias Krüger-3/+12
Revert stabilization of trait_upcasting feature Reverts #118133 This reverts commit 6d2b84b3ed7848fd91b8d6151d4451b3103ed816, reversing changes made to 73bc12199ea8c7651ed98b069c0dd6b0bb5fabcf. The feature has a soundness bug: * #120222 It is unclear to me whether we'll actually want to destabilize, but I thought it was still prudent to open the PR for easy destabilization once we get there.
2024-01-23Rename `struct_lint_level` as `lint_level`.Nicholas Nethercote-10/+10
2024-01-23Rename `TyCtxt::emit_spanned_lint` as `TyCtxt::emit_node_span_lint`.Nicholas Nethercote-3/+3
2024-01-23Rename `TyCtxt::struct_span_lint_hir` as `TyCtxt::node_span_lint`.Nicholas Nethercote-1/+1
2024-01-23Rename `TyCtxt::struct_lint_node` as `TyCtxt::node_lint`.Nicholas Nethercote-1/+1
2024-01-23Rename `LintLevelsBuilder::emit_spanned_lint` as ↵Nicholas Nethercote-7/+7
`LintLevelsBuilder::emit_span_lint`.
2024-01-23Rename `LintLevelsBuilder::struct_lint` as `LintLevelsBuilder::opt_span_lint`.Nicholas Nethercote-2/+2
2024-01-23Rename `LintContext::emit_spanned_lint` as `LintContext::emit_span_lint`.Nicholas Nethercote-128/+112
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-7/+27
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/+65
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/+65
- 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-12/+24
Check rust lints when an unknown lint is detected Fixes #118183
2024-01-12check rust lints when an unknown lint is detectedyukang-12/+24
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-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```