about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
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
2022-07-15Remove some more usages of guess_head_spanMichael Goulet-2/+1
2022-07-14Rollup merge of #98580 - PrestonFrom:issue_98466, r=estebankDylan DPC-0/+12
Emit warning when named arguments are used positionally in format Addresses Issue 98466 by emitting an error 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-14Auto merge of #99231 - Dylan-DPC:rollup-0tl8c0o, r=Dylan-DPCbors-1/+2
Rollup of 5 pull requests Successful merges: - #97720 (Always create elided lifetime parameters for functions) - #98315 (Stabilize `core::ffi:c_*` and rexport in `std::ffi`) - #98705 (Implement `for<>` lifetime binder for closures) - #99126 (remove allow(rustc::potential_query_instability) in rustc_span) - #99139 (Give a better error when `x dist` fails for an optional tool) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-07-14Rollup merge of #98705 - WaffleLapkin:closure_binder, r=cjgillotDylan DPC-1/+2
Implement `for<>` lifetime binder for closures This PR implements RFC 3216 ([TI](https://github.com/rust-lang/rust/issues/97362)) and allows code like the following: ```rust let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) }; // ^^^^^^^^^^^--- new! ``` cc ``@Aaron1011`` ``@cjgillot``
2022-07-13Rename `debugging_opts` to `unstable_opts`Joshua Nelson-3/+3
This is no longer used only for debugging options (e.g. `-Zoutput-width`, `-Zallow-features`). Rename it to be more clear.
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-13Rollup merge of #99011 - oli-obk:UnsoundCell, r=eddybDylan DPC-3/+2
`UnsafeCell` blocks niches inside its nested type from being available outside fixes #87341 This implements the plan by `@eddyb` in https://github.com/rust-lang/rust/issues/87341#issuecomment-886083646 Somewhat related PR (not strictly necessary, but that cleanup made this PR simpler): #94527
2022-07-12Lower closure binders to hir & properly check themMaybe Waffle-0/+1
2022-07-12Parse closure bindersMaybe Waffle-1/+1
This is first step in implementing RFC 3216. - Parse `for<'a>` before closures in ast - Error in lowering - Add `closure_lifetime_binder` feature
2022-07-07Auto merge of #95573 - cjgillot:lower-query, r=michaelwoeristerbors-2/+2
Make lowering a query Split from https://github.com/rust-lang/rust/pull/88186. This PR refactors the relationship between lowering and the resolver outputs in order to make lowering itself a query. In a first part, lowering is changed to avoid modifying resolver outputs, by maintaining its own data structures for creating new `NodeId`s and so. Then, the `TyCtxt` is modified to allow creating new `LocalDefId`s from inside it. This is done by: - enclosing `Definitions` in a lock, so as to allow modification; - creating a query `register_def` whose purpose is to declare a `LocalDefId` to the query system. See `TyCtxt::create_def` and `TyCtxt::iter_local_def_id` for more detailed explanations of the design.
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-07Comment updateOli Scherer-2/+1
2022-07-07`UnsafeCell` now has no niches, ever.Oli Scherer-1/+1
2022-07-06Make AST lowering a query.Camille GILLOT-2/+2
2022-07-06Add function to manually fulfill lint expectations (RFC 2383)xFrednet-1/+32
2022-07-06Rollup merge of #98519 - TaKO8Ki:add-head-span-field-to-item-and-impl-item, ↵Guillaume Gomez-24/+13
r=cjgillot Replace some `guess_head_span` with `def_span` This patch fixes a part of #97417. r? `@cjgillot`
2022-07-06fix miri-opt testsTakayuki Maeda-10/+6
2022-07-06replace `guess_head_span` with `def_span`Takayuki Maeda-14/+7
2022-07-06Rollup merge of #98884 - davidtwco:translation-on-lints-derive, r=oli-obkDylan DPC-15/+43
macros: `LintDiagnostic` derive - Move `LintDiagnosticBuilder` into `rustc_errors` so that a diagnostic derive can refer to it. - Introduce a `DecorateLint` trait, which is equivalent to `SessionDiagnostic` or `AddToDiagnostic` but for lints. Necessary without making more changes to the lint infrastructure as `DecorateLint` takes a `LintDiagnosticBuilder` and re-uses all of the existing logic for determining what type of diagnostic a lint should be emitted as (e.g. error/warning). - Various refactorings of the diagnostic derive machinery (extracting `build_field_mapping` helper and moving `sess` field out of the `DiagnosticDeriveBuilder`). - Introduce a `LintDiagnostic` derive macro that works almost exactly like the `SessionDiagnostic` derive macro except that it derives a `DecorateLint` implementation instead. A new derive is necessary for this because `SessionDiagnostic` is intended for when the generated code creates the diagnostic. `AddToDiagnostic` could have been used but it would have required more changes to the lint machinery. ~~At time of opening this pull request, ignore all of the commits from #98624, it's just the last few commits that are new.~~ r? `@oli-obk`
2022-07-06Update TypeVisitor pathsAlan Egerton-5/+5
2022-07-05macros: add diagnostic derive for lintsDavid Wood-7/+15
`SessionDiagnostic` isn't suitable for use on lints as whether or not it creates an error or a warning is decided at compile-time by the macro, whereas lints decide this at runtime based on the location of the lint being reported (as it will depend on the user's `allow`/`deny` attributes, etc). Re-using most of the machinery for `SessionDiagnostic`, this macro introduces a `LintDiagnostic` derive which implements a `DecorateLint` trait, taking a `LintDiagnosticBuilder` and adding to the lint according to the diagnostic struct.
2022-07-05errors: introduce `DecorateLint`David Wood-2/+22
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-7/+7
Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-05Rollup merge of #98624 - davidtwco:translation-on-lints, r=compiler-errorsDylan DPC-587/+507
lints: mostly translatable diagnostics As lints are created slightly differently than other diagnostics, intended to try make them translatable first and then look into the applicability of diagnostic structs but ended up just making most of the diagnostics in the crate translatable (which will still be useful if I do make a lot of them structs later anyway). r? ``@compiler-errors``
2022-06-30fix grammar in useless doc comment lintAndy Russell-2/+2