Commit Graph

19338 Commits

Author SHA1 Message Date
Esteban Küber
4a51f37bcb Do not suggest ref multiple times for the same binding 2022-11-23 12:17:47 -08:00
Esteban Küber
9e72e35ceb Suggest .clone() or ref binding on E0382 2022-11-23 12:17:47 -08:00
bors
70f8737b2f Auto merge of #104410 - WaffleLapkin:unregress, r=estebank
Fix perf regression by correctly matching keywords

This should (hopefully) fix regression from #99918

r? `@estebank`
2022-11-23 19:52:43 +00:00
Oli Scherer
6c2719a6d6 Bump the const eval step limit 2022-11-23 16:55:57 +00:00
bors
d121aa3b55 Auto merge of #104776 - Dylan-DPC:rollup-rf4c2u0, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #104269 (Fix hang in where-clause suggestion with `predicate_can_apply`)
 - #104286 (copy doc output files by format)
 - #104509 (Use obligation ctxt instead of dyn TraitEngine)
 - #104721 (Remove more `ref` patterns from the compiler)
 - #104744 (rustdoc: give struct fields CSS `display: block`)
 - #104751 (Fix an ICE parsing a malformed attribute.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-23 16:29:17 +00:00
Maybe Waffle
20f3de5ab1 Use nicer spans for deref_into_dyn_supertrait 2022-11-23 16:12:51 +00:00
Maybe Waffle
0d4a5c725a Make deref_into_dyn_supertrait lint the impl and not the usage 2022-11-23 15:40:27 +00:00
Maybe Waffle
11a5386256 Move get_associated_type from clippy to rustc_lint 2022-11-23 15:40:27 +00:00
Dylan DPC
5d7b68c82b
Rollup merge of #104751 - nnethercote:fix-104620, r=petrochenkov
Fix an ICE parsing a malformed attribute.

Fixes #104620.

r? `@petrochenkov`
2022-11-23 20:32:38 +05:30
Dylan DPC
c03026a7c6
Rollup merge of #104721 - WaffleLapkin:deref-harder, r=oli-obk
Remove more `ref` patterns from the compiler

r? `@oli-obk`
Previous PR: https://github.com/rust-lang/rust/pull/104500
2022-11-23 20:32:37 +05:30
Dylan DPC
0a791381c3
Rollup merge of #104509 - spastorino:use-obligation-ctxt, r=lcnr
Use obligation ctxt instead of dyn TraitEngine

r? `@lcnr`
2022-11-23 20:32:36 +05:30
Dylan DPC
bd91c94a5d
Rollup merge of #104269 - compiler-errors:hang-in-where-clause-sugg, r=lcnr
Fix hang in where-clause suggestion with `predicate_can_apply`

Using `predicate_may_hold` during error reporting causes an evaluation overflow, which (because we use `evaluate_obligation_no_overflow`) then causes the predicate to need to be re-evaluated locally, which results in a hang.

... but since the "add a where clause" suggestion is best-effort, just throw any overflow errors. No need for 100% accuracy.

r? `@lcnr` who has been thinking about overflows... Let me know if you want more context about this issue, and as always, feel free to reassign.

Fixes #104225
2022-11-23 20:32:35 +05:30
Oli Scherer
46b37e20af OpaqueCast projections are always overlapping, they can't possibly be disjoint 2022-11-23 14:37:13 +00:00
Santiago Pastorino
409203a315
Use ObligationCtxt::normalize 2022-11-23 11:32:49 -03:00
bors
80b3c6dbde Auto merge of #103947 - camsteffen:place-clones, r=cjgillot
Reduce `PlaceBuilder` cloning

Some API tweaks with an eye towards reducing clones.
2022-11-23 13:13:50 +00:00
Santiago Pastorino
859b147d4f
Pass ObligationCtxt from enter_canonical_trait_query and use ObligationCtxt API 2022-11-23 09:36:03 -03:00
Santiago Pastorino
5b3a06a3c2
Call fully_solve_obligations instead of repeating code 2022-11-23 09:36:00 -03:00
Santiago Pastorino
ad094cdceb
Use ObligationCtxt intead of dyn TraitEngine 2022-11-23 09:24:42 -03:00
bors
4e0d0d757e Auto merge of #102750 - the8472:opt-field-order, r=wesleywiser
optimize field ordering by grouping m*2^n-sized fields with equivalently aligned ones

