about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
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-7/+27
2023-12-19Plumb awaitness of for loopsEric Holk-3/+3
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-2/+2
2023-12-15Rollup merge of #118989 - compiler-errors:lint-decorator-2, r=WaffleLapkinJubilee-45/+11
Simplify lint decorator derive too See last commit, since this is stacked on top of #118727. r? WaffleLapkin
2023-12-16Simplify lint decorator derive tooMichael Goulet-45/+11
2023-12-16Remove the lint outrightMichael Goulet-0/+5
2023-12-15Fix commentsMichael Goulet-11/+0
2023-12-15Don't pass lint back out of lint decoratorMichael Goulet-36/+16
2023-12-14Recurse into let bindings if possible in ref casting lintUrgau-1/+6
2023-12-14Refactor and rename some functions in ref casting lintUrgau-40/+54
2023-12-14Extract casting detection logic in it's own functionUrgau-19/+24
2023-12-13Auto merge of #118213 - Urgau:check-cfg-diagnostics-rustc-cargo, r=petrochenkovbors-3/+48
Add more suggestions to unexpected cfg names and values This pull request adds more suggestion to unexpected cfg names and values diagnostics: - it first adds a links to the [rustc unstable book](https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html) or the [Cargo reference](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg), depending if rustc is invoked by Cargo - it secondly adds a suggestion on how to expect the cfg name or value: *excluding well known names and values* - for Cargo: it suggest using a feature or `cargo:rust-check-cfg` in build script - for rustc: it suggest using `--check-cfg` (with the correct invocation) Those diagnostics improvements are directed towards enabling users to fix the issue if the previous suggestions weren't good enough. r? `@petrochenkov`
2023-12-13Add more suggestion to unexpected cfg names and valuesUrgau-3/+48
2023-12-12Move some methods from `tcx.hir()` to `tcx`zetanumbers-4/+4
Renamings: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id Fix rebase changes using removed methods Use `tcx.hir_node_by_def_id()` whenever possible in compiler Fix clippy errors Fix compiler Apply suggestions from code review Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Add FIXME for `tcx.hir()` returned type about its removal Simplify with with `tcx.hir_node_by_def_id`
2023-12-11Auto merge of #117758 - Urgau:lint_pointer_trait_comparisons, r=davidtwcobors-8/+242
Add lint against ambiguous wide pointer comparisons This PR is the resolution of https://github.com/rust-lang/rust/issues/106447 decided in https://github.com/rust-lang/rust/issues/117717 by T-lang. ## `ambiguous_wide_pointer_comparisons` *warn-by-default* The `ambiguous_wide_pointer_comparisons` lint checks comparison of `*const/*mut ?Sized` as the operands. ### Example ```rust let ab = (A, B); let a = &ab.0 as *const dyn T; let b = &ab.1 as *const dyn T; let _ = a == b; ``` ### Explanation The comparison includes metadata which may not be expected. ------- This PR also drops `clippy::vtable_address_comparisons` which is superseded by this one. ~~One thing: is the current naming right? `invalid` seems a bit too much.~~ Fixes https://github.com/rust-lang/rust/issues/117717
2023-12-11Auto merge of #118661 - fee1-dead-contrib:restore-const-partialEq, ↵bors-1/+0
r=compiler-errors Restore `const PartialEq` And thus fixes a number of tests. There is a bug that still needs to be fixed, so WIP for now. r? `@compiler-errors`
2023-12-11Add spacing information to delimiters.Nicholas Nethercote-1/+1
This is an extension of the previous commit. It means the output of something like this: ``` stringify!(let a: Vec<u32> = vec![];) ``` goes from this: ``` let a: Vec<u32> = vec![] ; ``` With this PR, it now produces this string: ``` let a: Vec<u32> = vec![]; ```
2023-12-10Auto merge of #118692 - surechen:remove_unused_imports, r=petrochenkovbors-4/+0
remove redundant imports detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR. r? `@petrochenkov`
2023-12-10Revert "Don't print host effect param in pretty path_generic_args"Deadbeef-1/+0
This reverts commit f1bf874fb13703d706fc8184407c6df12555d8e9.
2023-12-10remove redundant importssurechen-4/+0
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-09Don't print host effect param in pretty path_generic_argsMichael Goulet-0/+1
2023-12-08Rename some more coro_kind -> coroutine_kindMichael Goulet-4/+5
2023-12-08Introduce closure_id method on CoroutineKindMichael Goulet-8/+2
2023-12-08Auto merge of #118420 - compiler-errors:async-gen, r=eholkbors-12/+11
Introduce support for `async gen` blocks I'm delighted to demonstrate that `async gen` block are not very difficult to support. They're simply coroutines that yield `Poll<Option<T>>` and return `()`. **This PR is WIP and in draft mode for now** -- I'm mostly putting it up to show folks that it's possible. This PR needs a lang-team experiment associated with it or possible an RFC, since I don't think it falls under the jurisdiction of the `gen` RFC that was recently authored by oli (https://github.com/rust-lang/rfcs/pull/3513, https://github.com/rust-lang/rust/issues/117078). ### Technical note on the pre-generator-transform yield type: The reason that the underlying coroutines yield `Poll<Option<T>>` and not `Poll<T>` (which would make more sense, IMO, for the pre-transformed coroutine), is because the `TransformVisitor` that is used to turn coroutines into built-in state machine functions would have to destructure and reconstruct the latter into the former, which requires at least inserting a new basic block (for a `switchInt` terminator, to match on the `Poll` discriminant). This does mean that the desugaring (at the `rustc_ast_lowering` level) of `async gen` blocks is a bit more involved. However, since we already need to intercept both `.await` and `yield` operators, I don't consider it much of a technical burden. r? `@ghost`
2023-12-08Make some matches exhaustive to avoid bugs, fix toolsMichael Goulet-12/+11
2023-12-08coro_kind -> coroutine_kindMichael Goulet-2/+2
2023-12-08Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errorsbors-11/+15
never_patterns: Parse match arms with no body Never patterns are meant to signal unreachable cases, and thus don't take bodies: ```rust let ptr: *const Option<!> = ...; match *ptr { None => { foo(); } Some(!), } ``` This PR makes rustc accept the above, and enforces that an arm has a body xor is a never pattern. This affects parsing of match arms even with the feature off, so this is delicate. (Plus this is my first non-trivial change to the parser). ~~The last commit is optional; it introduces a bit of churn to allow the new suggestions to be machine-applicable. There may be a better solution? I'm not sure.~~ EDIT: I removed that commit r? `@compiler-errors`