about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
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`
2023-12-06Rollup merge of #118504 - compiler-errors:must-use, r=WaffleLapkinMatthias Krüger-1/+1
Enforce `must_use` on associated types and RPITITs that have a must-use trait in bounds Warn when an RPITIT or (un-normalized) associated type with a `#[must_use]` trait in its bounds is unused. This is pending T-lang approval, since it changes the semantics of the `#[must_use]` attribute slightly, but I think it strictly catches more strange errors. I could also limit this to just RPITITs, but that seems less useful. Fixes #118444
2023-12-06Auto merge of #118605 - fee1-dead-contrib:rm-rustc_host, r=compiler-errorsbors-3/+3
Remove `#[rustc_host]`, use internal desugaring Also removed a way for users to explicitly specify the host param since that isn't particularly useful. This should eliminate any pain with encoding attributes across crates and etc. r? `@compiler-errors`
2023-12-06Add warn-by-default lint against ambiguous wide pointer comparisonsUrgau-8/+242
2023-12-05Remove `#[rustc_host]`, use internal desugaringDeadbeef-3/+3
2023-12-04Option<CoroutineKind>Eric Holk-4/+8
2023-12-04Merge Async and Gen into CoroutineKindEric Holk-2/+6
2023-12-03Parse a pattern with no armNadrieril-11/+15
2023-12-02Auto merge of #118470 - nnethercote:cleanup-error-handlers, r=compiler-errorsbors-1/+1
Cleanup error handlers Mostly by making function naming more consistent. More to do after this, but this is enough for one PR. r? compiler-errors
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-1/+1
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
2023-12-01vis note for no pub reexports glob importbohan-0/+4
2023-11-30Enforce must_use on associated types and RPITITsMichael Goulet-1/+1
2023-11-29Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errorsMatthias Krüger-1/+1
Add `never_patterns` feature gate This PR adds the feature gate and most basic parsing for the experimental `never_patterns` feature. See the tracking issue (https://github.com/rust-lang/rust/issues/118155) for details on the experiment. `@scottmcm` has agreed to be my lang-team liaison for this experiment.
2023-11-29Add `never_patterns` feature gateNadrieril-1/+1
2023-11-28Rename `BinOpKind::lazy` as `BinOpKind::is_lazy`.Nicholas Nethercote-2/+2
To match `BinOpKind::is_comparison` and `hir::BinOpKind::is_lazy`.
2023-11-26rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` ↵Vadim Petrochenkov-2/+2
cleanup
2023-11-25Rollup merge of #118288 - compiler-errors:is_some_and, r=lqd,dtolnayMichael Goulet-1/+1
Use `is_{some,ok}_and` more in the compiler slightly more fluent-reading code
2023-11-25Rollup merge of #118158 - nnethercote:reduce-fluent-boilerplate, ↵Michael Goulet-3/+1
r=compiler-errors Reduce fluent boilerplate Best reviewed one commit at a time. r? `@davidtwco`
2023-11-26Use `rustc_fluent_macro::fluent_messages!` directly.Nicholas Nethercote-2/+1
Currently we always do this: ``` use rustc_fluent_macro::fluent_messages; ... fluent_messages! { "./example.ftl" } ``` But there is no need, we can just do this everywhere: ``` rustc_fluent_macro::fluent_messages! { "./example.ftl" } ``` which is shorter.
2023-11-26Avoid need for `{D,Subd}iagnosticMessage` imports.Nicholas Nethercote-1/+0
The `fluent_messages!` macro produces uses of `crate::{D,Subd}iagnosticMessage`, which means that every crate using the macro must have this import: ``` use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; ``` This commit changes the macro to instead use `rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the imports.
2023-11-25Rollup merge of #118017 - tamird:better-safety, r=cjgillotGuillaume Gomez-4/+7
rustc_lint: address latent TODO See individual commits.
2023-11-25is_{some,ok}_andMichael Goulet-1/+1
2023-11-24Replace `option.map(cond) == Some(true)` with `option.is_some_and(cond)`David Tolnay-10/+6
2023-11-22Rework supertrait lint once againMichael Goulet-21/+35
2023-11-22rustc_session: implement latent TODOTamir Duberstein-3/+7