```rust
use std::ptr::addr_of;
use std::mem;

struct Foo {
    word: u32,
    byte: u8,
    ary: [u8; 4]
}

fn main() {
    let foo: Foo = unsafe { mem::zeroed() };

    println!("base: {:p}\nword: {:p}\nbyte: {:p}\nary:  {:p}", &foo, addr_of!(foo.word), addr_of!(foo.byte), addr_of!(foo.ary));
}
```

prints

```
base: 0x7fffc1a8a668
word: 0x7fffc1a8a668
byte: 0x7fffc1a8a66c
ary:  0x7fffc1a8a66d
```

I.e. the `u8` in the middle causes the array to sit at an odd offset, which might prevent optimizations, especially on architectures where unaligned loads are costly.

Note that this will make field ordering niche-dependent, i.e. a `Bar<T>` with `T=char` and `T=u32` may result in different field order, this may break some code that makes invalid assumptions about `repr(Rust)` types.
2022-11-23 10:01:48 +00:00
Michael Goulet
a884a9e634 Drive-by: Don't manually call evaluate_obligation_no_overflow 2022-11-23 04:42:38 +00:00
Michael Goulet
cbe9328018 Do not need to account for overflow in predicate_can_apply 2022-11-23 04:42:38 +00:00
Manish Goregaokar
54b6292855
Rollup merge of #104621 - YC:master, r=davidtwco
Fix --extern library finding errors

- `crate_name` is not specified/passed to `metadata_crate_location_unknown_type`
c493bae0d8/compiler/rustc_error_messages/locales/en-US/metadata.ftl (L274-L275)
- `metadata_lib_filename_form` is missing `$`
- Add additional check to ensure that library is file

Testing
1. Create file `a.rs`
```rust
extern crate t;
fn main() {}
```
1. Create empty file `x`
1. Create empty directory `y`
1. Run
```sh
$ rustc -o a a.rs --extern t=x
$ rustc -o a a.rs --extern t=y
```
Both currently panic with stable.
2022-11-22 22:54:40 -05:00
Manish Goregaokar
36815c6e3b
Rollup merge of #104612 - Swatinem:async-ret-y, r=estebank
Lower return type outside async block creation

This allows feeding a different output type to async blocks with a different `ImplTraitContext`. Spotted this while working on #104321
2022-11-22 22:54:39 -05:00
Manish Goregaokar
a673364c54
Rollup merge of #104359 - Nilstrieb:plus-one, r=fee1-dead
Refactor must_use lint into two parts

Before, the lint did the checking for `must_use` and pretty printing the types in a special format in one pass, causing quite complex and untranslatable code.
Now the collection and printing is split in two. That should also make it easier to translate or extract the type pretty printing in the future.

Also fixes an integer overflow in the array length pluralization
calculation.

fixes #104352
2022-11-22 22:54:39 -05:00
Manish Goregaokar
53eab246db
Rollup merge of #103488 - oli-obk:impl_trait_for_tait, r=lcnr
Allow opaque types in trait impl headers and rely on coherence to reject unsound cases

r? ````@lcnr````

fixes #99840
2022-11-22 22:54:38 -05:00
Michael Goulet
024bb8c7fb Pass ParamEnv down instead of using ParamEnv of a module 2022-11-23 02:06:03 +00:00
Michael Goulet
1e7f6a7e0d Pass InferCtxt to DropRangeVisitor so we can resolve vars 2022-11-23 01:48:03 +00:00
Nicholas Nethercote
7c3f631ddf Fix an ICE parsing a malformed attribute.
Fixes #104620.
2022-11-23 12:11:14 +11:00
The 8472
a9128d8927 fix tests, update size asserts 2022-11-22 23:12:26 +01:00
The 8472
97d8a9bdd3 also sort fields by niche sizes to retain optimizations 2022-11-22 23:12:26 +01:00
The 8472
a3450d060d group fields based on largest power of two dividing its size 2022-11-22 23:12:26 +01:00
The 8472
9f0cb566ea optimize field ordering by grouping power-of-two arrays with larger types 2022-11-22 23:12:26 +01:00
Vadim Petrochenkov
5fc359f1ef resolve: Don't use constructor def ids in the map for field names
Also do some minor cleanup to insertion of those field names
2022-11-23 00:53:50 +03:00
Yuki Okushi
3ec1ca0516
Rollup merge of #104728 - WaffleLapkin:require-lang-items-politely, r=compiler-errors
Use `tcx.require_lang_item` instead of unwrapping lang items

