about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/context.rs
AgeCommit message (Collapse)AuthorLines
2023-03-20Lint ambiguous glob re-exports许杰友 Jieyou Xu (Joe)-0/+4
2023-02-22Move the unused extern crate check back to the resolver.Camille GILLOT-0/+17
2023-02-19Make public API, docs algorithm-agnosticJacob Pratt-1/+1
2023-02-16Replace some `then`s with some `then_some`sMaybe Waffle-1/+1
2023-02-16`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle-6/+4
2023-02-14Fix #107998, avoid ICE when the generic_span is emptyyukang-1/+9
2023-01-30Allow more deriving on packed structs.Nicholas Nethercote-0/+3
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-16fix #104440Takayuki Maeda-21/+26
2023-01-09refactor: cleanupRejyr-2/+0
2023-01-09add: `#[rustc_lint_diagnostics]` for more `context.rs` functions.Rejyr-0/+5
2022-12-25fix more clippy::style findingsMatthias Krüger-8/+6
match_result_ok obfuscated_if_else single_char_add writeln_empty_string collapsible_match iter_cloned_collect unnecessary_mut_passed
2022-12-21Sort lint_groups in no_lint_suggestionUlrich Weigand-1/+10
The no_lint_suggestion routine passes a vector of lint group names to find_best_match_for_name. That routine depends on the sort order of its input vector, which matters in case multiple inputs are at the same Levenshtein distance to the target name. However, no_lint_suggestion currently just passes lint_groups.keys() as input vector - this is sorted in hash value order, which is not guaranteed to be stable, and in fact differs between big- and little-endian host platforms, causing test failures on s390x. To fix this, always sort the lint groups before using their names as input to find_best_match_for_name. In addition, deprecated lint groups should never be suggested, so filter those out. Fixes https://github.com/rust-lang/rust/issues/105379
2022-12-18don't restuct references just to reborrowMatthias Krüger-5/+5
2022-12-14Remove many more cases of `mk_substs_trait` that can now use the iterator ↵Oli Scherer-1/+1
scheme`
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-1/+1
2022-11-23Move `get_associated_type` from `clippy` to `rustc_lint`Maybe Waffle-0/+17
2022-11-19drive-by: PolyExistentialPredicateMichael Goulet-1/+1
2022-11-07fix: lint against lint functionsRejyr-0/+4
fix: lint against the functions `LintContext::{lookup_with_diagnostics,lookup,struct_span_lint,lint}`, `TyCtxt::struct_lint_node`, `LintLevelsBuilder::struct_lint`.
2022-10-26privacy: Rename "accessibility levels" to "effective visibilities"Vadim Petrochenkov-2/+2
And a couple of other naming tweaks Related to https://github.com/rust-lang/rust/issues/48054
2022-10-12link lint function with `decorate` function param to `struct_lint_level`Maybe Waffle-0/+19
2022-10-01Compute `lint_levels` by definitionDeadbeef-1/+1
2022-10-01`ui-fulldeps`: adopt to the new rustc lint APIMaybe Waffle-1/+1
2022-10-01Refactor rustc lint APIMaybe Waffle-24/+40
2022-09-24separate definitions and `HIR` ownersTakayuki Maeda-1/+1
fix a ui test use `into` fix clippy ui test fix a run-make-fulldeps test implement `IntoQueryParam<DefId>` for `OwnerId` use `OwnerId` for more queries change the type of `ParentOwnerIterator::Item` to `(OwnerId, OwnerNode)`
2022-09-22Revert "Auto merge of #101620 - cjgillot:compute_lint_levels_by_def, r=oli-obk"Camille GILLOT-1/+1
This reverts commit 2cb9a65684dba47c52de8fa938febf97a73e70a9, reversing changes made to 750bd1a7ff3e010611b97ee75d30b7cbf5f3a03c.
2022-09-14Compute `lint_levels` by definitionDeadbeef-1/+1
2022-09-06Allow lint passes to be bound by `TyCtxt`Jason Newcomb-9/+19
2022-09-03more clippy::perf fixesMatthias Krüger-1/+1
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-3/+2
by module
2022-08-26Rollup merge of #100776 - Rejyr:diagnostic-migration-rustc-lint, r=davidtwcoMichael Goulet-58/+35
Migrate `rustc_lint` errors to `SessionDiagnostic` Draft PR for migrating `rustc_lint` to `SessionDiagnostic`, as part of the [recent blog post](https://blog.rust-lang.org/inside-rust/2022/08/16/diagnostic-effort.html)
2022-08-23sugg: take into count the debug formattingVincenzo Palazzo-2/+7
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-08-23cleanup: commented lintsRejyr-3/+0
2022-08-22migrate: `rustc_lint::context`Rejyr-58/+38
2022-08-02Improve position named arguments lint underline and formatting namesPreston From-6/+11
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-2/+2
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-15Only suggest if span is not erroneousMichael Goulet-9/+10
2022-07-15Remove some more usages of guess_head_spanMichael Goulet-2/+1
2022-07-13Emit warning when named arguments are used positionally in formatPreston From-0/+12
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-1/+32
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-1/+32
2022-07-05errors: introduce `DecorateLint`David Wood-1/+21
Add a new trait to be generated by diagnostic derives which uses a `LintDiagnosticBuilder`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-05lint: `LintDiagnosticBuilder` into `rustc_errors`David Wood-2/+1
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-16Rollup merge of #97757 - xFrednet:rfc-2383-expect-with-force-warn, ↵Matthias Krüger-2/+2
r=wesleywiser,flip1995 Support lint expectations for `--force-warn` lints (RFC 2383) Rustc has a `--force-warn` flag, which overrides lint level attributes and forces the diagnostics to always be warn. This means, that for lint expectations, the diagnostic can't be suppressed as usual. This also means that the expectation would not be fulfilled, even if a lint had been triggered in the expected scope. This PR now also tracks the expectation ID in the `ForceWarn` level. I've also made some minor adjustments, to possibly catch more bugs and make the whole implementation more robust. This will probably conflict with https://github.com/rust-lang/rust/pull/97718. That PR should ideally be reviewed and merged first. The conflict itself will be trivial to fix. --- r? `@wesleywiser` cc: `@flip1995` since you've helped with the initial review and also discussed this topic with me. :upside_down_face: Follow-up of: https://github.com/rust-lang/rust/pull/87835 Issue: https://github.com/rust-lang/rust/issues/85549 Yeah, and that's it.
2022-06-16Support lint expectations for `--force-warn` lints (RFC 2383)xFrednet-2/+2
2022-06-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-4/+4
2022-05-20Lint single-use-lifetimes on the AST.Camille GILLOT-0/+37
2022-04-29errors: `span_suggestion` takes `impl ToString`David Wood-1/+1
Change `span_suggestion` (and variants) to take `impl ToString` rather than `String` for the suggested code, as this simplifies the requirements on the diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-19Rollup merge of #96086 - jsgf:remove-extern-location, r=davidtwcoDylan DPC-26/+1
Remove `--extern-location` and all associated code `--extern-location` was an experiment to investigate the best way to generate useful diagnostics for unused dependency warnings by enabling a build system to identify the corresponding build config. While I did successfully use this, I've since been convinced the alternative `--json unused-externs` mechanism is the way to go, and there's no point in having two mechanisms with basically the same functionality. This effectively reverts https://github.com/rust-lang/rust/pull/72603
2022-04-17Lint elided lifetimes in path on the AST.Camille GILLOT-1/+17
2022-04-15Remove `--extern-location` and all associated codeJeremy Fitzhardinge-26/+1
`--extern-location` was an experiment to investigate the best way to generate useful diagnostics for unused dependency warnings by enabling a build system to identify the corresponding build config. While I did successfully use this, I've since been convinced the alternative `--json unused-externs` mechanism is the way to go, and there's no point in having two mechanisms with basically the same functionality. This effectively reverts https://github.com/rust-lang/rust/pull/72603