Commit Graph

41308 Commits

Author SHA1 Message Date
Nicholas Nethercote
af50fe407e Put param_env into infcx.
Because they get passed around together a lot.
2024-11-19 11:44:07 +11:00
Nicholas Nethercote
c9283f8fa9 Pass constraints to RegionInferenceContext::new.
Instead of destructuring it in advance and passing all the components
individually. It's less code that way.
2024-11-19 11:33:48 +11:00
Nicholas Nethercote
801b150737 Don't refcount PlaceholderIndices.
It's not necessary.
2024-11-19 11:33:48 +11:00
Nicholas Nethercote
fe3c49fe9a Inline and remove TypeVerifier::new.
It has a single call site.
2024-11-19 11:33:48 +11:00
Nicholas Nethercote
2709dc8a13 Compute upvars lazily.
It can be computed from `tcx` on demand, instead of computing it eagerly
and passing it around.
2024-11-19 11:33:48 +11:00
Nicholas Nethercote
952c6d5c96 Clean up UniversalRegions.
There is an `Rc<UniversalRegions>` within `UniversalRegionRelations`,
and yet the two types get passed around in tandem a lot.

This commit makes `UniversalRegionRelations` own `UniversalRegions`,
removing the `Rc` (which wasn't truly needed) and the tandem-passing.
This requires adding a `universal_relations` method to
`UniversalRegionRelations`, and renaming a couple of existing methods
producing iterators to avoid a name clash.
2024-11-19 11:33:48 +11:00
Nicholas Nethercote
ed11fbe5df Make TypeChecker::region_bound_pairs owned.
No reason not to be, and it's simpler that way.
2024-11-19 11:33:48 +11:00
Nicholas Nethercote
227ecc803f Make TypeChecker::known_type_outlives_obligations owned.
This avoids the need to arena allocate it. `ConstraintConversion` needs
some simple lifetime adjustments to allow this.
2024-11-19 11:33:48 +11:00
Nicholas Nethercote
4c8a23ab0d Don't pass universal_regions unnecessarily.
`TypeChecker` already has it in a field.
2024-11-19 11:33:48 +11:00
bors
b71fb5edc0 Auto merge of #132460 - lcnr:questionable-uwu, r=compiler-errors
Use `TypingMode` throughout the compiler instead of `ParamEnv`

Hopefully the biggest single PR as part of https://github.com/rust-lang/types-team/issues/128.

## `infcx.typing_env` while defining opaque types

I don't know how'll be able to correctly handle opaque types when using something taking a `TypingEnv` while defining opaque types. To correctly handle the opaques we need to be able to pass in the current `opaque_type_storage` and return constraints, i.e. we need to use a proper canonical query. We should migrate all the queries used during HIR typeck and borrowck where this matters to proper canonical queries. This is

## `layout_of` and `Reveal::All`

We convert the `ParamEnv` to `Reveal::All` right at the start of the `layout_of` query, so I've changed callers of `layout_of` to already use a post analysis `TypingEnv` when encountering it.

ca87b535a0/compiler/rustc_ty_utils/src/layout.rs (L51)

## `Ty::is_[unpin|sized|whatever]`

I haven't migrated `fn is_item_raw` to use `TypingEnv`, will do so in a followup PR, this should significantly reduce the amount of `typing_env.param_env`. At some point there will probably be zero such uses as using the type system while ignoring the `typing_mode` is incorrect.

## `MirPhase` and phase-transitions

When inside of a MIR-body, we can mostly use its `MirPhase` to figure out the right `typing_mode`. This does not work during phase transitions, most notably when transitioning from `Analysis` to `Runtime`:

dae7ac133b/compiler/rustc_mir_transform/src/lib.rs (L606-L625)

All these passes still run with `MirPhase::Analysis`, but we should only use `Reveal::All` once we're run the `RevealAll` pass. This required me to manually construct the right `TypingEnv` in all these passes. Given that it feels somewhat easy to accidentally miss this going forward, I would maybe like to change `Body::phase` to an `Option` and replace it at the start of phase transitions. This then makes it clear that the MIR is currently in a weird state.

r? `@ghost`
2024-11-18 21:07:05 +00:00
omni
6f8fe7929a Make rustc --explain busybox less compatible
busybox less does not support the -r flag and less(1) says:

  USE OF THE -r OPTION IS NOT RECOMMENDED.
2024-11-18 20:37:32 +00:00
Ralf Jung
c6974344a5 interpret: do not ICE when a promoted fails with OOM 2024-11-18 20:48:03 +01:00
maxcabrajac
f6340f13bb Add MutVisitor::visit_fn_ret_ty 2024-11-18 15:49:09 -03:00
maxcabrajac
e65deb5ee1 Add Visitor::visit_qself 2024-11-18 15:43:35 -03:00
maxcabrajac
09c268417f Add Visitor::visit_fn_decl 2024-11-18 15:40:34 -03:00
Urgau
cc48194baf Report unexpected_cfgs lint in external macros 2024-11-18 18:52:27 +01:00
Guillaume Gomez
4baf540fce
Rollup merge of #133163 - RalfJung:cold, r=saethlin
remove pointless cold_path impl in interpreter

This has a fallback impl so the interpreter impl is not needed.

r? ``@saethlin``
2024-11-18 17:17:43 +01:00
Guillaume Gomez
86ba13ba2f
Rollup merge of #133157 - RalfJung:skip_stability_check_due_to_privacy, r=compiler-errors
stability: remove skip_stability_check_due_to_privacy

This was added in https://github.com/rust-lang/rust/pull/38689 to deal with https://github.com/rust-lang/rust/issues/38412. However, even after removing the check, the relevant tests still pass. Let's see if CI finds any other tests that rely on this. If not, it seems like logic elsewhere in the compiler changed so this is not required any more.
2024-11-18 17:17:42 +01:00
lcnr
2e087d2eaa review 2024-11-18 10:50:14 +01:00
lcnr
9cba14b95b use TypingEnv when no infcx is available
the behavior of the type system not only depends on the current
assumptions, but also the currentnphase of the compiler. This is
mostly necessary as we need to decide whether and how to reveal
opaque types. We track this via the `TypingMode`.
2024-11-18 10:38:56 +01:00
Ralf Jung
dff98a8a14 remove pointless cold_path impl in interpreter 2024-11-18 08:41:28 +01:00
Jacob Pratt
72a8d536ef
Rollup merge of #133142 - RalfJung:naming-is-hard, r=compiler-errors
rename rustc_const_stable_intrinsic -> rustc_intrinsic_const_stable_indirect

In https://github.com/rust-lang/rust/pull/120370 this name caused confusion as the author thought the intrinsic was stable. So let's try a different name...

If we can land this before the beta cutoff we can avoid needing `cfg(bootstrap)` for this. ;)
Cc `@compiler-errors` `@saethlin`
2024-11-18 02:24:35 -05:00
Jacob Pratt
21654a2f44
Rollup merge of #132934 - Zalathar:native-libs, r=jieyouxu
Overhaul the `-l` option parser (for linking to native libs)

