about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2024-05-10Use fewer origins when creating type variables.Nicholas Nethercote-2/+1
`InferCtxt::next_{ty,const}_var*` all take an origin, but the `param_def_id` is almost always `None`. This commit changes them to just take a `Span` and build the origin within the method, and adds new methods for the rare cases where `param_def_id` might not be `None`. This avoids a lot of tedious origin building. Specifically: - next_ty_var{,_id_in_universe,_in_universe}: now take `Span` instead of `TypeVariableOrigin` - next_ty_var_with_origin: added - next_const_var{,_in_universe}: takes Span instead of ConstVariableOrigin - next_const_var_with_origin: added - next_region_var, next_region_var_in_universe: these are unchanged, still take RegionVariableOrigin The API inconsistency (ty/const vs region) seems worth it for the large conciseness improvements.
2024-05-08Rollup merge of #124869 - compiler-errors:keyword, r=NilstriebMatthias Krüger-1/+10
Make sure we don't deny macro vars w keyword names `$async:ident`, etc are all valid. Fixes #124862
2024-05-08Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=NilstriebMatthias Krüger-2/+2
Remove braces when fixing a nested use tree into a single item [Back in 2019](https://github.com/rust-lang/rust/pull/56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`. This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then. A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`. This PR is best reviewed commit-by-commit.
2024-05-08Rollup merge of #124761 - Urgau:ref-casting_bigger_slice_index, r=jieyouxuMatthias Krüger-0/+7
Fix insufficient logic when searching for the underlying allocation This PR fixes the logic inside the `invalid_reference_casting` lint, when trying to lint on bigger memory layout casts. More specifically when looking for the "underlying allocation" we were wrongly assuming that when we got `&mut slice[index]` that `slice[index]` was the allocation, but it's not. Fixes https://github.com/rust-lang/rust/issues/124685
2024-05-07Make sure we don't deny macro vars w keyword namesMichael Goulet-1/+10
2024-05-06Auto merge of #124747 - MasterAwesome:master, r=davidtwcobors-13/+56
Support Result<T, E> across FFI when niche optimization can be used (v2) This PR is identical to #122253, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F). r? ghost Original PR description: --- Allow allow enums like `Result<T, E>` to be used across FFI if the T/E can be niche optimized and the non-niche-optimized type is FFI safe. Implementation of https://github.com/rust-lang/rfcs/pull/3391 Tracking issue: https://github.com/rust-lang/rust/issues/110503 Additional ABI and codegen tests were added in https://github.com/rust-lang/rust/pull/115372
2024-05-05Fix insufficient logic when searching for the underlying allocationUrgau-0/+7
in the `invalid_reference_casting` lint, when trying to lint on bigger memory layout casts.
2024-05-04Update Cargo diagnostics in check-cfgUrgau-4/+4
2024-05-04Auto merge of #124401 - oli-obk:some_hir_cleanups, r=cjgillotbors-3/+6
Some hir cleanups It seemed odd to not put `AnonConst` in the arena, compared with the other types that we did put into an arena. This way we can also give it a `Span` without growing a lot of other HIR data structures because of the extra field. r? compiler
2024-05-02Rollup merge of #124624 - WaffleLapkin:old_unit, r=fmeaseMatthias Krüger-3/+2
Use `tcx.types.unit` instead of `Ty::new_unit(tcx)` I don't think there is any need for the function, given that we can just access the `.types`, similarly to all other primitives?
2024-05-02Inline & delete `Ty::new_unit`, since it's just a field accessWaffle Lapkin-3/+2
2024-05-02Rollup merge of #124568 - Urgau:non-local-defs-doctest, ↵Guillaume Gomez-4/+17
r=michaelwoerister,GuillaumeGomez Adjust `#[macro_export]`/doctest help suggestion for non_local_defs lint This PR adjust the help suggestion of the `non_local_definitions` lint when encountering a `#[macro_export]` at top-level doctest. So instead of a non-sentential help suggestion to move the `macro_rules!` up above the `rustdoc`-generated function. We now suggest users to declare their own function. Fixes *(partially, needs backport)* #124534
2024-05-01Adjust `#[macro_export]`/doctest help suggestion for non_local_defs lintUrgau-4/+17
2024-05-01Auto merge of #124539 - Urgau:non-local-defs_modulo_modules, r=lcnrbors-5/+11
Consider inner modules to be local in the `non_local_definitions` lint This PR implements the [proposed fix](https://github.com/rust-lang/rust/issues/124396#issuecomment-2079553642) for #124396, that is to consider inner modules to be local in the `non_local_definitions` lint. This PR is voluntarily kept as minimal as possible so it can be backported easily. T-lang [nomination](https://github.com/rust-lang/rust/issues/124396#issuecomment-2079692820) will need to be removed before this can be merged. Fixes *(nearly, needs backport)* https://github.com/rust-lang/rust/issues/124396
2024-04-30Rollup merge of #124511 - nnethercote:rm-extern-crates, r=fee1-deadMatthias Krüger-4/+34
Remove many `#[macro_use] extern crate foo` items This requires the addition of more `use` items, which often make the code more verbose. But they also make the code easier to read, because `#[macro_use]` obscures where macros are defined. r? `@fee1-dead`
2024-04-29Consider inner modules to be local in the `non_local_definitions` lintUrgau-5/+11
2024-04-29Rollup merge of #124522 - blyxyas:refactor-is-loaded, r=jieyouxu许杰友 Jieyou Xu (Joe)-8/+10
[Refactor] Rename `Lint` and `LintGroup`'s `is_loaded` to `is_externally_loaded` The field being named `is_loaded` was very confusing. Turns out it's true for lints that are registered by external tools like Clippy (I had to look at https://github.com/rust-lang/rust/pull/116412 to know what the variable meant). So I renamed `is_loaded` to `is_externally_loaded` and added some docs.
2024-04-29[Refactor] Rename Lint and LintGroup\'s is_loaded to is_externally_loadedblyxyas-8/+10
2024-04-29Remove `extern crate rustc_middle` from numerous crates.Nicholas Nethercote-2/+7
2024-04-29Remove `extern crate rustc_session` from `rustc_lint`.Nicholas Nethercote-2/+27
2024-04-28Fix #124478 - offset_of! returns a temporaryGeorge Bateman-0/+1
This was due to the must_use() call. Adding HIR's OffsetOf to the must_use checking within the compiler avoids this issue.
2024-04-26Move `ConstArg::span` to `AnonConst::span`Oli Scherer-3/+6
2024-04-25ast: Generalize item kind visitingVadim Petrochenkov-1/+1
And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).
2024-04-23Put the RFC behind a feature gate `result_ffi_guarantees`Arvind Mukund-0/+4
2024-04-23Remove comment out of RFC's scopeArvind Mukund-1/+0
2024-04-23Reword `is_niche_optimization_candidate` docArvind Mukund-1/+1
2024-04-23Disallow single-variant enumsArvind Mukund-4/+6
Couldn't find documentation supporting that single-variant `#[repr(Rust)]` enums with RHS assigned work as expected with this change. ```rust enum Variants { A = 17, } // Would this be zero sized optimized guaranteed? ```
2024-04-23Don't lint niche optimized variants in enumsArvind Mukund-20/+13
2024-04-23We don't need to check for non-exhaustive fieldsArvind Mukund-2/+1
Fields are disallowed so checking the top attribute is enough.
2024-04-23Support Result<T, E> across FFI when niche optimization can be usedArvind Mukund-1/+47
Allow allow enums like `Result<T, E>` to be used across FFI if the T/E can be niche optimized and the non-niche-optimized type is FFI safe.
2024-04-23Rollup merge of #124218 - Xiretza:subsubdiagnostics, r=davidtwcoLeón Orell Valerian Liehr-18/+20
Allow nesting subdiagnostics in #[derive(Subdiagnostic)]
2024-04-23Rollup merge of #123050 - RalfJung:panic_str, r=m-ou-seMatthias Krüger-1/+1
panic_str only exists for the migration to 2021 panic macros The only caller is `expect_failed`, which is already a cold inline(never) function, so inlining into that function should be fine. (And indeed `panic_str` was `#[inline]` anyway.) The existence of panic_str risks someone calling it when they should call `panic` instead, and I can't see a reason why this footgun should exist. I also extended the comment in `panic` to explain why it needs a `'static` string -- I know I've wondered about this in the past and it took me quite a while to understand.
2024-04-23Auto merge of #124277 - matthiaskrgr:rollup-zdb93i4, r=matthiaskrgrbors-31/+75
Rollup of 7 pull requests Successful merges: - #123680 (Deny gen keyword in `edition_2024_compat` lints) - #124057 (Fix ICE when ADT tail has type error) - #124168 (Use `DefiningOpaqueTypes::Yes` in rustdoc, where the `InferCtxt` is guaranteed to have no opaque types it can define) - #124197 (Move duplicated code in functions in `tests/rustdoc-gui/notable-trait.goml`) - #124200 (Improve handling of expr->field errors) - #124220 (Miri: detect wrong vtables in wide pointers) - #124266 (remove an unused type from the reentrant lock tests) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-23Rollup merge of #123680 - compiler-errors:gen-kw, r=NadrierilMatthias Krüger-31/+75
Deny gen keyword in `edition_2024_compat` lints Splits the `keyword_idents` lint into two -- `keyword_idents_2018` and `keyword_idents_2024` -- since each corresponds to a future-compat warning in a different edition. Group these together into a new `keyword_idents` lint group, and add the latter to the `rust_2024_compatibility` so that `gen` is ready for the 2024 edition. cc `@traviscross` `@ehuss`
2024-04-23Auto merge of #123992 - compiler-errors:no-has-typeck-results, r=jackh726bors-1/+1
`has_typeck_results` doesnt need to be a query self-explanatory
2024-04-22Stabilize generic `NonZero`.Markus Reiter-1/+0
2024-04-22Deny gen keyword in edition_2024_compat lintsMichael Goulet-31/+75
2024-04-21Auto merge of #123594 - Urgau:fix-non_local_def-lint-overflow, r=lcnrbors-1/+13
Fix trait solver overflow with `non_local_definitions` lint This PR fixes the trait solver overflow with the `non_local_definitions` lint reported in https://github.com/rust-lang/rust/issues/123573 using the suggestion from `@lcnr:` https://github.com/rust-lang/rust/issues/123573#issuecomment-2041348320 to use the next trait solver. ~~I have not (yet) tried to create a minimized repro~~ ``@compiler-errors`` did the minimization (thanks you) but I have manually tested on the `starlark-rust` project that it fixes the issue. Fixes #123573 r? `@lcnr`
2024-04-21Move "elided lifetime in path" to subdiagnostic structXiretza-8/+10
This requires nested subdiagnostics.
2024-04-21Pass translation closure to add_to_diag_with() as referenceXiretza-10/+10
2024-04-17has_typeck_results doesnt need to be a queryMichael Goulet-1/+1
2024-04-17Rename `BindingAnnotation` to `BindingMode`Jules Bertholet-2/+2
2024-04-17Rollup merge of #122813 - nnethercote:nicer-quals, r=compiler-errorsMatthias Krüger-4/+5
Qualifier tweaking Adding and removing qualifiers in some cases that make things nicer. Details in individual commits. r? `@compiler-errors`
2024-04-16Rollup merge of #123501 - Urgau:stabilize-check-cfg, r=petrochenkovMatthias Krüger-2/+2
Stabilize checking of cfgs at compile-time: `--check-cfg` option This PR stabilize the `--check-cfg` CLI option of `rustc` (and `rustdoc`) :tada:. In particular this PR does two things: 1. it makes the `--check-cfg` option stable 2. and it moves the documentation to the stable books FCP: https://github.com/rust-lang/rust/issues/82450#issuecomment-1965328542 Resolves #82450 ``@rustbot`` labels +S-blocked +F-check-cfg r? ``@petrochenkov``
2024-04-16Auto merge of #123468 - compiler-errors:precise-capturing, r=oli-obkbors-1/+1
Implement syntax for `impl Trait` to specify its captures explicitly (`feature(precise_capturing)`) Implements `impl use<'a, 'b, T, U> Sized` syntax that allows users to explicitly list the captured parameters for an opaque, rather than inferring it from the opaque's bounds (or capturing *all* lifetimes under 2024-edition capture rules). This allows us to exclude some implicit captures, so this syntax may be used as a migration strategy for changes due to #117587. We represent this list of captured params as `PreciseCapturingArg` in AST and HIR, resolving them between `rustc_resolve` and `resolve_bound_vars`. Later on, we validate that the opaques only capture the parameters in this list. We artificially limit the feature to *require* mentioning all type and const parameters, since we don't currently have support for non-lifetime bivariant generics. This can be relaxed in the future. We also may need to limit this to require naming *all* lifetime parameters for RPITIT, since GATs have no variance. I have to investigate this. This can also be relaxed in the future. r? `@oli-obk` Tracking issue: - https://github.com/rust-lang/rust/issues/123432
2024-04-16Avoid lots of `hir::HirId{,Map,Set}` qualifiers.Nicholas Nethercote-4/+5
Because they're a bit redundant.
2024-04-15nitsMichael Goulet-8/+4
2024-04-15Parsing , pre-lowering support for precise capturesMichael Goulet-1/+1
2024-04-15Move --check-cfg documentation to stable booksUrgau-2/+2
2024-04-14store the span of the nested part of the use tree in the astPietro Albini-2/+2