about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2025-01-23Split hir `TyKind` and `ConstArgKind` in two and update `hir::Visitor`Boxy-25/+21
2025-01-23Make `hir::TyKind::TraitObject` use tagged ptrBoxy-1/+3
2025-01-22Rollup merge of #132983 - Anthony-Eid:dangling-pointers-lint, r=UrgauMatthias Krüger-1/+3
Edit dangling pointers Closes: #132283
2025-01-22[AIX] Lint on structs that have a different alignment in AIX's C ABIAmy Kwan-5/+133
2025-01-21remove long-deprecated no-op attributes no_start and crate_idRalf Jung-21/+2
2025-01-19Run `clippy --fix` for `unnecessary_map_or` lintYotam Ofek-1/+1
2025-01-16Rollup merge of #135249 - s-cerevisiae:fix-overflowing-literals-help, ↵Matthias Krüger-8/+23
r=chenyukang Fix overflows in the implementation of `overflowing_literals` lint's help This PR fixes two overflow problems that cause the `overflowing_literals` lint to behave incorrectly in some edge cases. 1. When an integer literal is between `i128::MAX` and `u128::MAX`, an overflowing `as` cast can cause the suggested type to be overly small. It's fixed by using checked type conversion and returning `u128` when it's the only choice. (Fixes #135248) 2. When an integer literal is `i128::MIN` but is of a smaller type, an overflowing negation cause the compiler to panic in debug build. Fixed by checking the number size beforehand and `wrapping_neg`. (Fixes #131849) Edit: extracted the type conversion part into a standalone function to separate the concern of overflowing.
2025-01-13Rollup merge of #135441 - compiler-errors:redundant-captures-lint, r=lqdJacob Pratt-1/+1
Make sure to mark `IMPL_TRAIT_REDUNDANT_CAPTURES` as `Allow` in edition 2024 I never got sign-off on #127672 for this lint being warn by default in edition 2024, so let's turn downgrade this lint to allow for now. Should be backported so it ships with the edition. ```@rustbot``` label: +beta-nominated
2025-01-13Make sure to mark IMPL_TRAIT_REDUNDANT_CAPTURES as Allow in edition 2024Michael Goulet-1/+1
2025-01-12Update unstable lint docs to include required feature attributesAditya-PS-05-0/+1
2025-01-12Suggest the smallest fitting type insteadspore-2/+2
Changes the behavior of the `overflowing_literals` suggestion so that it always suggest the smallest type regardless of the original type size.
2025-01-11Minor simplificationspore-1/+1
Apply eta-reduction on map to simplify code and make the style more consistent
2025-01-09Auto merge of #135268 - pietroalbini:pa-bump-stage0, r=Mark-Simulacrumbors-1/+1
Master bootstrap update Part of the release process. r? `@Mark-Simulacrum`
2025-01-09Rollup merge of #135269 - estebank:unneeded-into, r=compiler-errorsMatthias Krüger-3/+3
Remove some unnecessary `.into()` calls
2025-01-09Rollup merge of #135212 - Urgau:unreach_pub-upd-descr, r=petrochenkovMatthias Krüger-3/+2
Remove outdated information in the `unreachable_pub` lint description As far as I understand the `unreachable_pub` lint hasn't had false-positives since it started using "effective visibilities". Let's remove that warning from the lint description. r? `@petrochenkov`
2025-01-08Remove some unnecessary `.into()` callsEsteban Küber-3/+3
2025-01-08update cfg(bootstrap)Pietro Albini-1/+1
2025-01-09Extract integer conversion into a functionspore-16/+22
2025-01-08Detect overflow when the literal is negativespore-1/+7
2025-01-08Detect overflow when the literal is larger than i128::MAXspore-4/+7
2025-01-08Rename PatKind::Lit to ExprOli Scherer-1/+1
2025-01-07Remove outdated information in the `unreachable_pub` lint descriptionUrgau-3/+2
2025-01-07Avoid naming variables `str`Josh Triplett-3/+3
This renames variables named `str` to other names, to make sure `str` always refers to a type. It's confusing to read code where `str` (or another standard type name) is used as an identifier. It also produces misleading syntax highlighting.
2025-01-05Mention `unnameable_types` in `unreachable_pub` documentation.Kevin Reid-3/+5
This link makes sense because someone who wishes to avoid unusable `pub` is likely, but not guaranteed, to be interested in avoiding unnameable types. Also fixed some grammar problems I noticed in the area. Fixes #116604.
2025-01-04turn hir::ItemKind::Fn into a named-field variantRalf Jung-3/+3
2025-01-01Rollup merge of #134979 - estebank:default-lint-sugg, r=compiler-errorsStuart Cook-8/+26
Provide structured suggestion for `impl Default` of type where all fields have defaults ``` error: `Default` impl doesn't use the declared default field values --> $DIR/manual-default-impl-could-be-derived.rs:28:1 | LL | / impl Default for B { LL | | fn default() -> Self { LL | | B { LL | | x: s(), | | --- this field has a default value LL | | y: 0, | | - this field has a default value ... | LL | | } | |_^ | help: to avoid divergence in behavior between `Struct { .. }` and `<Struct as Default>::default()`, derive the `Default` | LL ~ #[derive(Default)] struct B { | ``` Note that above the structured suggestion also includes completely removing the manual `impl`, but the rendering doesn't.
2024-12-31Provide structured suggestion for `impl Default` of type where all fields ↵Esteban Küber-8/+26
have defaults ``` error: `Default` impl doesn't use the declared default field values --> $DIR/manual-default-impl-could-be-derived.rs:28:1 | LL | / impl Default for B { LL | | fn default() -> Self { LL | | B { LL | | x: s(), | | --- this field has a default value LL | | y: 0, | | - this field has a default value ... | LL | | } | |_^ | help: to avoid divergence in behavior between `Struct { .. }` and `<Struct as Default>::default()`, derive the `Default` | LL ~ #[derive(Default)] struct B { | ``` Note that above the structured suggestion also includes completely removing the manual `impl`, but the rendering doesn't.
2024-12-31Account for format_args in HiddenUnicodeCodepoints lintMichael Goulet-26/+34
2024-12-31Account for C string literals in HiddenUnicodeCodepoints lintMichael Goulet-5/+19
2024-12-28Rollup merge of #134737 - estebank:deive-lint-default-fields-base, ↵Stuart Cook-0/+188
r=compiler-errors Implement `default_overrides_default_fields` lint Detect when a manual `Default` implementation isn't using the existing default field values and suggest using `..` instead: ``` error: `Default` impl doesn't use the declared default field values --> $DIR/manual-default-impl-could-be-derived.rs:14:1 | LL | / impl Default for A { LL | | fn default() -> Self { LL | | A { LL | | y: 0, | | - this field has a default value ... | LL | | } | |_^ | = help: use the default values in the `impl` with `Struct { mandatory_field, .. }` to avoid them diverging over time note: the lint level is defined here --> $DIR/manual-default-impl-could-be-derived.rs:5:9 | LL | #![deny(default_overrides_default_fields)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` r? `@compiler-errors` This is a simpler version of #134441, detecting the simpler case when a field with a default should have not been specified in the manual `Default::default()`, instead using `..` for it. It doesn't provide any suggestions, nor the checks for "equivalences" nor whether the value used in the imp being used would be suitable as a default field value.
2024-12-25Implement `default_overrides_default_fields` lintEsteban Küber-0/+188
Detect when a manual `Default` implementation isn't using the existing default field values and suggest using `..` instead: ``` error: `Default` impl doesn't use the declared default field values --> $DIR/manual-default-impl-could-be-derived.rs:14:1 | LL | / impl Default for A { LL | | fn default() -> Self { LL | | A { LL | | y: 0, | | - this field has a default value ... | LL | | } | |_^ | = help: use the default values in the `impl` with `Struct { mandatory_field, .. }` to avoid them diverging over time note: the lint level is defined here --> $DIR/manual-default-impl-could-be-derived.rs:5:9 | LL | #![deny(default_overrides_default_fields)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ```
2024-12-24Auto merge of #134625 - compiler-errors:unsafe-binders-ty, r=oli-obkbors-0/+2
Begin to implement type system layer of unsafe binders Mostly TODOs, but there's a lot of match arms that are basically just noops so I wanted to split these out before I put up the MIR lowering/projection part of this logic. r? oli-obk Tracking: - https://github.com/rust-lang/rust/issues/130516
2024-12-23Use `#[derive(Default)]` instead of manually implementing itEsteban Küber-6/+1
2024-12-22Begin to implement type system layer of unsafe bindersMichael Goulet-0/+2
2024-12-21Rollup merge of #134586 - Urgau:fn-ptr-lint-option, r=compiler-errorsMatthias Krüger-2/+20
Also lint on option of function pointer comparisons This PR is the first part of #134536, ie. the linting on `Option<{fn ptr}>` in the `unpredictable_function_pointer_comparisons` lint, which isn't part of the lang nomination that the second part is going trough, and so should be able to be approved independently. Related to https://github.com/rust-lang/rust/issues/134527 r? `@compiler-errors`
2024-12-20Also lint on option of function pointer comparisonsUrgau-2/+20
2024-12-19Auto merge of #133961 - lcnr:borrowck-cleanup, r=jackh726bors-3/+3
cleanup region handling: add `LateParamRegionKind` The second commit is to enable a split between `BoundRegionKind` and `LateParamRegionKind`, by avoiding `BoundRegionKind` where it isn't necessary. The third comment then adds `LateParamRegionKind` to avoid having the same late-param region for separate bound regions. This fixes #124021. r? `@compiler-errors`
2024-12-18Rollup merge of #134481 - estebank:unstable-lint-span, r=compiler-errorsJacob Pratt-1/+1
Point at lint name instead of whole attr for gated lints ``` warning: unknown lint: `test_unstable_lint` --> $DIR/warn-unknown-unstable-lint-inline.rs:4:10 | LL | #![allow(test_unstable_lint, another_unstable_lint)] | ^^^^^^^^^^^^^^^^^^ | = note: the `test_unstable_lint` lint is unstable = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date note: the lint level is defined here --> $DIR/warn-unknown-unstable-lint-inline.rs:3:9 | LL | #![warn(unknown_lints)] | ^^^^^^^^^^^^^ warning: unknown lint: `test_unstable_lint` --> $DIR/warn-unknown-unstable-lint-inline.rs:4:29 | LL | #![allow(test_unstable_lint, another_unstable_lint)] | ^^^^^^^^^^^^^^^^^^^^^ | = note: the `another_unstable_lint` lint is unstable = help: add `#![feature(another_unstable_lint)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date ``` This is particularly relevant when there are multiple lints in the same `warn` attribute. Pointing at the smaller span makes it clearer which one the warning is complaining about.
2024-12-18Point at lint name instead of whole attr for gated lintsEsteban Küber-1/+1
``` warning: unknown lint: `test_unstable_lint` --> $DIR/warn-unknown-unstable-lint-inline.rs:4:10 | LL | #![allow(test_unstable_lint, another_unstable_lint)] | ^^^^^^^^^^^^^^^^^^ | = note: the `test_unstable_lint` lint is unstable = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date note: the lint level is defined here --> $DIR/warn-unknown-unstable-lint-inline.rs:3:9 | LL | #![warn(unknown_lints)] | ^^^^^^^^^^^^^ warning: unknown lint: `test_unstable_lint` --> $DIR/warn-unknown-unstable-lint-inline.rs:4:29 | LL | #![allow(test_unstable_lint, another_unstable_lint)] | ^^^^^^^^^^^^^^^^^^^^^ | = note: the `test_unstable_lint` lint is unstable = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date note: the lint level is defined here --> $DIR/warn-unknown-unstable-lint-inline.rs:3:9 | LL | #![warn(unknown_lints)] | ^^^^^^^^^^^^^ ``` This is particularly relevant when there are multiple lints in the same `warn` attribute. Pointing at the smaller span makes it clearer which one the warning is complaining about.
2024-12-18Auto merge of #134443 - joshtriplett:use-field-init-shorthand, ↵bors-1/+1
r=lqd,tgross35,nnethercote Use field init shorthand where possible Field init shorthand allows writing initializers like `tcx: tcx` as `tcx`. The compiler already uses it extensively. Fix the last few places where it isn't yet used. EDIT: this PR also updates `rustfmt.toml` to set `use_field_init_shorthand = true`.
2024-12-18introduce `LateParamRegionKind`lcnr-3/+3
2024-12-18Rollup merge of #134460 - oli-obk:push-ysuklyupnzpq, r=jieyouxu许杰友 Jieyou Xu (Joe)-21/+5
Merge some patterns together just something I noticed while browsing code. No change in functionality, deduplicates the 100% equal match arms by creating one big or pattern
2024-12-18Rollup merge of #134161 - nnethercote:overhaul-token-cursors, r=spastorino许杰友 Jieyou Xu (Joe)-2/+2
Overhaul token cursors Some nice cleanups here. r? `````@davidtwco`````
2024-12-18Merge some patterns togetherOli Scherer-21/+5
2024-12-18Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxubors-41/+24
Re-export more `rustc_span::symbol` things from `rustc_span`. `rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers to `rustc_span::`. This is a 300+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one. r? `@jieyouxu`
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-41/+24
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-18Rename `RefTokenTreeCursor`.Nicholas Nethercote-2/+2
Because `TokenStreamIter` is a much better name for a `TokenStream` iterator. Also rename the `TokenStream::trees` method as `TokenStream::iter`, and some local variables.
2024-12-17Use field init shorthand where possibleJosh Triplett-1/+1
Field init shorthand allows writing initializers like `tcx: tcx` as `tcx`. The compiler already uses it extensively. Fix the last few places where it isn't yet used.
2024-12-17Rollup merge of #133265 - the8472:extract-if-ranges, r=cuviperMatthias Krüger-2/+2
Add a range argument to vec.extract_if tracking issue: #43244 This adds the range argument requested in https://github.com/rust-lang/rust/issues/43244#issuecomment-2486160659
2024-12-17Auto merge of #134381 - jdonszelmann:move-attribute-types, r=oli-obkbors-8/+7
Split up attribute parsing code and move data types to `rustc_attr_data_structures` This change renames `rustc_attr` to `rustc_attr_parsing`, and splits up the parsing code. At the same time, all the data types used move to `rustc_attr_data_structures`. This is in preparation of also having a third crate: `rustc_attr_validation` I initially envisioned this as two separate PRs, but I think doing it in one go reduces the number of ways others would have to rebase their changes on this. However, I can still split them. r? `@oli-obk` (we already discussed how this is a first step in a larger plan) For a more detailed plan on how attributes are going to change, see https://github.com/rust-lang/rust/issues/131229 Edit: this looks like a giant PR, but the changes are actually rather trivial. Each commit is reviewable on its own, and mostly moves code around. No new logic is added.