about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2024-02-23Rollup merge of #121471 - estebank:lint-clone, r=TaKO8KiMatthias Krüger-1/+17
When encountering `<&T as Clone>::clone(x)` because `T: Clone`, suggest `#[derive(Clone)]` CC #40699. ``` warning: call to `.clone()` on a reference in this situation does nothing --> $DIR/noop-method-call.rs:23:71 | LL | let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone(); | ^^^^^^^^ | = note: the type `PlainType<u32>` does not implement `Clone`, so calling `clone` on `&PlainType<u32>` copies the reference, which does not do anything and can be removed help: remove this redundant call | LL - let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone(); LL + let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref; | help: if you meant to clone `PlainType<u32>`, implement `Clone` for it | LL + #[derive(Clone)] LL | struct PlainType<T>(T); | ```
2024-02-22When encountering `<&T as Clone>::clone(x)` because `T: Clone`, suggest ↵Esteban Küber-1/+17
`#[derive(Clone)]` CC #40699.
2024-02-21Rollup merge of #121338 - ↵Dylan DPC-3/+6
jieyouxu:ambiguous_wide_pointer_comparisons_suggestion, r=Nadrieril Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect In certain cases like #121330, it is possible to have more than one suggestion from the `ambiguous_wide_pointer_comparisons` lint (which before this PR are `MachineApplicable`). When this gets passed to rustfix, rustfix makes *multiple* changes according to the suggestions which result in incorrect code. This is a temporary workaround. The real long term solution to problems like these is to address <https://github.com/rust-lang/rust/issues/53934>. This PR also includes a drive-by edit to the panic message emitted by compiletest because "ui" test suite now uses `//`@`` directives. Fixes #121330.
2024-02-20Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect许杰友 Jieyou Xu (Joe)-3/+6
It is possible to have more than one valid suggestion, which when applied together via rustfix causes the code to no longer compile. This is a temporary workaround; the real long term solution to these issues is to solve <https://github.com/rust-lang/rust/issues/53934>.
2024-02-20Rollup merge of #121318 - kadiwa4:no_assembly_in_supposedly_safe_code, ↵Nilstrieb-0/+7
r=Nilstrieb Trigger `unsafe_code` lint on invocations of `global_asm` `unsafe_code` already warns about things that don't involve the `unsafe` keyword, e.g. `#[no_mangle]`. This makes it warn on `core::arch::global_asm` too. Fixes #103078
2024-02-20Add newtype for raw identsclubby789-1/+1
2024-02-20Auto merge of #120576 - nnethercote:merge-Diagnostic-DiagnosticBuilder, ↵bors-17/+65
r=davidtwco Overhaul `Diagnostic` and `DiagnosticBuilder` Implements the first part of https://github.com/rust-lang/compiler-team/issues/722, which moves functionality and use away from `Diagnostic`, onto `DiagnosticBuilder`. Likely follow-ups: - Move things around, because this PR was written to minimize diff size, so some things end up in sub-optimal places. E.g. `DiagnosticBuilder` has impls in both `diagnostic.rs` and `diagnostic_builder.rs`. - Rename `Diagnostic` as `DiagInner` and `DiagnosticBuilder` as `Diag`. r? `@davidtwco`
2024-02-20Auto merge of #121087 - oli-obk:eager_const_failures, r=lcnrbors-28/+0
Always evaluate free constants and statics, even if previous errors occurred work towards https://github.com/rust-lang/rust/issues/79738 We will need to evaluate static items before the `definitions.freeze()` below, as we will start creating new `DefId`s (for nested allocations) within the `eval_static_initializer` query. But even without that motivation, this is a good change. Hard errors should always be reported and not silenced if other errors happened earlier.
2024-02-20Reduce capabilities of `Diagnostic`.Nicholas Nethercote-17/+65
Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-20trigger `unsafe_code` on `global_asm!` invocationsKalle Wachsmuth-0/+7
2024-02-19Always evaluate free constants and statics, even if previous errors occurredOli Scherer-28/+0
2024-02-19Remove suspicious auto trait lintSantiago Pastorino-0/+5
2024-02-18Auto merge of #121034 - obeis:improve-static-mut-ref, r=RalfJungbors-0/+1
Improve wording of `static_mut_ref` Close #120964
2024-02-18Rollup merge of #121237 - Urgau:better-cargo-heuristic, r=compiler-errorsLeón Orell Valerian Liehr-2/+2
Use better heuristic for printing Cargo specific diagnostics It was [reported](https://github.com/rust-lang/rust/issues/82450#issuecomment-1948574677) in the check-cfg call for testing that the Rust for Linux project is setting the `CARGO` env without compiling with it, which is an issue since we are using the `CARGO` env as a proxy for "was launched from Cargo". This PR switch to the `CARGO_CRATE_NAME` [Cargo env](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates), which shouldn't collide (as much) with other build systems. I also took the opportunity to consolidate all the checks under the same function.
2024-02-18Improve wording of static_mut_refObei Sideg-0/+1
Rename `static_mut_ref` lint to `static_mut_refs`.
2024-02-17Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercoteMatthias Krüger-1/+1
errors: only eagerly translate subdiagnostics Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). r? ```@nnethercote```
2024-02-17Use better heuristic for printing Cargo specific diagnosticsUrgau-2/+2
2024-02-17Add cargo update suggestion for non local defsUrgau-3/+40
2024-02-17Add const-anon suggestion for non local implUrgau-2/+22
2024-02-17Implement RFC3373 non local definitions lintUrgau-0/+207
2024-02-16Auto merge of #120500 - oli-obk:intrinsics2.0, r=WaffleLapkinbors-1/+1
Implement intrinsics with fallback bodies fixes #93145 (though we can port many more intrinsics) cc #63585 The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The `Instance` (that was `InstanceDef::Intrinsic`) then gets converted to `InstanceDef::Item`, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for * codegen_ssa (so llvm and gcc) * codegen_cranelift other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body). cc `@scottmcm` `@WaffleLapkin` ### todo * [ ] miri support * [x] default intrinsic name to name of function instead of requiring it to be specified in attribute * [x] make sure that the bodies are always available (must be collected for metadata)
2024-02-16Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnaybors-3/+3
Use generic `NonZero` internally. Tracking issue: https://github.com/rust-lang/rust/issues/120257
2024-02-15Auto merge of #121142 - GuillaumeGomez:rollup-5qmksjw, r=GuillaumeGomezbors-0/+7
Rollup of 8 pull requests Successful merges: - #120449 (Document requirements for unsized {Rc,Arc}::from_raw) - #120505 (Fix BTreeMap's Cursor::remove_{next,prev}) - #120672 (std::thread update freebsd stack guard handling.) - #121088 (Implicitly enable evex512 if avx512 is enabled) - #121104 (Ignore unsized types when trying to determine the size of the original type) - #121107 (Fix msg for verbose suggestions with confusable capitalization) - #121113 (Continue compilation even if inherent impl checks fail) - #121120 (Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-15Auto merge of #120931 - chenyukang:yukang-cleanup-hashmap, r=michaelwoeristerbors-13/+10
Clean up potential_query_instability with FxIndexMap and UnordMap From https://github.com/rust-lang/rust/pull/120485#issuecomment-1916437191 r? `@michaelwoerister`
2024-02-15errors: only eagerly translate subdiagnosticsDavid Wood-1/+1
Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). Signed-off-by: David Wood <david@davidtw.co>
2024-02-15Use generic `NonZero` internally.Markus Reiter-3/+3
2024-02-14Ignore unsized types when trying to determine the size of a typeUrgau-0/+7
2024-02-14Rollup merge of #121075 - chenyukang:yukang-fix-121070-lint-range, r=oli-obkGuillaume Gomez-4/+12
Fix false positive with if let and ranges Fixes #121070
2024-02-14clean up potential_query_instability with FxIndexMap and UnordMapyukang-13/+10
2024-02-14Use fewer delayed bugs.Nicholas Nethercote-7/+6
For some cases where it's clear that an error has already occurred, e.g.: - there's a comment stating exactly that, or - things like HIR lowering, where we are lowering an error kind The commit also tweaks some comments around delayed bug sites.
2024-02-14Fix false positive with if let and rangesyukang-4/+12
2024-02-12Introduce small cache to avoid recomputing the same value twiceUrgau-4/+13
2024-02-12Lint on reference casting to bigger underlying allocationUrgau-8/+79
2024-02-12Make `is_intrinsic` query return the intrinsic nameOli Scherer-1/+1
2024-02-11Rollup merge of #120872 - petrochenkov:opthirpar, r=cjgillotMatthias Krüger-20/+14
hir: Refactor getters for HIR parents See individual commits. I ended up removing on of the FIXMEs from https://github.com/rust-lang/rust/pull/120206 instead of addressing it.
2024-02-10Rollup merge of #120866 - Zalathar:no-min-spec, r=compiler-errorsMatthias Krüger-1/+0
Remove unnecessary `#![feature(min_specialization)]` As of #119963 and #120676, we can now rely on `newtype_index!` having `#[allow_internal_unstable(min_specialization)]`, so there are a few compiler crates that no longer need to include min-spec in their own crate features. --- Some of the expansions of `newtype_index!` still appear to require min-spec in the crate features. I think this is because `#[orderable]` causes the expansion to include an implementation of `TrustedStep`, which is flagged with `#[rustc_specialization_trait]`, and for whatever reason that isn't permitted by allow-internal-unstable. So this PR only touches the crates where that isn't the case.
2024-02-10hir: Remove `hir::Map::{opt_parent_id,parent_id,get_parent,find_parent}`Vadim Petrochenkov-20/+14
2024-02-10Remove unnecessary `#![feature(min_specialization)]`Zalathar-1/+0
2024-02-10Rollup merge of #120853 - blyxyas:no-collect, r=cjgillotMatthias Krüger-6/+3
Avoid a collection and iteration on empty passes Just some mini optimization I saw in the wild. This way, we avoid a `collect` and `map` on an empty `passes`. Honestly, I don't even think this is big enough of a change to make a benchmark, but I'd still like to see results. Based on [this book](https://nnethercote.github.io/perf-book/iterators.html#collect-and-extend)
2024-02-09tidyblyxyas-4/+1
2024-02-09Avoid a collection and iteration on empty passesblyxyas-6/+6
2024-02-09Auto merge of #120676 - Mark-Simulacrum:bootstrap-bump, r=clubby789bors-1/+1
Bump bootstrap compiler to just-built 1.77 beta https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-02-09Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwcoMatthias Krüger-5/+4
Invert diagnostic lints. That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has been converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted. r? ````@davidtwco````
2024-02-08Auto merge of #120544 - BoxyUwU:enter_forall, r=lcnrbors-89/+92
Introduce `enter_forall` to supercede `instantiate_binder_with_placeholders` r? `@lcnr` Long term we'd like to experiment with decrementing the universe count after "exiting" binders so that we do not end up creating infer vars in non-root universes even when they logically reside in the root universe. The fact that we dont do this currently results in a number of issues in the new trait solver where we consider goals to be ambiguous because otherwise it would require lowering the universe of an infer var. i.e. the goal `?x.0 eq <T as Trait<?y.1>>::Assoc` where the alias is rigid would not be able to instantiate `?x` with the alias as there would be a universe error. This PR is the first-ish sort of step towards being able to implement this as eventually we would want to decrement the universe in `enter_forall`. Unfortunately its Difficult to actually implement decrementing universes nicely so this is a separate step which moves us closer to the long term goal :sparkles:
2024-02-08introduce `enter_forall`Boxy-89/+92
2024-02-08Step all bootstrap cfgs forwardMark Rousskov-1/+1
This also takes care of other bootstrap-related changes.
2024-02-08Rollup merge of #120734 - nnethercote:SubdiagnosticMessageOp, r=compiler-errorsMatthias Krüger-42/+12
Add `SubdiagnosticMessageOp` as a trait alias. It avoids a lot of repetition. r? matthewjasper
2024-02-08Add `SubdiagnosticMessageOp` as a trait alias.Nicholas Nethercote-42/+12
It avoids a lot of repetition.
2024-02-06Rollup merge of #120435 - chenyukang:yukang-fix-120427-cfg-name, ↵Matthias Krüger-10/+40
r=Urgau,Nilstrieb Suggest name value cfg when only value is used for check-cfg Fixes #120427 r? `````````````@Nilstrieb`````````````
2024-02-06Rollup merge of #120423 - RalfJung:indirect-structural-match, r=petrochenkovMatthias Krüger-0/+5
update indirect structural match lints to match RFC and to show up for dependencies This is a large step towards implementing https://github.com/rust-lang/rfcs/pull/3535. We currently have five lints related to "the structural match situation": - nontrivial_structural_match - indirect_structural_match - pointer_structural_match - const_patterns_without_partial_eq - illegal_floating_point_literal_pattern This PR concerns the first 3 of them. (The 4th already is set up to show for dependencies, and the 5th is removed by https://github.com/rust-lang/rust/pull/116284.) nontrivial_structural_match is being removed as per the RFC; the other two are enabled to show up in dependencies. Fixes https://github.com/rust-lang/rust/issues/73448 by removing the affected analysis.