I clearly remember esteban telling me that there is `require_lang_item` but he was from a phone atm and I couldn't find it, so I didn't use it. Stumbled on it today, so here we are :)
2022-11-23 06:40:24 +09:00
Yuki Okushi
dcbfb9776d
Rollup merge of #104724 - WaffleLapkin:to_def_idn't, r=compiler-errors
Fix `ClosureKind::to_def_id`

`Fn` and `FnOnce` were mixed up in https://github.com/rust-lang/rust/pull/99131.
2022-11-23 06:40:24 +09:00
Yuki Okushi
b162bb4270
Rollup merge of #102293 - ecnelises:aix.initial, r=davidtwco
Add powerpc64-ibm-aix as Tier-3 target

This is part of the effort mentioned in https://github.com/rust-lang/compiler-team/issues/553.

A reference to these options are definitions from [clang](ad6fe32032/clang/lib/Basic/Targets/PPC.h (L414-L448)) and [llvm](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp).

AIX has a system `ld` but [its options and behaviors](https://www.ibm.com/docs/en/aix/7.3?topic=l-ld-command) are different from GNU ld. Thanks to ``@bzEq`` for contributing the linking args.
2022-11-23 06:40:22 +09:00
Maybe Waffle
b97ec3924d rustc_ast_lowering: remove ref patterns 2022-11-22 18:49:29 +00:00
Maybe Waffle
a603635670 rustc_arena: remove a couple of ref patterns 2022-11-22 18:49:29 +00:00
Maybe Waffle
616df0f03b rustc_parse: remove ref patterns 2022-11-22 18:49:16 +00:00
Maybe Waffle
b80356a5ab Use tcx.require_lang_item instead of unwrapping 2022-11-22 17:19:19 +00:00
Maybe Waffle
04610ad129 Fix ClosureKind::to_def_id 2022-11-22 16:45:06 +00:00
bors
66ccf36f16 Auto merge of #104711 - Dylan-DPC:rollup-gkw1qr8, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #104295 (Check generics parity before collecting return-position `impl Trait`s in trait)
 - #104464 (Reduce exceptions overallocation on non Windows x86_64)
 - #104615 (Create def_id for async fns during lowering)
 - #104669 (Only declare bindings for if-let guards once per arm)
 - #104701 (Remove a lifetime resolution hack from `compare_predicate_entailment`)
 - #104710 (disable strict-provenance-violating doctests in Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-22 13:18:45 +00:00
Dylan DPC
b12d31f166
Rollup merge of #104701 - compiler-errors:rpitit-remove-reempty-hack, r=TaKO8Ki
Remove a lifetime resolution hack from `compare_predicate_entailment`

This is not needed anymore, probably due to #102334 equating the function signatures fully in `collect_trait_impl_trait_tys`. Also, the assertion in in #102903 makes sure that this is actually fixed, so I'm pretty confident this isn't needed.
2022-11-22 16:36:38 +05:30
Dylan DPC
d29491aba0
Rollup merge of #104669 - LeSeulArtichaut:88015-if-let-guard-bindings, r=cjgillot
Only declare bindings for if-let guards once per arm

Currently, each candidate for a match arm uses separate locals for the bindings in the if-let guard, causing problems (#88015) when those branches converge in the arm body.

Fixes #88015 (🤞)
2022-11-22 16:36:38 +05:30
Dylan DPC
88542a3150
Rollup merge of #104615 - spastorino:create-async-def-id-in-lowering, r=compiler-errors
Create def_id for async fns during lowering

r? `@compiler-errors`
2022-11-22 16:36:37 +05:30
Dylan DPC
680ba90f96
Rollup merge of #104295 - compiler-errors:rpitit-generics-parity, r=eholk
Check generics parity before collecting return-position `impl Trait`s in trait

The only thing is that this duplicates the error message for number of generics mismatch, but we already deduplicate that error message in Cargo. I could add a flag to delay the error if the reviewer cares.

Fixes #104281

Also drive-by adds a few comments to the `collect_trait_impl_trait_tys` method, and removes an unused argument from `compare_number_of_generics`.
2022-11-22 16:36:36 +05:30
bors
b7463e8bdb Auto merge of #103578 - petrochenkov:nofict, r=nagisa
Unreserve braced enum variants in value namespace

With this PR braced enum variants (`enum E { V { /*...*/ } }`) no longer take a slot in value namespace, so the special case mentioned in the note in https://github.com/rust-lang/rfcs/blob/master/text/1506-adt-kinds.md#braced-structs is removed.

Report - https://github.com/rust-lang/rust/pull/103578#issuecomment-1292594900.
2022-11-22 10:17:09 +00:00
Qiu Chaofan
85c99855c4 Allow power10-vector feature in PowerPC 2022-11-22 14:45:56 +08:00
Steven Tang
7169c7d105
Tests for bad --extern library path and file 2022-11-22 17:44:38 +11:00
Manish Goregaokar
9043dfd946
Rollup merge of #104638 - Nilstrieb:macro-diagnostics, r=compiler-errors
Move macro_rules diagnostics to diagnostics module

This will make it easier to add more diagnostics in the future in a centralized place.
2022-11-22 01:26:08 -05:00
Steven Tang
395f2b84e6
Remove extra . in metadata_lib_filename_form 2022-11-22 17:07:19 +11:00
Michael Goulet
1c1778da25 Remove a hack from compare_predicate_entailment 2022-11-22 03:41:13 +00:00
Michael Goulet
df5f247a5c Delay bug to deduplicate diagnostics 2022-11-22 01:36:41 +00:00
Michael Goulet
0a95878972 drive-by: style nits 2022-11-22 01:36:41 +00:00
Michael Goulet
94e047ba3b Check generics parity between impl and trait before collecting RPITITs 2022-11-22 01:36:41 +00:00
bors
0f7d81754d Auto merge of #104696 - matthiaskrgr:rollup-gi1pdb0, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #103396 (Pin::new_unchecked: discuss pinning closure captures)
 - #104416 (Fix using `include_bytes` in pattern position)
 - #104557 (Add a test case for async dyn* traits)
 - #104559 (Split `MacArgs` in two.)
 - #104597 (Probe + better error messsage for `need_migrate_deref_output_trait_object`)
 - #104656 (Move tests)
 - #104657 (Do not check transmute if has non region infer)
 - #104663 (rustdoc: factor out common button CSS)
 - #104666 (Migrate alias search result to CSS variables)
 - #104674 (Make negative_impl and negative_impl_exists take the right types)
 - #104692 (Update test's cfg-if dependency to 1.0)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-22 01:35:57 +00:00
Matthias Krüger
816a31fc66
Rollup merge of #104674 - spastorino:negative-impl-tcx, r=lcnr
Make negative_impl and negative_impl_exists take the right types

r? `@lcnr`
2022-11-22 00:01:12 +01:00
Matthias Krüger
9cefd9dd29
Rollup merge of #104657 - hi-rustin:rustin-patch-check-transmute, r=compiler-errors
Do not check transmute if has non region infer

close https://github.com/rust-lang/rust/issues/104609

See: https://github.com/rust-lang/rust/issues/104609#issuecomment-1320956351

r? `@compiler-errors`
2022-11-22 00:01:10 +01:00
Matthias Krüger
118ee14dd1
Rollup merge of #104597 - compiler-errors:need_migrate_deref_output_trait_object-msg, r=eholk
Probe + better error messsage for `need_migrate_deref_output_trait_object`

1. Use `InferCtxt::probe` in `need_migrate_deref_output_trait_object` -- that normalization *could* technically do type inference as a side-effect, and this is a lint, so it should have no side-effects.
2. Return the trait-ref so we format the error message correctly. See the UI test change -- `(dyn A + 'static)` is not a trait.
2022-11-22 00:01:09 +01:00
Matthias Krüger
589d843bd0
Rollup merge of #104559 - nnethercote:split-MacArgs, r=petrochenkov
Split `MacArgs` in two.

`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's used in two ways:
- For representing attribute macro arguments (e.g. in `AttrItem`), where all three variants are used.
- For representing function-like macros (e.g. in `MacCall` and `MacroDef`), where only the `Delimited` variant is used.

In other words, `MacArgs` is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using `MacArgs::Empty` in a `MacCall`).

This commit splits `MacArgs` in two:
- `DelimArgs` is a new struct just for the "delimited arguments" case. It is now used in `MacCall` and `MacroDef`.
- `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro case. Its `Delimited` variant now contains a `DelimArgs`.

Various other related things are renamed as well.

These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values.

r? `@petrochenkov`
2022-11-22 00:01:09 +01:00
Matthias Krüger
7a3eca690f
Rollup merge of #104416 - clubby789:fix-104414, r=eholk
Fix using `include_bytes` in pattern position

Fix #104414
2022-11-22 00:01:07 +01:00
Nicholas Nethercote
3e3a4192d8 Split MacArgs in two.
`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's
used in two ways:
- For representing attribute macro arguments (e.g. in `AttrItem`), where all
  three variants are used.
- For representing function-like macros (e.g. in `MacCall` and `MacroDef`),
  where only the `Delimited` variant is used.

In other words, `MacArgs` is used in two quite different places due to them
having partial overlap. I find this makes the code hard to read. It also leads
to various unreachable code paths, and allows invalid values (such as
accidentally using `MacArgs::Empty` in a `MacCall`).

This commit splits `MacArgs` in two:
- `DelimArgs` is a new struct just for the "delimited arguments" case. It is
  now used in `MacCall` and `MacroDef`.
- `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro
  case. Its `Delimited` variant now contains a `DelimArgs`.

Various other related things are renamed as well.

These changes make the code clearer, avoids several unreachable paths, and
disallows the invalid values.
2022-11-22 09:04:15 +11:00
bors
28a53cdb46 Auto merge of #104533 - oli-obk:method_callee, r=lcnr
Clean up and harden various methods around trait substs

r? `@lcnr`
2022-11-21 21:51:00 +00:00
Oli Scherer
c2ecd8f1f6 merge self type and substs in trait_method 2022-11-21 20:41:17 +00:00
Oli Scherer
a6c5212f13 Simplify one more TraitRef::new site 2022-11-21 20:40:56 +00:00
Oli Scherer
7658e0fccf Stop passing the self-type as a separate argument. 2022-11-21 20:39:46 +00:00
Oli Scherer
472444bc64 Remove some unnecessary slicing 2022-11-21 20:38:55 +00:00
Oli Scherer
48ea298abf Remove a redundant assert 2022-11-21 20:36:35 +00:00
Oli Scherer
4d9451b1d1 Fix an ICE that I just made worse 2022-11-21 20:36:15 +00:00
Oli Scherer
a9f3c2209c For lcnr 2022-11-21 20:35:50 +00:00
Oli Scherer
ad57f88d3f Add helper to create the trait ref for a lang item 2022-11-21 20:35:17 +00:00
Oli Scherer
25c4760b5d Some cleanup around trait_method lookup 2022-11-21 20:34:56 +00:00
Oli Scherer
9e4c3f41c1 Use iterators instead of slices at more sites 2022-11-21 20:34:28 +00:00
Oli Scherer
ec8d01fdcc Allow iterators instead of requiring slices that will get turned into iterators 2022-11-21 20:33:55 +00:00
Oli Scherer
bd40c10751 Remove an unnecessary query + subst round 2022-11-21 20:33:23 +00:00
Oli Scherer
19a1192d42 Add a helper for replacing the self type in trait refs 2022-11-21 20:32:41 +00:00
Oli Scherer
6f77c97b38 Assert that various types have the right amount of generic args and fix the sites that used the wrong amount 2022-11-21 20:31:59 +00:00
Oli Scherer
d9a02b0fb7 Split out the actual predicate solving code into a separate function 2022-11-21 20:31:34 +00:00
Oli Scherer
48ff6a95b5 Use ty::List instead of InternalSubsts 2022-11-21 20:31:11 +00:00
Oli Scherer
250dcf421a Check that type_implements_trait actually is passed the right amount of generic params 2022-11-21 20:30:45 +00:00
Oli Scherer
0c47deed9f Reduce the amount of passed-around arguments that will get merged into one later anyway 2022-11-21 20:28:48 +00:00
Vadim Petrochenkov
7a5376d23c Unreserve braced enum variants in value namespace 2022-11-21 22:40:06 +03:00
bors
b7bc90fea3 Auto merge of #104120 - mejrs:diag, r=davidtwco
Match and enforce crate and slug names

Some of these were in the wrong place or had a name that didn't match.
2022-11-21 18:36:26 +00:00
Oli Scherer
c16a90f5e3 Test generalization during coherence 2022-11-21 16:47:29 +00:00
Oli Scherer
11adf03790 Add some more assertions for type relations not used during coherence 2022-11-21 16:38:49 +00:00
Oli Scherer
7301cd7844 Type generalization should not look at opaque type in coherence 2022-11-21 16:38:23 +00:00
Oli Scherer
11ae334f07 Remove a function that doesn't actually do anything 2022-11-21 16:37:57 +00:00
Oli Scherer
f42e490d6f Register obligations from type relation 2022-11-21 16:37:53 +00:00
Oli Scherer
9a8e1eea7a Move a field around 2022-11-21 16:35:23 +00:00
Oli Scherer
ae80c764d4 Add an always-ambiguous predicate to make sure that we don't accidentlally allow trait resolution to prove false things during coherence 2022-11-21 16:35:04 +00:00
Oli Scherer
94fe30ff2f Treat different opaque types of the same def id as equal during coherence 2022-11-21 16:06:07 +00:00
Oli Scherer
2752e328c9 Allow opaque types in trait impl headers and rely on coherence to reject unsound cases 2022-11-21 16:00:31 +00:00
bors
1cbc45942d Auto merge of #104673 - matthiaskrgr:rollup-85f65ov, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #104420 (Fix doc example for `wrapping_abs`)
 - #104499 (rustdoc JSON: Use `Function` everywhere and remove `Method`)
 - #104500 (`rustc_ast`: remove `ref` patterns)
 - #104511 (Mark functions created for `raw-dylib` on x86 with DllImport storage class)
 - #104595 (Add `PolyExistentialPredicate` type alias)
 - #104605 (deduplicate constant evaluation in cranelift backend)
 - #104628 (Revert "Update CI to use Android NDK r25b")
 - #104662 (Streamline deriving on packed structs.)
 - #104667 (Revert formatting changes of a test)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-21 15:22:54 +00:00
Santiago Pastorino
16c9e39021
negative_impl_exists should take an InferCtxt 2022-11-21 11:26:23 -03:00
mejrs
e8e47e0873 Improve slug name error 2022-11-21 15:24:51 +01:00
mejrs
d494502f64 Fix tests 2022-11-21 15:24:51 +01:00
mejrs
fe212eca76 Match crate and slug names 2022-11-21 15:24:50 +01:00
Santiago Pastorino
2faad3b699
negative_impl should take a TyCtxt 2022-11-21 11:09:53 -03:00
Matthias Krüger
439a8e6cef
Rollup merge of #104662 - nnethercote:tweak-deriving-for-packed-non-copy, r=jackh726
Streamline deriving on packed structs.

The current approach to field accesses in derived code:
- Normal case: `&self.0`
- In a packed struct that derives `Copy`: `&{self.0}`
- In a packed struct that doesn't derive `Copy`: `let Self(ref x) = *self`

The `let` pattern used in the third case is equivalent to the simpler field access in the first case. This commit changes the third case to use a field access.

The commit also combines two boolean arguments (`is_packed` and `always_copy`) into a single field (`copy_fields`) earlier, to save passing both around.

r? ``@jackh726``
2022-11-21 14:11:13 +01:00
Matthias Krüger
ed22bdc18f
Rollup merge of #104605 - RalfJung:clf_consts, r=bjorn3
deduplicate constant evaluation in cranelift backend

The cranelift backend had two matches on `ConstantKind`, which can be avoided, and used this `eval_for_mir` that nothing else uses... this makes things more consistent with the (better-tested) LLVM backend.

I noticed this because cranelift was the only user of `eval_for_mir`. However `try_eval_for_mir` still has one other user in `eval`... the odd thing is that the interpreter has its own `eval_mir_constant` which seems to duplicate the same functionality and does not use `try_eval_for_mir`. No idea what is happening here.

r? ``@bjorn3``
Cc ``@lcnr``
2022-11-21 14:11:12 +01:00