about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
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-11/+0
2022-08-22refactor: migrate to kind-less `SessionDiagnostic` derivesRejyr-8/+8
2022-08-22migrate: `rustc_lint::context`Rejyr-59/+119
2022-08-22rename: `UnknownTool` to `UnknownToolInScopedLint`Rejyr-4/+4
2022-08-22migrate: `BuiltinEllipsisInclusiveRangePatterns`Rejyr-23/+23
2022-08-22migrate: `OverruledAttribute`Rejyr-12/+65
2022-08-22hotfix: add missing importRejyr-1/+1
2022-08-22change: diagnostic `String` field to `Symbol`Rejyr-3/+2
2022-08-22migrate: `bad_attr` to `SessionDiagnostic`Rejyr-18/+45
2022-08-22migrate: `UnknownTool` error to `SessionDiagnostic`Rejyr-16/+27
2022-08-22Use DiagnosticMessage for BufferedEarlyLint.msgfinalchild-1/+1
2022-08-21Replace #[lint/warning/error] with #[diag]Xiretza-1/+1
2022-08-16Rename some things related to literals.Nicholas Nethercote-2/+2
- Rename `ast::Lit::token` as `ast::Lit::token_lit`, because its type is `token::Lit`, which is not a token. (This has been confusing me for a long time.) reasonable because we have an `ast::token::Lit` inside an `ast::Lit`. - Rename `LitKind::{from,to}_lit_token` as `LitKind::{from,to}_token_lit`, to match the above change and `token::Lit`.
2022-08-15Auto merge of #96745 - ehuss:even-more-attribute-validation, r=cjgillotbors-65/+81
Visit attributes in more places. This adds 3 loosely related changes (I can split PRs if desired): - Attribute checking on pattern struct fields. - Attribute checking on struct expression fields. - Lint level visiting on pattern struct fields, struct expression fields, and generic parameters. There are still some lints which ignore lint levels in various positions. This is a consequence of how the lints themselves are implemented. For example, lint levels on associated consts don't work with `unused_braces`.
2022-08-12Adjust cfgsMark Rousskov-1/+0
2022-08-11Add missing visit_pat_field in early lint visitor.Eric Huss-0/+6
This ensures that lint attributes on pattern fields can control early lints.
2022-08-11Make Node::ExprField a child of Node::Expr.Eric Huss-51/+47
This was incorrectly inserting the ExprField as a sibling of the struct expression. This required adjusting various parts which were looking at parent node of a field expression to find the struct.
2022-08-11Add visitors for PatField and ExprField.Eric Huss-45/+19
This helps simplify the code. It also fixes it to use the correct parent when lowering. One consequence is the `non_snake_case` lint needed to change the way it looked for parent nodes in a struct pattern. This also includes a small fix to use the correct `Target` for expression field attribute validation.
2022-08-11Honor lint level attributes in more places.Eric Huss-6/+46
This extends the LintLevelBuilder to handle lint level attributes on struct expression fields and pattern fields. This also updates the early lints to honor lint levels on generic parameters.
2022-08-11Rollup merge of #100392 - nnethercote:simplify-visitors, r=cjgillotMatthias Krüger-28/+9
Simplify visitors By removing some unused arguments. r? `@cjgillot`
2022-08-11Simplify `rustc_ast::visit::Visitor::visit_poly_trait_ref`.Nicholas Nethercote-5/+4
It is passed an argument that is never used.
2022-08-11Simplify `rustc_hir::intravisit::Visitor::visit_variant_data`.Nicholas Nethercote-23/+5
It has four arguments that are never used. This avoids lots of argument passing in functions that feed into `visit_variant_data`.
2022-08-10Do not consider method call receiver as an argument in AST.Camille GILLOT-2/+1
2022-08-07Do not manually craft a span pointing inside a multibyte character.Camille GILLOT-46/+42
2022-08-04Fix imports.Aaron Kofsky-2/+2
I'm not really sure why this is nessecary to do, but the checks on the PR do not seem to work if do not do this.
2022-08-04Explain why let-underscoring a lock guard is incorrect.Aaron Kofsky-2/+11
Currently, the let_underscore_lock lint simply tells what is wrong, but not why it is wrong. We fix this by using a `MultiSpan` to explain specifically that doing `let _ = ` immediately drops the lock guard because it does not assign the lock guard to a binding.
2022-08-04Rollup merge of #100093 - wcampbell0x2a:unused-parens-for-match-arms, ↵Matthias Krüger-0/+14
r=petrochenkov Enable unused_parens for match arms Fixes: https://github.com/rust-lang/rust/issues/92751 Currently I can't get the `stderr` to work with `./x.py test`, but this should fix the issue. Help would be appreciated!
2022-08-04Enable unused_parens for match armswcampbell-0/+14
2022-08-03Remove index from Region::EarlyBound.Camille GILLOT-6/+13
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-08-01Remove DefId from AssocItemContainer.Camille GILLOT-2/+2
2022-08-01Rollup merge of #99911 - cjgillot:no-guess, r=davidtwcoMatthias Krüger-20/+5
Remove some uses of `guess_head_span` That function cuts a span at the first occurrence of `{`. Using `def_span` is almost always more precise.
2022-07-30Auto merge of #99887 - nnethercote:rm-TreeAndSpacing, r=petrochenkovbors-1/+1
Remove `TreeAndSpacing`. A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From<TokenTree> for TokenStream` - `impl From<TokenTree> for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`. r? `@petrochenkov`
2022-07-30Rollup merge of #99888 - nnethercote:streamline-visitors, r=cjgillotYuki Okushi-70/+2
Streamline lint checking The early (AST) and late (HIR) lint checkers have a number of functions that aren't used by rustc or clippy. Might as well remove them -- it's not like there's a canonical API here, as shown by the ad hoc use of `check_foo`/`check_foo_post` combinations. r? `@cjgillot`
2022-07-29Remove `TreeAndSpacing`.Nicholas Nethercote-1/+1
A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From<TokenTree> for TokenStream` - `impl From<TokenTree> for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`.
2022-07-29Remove some late `check_*` functions.Nicholas Nethercote-34/+2
They're not used by rustc or clippy.
2022-07-29Remove some early `check_*` functions.Nicholas Nethercote-36/+0
They're not used by rustc or clippy.
2022-07-29Auto merge of #99660 - PrestonFrom:issue_99265, r=compiler-errorsbors-2/+2
Generate correct suggestion with named arguments used positionally 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-28Remove guess_head_span.Camille GILLOT-20/+5
2022-07-27lint: add bad opt access internal lintDavid Wood-0/+38
Some command-line options accessible through `sess.opts` are best accessed through wrapper functions on `Session`, `TyCtxt` or otherwise, rather than through field access on the option struct in the `Session`. Adds a new lint which triggers on those options that should be accessed through a wrapper function so that this is prohibited. Options are annotated with a new attribute `rustc_lint_opt_deny_field_access` which can specify the error message (i.e. "use this other function instead") to be emitted. A simpler alternative would be to simply rename the options in the option type so that it is clear they should not be used, however this doesn't prevent uses, just discourages them. Another alternative would be to make the option fields private, and adding accessor functions on the option types, however the wrapper functions sometimes rely on additional state from `Session` or `TyCtxt` which wouldn't be available in an function on the option type, so the accessor would simply make the field available and its use would be discouraged too. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-27session: disable internal lints for rustdocDavid Wood-14/+0
If an internal lint uses `typeck_results` or similar queries then that can result in rustdoc checking code that it shouldn't (e.g. from other platforms) and emit compilation errors. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-27lint: add comment about diag lints in groupDavid Wood-0/+4
Add a brief comment explaining why the diagnostic migration lints aren't included in the `rustc::internal` diagnostic group. Signed-off-by: David Wood <david.wood@huawei.com>
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-21`special_module_name`: ignore inline modulesIbraheem Ahmed-1/+5
2022-07-20Rollup merge of #99433 - cjgillot:erase-foreign-sig, r=compiler-errorsDylan DPC-3/+4
Erase regions before comparing signatures of foreign fns. Fixes https://github.com/rust-lang/rust/issues/99276 The version with explicit lifetimes is probably tracked in another bug, but I could not find it.
2022-07-19Erase regions before comparing signatures of foreign fns.Camille GILLOT-3/+4
2022-07-18Update invalid atomic ordering lintTomasz Miąsko-38/+3
The restriction that success ordering must be at least as strong as its failure ordering in compare-exchange operations was lifted in #98383.
2022-07-16Stabilize `let_chains`Caio-1/+1
2022-07-15Only suggest if span is not erroneousMichael Goulet-9/+10