Commit Graph

20235 Commits

Author SHA1 Message Date
Michael Goulet
61adaf8187 Combine projection and opaque into alias 2022-12-13 17:48:55 +00:00
Michael Goulet
c13bd83528 squash OpaqueTy and ProjectionTy into AliasTy 2022-12-13 17:40:27 +00:00
Michael Goulet
5c6afb850c ProjectionTy.item_def_id -> ProjectionTy.def_id 2022-12-13 17:34:44 +00:00
Michael Goulet
7f3af72606 Use ty::OpaqueTy everywhere 2022-12-13 17:29:26 +00:00
Michael Goulet
918ede6474 make Opaque have one field: OpaqueTy 2022-12-13 17:27:41 +00:00
Jacob Bramley
73d374f3e7 bug! if branch-protection makes it to non-AArch64 codegen. 2022-12-13 17:04:02 +00:00
akida31
757396f5fe
tidy: ignore filelength 2022-12-13 16:37:44 +01:00
akida31
f780faa8c4
reduce to single suggestion for all arguments 2022-12-13 16:30:04 +01:00
akida31
4d87fb5d11
remove manual fn_decl extraction 2022-12-13 16:29:13 +01:00
akida31
7822822d51
change error message 2022-12-13 16:29:10 +01:00
akida31
b1d7430657
move changes to an extra function 2022-12-13 16:28:34 +01:00
akida31
e326e8c885
Remove hint from help message 2022-12-13 16:28:31 +01:00
akida31
1e5d772417
Improve diagnostic when passing arg to closure and missing borrow.
This checks the number of references for the given and expected type and
shows hints to the user if the numbers don't match.
2022-12-13 16:24:38 +01:00
bors
ed620cf969 Auto merge of #105612 - oli-obk:bind_rustdoc, r=GuillaumeGomez
use ty::Binder in rustdoc instead of `skip_binder`

r? `@GuillaumeGomez`

this is a preliminary cleanup required to be able to normalize correctly/conveniently in rustdoc
2022-12-13 13:09:40 +00:00
Santiago Pastorino
b22769a7bd
Clarify explicit_predicates_of is_assoc_item_ty comment 2022-12-13 09:41:12 -03:00
Santiago Pastorino
4ae0c5518d
Make InternalSubsts rust docs a bit clearer 2022-12-13 09:28:25 -03:00
Jakob Degen
3522d48112 Don't require owned data in MaybeStorageLive 2022-12-13 04:22:47 -08:00
Oli Scherer
1f5cb9e50e Use a label instead of a note for the drop site to create denser diagnostics 2022-12-13 10:08:46 +00:00
Oli Scherer
6984085088 Stop pointing to operators if their libcore method source is not available 2022-12-13 10:06:11 +00:00
Oli Scherer
59554a2b54 Avoid rendering empty annotations 2022-12-13 10:06:08 +00:00
Oli Scherer
2e2a4797a2 Don't emit empty notes 2022-12-13 09:53:36 +00:00
Oli Scherer
063b1675b2 Clarify what "this" means 2022-12-13 09:51:03 +00:00
Oli Scherer
717294fa04 Inform the user which trait is meant in the diagnostic itself instead of relying on the span making it obvious 2022-12-13 09:48:26 +00:00
Oli Scherer
cb26b35b12 Make some diagnostics not depend on the source of what they reference being available 2022-12-13 09:48:22 +00:00
bors
109cccbe4f Auto merge of #105350 - compiler-errors:faster-binder-relate, r=oli-obk
Fast-path some binder relations

A simpler approach than #104598

Fixes #104583

r? types
2022-12-13 07:10:53 +00:00
Michael Goulet
a8a45100a0 Move some codegen-y methods from rustc_hir_analysis::collect -> rustc_codegen_ssa 2022-12-13 05:01:36 +00:00
Michael Goulet
f705d64673 Remove instantiate_type_scheme 2022-12-13 04:56:44 +00:00
Michael Goulet
5dea1d1c6e EarlyBinder nits 2022-12-13 04:53:36 +00:00
Cassaundra Smith
52a9280fb2
Refine when invalid prefix case error arises
Fix cases where the "invalid base prefix for number literal" error arises with
suffixes that look erroneously capitalized but which are in fact invalid.
2022-12-12 19:32:12 -08:00
bors
71ec1457ee Auto merge of #105436 - nnethercote:inline-place_contents_drop_state_cannot_differ, r=spastorino
Inline and remove `place_contents_drop_state_cannot_differ`.

It has a single call site and is hot enough to be worth inlining. And make sure `is_terminal_path` is inlined, too.

r? `@ghost`
2022-12-13 03:28:57 +00:00
Michael Goulet
2025a96ee1 Fast path some binder relations 2022-12-13 03:17:14 +00:00
Gary Guo
d6dc9124b7 Extract shared logic into a new function 2022-12-13 02:34:43 +00:00
Gary Guo
5c58a1b003 Remove unnecessary recursive call to parent unsafeck
All bodies are unsafe checked anyway. Current MIR unsafeck also just
returns for closures.
2022-12-13 01:38:38 +00:00
Gary Guo
adf1717219 Ensure valid local_data is set for custom mir building
MIR unsafety checking requires this to be valid
2022-12-13 01:38:38 +00:00
Gary Guo
aa5af2a003 Allow unsafe through inline const for THIR unsafety checker
The closure handling code is changed slightly to avoid allocation
when THIR building failed.
2022-12-13 01:38:38 +00:00
Gary Guo
9342d1e73e Allow unsafe through inline const
This is handled similar to closures
2022-12-13 01:38:38 +00:00
Matthias Krüger
2707801858
Rollup merge of #105625 - matthiaskrgr:clippy_dec12, r=compiler-errors
minor code cleanups

r? `@compiler-errors`
2022-12-13 01:17:10 +01:00
Matthias Krüger
4069792d73
Rollup merge of #105620 - TaKO8Ki:remove-unnecessary-uses-of-clone, r=compiler-errors
Remove unnecessary uses of `clone`
2022-12-13 01:17:10 +01:00
Matthias Krüger
8917cc0f23
Rollup merge of #105332 - estebank:iterator-chains, r=oli-obk
Point out the type of associated types in every method call of iterator chains

Partially address #105184 by pointing out the type of associated types in every method call of iterator chains:

```
note: the expression is of type `Map<std::slice::Iter<'_, {integer}>, [closure@src/test/ui/iterators/invalid-iterator-chain.rs:12:18: 12:21]>`
    --> src/test/ui/iterators/invalid-iterator-chain.rs:12:14
     |
10   |         vec![0, 1]
     |         ---------- this expression has type `Vec<{integer}>`
11   |             .iter()
     |              ------ associated type `std::iter::Iterator::Item` is `&{integer}` here
12   |             .map(|x| { x; })
     |              ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here
