about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2024-11-17review commentsEsteban Küber-6/+5
2024-11-17Make suggestion verboseEsteban Küber-1/+2
2024-11-17Unify expanded constants and named constants in `PatKind`Esteban Küber-46/+71
2024-11-17Point at const when intended binding fall-through pattern is a constEsteban Küber-4/+25
``` error[E0004]: non-exhaustive patterns: `i32::MIN..=3_i32` and `5_i32..=i32::MAX` not covered --> $DIR/intended-binding-pattern-is-const.rs:2:11 | LL | match 1 { | ^ patterns `i32::MIN..=3_i32` and `5_i32..=i32::MAX` not covered LL | x => {} | - this pattern doesn't introduce a new catch-all binding, but rather pattern matches against the value of constant `x` | = note: the matched value is of type `i32` note: constant `x` defined here --> $DIR/intended-binding-pattern-is-const.rs:7:5 | LL | const x: i32 = 4; | ^^^^^^^^^^^^ help: if you meant to introduce a binding, use a different name | LL | x_var => {} | ++++ help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms | LL | x => {}, i32::MIN..=3_i32 | 5_i32..=i32::MAX => todo!() | ++++++++++++++++++++++++++++++++++++++++++++++++ ```
2024-11-17Use `item_name` instead of a span snippet when talking about const patternEsteban Küber-3/+2
2024-11-17Fold `PatKind::NamedConstant` into `PatKind::Constant`Esteban Küber-33/+21
2024-11-17Point at `const` definition when used instead of a binding in a `let` statementEsteban Küber-14/+52
After: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | const PAT: u32 = 0; | -------------- missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable ... LL | let PAT = v1; | ^^^ | | | pattern `1_u32..=u32::MAX` not covered | help: introduce a variable instead: `PAT_var` | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` ``` Before: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | let PAT = v1; | ^^^ | | | pattern `1_u32..=u32::MAX` not covered | missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable | help: introduce a variable instead: `PAT_var` | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` ```
2024-11-17Diagnostics for let mut in item contextKornel-8/+25
2024-11-17Inline ExprPrecedence::order into Expr::precedenceDavid Tolnay-214/+135
2024-11-17Likely unlikely fixJiri Bobek-18/+93
2024-11-17Rollup merge of #133116 - RalfJung:const-null-ptr, r=dtolnay许杰友 Jieyou Xu (Joe)-0/+6
stabilize const_ptr_is_null FCP passed in https://github.com/rust-lang/rust/issues/74939. The second commit cleans up const stability around UB checks a bit, now that everything they need (except for `const_eval_select`) is stable. Fixes https://github.com/rust-lang/rust/issues/74939
2024-11-17Rollup merge of #133060 - tyrone-wu:removelet-span-suggestion, r=jieyouxu许杰友 Jieyou Xu (Joe)-2/+3
Trim whitespace in RemoveLet primary span Separate `RemoveLet` span into primary span for `let` and removal suggestion span for `let `, so that primary span does not include whitespace. Fixes: #133031
2024-11-17Rollup merge of #133051 - estebank:cond-misparse, r=jieyouxu许杰友 Jieyou Xu (Joe)-8/+112
Increase accuracy of `if` condition misparse suggestion Fix #132656. Look at the expression that was parsed when trying to recover from a bad `if` condition to determine what was likely intended by the user beyond "maybe this was meant to be an `else` body". ``` error: expected `{`, found `map` --> $DIR/missing-dot-on-if-condition-expression-fixable.rs:4:30 | LL | for _ in [1, 2, 3].iter()map(|x| x) {} | ^^^ expected `{` | help: you might have meant to write a method call | LL | for _ in [1, 2, 3].iter().map(|x| x) {} | + ``` If a macro statement has been parsed after `else`, suggest a missing `if`: ``` error: expected `{`, found `falsy` --> $DIR/else-no-if.rs:47:12 | LL | } else falsy! {} { | ---- ^^^^^ | | | expected an `if` or a block after this `else` | help: add an `if` if this is the condition of a chained `else if` statement | LL | } else if falsy! {} { | ++ ```
2024-11-17Rollup merge of #133029 - veluca93:abi-checks-tier3, r=workingjubilee许杰友 Jieyou Xu (Joe)-17/+24
ABI checks: add support for some tier3 arches, warn on others. Followup to - https://github.com/rust-lang/rust/pull/132842 - https://github.com/rust-lang/rust/pull/132173 - https://github.com/rust-lang/rust/issues/131800 r? ``@workingjubilee``
2024-11-17Add `RUSTC_BOOTSTRAP=-1` to make rustc pretend as stable compilerJieyou Xu-9/+24
2024-11-17Auto merge of #133120 - matthiaskrgr:rollup-4actosy, r=matthiaskrgrbors-363/+440
Rollup of 7 pull requests Successful merges: - #131717 (Stabilize `const_atomic_from_ptr`) - #132134 (Remove `ResultsVisitable`) - #132449 (mark is_val_statically_known intrinsic as stably const-callable) - #132569 (rustdoc search: allow queries to end in an empty path segment) - #132787 (Unify FnKind between AST visitors and make WalkItemKind more straight forward) - #132832 (Deny capturing late-bound ty/const params in nested opaques) - #133097 (Opt out TaKO8Ki from review rotation for now) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-17Auto merge of #132566 - saethlin:querify-mir-collection, r=cjgillotbors-67/+165
Querify MonoItem collection Factored out of https://github.com/rust-lang/rust/pull/131650. These changes are required for post-mono MIR opts, because the previous implementation would load the MIR for every Instance that we traverse (as well as invoke queries on it). The cost of that would grow massively with post-mono MIR opts because we'll need to load new MIR for every Instance, instead of re-using the `optimized_mir` for every Instance with the same DefId. So the approach here is to add two new queries, `items_of_instance` and `size_estimate`, which contain the specific information about an Instance's MIR that MirUsedCollector and CGU partitioning need, respectively. Caching these significantly increases the size of the query cache, but that's justified by our improved incrementality (I'm sure walking all the MIR for a huge crate scales quite poorly). This also changes `MonoItems` into a type that will retain the traversal order (otherwise we perturb a bunch of diagnostics), and will also eliminate duplicate findings. Eliminating duplicates removes about a quarter of the query cache size growth. The perf improvements in this PR are inflated because rustc-perf uses `-Zincremental-verify-ich`, which makes loading MIR a lot slower because MIR contains a lot of Spans and computing the stable hash of a Span is slow. And the primary goal of this PR is to load less MIR. Some squinting at `collector profile_local perf-record +stage1` runs suggests the magnitude of the improvements in this PR would be decreased by between a third and a half if that flag weren't being used. Though this effect may apply to the regressions too since most are incr-full and this change also causes such builds to encode more Spans.
2024-11-16stabilize const_ptr_is_nullRalf Jung-0/+6
2024-11-16Rollup merge of #132832 - compiler-errors:late-ty, r=cjgillotMatthias Krüger-22/+29
Deny capturing late-bound ty/const params in nested opaques First, this reverts a7f609504c92c9912b61025ae26a5404d3ee4311. I can't exactly remember why I approved this specific bit of https://github.com/rust-lang/rust/pull/132466; specifically, I don't know that the purpose of that commit is, and afaict we will never have an opaque that captures late-bound params through a const because opaques can't be used inside of anon consts. Am I missing something `@cjgillot?` Since I can't see a case where this matters, and no tests seem to fail. The second commit adds a `deny_late_regions: bool` to distinguish `Scope::LateBoundary` which should deny *any* late-bound params or just ty/consts. Then, when resolving opaques we wrap ourselves in a `Scope::LateBoundary { deny_late_regions: false }` so that we deny late-bound ty/const, which fixes a bunch of ICEs that all vaguely look like `impl for<T> Trait<Assoc = impl OtherTrait<T>>`. I guess this could be achieved other ways; for example, with a different scope kind, or maybe we could just reuse `Scope::Opaque`. But this seems a bit more verbose. I'm open to feedback anyways. Fixes #131535 Fixes #131637 Fixes #132530 I opted to remove those crashes tests ^ without adding them as regular tests, since they're basically triggering uninteresting late-bound ICEs far off in the trait solver, and the reason that existing tests such as `tests/ui/type-alias-impl-trait/non-lifetime-binder-in-constraint.rs` don't ICE are kinda just coincidental (i.e. due to a missing impl block). I don't really feel motivated to add random permutations to tests just to exercise non-lifetime binders. r? cjgillot
2024-11-16Rollup merge of #132787 - maxcabrajac:fnctxt, r=petrochenkovMatthias Krüger-67/+150
Unify FnKind between AST visitors and make WalkItemKind more straight forward Unifying `FnKind` requires a bunch of changes to `WalkItemKind::walk` signature so I'll change them in one go related to #128974 r? `@petrochenkov`
2024-11-16Rollup merge of #132134 - nnethercote:rm-ResultsVisitable, r=cjgillotMatthias Krüger-274/+261
Remove `ResultsVisitable` `ResultsVisitable` has annoyed me for a while. This PR removes it. Details in the individual commits. r? `@cjgillot.`
2024-11-16review comment: move logic to new methodEsteban Küber-88/+103
2024-11-16Reword suggestion messageEsteban Küber-2/+2
2024-11-16Better account for `else if` macro conditions mising an `if`Esteban Küber-1/+10
If a macro statement has been parsed after `else`, suggest a missing `if`: ``` error: expected `{`, found `falsy` --> $DIR/else-no-if.rs:47:12 | LL | } else falsy! {} { | ---- ^^^^^ | | | expected an `if` or a block after this `else` | help: add an `if` if this is the condition of a chained `else if` statement | LL | } else if falsy! {} { | ++ ```
2024-11-16Increase accuracy of `if` condition misparse suggestionEsteban Küber-9/+89
Look at the expression that was parsed when trying to recover from a bad `if` condition to determine what was likely intended by the user beyond "maybe this was meant to be an `else` body". ``` error: expected `{`, found `map` --> $DIR/missing-dot-on-if-condition-expression-fixable.rs:4:30 | LL | for _ in [1, 2, 3].iter()map(|x| x) {} | ^^^ expected `{` | help: you might have meant to write a method call | LL | for _ in [1, 2, 3].iter().map(|x| x) {} | + ```
2024-11-16Auto merge of #130443 - veluca93:legacy-const-generics-fix, r=BoxyUwUbors-3/+97
Fix ICE when passing DefId-creating args to legacy_const_generics. r? BoxyUwU Fixes #123077 Fixes #129150
2024-11-16Fix ICE when passing DefId-creating args to legacy_const_generics.Luca Versari-3/+97
2024-11-15Improve VecCache under parallel frontendMark Rousskov-65/+458
This replaces the single Vec allocation with a series of progressively larger buckets. With the cfg for parallel enabled but with -Zthreads=1, this looks like a slight regression in i-count and cycle counts (<0.1%). With the parallel frontend at -Zthreads=4, this is an improvement (-5% wall-time from 5.788 to 5.4688 on libcore) than our current Lock-based approach, likely due to reducing the bouncing of the cache line holding the lock. At -Zthreads=32 it's a huge improvement (-46%: 8.829 -> 4.7319 seconds).
2024-11-15Rollup merge of #133080 - ehuss:edition-desugar-span, r=compiler-errorsGuillaume Gomez-1/+1
Fix span edition for 2024 RPIT coming from an external macro This fixes a problem where code generated by an external macro with an RPIT would end up using the call-site edition instead of the macro's edition for the RPIT. When used from a 2024 crate, this caused the code to change behavior to the 2024 capturing rules, which we don't want. This was caused by the impl-trait lowering code would replace the span with one marked with `DesugaringKind::OpaqueTy` desugaring. However, it was also overriding the edition of the span with the edition of the local crate. Instead it should be using the edition of the span itself. Fixes https://github.com/rust-lang/rust/issues/132917
2024-11-15Rollup merge of #132978 - WaffleLapkin:very-semantic-change-kind, ↵Guillaume Gomez-5/+46
r=compiler-errors Mention both release *and* edition breakage for never type lints This PR makes ~~two changes~~ a change to the never type lints (`dependency_on_unit_never_type_fallback` and `never_type_fallback_flowing_into_unsafe`): 1. Change the wording of the note to mention that the breaking change will be made in an edition _and_ in a future release 2. ~~Make these warnings be reported in deps (hopefully the lints are matured enough)~~ r? ``@compiler-errors`` cc ``@ehuss`` closes #132930
2024-11-15Rollup merge of #132956 - maxcabrajac:coroutine_kind, r=petrochenkovGuillaume Gomez-22/+17
Add visit_coroutine_kind to ast::Visitor r? ``@petrochenkov`` related to #128974
2024-11-15Rollup merge of #132936 - surechen:fix_131989, r=NadrierilGuillaume Gomez-0/+9
For expr `return (_ = 42);` unused_paren lint should not be triggered fixes #131989
2024-11-15Make WalkItemKind::walk signature compatible between Visitor versionsmaxcabrajac-18/+27
2024-11-15Add WalkItemKind::Ctxt so AssocCtxt is not sent to non-Assoc ItemKindsmaxcabrajac-27/+35
2024-11-15Make Visitor::FnKind and MutVisitor::FnKind compatiblemaxcabrajac-41/+107
2024-11-15Auto merge of #133079 - matthiaskrgr:rollup-k8u7syk, r=matthiaskrgrbors-100/+57
Rollup of 4 pull requests Successful merges: - #132817 (Recurse into APITs in `impl_trait_overcaptures`) - #133021 (Refactor `configure_annotatable`) - #133045 (tests: Test pac-ret flag merging on clang with LTO) - #133049 (Change Visitor::visit_precise_capturing_arg so it returns a Visitor::Result) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-15Fix span edition for 2024 RPIT coming from an external macroEric Huss-1/+1
This fixes a problem where code generated by an external macro with an RPIT would end up using the call-site edition instead of the macro's edition for the RPIT. When used from a 2024 crate, this caused the code to change behavior to the 2024 capturing rules, which we don't want. This was caused by the impl-trait lowering code would replace the span with one marked with `DesugaringKind::OpaqueTy` desugaring. However, it was also overriding the edition of the span with the edition of the local crate. Instead it should be using the edition of the span itself. Fixes https://github.com/rust-lang/rust/issues/132917
2024-11-15Rollup merge of #133049 - maxcabrajac:visit_precise_capturing_arg, ↵Matthias Krüger-9/+5
r=compiler-errors Change Visitor::visit_precise_capturing_arg so it returns a Visitor::Result r? `@petrochenkov` related to #128974
2024-11-15Rollup merge of #133021 - nnethercote:refactor-configure_annotatable, ↵Matthias Krüger-90/+47
r=petrochenkov Refactor `configure_annotatable` This PR streamlines `configure_annotatable` and nearby code considerably. r? `@petrochenkov`
2024-11-15Rollup merge of #132817 - compiler-errors:impl-trait-overcaptures-apit, ↵Matthias Krüger-1/+5
r=BoxyUwU Recurse into APITs in `impl_trait_overcaptures` We were previously not detecting cases where an RPIT was located in the return type of an async function, leading to underfiring of the `impl_trait_overcaptures`. This PR does this recursion properly now. cc https://github.com/rust-lang/rust/issues/132809
2024-11-15Merge `-Zhir-stats` into `-Zinput-stats`Sam Estep-157/+9
2024-11-15Print total node count in `-Z hir-stats`Sam Estep-1/+8
2024-11-15Trim whitespace in RemoveLet primary spanTyrone Wu-2/+3
Separate `RemoveLet` span into primary span for `let` and removal suggestion span for `let `, so that primary span does not include whitespace. Fixes: #133031 Signed-off-by: Tyrone Wu <wudevelops@gmail.com>
2024-11-15Auto merge of #132992 - RalfJung:check-consts-feature-gate, r=compiler-errorsbors-12/+36
check_consts: fix error requesting feature gate when that gate is not actually needed When working on https://github.com/rust-lang/hashbrown/pull/586 I noticed that the compiler asks for the `rustc_private` feature to be enabled if one forgets to set `rustc_const_stable_indirect` on a function -- but enabling `rustc_private` would not actually help. This fixes the diagnostics. r? `@compiler-errors`
2024-11-15fix: rust-lang/rust#47446Sven Kanoldt-4/+73
- Add test for issue 47446 - Implement the new lint lint_builtin_mixed_export_name_and_no_mangle - Add suggestion how to fix it
2024-11-15rustc_metadata: Preprocess search paths for better performancePiotr Osiewicz-76/+137
Over in Zed we've noticed that loading crates for a large-ish workspace can take almost 200ms. We've pinned it down to how rustc searches for paths, as it performs a linear search over the list of candidate paths. In our case the candidate list had about 20k entries which we had to iterate over for each dependency being loaded. This commit introduces a simple FilesIndex that's just a sorted Vec under the hood. Since crates are looked up by both prefix and suffix, we perform a range search on said Vec (which constraints the search space based on prefix) and follow up with a linear scan of entries with matching suffixes. FilesIndex is also pre-filtered before any queries are performed using available target information; query prefixes/sufixes are based on the target we are compiling for, so we can remove entries that can never match up front. Overall, this commit brings down build time for us in dev scenarios by about 6%. 100ms might not seem like much, but this is a constant cost that each of our workspace crates has to pay, even when said crate is miniscule.
2024-11-15Auto merge of #133059 - workingjubilee:rollup-rc5kvr1, r=workingjubileebors-0/+10
Rollup of 8 pull requests Successful merges: - #132790 (Add as_slice/into_slice for IoSlice/IoSliceMut.) - #132905 ([AIX] Add crate "unwind" to link with libunwind) - #132977 (Fix compilation error on Solaris due to flock usage) - #132984 ([illumos] use pipe2 to create anonymous pipes) - #133019 (docs: Fix missing period and colon in methods for primitive types) - #133048 (use `&raw` in `{read, write}_unaligned` documentation) - #133050 (Always inline functions signatures containing `f16` or `f128`) - #133053 (tests: Fix the SIMD FFI tests with certain x86 configuration) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-14Rollup merge of #133050 - tgross35:inline-f16-f128, r=saethlinJubilee-0/+10
Always inline functions signatures containing `f16` or `f128` There are a handful of tier 2 and tier 3 targets that cause a LLVM crash or linker error when generating code that contains `f16` or `f128`. The cranelift backend also does not support these types. To work around this, every function in `std` or `core` that contains these types must be marked `#[inline]` in order to avoid sending any code to the backend unless specifically requested. However, this is inconvenient and easy to forget. Introduce a check for these types in the frontend that automatically inlines any function signatures that take or return `f16` or `f128`. Note that this is not a perfect fix because it does not account for the types being passed by reference or as members of aggregate types, but this is sufficient for what is currently needed in the standard library. Fixes: https://github.com/rust-lang/rust/issues/133035 Closes: https://github.com/rust-lang/rust/pull/133037
2024-11-15Auto merge of #132965 - mati865:cfguard-gnullvm, r=wesleywiserbors-2/+6
allow CFGuard on windows-gnullvm No unit tests because of https://github.com/rust-lang/rust/issues/132278
2024-11-14Always inline functions signatures containing `f16` or `f128`Trevor Gross-0/+10
There are a handful of tier 2 and tier 3 targets that cause a LLVM crash or linker error when generating code that contains `f16` or `f128`. The cranelift backend also does not support these types. To work around this, every function in `std` or `core` that contains these types must be marked `#[inline]` in order to avoid sending any code to the backend unless specifically requested. However, this is inconvenient and easy to forget. Introduce a check for these types in the frontend that automatically inlines any function signatures that take or return `f16` or `f128`. Note that this is not a perfect fix because it does not account for the types being passed by reference or as members of aggregate types, but this is sufficient for what is currently needed in the standard library. Fixes: https://github.com/rust-lang/rust/issues/133035 Closes: https://github.com/rust-lang/rust/pull/133037