summary refs log tree commit diff
path: root/compiler/rustc_lint/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2022-12-27Switch `#[track_caller]` back to a no-op unless feature gate is enabledBryan Garza-0/+1
This patch fixes a regression, in which `#[track_caller]`, which was previously a no-op, was changed to actually turn on the behavior. This should instead only happen behind the `closure_track_caller` feature gate. Also, add a warning for the user to understand how their code will compile depending on the feature gate being turned on or not. Fixes #104588
2022-12-02Remove six macros relating to lint definitions.Nicholas Nethercote-119/+103
These were enabled by the removal of `-Zno-interleave-lints`.
2022-12-02Remove `-Zno-interleave-lints`.Nicholas Nethercote-44/+7
Because it complicates lint implementation greatly.
2022-11-23Make `deref_into_dyn_supertrait` lint the impl and not the usageMaybe Waffle-0/+3
2022-11-07fix: lint against lint functionsRejyr-0/+1
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-1/+1
And a couple of other naming tweaks Related to https://github.com/rust-lang/rust/issues/48054
2022-10-09fixup lint nameMaybe Waffle-3/+3
2022-10-09Start uplifting `clippy::for_loops_over_fallibles`Maybe Waffle-0/+3
I refactored the code: - Removed handling of methods, as it felt entirely unnecessary - Removed clippy utils (obviously...) - Used some shiny compiler features (let-else is very handy for lints :eyes:) - I also renamed the lint to `for_loop_over_fallibles` (note: no `s`). I'm not sure what's the naming convention here, so maybe I'm wrong.
2022-10-07make const_err a hard errorRalf Jung-0/+5
2022-10-02Make it a lint for all opaque typesMichael Goulet-3/+3
2022-10-02Lint for unsatisfied nested opaquesMichael Goulet-0/+3
2022-09-26remove cfg(bootstrap)Pietro Albini-1/+1
2022-09-22Revert "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.
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