summary refs log tree commit diff
path: root/compiler/rustc_lint/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2022-10-06Revert "Auto merge of #101620 - cjgillot:compute_lint_levels_by_def, r=oli-obk"Camille GILLOT-1/+0
This reverts commit 2cb9a65684dba47c52de8fa938febf97a73e70a9, reversing changes made to 750bd1a7ff3e010611b97ee75d30b7cbf5f3a03c. (cherry picked from commit fc43df0333d5862a219f16d294ae38b14b9191d3)
2022-09-15Only enable the let_else feature on bootstrapest31-1/+1
On later stages, the feature is already stable. Result of running: rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-14Move some code and add comments.Camille GILLOT-0/+1
2022-09-06Allow lint passes to be bound by `TyCtxt`Jason Newcomb-14/+29
2022-09-03Auto merge of #100574 - Urgau:check-cfg-warn-cfg, r=petrochenkovbors-0/+1
Add warning against unexpected --cfg with --check-cfg This PR adds a warning when an unexpected `--cfg` is specified but not in the specified list of `--check-cfg`. This is the follow-up PR I mentioned in https://github.com/rust-lang/rust/pull/99519. r? `@petrochenkov`
2022-09-02Add warning against unexpected --cfg with --check-cfgUrgau-0/+1
2022-09-02Rollup merge of #97739 - a2aaron:let_underscore, r=estebankGuillaume Gomez-0/+5
Uplift the `let_underscore` lints from clippy into rustc. This PR resolves #97241. This PR adds three lints from clippy--`let_underscore_drop`, `let_underscore_lock`, and `let_underscore_must_use`, which are meant to capture likely-incorrect uses of `let _ = ...` bindings (in particular, doing this on a type with a non-trivial `Drop` causes the `Drop` to occur immediately, instead of at the end of the scope. For a type like `MutexGuard`, this effectively releases the lock immediately, which is almost certainly the wrong behavior) In porting the lints from clippy I had to copy over a bunch of utility functions from `clippy_util` that these lints also relied upon. Is that the right approach? Note that I've set the `must_use` and `drop` lints to Allow by default and set `lock` to Deny by default (this matches the same settings that clippy has). In talking with `@estebank` he informed me to do a Crater run (I am not sure what type of Crater run to request here--I think it's just "check only"?) On the linked issue, there's some discussion about using `must_use` and `Drop` together as a heuristic for when to warn--I did not implement this yet. r? `@estebank`
2022-09-01Rollup merge of #94467 - ibraheemdev:master, r=pnkfelixMatthias Krüger-0/+1
Add `special_module_name` lint Declaring `lib` as a module is one of the most common beginner mistakes when trying to setup a binary and library target in the same crate. `special_module_name` lints against it, as well as `mod main;` ``` warning: found module declaration for main.rs --> $DIR/special_module_name.rs:4:1 | LL | mod main; | ^^^^^^^^^ | = note: a binary crate cannot be used as library warning: found module declaration for lib.rs --> $DIR/special_module_name.rs:1:1 | LL | mod lib; | ^^^^^^^^ | = note: `#[warn(special_module_name)]` on by default = note: lib.rs is the root of this crate's library target = help: to refer to it from other targets, use the library's name as the path ``` Note that the help message is not the best in that it doesn't provide an example of an import path (`the_actual_crate_name::`), and doesn't check whether the current file is part of a library/binary target to provide more specific error messages. I'm not sure where this lint would have to be run to access that information.
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-0/+2
by module
2022-08-29Revert let_chains stabilizationNilstrieb-0/+1
This reverts commit 326646074940222d602f3683d0559088690830f4. This is the revert against master, the beta revert was already done in #100538.
2022-08-23cleanup: commented lintsRejyr-2/+0
2022-08-22migrate: `UnknownTool` error to `SessionDiagnostic`Rejyr-0/+3
2022-08-12Adjust cfgsMark Rousskov-1/+0
2022-07-30Rollup merge of #99888 - nnethercote:streamline-visitors, r=cjgillotYuki Okushi-1/+1
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 some late `check_*` functions.Nicholas Nethercote-1/+1
They're not used by rustc or clippy.
2022-07-27lint: add bad opt access internal lintDavid Wood-0/+3
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-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-16Stabilize `let_chains`Caio-1/+1
2022-07-06Make AST lowering a query.Camille GILLOT-1/+1
2022-06-19Make some lints incremental.Camille GILLOT-14/+13
2022-06-10lint: add diagnostic translation migration lintsDavid Wood-0/+2
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-05Remove `let_underscore_must_use`Aaron Kofsky-6/+1
The `let_underscore_must_use` lint was really only added because clippy included it, but it doesn't actually seem very useful.
2022-06-04 Add `let_underscore_must_use` lint.Aaron Kofsky-1/+6
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-1/+1
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/+5
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-20Remove `crate` visibility usage in compilerJacob Pratt-1/+0
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-08Move lint expectation checking into a separate query (RFC 2383)xFrednet-0/+1
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-04-20Remove mutable_borrow_reservation_conflict lintJack Huey-0/+5
2022-03-02Make `LintExpectationId` stable between compilation sessions (RFC-2383)xFrednet-1/+1
2022-03-02Check lint expectations and emit lint if unfulfilled (RFC-2383)xFrednet-0/+1
2022-02-28add `special_module_name` lintIbraheem Ahmed-0/+1
2022-02-25Initiate the inner usage of `let_chains`Caio-2/+3
2022-02-25Switch bootstrap cfgsMark Rousskov-1/+1
2022-02-22Improve diagnostic of the unexpected_cfgs lintLoïc BRANSTETT-0/+1
2022-02-01add a rustc::query_stability lintlcnr-0/+5
2022-01-23rustc_lint: Reuse the set of registered tools from resolverVadim Petrochenkov-1/+1
2022-01-23rustc_lint: Remove some redundant fields from `EarlyContext`Vadim Petrochenkov-1/+1
Use consistent function parameter order for early context construction and early linting Rename some functions to make it clear that they do not necessarily work on the whole crate
2022-01-21Reject unsupported naked functionsTomasz Miąsko-0/+5
Transition unsupported naked functions future incompatibility lint into an error: * Naked functions must contain a single inline assembly block. Introduced as future incompatibility lint in 1.50 #79653. Change into an error fixes a soundness issue described in #32489. * Naked functions must not use any forms of inline attribute. Introduced as future incompatibility lint in 1.56 #87652.
2022-01-16Rollup merge of #92646 - mdibaiee:76935/pass-by-value, r=lcnrMatthias Krüger-1/+5
feat: rustc_pass_by_value lint attribute Useful for thin wrapper attributes that are best passed as value instead of reference. Fixes #76935
2022-01-09Compute most of Public/Exported access level in rustc_resolveLamb-1/+2
Mak DefId to AccessLevel map in resolve for export hir_id to accesslevel in resolve and applied in privacy using local def id removing tracing probes making function not recursive and adding comments Move most of Exported/Public res to rustc_resolve moving public/export res to resolve fix missing stability attributes in core, std and alloc move code to access_levels.rs return for some kinds instead of going through them Export correctness, macro changes, comments add comment for import binding add comment for import binding renmae to access level visitor, remove comments, move fn as closure, remove new_key fmt fix rebase fix rebase fmt fmt fix: move macro def to rustc_resolve fix: reachable AccessLevel for enum variants fmt fix: missing stability attributes for other architectures allow unreachable pub in rustfmt fix: missing impl access level + renaming export to reexport Missing impl access level was found thanks to a test in clippy
2022-01-09feat: pass_by_value lint attributeMahdi Dibaiee-1/+5
Useful for thin wrapper attributes that are best passed as value instead of reference.
2021-12-14Stabilize iter::zip.PFPoitras-1/+0
2021-12-02Rollup merge of #91394 - Mark-Simulacrum:bump-stage0, r=pietroalbiniMatthias Krüger-1/+0
Bump stage0 compiler r? `@pietroalbini` (or anyone else)
2021-11-30Apply cfg-bootstrap switchMark Rousskov-1/+0
2021-11-16Use get_diagnostic_name moreCameron Steffen-0/+1