```

We also reduce the number of impls we mention when any of the candidates is an "exact match". This benefits the output of cases with numerics greatly.

Outstanding work would be to provide a structured suggestion for appropriate changes, like in this case detecting the spurious `;` in the closure.
2022-12-13 01:17:09 +01:00
Matthias Krüger
6dbaf86672
Rollup merge of #104864 - chenyukang:yukang/fix-104700-binding, r=estebank
Account for item-local in inner scope for E0425

Fixes #104700
2022-12-13 01:17:08 +01:00
Esteban Küber
f4ed2d1cca Do not skip_binders 2022-12-12 11:53:39 -08:00
Santiago Pastorino
b0c3228404
Join match arms since they do the same thing 2022-12-12 16:44:39 -03:00
Santiago Pastorino
893772025d
Fix typo 2022-12-12 16:43:38 -03:00
Matthias Krüger
2ea368e53c minor code cleanups 2022-12-12 19:49:53 +01:00
Matthias Krüger
666366444c
Rollup merge of #105615 - WaffleLapkin:remove_opt_scope_span_mention, r=compiler-errors
Fixup method doc that mentions removed param

The param was removed in https://github.com/rust-lang/rust/pull/61872 (101a2f59b4)
2022-12-12 19:20:36 +01:00
Matthias Krüger
c8b07c0529
Rollup merge of #105614 - lukas-code:ascription, r=Nilstrieb
delete mentions of type ascription from lint descriptions

Tracking Issue: https://github.com/rust-lang/rust/issues/101728
2022-12-12 19:20:36 +01:00
Matthias Krüger
38d97d3ea7
Rollup merge of #105593 - jruderman:patch-3, r=Dylan-DPC
Fix typo in comment: length_limit
2022-12-12 19:20:35 +01:00
Matthias Krüger
f4cca46078
Rollup merge of #105561 - TaKO8Ki:fix-105449, r=fee1-dead
Normalize receiver substs and erase the regions

Fixes #105449
2022-12-12 19:20:34 +01:00
Esteban Küber
348386985d Move logic to their own methods 2022-12-12 09:23:36 -08:00
Takayuki Maeda
ee40a67cd9 remove unnecessary uses of clone 2022-12-13 02:06:24 +09:00
Lukas Markeffsky
6abffffdff delete mentions of type ascription from lint descriptions
Move it to the historical context section instead.
2022-12-12 17:43:15 +01:00
Maybe Waffle
613c1216b7 Fixup method doc that mentions removed param 2022-12-12 15:43:04 +00:00
Oli Scherer
30754517d1 Avoid trying to normalize unnormalizable types 2022-12-12 14:39:08 +00:00
Boxy
dd19656df3 fold instead of obliterating args 2022-12-12 14:30:01 +00:00
Oli Scherer
21917b0866 Round 3: require binders for substs 2022-12-12 13:20:36 +00:00
Takayuki Maeda
3bc54baa61 normalize receiver substs and erase the regions
use a smaller example
2022-12-12 22:16:51 +09:00
Oli Scherer
dbf4b8a436 Round 1: add some binders (fails due to losing bound vars and then rebinding them with Binder::dummy) 2022-12-12 12:12:40 +00:00
bors
37d7de3379 Auto merge of #105252 - bjorn3:codegen_less_pair_values, r=nagisa
Use struct types during codegen in less places

This makes it easier to use cg_ssa from a backend like Cranelift that doesn't have any struct types at all. After this PR struct types are still used for function arguments and return values. Removing those usages is harder but should still be doable.
2022-12-12 10:38:31 +00:00
bors
2176e3a7a4 Auto merge of #105592 - matthiaskrgr:rollup-1cazogq, r=matthiaskrgr
Rollup of 2 pull requests

Successful merges:

 - #104997 (Move tests)
 - #105569 (`bug!` with a better error message for failing `Instance::resolve`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-12 07:57:41 +00:00
Matthias Krüger
5877a3fce1
Rollup merge of #105569 - compiler-errors:resolve-bug-better, r=TaKO8Ki
`bug!` with a better error message for failing `Instance::resolve`

Better ICE message when `.unwrap().unwrap()` fails.
2022-12-12 08:21:32 +01:00
Jesse Ruderman
c27d7949a1
Fix typo in comment: length_limit 2022-12-11 23:21:10 -08:00
bors
2cd2070af7 Auto merge of #105160 - nnethercote:rm-Lit-token_lit, r=petrochenkov
Remove `token::Lit` from `ast::MetaItemLit`.

Currently `ast::MetaItemLit` represents the literal kind twice. This PR removes that redundancy. Best reviewed one commit at a time.

r? `@petrochenkov`
2022-12-12 05:16:50 +00:00
Erik Desjardins
6085d33033 fix transmutes between pointers in different address spaces 2022-12-11 22:27:09 -05:00
bors
b397bc0727 Auto merge of #105485 - nnethercote:fix-lint-perf-regressions, r=cjgillot
Fix lint perf regressions

#104863 caused small but widespread regressions in lint performance. I tried to improve things in #105291 and #105416 with minimal success, before fully understanding what caused the regression. This PR effectively reverts all of #105291 and part of #104863 to fix the perf regression.

r? `@cjgillot`
2022-12-12 02:17:08 +00:00
Esteban Küber
2838b8e515 Point at method call when it is the source of the bound error 2022-12-11 14:49:50 -08:00
Matthias Krüger
79f99e7969
Rollup merge of #105555 - krasimirgg:llvm-int-opt-2, r=cuviper
llvm-wrapper: adapt for LLVM API changes

This is a follow-up of 75aec4703d. There, I updated the wrapper to only include llvm/ADT/Optional.h for LLVM version below 16. But I missed updating some of the None references.

Found by our experimental rust + llvm at HEAD bot: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/15587#0185006b-e0af-49e5-8b06-280ed125ff0d/200-539
2022-12-11 23:36:47 +01:00
Matthias Krüger
6042f5bca7
Rollup merge of #105521 - tshepang:keep-heading-separate, r=nagisa
separate heading from body
2022-12-11 23:36:46 +01:00
Matthias Krüger
6ed8cb6616
Rollup merge of #105472 - spastorino:make-encoder-use-queries, r=oli-obk
Make encode_info_for_trait_item use queries instead of accessing the HIR

This change avoids accessing the HIR on `encode_info_for_trait_item` and uses queries. We will need to execute this function for elements that have no HIR and by using queries we will be able to feed for definitions that have no HIR.

r? ``@oli-obk``
2022-12-11 23:36:46 +01:00
Matthias Krüger
4154e14f9a
Rollup merge of #105369 - chenyukang:yukang/fix-105226, r=TaKO8Ki
Detect spurious ; before assoc fn body

Fixes #105226

r? ``@TaKO8Ki``
2022-12-11 23:36:46 +01:00
Matthias Krüger
aa7b5b32e3
Rollup merge of #105283 - compiler-errors:ty-var-in-hir-wfcheck, r=nagisa
Don't call `diagnostic_hir_wf_check` query if we have infer variables

Fixes #105260
2022-12-11 23:36:45 +01:00
Nicholas Nethercote
4ff5a3655f Speed up the "builtin lints only" case.
This commit partly undoes #104863, which combined the builtin lints pass
with other lints. This caused a slowdown, because often there are no
other lints, and it's faster to do a pass with a single lint directly
than it is to do a combined pass with a `passes` vector containing a
single lint.
2022-12-12 08:59:27 +11:00
Nicholas Nethercote
3c53781800 Reinstate {Early,Late}LintPassObjects.
I removed these in #105291, and subsequently learned they are necessary
for performance.

This commit reinstates them with the new and more descriptive names
`RuntimeCombined{Early,Late}LintPass`, similar to the existing passes
like `BuiltinCombinedEarlyLintPass`. It also adds some comments,
particularly emphasising how we have ways to combine passes at both
compile-time and runtime. And it moves some comments around.
2022-12-12 08:59:27 +11:00
Nicholas Nethercote
2b05f84115 Rename run_early_passes as lint_callback.
This matches the name used in `late.rs`.
2022-12-12 08:59:27 +11:00
Michael Goulet
bc293ed53e bug! with a better error message for failing Instance::resolve 2022-12-11 19:48:24 +00:00
Esteban Küber
ce486d538b Use with_forced_trimmed_paths 2022-12-11 11:38:43 -08:00
Esteban Küber
78f97595a3 Only point at methods that might be relevant 2022-12-11 09:46:02 -08:00
Esteban Küber
aff0ab43c8 Add label to method chains where assoc type remains the same 2022-12-11 09:46:02 -08:00
Esteban Küber
c77ad2d765 Remove mention of "assoc type" in label as it is already in the note message 2022-12-11 09:46:02 -08:00
Esteban Küber
71db025cfa Account for method call chains split across multiple bindings 2022-12-11 09:46:02 -08:00
Esteban Küber
64bc975d27 Mention only assoc types changes 2022-12-11 09:46:01 -08:00
Michael Goulet
bc60d50eaa Provide associated type information in method chains
When encountering an unmet obligation that affects a method chain, like
in iterator chains where one of the links has the wrong associated
type, we point at every method call and mention their evaluated
associated type at that point to give context to the user of where
expectations diverged from the code as written.

```
note: the expression is of type `Map<std::slice::Iter<'_, {integer}>, [closure@$DIR/invalid-iterator-chain.rs:12:18: 12:21]>`
  --> $DIR/invalid-iterator-chain.rs:12:14
   |
LL |         vec![0, 1]
   |         ---------- this expression has type `Vec<{integer}>`
LL |             .iter()
   |              ------ associated type `std::iter::Iterator::Item` is `&{integer}` here
LL |             .map(|x| { x; })
   |              ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here
