Commit graph

45225 commits

Author SHA1 Message Date
Oli Scherer
dabee5d563 Do not treat lifetimes from parent items as influencing child items 2025-03-28 17:06:00 +00:00
bors
2a06022951 Auto merge of #138503 - bjorn3:string_merging, r=tmiasko
Avoid wrapping constant allocations in packed structs when not necessary

This way LLVM will set the string merging flag if the alloc is a nul terminated string, reducing binary sizes.

try-job: armhf-gnu
2025-03-28 10:18:32 +00:00
bjorn3
5c82a59bd3 Add test and comment 2025-03-28 09:19:57 +00:00
bjorn3
a5fa12b6b9 Avoid wrapping constant allocations in packed structs when not necessary
This way LLVM will set the string merging flag if the alloc is a nul
terminated string, reducing binary sizes.
2025-03-28 09:19:57 +00:00
bors
e77a8f439c Auto merge of #139037 - jhpratt:rollup-4c74y8a, r=jhpratt
Rollup of 6 pull requests

Successful merges:

 - #138720 (Specify a concrete stack size in channel tests)
 - #139010 (Improve `xcrun` error handling)
 - #139021 (std: get rid of pre-Vista fallback code)
 - #139025 (Do not trim paths in MIR validator)
 - #139026 (Use `abs_diff` where applicable)
 - #139030 (saethlin goes on vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-28 06:28:48 +00:00
bors
3f690c2257 Auto merge of #138965 - nnethercote:less-kw-Empty-hir-Lifetime, r=lcnr
Remove `kw::Empty` uses from `hir::Lifetime::ident`

`hir::Lifetime::ident` is sometimes set to `kw::Empty` and it's really confusing. This PR stops that. Helps with #137978.

r? `@lcnr`
2025-03-28 03:20:06 +00:00
Jacob Pratt
2465b62858
Rollup merge of #139026 - yotamofek:pr/abs-diff, r=compiler-errors
Use `abs_diff` where applicable

