about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2024-09-20compiler: reuse {un,}signed_fit in get_type_suggestion (nfc)Jubilee Young-40/+14
no need for a weird macro when a self-explanatory `match` will do.
2024-09-20compiler: factor OVERFLOWING_LITERALS impl into a file (nfc)Jubilee Young-405/+421
no functional changes should arise, just moves the lint impl details out of a very crowded file with lots of different lints in it.
2024-09-20Auto merge of #124895 - obeis:static-mut-hidden-ref, r=compiler-errorsbors-0/+189
Disallow hidden references to mutable static Closes #123060 Tracking: - https://github.com/rust-lang/rust/issues/123758
2024-09-20Add recursion limit to FFI safety lintGurinder Singh-3/+17
Fixes stack overflow in the case of recursive types
2024-09-19warn less about non-exhaustive in ffiJubilee Young-9/+18
Bindgen allows generating `#[non_exhaustive] #[repr(u32)]` enums. This results in nonintuitive nonlocal `improper_ctypes` warnings, even when the types are otherwise perfectly valid in C. Adjust for actual tooling expectations by avoiding warning on simple enums with only unit variants.
2024-09-18Rollup merge of #130507 - Urgau:check-cfg-raw-keywords, r=jieyouxuMatthias Krüger-4/+13
Improve handling of raw-idents in check-cfg This PR improves the handling of raw-idents in the check-cfg diagnostics. In particular the list of expected names and the suggestion now correctly take into account the "keyword-ness" of the ident, and correctly prefix the ident with `r#` when necessary. `@rustbot` labels +F-check-cfg
2024-09-18Improve handling of raw-idents in check-cfgUrgau-4/+13
2024-09-17Rollup merge of #130469 - compiler-errors:wc-obj-safety, r=jackh726Matthias Krüger-0/+5
Mark `where_clauses_object_safety` as removed r? lcnr
2024-09-17Mark where_clauses_object_safety as removedMichael Goulet-0/+5
2024-09-16Don't ICE in opaque_hidden_inferred_bound lint for RPITIT in trait with no ↵Michael Goulet-0/+12
default method body
2024-09-15Rollup merge of #130293 - gurry:130142-lint-level-issue, r=cjgillotMatthias Krüger-5/+3
Fix lint levels not getting overridden by attrs on `Stmt` nodes Fixes #130142. See comments on the issue for context. r? `@cjgillot`
2024-09-15Rollup merge of #130353 - Zalathar:lint-zero, r=jieyouxuStuart Cook-1/+1
Make some lint doctests compatible with `--stage=0` Currently, running `x test compiler --stage=0` (with `rust.parallel-compiler=false` to avoid other problems) results in two failures, because these lint doctests aren't compatible with the current stage0 compiler. In theory, the more “correct” solution would be to wrap the opening triple-backtick line in `#[cfg_attr(not(bootstrap), doc = "..."]`. However, that causes a few practical problems: - `tidy` doesn't understand that syntax, and miscounts the number of backticks in the comment block. - `lint-docs` doesn't understand that syntax, and thinks it's trying to declare the lint name. - Working around the above problems would cause more work and more confusion for whoever does the next bootstrap beta bump. So instead this PR adds some bootstrap gates inside the individual doctests, which end up producing the desired behaviour, and are straightforward to remove.
2024-09-14Auto merge of #128543 - RalfJung:const-interior-mut, r=fee1-deadbors-0/+4
const-eval interning: accept interior mutable pointers in final value …but keep rejecting mutable references This fixes https://github.com/rust-lang/rust/issues/121610 by no longer firing the lint when there is a pointer with interior mutability in the final value of the constant. On stable, such pointers can be created with code like: ```rust pub enum JsValue { Undefined, Object(Cell<bool>), } impl Drop for JsValue { fn drop(&mut self) {} } // This does *not* get promoted since `JsValue` has a destructor. // However, the outer scope rule applies, still giving this 'static lifetime. const UNDEFINED: &JsValue = &JsValue::Undefined; ``` It's not great to accept such values since people *might* think that it is legal to mutate them with unsafe code. (This is related to how "infectious" `UnsafeCell` is, which is a [wide open question](https://github.com/rust-lang/unsafe-code-guidelines/issues/236).) However, we [explicitly document](https://doc.rust-lang.org/reference/behavior-considered-undefined.html) that things created by `const` are immutable. Furthermore, we also accept the following even more questionable code without any lint today: ```rust let x: &'static Option<Cell<i32>> = &None; ``` This is even more questionable since it does *not* involve a `const`, and yet still puts the data into immutable memory. We could view this as promotion [potentially introducing UB](https://github.com/rust-lang/unsafe-code-guidelines/issues/493). However, we've accepted this since ~forever and it's [too late to reject this now](https://github.com/rust-lang/rust/pull/122789); the pattern is just too useful. So basically, if you think that `UnsafeCell` should be tracked fully precisely, then you should want the lint we currently emit to be removed, which this PR does. If you think `UnsafeCell` should "infect" surrounding `enum`s, the big problem is really https://github.com/rust-lang/unsafe-code-guidelines/issues/493 which does not trigger the lint -- the cases the lint triggers on are actually the "harmless" ones as there is an explicit surrounding `const` explaining why things end up being immutable. What all this goes to show is that the hard error added in https://github.com/rust-lang/rust/pull/118324 (later turned into the future-compat lint that I am now suggesting we remove) was based on some wrong assumptions, at least insofar as it concerns shared references. Furthermore, that lint does not help at all for the most problematic case here where the potential UB is completely implicit. (In fact, the lint is actively in the way of [my preferred long-term strategy](https://github.com/rust-lang/unsafe-code-guidelines/issues/493#issuecomment-2028674105) for dealing with this UB.) So I think we should go back to square one and remove that error/lint for shared references. For mutable references, it does seem to work as intended, so we can keep it. Here it serves as a safety net in case the static checks that try to contain mutable references to the inside of a const initializer are not working as intended; I therefore made the check ICE to encourage users to tell us if that safety net is triggered. Closes https://github.com/rust-lang/rust/issues/122153 by removing the lint. Cc `@rust-lang/opsem` `@rust-lang/lang`
2024-09-14Rollup merge of #130343 - Fayti1703:patch-correct-async-block-lint-doc, ↵León Orell Valerian Liehr-0/+1
r=compiler-errors docs: Enable required feature for 'closure_returning_async_block' lint Failing to do this results in the lint example output complaining about the lint not existing instead of the thing the lint is supposed to be complaining about. See <https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#closure-returning-async-block>: ![image](https://github.com/user-attachments/assets/78bae16f-3fb6-4d6d-b8aa-768b477cd187)
2024-09-14Rollup merge of #130294 - nnethercote:more-lifetimes, r=lcnrLeón Orell Valerian Liehr-16/+16
Lifetime cleanups The last commit is very opinionated, let's see how we go. r? `@oli-obk`
2024-09-14Make some lint doctests compatible with `--stage=0`Zalathar-1/+1
2024-09-14Fix lint levels not getting overridden by attrs on `Stmt` nodesGurinder Singh-5/+3
2024-09-14docs: Enable required feature for 'closure_returning_async_block' lintFayti1703-0/+1
Failing to do this results in the lint example output complaining about the lint not existing instead of the thing the lint is supposed to be complaining about.
2024-09-13Disallow hidden references to mutable staticObei Sideg-0/+189
2024-09-13some fixes for clashing_extern_declarations lintRalf Jung-39/+35
2024-09-13Rename and reorder lots of lifetimes.Nicholas Nethercote-13/+13
- Replace non-standard names like 's, 'p, 'rg, 'ck, 'parent, 'this, and 'me with vanilla 'a. These are cases where the original name isn't really any more informative than 'a. - Replace names like 'cx, 'mir, and 'body with vanilla 'a when the lifetime applies to multiple fields and so the original lifetime name isn't really accurate. - Put 'tcx last in lifetime lists, and 'a before 'b.
2024-09-13Remove unnecessary lifetime from `BuiltinTypeAliasBounds`.Nicholas Nethercote-3/+3
2024-09-13Auto merge of #107251 - dingxiangfei2009:let-chain-rescope, r=jieyouxubors-0/+433
Rescope temp lifetime in if-let into IfElse with migration lint Tracking issue #124085 This PR shortens the temporary lifetime to cover only the pattern matching and consequent branch of a `if let`. At the expression location, means that the lifetime is shortened from previously the deepest enclosing block or statement in Edition 2021. This warrants an Edition change. Coming with the Edition change, this patch also implements an edition lint to warn about the change and a safe rewrite suggestion to preserve the 2021 semantics in most cases. Related to #103108. Related crater runs: https://github.com/rust-lang/rust/pull/129466.
2024-09-13simplify the suggestion notesDing Xiang Fei-108/+123
2024-09-12Rollup merge of #130235 - compiler-errors:nested-if, r=michaelwoeristerStuart Cook-4/+2
Simplify some nested `if` statements Applies some but not all instances of `clippy::collapsible_if`. Some ended up looking worse afterwards, though, so I left those out. Also applies instances of `clippy::collapsible_else_if` Review with whitespace disabled please.
2024-09-11Rollup merge of #130114 - eduardosm:needless-returns, r=compiler-errorsJubilee-1/+1
Remove needless returns detected by clippy in the compiler
2024-09-11Simplify some nested if statementsMichael Goulet-4/+2
2024-09-11Auto merge of #130050 - cjgillot:expect-attr-id, r=fee1-deadbors-51/+39
Enumerate lint expectations using AttrId This PR implements the idea I outlined in https://github.com/rust-lang/rust/issues/127884#issuecomment-2240338547 We can uniquely identify a lint expectation `#[expect(lint0, lint1...)]` using the `AttrId` and the index of the lint inside the attribute. This PR uses this property in `check_expectations`. In addition, this PR stops stashing expected diagnostics to wait for the unstable -> stable `LintExpectationId` mapping: if the lint is emitted with an unstable attribute, it must have been emitted by an `eval_always` query (like inside the resolver), so won't be loaded from cache. Decoding an `AttrId` from the on-disk cache ICEs, so we have no risk of accidentally checking an expectation. Fixes https://github.com/rust-lang/rust/issues/127884 cc `@xFrednet`
2024-09-11coalesce lint suggestions that can intersectDing Xiang Fei-109/+212
2024-09-11rescope temp lifetime in let-chain into IfElseDing Xiang Fei-0/+315
apply rules by span edition
2024-09-10Auto merge of #130025 - Urgau:missing_docs-expect, r=petrochenkovbors-6/+0
Also emit `missing_docs` lint with `--test` to fulfil expectations This PR removes the "test harness" suppression of the `missing_docs` lint to be able to fulfil `#[expect]` (expectations) as it is now "relevant". I think the goal was to maybe avoid false-positive while linting on public items under `#[cfg(test)]` but with effective visibility we should no longer have any false-positive. Another possibility would be to query the lint level and only emit the lint if it's of expect level, but that is even more hacky. Fixes https://github.com/rust-lang/rust/issues/130021 try-job: x86_64-gnu-aux
2024-09-10const-eval interning: accpt interior mutable pointers in final value (but ↵Ralf Jung-0/+4
keep rejecting mutable references)
2024-09-09Remove needless returns detected by clippy in the compilerEduardo Sánchez Muñoz-1/+1
2024-09-07Rollup merge of #126452 - compiler-errors:raw-lifetimes, r=spastorinoMatthias Krüger-5/+31
Implement raw lifetimes and labels (`'r#ident`) This PR does two things: 1. Reserve lifetime prefixes, e.g. `'prefix#lt` in edition 2021. 2. Implements raw lifetimes, e.g. `'r#async` in edition 2021. This PR additionally extends the `keyword_idents_2024` lint to also check lifetimes. cc `@traviscross` r? parser
2024-09-06Check AttrId for expectations.Camille GILLOT-51/+39
2024-09-06Lint against keyword lifetimes in keyword_identsMichael Goulet-5/+18
2024-09-06Add initial support for raw lifetimesMichael Goulet-0/+13
2024-09-06Hack around a conflict with `clippy::needless_lifetimes`Pavel Grigorenko-0/+7
2024-09-06elided_named_lifetimes: manually implement `LintDiagnostic`Pavel Grigorenko-31/+48
2024-09-06elided_named_lifetimes: add suggestionsPavel Grigorenko-16/+30
2024-09-06elided_named_lifetimes: unify lint def & pass MissingLifetimeKindPavel Grigorenko-10/+13
2024-09-06Also emit `missing_docs` lint with `--test` to fulfill expectationsUrgau-6/+0
2024-09-06Rollup merge of #129969 - GrigorenkoPV:boxed-ty, r=compiler-errorsMatthias Krüger-10/+8
Make `Ty::boxed_ty` return an `Option` Looks like a good place to use Rust's type system. --- Most of https://github.com/rust-lang/rust/blob/4ac7bcbaad8d6fd7a51bdf1b696cbc3ba4c796cf/compiler/rustc_middle/src/ty/sty.rs#L971-L1963 looks like it could be moved to `TyKind` (then I guess `Ty` should be made to deref to `TyKind`).
2024-09-06Auto merge of #129999 - matthiaskrgr:rollup-pzr9c8p, r=matthiaskrgrbors-3/+29
Rollup of 11 pull requests Successful merges: - #128919 (Add an internal lint that warns when accessing untracked data) - #129472 (fix ICE when `asm_const` and `const_refs_to_static` are combined) - #129653 (clarify that addr_of creates read-only pointers) - #129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails) - #129939 (explain why Rvalue::Len still exists) - #129942 (copy rustc rustlib artifacts from ci-rustc) - #129943 (use the bootstrapped compiler for `test-float-parse` test) - #129944 (Add compat note for trait solver change) - #129947 (Add digit separators in `Duration` examples) - #129955 (Temporarily remove fmease from the review rotation) - #129957 (forward linker option to lint-docs) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-06Make `Ty::boxed_ty` return an `Option`Pavel Grigorenko-10/+8
2024-09-05Review commentsMichael Goulet-48/+40
2024-09-05Do less work on the good pathMichael Goulet-110/+113
2024-09-05Don't worry about uncaptured contravariant lifetimes if they outlive a ↵Michael Goulet-21/+226
captured lifetime
2024-09-03Add an internal lint that warns when accessing untracked dataNadrieril-3/+29
2024-09-02Rollup merge of #129877 - Sajjon:sajjon_fix_typos_batch_2, r=fee1-deadMatthias Krüger-1/+1
chore: Fix typos in 'compiler' (batch 2) Batch 2/3: Fixes typos in `compiler` (See [issue](https://github.com/rust-lang/rust/issues/129874) tracking all PRs with typos fixes)