```
2022-12-11 09:46:01 -08:00
bors
d137783642 Auto merge of #102900 - abrachet:master, r=bjorn3
Don't internalize __llvm_profile_counter_bias

Currently, LLVM profiling runtime counter relocation cannot be used by rust during LTO because symbols are being internalized before all symbol information is known.

This mode makes LLVM emit a __llvm_profile_counter_bias symbol which is referenced by the profiling initialization, which itself is pulled in by the rust driver here [1].

It is enabled with -Cllvm-args=-runtime-counter-relocation for platforms which are opt-in to this mode like Linux. On these platforms there will be no link error, rather just surprising behavior for a user which request runtime counter relocation. The profiling runtime will not see that symbol go on as if it were never there. On Fuchsia, the profiling runtime must have this symbol which will cause a hard link error.

As an aside, I don't have enough context as to why rust's LTO model is how it is. AFAICT, the internalize pass is only safe to run at link time when all symbol information is actually known, this being an example as to why. I think special casing this symbol as a known one that LLVM can emit which should not have it's visbility de-escalated should be fine given how seldom this pattern of defining an undefined symbol to get initilization code pulled in is. From a quick grep, __llvm_profile_runtime is the only symbol that rustc does this for.

[1] 0265a3e93b/compiler/rustc_codegen_ssa/src/back/linker.rs (L598)
2022-12-11 14:42:45 +00:00
Krasimir Georgiev
cbdc00f6e6 llvm-wrapper: adapt for LLVM API changes
This is a follow-up of
75aec4703d.
There, I updated the wrapper to only include llvm/ADT/Optional.h for
LLVM version below 16. But I missed updating some of the None references.

Found by our experimental rust + llvm at HEAD bot:
https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/15587#0185006b-e0af-49e5-8b06-280ed125ff0d/200-539
2022-12-11 09:14:50 +00:00
Matthias Krüger
2daa3bcbc2
Rollup merge of #105537 - kadiwa4:remove_some_imports, r=fee1-dead
compiler: remove unnecessary imports and qualified paths

Some of these imports were necessary before Edition 2021, others were already in the prelude.

I hope it's fine that this PR is so spread-out across files :/
2022-12-11 09:51:57 +01:00
Matthias Krüger
cb4753135e
Rollup merge of #105411 - estebank:short-names, r=oli-obk
Introduce `with_forced_trimmed_paths`

Built on top of https://github.com/rust-lang/rust/pull/104922, only last commit is relevant.
2022-12-11 09:51:56 +01:00
Matthias Krüger
30db3a7d25
Rollup merge of #105542 - compiler-errors:confirm-nits, r=jackh726
Some method confirmation code nits

1. Make some pick methods take `&self` instead of `&mut` to avoid some cloning
2. Pass some values by reference to avoid some cloning
3. Rename a few variables here and there
2022-12-11 00:30:21 +01:00
Esteban Küber
3ad7131aa1 Introduce with_forced_trimmed_paths 2022-12-10 14:35:40 -08:00
Michael Goulet
11ad94d87a Some method confirmation code nits 2022-12-10 21:26:40 +00:00
bors
c6fcdb6906 Auto merge of #105416 - nnethercote:more-linting-tweaks, r=cjgillot
More linting tweaks

Squeeze a little more blood from this stone.

r? `@cjgillot`
2022-12-10 19:49:51 +00:00
KaDiWa
9bc69925cb
compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
Matthias Krüger
ab505298ea
Rollup merge of #105482 - wesleywiser:fix_debuginfo_ub, r=tmiasko
Fix invalid codegen during debuginfo lowering

In order for LLVM to correctly generate debuginfo for msvc, we sometimes need to spill arguments to the stack and perform some direct & indirect offsets into the value. Previously, this code always performed those actions, even when not required as LLVM would clean it up during optimization.

However, when MIR inlining is enabled, this can cause problems as the operations occur prior to the spilled value being initialized. To solve this, we first calculate the necessary offsets using just the type which is side-effect free and does not alter the LLVM IR. Then, if we are in a situation which requires us to generate the LLVM IR (and this situation only occurs for arguments, not local variables) then we perform the same calculation again, this time generating the appropriate LLVM IR as we go.

r? `@tmiasko` but feel free to reassign if you want 🙂

Fixes #105386
2022-12-10 15:01:45 +01:00
Matthias Krüger
62160cba7b
Rollup merge of #105410 - TaKO8Ki:fix-105257, r=BoxyUwU
Consider `parent_count` for const param defaults

Fixes #105257
2022-12-10 15:01:44 +01:00
Matthias Krüger
b66e123677
Rollup merge of #105234 - JakobDegen:unneeded-field, r=oli-obk
Remove unneeded field from `SwitchTargets`

This had a fixme already. The only change in behavior is that the mir dumps now no longer contains labels for the types of the integers on the edges of a switchint:

Before:
![image](https://user-images.githubusercontent.com/51179609/205467622-34401a68-dca6-43eb-915e-b9fda1988860.png)

After:
![image](https://user-images.githubusercontent.com/51179609/205467634-b5b2a259-9cb4-4843-845c-592c500f0f9c.png)

I don't think that's a problem though. The information is still available to a user that really cares by checking the type of `_2`, so it honestly feels like a bit of an improvement to me.

r? mir
2022-12-10 15:01:43 +01:00
Matthias Krüger
7e1857db1e
Rollup merge of #105192 - estebank:point-at-lhs-on-binop, r=fee1-dead
Point at LHS on binop type err if relevant
2022-12-10 15:01:43 +01:00
Matthias Krüger
3b7a1593f5
Rollup merge of #104460 - Nilstrieb:expand-the-translation, r=davidtwco
Migrate parts of `rustc_expand` to session diagnostics

This migrates everything but the `mbe` and `proc_macro` modules. It also contains a few cleanups and drive-by/accidental diagnostic improvements which can be seen in the diff for the UI tests.
2022-12-10 15:01:42 +01:00
bors
b12b83674f Auto merge of #105525 - matthiaskrgr:rollup-ricyw5s, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #98391 (Reimplement std's thread parker on top of events on SGX)
 - #104019 (Compute generator sizes with `-Zprint_type_sizes`)
 - #104512 (Set `download-ci-llvm = "if-available"` by default when `channel = dev`)
 - #104901 (Implement masking in FileType comparison on Unix)
 - #105082 (Fix Async Generator ABI)
 - #105109 (Add LLVM KCFI support to the Rust compiler)
 - #105505 (Don't warn about unused parens when they are used by yeet expr)
 - #105514 (Introduce `Span::is_visible`)
 - #105516 (Update cargo)
 - #105522 (Remove wrong note for short circuiting operators)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-10 11:16:18 +00:00
nils
2f9f097cb8 Migrate parts of rustc_expand to session diagnostics
This migrates everything but the `mbe` and `proc_macro` modules. It also
contains a few cleanups and drive-by/accidental diagnostic improvements
which can be seen in the diff for the UI tests.
2022-12-10 11:02:41 +01:00
Matthias Krüger
cf840069f3
Rollup merge of #105514 - estebank:is_visible, r=oli-obk
Introduce `Span::is_visible`

r? `@oli-obk`
2022-12-10 09:24:44 +01:00
Matthias Krüger
9e87dd907e
Rollup merge of #105505 - WaffleLapkin:yeet_unused_parens_lint, r=fee1-dead
Don't warn about unused parens when they are used by yeet expr

Don't even get me started on how I've found this.
2022-12-10 09:24:44 +01:00
Matthias Krüger
947fe7e341
Rollup merge of #105109 - rcvalle:rust-kcfi, r=bjorn3
Add LLVM KCFI support to the Rust compiler

This PR adds LLVM Kernel Control Flow Integrity (KCFI) support to the Rust compiler. It initially provides forward-edge control flow protection for operating systems kernels for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. (See llvm/llvm-project@cff5bef.)

Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue #89653).

LLVM KCFI can be enabled with -Zsanitizer=kcfi.

Thank you again, `@bjorn3,` `@eddyb,` `@nagisa,` and `@ojeda,` for all the help!
2022-12-10 09:24:43 +01:00
Matthias Krüger
020d7af949
Rollup merge of #105082 - Swatinem:async-abi, r=compiler-errors
Fix Async Generator ABI

This change was missed when making async generators implement `Future` directly.
It did not cause any problems in codegen so far, as `GeneratorState<(), Output>`
happens to have the same ABI as `Poll<Output>`.
2022-12-10 09:24:43 +01:00
Matthias Krüger
0f5d3ba30f
Rollup merge of #104019 - compiler-errors:print-generator-sizes, r=wesleywiser
Compute generator sizes with `-Zprint_type_sizes`

Fixes #103887
r? `@pnkfelix`
2022-12-10 09:24:41 +01:00
bors
cbc70ff277 Auto merge of #105357 - oli-obk:feeding, r=cjgillot,petrochenkov
Group some fields in a common struct so we only pass one reference instead of three

r? `@cjgillot`
2022-12-10 08:23:16 +00:00
bors
a000811405 Auto merge of #105512 - matthiaskrgr:rollup-i74avrf, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #102406 (Make `missing_copy_implementations` more cautious)
 - #105265 (Add `rustc_on_unimplemented` to `Sum` and `Product` trait.)
 - #105385 (Skip test on s390x as LLD does not support the platform)
 - #105453 (Make `VecDeque::from_iter` O(1) from `vec(_deque)::IntoIter`)
 - #105468 (Mangle "main" as "__main_void" on wasm32-wasi)
 - #105480 (rustdoc: remove no-op mobile CSS `#sidebar-toggle { text-align }`)
 - #105489 (Fix typo in apple_base.rs)
 - #105504 (rustdoc: make stability badge CSS more consistent)
 - #105506 (Tweak `rustc_must_implement_one_of` diagnostic output)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-10 05:32:44 +00:00
yukang
b70a869d8f fix #105366, suggest impl in the scenario of typo with fn 2022-12-10 11:01:52 +08:00
Tshepang Mbambo
6a43946370 separate heading from body 2022-12-10 04:48:37 +02:00
Esteban Küber
b9da55afb5 Introduce Span::is_visible 2022-12-09 14:35:55 -08:00
Matthias Krüger
376b0bce36
Rollup merge of #105506 - estebank:rustc_must_implement_one_of, r=compiler-errors
Tweak `rustc_must_implement_one_of` diagnostic output
2022-12-09 22:31:59 +01:00
Matthias Krüger
f78babd6c4
Rollup merge of #105489 - eltociear:patch-17, r=Dylan-DPC
Fix typo in apple_base.rs

erronous -> erroneous
2022-12-09 22:31:58 +01:00
Matthias Krüger
320d018268
Rollup merge of #105468 - sunfishcode:sunfishcode/main-void-wasi, r=estebank
Mangle "main" as "__main_void" on wasm32-wasi

On wasm, the age-old C trick of having a main function which can either have no arguments or argc+argv doesn't work, because wasm requires caller and callee signatures to match. WASI's current strategy is to have compilers mangle main's name to indicate which signature they're using. Rust uses the no-argument form, which should be mangled as `__main_void`.

This is needed on wasm32-wasi as of #105395.
2022-12-09 22:31:57 +01:00
Matthias Krüger
4fae5891d0
Rollup merge of #102406 - mejrs:missing_copy, r=wesleywiser
Make `missing_copy_implementations` more cautious

- Fixes https://github.com/rust-lang/rust/issues/98348
- Also makes the lint not fire on large types and types containing raw pointers. Thoughts?
2022-12-09 22:31:54 +01:00
bors
0d5573e6da Auto merge of #105363 - WaffleLapkin:thin2win_box_next_argument, r=nnethercote
Shrink `rustc_parse_format::Piece`

This makes both variants closer together in size (previously they were different by 208 bytes -- 16 vs 224). This may make things worse, but it's worth a try.

r? `@nnethercote`
2022-12-09 21:27:35 +00:00
Esteban Küber
b3b17bde31 Tweak rustc_must_implement_one_of diagnostic output 2022-12-09 10:44:11 -08:00
Maybe Waffle
84a46352ac Don't warn about unused parens when they are used by yeet expr 2022-12-09 18:32:06 +00:00
Oli Scherer
75ff5c7dd3 Fold Definitions into the untracked data 2022-12-09 14:59:39 +00:00
Oli Scherer
1c1d3570ee Move the untracked cstore and source_span into a struct 2022-12-09 14:53:24 +00:00
Oli Scherer
2cd36f2c89 Generate crate loaders on the fly 2022-12-09 14:53:23 +00:00
Oli Scherer
4b08fbaea8 ResolverTree does not require access to the crate loader, only the store 2022-12-09 14:50:09 +00:00
Jakob Degen
9fb8da8f8f Remove unneeded field from SwitchTargets 2022-12-09 04:53:10 -08:00
Maybe Waffle
7e79c575e9 Help rust-analyzer normalize query return types 2022-12-09 12:26:01 +00:00
bors
e10201c9bb Auto merge of #104572 - pkubaj:patch-1, r=cuviper
Fix build on powerpc-unknown-freebsd

Probably also fixes build on arm and mips*. Related to https://github.com/rust-lang/rust/issues/104220
2022-12-09 12:00:58 +00:00
Robin Schroer
40ba1c902f
Illegal sized bounds: only suggest mutability change if needed
In a scenario like

```
struct Type;

pub trait Trait {
    fn function(&mut self)
    where
        Self: Sized;
}

impl Trait for Type {
    fn function(&mut self) {}
}

fn main() {
    (&mut Type as &mut dyn Trait).function();
}
```

the problem is Sized, not the mutability of self. Thus don't emit the
"you need &T instead of &mut T" note, or the other way around, as all
it does is just invert the mutability of whatever was supplied.

Fixes #103622.
2022-12-09 12:15:51 +01:00
bors
14ca83a04b Auto merge of #105486 - matthiaskrgr:rollup-o7c4l1c, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #105216 (Remove unused GUI test)
 - #105245 (attempt to clarify align_to docs)
 - #105387 (Improve Rustdoc scrape-examples UI)
 - #105389 (Enable profiler in dist-powerpc64le-linux)
 - #105427 (Dont silently ignore rustdoc errors)
 - #105442 (rustdoc: clean up docblock table CSS)
 - #105443 (Move some queries and methods)
 - #105455 (use the correct `Reveal` during validation)
 - #105470 (Clippy: backport ICE fix before beta branch)
 - #105474 (lib docs: fix typo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-09 09:19:26 +00:00
Ikko Ashimine
f41576bd3d
Fix typo in apple_base.rs
erronous -> erroneous
2022-12-09 18:09:32 +09:00
Matthias Krüger
04dac4285a
Rollup merge of #105455 - lcnr:correct-reveal-in-validate, r=jackh726
use the correct `Reveal` during validation

supersedes #105454. Deals with https://github.com/rust-lang/rust/issues/105009#issuecomment-1342395333, not closing #105009 as the ICE may leak into beta

The issue was the following:
- we optimize the mir, using `Reveal::All`
- some optimization relies on the hidden type of an opaque type
- we then validate using `Reveal::UserFacing` again which is not able to observe the hidden type

r? `@jackh726`
2022-12-09 07:25:47 +01:00
Matthias Krüger
6111a7345b
Rollup merge of #105443 - compiler-errors:move-more, r=oli-obk
Move some queries and methods

