about summary refs log tree commit diff
path: root/compiler/rustc_lint_defs/src
AgeCommit message (Collapse)AuthorLines
2024-09-15Rollup merge of #130353 - Zalathar:lint-zero, r=jieyouxuStuart Cook-0/+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-14Make some lint doctests compatible with `--stage=0`Zalathar-0/+1
2024-09-13Disallow hidden references to mutable staticObei Sideg-53/+1
2024-09-10const-eval interning: accpt interior mutable pointers in final value (but ↵Ralf Jung-46/+0
keep rejecting mutable references)
2024-09-07Rollup merge of #126452 - compiler-errors:raw-lifetimes, r=spastorinoMatthias Krüger-0/+2
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-06Add initial support for raw lifetimesMichael Goulet-0/+2
2024-09-06elided_named_lifetimes: unify lint def & pass MissingLifetimeKindPavel Grigorenko-7/+10
2024-09-04update docs of missing_abi lintKalle Wachsmuth-5/+7
2024-09-01Auto merge of #127313 - cjgillot:single-expect, r=jieyouxubors-26/+5
Rewrite lint_expectations in a single pass. This PR aims at reducing the perf regression from https://github.com/rust-lang/rust/pull/120924#issuecomment-2202486203 with drive-by simplifications. Basically, instead of using the lint level builder, which is slow, this PR splits `lint_expectations` logic in 2: - listing the `LintExpectations` is done in `shallow_lint_levels_on`, on a per-owner basis; - building the unstable->stable expectation id map is done by iterating on attributes. r? ghost for perf
2024-09-01Rollup merge of #129207 - GrigorenkoPV:elided-is-named, r=cjgillotMatthias Krüger-0/+40
Lint that warns when an elided lifetime ends up being a named lifetime As suggested in https://github.com/rust-lang/rust/issues/48686#issuecomment-1817334575 Fixes #48686
2024-08-31Remove attr_id from stable lint ids.Camille GILLOT-26/+5
2024-08-31Implement `elided_named_lifetimes` lintPavel Grigorenko-0/+40
2024-08-31Rollup merge of #129534 - workingjubilee:ratchet-wasm-c-abi-fcw-to-deny, ↵Matthias Krüger-1/+1
r=daxpedda,alexcrichton Deny `wasm_c_abi` lint to nudge the last 25% This shouldn't affect projects indirectly depending on wasm-bindgen because cargo passes `--cap-lints=allow` when building dependencies. The motivation is that the ecosystem has mostly taken up the versions of wasm-bindgen that are compatible in general, but ~25% or so of recent downloads remain on lower versions. However, this change might still be unnecessarily disruptive. I mostly propose it as a discussion point.
2024-08-27Add `warn(unreachable_pub)` to `rustc_lint_defs`.Nicholas Nethercote-0/+4
2024-08-24Deny wasm_c_abi lint to nudge the last 25%Jubilee Young-1/+1
This shouldn't affect projects indirectly depending on wasm-bindgen because cargo passes `--cap-lints=allow` when building dependencies.
2024-08-24Rollup merge of #129199 - RalfJung:writes_through_immutable_pointer, ↵Matthias Krüger-35/+0
r=compiler-errors make writes_through_immutable_pointer a hard error This turns the lint added in https://github.com/rust-lang/rust/pull/118324 into a hard error. This has been reported in cargo's future-compat reports since Rust 1.76 (released in February). Given that const_mut_refs is still unstable, it should be impossible to even hit this error on stable: we did accidentally stabilize some functions that can cause this error, but that got reverted in https://github.com/rust-lang/rust/pull/117905. Still, let's do a crater run just to be sure. Given that this should only affect unstable code, I don't think it needs an FCP, but let's Cc ``@rust-lang/lang`` anyway -- any objection to making this unambiguous UB into a hard error during const-eval? This can be viewed as part of https://github.com/rust-lang/rust/pull/129195 which is already nominated for discussion.
2024-08-21Rollup merge of #128727 - RalfJung:conflicting-repr-future-incompat, r=lcnrMatthias Krüger-1/+1
bump conflicting_repr_hints lint to be shown in dependencies This has been a future compatibility lint for years, let's bump it up to be shown in dependencies (so that hopefully we can then make it a hard error fairly soon). Cc https://github.com/rust-lang/rust/issues/68585
2024-08-17Auto merge of #128771 - carbotaniuman:stabilize_unsafe_attr, r=nnethercotebors-1/+0
Stabilize `unsafe_attributes` # Stabilization report ## Summary This is a tracking issue for the RFC 3325: unsafe attributes We are stabilizing `#![feature(unsafe_attributes)]`, which makes certain attributes considered 'unsafe', meaning that they must be surrounded by an `unsafe(...)`, as in `#[unsafe(no_mangle)]`. RFC: rust-lang/rfcs#3325 Tracking issue: #123757 ## What is stabilized ### Summary of stabilization Certain attributes will now be designated as unsafe attributes, namely, `no_mangle`, `export_name`, and `link_section` (stable only), and these attributes will need to be called by surrounding them in `unsafe(...)` syntax. On editions prior to 2024, this is simply an edition lint, but it will become a hard error in 2024. This also works in `cfg_attr`, but `unsafe` is not allowed for any other attributes, including proc-macros ones. ```rust #[unsafe(no_mangle)] fn a() {} #[cfg_attr(any(), unsafe(export_name = "c"))] fn b() {} ``` For a table showing the attributes that were considered to be included in the list to require unsafe, and subsequent reasoning about why each such attribute was or was not included, see [this comment here](https://github.com/rust-lang/rust/pull/124214#issuecomment-2124753464) ## Tests The relevant tests are in `tests/ui/rust-2024/unsafe-attributes` and `tests/ui/attributes/unsafe`.
2024-08-17make writes_through_immutable_pointer a hard errorRalf Jung-35/+0
2024-08-07Disallow setting built-in cfgs via set the command-lineUrgau-0/+39
2024-08-07Make `Span` optional in `BufferedEarlyLint`Urgau-2/+2
2024-08-07Stabilize `unsafe_attributes`carbotaniuman-1/+0
2024-08-06bump conflicting_repr_hints lint to be shown in dependenciesRalf Jung-1/+1
2024-08-05Rollup merge of #127907 - RalfJung:byte_slice_in_packed_struct_with_derive, ↵Matthias Krüger-34/+0
r=nnethercote built-in derive: remove BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE hack and lint Fixes https://github.com/rust-lang/rust/issues/107457 by turning the lint into a hard error. The lint has been shown in future breakage reports since Rust 1.69 (released in April 2023). Let's see (via crater) if enough time has passed since https://github.com/rust-lang/rust/pull/104429, and https://github.com/unicode-org/icu4x/pull/2834 has propagated far enough to let us make this a hard error. Cc ``@nnethercote`` ``@Manishearth``
2024-08-05Rollup merge of #127655 - RalfJung:invalid_type_param_default, r=compiler-errorsMatthias Krüger-1/+1
turn `invalid_type_param_default` into a `FutureReleaseErrorReportInDeps` `````@rust-lang/types````` I assume the plan is still to disallow this? It has been a future-compat lint for a long time, seems ripe to go for hard error. However, turns out that outright removing it right now would lead to [tons of crater regressions](https://github.com/rust-lang/rust/pull/127655#issuecomment-2228285460), so for now this PR just makes this future-compat lint show up in cargo's reports, so people are warned when they use a dependency that is affected by this. Fixes https://github.com/rust-lang/rust/issues/27336 by removing the feature gate (so there's no way to silence the lint even on nightly) CC https://github.com/rust-lang/rust/issues/36887
2024-08-03Rollup merge of #127921 - spastorino:stabilize-unsafe-extern-blocks, ↵Matthias Krüger-1/+0
r=compiler-errors Stabilize unsafe extern blocks (RFC 3484) # Stabilization report ## Summary This is a tracking issue for the RFC 3484: Unsafe Extern Blocks We are stabilizing `#![feature(unsafe_extern_blocks)]`, as described in [Unsafe Extern Blocks RFC 3484](https://github.com/rust-lang/rfcs/pull/3484). This feature makes explicit that declaring an extern block is unsafe. Starting in Rust 2024, all extern blocks must be marked as unsafe. In all editions, items within unsafe extern blocks may be marked as safe to use. RFC: https://github.com/rust-lang/rfcs/pull/3484 Tracking issue: #123743 ## What is stabilized ### Summary of stabilization We now need extern blocks to be marked as unsafe and items inside can also have safety modifiers (unsafe or safe), by default items with no modifiers are unsafe to offer easy migration without surprising results. ```rust unsafe extern { // sqrt (from libm) may be called with any `f64` pub safe fn sqrt(x: f64) -> f64; // strlen (from libc) requires a valid pointer, // so we mark it as being an unsafe fn pub unsafe fn strlen(p: *const c_char) -> usize; // this function doesn't say safe or unsafe, so it defaults to unsafe pub fn free(p: *mut core::ffi::c_void); pub safe static IMPORTANT_BYTES: [u8; 256]; pub safe static LINES: SyncUnsafeCell<i32>; } ``` ## Tests The relevant tests are in `tests/ui/rust-2024/unsafe-extern-blocks`. ## History - https://github.com/rust-lang/rust/pull/124482 - https://github.com/rust-lang/rust/pull/124455 - https://github.com/rust-lang/rust/pull/125077 - https://github.com/rust-lang/rust/pull/125522 - https://github.com/rust-lang/rust/issues/126738 - https://github.com/rust-lang/rust/issues/126749 - https://github.com/rust-lang/rust/issues/126755 - https://github.com/rust-lang/rust/pull/126757 - https://github.com/rust-lang/rust/pull/126758 - https://github.com/rust-lang/rust/issues/126756 - https://github.com/rust-lang/rust/pull/126973 - https://github.com/rust-lang/rust/pull/127535 - https://github.com/rust-lang/rustfmt/pull/6204 ## Unresolved questions I am not aware of any unresolved questions.
2024-07-31Rollup merge of #123813 - compiler-errors:redundant-lint, r=petrochenkovMatthias Krüger-0/+26
Add `REDUNDANT_IMPORTS` lint for new redundant import detection Defaults to Allow for now. Stacked on #123744 to avoid merge conflict, but much easier to review all as one. r? petrochenkov
2024-07-31Rollup merge of #128412 - compiler-errors:crate-level-only, r=cjgillotMatthias Krüger-2/+1
Remove `crate_level_only` from `ELIDED_LIFETIMES_IN_PATHS` As far as I can tell, we provide the right node id to the `ELIDED_LIFETIMES_IN_PATHS` lint: https://github.com/rust-lang/rust/blob/f8060d282d42770fadd73905e3eefb85660d3278/compiler/rustc_resolve/src/late.rs#L2015-L2027 So I've gone ahead and removed the restriction from this lint.
2024-07-31Introduce REDUNDANT_IMPORTS lintMichael Goulet-0/+26
2024-07-30Remove crate_level_only from ELIDED_LIFETIMES_IN_PATHSMichael Goulet-2/+1
2024-07-30Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68bors-2/+0
Bump bootstrap compiler to new beta https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-07-29Reformat `use` declarations.Nicholas Nethercote-7/+7
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28step cfg(bootstrap)Mark Rousskov-2/+0
2024-07-28Rollup merge of #125889 - Nilstrieb:migrate-into-the-future, r=compiler-errorsMatthias Krüger-0/+41
Add migration lint for 2024 prelude additions This adds the migration lint for the newly ambiguous methods `poll` and `into_future`. When these methods are used on types implementing the respective traits, it will be ambiguous in the future, which can lead to hard errors or behavior changes depending on the exact circumstances. tracked by #121042 <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> r? compiler-errors as the method prober
2024-07-28Add migration lint for 2024 prelude additionsNilstrieb-0/+41
This adds the migration lint for the newly ambiguous methods `poll` and `into_future`. When these methods are used on types implementing the respective traits, it will be ambiguous in the future, which can lead to hard errors or behavior changes depending on the exact circumstances.
2024-07-28stabilize `is_sorted`Slanterns-4/+8
2024-07-27built-in derive: remove BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE hack and lintRalf Jung-34/+0
2024-07-24Mark `missing_fragment_specifier` as `FutureReleaseErrorReportInDeps`Trevor Gross-1/+1
We are moving toward forbidding `missing_fragment_specifier` either in edition 2024 or unconditionally. Make a first step toward this by ensuring crates that rely on the old behavior are reported when used as dependencies. Tracking issue: <https://github.com/rust-lang/rust/issues/128143>
2024-07-23Stabilize unsafe extern blocks (RFC 3484)Santiago Pastorino-1/+0
2024-07-22Rollup merge of #125990 - tbu-:pr_unsafe_env_lint_name, r=ehussTrevor Gross-6/+6
Rename `deprecated_safe` lint to `deprecated_safe_2024` Create a lint group `deprecated_safe` that includes `deprecated_safe_2024`. Addresses https://github.com/rust-lang/rust/issues/124866#issuecomment-2142814375. r? `@ehuss`
2024-07-18make pub_use_of_private_extern_crate show up in future breakage reportsRalf Jung-4/+4
2024-07-17Rename `deprecated_safe` lint to `deprecated_safe_2024`Tobias Bucher-6/+6
Create a lint group `deprecated_safe` that includes `deprecated_safe_2024`. Addresses https://github.com/rust-lang/rust/issues/124866#issuecomment-2142814375.
2024-07-15make invalid_type_param_default lint show up in cargo future-compat reportsRalf Jung-1/+1
and remove the feature gate that silenced the lint
2024-07-11Auto merge of #127097 - compiler-errors:async-closure-lint, r=oli-obkbors-13/+12
Implement simple, unstable lint to suggest turning closure-of-async-block into async-closure We want to eventually suggest people to turn `|| async {}` to `async || {}`. This begins doing that. It's a pretty rudimentary lint, but I wanted to get something down so I wouldn't lose the code. Tracking: * #62290
2024-07-10Rollup merge of #124211 - ↵Jacob Pratt-1/+1
compiler-errors:bump-elided_lifetimes_in_associated_constant, r=BoxyUwU Bump `elided_lifetimes_in_associated_constant` to deny It's been 5 versions since this was last bumped. Let's bump it up again.
2024-07-08Rollup merge of #120248 - WaffleLapkin:bonk-ptr-object-casts, ↵Matthias Krüger-0/+53
r=compiler-errors,oli-obk,lnicola Make casts of pointers to trait objects stricter This is an attempt to `fix` https://github.com/rust-lang/rust/issues/120222 and https://github.com/rust-lang/rust/issues/120217. This is done by adding restrictions on casting pointers to trait objects. Before this PR the rules were as follows: > When casting `*const X<dyn A>` -> `*const Y<dyn B>`, principal traits in `A` and `B` must refer to the same trait definition (or no trait). With this PR the rules are changed to > When casting `*const X<dyn Src>` -> `*const Y<dyn Dst>` > - if `Dst` has a principal trait `DstP`, > - `Src` must have a principal trait `SrcP` > - `dyn SrcP` and `dyn DstP` must be the same type (modulo the trait object lifetime, `dyn T+'a` -> `dyn T+'b` is allowed) > - Auto traits in `Dst` must be a subset of auto traits in `Src` > - Not adhering to this is currently a FCW (warn-by-default + `FutureReleaseErrorReportInDeps`), instead of an error > - if `Src` has a principal trait `Dst` must as well > - this restriction will be removed in a follow up PR This ensures that 1. Principal trait's generic arguments match (no `*const dyn Tr<A>` -> `*const dyn Tr<B>` casts, which are a problem for [#120222](https://github.com/rust-lang/rust/issues/120222)) 2. Principal trait's lifetime arguments match (no `*const dyn Tr<'a>` -> `*const dyn Tr<'b>` casts, which are a problem for [#120217](https://github.com/rust-lang/rust/issues/120217)) 3. No auto traits can be _added_ (this is a problem for arbitrary self types, see [this comment](https://github.com/rust-lang/rust/pull/120248#discussion_r1463835350)) Some notes: - We only care about the metadata/last field, so you can still cast `*const dyn T` to `*const WithHeader<dyn T>`, etc - The lifetime of the trait object itself (`dyn A + 'lt`) is not checked, so you can still cast `*mut FnOnce() + '_` to `*mut FnOnce() + 'static`, etc - This feels fishy, but I couldn't come up with a reason it must be checked The diagnostics are currently not great, to say the least, but as far as I can tell this correctly fixes the issues. cc `@oli-obk` `@compiler-errors` `@lcnr`
2024-07-08Rollup merge of #126881 - ↵许杰友 Jieyou Xu (Joe)-0/+1
WaffleLapkin:unsafe-code-affected-by-fallback-hard-in-2024, r=compiler-errors Make `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` a deny-by-default lint in edition 2024 I don't actually really care about this, but ``@traviscross`` asked me to do this, because lang team briefly discussed this before. (TC here:) Specifically, our original FCPed plan included this step: - Add a lint against fallback affecting a generic that is passed to an `unsafe` function. - Perhaps make this lint `deny-by-default` or a hard error in Rust 2024. That is, we had left as an open question strengthening this in Rust 2024, and had marked it as an open question on the tracking issue. We're nominating here to address the open question. (Closing the remaining open question helps us to fully mark this off for Rust 2024.) r? ``@compiler-errors`` Tracking: - https://github.com/rust-lang/rust/issues/123748
2024-07-04Fill in tracking issueMaybe Lapkin-2/+1
2024-07-04Align the changes to the lang decisionMaybe Lapkin-0/+54
2024-07-01Ensure `out_of_scope_macro_calls` lint is registeredbeetrees-0/+1