Very small cleanup, dogfooding a [new clippy lint](https://github.com/rust-lang/rust-clippy/pull/14482) I'm trying to add
2025-03-27 21:41:50 -04:00
Jacob Pratt
d837ab4489
Rollup merge of #139025 - compiler-errors:trim-validator-err, r=jieyouxu
Do not trim paths in MIR validator

From my inline comment:

```
// The type checker formats a bunch of strings with type names in it, but these strings
// are not always going to be encountered on the error path since the inliner also uses
// the validator, and there are certain kinds of inlining (even for valid code) that
// can cause validation errors (mostly around where clauses and rigid projections).
```

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

r? `@jieyouxu`
2025-03-27 21:41:49 -04:00
Jacob Pratt
0b40e6e2cf
Rollup merge of #139010 - madsmtm:parse-xcrun-better, r=wesleywiser
Improve `xcrun` error handling

The compiler invokes `xcrun` on macOS when linking Apple targets, to find the Xcode SDK which contain all the necessary linker stubs. The error messages that `xcrun` outputs aren't always that great though, so this PR tries to improve that by providing extra context when an error occurs.

Fixes https://github.com/rust-lang/rust/issues/56829.
Fixes https://github.com/rust-lang/rust/issues/84534.
Part of https://github.com/rust-lang/rust/issues/129432.
See also the alternative https://github.com/rust-lang/rust/pull/131433.

Tested on:
- `x86_64-apple-darwin`, MacBook Pro running Mac OS X 10.12.6
    - With no tooling installed
    - With Xcode 9.2
    - With Xcode 9.2 Commandline Tools
- `aarch64-apple-darwin`, MacBook M2 Pro running macOS 14.7.4
    - With Xcode 13.4.1
    - With Xcode 16.2
    - Inside `nix-shell -p xcbuild` (nixpkgs' `xcrun` shim)
- `aarch64-apple-darwin`, VM running macOS 15.3.1
    - With no tooling installed
    - With Xcode 16.2 Commandline Tools

``@rustbot`` label O-apple
r? compiler
CC ``@BlackHoleFox`` ``@thomcc``
2025-03-27 21:41:48 -04:00
Nicholas Nethercote
8d2c63f514 Don't use kw::Empty in hir::Lifetime::ident.
`hir::Lifetime::ident` currently sometimes uses `kw::Empty` for elided
lifetimes and sometimes uses `kw::UnderscoreLifetime`, and the
distinction is used when creating some error suggestions, e.g. in
`Lifetime::suggestion` and `ImplicitLifetimeFinder::visit_ty`. I found
this *really* confusing, and it took me a while to understand what was
going on.

This commit replaces all uses of `kw::Empty` in `hir::Lifetime::ident`
with `kw::UnderscoreLifetime`. It adds a new field
`hir::Lifetime::is_path_anon` that mostly replaces the old
empty/underscore distinction and makes things much clearer.

Some other notable changes:

- Adds a big comment to `Lifetime` talking about permissable field
  values.

- Adds some assertions in `new_named_lifetime` about what ident values
  are permissible for the different `LifetimeRes` values.

- Adds a `Lifetime::new` constructor that does some checking to make
  sure the `is_elided` and `is_anonymous` states are valid.

- `add_static_impl_trait_suggestion` now looks at `Lifetime::res`
  instead of the ident when creating the suggestion. This is the one
  case where `is_path_anon` doesn't replace the old empty/underscore
  distinction.

- A couple of minor pretty-printing improvements.
2025-03-28 10:15:23 +11:00
Nicholas Nethercote
cfd00f9c16 Remove ImplicitObjectLifetimeDefault case from suggestion.
It has no effect on anything in the test suite.

This means it can also be rewritten as a neater pairwise `match`.
2025-03-28 08:25:07 +11:00
Nicholas Nethercote
c6d8d65496 Remove LifetimeSuggestionPosition and Lifetime::suggestion_position.
They both are only used in `Lifetime::suggestion`. This commit inlines
and removes them.
2025-03-28 08:25:07 +11:00
Yotam Ofek
bec69704c0 Use abs_diff where applicable 2025-03-27 18:29:06 +00:00
Michael Goulet
ed0a798828 Drive-by get rid of a bunch of unnecessary :? 2025-03-27 17:45:18 +00:00
Michael Goulet
c00343a5b4 Do not trim paths in MIR validator 2025-03-27 17:45:02 +00:00
Jacob Pratt
d517a4f0ae
Rollup merge of #139014 - xizheyin:issue-138931, r=oli-obk
Improve suggest construct with literal syntax instead of calling

Closing #138931

When constructing a structure through a format similar to calling a constructor, we can use verbose suggestions to hint at using literal syntax for clearer advice. The case of multiple fields is also considered here, provided that the field has the same number of arguments as CallExpr.

r? compiler
2025-03-27 13:11:20 -04:00
Jacob Pratt
322d1c1974
Rollup merge of #138989 - m-ou-se:clean-up-things, r=jdonszelmann,dingxiangfei2009
Clean up a few things in rustc_hir_analysis::check::region

Each commit is independent. They are all small clean-ups in rustc_hir_analysis::check::region.
2025-03-27 13:11:18 -04:00
Jacob Pratt
10debec01a
Rollup merge of #138926 - nnethercote:less-kw-Empty-rustc_middle, r=lcnr
Remove `kw::Empty` uses from `rustc_middle`.

There are several places in `rustc_middle` that check for an empty lifetime name. These checks appear to be totally unnecessary, because empty lifetime names aren't produced here. (Empty lifetime names *are* possible in `hir::Lifetime`. Perhaps there was some confusion between it and the `rustc_middle` types?)

This commit removes the `kw::Empty` checks.

r? `@lcnr`
2025-03-27 13:11:18 -04:00
Jacob Pratt
3a8621d681
Rollup merge of #138844 - petrochenkov:cfgtrace2, r=nnethercote
expand: Leave traces when expanding `cfg` attributes

This is the same as https://github.com/rust-lang/rust/pull/138515, but for `cfg(true)` instead of `cfg_attr`.

The difference is that `cfg(true)`s already left "traces" after themselves - the `cfg` attributes themselves, with `expanded_inert_attrs` set to true, with full tokens, available to proc macros.
This is not a reasonably expected behavior, but it could not be removed without a replacement, because a [major rustdoc feature](https://github.com/rust-lang/rfcs/pull/3631) and a number of clippy lints rely on it. This PR implements a replacement.

This needs a crater run, because it changes observable behavior (in an intended way) - proc macros can no longer see expanded `cfg(true)` attributes.

(Some minor unnecessary special casing for `sym::cfg_attr` is also removed in this PR.)

r? `@nnethercote`
2025-03-27 13:11:17 -04:00
xizheyin
4648650d89
Improve suggest construct with literal syntax instead of calling
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-27 20:09:37 +08:00
bors
ecb170afc8 Auto merge of #139012 - Zalathar:rollup-qgt5yfo, r=Zalathar
Rollup of 10 pull requests

Successful merges:

 - #130883 (Add environment variable query)
 - #138624 (Add mipsel maintainer)
 - #138672 (Avoiding calling queries when collecting active queries)
 - #138935 (Update wg-prio triagebot config)
 - #138946 (Un-bury chapters from the chapter list in rustc book)
 - #138964 (Implement lint against using Interner and InferCtxtLike in random compiler crates)
 - #138977 (Don't deaggregate InvocationParent just to reaggregate it again)
 - #138980 (Collect items referenced from var_debug_info)
 - #138985 (Use the correct binder scope for elided lifetimes in assoc consts)
 - #138987 (Always emit `native-static-libs` note, even if it is empty)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-27 07:47:39 +00:00
Stuart Cook
8fa981665c
Rollup merge of #138987 - madsmtm:fix-108825, r=jieyouxu
Always emit `native-static-libs` note, even if it is empty

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

Retry of https://github.com/rust-lang/rust/pull/121216, finally got around to fixing the test, the errors in that PR were because `libcore` uses the `#[link]` attribute on MSVC.

try-job: x86_64-msvc
r? wesleywiser
2025-03-27 15:57:26 +11:00
Stuart Cook
3db0999100
Rollup merge of #138985 - oli-obk:push-mvlqmtmyozro, r=compiler-errors
Use the correct binder scope for elided lifetimes in assoc consts

Beyond diagnostics this has no real effect, and it's also just about a future incompat lint. But it causes ICEs in some refactorings that I'm doing, so trying to get it out of the way
2025-03-27 15:57:25 +11:00
Stuart Cook
c33df2763f
Rollup merge of #138980 - tmiasko:collect-var-debug-info, r=compiler-errors
Collect items referenced from var_debug_info

The collection is limited to full debuginfo builds to match behavior of FunctionCx::compute_per_local_var_debug_info.

Fixes #138942.
2025-03-27 15:57:25 +11:00
Stuart Cook
d26047dcaa
Rollup merge of #138977 - oli-obk:invoc-parent-keep-aggregated, r=compiler-errors
Don't deaggregate InvocationParent just to reaggregate it again

Also makes it easier to add more things to it in the future (which I am doing in some local experiments, so not really a reason to do this just now, but I think this PR stands on its own).
2025-03-27 15:57:24 +11:00
Stuart Cook
cb39217d44
Rollup merge of #138964 - compiler-errors:usage-of-interner, r=lcnr
Implement lint against using Interner and InferCtxtLike in random compiler crates

Often `Interner` defines similar methods to `TyCtxt` (but often simplified due to the simpler API surface of the type system layer for the new solver), which people will either unintentionally or intentionally import and use. Let's discourage that.

r? lcnr
2025-03-27 15:57:24 +11:00
Stuart Cook
7853b88423
Rollup merge of #138672 - Zoxc:deferred-queries-in-deadlock-handler, r=oli-obk
Avoiding calling queries when collecting active queries

This PR changes active query collection to no longer call queries. Instead the fields needing queries have their computation delayed to when an cycle error is emitted or when printing the query backtrace in a panic.

This is done by splitting the fields in `QueryStackFrame` needing queries into a new `QueryStackFrameExtra` type. When collecting queries `QueryStackFrame` will contain a closure that can create `QueryStackFrameExtra`, which does make use of queries. Calling `lift` on a `QueryStackFrame` or `CycleError` will convert it to a variant containing `QueryStackFrameExtra` using those closures.

This also only calls queries needed to collect information on a cycle errors, instead of information on all active queries.

Calling queries when collecting active queries is a bit odd. Calling queries should not be done in the deadlock handler at all.

This avoids the out of memory scenario in https://github.com/rust-lang/rust/issues/124901.
2025-03-27 15:57:22 +11:00
Stuart Cook
c45986ae61
Rollup merge of #130883 - madsmtm:env-var-query, r=petrochenkov
Add environment variable query

Generally, `rustc` prefers command-line arguments, but in some cases, an environment variable really is the most sensible option. We should make sure that this works properly with the compiler's change-tracking mechanisms, such that changing the relevant environment variable causes a rebuild.

This PR is a first step forwards in doing that.

Part of the work needed to do https://github.com/rust-lang/rust/issues/118204, see https://github.com/rust-lang/rust/pull/129342 for some discussion.

r? ``@petrochenkov``
2025-03-27 15:57:21 +11:00
bors
ea1da921c8 Auto merge of #138915 - compiler-errors:binder-tweak, r=lcnr
Instantiate binder before registering nested obligations for auto/built-in traits

Instead of turning a `Binder<Vec<Ty>>` into a bunch of higher-ranked predicates, instantiate the binder eagerly *once* and turn them into a bunch of non-higher-ranked predicates.

Right now this feels like a noop, but this `enter_forall_and_leak_universe` call would be the singular place where we could instantiate bound lifetime assumptions for coroutine witnesses... if we had them. Thus consolidating the binder instantiation here is useful if we want to fix the coroutine-auto-trait problem.

r? lcnr
2025-03-27 04:35:12 +00:00
Mads Marquart
89348e51e3 Emit better error messages when invoking xcrun
Also allow the SDK path to be non-UTF-8.
2025-03-27 04:38:54 +01:00
Mads Marquart
bd1ef0fad2 Invoke xcrun inside sess.time
It can be a fairly expensive operation when the output is not cached, so
it's nice to get some visibility into the runtime cost.
2025-03-27 03:34:17 +01:00
Mads Marquart
713becd7da refactor: Move Apple SDK names to rustc_codegen_ssa:🔙:apple 2025-03-27 03:34:11 +01:00
Mads Marquart
d1cd621b55 Always emit native-static-libs note, even if it is empty 2025-03-26 21:59:00 +01:00
bors
a2e63569fd Auto merge of #138824 - Zoxc:dep-graph-no-prev-map, r=oli-obk
Remove `prev_index_to_index` field from `CurrentDepGraph`

The dep graph currently has 2 ways to map a previous index into a current index. The `prev_index_to_index` map stores the current index equivalent of a previous index. For indices which are marked green, we also store the same information in the `DepNodeColorMap`. We actually only need to known the mapping for green nodes however, so this PR removes `prev_index_to_index` and instead makes use of the `DepNodeColorMap`.

To avoid racing when promoting a node from the previous session, the encoder lock is now used to ensure only one thread encodes the promoted node. This was previously done by the lock in `prev_index_to_index`.

This also changes `nodes_newly_allocated_in_current_session` used to detect duplicate dep nodes to contain both new and previous nodes, which is simpler and can better catch duplicates.

The dep node index encoding used in `DepNodeColorMap` is tweak to avoid subtraction / addition to optimize accessing the current equivalent of a previous index.

r? `@oli-obk`
2025-03-26 17:36:52 +00:00
Mara Bos
2cc3fa32ef Remove ScopeDepth from var_parent.
It was never used.
2025-03-26 17:18:35 +01:00
Mara Bos
0ad0142a5b Don't set cx.parent to None; it seems unnecessary. 2025-03-26 17:18:35 +01:00
Mara Bos
227f93395a Simplify RvalueCandidateType.
There is no difference between the Patternand Borrow cases. Reduce it to
a simple struct.
2025-03-26 17:18:35 +01:00
Mara Bos
1da5e60ac5 Don't record child scopes for patterns.
They are unused.
2025-03-26 17:18:18 +01:00
Mads Marquart
632ce38c9a Add environment variable tracking in places where it was convenient
This won't work with Cargo's change tracking, but it should work with incremental.
2025-03-26 15:46:40 +01:00
Mads Marquart
17db054141 Add TyCtx::env_var_os
Along with `TyCtx::env_var` helper. These can be used to track
environment variable accesses in the query system.

Since `TyCtx::env_var_os` uses `OsStr`, this commit also adds the
necessary trait implementations for that to work.
2025-03-26 15:46:05 +01:00
bors
19cab6b878 Auto merge of #130324 - petrochenkov:ctxtache, r=oli-obk
hygiene: Ensure uniqueness of `SyntaxContextData`s

`SyntaxContextData`s are basically interned with `SyntaxContext`s working as indices, so they are supposed to be unique.
However, currently duplicate `SyntaxContextData`s can be created during decoding from metadata or incremental cache.
This PR fixes that.

cc https://github.com/rust-lang/rust/pull/129827#discussion_r1759074553
2025-03-26 14:11:48 +00:00
Oli Scherer
a830c59f24 Use the correct binder scope for elided lifetimes in assoc consts 2025-03-26 12:44:33 +00:00
Vadim Petrochenkov
92d802eda6 expand: Leave traces when expanding cfg attributes 2025-03-26 15:30:12 +03:00
John Kåre Alsaker
6ca2af6434 Use a function to create QueryStackDeferred to ensure context is Copy 2025-03-26 13:09:36 +01:00
bors
f1bc669636 Auto merge of #138974 - Zalathar:rollup-568cpmy, r=Zalathar
Rollup of 7 pull requests

Successful merges:

 - #138483 (Target modifiers fix for bool flags without value)
 - #138818 (Don't produce debug information for compiler-introduced-vars when desugaring assignments.)
 - #138898 (Mostly parser: Eliminate code that's been dead / semi-dead since the removal of type ascription syntax)
 - #138930 (Add bootstrap step diff to CI job analysis)
 - #138954 (Ensure `define_opaque` attrs are accounted for in HIR hash)
 - #138959 (Revert "Make MatchPairTree::place non-optional")
 - #138967 (Fix typo in error message)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-26 11:03:12 +00:00
Tomasz Miąsko
b04e5b4963 Collect items referenced from var_debug_info
The collection is limited to full debuginfo builds to match behavior of
FunctionCx::compute_per_local_var_debug_info.
2025-03-26 11:35:34 +01:00
Oli Scherer
781785d2b6 Don't deaggregate InvocationParent just to reaggregate it again 2025-03-26 09:40:27 +00:00
Stuart Cook
33c90235a1
Rollup merge of #138959 - meithecatte:matchpair-place-option, r=Zalathar
Revert "Make MatchPairTree::place non-optional"

Reverts a part of #137875. Fixes #138958.

cc `@Zalathar`
2025-03-26 19:40:31 +11:00
Stuart Cook
19a53b7d3f
Rollup merge of #138954 - compiler-errors:hash-opaques, r=oli-obk
Ensure `define_opaque` attrs are accounted for in HIR hash

Fixes #138948

r? oli-obk
2025-03-26 19:40:30 +11:00
Stuart Cook
30344f7fa3
Rollup merge of #138898 - fmease:decrustify-parser-post-ty-ascr, r=compiler-errors
Mostly parser: Eliminate code that's been dead / semi-dead since the removal of type ascription syntax

**Disclaimer**: This PR is intended to mostly clean up code as opposed to bringing about behavioral changes. Therefore it doesn't aim to address any of the 'FIXME: remove after a month [dated: 2023-05-02]: "type ascription syntax has been removed, see issue [#]101728"'.

---

By commit:

1. Removes truly dead code:
   * Since 1.71 (#109128) `let _ = { f: x };` is a syntax error as opposed to a semantic error which allows the parse-time diagnostic (suggestion) "*struct literal body without path // you might have forgotten […]*" to kick in.
   * The analysis-time diagnostic (suggestion) from <=1.70 "*cannot find value \`f\` in this scope // you might have forgotten […]*" is therefore no longer reachable.
2. Updates `is_certainly_not_a_block` to be in line with the current grammar:
   * The seq. `{ ident:` is definitely not the start of a block. Before the removal of ty ascr, `{ ident: ty_start` would begin a block expr.
   * This shouldn't make more code compile IINM, it should *ultimately* only affect diagnostics.
   * For example, `if T { f: () } {}` will now be interpreted as an `if` with struct lit `T { f: () }` as its *condition* (which is banned in the parser anyway) as opposed to just `T` (with the *consequent* being `f : ()` which is also invalid (since 1.71)). The diagnostics are almost the same because we have two separate parse recovery procedures + diagnostics: `StructLiteralNeedingParens` (*invalid struct lit*) before and `StructLiteralNotAllowedHere` (*struct lits aren't allowed here*) now, as you can see from the diff.
   * (As an aside, even before this PR, fn `maybe_suggest_struct_literal` should've just used the much older & clearer `StructLiteralNotAllowedHere`)
   * NB: This does sadly regress the compiler output for `tests/ui/parser/type-ascription-in-pattern.rs` but that can be fixed in follow-up PRs. It's not super important IMO and a natural consequence.
3. Removes code that's become dead due to the prior commit.
   * Basically reverts #106620 + #112475 (without regressing rustc's output!).
   * Now the older & more robust parse recovery procedure (cc `StructLiteralNotAllowedHere`) takes care of the cases the removed code used to handle.
   * This automatically fixes the suggestions for \[[playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=7e2030163b11ee96d17adc3325b01780)\]:
     * `if Ty::<i32> { f: K }.m() {}`: `if Ty::<i32> { SomeStruct { f: K } }.m() {}` (broken) → ` if (Ty::<i32> { f: K }).m() {}`
     * `if <T as Trait>::Out { f: K::<> }.m() {}`: `if <T as Trait>(::Out { f: K::<> }).m() {}` (broken) → `if (<T as Trait>::Out { f: K::<> }).m() {}`
4. Merge and simplify UI tests pertaining to this issue, so it's easier to add more regression tests like for the two cases mentioned above.
5. Merge UI tests and add the two regression tests.

Best reviewed commit by commit (on request I'll partially squash after approval).
2025-03-26 19:40:28 +11:00