Each commit's title should be self-explanatory. Motivated to break up some large, general files and move queries into leaf crates.
2022-12-09 07:25:46 +01:00
bors
badd6a5a03 Auto merge of #104449 - oli-obk:unhide_unknown_spans, r=estebank,RalfJung
Start emitting labels even if their pointed to file is not available locally

r? `@estebank`

cc `@RalfJung`

fixes #97699
2022-12-09 06:24:28 +00:00
Wesley Wiser
7253057887 Don't generate pointer loads to spills unless necessary
In order for LLVM to correctly generate debuginfo for msvc, we sometimes
need to spill arguments to the stack and perform some direct & indirect
offsets into the value. Previously, this code always performed those
actions, even when not required as LLVM would clean it up during
optimization.

However, when MIR inlining is enabled, this can cause problems as the
operations occur prior to the spilled value being initialized. To solve
this, we first calculate the necessary offsets using just the type which
is side-effect free and does not alter the LLVM IR. Then, if we are in a
situation which requires us to generate the LLVM IR (and this situation
only occurs for arguments, not local variables) then we perform the same
calculation again, this time generating the appropriate LLVM IR as we
go.
2022-12-08 20:38:23 -05:00
Wesley Wiser
b33d1e26b2 Make debuginfo_offset_calcuation generic so we can resuse the logic
This will allow us to separate the act of calculating the offsets from
creating LLVM IR that performs the actions.
2022-12-08 20:38:23 -05:00
Wesley Wiser
525d0dd6e2 Factor out debuginfo offset calculation 2022-12-08 20:38:23 -05:00
Ramon de C Valle
65698ae9f3 Add LLVM KCFI support to the Rust compiler
This commit adds LLVM Kernel Control Flow Integrity (KCFI) support to
the Rust compiler. It initially provides forward-edge control flow
protection for operating systems kernels for Rust-compiled code only by
aggregating function pointers in groups identified by their return and
parameter types. (See llvm/llvm-project@cff5bef.)