The current parser for `-l` options has accumulated over time, making it hard to follow. This PR tries to clean it up in several ways.

Key changes:
- This code now gets its own submodule, to slightly reduce clutter in `rustc_session::config`.
- Cleaner division between iterating over multiple `-l` options, and processing each individual one.
- Separate “split” step that breaks up the value string into `[KIND[:MODIFIERS]=]NAME[:NEW_NAME]`, but leaves parsing/validating those parts to later steps.
  - This step also gets its own (disposable) unit test, to make sure it works as expected.
- A context struct reduces the burden of parameter passing, and makes it easier to write error messages that adapt to nightly/stable compilers.
- Fewer calls to `nightly_options` helper functions, because at this point we can get the same information from `UnstableOptions` and `UnstableFeatures` (which are downstream of earlier calls to those helper functions).

There should be no overall change in compiler behaviour.
2024-11-18 02:24:35 -05:00
Ralf Jung
b07ed6ab16 stability: remove skip_stability_check_due_to_privacy 2024-11-18 08:07:46 +01:00
Ralf Jung
9d4b1b2db4 rename rustc_const_stable_intrinsic -> rustc_intrinsic_const_stable_indirect 2024-11-18 07:47:44 +01:00
Zalathar
78edefea9d Overhaul the -l option parser (for linking to native libs) 2024-11-18 15:55:12 +11:00
Zalathar
478db489b3 Move -l option parsing into its own submodule
No functional change (yet).
2024-11-18 15:55:12 +11:00
Jacob Pratt
6c4a7b6ff3
Rollup merge of #133143 - kornelski:let-mut-global, r=compiler-errors
Diagnostics for let mut in item context

