Commit Graph

30927 Commits

Author SHA1 Message Date
lcnr 5d97ada1ec rename `-Ztrait-solver` to `-Znext-solver` 2023-12-14 15:22:37 +01:00
Urgau c355040a5c Don't forget pure rustc target features in check-cfg 2023-12-14 14:50:32 +01:00
Urgau acac133997 Use all the known features in check-cfg 2023-12-14 14:49:42 +01:00
Urgau 428395e064 Move rustc_codegen_ssa target features to rustc_target 2023-12-14 14:40:55 +01:00
Ben Kimock e559172249 Fix cases where std accidentally relied on inline(never) 2023-12-14 08:30:36 -05:00
bors 1aa6aefdc9 Auto merge of #118566 - klensy:cstr-new, r=WaffleLapkin
use c literals in compiler and library

Relands refreshed https://github.com/rust-lang/rust/pull/111647
2023-12-14 11:14:03 +00:00
bors 9d49eb76c4 Auto merge of #118417 - anforowicz:default-hidden-visibility, r=TaKO8Ki
Add unstable `-Zdefault-hidden-visibility` cmdline flag for `rustc`.

The new flag has been described in the Major Change Proposal at
https://github.com/rust-lang/compiler-team/issues/656
2023-12-14 09:16:15 +00:00
Ralf Jung 5d87d8307f interpret: extend comment on the inhabitedness check in downcast 2023-12-14 09:50:47 +01:00
bors 1a8afa0e74 Auto merge of #118538 - RalfJung:size-of-val-comments, r=WaffleLapkin
fix dynamic size/align computation logic for packed types with dyn trait tail

This logic was never updated to support `packed(N)` where `N > 1`, and it turns out to be wrong for that case.

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

`@bjorn3` I have not looked at cranelift; I assume it basically copied the size-of-val logic and hence could use much the same patch.
2023-12-14 07:19:07 +00:00
Nicholas Nethercote e3b7ecc1ef Remove one use of `span_bug_no_panic`.
It's unclear why this is used here. All entries in the third column of
`UNICODE_ARRAY` are covered by `ASCII_ARRAY`, so if the lookup fails
it's a genuine compiler bug. It was added way back in #29837, for no
clear reason.

This commit changes it to `span_bug`, which is more typical.
2023-12-14 15:53:55 +11:00
Nicholas Nethercote 7bdb227567 Avoid `struct_diagnostic` where possible.
It's necessary for `derive(Diagnostic)`, but is best avoided elsewhere
because there are clearer alternatives.

This required adding `Handler::struct_almost_fatal`.
2023-12-14 15:53:55 +11:00
Nicholas Nethercote dc05a30996 Inline and remove `HandlerInner::emit_diag_at_span`.
It has a single call site.
2023-12-14 15:53:55 +11:00
Nicholas Nethercote 43a0f55506 Remove unused `Handler::treat_err_as_bug`. 2023-12-14 15:53:55 +11:00
bors d23e1a6894 Auto merge of #117749 - aliemjay:perf-canon-cache, r=lcnr
cache param env canonicalization

Canonicalize ParamEnv only once and store it. Then whenever we try to canonicalize `ParamEnvAnd<'tcx, T>` we only have to canonicalize `T` and then merge the results.

Prelimiary results show ~3-4% savings in diesel and serde benchmarks.

Best to review commits individually. Some commits have a short description.

