summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2023-07-31do not use stringly typed diagnosticsDeadbeef-19/+26
2023-07-31`suspicious_double_ref_op`: don't lint on `.borrow()`Deadbeef-15/+18
2023-07-11Prevent emitting `missing_docs` for `pub extern crate`Guillaume Gomez-2/+6
2023-07-08Fix dropping_copy_types lint from linting in match-arm with side-effectsUrgau-1/+1
2023-05-27Rollup merge of #111714 - cjgillot:lint-expect-confusion, r=wesleywiserMatthias Krüger-3/+7
Stop confusing specification levels when computing expectations. Fixes https://github.com/rust-lang/rust/issues/111682
2023-05-25Rollup merge of #111757 - lowr:fix/lint-attr-on-match-arm, r=eholkMichael Goulet-2/+4
Consider lint check attributes on match arms Currently, lint check attributes on match arms have no effect for some lints. This PR makes some lint passes to take those attributes into account. - `LateContextAndPass` for late lint doesn't update `last_node_with_lint_attrs` when it visits match arms. This leads to lint check attributes on match arms taking no effects on late lints that operate on the arms' pattern: ```rust match value { #[deny(non_snake_case)] PAT => {} // `non_snake_case` only warned due to default lint level } ``` To be honest, I'm not sure whether this is intentional or just an oversight. I've dug the implementation history and searched up issues/PRs but couldn't find any discussion on this. - `MatchVisitor` doesn't update its lint level when it visits match arms. This leads to check lint attributes on match arms taking no effect on some lints handled by this visitor, namely: `bindings_with_variant_name` and `irrefutable_let_patterns`. This seems to be a fallout from #108504. Before 05082f57afbf5d2e8fd7fb67719336d78b58e759, when the visitor operated on HIR rather than THIR, check lint attributes for the said lints were effective. [This playground][play] compiles successfully on current stable (1.69) but fails on current beta and nightly. I wasn't sure where best to place the test for this. Let me know if there's a better place. [play]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=38432b79e535cb175f8f7d6d236d29c3 [play-match]: https://play.rust-lang.org/?version=beta&mode=debug&edition=2021&gist=629aa71b7c84b269beadeba664e2221d
2023-05-24Use `is_some_and`/`is_ok_and` in less obvious spotsMaybe Waffle-3/+2
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-5/+5
2023-05-21Rename `forget_ref` lint to `forgetting_references`Urgau-5/+5
2023-05-21Rename `drop_ref` lint to `dropping_references`Urgau-6/+6
2023-05-21Rename `forget_copy` lint to `forgetting_copy_types`Urgau-5/+5
2023-05-21Rename `drop_copy` lint to `dropping_copy_types`Urgau-5/+5
2023-05-20Rollup merge of #111491 - compiler-errors:nested-fut-must-use, r=wesleywiserDylan DPC-1/+3
Dont check `must_use` on nested `impl Future` from fn Fixes (but does not close, per beta policy) #111484 Also fixes a `FIXME` left in the code about (presumably) false-positives on non-async `#[must_use] fn() -> impl Future` cases, though if that's not desirable to include in the beta backport then I can certainly revert it. Beta nominating as it fixes a beta ICE.
2023-05-19Consider lint check attributes on match arms in late lintsRyo Yoshida-2/+4
Additionally add analogous test for early lints.
2023-05-18Stop confusing specification levels when computing expectations.Camille GILLOT-3/+7
2023-05-16Rollup merge of #111572 - kpreid:mdi, r=compiler-errorsNilstrieb-2/+2
Document that `missing_copy_implementations` and `missing_debug_implementations` only apply to public items. I encountered #111359 (fixed) and noticed that the documentation didn't say that it was _intended_ that `missing_debug_implementations` only applies to public items. This PR fixes that, and makes the same wording change to `missing_copy_implementations` which has the same condition. I chose the words to also be similar to `missing_docs` which already had such a remark.
2023-05-15Move expansion of query macros in rustc_middle to rustc_middle::queryJohn Kåre Alsaker-3/+3
2023-05-14Document that `missing_copy_implementations` and ↵Kevin Reid-2/+2
`missing_debug_implementations` only apply to public items.
2023-05-14Auto merge of #111425 - Bryanskiy:privacy_ef, r=petrochenkovbors-2/+6
Populate effective visibilities in `rustc_privacy` (take 2) Same as https://github.com/rust-lang/rust/pull/110907 + regressions fixes. Fixes https://github.com/rust-lang/rust/issues/111359. r? `@petrochenkov`
2023-05-13Auto merge of #107586 - SparrowLii:parallel-query, r=cjgillotbors-10/+10
Introduce `DynSend` and `DynSync` auto trait for parallel compiler part of parallel-rustc #101566 This PR introduces `DynSend / DynSync` trait and `FromDyn / IntoDyn` structure in rustc_data_structure::marker. `FromDyn` can dynamically check data structures for thread safety when switching to parallel environments (such as calling `par_for_each_in`). This happens only when `-Z threads > 1` so it doesn't affect single-threaded mode's compile efficiency. r? `@cjgillot`
2023-05-12Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwcobors-0/+204
Uplift `clippy::{drop,forget}_{ref,copy}` lints This PR aims at uplifting the `clippy::drop_ref`, `clippy::drop_copy`, `clippy::forget_ref` and `clippy::forget_copy` lints. Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted. ## `drop_ref` and `forget_ref` The `drop_ref` and `forget_ref` lint checks for calls to `std::mem::drop` or `std::mem::forget` with a reference instead of an owned value. ### Example ```rust let mut lock_guard = mutex.lock(); std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex // still locked operation_that_requires_mutex_to_be_unlocked(); ``` ### Explanation Calling `drop` or `forget` on a reference will only drop the reference itself, which is a no-op. It will not call the `drop` or `forget` method on the underlying referenced value, which is likely what was intended. ## `drop_copy` and `forget_copy` The `drop_copy` and `forget_copy` lint checks for calls to `std::mem::forget` or `std::mem::drop` with a value that derives the Copy trait. ### Example ```rust let x: i32 = 42; // i32 implements Copy std::mem::forget(x) // A copy of x is passed to the function, leaving the // original unaffected ``` ### Explanation Calling `std::mem::forget` [does nothing for types that implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the value will be copied and moved into the function on invocation. ----- Followed the instructions for uplift a clippy describe here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 cc `@m-ou-se` (as T-libs-api leader because the uplifting was discussed in a recent meeting)
2023-05-11refactor: use by-ref TokenTree iterator to avoid a few clonesCaleb Cartwright-4/+4
2023-05-12Dont check `must_use` on nested `impl Future` from fnMichael Goulet-1/+3
2023-05-11Populate effective visibilities in rustc_privacyBryanskiy-2/+6
2023-05-10Add note to suggest using `let _ = x` to ignore the valueUrgau-0/+4
2023-05-10Use label instead of note to be more consistent with other lintsUrgau-12/+12
2023-05-10Uplift clippy::forget_copy to rustcUrgau-2/+44
2023-05-10Uplift clippy::forget_ref to rustcUrgau-2/+36
2023-05-10Uplift clippy::drop_copy to rustcUrgau-2/+38
2023-05-10Uplift clippy::drop_ref to rustcUrgau-0/+88
2023-05-08Rollup merge of #109410 - fmease:iat-alias-kind-inherent, r=compiler-errorsMichael Goulet-3/+8
Introduce `AliasKind::Inherent` for inherent associated types Allows us to check (possibly generic) inherent associated types for well-formedness. Type inference now also works properly. Follow-up to #105961. Supersedes #108430. Fixes #106722. Fixes #108957. Fixes #109768. Fixes #109789. Fixes #109790. ~Not to be merged before #108860 (`AliasKind::Weak`).~ CC `@jackh726` r? `@compiler-errors` `@rustbot` label T-types F-inherent_associated_types
2023-05-07Rollup merge of #111300 - Flying-Toast:while_true_span_condition, ↵Yuki Okushi-2/+1
r=compiler-errors Emit while_true lint spanning the entire loop condition The lint that suggests `loop {}` instead of `while true {}` has functionality to 'pierce' parenthesis in cases like `while (true) {}`. In these cases, the emitted span only went to the hi of the `true` itself, not spanning the entire loop condition. Before: ``` warning: denote infinite loops with `loop { ... }` --> /tmp/foobar.rs:2:5 | 2 | while ((((((true)))))) {} | ^^^^^^^^^^^^^^^^ help: use `loop` | = note: `#[warn(while_true)]` on by default ``` After: ``` warning: denote infinite loops with `loop { ... }` --> /tmp/foobar.rs:2:5 | 2 | while ((((((true)))))) {} | ^^^^^^^^^^^^^^^^^^^^^^ help: use `loop` | = note: `#[warn(while_true)]` on by default ``` This is especially a problem for rustfix.
2023-05-07Rollup merge of #111150 - mj10021:issue-111025-fix, r=petrochenkovYuki Okushi-24/+5
added TraitAlias to check_item() for missing_docs As in issue #111025 the `missing_docs` was not being triggered for trait aliases. I added `TraitAlias` to the pattern match for check_item(), and the lint seems to be behaving appropriately
2023-05-06delete whitelist and add checks to check_item() for missing_docsJames Dietz-24/+5
add test and bless
2023-05-06Emit while_true lint spanning the entire loop conditionFlying-Toast-2/+1
The lint that suggests `loop {}` instead of `while true {}` has functionality to 'pierce' parenthesis in cases like `while (true) {}`. In these cases, the emitted span only went to the hi of the `true` itself, not spanning the entire loop condition. Before: ``` warning: denote infinite loops with `loop { ... }` --> /tmp/foobar.rs:2:5 | 2 | while ((((((true)))))) {} | ^^^^^^^^^^^^^^^^ help: use `loop` | = note: `#[warn(while_true)]` on by default ``` After: ``` warning: denote infinite loops with `loop { ... }` --> /tmp/foobar.rs:2:5 | 2 | while ((((((true)))))) {} | ^^^^^^^^^^^^^^^^^^^^^^ help: use `loop` | = note: `#[warn(while_true)]` on by default ```
2023-05-06Check arguments length in trivial diagnostic lintclubby789-2/+4
2023-05-06introduce `DynSend` and `DynSync` auto traitSparrowLii-10/+10
2023-05-05Improve check-cfg diagnostics (part 2)Urgau-9/+45
2023-05-05Improve check-cfg diagnostics (part 1)Urgau-8/+8
2023-05-05Improve internal representation of check-cfgUrgau-16/+18
This is done to simplify to relationship between names() and values() but also make thing clearer (having an Any to represent that any values are allowed) but also to allow the (none) + values expected cases that wasn't possible before.
2023-05-04IAT: Introduce AliasKind::InherentLeón Orell Valerian Liehr-3/+8
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-11/+11
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
2023-04-29add match to diagnostic messagesDeadbeef-3/+3
2023-04-28uplift `clippy::clone_double_ref` as `suspicious_double_ref_op`Deadbeef-18/+71
2023-04-27rename `needs_subst` to `has_param`Boxy-1/+1
2023-04-26Rollup merge of #108760 - clubby789:autolintstuff, r=wesleywiserMatthias Krüger-1/+84
Add lint to deny diagnostics composed of static strings r? ghost I'm hoping to have a lint that semi-automatically converts simple diagnostics such as `struct_span_err(span, "msg").help("msg").span_note(span2, "msg").emit()` to typed session diagnostics. It's quite hacky and not entirely working because of problems with `x fix` but should hopefully help reduce some of the work. I'm going to start trying to apply what I can from this, but opening this as a draft in case anyone wants to develop on it. cc #100717
2023-04-25Rollup merge of #110556 - kylematsuda:earlybinder-explicit-item-bounds, ↵Matthias Krüger-3/+3
r=compiler-errors Switch to `EarlyBinder` for `explicit_item_bounds` Part of the work to finish https://github.com/rust-lang/rust/issues/105779. This PR adds `EarlyBinder` to the return type of the `explicit_item_bounds` query and removes `bound_explicit_item_bounds`. r? `@compiler-errors` (hope it's okay to request you, since you reviewed #110299 and #110498 :smiley:)
2023-04-25Add deny lint to prevent untranslatable diagnostics using static stringsclubby789-1/+84
2023-04-24Split `{Idx, IndexVec, IndexSlice}` into their own modulesMaybe Waffle-1/+1
2023-04-20add subst_identity_iter and subst_identity_iter_copied methods on ↵Kyle Matsuda-26/+18
EarlyBinder; use this to simplify some EarlyBinder noise around explicit_item_bounds calls