summary refs log tree commit diff
path: root/compiler/rustc_lint_defs/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2024-01-04Split StableCompare trait out of StableOrd trait.Michael Woerister-1/+11
StableCompare 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 `StableOrd` 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`.)
2023-12-12Rollup merge of #117927 - ehuss:future-incompat-docs, r=wesleywiserMatthias Krüger-0/+67
Clarify how to choose a FutureIncompatibilityReason variant. There has been some confusion about how to choose these variants, or what the procedure is for handling future-incompatible errors. Hopefully this helps provide some more information on how these work.
2023-12-01vis note for no pub reexports glob importbohan-0/+4
2023-11-14Clarify how to choose a FutureIncompatibilityReason variant.Eric Huss-0/+67
There has been some confusion about how to choose these variants, or what the procedure is for handling future-incompatible errors. Hopefully this helps provide some more information on how these work.
2023-11-04Remove support for compiler plugins.Nicholas Nethercote-4/+4
They've been deprecated for four years. This commit includes the following changes. - It eliminates the `rustc_plugin_impl` crate. - It changes the language used for lints in `compiler/rustc_driver_impl/src/lib.rs` and `compiler/rustc_lint/src/context.rs`. External lints are now called "loaded" lints, rather than "plugins" to avoid confusion with the old plugins. This only has a tiny effect on the output of `-W help`. - E0457 and E0498 are no longer used. - E0463 is narrowed, now only relating to unfound crates, not plugins. - The `plugin` feature was moved from "active" to "removed". - It removes the entire plugins chapter from the unstable book. - It removes quite a few tests, mostly all of those in `tests/ui-fulldeps/plugin/`. Closes #29597.
2023-09-28Remove `rustc_lint_defs::lint_array`DaniPopes-11/+2
2023-09-22make the reason: field mandatory for @future_incompatible lintsRalf Jung-1/+5
2023-09-22give FutureIncompatibilityReason variants more explicit namesRalf Jung-5/+11
2023-09-06Change unsafe_op_in_unsafe_fn to be warn-by-default from edition 2024Wim Looman-16/+4
2023-08-22Auto merge of #115104 - compiler-errors:rollup-8235xz5, r=compiler-errorsbors-0/+4
Rollup of 6 pull requests Successful merges: - #114959 (fix #113702 emit a proper diagnostic message for unstable lints passed from CLI) - #115011 (Warn on elided lifetimes in associated constants (`ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT`)) - #115077 (Do not emit invalid suggestion in E0191 when spans overlap) - #115087 (Add disclaimer on size assertion macro) - #115090 (Always use `os-release` rather than `/lib` to detect `NixOS` (bootstrap)) - #115101 (triagebot: add dependency licensing pings) r? `@ghost` `@rustbot` modify labels: rollup
2023-08-21Redefine the pluralize macro's armallaboutevemirolive-1/+2
2023-08-20Warn on elided lifetimes in associated constantsMichael Goulet-0/+4
2023-07-29fix(resolve): update the ambiguity glob binding as warning recursivelybohan-0/+18
2023-07-18Fix removal span calculation of unused_qualifications suggestion许杰友 Jieyou Xu (Joe)-4/+2
2023-07-13Add machine-applicable suggestion for `unused_qualifications` lint许杰友 Jieyou Xu (Joe)-0/+6
2023-05-27Add warn-by-default lint for local binding shadowing exported glob re-export ↵许杰友 Jieyou Xu (Joe)-0/+10
item
2023-05-05Improve check-cfg diagnostics (part 2)Urgau-1/+2
2023-04-10Fix typos in compilerDaniPopes-1/+1
2023-03-20Lint ambiguous glob re-exports许杰友 Jieyou Xu (Joe)-0/+10
2023-03-11Rollup merge of #108806 - cjgillot:query-lints, r=davidtwcoMatthias Krüger-2/+5
Querify register_tools and post-expansion early lints The 2 extra queries correspond to code that happen before and after macro expansion, and don't need the resolver to exist.
2023-03-06Querify early_lint_checks.Camille GILLOT-1/+2
2023-03-06Querify registered_tools.Camille GILLOT-1/+3
2023-02-22Move the unused extern crate check back to the resolver.Camille GILLOT-0/+7
2023-01-30Allow more deriving on packed structs.Nicholas Nethercote-0/+1
Currently, deriving on packed structs has some non-trivial limitations, related to the fact that taking references on unaligned fields is UB. The current approach to field accesses in derived code: - Normal case: `&self.0` - In a packed struct that derives `Copy`: `&{self.0}` - In a packed struct that doesn't derive `Copy`: `&self.0` Plus, we disallow deriving any builtin traits other than `Default` for any packed generic type, because it's possible that there might be misaligned fields. This is a fairly broad restriction. Plus, we disallow deriving any builtin traits other than `Default` for most packed types that don't derive `Copy`. (The exceptions are those where the alignments inherently satisfy the packing, e.g. in a type with `repr(packed(N))` where all the fields have alignments of `N` or less anyway. Such types are pretty strange, because the `packed` attribute is not having any effect.) This commit introduces a new, simpler approach to field accesses: - Normal case: `&self.0` - In a packed struct: `&{self.0}` In the latter case, this requires that all fields impl `Copy`, which is a new restriction. This means that the following example compiles under the old approach and doesn't compile under the new approach. ``` #[derive(Debug)] struct NonCopy(u8); #[derive(Debug) #[repr(packed)] struct MyType(NonCopy); ``` (Note that the old approach's support for cases like this was brittle. Changing the `u8` to a `u16` would be enough to stop it working. So not much capability is lost here.) However, the other constraints from the old rules are removed. We can now derive builtin traits for packed generic structs like this: ``` trait Trait { type A; } #[derive(Hash)] #[repr(packed)] pub struct Foo<T: Trait>(T, T::A); ``` To allow this, we add a `T: Copy` bound in the derived impl and a `T::A: Copy` bound in where clauses. So `T` and `T::A` must impl `Copy`. We can now also derive builtin traits for packed structs that don't derive `Copy`, so long as the fields impl `Copy`: ``` #[derive(Hash)] #[repr(packed)] pub struct Foo(u32); ``` This includes types that hand-impl `Copy` rather than deriving it, such as the following, that show up in winapi-0.2: ``` #[derive(Clone)] #[repr(packed)] struct MyType(i32); impl Copy for MyType {} ``` The new approach is simpler to understand and implement, and it avoids the need for the `unsafe_derive_on_repr_packed` check. One exception is required for backwards-compatibility: we allow `[u8]` fields for now. There is a new lint for this, `byte_slice_in_packed_struct_with_derive`.
2023-01-21Rollup merge of #106935 - TaKO8Ki:fix-104440, r=cjgillotMichael Goulet-1/+1
Fix `SingleUseLifetime` ICE Fixes #104440 cc: ``@matthiaskrgr``
2023-01-19Use UnordMap instead of FxHashMap in define_id_collections!().Michael Woerister-2/+3
2023-01-16fix #104440Takayuki Maeda-1/+1
2023-01-10create helper function for `rustc_lint_defs::Level` and remove it's ↵ozkanonur-0/+13
duplicated code r=ozkanonur Signed-off-by: ozkanonur <work@onurozkan.dev>
2022-10-07Rewrite representabilityCameron Steffen-0/+3
2022-10-01Compute `lint_levels` by definitionDeadbeef-5/+26
2022-09-22Revert "Auto merge of #101620 - cjgillot:compute_lint_levels_by_def, r=oli-obk"Camille GILLOT-26/+5
This reverts commit 2cb9a65684dba47c52de8fa938febf97a73e70a9, reversing changes made to 750bd1a7ff3e010611b97ee75d30b7cbf5f3a03c.
2022-09-14Compute `lint_levels` by definitionDeadbeef-5/+26
2022-09-12Allow tool-lints to specify a feature-gate tooWim Looman-3/+7
2022-08-28Suggest calling when operator types mismatchMichael Goulet-1/+2
2022-08-22Tidyfinalchild-1/+1
2022-08-22Migrate deprecated_where_clause_location, forbidden_assoc_constraint, ↵finalchild-2/+2
keyword_lifetime, invalid_label, invalid_visibility
2022-08-22Use DiagnosticMessage for BufferedEarlyLint.msgfinalchild-4/+4
2022-08-18Add diagnostic translation lints to crates that don't emit them5225225-0/+2
2022-08-02Improve position named arguments lint underline and formatting namesPreston From-1/+13
For named arguments used as implicit position arguments, underline both the opening curly brace and either: * if there is formatting, the next character (which will either be the closing curl brace or the `:` denoting the start of formatting args) * if there is no formatting, the entire arg span (important if there is whitespace like `{ }`) This should make it more obvious where the named argument should be. Additionally, in the lint message, emit the formatting argument names without a dollar sign to avoid potentially confusion. Fixes #99907
2022-07-25Generate correct suggestion with named arguments used positionallyPreston From-1/+1
Address issue #99265 by checking each positionally used argument to see if the argument is named and adding a lint to use the name instead. This way, when named arguments are used positionally in a different order than their argument order, the suggested lint is correct. For example: ``` println!("{b} {}", a=1, b=2); ``` This will now generate the suggestion: ``` println!("{b} {a}", a=1, b=2); ``` Additionally, this check now also correctly replaces or inserts only where the positional argument is (or would be if implicit). Also, width and precision are replaced with their argument names when they exists. Since the issues were so closely related, this fix for issue #99265 also fixes issue #99266. Fixes #99265 Fixes #99266
2022-07-20avoid a `Symbol` to `String` conversionTakayuki Maeda-1/+1
2022-07-15Only suggest if span is not erroneousMichael Goulet-1/+1
2022-07-13Emit warning when named arguments are used positionally in formatPreston From-0/+1
Addresses Issue 98466 by emitting a warning if a named argument is used like a position argument (i.e. the name is not used in the string to be formatted). Fixes rust-lang#98466
2022-07-07Rollup merge of #98507 - xFrednet:rfc-2383-manual-expectation-magic, ↵Dylan DPC-0/+7
r=wesleywiser Finishing touches for `#[expect]` (RFC 2383) This PR adds documentation and some functionality to rustc's lint passes, to manually fulfill expectations. This is needed for some lints in Clippy. Hopefully, it should be one of the last things before we can move forward with stabilizing this feature. As part of this PR, I've also updated `clippy::duplicate_mod` to showcase how this new functionality can be used and to ensure that it works correctly. --- changelog: [`duplicate_mod`]: Fixed lint attribute interaction r? `@wesleywiser` cc: https://github.com/rust-lang/rust/issues/97660, https://github.com/rust-lang/rust/issues/85549 And I guess that's it. Here have a magical unicorn :unicorn:
2022-07-06Add function to manually fulfill lint expectations (RFC 2383)xFrednet-0/+7
2022-06-22add "was" to pluralize macro and use itTakayuki Maeda-0/+3
2022-06-16Support lint expectations for `--force-warn` lints (RFC 2383)xFrednet-4/+10
2022-06-03Use serde_json for json error messagesbjorn3-1/+3
2022-05-20Lint single-use-lifetimes on the AST.Camille GILLOT-1/+15
2022-04-27Plumb through rustc_lint_defs::Level as enum rather than string.Jeremy Fitzhardinge-0/+7