Forward-edge control flow protection for C or C++ and Rust -compiled
code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code
share the same virtual address space) will be provided in later work as
part of this project by identifying C char and integer type uses at the
time types are encoded (see Type metadata in the design document in the
tracking issue #89653).

LLVM KCFI can be enabled with -Zsanitizer=kcfi.

Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2022-12-08 17:24:39 -08:00
pkubaj
32c777e891 Fix build on powerpc-unknown-freebsd
Probably also fixes build on mips*. Related to https://github.com/rust-lang/rust/issues/104220
2022-12-09 02:11:15 +01:00
Esteban Küber
132a140214 Point at LHS on binop type err if relevant 2022-12-08 15:30:57 -08:00
Maybe Waffle
c44c82de2b Assert size of rustc_parse_format::Piece<'_> 2022-12-08 22:50:39 +00:00
Arpad Borsos
ecf812777a
Fix Async Generator ABI
This change was missed when making async generators implement `Future` directly.
It did not cause any problems in codegen so far, as `GeneratorState<(), Output>`
happens to have the same ABI as `Poll<Output>`.
2022-12-08 23:27:57 +01:00
Dan Gohman
98ae83daae Mangle "main" as "__main_void" on wasm32-wasi
On wasm, the age-old C trick of having a main function which can either have
no arguments or argc+argv doesn't work, because wasm requires caller and
callee signatures to match. WASI's current strategy is to have compilers
mangle main's name to indicate which signature they're using. Rust uses the
no-argument form, which should be mangled as `__main_void`.

This is needed on wasm32-wasi as of #105395.
2022-12-08 13:15:40 -08:00
Gary Guo
6275b045d7 Move paren expr and loop HIR lowering 2022-12-08 17:28:21 +00:00
Gary Guo
0c0fb226bb Support #[track_caller] on async closures 2022-12-08 17:23:44 +00:00
Santiago Pastorino
99d229095e
Make encode_info_for_trait_item use queries instead of accessing the HIR 2022-12-08 11:58:14 -03:00
Matthias Krüger
660795eee5
Rollup merge of #105441 - nnethercote:rm-UnsafetyState, r=lcnr
Remove `UnsafetyState`

r? `@lcnr`
2022-12-08 12:57:33 +01:00
Matthias Krüger
fbfc5ada02
Rollup merge of #105423 - oli-obk:symbols, r=jackh726
Use `Symbol` for the crate name instead of `String`/`str`

It always got converted to a symbol anyway
2022-12-08 12:57:32 +01:00
Matthias Krüger
2fbde2b028
Rollup merge of #105408 - cuviper:help-rpitirpit, r=compiler-errors
Add help for `#![feature(impl_trait_in_fn_trait_return)]`

This adds a new variant `ImplTraitContext::FeatureGated`, so we can
generalize the help for `return_position_impl_trait_in_trait` to also
work for `impl_trait_in_fn_trait_return`.

cc #99697
2022-12-08 12:57:31 +01:00
Matthias Krüger
4d5a2f3d81
Rollup merge of #105405 - sunfishcode:sunfishcode/export-dynamic, r=TaKO8Ki
Stop passing -export-dynamic to wasm-ld.

-export-dynamic was a temporary hack added in the early days of the Rust wasm32 target when Rust didn't have a way to specify wasm exports in the source code. This flag causes all global symbols, and some compiler-internal symbols, to be exported, which is often more than needed.

Rust now does have a way to specify exports in the source code: `#[export_name = "..."]`.

So as the original comment suggests, -export-dynamic can now be removed, allowing users to have smaller binaries and better encapsulation in their wasm32-unknown-unknown modules.

It's possible that this change will require existing wasm32-unknown-unknown users will to add explicit `#[export_name = "..."]` directives to exporrt the symbols that their programs depend on having exported.
2022-12-08 12:57:30 +01:00
Matthias Krüger
f1f7560598
Rollup merge of #105317 - RalfJung:retag-rework, r=oli-obk
make retagging work even with 'unstable' places

This is based on top of https://github.com/rust-lang/rust/pull/105301. Only the last two commits are new.

While investigating https://github.com/rust-lang/unsafe-code-guidelines/issues/381 I realized that we would have caught this issue much earlier if the add_retag pass wouldn't bail out on assignments of the form `*ptr = ...`.

So this PR changes our retag strategy:
- When a new reference is created via `Rvalue::Ref` (or a raw ptr via `Rvalue::AddressOf`), we do the retagging as part of just executing that address-taking operation.
- For everything else, we still insert retags -- these retags basically serve to ensure that references stored in local variables (and their fields) are always freshly tagged, so skipping this for assignments like `*ptr = ...` is less egregious.
r? ```@oli-obk```
2022-12-08 12:57:30 +01:00
Matthias Krüger
e826a9acb4
Rollup merge of #105255 - cjgillot:issue-105197, r=compiler-errors
Make nested RPIT inherit the parent opaque's generics.

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

r? ```@compiler-errors```
2022-12-08 12:57:29 +01:00
Matthias Krüger
086bdbbd73
Rollup merge of #104922 - estebank:fur-elize, r=oli-obk
Detect long types in E0308 and write them to disk

On type error with long types, print an abridged type and write the full type to disk.

Print the widest possible short type while still fitting in the terminal.
2022-12-08 12:57:28 +01:00
lcnr
dd9d05cec4 validate: use the correct reveal during opts 2022-12-08 11:24:25 +01:00
Erik Desjardins
a99e97af97 Add 0..=isize::MAX range metadata to size loads from vtables 2022-12-08 01:30:07 -05:00
Michael Goulet
3b9daac6a2 Move some suggestions from error_reporting to error_reporting::suggest 2022-12-08 05:58:30 +00:00
Michael Goulet
25a6daccab Move codegen_select_candidate to a rustc_traits 2022-12-08 05:16:57 +00:00
Michael Goulet
b36035c20f Move vtable methods into its own module 2022-12-08 05:16:57 +00:00
Michael Goulet
48270044b0 Move has_structural_eq_impls provider to rustc_ty_utils 2022-12-08 05:16:48 +00:00
Takayuki Maeda
85d7d9b6b7 add a test case for generic_const_exprs in trait items 2022-12-08 14:11:29 +09:00
Michael Goulet
7d23e29f9f Pull out logic into distinct functions 2022-12-08 04:59:10 +00:00
Nicholas Nethercote
9af48e5ab6 Fix a typo. 2022-12-08 15:53:31 +11:00
Nicholas Nethercote
7a4669285a Remove UnsafetyState.
`FnCtxt::ps` is the only occurrence. It gets updated during HIR
typechecking, but is never looked at.
2022-12-08 15:42:57 +11:00
Nicholas Nethercote
68a19209e0 Inline and remove place_contents_drop_state_cannot_differ.
It has a single call site and is hot enough to be worth inlining. And
make sure `is_terminal_path` is inlined, too.
2022-12-08 13:59:29 +11:00
Oli Scherer
d30848b30a Use Symbol for the crate name instead of String/str 2022-12-07 20:30:02 +00:00
Michael Goulet
57b722688d Properly print generator interior type sizes 2022-12-07 18:33:26 +00:00
Michael Goulet
b0dcadfc45 Move closure/generator type info methods to TyCtxt 2022-12-07 17:00:33 +00:00
Alex Brachet
5d88d36053 Don't internalize __llvm_profile_counter_bias
Currently, LLVM profiling runtime counter relocation cannot be
used by rust during LTO because symbols are being internalized
before all symbol information is known.

This mode makes LLVM emit a __llvm_profile_counter_bias symbol
which is referenced by the profiling initialization, which itself
is pulled in by the rust driver here [1].

It is enabled with -Cllvm-args=-runtime-counter-relocation for
platforms which are opt-in to this mode like Linux. On these
platforms there will be no link error, rather just surprising
behavior for a user which request runtime counter relocation.
The profiling runtime will not see that symbol go on as if it
were never there. On Fuchsia, the profiling runtime must have
this symbol which will cause a hard link error.

As an aside, I don't have enough context as to why rust's LTO
model is how it is. AFAICT, the internalize pass is only safe
to run at link time when all symbol information is actually
known, this being an example as to why. I think special casing
this symbol as a known one that LLVM can emit which should not
have it's visbility de-escalated should be fine given how
seldom this pattern of defining an undefined symbol to get
initilization code pulled in is. From a quick grep,
__llvm_profile_runtime is the only symbol that rustc does this
for.

[1] 0265a3e93b/compiler/rustc_codegen_ssa/src/back/linker.rs (L598)
2022-12-07 16:32:59 +00:00
Matthias Krüger
4968af0ee8
Rollup merge of #105418 - BelovDV:fix-libc-hack, r=petrochenkov
fix: remove hack from link.rs

This logic implemented in libc.

r? `@petrochenkov`
2022-12-07 15:39:09 +01:00
Matthias Krüger
b23419b03d
Rollup merge of #105400 - BoxyUwU:braced_param_evaluatability, r=oli-obk
normalize before handling simple checks for evaluatability of `ty::Const`

`{{{{{{{ N }}}}}}}` is desugared into a `ConstKind::Unevaluated` for an anonymous `const` item so when calling `is_const_evaluatable` on it we skip the `ConstKind::Param(_) => Ok(())` arm which is incorrect.
2022-12-07 15:39:08 +01:00
Matthias Krüger
52cec8c99f
Rollup merge of #105368 - WaffleLapkin:deref-even-harder, r=TaKO8Ki
Remove more `ref` patterns from the compiler

Previous PR: #105045
2022-12-07 15:39:07 +01:00
Matthias Krüger
95da525982
Rollup merge of #105343 - nbdd0121:hir, r=fee1-dead
Simplify attribute handling in rustc_ast_lowering

Given that attributes is stored in a separate BTreeMap, it's not necessary to pass it in when constructing `hir::Expr`. We can just construct `hir::Expr` and then call `self.lower_attrs` later if it needs attributes.

As most desugaring code don't use attributes, this allows some code cleanup.
2022-12-07 15:39:07 +01:00
Matthias Krüger
3bcfa4c459
Rollup merge of #105267 - compiler-errors:issue-104613, r=oli-obk
Don't ICE in ExprUseVisitor on FRU for non-existent struct

Fixes #104613
Fixes #105202
2022-12-07 15:39:06 +01:00
bors
91b8f34ac2 Auto merge of #104799 - pcc:linkage-fn, r=tmiasko
Support Option and similar enums as type of static variable with linkage attribute

Compiler MCP:
rust-lang/compiler-team#565
2022-12-07 10:24:59 +00:00
Daniil Belov
a9cf163c08 fix: remove hack from link.rs (moved to libc) 2022-12-07 13:13:58 +03:00
Nicholas Nethercote
d049be30cf Split EarlyContextAndPasses::check_id in two. 2022-12-07 19:29:31 +11:00
Nicholas Nethercote
b08fd6e8ef Inline some hot lint pass functions.
These each have a single call site, due to being called from a
"combined" lint pass.
2022-12-07 19:29:31 +11:00
Nicholas Nethercote
ec117c0ebd Rename $passes as $pass in several macros.
Because it makes more sense that way.
2022-12-07 19:29:31 +11:00
Nicholas Nethercote
ac1e69c903 Add some useful comments. 2022-12-07 19:29:31 +11:00
Nicholas Nethercote
0c844730d3 Remove $hir argument from late_lint_methods!.
Because it's always `'tcx`.
2022-12-07 19:29:26 +11:00
yukang
5599f2ad09 fix #105226, Detect spurious ; before assoc fn body 2022-12-07 16:13:39 +08:00
Takayuki Maeda
cb596e3015 consider parent_count for const param defaults 2022-12-07 12:55:30 +09:00
bors
e491d2b24d Auto merge of #105291 - nnethercote:remove-LintPassObjects, r=cjgillot
Remove `{Early,Late}LintPassObjects`.

`EarlyContextAndPass` wraps a single early lint pass. We aggregate multiple passes into that single pass by using `EarlyLintPassObjects`.

This commit removes `EarlyLintPassObjects` by changing `EarlyContextAndPass` into `EarlyContextAndPasses`. I.e. it just removes a level of indirection. This makes the code simpler and slightly faster.

The commit does likewise for late lints.

r? `@cjgillot`
2022-12-07 03:52:19 +00:00
Michael Goulet
b45b9489bb Compute generator sizes with -Zprint_type_sizes 2022-12-07 03:10:56 +00:00
Josh Stone
e9dd59131b Add help for #![feature(impl_trait_in_fn_trait_return)]
This adds a new variant `ImplTraitContext::FeatureGated`, so we can
generalize the help for `return_position_impl_trait_in_trait` to also
work for `impl_trait_in_fn_trait_return`.
2022-12-06 17:53:50 -08:00
Dan Gohman
3a07aa9b5e Stop passing -export-dynamic to wasm-ld.
-export-dynamic was a temporary hack added in the early days of the Rust
wasm32 target when Rust didn't have a way to specify wasm exports in the
source code. This flag causes all global symbols, and some compiler-internal
symbols, to be exported, which is often more than needed.

Rust now does have a way to specify exports in the source code:
`#[export_name = "..."]`.

So as the original comment suggests, -export-dynamic can now be removed,
allowing users to have smaller binaries and better encapsulation in
their wasm32-unknown-unknown modules.

It's possible that this change will require existing wasm32-unknown-unknown
users will to add explicit `#[export_name = "..."]` directives to
exporrt the symbols that their programs depend on having exported.
2022-12-06 16:50:29 -08:00
Boxy
9f438bef0b normalize before matching on ConstKind 2022-12-06 22:53:13 +00:00
Matthias Krüger
280501d6bc
Rollup merge of #105382 - BoxyUwU:fixme_typo_sadface, r=lcnr
remove an excess `this`
2022-12-06 23:13:51 +01:00
Matthias Krüger
e434f613fd
Rollup merge of #105298 - krasimirgg:llvm-16-dec-1, r=cuviper
llvm-wrapper: adapt for an LLVM API change

Adapts llvm-wrapper for 8c7c20f033.
No functional changes intended.

Found via our experimental rust + llvm @ HEAD bot: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/15404#0184d95d-5a68-4db6-ad32-51ddbc3ab543/202-571
2022-12-06 23:13:49 +01:00
Oli Scherer
f89d6236aa Properly indent messages 2022-12-06 18:59:46 +00:00
Oli Scherer
99348a5330 Change CTFE backtraces to use note instead of label to preserve their order
labels are reordered within the file in which they are reported, which can mess up the stack trace
2022-12-06 18:59:46 +00:00
Oli Scherer
7782a2b70d Remove now-redundant file/line info from const backtraces 2022-12-06 18:59:46 +00:00
Oli Scherer
10b75cbbb0 Start emitting labels even if their pointed to file is not available locally 2022-12-06 18:59:46 +00:00
Oli Scherer
19d7dceed3 remove an unnecessary ? 2022-12-06 18:59:45 +00:00
Oli Scherer
9eb9176b08 Simplify span fallback 2022-12-06 18:59:45 +00:00
Oli Scherer
b9bf119c4f Simplify some nested conditions 2022-12-06 18:59:45 +00:00
bors
b28d30e1e3 Auto merge of #105378 - matthiaskrgr:rollup-fjeorw5, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #104898 (Put all cached values into a central struct instead of just the stable hash)
 - #105004 (Fix `emit_unused_delims_expr` ICE)
 - #105174 (Suggest removing struct field from destructive binding only in shorthand scenario)
 - #105250 (Replace usage of `ResumeTy` in async lowering with `Context`)
 - #105286 (Add -Z maximal-hir-to-mir-coverage flag)
 - #105320 (rustdoc: simplify CSS selectors on top-doc and non-exhaustive toggles)
 - #105349 (Point at args in associated const fn pointers)
 - #105362 (Cleanup macro-expanded code in `rustc_type_ir`)
 - #105370 (Remove outdated syntax from trait alias pretty printing)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-06 18:51:14 +00:00
Krasimir Georgiev
75aec4703d llvm-wrapper: adapt for and LLVM API change 2022-12-06 18:25:33 +00:00
Boxy
0070fae2dc typo :( 2022-12-06 16:40:57 +00:00
Matthias Krüger
97008a23fc
Rollup merge of #105370 - WaffleLapkin:pp, r=oli-obk
Remove outdated syntax from trait alias pretty printing

Given the following program:
```rust
#![feature(trait_alias)]
trait A = ?Sized;

fn main() {}
```
Old output of `rustc +nightly ./t.rs -Zunpretty=normal`:
```rust
#![feature(trait_alias)]
trait A for ? Sized ;

fn main() {}
```
New output of `rustc +a ./t.rs -Zunpretty=normal`:
```rust
#![feature(trait_alias)]
trait A = ?Sized;

fn main() {}
```

cc `@durka` (you've written the `FIXME` in #45047, see https://github.com/rust-lang/rust/pull/45047#discussion_r144960751)
2022-12-06 16:54:57 +01:00
Matthias Krüger
4f527a55de
Rollup merge of #105362 - WaffleLapkin:🙅, r=oli-obk
Cleanup macro-expanded code in `rustc_type_ir`

We could of course just leave this as-is, but every time I go-to-def to this file it's painful to see all this `(&A(ref __self_1_0),)` stuff.
2022-12-06 16:54:56 +01:00
Matthias Krüger
4f919e4628
Rollup merge of #105349 - compiler-errors:point-at-assoc-ct-fn-ptr-arg, r=cjgillot
Point at args in associated const fn pointers

Tiny follow-up to #105201, not so sure it's worth it but 🤷

The UI test example is a bit more compelling when it's `GlUniformScalar::FACTORY`

r? `@cjgillot`
2022-12-06 16:54:56 +01:00
Matthias Krüger
c699b05306
Rollup merge of #105286 - willcrichton:maximal-hir-to-mir-coverage, r=cjgillot
Add -Z maximal-hir-to-mir-coverage flag

This PR adds a new unstable flag `-Z maximal-hir-to-mir-coverage` that changes the behavior of `maybe_lint_level_root_bounded`, pursuant to [a discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Mapping.20MIR.20to.20HIR). When enabled, this function will not search upwards for a lint root, but rather immediately return the provided HIR node ID. This change increases the granularity of the mapping between MIR locations and HIR nodes inside the `SourceScopeLocalData` data structures. This increase in granularity is useful for rustc consumers like [Flowistry](https://github.com/willcrichton/flowistry) that rely on getting source-mapping information about the MIR CFG that is as precise as possible.

A test `maximal_mir_to_hir_coverage.rs` has been added to verify that this flag does not break anything.

r? `@cjgillot`

cc `@gavinleroy`
2022-12-06 16:54:55 +01:00
Matthias Krüger
967085ecdf
Rollup merge of #105250 - Swatinem:async-rm-resumety, r=oli-obk
Replace usage of `ResumeTy` in async lowering with `Context`

Replaces using `ResumeTy` / `get_context` in favor of using `&'static mut Context<'_>`.

Usage of the `'static` lifetime here is technically "cheating", and replaces the raw pointer in `ResumeTy` and the `get_context` fn that pulls the correct lifetimes out of thin air.

fixes https://github.com/rust-lang/rust/issues/104828 and https://github.com/rust-lang/rust/pull/104321#issuecomment-1336363077

r? `@oli-obk`
2022-12-06 16:54:54 +01:00
Matthias Krüger
90d84ce3a2
Rollup merge of #105174 - chenyukang:yukang/fix-105028-unused, r=eholk
Suggest removing struct field from destructive binding only in shorthand scenario

Fixes #105028
2022-12-06 16:54:53 +01:00
Matthias Krüger
b29a4f9bac
Rollup merge of #105004 - TaKO8Ki:fix-104897, r=wesleywiser
Fix `emit_unused_delims_expr` ICE

Fixes #104897

This is also related to #104433.
2022-12-06 16:54:53 +01:00
Matthias Krüger
db416ea195
Rollup merge of #104898 - oli-obk:group_all_the_things, r=wesleywiser
Put all cached values into a central struct instead of just the stable hash

cc `@nnethercote`

this allows re-use of the type for Predicate without duplicating all the logic for the non-hash cached fields
2022-12-06 16:54:52 +01:00
Jacob Bramley
49f3c0b736 Check AArch64 branch-protection earlier in the pipeline.
As suggested in #93516.
2022-12-06 15:51:57 +00:00
bors
e60fbaf4ce Auto merge of #105229 - saethlin:zst-writes-to-unions, r=oli-obk
Re-enable removal of ZST writes to unions

This was previously disabled because Miri was lazily allocating unsized locals. But we aren't doing that anymore since  https://github.com/rust-lang/rust/pull/98831, so we can have this optimization back.
2022-12-06 15:35:55 +00:00
Maybe Waffle
700c095306 rustc_builtin_macros: remove ref patterns
... and other pattern matching improvements
2022-12-06 14:45:58 +00:00
Maybe Waffle
244990a6e9 rustc_attr remove ref patterns
...and some if-let-elses too :P
2022-12-06 14:45:58 +00:00
Maybe Waffle
c75817fb1b rustc_borrowck: remove ref patterns 2022-12-06 14:45:58 +00:00
Maybe Waffle
12ce0c2a89 Remove outdated syntax from trait alias pretty printing 2022-12-06 13:45:11 +00:00
Maybe Waffle
e12d22239a Add debug asserts to hand-implemented Ord/Eq impls 2022-12-06 13:38:50 +00:00
Matthias Krüger
a9ffe7c738
Rollup merge of #105342 - compiler-errors:note_cause_code-takes-predicate, r=fee1-dead
Make `note_obligation_cause_code`  take a `impl ToPredicate` for predicate

The only usecase that wasn't `impl ToPredicate` was noting overflow errors while revealing opaque types, which passed in an `Obligation<'tcx, Ty<'tcx>>`... Since this only happens in a `RevealAll` environment, which is after typeck (and probably primarily within `normalize_erasing_regions`) we're unlikely to display anything useful while noting this code, evidenced by the lack of UI test changes.
2022-12-06 13:27:45 +01:00
Matthias Krüger
07fd8089a4
Rollup merge of #105340 - estebank:ice-ice-baby, r=compiler-errors
Avoid ICE by accounting for missing type

Fix #105330
2022-12-06 13:27:45 +01:00
Matthias Krüger
762d2545f4
Rollup merge of #105339 - BoxyUwU:wf_ct_kind_expr, r=TaKO8Ki
support `ConstKind::Expr` in `is_const_evaluatable` and `WfPredicates::compute`

Fixes #105205

Currently we haven't implemented a way to evaluate `ConstKind::Expr(Expr::Binop(Add, 1, 2))` so I just left that with a `FIXME` and a `delay_span_bug` since I have no idea how to do that and it would make this a much larger (and more complicated) PR :P
2022-12-06 13:27:44 +01:00
Matthias Krüger
e29a510ff0
Rollup merge of #105318 - compiler-errors:issue-105304, r=jackh726
Make `get_impl_future_output_ty` work with AFIT

Fixes #105304
2022-12-06 13:27:44 +01:00
Matthias Krüger
61189b6ae3
Rollup merge of #105310 - compiler-errors:issue-105288, r=eholk
Be more careful about unresolved exprs in suggestion

Fixes #105288
2022-12-06 13:27:43 +01:00
Matthias Krüger
0a07ffe4ad
Rollup merge of #105287 - compiler-errors:issue-105275, r=eholk
Synthesize substitutions for bad auto traits in dyn types

Auto traits are stored as just `DefId`s inside a `dyn Trait`'s existential predicates list. This is usually fine, since auto traits are forbidden to have generics -- but this becomes a problem for an ill-formed auto trait.

But since this will always result in an error, just synthesize some dummy (error) substitutions which are used at least to keep trait selection code happy about the number of substs in a trait ref.

Fixes #104808
2022-12-06 13:27:43 +01:00
Matthias Krüger
ddb98e0aac
Rollup merge of #105254 - cjgillot:issue-105251, r=oli-obk
Recurse into nested impl-trait when computing variance.

Fixes https://github.com/rust-lang/rust/issues/105251
2022-12-06 13:27:42 +01:00
Matthias Krüger
48172ff64b
Rollup merge of #105098 - lyming2007:issue-103869-fix, r=eholk
propagate the error from parsing enum variant to the parser and emit out

While parsing enum variant, the error message always disappear
Because the error message that emit out is from main error of parser
The information of enum variant disappears while parsing enum variant with error
We only check the syntax of expecting token, i.e, in case https://github.com/rust-lang/rust/issues/103869
It will error it without telling the message that this error is from pasring enum variant.
Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err
Check the sub-error before emitting the main error of parser and attach it.
Fix https://github.com/rust-lang/rust/issues/103869
2022-12-06 13:27:41 +01:00
Matthias Krüger
be3ad5d6b0
Rollup merge of #105005 - estebank:where-clause-lts, r=compiler-errors
On E0195 point at where clause lifetime bounds

Fix #104733
2022-12-06 13:27:41 +01:00
Maybe Waffle
78060cb6de Box rustc_parse_format::Piece::NextArgument
This makes both variants closer together in size (previously they were
different by 208 bytes -- 16 vs 224). This may make things worse, but
it's worth a try.
2022-12-06 12:02:56 +00:00
Maybe Waffle
07fbb1b372 Cleanup macro-expanded code in rustc_type_ir 2022-12-06 11:17:49 +00:00
Ralf Jung
9397ea1368 make retagging work even with 'unstable' places 2022-12-06 10:33:34 +01:00
bors
9db224fc90 Auto merge of #105175 - michaelwoerister:add-stable-ord-trait, r=nagisa
Add StableOrd trait as proposed in MCP 533.

The `StableOrd` trait can be used to mark types as having a stable sort order across compilation sessions. Collections that sort their items in a stable way can safely implement HashStable by hashing items in sort order.

See https://github.com/rust-lang/compiler-team/issues/533 for more information.
2022-12-06 09:21:49 +00:00
Arpad Borsos
cf031a3355
Replace usage of ResumeTy in async lowering with Context
Replaces using `ResumeTy` / `get_context` in favor of using `&'static mut Context<'_>`.

Usage of the `'static` lifetime here is technically "cheating", and replaces
the raw pointer in `ResumeTy` and the `get_context` fn that pulls the
correct lifetimes out of thin air.
2022-12-06 10:16:23 +01:00
bors
c5351ad4dc Auto merge of #105348 - JohnTitor:rollup-q9bichr, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #104967 (Fix UI issues with Rustdoc scrape-examples feature.)
 - #105207 (interpret: clobber return place when calling function)
 - #105246 (Fix --pass in compiletest)
 - #105256 (Add small comment explaining what `method-margins.goml` test is about)
 - #105289 (Fix dupe word typos)
 - #105309 (rustdoc: remove no-op mobile CSS `.sidebar { margin: 0; padding: 0 }`)
 - #105313 (Update books)
 - #105315 (Normalize inherent associated types after substitution)
 - #105324 (Point at GAT `where` clause when an obligation is unsatisfied)
 - #105338 (Tweak "the following other types implement trait")

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-06 06:34:13 +00:00
Esteban Küber
e802165dfe On E0195 point at where clause lifetime bounds
Fix #104733
2022-12-05 20:43:41 -08:00
Esteban Küber
eff76455fd Avoid ICE by accounting for missing type
Fix #105330
2022-12-05 20:30:17 -08:00
Michael Goulet
9c9c476774 Point at args in associated const fn pointers 2022-12-06 03:51:19 +00:00
Yuki Okushi
1310d9bd2b
Rollup merge of #105338 - estebank:other-impls, r=compiler-errors
Tweak "the following other types implement trait"

When *any* of the suggested impls is an exact match, *only* show the exact matches. This is particularly relevant for integer types.

r? `@compiler-errors`
2022-12-06 12:48:54 +09:00
Yuki Okushi
e09c71e4c1
Rollup merge of #105324 - compiler-errors:gat-where-clause-binding-obl, r=jackh726
Point at GAT `where` clause when an obligation is unsatisfied

Slightly helps with #105306
2022-12-06 12:48:54 +09:00
Yuki Okushi
7ba37adbfd
Rollup merge of #105315 - fmease:norm-subst-iat, r=compiler-errors
Normalize inherent associated types after substitution

Fixes #105314.

r? ````@cjgillot```` (#105224)
````@rustbot```` label F-inherent_associated_types
2022-12-06 12:48:53 +09:00
Yuki Okushi
fa7d3ec630
Rollup merge of #105289 - Rageking8:fix-dupe-word-typos, r=cjgillot
Fix dupe word typos
2022-12-06 12:48:52 +09:00
Yuki Okushi
aa0831092b
Rollup merge of #105207 - RalfJung:interpret-clobber-return, r=oli-obk
interpret: clobber return place when calling function

Makes sure the callee cannot observe the previous contents of the return place, and the caller cannot read any of the old return place contents even if the function unwinds.

I don't think we can test for this though, that would require some strange hand-written MIR.

r? `````@oli-obk`````
2022-12-06 12:48:50 +09:00
bors
ed61c139c2 Auto merge of #105220 - oli-obk:feeding, r=cjgillot
feed resolver_for_lowering instead of storing it in a field

r? `@cjgillot`

opening this as

* a discussion for `no_hash` + `feedable` queries. I think we'll want those, but I don't quite understand why they are rejected beyond a double check of the stable hashes for situations where the query is fed but also read from incremental caches.
* and a discussion on removing all untracked fields from TyCtxt and setting it up so that they are fed queries instead
2022-12-06 03:47:41 +00:00
Michael Goulet
6dc2aa2675 Add GenericParamDef::to_error and InternalSubsts::extend_with_error 2022-12-06 01:53:01 +00:00
Gary Guo
c559cf62c2 Simplify attribute handling in rustc_ast_lowering
Given that attributes is stored in a separate BTreeMap, it's not necessary
to pass it in when constructing `hir::Expr`. We can just construct
`hir::Expr` and then call `self.lower_attrs` later if it needs attributes.

As most desugaring code don't use attributes, this allows some code cleanup.
2022-12-06 01:05:17 +00:00
bors
226202d902 Auto merge of #105119 - JakobDegen:inline-experiments, r=cjgillot
Disable top down MIR inlining

The current MIR inliner has exponential behavior in some cases: <https://godbolt.org/z/7jnWah4fE>. The cause of this is top-down inlining, where we repeatedly do inlining like `call_a() => { call_b(); call_b(); }`. Each decision on its own seems to make sense, but the result is exponential.

Disabling top-down inlining fundamentally prevents this. Each call site in the original, unoptimized source code is now considered for inlining exactly one time, which means that the total growth in MIR size is limited to number of call sites * inlining threshold.

Top down inlining may be worth re-introducing at some point, but it needs to be accompanied with a principled way to prevent this kind of behavior.
2022-12-06 00:53:01 +00:00
Michael Goulet
d2a80c1571 Avoid noting cause code (which is usually misc, b/c codegen) for opaque type reveal overflow 2022-12-06 00:19:55 +00:00
Michael Goulet
e940f845be drive-by: Default param for ToPredicate 2022-12-06 00:19:55 +00:00
Boxy
c9bab74fb2 support Expr in is_const_evaluatable and compute 2022-12-05 23:17:55 +00:00
Peter Collingbourne
f44a0153bc Support Option and similar enums as type of static variable with linkage attribute.
Compiler MCP:
https://github.com/rust-lang/compiler-team/issues/565
2022-12-05 15:05:43 -08:00
Peter Collingbourne
5873ebeef3 Move linkage type check to HIR analysis and fix semantics issues.
This ensures that the error is printed even for unused variables,
as well as unifying the handling between the LLVM and GCC backends.

This also fixes unusual behavior around exported Rust-defined variables
with linkage attributes. With the previous behavior, it appears to be
impossible to define such a variable such that it can actually be imported
and used by another crate. This is because on the importing side, the
variable is required to be a pointer, but on the exporting side, the
type checker rejects static variables of pointer type because they do
not implement `Sync`. Even if it were possible to import such a type, it
appears that code generation on the importing side would add an unexpected
additional level of pointer indirection, which would break type safety.

This highlighted that the semantics of linkage on Rust-defined variables
is different to linkage on foreign items. As such, we now model the
difference with two different codegen attributes: linkage for Rust-defined
variables, and import_linkage for foreign items.

This change gives semantics to the test
src/test/ui/linkage-attr/auxiliary/def_illtyped_external.rs which was
previously expected to fail to compile. Therefore, convert it into a
test that is expected to successfully compile.

The update to the GCC backend is speculative and untested.
2022-12-05 15:05:43 -08:00
Esteban Küber
e1649c442f Tweak "the following other types implement trait"
When *any* of the suggested impls is an exact match, *only* show the
exact matches. This is particularly relevant for integer types.

fix fmt
2022-12-05 14:59:30 -08:00
Will Crichton
d595884302 Move -Z maximal-hir-to-mir-coverage implementation to new maybe_new_source_scope method 2022-12-05 12:47:44 -08:00
Matthias Krüger
4ebbb20dad
Rollup merge of #105230 - cjgillot:issue-104312, r=petrochenkov
Skip recording resolution for duplicated generic params.

Turns out the fix was simpler than I thought.

Fixes https://github.com/rust-lang/rust/issues/104312
2022-12-05 20:43:44 +01:00
Matthias Krüger
66a4cb5368
Rollup merge of #105223 - lukas-code:(ExprWithBlock), r=petrochenkov
suggest parenthesis around ExprWithBlock BinOp ExprWithBlock

fix https://github.com/rust-lang/rust/issues/105179
fix https://github.com/rust-lang/rust/issues/102171
2022-12-05 20:43:44 +01:00
Matthias Krüger
78cf0b916a
Rollup merge of #105180 - nbdd0121:async_track_caller, r=compiler-errors
Use proper HirId for async track_caller attribute check

Fix #105134
2022-12-05 20:43:42 +01:00
Michael Goulet
a1fbc14372 Point at GAT where clause when unsatisfied 2022-12-05 19:11:31 +00:00
Michael Goulet
da929fa63c Make get_impl_future_output_ty work with AFIT 2022-12-05 17:34:42 +00:00
León Orell Valerian Liehr
d5cb5fb185
normalize inherent associated types after substitution 2022-12-05 18:02:47 +01:00
Michael Goulet
f4c76b193d Be more careful about unresolved exprs in suggestion 2022-12-05 08:15:30 -08:00
Oli Scherer
f693b7848e feed resolver_for_lowering instead of storing it in a field 2022-12-05 10:58:55 +00:00
Oli Scherer
125b729ddd Allow arbitrary keys in feeding API 2022-12-05 10:58:55 +00:00
Michael Woerister
56aacb245c StableOrd: Address review comments. 2022-12-05 10:45:31 +01:00
Nicholas Nethercote
8980d9a76d Remove {Early,Late}LintPassObjects.
`EarlyContextAndPass` wraps a single early lint pass. We aggregate
multiple passes into that single pass by using `EarlyLintPassObjects`.

This commit removes `EarlyLintPassObjects` by changing
`EarlyContextAndPass` into `EarlyContextAndPasses`. I.e. it just removes
a level of indirection. This makes the code simpler and slightly faster.

The commit does likewise for late lints.
2022-12-05 19:50:10 +11:00
Rageking8
58110572fb fix dupe word typos 2022-12-05 16:42:36 +08:00
Will Crichton
3bf7d88ef1 Add -Z maximal-hir-to-mir-coverage flag 2022-12-04 23:58:20 -08:00
bors
e72ea1dc37 Auto merge of #104824 - klensy:bump-some, r=Mark-Simulacrum
deps: update cpufeatures, swap difference to dissimilar

Updating cpufeatures v0.2.1 -> v0.2.5: https://github.com/RustCrypto/utils/blob/master/cpufeatures/CHANGELOG.md#025-2022-09-04, was yanked bc of miscompile (https://github.com/RustCrypto/utils/pull/800, https://github.com/rust-lang/rust/issues/101346)

Removing difference v2.0.0
     Adding dissimilar v1.0.4
   Updating expect-test v1.0.1 -> v1.4.0

difference unmaintened https://rustsec.org/advisories/RUSTSEC-2020-0095.html, so replaced with https://github.com/dtolnay/dissimilar (as dependency of `expect-test`)
2022-12-05 05:54:33 +00:00
Michael Goulet
19175e9b75 Synthesize generics for bad auto traits in dyn types 2022-12-05 05:45:12 +00:00
Nicholas Nethercote
7e0c6dba0d Remove LitKind::synthesize_token_lit.
It has a single call site in the HIR pretty printer, where the resulting
token lit is immediately converted to a string.

This commit replaces `LitKind::synthesize_token_lit` with a `Display`
impl for `LitKind`, which can be used by the HIR pretty printer.
2022-12-05 16:33:24 +11:00
Nicholas Nethercote
568e647047 Remove three uses of LitKind::synthesize_token_lit. 2022-12-05 16:33:20 +11:00
Nicholas Nethercote
d887615b4c Parameterise Parser::{recover_unclosed_char,handle_missing_lit}.
These two methods both produce a `MetaItemLit`, and then some of the
call sites convert the `MetaItemLit` to a `token::Lit` with
`as_token_lit`.

This commit parameterises these two methods with a `mk_lit_char`
closure, which can be used to produce either `MetaItemLit` or
`token::Lit` directly as necessary.
2022-12-05 15:04:33 +11:00
Nicholas Nethercote
4ae956f600 Remove ExtCtxt::expr_lit. 2022-12-05 14:20:38 +11:00
Michael Goulet
64ad337a3b Don't call diagnostic_hir_wf_check query if we have infer variables 2022-12-05 03:18:57 +00:00
Gary Guo
34c377335b Add fixme note 2022-12-05 03:18:26 +00:00
bors
b9341bfdb1 Auto merge of #104920 - compiler-errors:avoid-infcx-build, r=jackh726
Avoid some `InferCtxt::build` calls

Either because we're inside of an `InferCtxt` already, or because we're not in a place where we'd ever see inference vars.

r? types
2022-12-05 02:51:06 +00:00
Michael Goulet
1c81540206 Unconditional check FRU expression, even if there are errors present 2022-12-05 00:42:40 +00:00
Nicholas Nethercote
7d30472180 Remove mk_name_value_item{,_str}.
There are better ways to create the meta items.
- In the rustdoc tests, the commit adds `dummy_meta_item_name_value`,
  which matches the existing `dummy_meta_item_word` function and
  `dummy_meta_item_list` macro.
- In `types.rs` the commit clones the existing meta item and then
  modifies the clone.
2022-12-05 11:24:48 +11:00
bors
d1449560e3 Auto merge of #105094 - Swatinem:generator-not-future, r=compiler-errors
Make sure async constructs do not `impl Generator`

Async lowering turns async functions and blocks into generators internally.
Though these special kinds of generators should not `impl Generator` themselves.
The other way around, normal generators should not `impl Future`.

This was discovered in https://github.com/rust-lang/rust/pull/105082#issuecomment-1332210907 and is a regression from https://github.com/rust-lang/rust/pull/104321.

r? `@compiler-errors`
2022-12-04 22:46:11 +00:00
Michael Goulet
a68eae2f70 Avoid InferCtxt::build in generic_arg_mismatch_err 2022-12-04 20:54:30 +00:00
Michael Goulet
e3072a24ad Avoid InferCtxt::build in report_similar_impl_candidates 2022-12-04 20:54:30 +00:00
bors
53e4b9dd74 Auto merge of #104535 - mikebenfield:discr-fix, r=pnkfelix
rustc_codegen_ssa: Fix for codegen_get_discr

When doing the optimized implementation of getting the discriminant, the arithmetic needs to be done in the tag type so wrapping behavior works correctly.

Fixes #104519
2022-12-04 20:05:32 +00:00
Michael Goulet
d442c015d6 Don't ICE in ExprUseVisitor on FRU for non-existent struct 2022-12-04 18:53:50 +00:00
Michael Goulet
26b24cd755 drive-by: move field_index to typeck results 2022-12-04 17:59:21 +00:00
bors
0f0d5d716a Auto merge of #105261 - matthiaskrgr:rollup-9ghhc9c, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #101975 (Suggest to use . instead of :: when accessing a method of an object)
 - #105141 (Fix ICE on invalid variable declarations in macro calls)
 - #105224 (Properly substitute inherent associated types.)
 - #105236 (Add regression test for #47814)
 - #105247 (Use parent function WfCheckingContext to check RPITIT.)
 - #105253 (Update a couple of rustbuild deps)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-04 16:32:21 +00:00
Matthias Krüger
d055d6ad5e
Rollup merge of #105247 - cjgillot:issue-102682, r=compiler-errors
Use parent function WfCheckingContext to check RPITIT.

WF-check for RPITIT was done in the opaque type's param-env, so it could not benefit from assumed wf types from the function's parameters.

cc `@compiler-errors` since you chose that param-env in fd2766e7fd

Fixes https://github.com/rust-lang/rust/issues/102682
Fixes https://github.com/rust-lang/rust/issues/104908
Fixes https://github.com/rust-lang/rust/issues/102552
Fixes https://github.com/rust-lang/rust/issues/104529
2022-12-04 16:25:34 +01:00
Matthias Krüger
f2e223c576
Rollup merge of #105224 - cjgillot:issue-104240, r=compiler-errors
Properly substitute inherent associated types.

Fixes https://github.com/rust-lang/rust/issues/104240
2022-12-04 16:25:33 +01:00
Matthias Krüger
b1816833bd
Rollup merge of #105141 - ohno418:fix-ice-on-invalid-var-decl-in-macro-call, r=compiler-errors
Fix ICE on invalid variable declarations in macro calls

This fixes ICE that happens with invalid variable declarations in macro calls like:

```rust
macro_rules! m { ($s:stmt) => {} }
m! { var x }
m! { auto x }
m! { mut x }
```

Found this is because of not collecting tokens on recovery, so I changed to force collect them.

Fixes https://github.com/rust-lang/rust/issues/103529.
2022-12-04 16:25:32 +01:00
Matthias Krüger
7dbd1603b8
Rollup merge of #101975 - chenyukang:fix-101749, r=compiler-errors
Suggest to use . instead of :: when accessing a method of an object

Fixes #101749
Fixes #101542
2022-12-04 16:25:32 +01:00
Camille GILLOT
e2d41f4c97 Make nested RPITIT inherit the parent opaque's generics. 2022-12-04 14:38:20 +00:00
bors
19c250aa12 Auto merge of #103293 - est31:untwist_and_drop_order, r=nagisa
Remove drop order twist of && and || and make them associative

Previously a short circuiting binop chain (chain of && or ||s) would drop the temporaries created by the first element after all the other elements, and otherwise follow evaluation order. So `f(1).g() && f(2).g() && f(3).g() && f(4).g()` would drop the temporaries in the order `2,3,4,1`. This made `&&` and `||` non-associative regarding drop order. In other words, adding ()'s to the expression would change drop order: `f(1).g() && (f(2).g() && f(3).g()) && f(4).g()` for example would drop in the order `3,2,4,1`.

As, except for the bool result, there is no data returned by the sub-expressions of the short circuiting binops, we can safely discard of any temporaries created by the sub-expr. Previously, code was already putting the rhs's into terminating scopes, but missed it for the lhs's.

This commit addresses this "twist". We now also put the lhs into a terminating scope. The drop order of the above expressions becomes `1,2,3,4`.

There might be code relying on the current order, and therefore I'd recommend doing a crater run to gauge the impact. I'd argue that such code is already quite wonky as it is one `foo() &&` addition away from breaking. ~~For the impact, I don't expect any *build* failures, as the compiler gets strictly more tolerant: shortening the lifetime of temporaries only expands the list of programs the compiler accepts as valid. There might be *runtime* failures caused by this change however.~~ Edit: both build and runtime failures are possible, e.g. see the example provided by dtolnay [below](https://github.com/rust-lang/rust/pull/103293#issuecomment-1285341113). Edit2: the crater run has finished and [results](https://github.com/rust-lang/rust/pull/103293#issuecomment-1292275203) are that there is only one build failure which is easy to fix with a +/- 1 line diff.

I've included a testcase that now compiles thanks to this patch.

The breakage is also limited to drop order relative to conditionals in the && chain: that is, in code like this:

```Rust
let hello = foo().hi() && bar().world();
println!("hi");
```

we already drop the temporaries of `foo().hi()` before we reach "hi".

I'd ideally have this PR merged before let chains are stabilized. If this PR is taking too long, I'd love to have a more restricted version of this change limited to `&&`'s in let chains: the `&&`'s of such chains are quite special anyways as they accept `let` bindings, in there the `&&` is therefore more a part of the "if let chain" construct than a construct of its own.

Fixes #103107

Status: waiting on [this accepted FCP](https://github.com/rust-lang/rust/pull/103293#issuecomment-1293411354) finishing.
2022-12-04 14:03:12 +00:00
Camille GILLOT
44948d1fdc Recurse into nested impl-trait when computing variance. 2022-12-04 13:54:56 +00:00
bjorn3
262ace5284 Avoid from_immediate_or_packed_pair in ThreadLocalRef codegen 2022-12-04 12:53:46 +00:00
Matthias Krüger
3c4a430900
Rollup merge of #105142 - nbdd0121:inline_const, r=petrochenkov
Make inline const block `ExprWithBlock`

Fix https://github.com/rust-lang/rust/pull/104087#issuecomment-1324190817

`@rustbot` label: +T-lang +F-inline_const
2022-12-04 11:38:51 +01:00
Matthias Krüger
7fe9597775
Rollup merge of #105123 - BlackHoleFox:fixing-the-macos-deployment, r=oli-obk
Fix passing MACOSX_DEPLOYMENT_TARGET to the linker

I messed up in https://github.com/rust-lang/rust/pull/103929 when merging the two base files together and as a result, started ignoring `MACOSX_DEPLOYMENT_TARGET` at the linker level. This ended up being the cause of nighty builds not running on older macOS versions.

My original hope with the previous PR was that CI would have caught something like that but there were only tests checking the compiler target definitions in codegen tests. Because of how badly this sucks to break, I put together a new test via `run-make` that actually confirms the deployment target set makes it to the linker instead of just LLVM.

Closes https://github.com/rust-lang/rust/issues/104570 (for real this time)
2022-12-04 11:38:51 +01:00
Matthias Krüger
785b47d92a
Rollup merge of #104856 - luqmana:associated-const-bad-suggestion, r=compiler-errors
Don't suggest associated function call for associated const.

Fixes #104801.

r? `@compiler-errors`
2022-12-04 11:38:50 +01:00
Camille GILLOT
12473d3f36 Use parent function WfCheckingContext to check RPITIT. 2022-12-04 10:33:07 +00:00
bors
fd02567705 Auto merge of #105121 - oli-obk:simpler-cheaper-dump_mir, r=nnethercote
Cheaper `dump_mir` take two

alternative to #105083

r? `@nnethercote`
2022-12-04 05:47:10 +00:00
est31
a59a2d3f6a Also avoid creating a terminating scope in mixed chains
This avoids creation of a terminating scope in
chains that contain both && and ||, because
also there we know that a terminating scope is
not neccessary: all the chain members are already
in such terminating scopes.

Also add a mixed && / || test.
2022-12-04 04:09:40 +01:00
est31
a2076dc0a6 Improve comments 2022-12-04 04:09:40 +01:00
Ben Kimock
74a270ac93 Re-enable removal of ZST writes to unions 2022-12-03 19:17:45 -05:00
mejrs
a7838d8bd7 Always evaluate vecs of subdiagnostics eagerly 2022-12-04 01:13:21 +01:00
Lukas Markeffsky
c808d0b289 more comments 2022-12-03 23:54:06 +01:00
Camille GILLOT
b1514108e2 Skip recording resolution for duplicated generic params. 2022-12-03 22:40:30 +00:00
est31
8cf521d80e Remove drop order twist of && and || and make them associative
Previously a short circuiting && chain would drop the
first element after all the other elements, and otherwise
follow evaluation order, so code like:

f(1).g() && f(2).g() && f(3).g() && f(4).g()

would drop the temporaries in the order 2,3,4,1. This made
&& and || non-associative regarding drop order, so
adding ()'s to the expression would change drop order:

f(1).g() && (f(2).g() && f(3).g()) && f(4).g()

for example would drop in the order 3,2,4,1.

As, except for the bool result, there is no data returned
by the sub-expressions of the short circuiting binops,
we can safely discard of any temporaries created by the
sub-expr. Previously, code was already putting the rhs's
into terminating scopes, but missed it for the lhs's.

This commit addresses this "twist". In the expression,
we now also put the lhs into a terminating scope.
The drop order for the above expressions is 1,2,3,4
now.
2022-12-03 23:32:08 +01:00
bors
b8a52e3a4b Auto merge of #105218 - matthiaskrgr:rollup-8d3k08n, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #104199 (Keep track of the start of the argument block of a closure)
 - #105050 (Remove useless borrows and derefs)
 - #105153 (Create a hacky fail-fast mode that stops tests at the first failure)
 - #105164 (Restore `use` suggestion for `dyn` method call requiring `Sized`)
 - #105193 (Disable coverage instrumentation for naked functions)
 - #105200 (Remove useless filter in unused extern crate check.)
 - #105201 (Do not call fn_sig on non-functions.)
 - #105208 (Add AmbiguityError for inconsistent resolution for an import)
 - #105214 (update Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-03 21:25:45 +00:00
Camille GILLOT
8a7ae23f75 Properly substitute inherent associated types. 2022-12-03 19:08:00 +00:00
Lukas Markeffsky
35c00a9731 suggest parenthesis around ExprWithBlock BinOp ExprWithBlock 2022-12-03 20:02:39 +01:00
Alex Gaynor
bd8e476d8b
Avoid a temporary file when processing macOS fat archives 2022-12-03 14:02:35 -05:00
Alex Gaynor
047c7cc60c
Remove macOS fat archive support from LlvmArchiveBuilder
its only ever used for wasm targets
2022-12-03 13:29:22 -05:00
bjorn3
b2e0db93e7 Directly return loaded value from type_checked_load 2022-12-03 18:27:43 +00:00
bjorn3
fff6296b62 Destruct landing_pad return value before passing it to cg_ssa 2022-12-03 18:27:18 +00:00
Matthias Krüger
af8f72292b
Rollup merge of #105208 - chenyukang:yukang/fix-105069, r=cjgillot
Add AmbiguityError for inconsistent resolution for an import

Fixes #105069
Fixes #83950
2022-12-03 17:37:45 +01:00