about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2024-05-21Generate lint diagnostic message from BuiltinLintDiagXiretza-24/+139
Translation of the lint message happens when the actual diagnostic is created, not when the lint is buffered. Generating the message from BuiltinLintDiag ensures that all required data to construct the message is preserved in the LintBuffer, eventually allowing the messages to be moved to fluent. Remove the `msg` field from BufferedEarlyLint, it is either generated from the data in the BuiltinLintDiag or stored inside BuiltinLintDiag::Normal.
2024-05-21Convert unexpected_cfg_{name,value} to struct diagnosticsXiretza-152/+402
2024-05-21Convert NAMED_ASM_LABELS lint to diag structXiretza-19/+12
2024-05-20Adjust the method ambiguity lint tooMichael Goulet-1/+1
2024-05-20Implement BOXED_SLICE_INTO_ITERMichael Goulet-153/+167
2024-05-20Auto merge of #125219 - Urgau:check-cfg-cargo-config, r=fmeasebors-18/+32
Update `unexpected_cfgs` lint for Cargo new `check-cfg` config This PR updates the diagnostics output of the `unexpected_cfgs` lint for Cargo new `check-cfg` config. It's a simple and cost-less alternative to the build-script `cargo::rustc-check-cfg` instruction. ```toml [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo, values("bar"))'] } ``` This PR also adds a Cargo specific section regarding check-cfg and Cargo inside rustc's book (motivation is described inside the file, but mainly check-cfg is a rustc feature not a Cargo one, Cargo only enabled the feature, it does not own it; T-cargo even considers the `check-cfg` lint config to be an implementation detail). This PR also updates the links to refer to that sub-page when using Cargo from rustc. As well as updating the lint doc to refer to the check-cfg docs. ~**Not to be merged before https://github.com/rust-lang/cargo/pull/13913 reaches master!**~ (EDIT: merged in https://github.com/rust-lang/rust/pull/125237) `@rustbot` label +F-check-cfg r? `@fmease` *(feel free to roll)* Fixes https://github.com/rust-lang/rust/issues/124800 cc `@epage` `@weihanglo`
2024-05-20Fix quote escaping inside check-cfg valueUrgau-3/+2
2024-05-19Rollup merge of #124948 - blyxyas:remove-repeated-words, r=compiler-errorsMatthias Krüger-1/+1
chore: Remove repeated words (extension of #124924) When I saw #124924 I thought "Hey, I'm sure that there are far more than just two typos of this nature in the codebase". So here's some more typo-fixing. Some found with regex, some found with a spellchecker. Every single one manually reviewed by me (along with hundreds of false negatives by the tools)
2024-05-19Refer to the Cargo specific doc in the check-cfg diagnosticsUrgau-2/+4
2024-05-19Prefer suggesting string-literal for Cargo `check-cfg` lint configUrgau-18/+29
2024-05-18Auto merge of #125077 - spastorino:add-new-fnsafety-enum2, r=jackh726bors-5/+5
Rename Unsafe to Safety Alternative to #124455, which is to just have one Safety enum to use everywhere, this opens the posibility of adding `ast::Safety::Safe` that's useful for unsafe extern blocks. This leaves us today with: ```rust enum ast::Safety { Unsafe(Span), Default, // Safe (going to be added for unsafe extern blocks) } enum hir::Safety { Unsafe, Safe, } ``` We would convert from `ast::Safety::Default` into the right Safety level according the context.
2024-05-18Fix typos (taking into account review comments)blyxyas-1/+1
2024-05-17Rename Unsafe to SafetySantiago Pastorino-5/+5
2024-05-16Update `unexpected_cfgs` lint for Cargo new `check-cfg` configUrgau-6/+8
2024-05-16Remove trivial Binder::dummy callsMichael Goulet-1/+1
2024-05-16Rename ToPredicate for UpcastMichael Goulet-2/+2
2024-05-15Use 'a' article for &Option.Zachary S-0/+1
2024-05-15Include reference in lint diagnosticZachary S-3/+8
2024-05-15Also apply `warn(for_loops_over_fallibles)` to &T and &mut T, not just T = ↵Zachary S-1/+9
Result/Option.
2024-05-15Add `on_unimplemented" typo suggestionsmejrs-0/+8
2024-05-13And finally add testsMichael Goulet-15/+74
2024-05-13Warn against redundant use<...>Michael Goulet-68/+139
2024-05-13Don't suggest using use<> syntax to capture APITsMichael Goulet-4/+9
2024-05-13Suggest adding use<> syntaxMichael Goulet-6/+41
2024-05-13Add some commentingMichael Goulet-4/+23
2024-05-13Implement initial IMPL_TRAIT_OVERCAPTURES lintMichael Goulet-0/+239
2024-05-13split out AliasTy -> AliasTermMichael Goulet-4/+7
2024-05-12Auto merge of #119427 - dtolnay:maccall, r=compiler-errorsbors-0/+27
Fix, document, and test parser and pretty-printer edge cases related to braced macro calls _Review note: this is a deceptively small PR because it comes with 145 lines of docs and 196 lines of tests, and only 25 lines of compiler code changed. However, I recommend reviewing it 1 commit at a time because much of the effect of the code changes is non-local i.e. affecting code that is not visible in the final state of the PR. I have paid attention that reviewing the PR one commit at a time is as easy as I can make it. All of the code you need to know about is touched in those commits, even if some of those changes disappear by the end of the stack._ This is a follow-up to https://github.com/rust-lang/rust/pull/119105. One case that is not relevant to `-Zunpretty=expanded`, but which came up as I'm porting #119105 and #118726 into `syn`'s printer and `prettyplease`'s printer where it **is** relevant, and is also relevant to rustc's `stringify!`, is statement boundaries in the vicinity of braced macro calls. Rustc's AST pretty-printer produces invalid syntax for statements that begin with a braced macro call: ```rust macro_rules! stringify_item { ($i:item) => { stringify!($i) }; } macro_rules! repro { ($e:expr) => { stringify_item!(fn main() { $e + 1; }) }; } fn main() { println!("{}", repro!(m! {})); } ``` **Before this PR:** output is not valid Rust syntax. ```console fn main() { m! {} + 1; } ``` ```console error: leading `+` is not supported --> <anon>:1:19 | 1 | fn main() { m! {} + 1; } | ^ unexpected `+` | help: try removing the `+` | 1 - fn main() { m! {} + 1; } 1 + fn main() { m! {} 1; } | ``` **After this PR:** valid syntax. ```console fn main() { (m! {}) + 1; } ```
2024-05-11Document the situation with unused_parens lint and braced macro callsDavid Tolnay-4/+28
2024-05-11Macro call with braces does not require semicolon to be statementDavid Tolnay-1/+4
This commit by itself is supposed to have no effect on behavior. All of the call sites are updated to preserve their previous behavior. The behavior changes are in the commits that follow.
2024-05-11Mark expr_requires_semi_to_be_stmt call sitesDavid Tolnay-1/+1
For each of these, we need to decide whether they need to be using `expr_requires_semi_to_be_stmt`, or `expr_requires_comma_to_be_match_arm`, which are supposed to be 2 different behaviors. Previously they were conflated into one, causing either too much or too little parenthesization.
2024-05-11Uplift `TraitPredicate`Michael Goulet-3/+2
2024-05-11Rollup merge of #124978 - saethlin:ref-casting_derefs, r=Urgau,NilstriebMatthias Krüger-2/+4
Handle Deref expressions in invalid_reference_casting Similar to https://github.com/rust-lang/rust/pull/124908 See https://github.com/rust-lang/rust/issues/124951 for context; this PR fixes the last of the known false postiive cases with this lint that we encounter in Crater.
2024-05-10Auto merge of #124982 - compiler-errors:uplift-trait-ref, r=lcnrbors-1/+1
Uplift `TraitRef` into `rustc_type_ir` Emotional rollercoaster r? lcnr
2024-05-10Lift `TraitRef` into `rustc_type_ir`Michael Goulet-1/+1
2024-05-10Handle Deref expressions in invalid_reference_castingBen Kimock-2/+4
2024-05-10Rename some ObligationCauseCode variantsMichael Goulet-5/+2
2024-05-10Rollup merge of #124955 - nnethercote:next_ty_var, r=lcnrMatthias Krüger-2/+1
Use fewer origins when creating type variables. To reduce lots of repetitive boilerplate code. Details in the individual commit messages. r? ``@lcnr``
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-09always use `GenericArgsRef`lcnr-2/+2
2024-05-09Rollup merge of #124908 - saethlin:ref-casting_bigger_place_projection, ↵Matthias Krüger-1/+2
r=fee1-dead Handle field projections like slice indexing in invalid_reference_casting r? `@Urgau` I saw the implementation in https://github.com/rust-lang/rust/pull/124761, and I was wondering if we also need to handle field access. We do. Without this PR, we get this errant diagnostic: ``` error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused --> /home/ben/rust/tests/ui/lint/reference_casting.rs:262:18 | LL | let r = &mut v.0; | --- backing allocation comes from here LL | let ptr = r as *mut i32 as *mut Vec3<i32>; | ------------------------------- casting happend here LL | unsafe { *ptr = Vec3(0, 0, 0) } | ^^^^^^^^^^^^^^^^^^^^ | = note: casting from `i32` (4 bytes) to `Vec3<i32>` (12 bytes) ```
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-08Handle field projections like slice indexing in invalid_reference_castingBen Kimock-1/+2
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