Initial implementation had a soundness bug (https://github.com/rust-lang/rust/pull/117749#issuecomment-1840453387) due to cache invalidation:
- When canonicalizing `Ty<'?0>` we first try to resolve region variables in the current InferCtxt which may have a constraint `?0 == 'static`. This means that we register `Ty<'?0> => Canonical<Ty<'static>>` in the cache, which is obviously incorrect in another inference context.
- This is fixed by not doing region resolution when canonicalizing the query *input* (vs. response), which is the only place where ParamEnv is used, and then in a later commit we *statically* guard against any form of inference variable resolution of the cached canonical ParamEnv's.

r? `@ghost`
2023-12-14 04:04:10 +00:00
Ali MJ Al-Nasrawy e452c94912 remove canonicalize_query_preserving_universes
unused!
2023-12-14 03:03:03 +00:00
Ali MJ Al-Nasrawy 3b55869615 make infcx optional in canonicalizer
This doesn't change behavior.
It should prevent unintentional resolution of inference variables
during canonicalization, which previously caused a soundness bug.
See PR description for more.
2023-12-14 03:03:03 +00:00
bors e6d1b0ec98 Auto merge of #118491 - cuviper:aarch64-stack-probes, r=wesleywiser
Enable stack probes on aarch64 for LLVM 18

I tested this on `aarch64-unknown-linux-gnu` with LLVM main (~18).

cc #77071, to be closed once we upgrade our LLVM submodule.
2023-12-14 02:01:13 +00:00
Celina G. Val a66cac92cc Add spread arg and missing CoroutineKind 2023-12-13 16:36:15 -08:00
Celina G. Val c3a2302fb0 Erase late bound regions from instance `fn_sig()`
Late bound regions were still part of the signature.
2023-12-13 16:36:14 -08:00
Esteban Küber 9d846fcc11 Tweak `short_ty_string` to reduce number of files
When shortening types and writing them to disk, make `short_ty_string`
capable of reusing the same file, instead of writing a file per
shortened type.
2023-12-13 23:07:10 +00:00
Lukasz Anforowicz 981c4e3ce6 Add unstable `-Zdefault-hidden-visibility` cmdline flag for `rustc`.
The new flag has been described in the Major Change Proposal at
https://github.com/rust-lang/compiler-team/issues/656
2023-12-13 21:14:23 +00:00
bors a90372c6e8 Auto merge of #118213 - Urgau:check-cfg-diagnostics-rustc-cargo, r=petrochenkov
Add more suggestions to unexpected cfg names and values

This pull request adds more suggestion to unexpected cfg names and values diagnostics:
 - it first adds a links to the [rustc unstable book](https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html) or the [Cargo reference](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg), depending if rustc is invoked by Cargo
 - it secondly adds a suggestion on how to expect the cfg name or value:
    *excluding well known names and values*
    - for Cargo: it suggest using a feature or `cargo:rust-check-cfg` in build script
    - for rustc: it suggest using `--check-cfg` (with the correct invocation)

Those diagnostics improvements are directed towards enabling users to fix the issue if the previous suggestions weren't good enough.

r? `@petrochenkov`
2023-12-13 19:45:57 +00:00
Ralf Jung 7e4c4271f4 fix computing the dynamic alignment of packed structs with dyn trait tails 2023-12-13 20:21:57 +01:00
Matthias Krüger 1dd36119d0
Rollup merge of #118871 - tmiasko:coroutine-maybe-uninit-fields, r=compiler-errors
Coroutine variant fields can be uninitialized

Wrap coroutine variant fields in MaybeUninit to indicate that they might be uninitialized. Otherwise an uninhabited field will make the entire variant uninhabited and introduce undefined behaviour.

The analogous issue in the prefix of coroutine layout was addressed by 6fae7f8071.
2023-12-13 18:03:33 +01:00
Matthias Krüger dbc6ec6636
Rollup merge of #118759 - compiler-errors:bare-unit-structs, r=petrochenkov
Support bare unit structs in destructuring assignments

We should be allowed to use destructuring assignments on *bare* unit structs, not just unit structs that are located within other pattern constructors.

Fixes #118753

r? petrochenkov since you reviewed #95380, reassign if you're busy or don't want to review this.
2023-12-13 18:03:33 +01:00
Urgau 5345a166fe Add more suggestion to unexpected cfg names and values 2023-12-13 17:48:04 +01:00
Ali MJ Al-Nasrawy fafe66d438 don't resolve regions in query input
fixes a soundness regression described in the PR description.
2023-12-13 14:57:52 +00:00
Ali MJ Al-Nasrawy a1459c3fca fix small perf regressions 2023-12-13 14:57:52 +00:00
Ali MJ Al-Nasrawy 85338197d4 don't store OriginalQueryValues::universe_map
ParamEnv is canonicalized in *queries input* rather than query response.
In such case we don't "preserve universes" of canonical variable.
This means that `universe_map` always has the default value, which is
wasteful to store in the cache.
2023-12-13 14:57:52 +00:00
Ali MJ Al-Nasrawy f38d1e971d global param_env canonicalization cache 2023-12-13 14:57:52 +00:00
bors c3def263a4 Auto merge of #118870 - Enselic:rustc_passes-query-stability, r=compiler-errors
rustc_passes: Enforce `rustc::potential_query_instability` lint

Stop allowing `rustc::potential_query_instability` in all of `rustc_passes` and instead allow it on a case-by-case basis if it is safe. In this case, all instances of the lint are safe to allow.

Part of https://github.com/rust-lang/rust/issues/84447 which is E-help-wanted.
2023-12-13 12:47:43 +00:00
bors 56d25ba5ea Auto merge of #118500 - ZetaNumbers:tcx_hir_refactor, r=petrochenkov
Move some methods from `tcx.hir()` to `tcx`

https://github.com/rust-lang/rust/pull/118256#issuecomment-1826442834

Renamed:
- find -> opt_hir_node
- get -> hir_node
- find_by_def_id -> opt_hir_node_by_def_id
- get_by_def_id -> hir_node_by_def_id
2023-12-13 10:31:56 +00:00
bors 2fdd9eda0c Auto merge of #118534 - RalfJung:extern-type-size-of-val, r=WaffleLapkin
codegen: panic when trying to compute size/align of extern type

The alignment is also computed when accessing a field of extern type at non-zero offset, so we also panic in that case.

Previously `size_of_val` worked because the code path there assumed that "thin pointer" means "sized". But that's not true any more with extern types. The returned size and align are just blatantly wrong, so it seems better to panic than returning wrong results. We use a non-unwinding panic since code probably does not expect size_of_val to panic.
2023-12-13 08:33:05 +00:00
bors f651b436ce Auto merge of #117050 - c410-f3r:here-we-go-again, r=petrochenkov
[`RFC 3086`] Attempt to try to resolve blocking concerns

Implements what is described at https://github.com/rust-lang/rust/issues/83527#issuecomment-1744822345 to hopefully make some progress.

It is unknown if such approach is or isn't desired due to the lack of further feedback, as such, it is probably best to nominate this PR to the official entities.

`@rustbot` labels +I-compiler-nominated
2023-12-13 06:37:08 +00:00
Jubilee f9078a40ee
Rollup merge of #118891 - compiler-errors:async-gen-blocks, r=eholk
Actually parse async gen blocks correctly

1. I got the control flow in `parse_expr_bottom` messed up, and obviously forgot a test for `async gen`, so we weren't actually ever parsing it correctly.
2. I forgot to gate the span for `async gen {}`, so even if we did parse it, we wouldn't have correctly denied it in `cfg(FALSE)`.

r? eholk
2023-12-12 18:48:55 -08:00
Jubilee 4583a0134f
Rollup merge of #118889 - matthiaskrgr:compl_2023_2, r=WaffleLapkin
more clippy::complexity fixes

      redundant_guards
      redundant_slicing
      filter_next
      needless_borrowed_reference
      useless_format
2023-12-12 18:48:54 -08:00
Jubilee df0686b629
Rollup merge of #118887 - smoelius:patch-1, r=Nilstrieb
Typo
2023-12-12 18:48:54 -08:00
Jubilee 5308733112
Rollup merge of #118885 - matthiaskrgr:compl_2023, r=compiler-errors
clippy::complexity fixes

 filter_map_identity
 needless_bool
 search_is_some
 unit_arg
 map_identity
 needless_question_mark
 derivable_impls
2023-12-12 18:48:53 -08:00
Jubilee 89d4a9bee9
Rollup merge of #118884 - matthiaskrgr:auszweimacheins, r=Nadrieril
NFC: simplify merging of two vecs
2023-12-12 18:48:52 -08:00
Jubilee a33f1a3d3a
Rollup merge of #118864 - farnoy:masked-load-store-fixes, r=workingjubilee
Fix alignment passed down to LLVM for simd_masked_load

Follow up to #117953

The alignment for a masked load operation should be that of the element/lane, not the vector as a whole

It can produce miscompilations after the LLVM optimizer notices the higher alignment and promotes this to an unmasked, aligned load followed up by blend/select - https://rust.godbolt.org/z/KEeGbevbb
2023-12-12 18:48:51 -08:00
Josh Stone 233de9d89e Set the `StackProbeType` in `apple::opts` 2023-12-12 17:26:51 -08:00
Michael Goulet 9f0849f9e0 Uplift TypeAndMut 2023-12-12 23:24:44 +00:00
Michael Goulet b8ea6e686f Uplift ClosureKind 2023-12-12 23:24:44 +00:00
Michael Goulet 1d78ce681e Actually parse async gen blocks correctly 2023-12-12 20:13:37 +00:00
Matthias Krüger 2a1acc26a0
Update compiler/rustc_pattern_analysis/src/constructor.rs
add note that `missing_empty` is cleared now

Co-authored-by: Nadrieril <Nadrieril@users.noreply.github.com>
2023-12-12 21:12:19 +01:00
Matthias Krüger 3795cc8eb0 more clippy::complexity fixes
redundant_guards
      redundant_slicing
      filter_next
      needless_borrowed_reference
      useless_format
2023-12-12 20:41:51 +01:00
Samuel Moelius 046f2dea33
Typo 2023-12-12 13:48:20 -05:00
Matthias Krüger d707461a1a clippy::complexity fixes
filter_map_identity
 needless_bool
 search_is_some
 unit_arg
 map_identity
 needless_question_mark
 derivable_impls
2023-12-12 19:28:13 +01:00
bors 028b6d152e Auto merge of #118881 - matthiaskrgr:rollup-0rl3tir, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #116740 (dont ICE when ConstKind::Expr for is_const_evaluatable)
 - #117914 (On borrow return type, suggest borrowing from arg or owned return type)
 - #117927 (Clarify how to choose a FutureIncompatibilityReason variant.)
 - #118855 (Improve an error involving attribute values.)
 - #118856 (rustdoc-search: clean up parser)
 - #118865 (rustc_codegen_llvm: Enforce `rustc::potential_query_instability` lint)
 - #118866 (llvm-wrapper: adapt for LLVM API change)
 - #118868 (Correctly gate the parsing of match arms without body)
 - #118877 (tests: CGU tests require build-pass, not check-pass (remove FIXME))

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-12 18:20:37 +00:00
Matthias Krüger 6892fcd690 simplify merging of two vecs 2023-12-12 18:42:37 +01:00
Matthias Krüger d661974017
Rollup merge of #118868 - Nadrieril:correctly-gate-never_patterns-parsing, r=petrochenkov
Correctly gate the parsing of match arms without body

https://github.com/rust-lang/rust/pull/118527 accidentally allowed the following to parse on stable:
```rust
match Some(0) {
    None => { foo(); }
    #[cfg(FALSE)]
    Some(_)
}
```

This fixes that oversight. The way I choose which error to emit is the best I could think of, I'm open if you know a better way.

r? `@petrochenkov` since you're the one who noticed
2023-12-12 17:40:56 +01:00
Matthias Krüger 9ed12f8d7a
Rollup merge of #118866 - krasimirgg:llvm-18-ref, r=durin42
llvm-wrapper: adapt for LLVM API change

LLVM commit f09cf34d00 (old) moved some functions to a different header. It looks we were getting it transitively in PassWrapper, and something in LLVM recently removed it from the set of transitively available headers, so include it directly:
https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/24416#018c5de6-b9c9-4b22-9473-6070d99dcfa7/233-537

r? `@nikic`
2023-12-12 17:40:55 +01:00
Matthias Krüger 04c77a51ef
Rollup merge of #118865 - Enselic:rustc_codegen_llvm-lint-fix, r=petrochenkov
rustc_codegen_llvm: Enforce `rustc::potential_query_instability` lint

Stop allowing `rustc::potential_query_instability` on all of `rustc_codegen_llvm` and instead allow it on a case-by-case basis if it is safe to do so. In this case, all 2 instances are safe to allow.

Part of https://github.com/rust-lang/rust/issues/84447 which is E-help-wanted.
2023-12-12 17:40:55 +01:00
Matthias Krüger cd7809b953
Rollup merge of #118855 - nnethercote:improve-attribute-value-error, r=compiler-errors,petrochenkov
Improve an error involving attribute values.

Attribute values must be literals. The error you get when that doesn't hold is pretty bad, e.g.:
```
unexpected expression: 1 + 1
```
You also get the same error if the attribute value is a literal, but an invalid literal, e.g.:
```
unexpected expression: "foo"suffix
```

This commit does two things.
- Changes the error message to "attribute value must be a literal", which gives a better idea of what the problem is and how to fix it. It also no longer prints the invalid expression, because the carets below highlight it anyway.
- Separates the "not a literal" case from the "invalid literal" case. Which means invalid literals now get the specific error at the literal level, rather than at the attribute level.

r? `@compiler-errors`
2023-12-12 17:40:54 +01:00
Matthias Krüger 111c40ec22
Rollup merge of #117927 - ehuss:future-incompat-docs, r=wesleywiser
Clarify how to choose a FutureIncompatibilityReason variant.

There has been some confusion about how to choose these variants, or what the procedure is for handling future-incompatible errors. Hopefully this helps provide some more information on how these work.
2023-12-12 17:40:53 +01:00
Matthias Krüger ffdb471872
Rollup merge of #117914 - estebank:issue-85843, r=wesleywiser
On borrow return type, suggest borrowing from arg or owned return type

When we encounter a function with a return type that has an anonymous lifetime with no argument to borrow from, besides suggesting the `'static` lifetime we now also suggest changing the arguments to be borrows or changing the return type to be an owned type.

```
error[E0106]: missing lifetime specifier
  --> $DIR/variadic-ffi-6.rs:7:6
   |
LL | ) -> &usize {
   |      ^ expected named lifetime parameter
   |
   = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
   |
LL | ) -> &'static usize {
   |       +++++++
help: instead, you are more likely to want to change one of the arguments to be borrowed...
   |
LL |     x: &usize,
   |        +
help: ...or alternatively, to want to return an owned value
   |
LL - ) -> &usize {
LL + ) -> usize {
   |
```

Fix #85843.
2023-12-12 17:40:53 +01:00
Matthias Krüger b2a0175b97
Rollup merge of #116740 - lenko-d:const_evaluatable_failed_for_non_unevaluated_const, r=BoxyUwU
dont ICE when ConstKind::Expr for is_const_evaluatable

The problem is that we are not handling ConstKind::Expr inside report_not_const_evaluatable_error

Fixes [#114151]
2023-12-12 17:40:52 +01:00
bors 835ed0021e Auto merge of #118751 - lcnr:writeback-change, r=compiler-errors
refactor writeback: emit normalization errors with new solver

implements https://github.com/rust-lang/rust/pull/118725#discussion_r1419824030

r? `@compiler-errors` `@BoxyUwU` whoever comes first n stuff
2023-12-12 16:14:57 +00:00
zetanumbers 24f009c5e5 Move some methods from `tcx.hir()` to `tcx`
Renamings:
- find -> opt_hir_node
- get -> hir_node
- find_by_def_id -> opt_hir_node_by_def_id
- get_by_def_id -> hir_node_by_def_id

Fix rebase changes using removed methods

Use `tcx.hir_node_by_def_id()` whenever possible in compiler

Fix clippy errors

Fix compiler

Apply suggestions from code review

Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

Add FIXME for `tcx.hir()` returned type about its removal

Simplify with with `tcx.hir_node_by_def_id`
2023-12-12 06:40:29 -08:00
Nadrieril 19e0c984d3 Don't gate the feature twice 2023-12-12 14:52:05 +01:00
Nadrieril e274372689 Correctly gate the parsing of match arms without body 2023-12-12 14:42:04 +01:00
Martin Nordholts e9b16cc2c5 rustc_passes: Enforce `rustc::potential_query_instability` lint
Stop allowing `rustc::potential_query_instability` in all of
`rustc_passes` and instead allow it on a case-by-case basis if it is
safe. In this case, all instances of the lint are safe to allow.
2023-12-12 13:57:52 +01:00
bors 27d8a57713 Auto merge of #118841 - compiler-errors:always-copy, r=jackh726
Make most `rustc_type_ir` kinds `Copy` by default

1. There's no reason why `TyKind` and `ConstKind`/`ConstData` can't be `Copy`. This allows us to avoid needing a typed arena for the two types.
2. Simplify some impls into derives.
2023-12-12 12:32:32 +00:00
Krasimir Georgiev 46a8015591 llvm-wrapper: adapt for LLVM API change
LLVM commit f09cf34d00 moved some functions to a different header:

https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/24416#018c5de6-b9c9-4b22-9473-6070d99dcfa7/233-537
2023-12-12 12:29:30 +00:00
lcnr 0bea818b29 review + rename fn 2023-12-12 12:28:54 +00:00
lcnr 6ffe36b37d refactor writeback: emit normalization errors with new solver 2023-12-12 12:20:54 +00:00
Martin Nordholts f44ccbab2b rustc_codegen_llvm: Enforce `rustc::potential_query_instability` lint
Stop allowing `rustc::potential_query_instability` on all of
`rustc_codegen_llvm` and instead allow it on a case-by-case basis. In
this case, both instances are safe to allow.
2023-12-12 13:16:14 +01:00
Jakub Okoński 95b5a80f47
Fix alignment passed down to LLVM for simd_masked_load 2023-12-12 13:11:59 +01:00
Ralf Jung b9c9b3e7a2 remove a cranelift test that doesn't make sense any more 2023-12-12 08:15:17 +01:00
Ralf Jung 9ef1e35166 reject projecting to fields whose offset we cannot compute 2023-12-12 08:15:17 +01:00
Ralf Jung b1613ebc43 codegen: panic when trying to compute size/align of extern type 2023-12-12 08:15:17 +01:00
Matthias Krüger d67e80f12d
Rollup merge of #118846 - celinval:smir-ty-methods, r=compiler-errors
Fix BinOp `ty()` assertion and `fn_sig()` for closures

`BinOp::ty()` was asserting that the argument types were primitives. However, the primitive check doesn't include pointers, which can be used in a `BinaryOperation`. Thus extend the arguments to include them.

Since I had to add methods to check for pointers in TyKind, I just went ahead and added a bunch more utility checks that can be handy for our users and fixed the `fn_sig()` method to also include closures.

`@compiler-errors` just wanted to confirm that today no `BinaryOperation` accept SIMD types. Is that correct?

r? `@compiler-errors`
2023-12-12 06:52:51 +01:00
Matthias Krüger cdc4fc9f35
Rollup merge of #118844 - celinval:smir-mono-args, r=compiler-errors
Monomorphize args while building Instance body in StableMIR

The function `Instance::body()` in StableMIR is supposed to return a monomorphic body by instantiating all possibly generic constructs. We were previously instantiating type and constants, but not generic arguments. This PR ensures that we also instantiate them.

r? ``@compiler-errors``
2023-12-12 06:52:51 +01:00
Matthias Krüger fefa8fc6c4
Rollup merge of #118840 - matthiaskrgr:cloooooone, r=compiler-errors
remove some redundant clones
2023-12-12 06:52:50 +01:00
Matthias Krüger b862e7edce
Rollup merge of #118797 - tmiasko:dead-coro, r=davidtwco
End locals' live range before suspending coroutine

State transforms retains storage statements for locals that are not
stored inside a coroutine. It ensures those locals are live when
resuming by inserting StorageLive as appropriate. It forgot to end the
storage of those locals when suspending, which is fixed here.

While the end of live range is implicit when executing return, it is
nevertheless useful for inliner which would otherwise extend the live
range beyond return.

Fixes #117733
2023-12-12 06:52:50 +01:00
Matthias Krüger dfc5ffacd3
Rollup merge of #118756 - jyn514:colors, r=estebank
use bold magenta instead of bold white for highlighting

according to a poll of gay people in my phone, purple is the most popular color to use for highlighting

| color      | percentage |
| ---------- | ---------- |
| bold white | 6%         |
| blue       | 14%        |
| cyan       | 26%        |
| purple     | 37%        |
| magenta    | 17%        |

unfortunately, purple is not supported by 16-color terminals, which rustc apparently wants to support for some reason.
until we require support for full 256-color terms (e.g. by doing the same feature detection as we currently do for urls), we can't use it.

instead, i have collapsed the purple votes into magenta on the theory that they're close, and also because magenta is pretty.

before:
![image](https://github.com/rust-lang/rust/assets/23638587/9a89eee2-8b89-422e-8554-812827bb2a23)

after:
![image](https://github.com/rust-lang/rust/assets/23638587/5bf3a917-8a20-4afd-af3e-f9491d0d57f5)

other colors for comparison:
blue: ![image](https://github.com/rust-lang/rust/assets/23638587/6f199c7b-d598-4009-8ffc-6b7b1d0d1f8c)
cyan: ![image](https://github.com/rust-lang/rust/assets/23638587/a77e4fe3-563e-4aa5-ae92-745bb67287d1)
purple: ![image](https://github.com/rust-lang/rust/assets/23638587/ffe603fb-d811-4106-95a9-4dd4c955924c)
magenta without bolding: ![image](https://github.com/rust-lang/rust/assets/23638587/cf927e5f-8b25-4dc2-b8e7-32905a11a459)

r? ``@estebank``
2023-12-12 06:52:49 +01:00
Nicholas Nethercote 226edf64fa Improve an error involving attribute values.
Attribute values must be literals. The error you get when that doesn't
hold is pretty bad, e.g.:
```
unexpected expression: 1 + 1
```
You also get the same error if the attribute value is a literal, but an
invalid literal, e.g.:
```
unexpected expression: "foo"suffix
```

This commit does two things.
- Changes the error message to "attribute value must be a literal",
  which gives a better idea of what the problem is and how to fix it. It
  also no longer prints the invalid expression, because the carets below
  highlight it anyway.
- Separates the "not a literal" case from the "invalid literal" case.
  Which means invalid literals now get the specific error at the literal
  level, rather than at the attribute level.
2023-12-12 15:54:25 +11:00
bors 5f5d248602 Auto merge of #118742 - lcnr:infer-var-cleanup, r=compiler-errors
refactor infer var storage

cleanup the code, discovered while working on #118725
2023-12-12 03:23:37 +00:00
Celina G. Val 638b08ebdf Remove scalar fn and tighten the BiOp Ty assertions 2023-12-11 19:02:54 -08:00
Michael Goulet f3218b2a70 Make ConstKind and TyKind Copy 2023-12-12 01:09:12 +00:00
Michael Goulet e947234520 Simplify some Copy impls in rustc_type_ir 2023-12-12 01:09:12 +00:00
Celina G. Val 3b97b5130a Fix doc comment 2023-12-11 16:37:33 -08:00
Celina G. Val 2f790af726 Fix BinOp ty assertion and `fn_sig` for closures
Also added a few more util methods to TyKind to check for specific types.
2023-12-11 16:06:48 -08:00
Tomasz Miąsko a48cebc4b8 Coroutine variant fields can be uninitialized
Wrap coroutine variant fields in MaybeUninit to indicate that they
might be uninitialized. Otherwise an uninhabited field will make
the entire variant uninhabited and introduce undefined behaviour.

The analogous issue in the prefix of coroutine layout was addressed by
6fae7f8071.
2023-12-12 00:00:00 +00:00
Celina G. Val 0a65dd305f Monomorphize args while building Instance body 2023-12-11 15:29:34 -08:00
bors e2a3c9b3f0 Auto merge of #117962 - weihanglo:debug-name-table, r=wesleywiser
fix: stop emitting `.debug_pubnames` and `.debug_pubtypes`

A continuation of #94181.
Fixes #48762
MCP can be found in <https://github.com/rust-lang/compiler-team/issues/688>.

`.debug_pubnames` and `.debug_pubtypes` are poorly designed and people
seldom use them. However, they take a considerable portion of size in
the final binary. This tells LLVM stop emitting those sections on
DWARFv4 or lower. DWARFv5 use `.debug_names` which is more concise
in size and performant for name lookup.

Some other no-really-useful personal notes:

<details><summary>Details</summary>
<p>

## Pepole saying they are not useful

* https://github.com/rust-lang/rust/issues/48762
* https://rust-lang.zulipchat.com/#narrow/stream/317568-t-compiler.2Fwg-debugging/topic/investigating.20debuginfo.20size/near/342713604
* `DwarfCompileUnit::hasDwarfPubSections()` — f633f325a1/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (L1477-L1494)
* clang default to no debug name table when no option provided — f633f325a1/clang/lib/Frontend/CompilerInvocation.cpp (L1819-L1824)
* GCC explicitly says GDB doesn't use pub sections (`TARGET_WANT_DEBUG_PUB_SECTIONS` only be true on Darwin) — 5d2a360f0a/gcc/target.def (L6985-L6990) and 319b460545/gold/dwarf_reader.h (L424-L427)
* Probably the only place that makes use of pub section in lldb — 725115d7bb/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (L2117-L2135)

* "The -gsplit-dwarf option requires -ggnu-pubnames." — 5d2a360f0a/gcc/opts.cc (L1205)

* LLVM: Always emit `.debug_names` with dwarf 5 for Apple platforms — https://reviews.llvm.org/D118754

</p>
</details>
2023-12-11 22:32:08 +00:00
Tomasz Miąsko eaaa290dbc Remove redundant special case for resume argument
The special case is subsumed by the check for always live locals that
follows it.
2023-12-11 23:11:20 +01:00
Tomasz Miąsko ef1831a21f End locals' live range before suspending coroutine
State transforms retains storage statements for locals that are not
stored inside a coroutine. It ensures those locals are live when
resuming by inserting StorageLive as appropriate. It forgot to end the
storage of those locals when suspending, which is fixed here.

While the end of live range is implicit when executing return, it is
nevertheless useful for inliner which would otherwise extend the live
range beyond return.
2023-12-11 23:11:20 +01:00
Weihang Lo 6aac62cdcb
refactor: only check dwarf version when emitting dwarf 2023-12-11 16:24:24 -05:00
Matthias Krüger 0564de10b1 remove some redundant clones 2023-12-11 21:54:36 +01:00
Weihang Lo 1667f3d2cc
fix: stop emitting `.debug_pubnames` and `.debug_pubtypes`
`.debug_pubnames` and `.debug_pubtypes` are poorly designed and people
seldom use them. However, they take a considerable portion of size in
the final binary. This tells LLVM stop emitting those sections on
DWARFv4 or lower. DWARFv5 use `.debug_names` which is more concise
in size and performant for name lookup.
2023-12-11 14:58:02 -05:00
Matthias Krüger 1cf538b0b1
Rollup merge of #118835 - Urgau:fix-rccg-gcc-tests, r=matthiaskrgr
Fix again `rustc_codegen_gcc` tests

Similar to https://github.com/rust-lang/rust/pull/118706

r? `@GuillaumeGomez`
2023-12-11 20:46:52 +01:00
Matthias Krüger dd0887c75c
Rollup merge of #118822 - Nadrieril:librarify, r=compiler-errors
Extract exhaustiveness into its own crate

It now makes sense to extract exhaustiveness into its own crate! This was much-requested by rust-analyzer (they currently maintain by hand a copy of the algorithm), and I hope this can serve other projects e.g. clippy.

This is the churny PR: it exclusively moves code around. It's not yet useable outside of rustc but I wanted the churny parts to be out of the way.

r? `@compiler-errors`
2023-12-11 20:46:50 +01:00
Matthias Krüger dadecea9f1
Rollup merge of #118818 - krasimirgg:llvm-18-pass, r=nikic
llvm-wrapper: adapt for LLVM API change

LLVM commit 1d608fc755 renamed the pass.

r? ````@nikic````
2023-12-11 20:46:50 +01:00
Matthias Krüger 3a0562b93c
Rollup merge of #118726 - dtolnay:matchguardlet, r=compiler-errors
Do not parenthesize exterior struct lit inside match guards

Before this PR, the AST pretty-printer injects parentheses around expressions any time parens _could_ be needed depending on what else is in the code that surrounds that expression. But the pretty-printer did not pass around enough context to understand whether parentheses really _are_ needed on any particular expression. As a consequence, there are false positives where unneeded parentheses are being inserted.

Example:

```rust
#![feature(if_let_guard)]

macro_rules! pp {
    ($e:expr) => {
        stringify!($e)
    };
}

fn main() {
    println!("{}", pp!(match () { () if let _ = Struct {} => {} }));
}
```

**Before:**

```console
match () { () if let _ = (Struct {}) => {} }
```

**After:**

```console
match () { () if let _ = Struct {} => {} }
```

This PR introduces a bit of state that is passed across various expression printing methods to help understand accurately whether particular situations require parentheses injected by the pretty printer, and it fixes one such false positive involving match guards as shown above.

There are other parenthesization false positive cases not fixed by this PR. I intend to address these in follow-up PRs. For example here is one: the expression `{ let _ = match x {} + 1; }` is pretty-printed as `{ let _ = (match x {}) + 1; }` despite there being no reason for parentheses to appear there.
2023-12-11 20:46:49 +01:00
Matthias Krüger 670ba478de
Rollup merge of #118620 - petrochenkov:defeed2, r=compiler-errors
resolve: Use `def_kind` query to cleanup some code

Follow up to https://github.com/rust-lang/rust/pull/118188.

Similar attempts to use queries in resolver resulted in perf regressions in the past, so this needs a perf run first.
2023-12-11 20:46:48 +01:00
Urgau b1bfeb1cdf Fix rustc codegen gcc tests 2023-12-11 18:48:49 +01:00
bors 57010939ed Auto merge of #118344 - saethlin:rmeta-header-pos, r=WaffleLapkin
Use a u64 for the rmeta root position

Waffle noticed this in https://github.com/rust-lang/rust/pull/117301#discussion_r1405410174

We've upgraded the other file offsets to u64, and this one only costs 4 bytes per file. Also the way the truncation was being done before was extremely easy to miss, I sure missed it! It's not clear to me if not having this change effectively made the other upgrades from u32 to u64 ineffective, but we can have it now.

r? `@WaffleLapkin`
2023-12-11 17:21:14 +00:00
bors 8a3765582c Auto merge of #117758 - Urgau:lint_pointer_trait_comparisons, r=davidtwco
Add lint against ambiguous wide pointer comparisons

This PR is the resolution of https://github.com/rust-lang/rust/issues/106447 decided in https://github.com/rust-lang/rust/issues/117717 by T-lang.

## `ambiguous_wide_pointer_comparisons`

*warn-by-default*

The `ambiguous_wide_pointer_comparisons` lint checks comparison of `*const/*mut ?Sized` as the operands.

### Example

```rust
let ab = (A, B);
let a = &ab.0 as *const dyn T;
let b = &ab.1 as *const dyn T;

let _ = a == b;
```

### Explanation

The comparison includes metadata which may not be expected.

-------

This PR also drops `clippy::vtable_address_comparisons` which is superseded by this one.

~~One thing: is the current naming right? `invalid` seems a bit too much.~~

Fixes https://github.com/rust-lang/rust/issues/117717
2023-12-11 14:33:16 +00:00
bors ff2c56344c Auto merge of #118823 - GuillaumeGomez:rollup-6v51gxv, r=GuillaumeGomez
Rollup of 3 pull requests

Successful merges:

 - #118802 (Remove edition umbrella features.)
 - #118807 (Remove an allocation in min_stack)
 - #118812 (rustdoc-search: do not treat associated type names as types)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-11 12:33:04 +00:00