about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2022-06-11Reword suggestion messages.Aaron Kofsky-2/+2
2022-06-10lint: add diagnostic translation migration lintsDavid Wood-31/+109
Introduce allow-by-default lints for checking whether diagnostics are written in `SessionDiagnostic`/`AddSubdiagnostic` impls and whether diagnostics are translatable. These lints can be denied for modules once they are fully migrated to impls and translation. Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-09Use `multipart_suggestion` to create an applicable suggestion.Aaron Kofsky-4/+6
The "consider explicitly droping" can now suggest a machine applicable suggestion now.
2022-06-08Remove the `infer_static_outlives_requirements` featureYuki Okushi-11/+2
2022-06-08Folding revamp.Nicholas Nethercote-1/+1
This commit makes type folding more like the way chalk does it. Currently, `TypeFoldable` has `fold_with` and `super_fold_with` methods. - `fold_with` is the standard entry point, and defaults to calling `super_fold_with`. - `super_fold_with` does the actual work of traversing a type. - For a few types of interest (`Ty`, `Region`, etc.) `fold_with` instead calls into a `TypeFolder`, which can then call back into `super_fold_with`. With the new approach, `TypeFoldable` has `fold_with` and `TypeSuperFoldable` has `super_fold_with`. - `fold_with` is still the standard entry point, *and* it does the actual work of traversing a type, for all types except types of interest. - `super_fold_with` is only implemented for the types of interest. Benefits of the new model. - I find it easier to understand. The distinction between types of interest and other types is clearer, and `super_fold_with` doesn't exist for most types. - With the current model is easy to get confused and implement a `super_fold_with` method that should be left defaulted. (Some of the precursor commits fixed such cases.) - With the current model it's easy to call `super_fold_with` within `TypeFolder` impls where `fold_with` should be called. The new approach makes this mistake impossible, and this commit fixes a number of such cases. - It's potentially faster, because it avoids the `fold_with` -> `super_fold_with` call in all cases except types of interest. A lot of the time the compile would inline those away, but not necessarily always.
2022-06-07Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakisbors-1/+0
Remove migrate borrowck mode Closes #58781 Closes #43234 # Stabilization proposal This PR proposes the stabilization of `#![feature(nll)]` and the removal of `-Z borrowck`. Current borrow checking behavior of item bodies is currently done by first infering regions *lexically* and reporting any errors during HIR type checking. If there *are* any errors, then MIR borrowck (NLL) never occurs. If there *aren't* any errors, then MIR borrowck happens and any errors there would be reported. This PR removes the lexical region check of item bodies entirely and only uses MIR borrowck. Because MIR borrowck could never *not* be run for a compiled program, this should not break any programs. It does, however, change diagnostics significantly and allows a slightly larger set of programs to compile. Tracking issue: #43234 RFC: https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md Version: 1.63 (2022-06-30 => beta, 2022-08-11 => stable). ## Motivation Over time, the Rust borrow checker has become "smarter" and thus allowed more programs to compile. There have been three different implementations: AST borrowck, MIR borrowck, and polonius (well, in progress). Additionally, there is the "lexical region resolver", which (roughly) solves the constraints generated through HIR typeck. It is not a full borrow checker, but does emit some errors. The AST borrowck was the original implementation of the borrow checker and was part of the initially stabilized Rust 1.0. In mid 2017, work began to implement the current MIR borrow checker and that effort ompleted by the end of 2017, for the most part. During 2018, efforts were made to migrate away from the AST borrow checker to the MIR borrow checker - eventually culminating into "migrate" mode - where HIR typeck with lexical region resolving following by MIR borrow checking - being active by default in the 2018 edition. In early 2019, migrate mode was turned on by default in the 2015 edition as well, but with MIR borrowck errors emitted as warnings. By late 2019, these warnings were upgraded to full errors. This was followed by the complete removal of the AST borrow checker. In the period since, various errors emitted by the MIR borrow checker have been improved to the point that they are mostly the same or better than those emitted by the lexical region resolver. While there do remain some degradations in errors (tracked under the [NLL-diagnostics tag](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-diagnostics), those are sufficiently small and rare enough that increased flexibility of MIR borrow check-only is now a worthwhile tradeoff. ## What is stabilized As said previously, this does not fundamentally change the landscape of accepted programs. However, there are a [few](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-fixed-by-NLL) cases where programs can compile under `feature(nll)`, but not otherwise. There are two notable patterns that are "fixed" by this stabilization. First, the `scoped_threads` feature, which is a continutation of a pre-1.0 API, can sometimes emit a [weird lifetime error](https://github.com/rust-lang/rust/issues/95527) without NLL. Second, actually seen in the standard library. In the `Extend` impl for `HashMap`, there is an implied bound of `K: 'a` that is available with NLL on but not without - this is utilized in the impl. As mentioned before, there are a large number of diagnostic differences. Most of them are better, but some are worse. None are serious or happen often enough to need to block this PR. The biggest change is the loss of error code for a number of lifetime errors in favor of more general "lifetime may not live long enough" error. While this may *seem* bad, the former error codes were just attempts to somewhat-arbitrarily bin together lifetime errors of the same type; however, on paper, they end up being roughly the same with roughly the same kinds of solutions. ## What isn't stabilized This PR does not completely remove the lexical region resolver. In the future, it may be possible to remove that (while still keeping HIR typeck) or to remove it together with HIR typeck. ## Tests Many test outputs get updated by this PR. However, there are number of tests specifically geared towards NLL under `src/test/ui/nll` ## History * On 2017-07-14, [tracking issue opened](https://github.com/rust-lang/rust/issues/43234) * On 2017-07-20, [initial empty MIR pass added](https://github.com/rust-lang/rust/pull/43271) * On 2017-08-29, [RFC opened](https://github.com/rust-lang/rfcs/pull/2094) * On 2017-11-16, [Integrate MIR type-checker with NLL](https://github.com/rust-lang/rust/pull/45825) * On 2017-12-20, [NLL feature complete](https://github.com/rust-lang/rust/pull/46862) * On 2018-07-07, [Don't run AST borrowck on mir mode](https://github.com/rust-lang/rust/pull/52083) * On 2018-07-27, [Add migrate mode](https://github.com/rust-lang/rust/pull/52681) * On 2019-04-22, [Enable migrate mode on 2015 edition](https://github.com/rust-lang/rust/pull/59114) * On 2019-08-26, [Don't downgrade errors on 2015 edition](https://github.com/rust-lang/rust/pull/64221) * On 2019-08-27, [Remove AST borrowck](https://github.com/rust-lang/rust/pull/64790)
2022-06-06Auto merge of #97086 - 5225225:link-section-is-unsafe, r=davidtwcobors-0/+29
Report unsafe for overriding link sections I'm not too sure about the lint wording here, but I couldn't think of anything better.
2022-06-05Add `{{produces}}` tag to lint doc comments.Aaron Kofsky-1/+8
2022-06-05Remove `let_underscore_must_use`Aaron Kofsky-109/+3
The `let_underscore_must_use` lint was really only added because clippy included it, but it doesn't actually seem very useful.
2022-06-04Use diagnostic items instead of hard coded paths for `let_underscore_lock`Aaron Kofsky-20/+11
Using diagnostic items avoids having to update the paths if the guard types ever get moved around for some reason. Additionally, it also greatly simplifies the `is_sync_lock` check.
2022-06-04Bail out early if the type does not has a trivial Drop implementation.Aaron Kofsky-2/+6
If the type has a trivial Drop implementation, then it is probably irrelevant that the type was dropped immediately, since nothing important happens on drop. Hence, we can bail out early instead of doing some expensive checks.
2022-06-04Use `has_attr` instead of `get_attrs` in `has_must_use_attr`Aaron Kofsky-4/+1
2022-06-04Move local functions to outer scope.Aaron Kofsky-69/+65
2022-06-04Set `let_underscore_lock` to Deny by default.Aaron Kofsky-2/+2
Clippy sets this lint to Deny by default, and it having the lint be Deny is useful for when we test the lint against a Crater run.
2022-06-04Show code suggestions in `let_undescore` lint messages.Aaron Kofsky-13/+47
This commit uses `span_suggestion_verbose` to add what specific code changes can be done as suggested by the lint--in this case, either binding the expression to an unused variable or using `std::mem::drop` to drop the value explicitly.
2022-06-04Allow `let_underscore_drop` and `let_underscore_must_use` by default.Aaron Kofsky-2/+2
These lints are very noisy and are allow-by-default in clippy anyways. Hence, setting them to allow-by-default here makes more sense than warning constantly on these cases.
2022-06-04 Add `let_underscore_must_use` lint.Aaron Kofsky-3/+110
Similar to `let_underscore_drop`, this lint checks for statements similar to `let _ = foo`, where `foo` is an expression marked `must_use`.
2022-06-04Add `let_underscore_lock` lint.Aaron Kofsky-3/+71
Similar to `let_underscore_drop`, this lint checks for statements similar to `let _ = foo`, where `foo` is a lock guard. These types of let statements are especially problematic because the lock gets released immediately, instead of at the end of the scope. This behavior is almost always the wrong thing.
2022-06-03Fully stabilize NLLJack Huey-1/+0
2022-05-29Add `let_underscore_drop` lint.Aaron Kofsky-0/+71
This lint checks for statements similar to `let _ = foo`, where `foo` is a type that implements `Drop`. These types of let statements cause the expression in them to be dropped immediately, instead of at the end of the scope. Such behavior can be surprizing, especially if you are relying on the value to be dropped at the end of the scope. Instead, the binding should be an underscore prefixed name (like `_unused`) or the value should explicitly be passed to `std::mem::drop()` if the value really should be dropped immediately.
2022-05-28Fix TyKind lint, make consts no longer fn, etcMichael Goulet-68/+123
2022-05-28Move things to rustc_type_irWilco Kusee-2/+2
2022-05-25Tweak memory ordering diagnostic.Mara Bos-1/+6
2022-05-25Improve invalid memory ordering diagnostics.Mara Bos-82/+61
2022-05-25Rollup merge of #97266 - est31:unknown_lints_cfg_attr, r=lcnrYuki Okushi-17/+17
Make weird name lints trigger behind cfg_attr The weird name lints (`unknown_lints`, `renamed_and_removed_lints`), the lints that lint the linting, were previously not firing for lint level declarations behind `cfg_attr`, as they were only running before expansion. Now, this will give a `unknown_lints` warning: ```Rust #[cfg_attr(all(), allow(this_lint_does_not_exist))] fn foo() {} ``` Lint level declarations behind a `cfg_attr` whose condition is not applying are still ignored. So this still won't give a warning: ```Rust #[cfg_attr(any(), allow(this_lint_does_not_exist))] fn foo() {} ``` Furthermore, this PR also makes the weird name lints respect level delcarations for *them* that were hidden by `cfg_attr`, making them consistent to other lints. So this will now not issue a warning: ```Rust #[cfg_attr(all(), allow(unknown_lints))] mod foo { #[allow(does_not_exist)] fn foo() { } } ``` Fixes #97094
2022-05-24Emit weird lint name lints after expansionest31-17/+17
Previously, we were emitting weird name lints (for renamed or unknown lints) before expansion, most importantly before cfg expansion. This meant that the weird name lints would not fire for lint attributes hidden inside cfg_attr. The same applied for lint level specifications of those lints. By moving the lints for the lint names to the post-expansion phase, these issues are resolved.
2022-05-21Remove feature: `crate` visibility modifierJacob Pratt-7/+1
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-6/+8
2022-05-20Lint single-use-lifetimes on the AST.Camille GILLOT-1/+47
2022-05-20Introduce LifetimeCtxt.Camille GILLOT-1/+1
2022-05-17Auto merge of #97012 - oli-obk:🦀_intrinsics, r=davidtwcobors-3/+1
Add a query for checking whether a function is an intrinsic. work towards #93145 This will reduce churn when we add more ways to declare intrinsics r? `@scottmcm`
2022-05-16Report unsafe for overriding link sections5225225-0/+29
2022-05-16Add a query for checking whether a function is an intrinsic.Oli Scherer-3/+1
2022-05-12Auto merge of #95562 - lcnr:attr-no-encode, r=davidtwcobors-26/+21
don't encode only locally used attrs Part of https://github.com/rust-lang/compiler-team/issues/505. We now filter builtin attributes before encoding them in the crate metadata in case they should only be used in the local crate. To prevent accidental misuse `get_attrs` now requires the caller to state which attribute they are interested in. For places where that isn't trivially possible, I've added a method `fn get_attrs_unchecked` which I intend to remove in a followup PR. After this pull request landed, we can then slowly move all attributes to only be used in the local crate while being certain that we don't accidentally try to access them from extern crates. cc https://github.com/rust-lang/rust/pull/94963#issuecomment-1082924289
2022-05-12Auto merge of #96150 - est31:unused_macro_rules, r=petrochenkovbors-0/+1
Implement a lint to warn about unused macro rules This implements a new lint to warn about unused macro rules (arms/matchers), similar to the `unused_macros` lint added by #41907 that warns about entire macros. ```rust macro_rules! unused_empty { (hello) => { println!("Hello, world!") }; () => { println!("empty") }; //~ ERROR: 1st rule of macro `unused_empty` is never used } fn main() { unused_empty!(hello); } ``` Builds upon #96149 and #96156. Fixes #73576
2022-05-11ast: Introduce some traits to get AST node properties genericallyVadim Petrochenkov-2/+1
And use them to avoid constructing some artificial `Nonterminal` tokens during expansion
2022-05-11Rollup merge of #96882 - jackh726:no-subst, r=oli-obkYuki Okushi-7/+3
Don't subst an AdtDef with its own substs
2022-05-10only_local: always check for misuselcnr-26/+21
2022-05-10Rollup merge of #96812 - cjgillot:no-lint-outllives-macro, r=petrochenkovDylan DPC-1/+2
Do not lint on explicit outlives requirements from external macros. The current implementation of the list rightfully skipped where predicates from external macros. However, if the where predicate came from the current macro but the bounds were from an external macro, the lint still fired. Closes https://github.com/rust-lang/rust/issues/96640
2022-05-09Don't subst an adt defJack Huey-7/+3
2022-05-09Auto merge of #95542 - xFrednet:rfc-2383-expect-query, r=wesleywiserbors-12/+29
Support tool lints with the `#[expect]` attribute (RFC 2383) This PR fixes the ICE https://github.com/rust-lang/rust/issues/94953 by making the assert for converted expectation IDs conditional. Additionally, it moves the lint expectation check into a separate query to support rustdoc and other tools. On the way, I've also added some tests to ensure that the attribute works for Clippy and rustdoc lints. The number of changes comes from the long test file. This may look like a monster PR, this may smell like a monster PR and this may be a monster PR, but it's a harmless monster. :sauropod: --- Closes: https://github.com/rust-lang/rust/issues/94953 cc: https://github.com/rust-lang/rust/issues/85549 r? `@wesleywiser` cc: `@rust-lang/rustdoc`
2022-05-08Auto merge of #96770 - flip1995:fix-trait-type-in-bounds, r=cjgillotbors-2/+2
Track if a where bound comes from a impl Trait desugar With https://github.com/rust-lang/rust/pull/93803 `impl Trait` function arguments get desugared to hidden where bounds. However, Clippy needs to know if a bound was originally a `impl Trait` or an actual bound. This adds a field to the `WhereBoundPredicate` struct to keep track of this information during AST->HIR lowering. r? `@cjgillot` cc `@estebank` (as the reviewer of #93803)
2022-05-08Move lint expectation checking into a separate query (RFC 2383)xFrednet-12/+29
2022-05-07Track if a where bound comes from a impl Trait desugarflip1995-2/+2
With #93803 `impl Trait` function arguments get desugared to hidden where bounds. However, Clippy needs to know if a bound was originally a impl Trait or an actual bound. This adds a field to the `WhereBoundPredicate` struct to keep track of this information during HIR lowering.
2022-05-07Do not lint on explicit outlives requirements from external macros.Camille GILLOT-1/+2
2022-05-06Auto merge of #96268 - ↵bors-0/+5
jackh726:remove-mutable_borrow_reservation_conflict-lint, r=nikomatsakis Remove mutable_borrow_reservation_conflict lint and allow the code pattern This was the only breaking issue with the NLL stabilization PR. Lang team decided to go ahead and allow this. r? `@nikomatsakis` Closes #59159 Closes #56254
2022-05-04Stabilize `bool::then_some`Josh Triplett-1/+0
2022-05-04Add unused_macro_rules lint definitionest31-0/+1
Not fired yet.
2022-05-03Auto merge of #96558 - bjorn3:librarify_parse_format, r=davidtwcobors-1/+4
Make rustc_parse_format compile on stable This allows it to be used by lightweight formatting systems and may allow it to be used by rust-analyzer.
2022-05-03Make rustc_parse_format compile on stablebjorn3-1/+4
This allows it to be used by lightweight formatting systems and may allow it to be used by rust-analyzer.