The diagnostics for `let` at the top level did not account for `let mut`, which [made the error unclear](https://users.rust-lang.org/t/create-a-vector-of-constants-outside-main/121251/1).

I've made the diagnostic always display a link to valid items. I've added dedicated help for `let mut` case that suggests using a `Mutex` (to steer novice users away from the `static mut` trap). Unfortunately, neither the Rust book, nor libstd docs have dedicated section listing all other types for interior-mutable `static`s.
2024-11-17 22:30:51 -05:00
Jacob Pratt
fc4f71db68
Rollup merge of #133130 - dianne:fix-133118, r=compiler-errors
`suggest_borrow_generic_arg`: instantiate clauses properly

This simplifies and fixes the way `suggest_borrow_generic_arg` instantiates callees' predicates when testing them to see if a moved argument can instead be borrowed. Previously, it would ICE if the moved argument's type included a region variable, since it was getting passed to a call of `EarlyBinder::instantiate`. This makes the instantiation much more straightforward, which also fixes the ICE.

Fixes #133118

This also modifies `tests/ui/moves/moved-value-on-as-ref-arg.rs` to have more useful bounds on the tests for suggestions to borrow `Borrow` and `BorrowMut` arguments. With its old tautological `T: BorrowMut<T>` bound, this fix would make it suggest a shared borrow for that argument.
2024-11-17 22:30:49 -05:00
Jacob Pratt
c68fef9fc9
Rollup merge of #132993 - jieyouxu:i_am_very_stable, r=chenyukang
Make rustc consider itself a stable compiler when `RUSTC_BOOTSTRAP=-1`

Addresses https://github.com/rust-lang/rust/issues/123404 to allow test writers to specify `//@ rustc-env:RUSTC_BOOTSTRAP=-1` to have a given rustc consider itself a stable rustc. This is only intended for testing usages.

I did not use `RUSTC_BOOTSTRAP=0` because that can be confusing, i.e. one might think that means "not bootstrapping", but "forcing a given rustc to consider itself a stable compiler" is a different use case.

I also added a specific test to check `RUSTC_BOOTSTRAP`'s various values and how that interacts with rustc's stability story w.r.t. features and cli flags.

Noticed when trying to write a test for enabling ICE file dumping on stable.

Dunno if this needs a compiler FCP or MCP, but I can file an MCP or ask someone to start an FCP if needed. Note that `RUSTC_BOOTSTRAP` is a perma-unstable env var and has no stability guarantees (heh) whatsoever. This does not affect bootstrapping because bootstrap never sets `RUSTC_BOOTSTRAP=-1`. If someone does set that when bootstrapping, it is considered PEBKAC.

Accompanying dev-guide PR: https://github.com/rust-lang/rustc-dev-guide/pull/2136

cc `@estebank` and `@rust-lang/wg-diagnostics` for FYI
2024-11-17 22:30:49 -05:00
Jacob Pratt
c874121487
Rollup merge of #132944 - linyihai:needing-parenthases-issue-132924, r=chenyukang
add parentheses when unboxing suggestion needed

This PR tried to `add parentheses when unboxing suggestion needed`

Fixes #132924
2024-11-17 22:30:48 -05:00
Jacob Pratt
e2993cd06e
Rollup merge of #132795 - compiler-errors:refine-rpitit, r=lcnr
Check `use<..>` in RPITIT for refinement

`#![feature(precise_capturing_in_traits)]` allows users to write `+ use<>` bounds on RPITITs to control what lifetimes are captured by the RPITIT.

Since RPITITs currently also warn for refinement in implementations, this PR extends that refinement check for cases where we *undercapture* in an implementation, since that may be indirectly "promising" a more relaxed outlives bound than the impl author intended.

For an opaque to be refining, we need to capture *fewer* parameters than those mentioned in the captured params of the trait. For example:

```
trait TypeParam<T> {
    fn test() -> impl Sized;
}
// Indirectly capturing a lifetime param through a type param substitution.
impl<'a> TypeParam<&'a ()> for i32 {
    fn test() -> impl Sized + use<> {}
    //~^ WARN impl trait in impl method captures fewer lifetimes than in trait
}
```

Since the opaque in the method (implicitly) captures `use<Self, T>`, and `Self = i32, T = &'a ()` in the impl, we must mention `'a` in our `use<..>` on the impl.

Tracking:
* https://github.com/rust-lang/rust/issues/130044
2024-11-17 22:30:47 -05:00
dianne
546ba3d310 suggest_borrow_generic_arg: instantiate clauses properly
Fixes issue 133118.
This also modifies `tests/ui/moves/moved-value-on-as-ref-arg.rs` to have more
useful bounds on the tests for suggestions to borrow `Borrow` and `BorrowMut`
arguments. With its old tautological `T: BorrowMut<T>` bound, this fix would
make it suggest a shared borrow for that argument.
2024-11-17 18:09:36 -08:00
Michael Goulet
32d2340dbd Check use<..> in RPITIT for refinement 2024-11-18 00:27:44 +00:00
Esteban Küber
29acf8b422 Account for ExpandedConstant in parse_match 2024-11-17 23:58:22 +00:00
bors
3fb7e441ae Auto merge of #120370 - x17jiri:likely_unlikely_fix, r=saethlin
Likely unlikely fix

RFC 1131 ( https://github.com/rust-lang/rust/issues/26179 ) added likely/unlikely intrinsics, but they have been broken for a while: https://github.com/rust-lang/rust/issues/96276 , https://github.com/rust-lang/rust/issues/96275 , https://github.com/rust-lang/rust/issues/88767 . This PR tries to fix them.

Changes:
- added a new `cold_path()` intrinsic
- `likely()` and `unlikely()` changed to regular functions implemented using `cold_path()`
2024-11-17 23:57:53 +00:00
Esteban Küber
912ee65ccd review comment: modify doc comment 2024-11-17 23:40:00 +00:00
Esteban Küber
6480b76e45 review comments
- Remove check for "how many path segments is the pattern"
- Check before suggesting if the path has multiple path segments
2024-11-17 23:40:00 +00:00
Esteban Küber
bb37e5d3cd review comments 2024-11-17 23:40:00 +00:00
Esteban Küber
f1772d5739 Make suggestion verbose 2024-11-17 23:40:00 +00:00
Esteban Küber
f563efec15 Unify expanded constants and named constants in PatKind 2024-11-17 23:40:00 +00:00
Esteban Küber
a5b4d458a1 Point at const when intended binding fall-through pattern is a const
```
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-17 23:40:00 +00:00
Esteban Küber
6dc79f6133 Use item_name instead of a span snippet when talking about const pattern 2024-11-17 23:40:00 +00:00
Esteban Küber
c25b44bee9 Fold PatKind::NamedConstant into PatKind::Constant 2024-11-17 23:39:59 +00:00
Esteban Küber
ff2f7a7a83 Point at const definition when used instead of a binding in a let statement
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-17 23:39:59 +00:00
Kornel
7765f23ea1
Diagnostics for let mut in item context 2024-11-17 22:30:11 +00:00
Jiri Bobek
777003ae9f Likely unlikely fix 2024-11-17 21:49:10 +01:00
许杰友 Jieyou Xu (Joe)
af1c8be400
Rollup merge of #133116 - RalfJung:const-null-ptr, r=dtolnay
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-17 23:56:10 +08:00
许杰友 Jieyou Xu (Joe)
0b157e88d7
Rollup merge of #133060 - tyrone-wu:removelet-span-suggestion, r=jieyouxu
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-17 23:56:09 +08:00
许杰友 Jieyou Xu (Joe)
2f62fd3d13
Rollup merge of #133051 - estebank:cond-misparse, r=jieyouxu
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-17 23:56:08 +08:00
许杰友 Jieyou Xu (Joe)
2d9690d2e7
Rollup merge of #133029 - veluca93:abi-checks-tier3, r=workingjubilee
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-17 23:56:08 +08:00
Jieyou Xu
202caa7c57 Add RUSTC_BOOTSTRAP=-1 to make rustc pretend as stable compiler 2024-11-17 19:59:52 +08:00
bors
1e0df74445 Auto merge of #133120 - matthiaskrgr:rollup-4actosy, r=matthiaskrgr
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-17 09:45:48 +00:00
bors
ee4a56e353 Auto merge of #132566 - saethlin:querify-mir-collection, r=cjgillot
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-17 06:39:47 +00:00
Ralf Jung
5eef5ee38a stabilize const_ptr_is_null 2024-11-16 22:50:22 +01:00
Matthias Krüger
a1c98ca160
Rollup merge of #132832 - compiler-errors:late-ty, r=cjgillot
Deny capturing late-bound ty/const params in nested opaques

First, this reverts a7f609504c. 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-16 21:05:46 +01:00
Matthias Krüger
6b47c6d786
Rollup merge of #132787 - maxcabrajac:fnctxt, r=petrochenkov
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-16 21:05:46 +01:00
Matthias Krüger
5c81dbf4fa
Rollup merge of #132134 - nnethercote:rm-ResultsVisitable, r=cjgillot
Remove `ResultsVisitable`

`ResultsVisitable` has annoyed me for a while. This PR removes it. Details in the individual commits.

r? `@cjgillot.`
2024-11-16 21:05:44 +01:00
Esteban Küber
6913194b8e review comment: move logic to new method 2024-11-16 20:03:31 +00:00
Esteban Küber
c09c73b996 Reword suggestion message 2024-11-16 20:03:31 +00:00
Esteban Küber
629a69f3e2 Better account for else if macro conditions mising an if
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-16 20:03:31 +00:00
Esteban Küber
04fe839177 Increase accuracy of if condition misparse suggestion
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-16 20:03:31 +00:00
bors
46e8d20301 Auto merge of #130443 - veluca93:legacy-const-generics-fix, r=BoxyUwU
Fix ICE when passing DefId-creating args to legacy_const_generics.

r? BoxyUwU

Fixes #123077
Fixes #129150
2024-11-16 04:57:15 +00:00
Luca Versari
b462c68aee Fix ICE when passing DefId-creating args to legacy_const_generics. 2024-11-16 01:07:51 +01:00
Mark Rousskov
da58efb11d Improve VecCache under parallel frontend
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-15 18:20:32 -05:00
Guillaume Gomez
fc8d2b38d8
Rollup merge of #133080 - ehuss:edition-desugar-span, r=compiler-errors
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-15 23:38:12 +01:00
Guillaume Gomez
b3e2981ff7
Rollup merge of #132978 - WaffleLapkin:very-semantic-change-kind, 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-15 23:38:10 +01:00
Guillaume Gomez
325bc6c201
Rollup merge of #132956 - maxcabrajac:coroutine_kind, r=petrochenkov
Add visit_coroutine_kind to ast::Visitor

r? ``@petrochenkov``

related to #128974
2024-11-15 23:38:10 +01:00
Guillaume Gomez
1f83a4de1f
Rollup merge of #132936 - surechen:fix_131989, r=Nadrieril
For expr `return (_ = 42);` unused_paren lint should not be triggered

fixes #131989
2024-11-15 23:38:09 +01:00
maxcabrajac
516a3b0c9b Make WalkItemKind::walk signature compatible between Visitor versions 2024-11-15 17:01:53 -03:00
maxcabrajac
6180173612 Add WalkItemKind::Ctxt so AssocCtxt is not sent to non-Assoc ItemKinds 2024-11-15 17:00:01 -03:00
maxcabrajac
1236656319 Make Visitor::FnKind and MutVisitor::FnKind compatible 2024-11-15 16:59:47 -03:00
bors
917a50a039 Auto merge of #133079 - matthiaskrgr:rollup-k8u7syk, r=matthiaskrgr
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-15 19:13:57 +00:00
Eric Huss
03e2828e88 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-15 10:06:53 -08:00
Matthias Krüger
a111716c42
Rollup merge of #133049 - maxcabrajac:visit_precise_capturing_arg, r=compiler-errors
Change Visitor::visit_precise_capturing_arg so it returns a Visitor::Result

r? `@petrochenkov`

related to #128974
2024-11-15 19:05:18 +01:00
Matthias Krüger
6963572c78
Rollup merge of #133021 - nnethercote:refactor-configure_annotatable, r=petrochenkov
Refactor `configure_annotatable`

This PR streamlines `configure_annotatable` and nearby code considerably.

r? `@petrochenkov`
2024-11-15 19:05:16 +01:00
Matthias Krüger
213803549a
Rollup merge of #132817 - compiler-errors:impl-trait-overcaptures-apit, 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-15 19:05:15 +01:00
Sam Estep
090c24fbbf Merge -Zhir-stats into -Zinput-stats 2024-11-15 12:46:40 -05:00
Sam Estep
12eaa3ab84 Print total node count in -Z hir-stats 2024-11-15 12:46:31 -05:00
Tyrone Wu
dd557c988f
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

Signed-off-by: Tyrone Wu <wudevelops@gmail.com>
2024-11-15 17:43:29 +00:00
bors
ce40196577 Auto merge of #132992 - RalfJung:check-consts-feature-gate, r=compiler-errors
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-15 16:03:47 +00:00
Piotr Osiewicz
42e71bb8ea rustc_metadata: Preprocess search paths for better performance
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-15 10:35:33 +01:00
bors
251dc8ad84 Auto merge of #133059 - workingjubilee:rollup-rc5kvr1, r=workingjubilee
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-15 03:29:57 +00:00
Jubilee
cea081e980
Rollup merge of #133050 - tgross35:inline-f16-f128, r=saethlin
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-14 17:55:27 -08:00
bors
3bc6916f4c Auto merge of #132965 - mati865:cfguard-gnullvm, r=wesleywiser
allow CFGuard on windows-gnullvm

No unit tests because of https://github.com/rust-lang/rust/issues/132278
2024-11-15 00:21:07 +00:00
Trevor Gross
5d818914af 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-14 16:18:41 -06:00
bors
e84902d35a Auto merge of #133047 - matthiaskrgr:rollup-9se1vth, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #128197 (Skip locking span interner for some syntax context checks)
 - #133040 ([rustdoc] Fix handling of footnote reference in footnote definition)
 - #133043 (rustdoc-search: case-sensitive only when capitals are used)
 - #133046 (Clippy subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-14 21:09:28 +00:00
maxcabrajac
9fde49b338 Change visit_precise_capturing_arg so it returns a Self::Result 2024-11-14 17:07:46 -03:00
Matthias Krüger
e158303c09
Rollup merge of #128197 - Alexendoo:span-ctxt, r=davidtwco
Skip locking span interner for some syntax context checks

- `from_expansion` now never needs to consult the interner
- `eq_ctxt` now only needs the interner when both spans are fully interned
2024-11-14 20:45:12 +01:00
Guillaume Gomez
5ee347ece4
Rollup merge of #132172 - dianne:suggest-borrow-generic, r=matthewjasper
borrowck diagnostics: suggest borrowing function inputs in generic positions

# Summary
This generalizes borrowck's existing suggestions to borrow instead of moving when passing by-value to a function that's generic in that input. Previously, this was special-cased to `AsRef`/`Borrow`-like traits and `Fn`-like traits. This PR changes it to test if, for a moved place with type `T`, that the callee's signature and clauses don't break if you substitute in `&T` or `&mut T`. For instance, it now works with `Read`/`Write`-like traits.

Fixes https://github.com/rust-lang/rust/issues/131413

# Incidental changes
- No longer spuriously suggests mutable borrows of closures in some situations (see e.g. the tests in [tests/ui/closures/2229_closure_analysis/](https://github.com/rust-lang/rust/compare/master...dianne:rust:suggest-borrow-generic?expand=1#diff-8dfb200c559f0995d0f2ffa2f23bc6f8041b263e264e5c329a1f4171769787c0)).
- No longer suggests cloning closures that implement `Fn`, since they can be borrowed (see e.g. [tests/ui/moves/borrow-closures-instead-of-move.stderr](https://github.com/rust-lang/rust/compare/master...dianne:rust:suggest-borrow-generic?expand=1#diff-5db268aac405eec56d099a72d8b58ac46dab523cf013e29008104840168577fb)).

This keeps the behavior to suppress suggestions of `fn_once.clone()()`. I think it might make sense to suggest it with a "but this might not be your desired behavior" caveat, as is done when something is used after being consumed as the receiver for a method call. That's probably out of the scope of this PR though.

# Limitations and possible improvements
- This doesn't work for receivers of method calls. This is a small change, and I have it implemented locally, but I'm not sure it's useful on its own. In most cases I've found borrowing the receiver would change the call's output type (see below). In other cases (e.g. `Iterator::sum`), borrowing the receiver isn't useful since it's consumed.
- This doesn't work when it would change the call's output type. In general, I figure inserting references into the output type is an unwanted change. However, this also means it doesn't work in cases where the new output type would be effectively the same as the old one. For example, from the rand crate, the iterator returned by [`Rng::sample_iter`](https://docs.rs/rand/latest/rand/trait.Rng.html#method.sample_iter) is effectively the same (modulo regions) whether you borrow or consume the receiver `Rng`, so common usage involves borrowing it. I'm not sure whether the best approach is to add a more complex check of approximate equivalence, to forego checking the call's output type and give spurious suggestions, or to leave it as-is.
- This doesn't work when it would change the call's other input types. Instead, it could suggest borrowing any others that have the same parameter type (but only when suggesting shared borrows). I think this would be a pretty easy change, but I don't think it's very useful so long as the normalized output type can't change.

I'm happy to implement any of these (or other potential improvements to this), but I'm not sure which are common enough patterns to justify the added complexity. Please let me know if any sound worthwhile.
2024-11-14 15:16:08 +01:00
Guillaume Gomez
e3c76c5699
Rollup merge of #132773 - jakos-sec:fix-asan-win32, r=jieyouxu
PassWrapper: disable UseOdrIndicator for Asan Win32

As described in https://reviews.llvm.org/D137227 UseOdrIndicator should be disabled on Windows since link.exe does not support duplicate weak definitions.

Fixes https://github.com/rust-lang/rust/issues/124390.

Credits also belong to `@1c3t3a`  who worked with me on this.
We are currently testing this on a Windows machine.
2024-11-14 18:26:15 +08:00
Luca Versari
3d3b515707 ABI checks: add support for some tier3 arches, warn on others. 2024-11-14 08:57:39 +01:00
Jubilee
aa189460b8
Rollup merge of #132971 - BoxyUwU:handle_infers_in_anon_consts, r=compiler-errors
Handle infer vars in anon consts on stable

Fixes #132955

Diagnostics will sometimes try to replace generic parameters with inference variables in failing goals. This means that if we have some failing goal with an array repeat expr count anon const in it, we will wind up with some `ty::ConstKind::Unevaluated(anon_const_def, [?x])` during diagnostics which will then ICE if we do not handle inference variables correctly on stable when normalizing type system consts.

r? ```@compiler-errors```
2024-11-13 22:43:37 -08:00
Maybe Lapkin
673bb5e3ff
Mark never_type_fallback_flowing_into_unsafe as a semantic change
...rather than a future error
2024-11-14 06:01:14 +01:00
dianne
2ab8480605 Suggest borrowing arguments in generic positions when trait bounds are satisfied
This subsumes the suggestions to borrow arguments with `AsRef`/`Borrow` bounds and those to borrow
arguments with `Fn` and `FnMut` bounds. It works for other traits implemented on references as well,
such as `std::io::Read`, `std::io::Write`, and `core::fmt::Write`.

Incidentally, by making the logic for suggesting borrowing closures general, this removes some
spurious suggestions to mutably borrow `FnMut` closures in assignments, as well as an unhelpful
suggestion to add a `Clone` constraint to an `impl Fn` argument.
2024-11-13 20:29:40 -08:00
Nicholas Nethercote
7a96ed3dd0 Remove unreachable code in has_cfg_or_cfg_attr. 2024-11-14 14:58:16 +11:00
Nicholas Nethercote
d55a5e5dda Merge matches in configure_annotatable.
There are two matches: one in a closure, and one vanilla one. They can
be combined and simplified by putting them in a `try` block.
2024-11-14 14:52:42 +11:00
Nicholas Nethercote
b2b643c9d9 Inline and remove flat_map_annotatable.
Important: we know from the `parse_annotatable_with` call above the call
site that only some of the `Annotatable` variants are possible. The
remaining cases can be replaced with `unreachable!`.
2024-11-14 14:52:18 +11:00
Nicholas Nethercote
7aee2b332f Make configure_annotatable/flat_map_annotatable infallible.
They each have a single callsite, and the result is always unwrapped, so
the `Option<Annotatable>` return type is misleading.

Also, the comment at the `configure_annotatable` call site is wrong,
talking about a result vector, so this commit also removes that.
2024-11-14 14:51:45 +11:00
surechen
3a74bce72e Adding BreakValue to UnusedDelimsCtx to make UnusedParens and UnusedBraces checking break 2024-11-14 09:08:56 +08:00