Commit Graph

19480 Commits

Author SHA1 Message Date
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
Michael Goulet
0ba5e7416f Add size hints to early binder iterator adapters 2022-11-22 18:35:49 +00:00
Vadim Petrochenkov
24f2ee1efd rustc_metadata: Cleanup to get_module_children
to unify proc-macro and non-proc-macro cases in particular.
2022-11-22 20:43:48 +03:00
Vadim Petrochenkov
6a233b5e2a rustc_metadata: Switch module children decoding to an iterator 2022-11-22 20:43:48 +03:00
Vadim Petrochenkov
f3b5791a47 rustc_metadata: Do not encode empty reexport lists
This is more a cleanup than optimization
2022-11-22 20:43:48 +03: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
Matthias Krüger
844e3fb928
Rollup merge of #104595 - compiler-errors:poly-existential-predicate, r=lcnr
Add `PolyExistentialPredicate` type alias

Wrapping `ExistentialPredicate`s in a binder is very common, and this alias already exists for the `PolyExistential{TraitRef,Projection}` types.
2022-11-21 14:11:11 +01:00
Matthias Krüger
cc2397b2cd
Rollup merge of #104511 - dpaoliello:privateglobalworkaround, r=michaelwoerister
Mark functions created for `raw-dylib` on x86 with DllImport storage class

Fix for #104453

## Issue Details
On x86 Windows, LLVM uses 'L' as the prefix for any private global symbols (`PrivateGlobalPrefix`), so when the `raw-dylib` feature creates an undecorated function symbol that begins with an 'L' LLVM misinterprets that as a private global symbol that it created and so fails the compilation at a later stage since such a symbol must have a definition.

## Fix Details
Mark the function we are creating for `raw-dylib` with `DllImport` storage class (this was already being done for MSVC at a later point for `callee::get_fn` but not for GNU (due to "backwards compatibility")): this will cause LLVM to prefix the name with `__imp_` and so it won't mistake it for a private global symbol.
2022-11-21 14:11:10 +01:00
bors
7fe6f36224 Auto merge of #103491 - cjgillot:self-rpit, r=oli-obk
Support using `Self` or projections inside an RPIT/async fn

I reuse the same idea as https://github.com/rust-lang/rust/pull/103449 to use variances to encode whether a lifetime parameter is captured by impl-trait.

The current implementation of async and RPIT replace all lifetimes from the parent generics by `'static`.  This PR changes the scheme
```rust
impl<'a> Foo<'a> {
    fn foo<'b, T>() -> impl Into<Self> + 'b { ... }
}

opaque Foo::<'_a>::foo::<'_b, T>::opaque<'b>: Into<Foo<'_a>> + 'b;
impl<'a> Foo<'a> {
    // OLD
    fn foo<'b, T>() -> Foo::<'static>::foo::<'static, T>::opaque::<'b> { ... }
                             ^^^^^^^ the `Self` becomes `Foo<'static>`

    // NEW
    fn foo<'b, T>() -> Foo::<'a>::foo::<'b, T>::opaque::<'b> { ... }
                             ^^ the `Self` stays `Foo<'a>`
}
```

There is the same issue with projections. In the example, substitute `Self` by `<T as Trait<'b>>::Assoc` in the sugared version, and `Foo<'_a>` by `<T as Trait<'_b>>::Assoc` in the desugared one.

This allows to support `Self` in impl-trait, since we do not replace lifetimes by `'static` any more.  The same trick allows to use projections like `T::Assoc` where `Self` is allowed.  The feature is gated behind a `impl_trait_projections` feature gate.

The implementation relies on 2 tweaking rules for opaques in 2 places:
- we only relate substs that correspond to captured lifetimes during TypeRelation;
- we only list captured lifetimes in choice region computation.

For simplicity, I encoded the "capturedness" of lifetimes as a variance, `Bivariant` vs `Invariant` for unused vs captured lifetimes. The `variances_of` query used to ICE for opaques.

Impl-trait that do not reference `Self` or projections will have their variances as:
- `o` (invariant) for each parent type or const;
- `*` (bivariant) for each parent lifetime --> will not participate in borrowck;
- `o` (invariant) for each own lifetime.

Impl-trait that does reference `Self` and/or projections will have some parent lifetimes marked as `o` (as the example above), and participate in type relation and borrowck.  In the example above, `variances_of(opaque) = ['_a: o, '_b: *, T: o, 'b: o]`.

r? types
cc `@compiler-errors` , as you asked about the issue with `Self` and projections.
2022-11-21 12:17:03 +00:00
hi-rustin
fec6ffc816 Add delay span bug
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-11-21 20:03:28 +08:00
Léo Lanteri Thauvin
baa59d1a77 Only declare bindings for if-let guards once per arm 2022-11-21 12:45:29 +01:00
Maybe Waffle
417ed9fee2 Remove ref patterns from rustc_ast
Also use if let chains in one case.
2022-11-21 09:18:59 +00:00
bors
736c675d2a Auto merge of #103454 - camsteffen:remove-conservatively-uninhabited, r=oli-obk
Factor out `conservative_is_privately_uninhabited`

After #102660 there is no more need for `conservative_is_privately_uninhabited`.

r? `@oli-obk`
2022-11-21 04:42:43 +00:00
Nicholas Nethercote
a6e09a19fc 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.
2022-11-21 14:07:39 +11:00
bors
ccde51a912 Auto merge of #102717 - beetrees:repr128-c-style-debuginfo, r=nagisa
Pass 128-bit C-style enum enumerator values to LLVM

Pass the full 128 bits of C-style enum enumerators through to LLVM. This means that debuginfo for C-style repr128 enums is now emitted correctly for DWARF platforms (as compared to not being correctly emitted on any platform).

Tracking issue: #56071
2022-11-21 01:44:12 +00:00
Cameron Steffen
cc8dddbac9 Factor out conservative_is_privately_uninhabited 2022-11-20 19:04:11 -06:00
Cameron Steffen
34cbe72780 Change to Ty::is_inhabited_from 2022-11-20 19:04:11 -06:00
Cameron Steffen
a6d96f9fd7 Fix typo 2022-11-20 19:04:11 -06:00
hi-rustin
a60e267200 Do not check transmute if has non region infer
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-11-21 09:03:33 +08:00
Matthias Krüger
fce077b053
Rollup merge of #104504 - compiler-errors:fru-syntax-note, r=estebank
Add a detailed note for missing comma typo w/ FRU syntax

Thanks to `@pierwill` for working on this with me!

Fixes #104373, perhaps `@alice-i-cecile` can comment on the new error for the example provided on that issue -- feedback is welcome.

```
error[E0063]: missing field `defaulted` in initializer of `Outer`
  --> $DIR/multi-line-fru-suggestion.rs:14:5
   |
LL |     Outer {
   |     ^^^^^ missing `defaulted`
   |
note: this expression may have been misinterpreted as a `..` range expression
  --> $DIR/multi-line-fru-suggestion.rs:16:16
   |
LL |           inner: Inner {
   |  ________________^
LL | |             a: 1,
LL | |             b: 2,
LL | |         }
   | |_________^ this expression does not end in a comma...
LL |           ..Default::default()
   |           ^^^^^^^^^^^^^^^^^^^^ ... so this is interpreted as a `..` range expression, instead of functional record update syntax
help: to set the remaining fields from `Default::default()`, separate the last named field with a comma
   |
LL |         },
   |          +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0063`.
```
2022-11-20 23:50:27 +01:00
Matthias Krüger
820a41580e
Rollup merge of #104564 - RalfJung:either, r=oli-obk
interpret: use Either over Result when it is not representing an error condition

r? `@oli-obk`
2022-11-20 18:21:48 +01:00
Nilstrieb
a1e5fea136
Move macro_rules diagnostics to diagnostics module 2022-11-20 13:06:44 +01:00
bors
9cdfe03b06 Auto merge of #103390 - compiler-errors:metadata-mod-regions, r=eholk
Check fat pointer metadata compatibility modulo regions

Regions don't really mean anything anyways during hir typeck.

If this `erase_regions` makes anyone nervous, it's probably equally valid to just equate the types using a type relation, but regardless we should _not_ be using strict type equality while region variables are present.

Fixes #103384
2022-11-20 10:09:39 +00:00
bors
e07425d55b Auto merge of #98914 - fee1-dead-contrib:min-deref-patterns, r=compiler-errors
Minimal implementation of implicit deref patterns for Strings

cc `@compiler-errors` `@BoxyUwU` https://github.com/rust-lang/lang-team/issues/88 #87121

~~I forgot to add a feature gate, will do so in a minute~~ Done
2022-11-20 07:16:42 +00:00
bors
2ed65da152 Auto merge of #104629 - JohnTitor:rollup-vp3m98i, r=JohnTitor
Rollup of 6 pull requests

Successful merges:

 - #103901 (Add tracking issue for `const_arguments_as_str`)
 - #104112 (rustdoc: Add copy to the description of repeat)
 - #104435 (`VecDeque::resize` should re-use the buffer in the passed-in element)
 - #104467 (Fix substraction with overflow in `wrong_number_of_generic_args.rs`)
 - #104608 (Cleanup macro matching recovery)
 - #104626 (Fix doctest errors related to rustc_middle)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-20 04:28:21 +00:00
Yuki Okushi
d553811c1f
Rollup merge of #104626 - reez12g:issue-99144-2, r=jyn514
Fix doctest errors related to rustc_middle

Helps with https://github.com/rust-lang/rust/issues/99144
2022-11-20 13:16:00 +09:00
Yuki Okushi
28034bb2f8
Rollup merge of #104608 - Nilstrieb:fixmed, r=compiler-errors
Cleanup macro matching recovery

The retry has been implemented already in #104335. Also removes a `HACK` comment that's not really needed anymore because the "don't recover during macro matching" isn't really a hack but correct behavior.
2022-11-20 13:15:59 +09:00
Yuki Okushi
3e937d02a0
Rollup merge of #104467 - fuzzypixelz:fix/attempt-to-substract-with-overflow, r=compiler-errors
Fix substraction with overflow in `wrong_number_of_generic_args.rs`

Fixes #104287

This issue happens in the `suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path` function, which seems to run before the error checking facilities can catch an invalid use of generic arguments. Thus we get a subtraction with overflow because the code implicitly assumes that the source program makes sense (or is this assumption not true even if the program is correct?).
2022-11-20 13:15:59 +09:00
reez12g
e1f0d6af15 Fix doctest errors related to rustc_middle 2022-11-20 11:10:45 +09:00
bors
7477c1f4f7 Auto merge of #104522 - RalfJung:try_normalize_after_erasing_regions, r=oli-obk
try_normalize_after_erasing_regions: promote an assertion to always run

In https://github.com/rust-lang/miri/issues/2433 this assertion has been seen to trigger, so it might be worth actually checking this? Regressing debug assertions are very easy to miss until much later, and then they become quite hard to debug.
2022-11-20 01:16:52 +00:00
Steven Tang
a1ea1c128d
Check that library is file 2022-11-20 10:48:55 +11:00
Steven Tang
40b7e0e525
Fix metadata_lib_filename_form 2022-11-20 10:48:48 +11:00
Steven Tang
1e4adaf11f
Fix CrateLocationUnknownType error 2022-11-20 10:48:37 +11:00
Santiago Pastorino
520fafe5c2
Create def_id for async fns during lowering 2022-11-19 19:17:14 -03:00
ouz-a
90128c30a0 revert-overflow 2022-11-19 22:43:12 +03:00
Nilstrieb
4e9ceef76d
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.
2022-11-19 20:07:18 +01:00
bors
c5d82ed7a4 Auto merge of #102795 - lukas-code:constify-is-aligned-via-align-offset, r=oli-obk
Constify `is_aligned` via `align_offset`

Alternative to https://github.com/rust-lang/rust/pull/102753

Make `align_offset` work in const eval (and not always return `usize::MAX`) and then use that to constify `is_aligned{_to}`.

Tracking Issue: https://github.com/rust-lang/rust/issues/104203
2022-11-19 18:57:39 +00:00
Mahmoud Mazouz
01f2a15420
Fix substraction with overflow in wrong_number_of_generic_args.rs
Rarranging the substration and equality check into an addition and an equality
check is sufficient.

Algebra is cool, isn't it?

Co-authored-by: Michael Goulet <michael@errs.io>
2022-11-19 18:53:36 +01:00
Arpad Borsos
b59090ebe3
Lower return type outside async block creation
This allows feeding a different output type to async blocks with a
different `ImplTraitContext`.
2022-11-19 18:23:32 +01:00
Nilstrieb
825b8db34a
Cleanup macro matching recovery
The retry has been implemented already.
2022-11-19 17:46:04 +01:00
Lukas Markeffsky
3d7e9c4b7f Revert "don't call align_offset during const eval, ever"
This reverts commit f3a577bfae376c0222e934911865ed14cddd1539.
2022-11-19 16:58:02 +01:00
Lukas Markeffsky
9e5d497b67 fix const align_offset implementation 2022-11-19 16:57:58 +01:00
Lukas Markeffsky
60f352fd7d replace potential ICE with graceful error (no_core only) 2022-11-19 16:47:42 +01:00
Lukas Markeffsky
a906f6cb69 don't call align_offset during const eval, ever 2022-11-19 16:47:42 +01:00
Lukas Markeffsky
211743b2c8 make const align_offset useful 2022-11-19 16:36:08 +01:00
Lukas Markeffsky
f770fecfe1 unify inherent impls of CompileTimeEvalContext 2022-11-19 16:36:08 +01:00
Lukas Markeffsky
f13c4f4d6a constify exact_div intrinsic 2022-11-19 16:36:08 +01:00
Matthias Krüger
c571b2a964
Rollup merge of #104593 - compiler-errors:rpitit-object-safety-spans, r=fee1-dead
Improve spans for RPITIT object-safety errors

No reason why we can't point at the `impl Trait` that causes the object-safety violation.

Also [drive-by: Add is_async fn to hir::IsAsync](c4165f3a96), which touches clippy too.
2022-11-19 15:35:23 +01:00
Matthias Krüger
e86f1845ff
Rollup merge of #104497 - lyming2007:issue-104379-fix, r=fee1-dead
detect () to avoid redundant <> suggestion for type

fix #104379
2022-11-19 15:35:21 +01:00
Matthias Krüger
06707c073d
Rollup merge of #104469 - estebank:long-types, r=oli-obk
Make "long type" printing type aware and trim types in E0275

Instead of simple string cutting, use a custom printer to hide parts of long printed types.

On E0275, check for type length before printing.
2022-11-19 15:35:21 +01:00
Matthias Krüger
52cc0d5360
Rollup merge of #103117 - joshtriplett:use-is-terminal, r=eholk
Use `IsTerminal` in place of `atty`

In any crate that can use nightly features, use `IsTerminal` rather than
`atty`:

- Use `IsTerminal` in `rustc_errors`
- Use `IsTerminal` in `rustc_driver`
- Use `IsTerminal` in `rustc_log`
- Use `IsTerminal` in `librustdoc`
2022-11-19 15:35:18 +01:00
Ralf Jung
3338244f69 deduplicate constant evaluation in cranelift backend
also sync LLVM and cranelift structure a bit
2022-11-19 14:08:12 +01:00
bors
5e6de2369c Auto merge of #103509 - compiler-errors:opaques-w-bound-vars-r-hard, r=oli-obk
Revert "Normalize opaques with escaping bound vars"

This caused a perf regression in #103423, cc `@skyzh` this should fix #103423.

reverts #100980

r? `@oli-obk`
2022-11-19 09:30:35 +00:00
Dylan DPC
3cf3a65a71
Rollup merge of #104580 - notriddle:notriddle/issue-102354-hide-sugg, r=compiler-errors
diagnostics: only show one suggestion for method -> assoc fn

Fixes #102354
2022-11-19 11:54:47 +05:30
Dylan DPC
3c6fc06906
Rollup merge of #104566 - matthiaskrgr:clippy_perf_nov18, r=oli-obk
couple of clippy::perf fixes
2022-11-19 11:54:46 +05:30
Dylan DPC
7f35493e99
Rollup merge of #104554 - BoxyUwU:less_unchecked_pls, r=lcnr
Use `ErrorGuaranteed::unchecked_claim_error_was_emitted` less

there are only like 3 or 4 call sites left after this but it wasnt obvious to me how to remove them
2022-11-19 11:54:45 +05:30
Dylan DPC
00876c68c4
Rollup merge of #104411 - lcnr:bivariance-nll, r=compiler-errors
nll: correctly deal with bivariance

fixes #104409

when in a bivariant context, relating stuff should always trivially succeed. Also changes the mir validator to correctly deal with higher ranked regions.

r? types cc ``@RalfJung``
2022-11-19 11:54:44 +05:30
Dylan DPC
aeeac5dd0c
Rollup merge of #104001 - Ayush1325:custom-entry, r=bjorn3
Improve generating Custom entry function

This commit is aimed at making compiler-generated entry functions (Basically just C `main` right now) more generic so other targets can do similar things for custom entry. This was initially implemented as part of https://github.com/rust-lang/rust/pull/100316.

Currently, this moves the entry function name and Call convention to the target spec.

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-11-19 11:54:43 +05:30
Michael Goulet
5384af01e3 Probe + better error messsage for need_migrate_deref_output_trait_object 2022-11-19 06:09:29 +00:00
Michael Goulet
c36ff28d42 drive-by: PolyExistentialPredicate 2022-11-19 04:04:27 +00:00
Michael Goulet
9a9d0f40b8 Improve spans for RPITIT object-safety errors 2022-11-19 02:34:37 +00:00
bors
becc24a23a Auto merge of #97870 - eggyal:inplace_fold_spec, r=wesleywiser
Use liballoc's specialised in-place vec collection

liballoc already specialises in-place vector collection, so manually
reimplementing it in `IdFunctor::try_map_id` was superfluous.
2022-11-19 02:28:47 +00:00
Michael Goulet
c4165f3a96 drive-by: Add is_async fn to hir::IsAsync 2022-11-19 02:22:24 +00:00
bors
ff0ffda6b3 Auto merge of #104591 - Manishearth:rollup-b3ser4e, r=Manishearth
Rollup of 8 pull requests

Successful merges:

 - #102977 (remove HRTB from `[T]::is_sorted_by{,_key}`)
 - #103378 (Fix mod_inv termination for the last iteration)
 - #103456 (`unchecked_{shl|shr}` should use `u32` as the RHS)
 - #103701 (Simplify some pointer method implementations)
 - #104047 (Diagnostics `icu4x` based list formatting.)
 - #104338 (Enforce that `dyn*` coercions are actually pointer-sized)
 - #104498 (Edit docs for `rustc_errors::Handler::stash_diagnostic`)
 - #104556 (rustdoc: use `code-header` class to format enum variants)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-18 23:20:53 +00:00
Manish Goregaokar
a065e97bdc
Rollup merge of #104498 - pierwill:stash-diag-docs, r=compiler-errors
Edit docs for `rustc_errors::Handler::stash_diagnostic`

Clarify that the diagnostic can be retrieved with `steal_diagnostic`.

r? ```@compiler-errors```
2022-11-18 17:48:19 -05:00
Manish Goregaokar
24ee599195
Rollup merge of #104338 - compiler-errors:pointer-sized, r=eholk
Enforce that `dyn*` coercions are actually pointer-sized

Implement a perma-unstable, rudimentary `PointerSized` trait to enforce `dyn*` casts are `usize`-sized for now, at least to prevent ICEs and weird codegen issues from cropping up after monomorphization since currently we enforce *nothing*.

This probably can/should be removed in favor of a more sophisticated trait for handling `dyn*` conversions when we decide on one, but I just want to get something up for discussion and experimentation for now.

r? ```@eholk``` cc ```@tmandry``` (though feel free to claim/reassign)

Fixes #102141
Fixes #102173
2022-11-18 17:48:18 -05:00
Charles Lew
b22cb90e0a Update crate documentation of rustc_baked_icu_data crate 2022-11-18 14:46:36 -08:00
Charles Lew
b21e0b82c5 Fix compilation issue after rebase 2022-11-18 14:46:36 -08:00
Charles Lew
707c035e00 Include zh locale in icu data 2022-11-18 14:46:35 -08:00
Charles Lew
d15b020278 Enable icu sync feature for parallel compiler 2022-11-18 14:46:35 -08:00
Charles Lew
bde2f9857b Import icu locale fallback data 2022-11-18 14:46:35 -08:00
Charles Lew
a775004322 Migrate diagnostics list output to use icu list formatter. 2022-11-18 14:46:35 -08:00
Charles Lew
42d3bda08c Add rustc_baked_icu_data crate. 2022-11-18 14:46:35 -08:00
bors
b833ad56f4 Auto merge of #104573 - matthiaskrgr:rollup-k36ybtp, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #101162 (Migrate rustc_resolve to use SessionDiagnostic, part # 1)
 - #103386 (Don't allow `CoerceUnsized` into `dyn*` (except for trait upcasting))
 - #103405 (Detect incorrect chaining of if and if let conditions and recover)
 - #103594 (Fix non-associativity of `Instant` math on `aarch64-apple-darwin` targets)
 - #104006 (Add variant_name function to `LangItem`)
 - #104494 (Migrate GUI test to use functions)
 - #104516 (rustdoc: clean up sidebar width CSS)
 - #104550 (fix a typo)

Failed merges:

 - #104554 (Use `ErrorGuaranteed::unchecked_claim_error_was_emitted` less)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-18 20:26:58 +00:00
Daniel Paoliello
67e746cc68 Workaround for private global symbol issue 2022-11-18 11:38:31 -08:00
Michael Goulet
39e076a2e7 Only enforce ABI-mandated align, not preferred align is compatible 2022-11-18 18:23:48 +00:00
Michael Goulet
b3da04aa52 Check both align and size in PointerSized 2022-11-18 18:23:48 +00:00
Michael Goulet
da3c5397a6 Enforce that dyn* casts are actually pointer-sized 2022-11-18 18:23:48 +00:00
Michael Goulet
b8a92c1dd6 Revert "Normalize opaques with escaping bound vars"
This reverts commit 43119d6438.
2022-11-18 17:40:14 +00:00
Michael Howell
df7ecbcb11 diagnostics: only show one suggestion for method -> assoc fn
Fixes #102354
2022-11-18 10:39:26 -07:00
Michael Goulet
bb0cb9ae9f Add a detailed note for missing comma in FRU syntax typo 2022-11-18 17:27:55 +00:00
bors
70fe5f08ff Auto merge of #101562 - nnethercote:shrink-ast-Expr-harder, r=petrochenkov
Shrink `ast::Expr` harder

r? `@ghost`
2022-11-18 16:56:12 +00:00
Esteban Küber
bcb2655a9a review comment 2022-11-18 08:46:48 -08:00
Esteban Küber
3debf5006a Only use ... instead of _ for type elision
`_` might confuse people into believing that the type isn't known,
while `...` is not used anywhere else for types and is not valid
syntax, making it more likely to convey the right understanding.
2022-11-18 08:46:47 -08:00
Esteban Küber
4ed1376490 On E0275 do not print out the full type in the msg
When printing requirement overflow errors, do not print out the full
type name when it is longer than 50 characters long.
2022-11-18 08:46:47 -08:00
Esteban Küber
787e633d1a On overflow errors, do not print out long types 2022-11-18 08:46:47 -08:00
Esteban Küber
d49c10ac62 Make "long type" printing type aware
Instead of simple string cutting, use a custom printer to hide parts of
long printed types.
2022-11-18 08:42:59 -08:00
Boxy
45a09a4683 review comments 2 electric boogalo 2022-11-18 13:45:47 +00:00
Boxy
9ed348376f require an ErrorGuaranteed to taint infcx with errors 2022-11-18 13:25:17 +00:00
Boxy
1c48039a87 rename is_tainted_by_errors 2022-11-18 13:25:17 +00:00
Boxy
3fca95a597 track_errors use a delay_span_bug 2022-11-18 13:25:17 +00:00
Boxy
95a267bb34 make replaced_with_error store ErrorGuaranteed 2022-11-18 13:25:17 +00:00
Boxy
9c510048fd InferCtxt::is_tainted_by_errors returns ErrorGuaranteed 2022-11-18 13:25:17 +00:00
Boxy
c1ec8ff14d dont unchecked create ErrorGuaranteed in BorrowckErrors 2022-11-18 13:25:17 +00:00
Ralf Jung
09a887cebf review feedback 2022-11-18 14:24:48 +01:00
Matthias Krüger
7e5e520c7d
Rollup merge of #104550 - RalfJung:typo, r=compiler-errors
fix a typo

r? `@lcnr`
2022-11-18 14:13:39 +01:00
Matthias Krüger
2ea012619e
Rollup merge of #104006 - flip1995:lang-items-clippy, r=oli-obk
Add variant_name function to `LangItem`

Clippy has an internal lint that checks for the usage of hardcoded def paths and suggests to replace them with a lang or diagnostic item, if possible. This was implemented with a hack, by getting all the variants of the `LangItem` enum and then index into it with the position of the `LangItem` in the `items` list. This is no longer possible, because the `items` list can't be accessed anymore.

Follow up to #103603

cc `@camsteffen`
r? `@oli-obk`

This is blocking the sync between Clippy and Rust. I'm not sure if this is the best solution here, or if I should add a method `items()` to `LanguageItems` and keep the code in Clippy unchanged.
2022-11-18 14:13:37 +01:00
Matthias Krüger
3efbf30220
Rollup merge of #103405 - chenyukang:yukang/fix-103381-and-if, r=compiler-errors
Detect incorrect chaining of if and if let conditions and recover

Fixes #103381
2022-11-18 14:13:36 +01:00
Matthias Krüger
741f3cf383
Rollup merge of #103386 - compiler-errors:no-coerceunsized-to-dynstar, r=eholk
Don't allow `CoerceUnsized` into `dyn*` (except for trait upcasting)

This makes sure we don't accidentally allow coercions like `Box<T>` -> `Box<dyn* Trait>`, or in the case of this ICE, `&T` to `&dyn* Trait`. These coercions don't make sense, at least not via the `CoerceUnsized` trait.

Fixes #102172
Fixes #102429
2022-11-18 14:13:35 +01:00
Matthias Krüger
3e5965722c
Rollup merge of #101162 - rajputrajat:master, r=davidtwco
Migrate rustc_resolve to use SessionDiagnostic, part # 1

crate a somewhat on larger size, so plz allow some time to get it finished.
2022-11-18 14:13:35 +01:00
bors
fd3bfb3551 Auto merge of #104330 - CastilloDel:ast_lowering, r=cjgillot
Remove allow(rustc::potential_query_instability) from rustc_ast_lowering

Related to https://github.com/rust-lang/rust/issues/84447.

`@cjgillot` Thanks for helping me!
2022-11-18 13:12:18 +00:00
Matthias Krüger
e3036df003 couple of clippy::perf fixes 2022-11-18 10:30:47 +01:00
Ralf Jung
4101889786 interpret: use Either over Result when it is not representing an error condition 2022-11-18 10:18:32 +01:00
Deadbeef
bc51f8783c rename to string_deref_patterns 2022-11-18 06:16:20 +00:00
Deadbeef
64a17a09a8 Rm diagnostic item, use lang item 2022-11-18 06:16:20 +00:00
Cameron Steffen
9cf6ce070d Remove more PlaceBuilder clones 2022-11-17 19:01:05 -06:00
Cameron Steffen
105abe39c0 Replace into_place with to_place 2022-11-17 19:01:05 -06:00
Cameron Steffen
be5b7778c8 Replace try_upvars_resolved with try_to_place 2022-11-17 19:01:05 -06:00
Cameron Steffen
1c819792a7 Introduce PlaceBuilder::resolve_upvar by ref 2022-11-17 19:01:05 -06:00
pierwill
19b63bc791 Edit docs for rustc_errors::Handler::stash_diagnostic
Clarify that the diagnostic can be retrieved with `steal_diagnostic`.
2022-11-17 15:45:46 -06:00
Matthias Krüger
239f84bc51
Rollup merge of #104545 - flip1995:diag_item_matches_macro, r=compiler-errors
Readd the matches_macro diag item

This is now used by Clippy

r? `@compiler-errors`

This was removed in #104383. But in the meantime Clippy now makes use of it dac600e32f/clippy_lints/src/manual_is_ascii_check.rs (L153)

---

This is blocking the Clippy sync. (kinda. I could work around it, but I don't want to play ping-pong with this change.)
2022-11-17 22:33:22 +01:00
Matthias Krüger
58292874e1
Rollup merge of #104515 - chenyukang:yukang/fix-104510-ice, r=compiler-errors
ICE fixing, remove is_tainted_by_errors since we have ty_error for delay bug

Fixes #104510
2022-11-17 22:33:21 +01:00
Matthias Krüger
43fa2918d1
Rollup merge of #104508 - compiler-errors:dyn-return, r=oli-obk
Check `dyn*` return type correctly

In `check_fn`, if the declared return type is `dyn Trait`, then we check the return type separately to produce better diagnostics, because this is never valid -- however, when `dyn*` was introduced, this check was never adjusted to only account for *unsized* `dyn Trait` and not *sized* `dyn* Trait`.

Fixes #104501
2022-11-17 22:33:21 +01:00
Matthias Krüger
ed97f245f1
Rollup merge of #104483 - oli-obk:santa-clauses-make-goals, r=compiler-errors
Convert predicates into Predicate in the Obligation constructor

instead of having almost all callers do that.

This reduces a bit of boilerplate, and also paves the way for my work towards https://github.com/rust-lang/compiler-team/issues/531 (as it makes it easier to accept both goals and clauses where right now it only accepts predicates).
2022-11-17 22:33:19 +01:00
Matthias Krüger
1c52c247f9
Rollup merge of #104444 - chenyukang:yukang/fix-104390, r=compiler-errors
Fix ICE in in_operand for ty error

Fixes #104390

By the way, moving some test cases to proper directory for tidy bless.
2022-11-17 22:33:19 +01:00
Matthias Krüger
c9ccb0ba28
Rollup merge of #104433 - TaKO8Ki:fix-104392, r=estebank
Fix `emit_unused_delims_expr` ICE

Fixes #104392
2022-11-17 22:33:18 +01:00
Matthias Krüger
1521795a7d
Rollup merge of #103852 - compiler-errors:rpitit-early-from-impl, r=lcnr
Don't remap early-bound regions for return-position `impl Trait` in trait originating from `impl`

long title 😓

We don't want to remap early-bound regions that originate from the `impl`s themselves, since they have no corresponding region in the trait. Not sure if there's a better condition than checking if the EBR's def-id's parent is the impl -- maybe we should be checking if the region comes from the method or RPITIT... 🤷

r? types

Fixes #103850
2022-11-17 22:33:17 +01:00
Ralf Jung
ff38c2891d fix a typo 2022-11-17 21:13:23 +01:00
Philipp Krones
4e65f5ea82
Add variant_name function to LangItem
Clippy has an internal lint that checks for the usage of hardcoded def
paths and suggests to replace them with a lang or diagnostic item, if
possible. This was implemented with a hack, by getting all the variants
of the `LangItem` enum and then index into it with the position of the
`LangItem` in the `items` list. This is no longer possible, because the
`items` list can't be accessed anymore.
2022-11-17 20:06:25 +01:00
Philipp Krones
34a14349b7
Readd the matches_macro diag item
This is now used by Clippy
2022-11-17 19:32:28 +01:00
bors
83356b78c4 Auto merge of #104361 - vladimir-ea:watchos_fix_linking, r=oli-obk
[watchos] Dynamic linking is not allowed for watchos targets

Dynamic linking of all apple targets was (re-) enabled in PR #100636. However, dynamic linking is not allowed on WatchOS so this broke the build of standard library for WatchOS.

This change disables dynamic linking for WatchOS non-simulator targets.
2022-11-17 17:15:31 +00:00
Yiming Lei
867582eb97 detect () to avoid redundant <> suggestion for type
fix #104379
2022-11-17 09:01:27 -08:00
bors
b6097f2e1b Auto merge of #104219 - bryangarza:async-track-caller-dup, r=eholk
Support `#[track_caller]` on async fns

Adds `#[track_caller]` to the generator that is created when we desugar the async fn.

Fixes #78840

Open questions:
- What is the performance impact of adding `#[track_caller]` to every `GenFuture`'s `poll(...)` function, even if it's unused (i.e., the parent span does not set `#[track_caller]`)? We might need to set it only conditionally, if the indirection causes overhead we don't want.
2022-11-17 13:47:03 +00:00
Deadbeef
0537d301c5 Add feature gate 2022-11-17 12:46:43 +00:00
Deadbeef
b2cb42d6a7 Minimal implementation of implicit deref patterns 2022-11-17 12:46:43 +00:00
Ayush Singh
2436dff772
Use custom entry name in cranelift
This is a continuation of 9f0a8620bd for
cranelift.

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-11-17 15:28:47 +05:30
Qiu Chaofan
aef3d938e4 Add powerpc64-ibm-aix as Tier-3 target 2022-11-17 16:36:54 +08:00
Ralf Jung
99f7e9494e try_normalize_after_erasing_regions: promote an assertion to always run 2022-11-17 09:06:15 +01:00
bors
7c75fe4c85 Auto merge of #104170 - cjgillot:hir-def-id, r=fee1-dead
Record `LocalDefId` in HIR nodes instead of a side table

This is part of an attempt to remove the `HirId -> LocalDefId` table from HIR.
This attempt is a prerequisite to creation of `LocalDefId` after HIR lowering (https://github.com/rust-lang/rust/pull/96840), by controlling how `def_id` information is accessed.

This first part adds the information to HIR nodes themselves instead of a table.
The second part is https://github.com/rust-lang/rust/pull/103902
The third part will be to make `hir::Visitor::visit_fn` take a `LocalDefId` as last parameter.
The fourth part will be to completely remove the side table.
2022-11-17 07:42:27 +00:00
Divam Narula
693c6311f0
Throw error on failure in loading llvm-plugin 2022-11-17 15:25:18 +09:00
Nicholas Nethercote
67d5cc0462 Use ThinVec in ast::Path. 2022-11-17 13:56:38 +11:00
Nicholas Nethercote
6b7ca2fcf2 Box ExprKind::{Closure,MethodCall}, and QSelf in expressions, types, and patterns. 2022-11-17 13:45:59 +11:00
bors
251831ece9 Auto merge of #103138 - nnethercote:merge-BBs, r=bjorn3
Merge basic blocks where possible when generating LLVM IR.

r? `@ghost`
2022-11-17 01:56:24 +00:00
bors
bebd57a960 Auto merge of #102944 - nnethercote:ast-Lit-third-time-lucky, r=petrochenkov
Use `token::Lit` in `ast::ExprKind::Lit`.

Instead of `ast::Lit`.

Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing.

r? `@petrochenkov`
2022-11-16 23:03:14 +00:00
Michael Goulet
75afb22331 Check dyn* return type correctly 2022-11-16 22:21:41 +00:00
Maybe Waffle
94470f4efd Use as_deref in compiler (but only where it makes sense) 2022-11-16 21:58:58 +00:00
Matthias Krüger
163a7090b8
Rollup merge of #104394 - oli-obk:suggest_method_call, r=lcnr
various cleanups to try to reduce the use of spans inside method resolution

definitely review commit by commit.
2022-11-16 15:39:46 +01:00
Matthias Krüger
e033a389e1
Rollup merge of #104335 - Nilstrieb:macrowo, r=compiler-errors
Only do parser recovery on retried macro matching

Eager parser recovery can break macros, so we don't do it at first. But when we already know that the macro failed, we can retry it with recovery enabled to still emit useful diagnostics.

Helps with #103534
2022-11-16 15:39:46 +01:00
Matthias Krüger
353b915fec
Rollup merge of #104317 - RalfJung:ctfe-error-reporting, r=oli-obk
cleanup and dedupe CTFE and Miri error reporting

It looks like most of the time, this error raised from const_prop_lint is just redundant -- it duplicates the error reported when evaluating the const-eval query. This lets us make `ConstEvalErr` private to the const_eval module which I think is a good step.

The Miri change mostly replaces a `match` by `if let`, and dedupes the "this error is impossible in Miri" checks.

r? ``@oli-obk``
Fixes https://github.com/rust-lang/rust/issues/75461
2022-11-16 15:39:45 +01:00
Matthias Krüger
fbcd751ea1
Rollup merge of #104137 - StackDoubleFlow:err-lsc-unsupported, r=bjorn3
Issue error when -C link-self-contained option is used on unsupported platforms

The documentation was also updated to reflect this.

I'm assuming the supported platforms are the same as initially written in [RELEASES.md](https://github.com/rust-lang/rust/blob/master/RELEASES.md#compiler-17).

Fixes #103576
2022-11-16 15:39:45 +01:00
Matthias Krüger
56a28a65f5
Rollup merge of #103750 - calebzulawski:master, r=workingjubilee
Fix some misleading target feature aliases

This is the first half of a fix for #100752.  It looks like these aliases were added in #78361 and slipped under the radar, as these features are not AVX512.  These features _do_ add AVX512 instructions when used _in combination_ with AVX512F, but without AVX512F, these features still provide 128-bit and 256-bit vector instructions.  A user might be mislead into thinking these features imply AVX512F (which is true of the actual AVX512 features).  This PR allows using the names as defined by LLVM, which matches Intel documentation.

A future PR should change the `std::arch` intrinsics to use these names, and finally remove these aliases from rustc.

r? ```@workingjubilee```

cc ```@Amanieu```
2022-11-16 15:39:44 +01:00
Maybe Waffle
e2a28165a3 Fix perf regression by correctly matching keywords 2022-11-16 13:42:30 +00:00
yukang
9c2d4dd529 fix #104510, Remove is_tainted_by_errors since we have ty_error for delay bug 2022-11-16 19:41:08 +08:00
yukang
20ea083d87 fix #104390, fix ICE in in_operand for ty error 2022-11-16 17:48:13 +08:00
Oli Scherer
4f11f3b257 Convert predicates into Predicate in the Obligation constructor 2022-11-16 09:25:19 +00:00
Oli Scherer
634df06fae Generalize the ToPredicate trait
Its name is now not accurate anymore, but we'll adjust that later
2022-11-16 09:20:28 +00:00
Ralf Jung
1115ec601a cleanup and dedupe CTFE and Miri error reporting 2022-11-16 10:13:29 +01:00
Matthias Krüger
3a8cacd7fb
Rollup merge of #104348 - fmease:iat-vis-stab, r=cjgillot
Respect visibility & stability of inherent associated types

As discussed in #103621, this probably won't be the final location of the code that resolves inherent associated types. Still, I think it's valuable to push correctness fixes for this feature (in regards to visibility and stability).

Let me know if I should write a translatable diagnostic instead and if I should move the tests to `privacy/` and `stability-attribute/` respectively.

Fixes #104243.
````@rustbot```` label A-visibility F-inherent_associated_types
r? ````@cjgillot```` (since you reviewed #103621, feel free to reroll though)
2022-11-16 08:36:11 +01:00
Matthias Krüger
88a19197b9
Rollup merge of #104193 - TaKO8Ki:fix-104142, r=cjgillot
Shift no characters when using raw string literals

Fixes #104142

Given the following code:

```rust
fn main() {
    println!(r#"\'\'\'\'\'\'\'\'\'\'\'\'\'\'}"#);
}
```

The current output is:

```
error: invalid format string: unmatched `}` found
 --> src/main.rs:2:59
  |
2 |     println!(r#"\'\'\'\'\'\'\'\'\'\'\'\'\'\'}"#); //~ ERROR invalid format string: unmatched `}` found
  |                                                           ^ unmatched `}` in format string
  |
  = note: if you intended to print `}`, you can escape it using `}}`

error: could not compile `debug_playground` due to previous error
```

The output should look like:

```
error: invalid format string: unmatched `}` found
 --> src/main.rs:2:45
  |
2 |     println!(r#"\'\'\'\'\'\'\'\'\'\'\'\'\'\'}"#); //~ ERROR invalid format string: unmatched `}` found
  |                                             ^ unmatched `}` in format string
  |
  = note: if you intended to print `}`, you can escape it using `}}`

error: could not compile `debug_playground` due to previous error
```

This pull request fixes the wrong span for `invalid format string` error and also solves the ICE.
2022-11-16 08:36:11 +01:00
Matthias Krüger
5140bbd102
Rollup merge of #103484 - saschanaz:patch-2, r=ehuss
Add `rust` to `let_underscore_lock` example

Currently https://doc.rust-lang.org/beta/rustc/lints/listing/deny-by-default.html#let-underscore-lock has no colored grammar and raw `{{produces}}` command is exposed.
2022-11-16 08:36:10 +01:00
Nicholas Nethercote
54082dd216 Merge basic blocks where possible when generating LLVM IR.
In `codegen_assert_terminator` we decide if a BB's successor is a
candidate for merging, which requires that it be the only successor, and
that it only have one predecessor. That result then gets passed down,
and if it reaches `funclet_br` with the appropriate BB characteristics,
then no `br` instruction is issued, a `MergingSucc::True` result is
passed back, and the merging proceeds in `codegen_block`.

The commit also adds `CachedLlbb`, a new type to help keep track of
each BB that has been merged into its predecessor.
2022-11-16 15:46:39 +11:00
Nicholas Nethercote
68194aa8d5 Use &mut Bx more.
For the next commit, `FunctionCx::codegen_*_terminator` need to take a
`&mut Bx` instead of consuming a `Bx`. This triggers a cascade of
similar changes across multiple functions. The resulting code is more
concise and replaces many `&mut bx` expressions with `bx`.
2022-11-16 15:46:39 +11:00
bors
79146baa9c Auto merge of #102570 - cjgillot:deagg-debuginfo, r=oli-obk
Perform simple scalar replacement of aggregates (SROA) MIR opt

This is a re-open of https://github.com/rust-lang/rust/pull/85796

I copied the debuginfo implementation (first commit) from `@eddyb's` own SROA PR.

This pass replaces plain field accesses by simple locals when possible.
To be eligible, the replaced locals:
- must not be enums or unions;
- must not be used whole;
- must not have their address taken.

The storage and deinit statements are duplicated on each created local.

cc `@tmiasko` who reviewed the former version of this PR.
2022-11-15 23:52:22 +00:00
Nicholas Nethercote
358a603f11 Use token::Lit in ast::ExprKind::Lit.
Instead of `ast::Lit`.

Literal lowering now happens at two different times. Expression literals
are lowered when HIR is crated. Attribute literals are lowered during
parsing.

This commit changes the language very slightly. Some programs that used
to not compile now will compile. This is because some invalid literals
that are removed by `cfg` or attribute macros will no longer trigger
errors. See this comment for more details:
https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773
2022-11-16 09:41:28 +11:00
Kagami Sascha Rosylight
0a528b16fc
Merge branch 'master' into patch-2 2022-11-15 21:16:11 +01:00
Nilstrieb
b7b67228f9
Only do parser recovery on retried macro matching
This prevents issues with eager parser recovery during macro matching.
2022-11-15 19:34:35 +01:00
Camille GILLOT
779007da06 Enable SROA by at mir-opt level 3. 2022-11-15 17:59:36 +00:00
Camille GILLOT
e4f343191a Flatten aggregates into locals. 2022-11-15 17:55:11 +00:00
Camille GILLOT
b550eabfa6 Introduce composite debuginfo. 2022-11-15 17:53:50 +00:00
bors
a00f8ba7fc Auto merge of #104054 - RalfJung:byte-provenance, r=oli-obk
interpret: support for per-byte provenance

Also factors the provenance map into its own module.

The third commit does the same for the init mask. I can move it in a separate PR if you prefer.

Fixes https://github.com/rust-lang/miri/issues/2181

r? `@oli-obk`
2022-11-15 17:37:15 +00:00
Ayush Singh
6dfe2395c9
Use custom entry name in gcc
This is a continuation of 9f0a8620bd for
gcc.

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-11-15 22:15:55 +05:30
lcnr
b2e6d08e3f use ocx type relation routines 2022-11-15 14:13:47 +01:00
Daniel del Castillo
557226348f Update compiler/rustc_ast_lowering/src/item.rs
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2022-11-15 13:57:25 +01:00
CastilloDel
fdb5fe2ed8 Change LoweringContext.children to Vec 2022-11-15 13:57:24 +01:00
CastilloDel
d1eab51f47 Make clobber_abis use an FxIndexMap
It seems to be used more for lookup than iteration, so this could be a
perf hit
2022-11-15 13:57:24 +01:00
CastilloDel
769cc733b1 Remove allow(rustc::potential_query_instability) from rustc_ast_lowering 2022-11-15 13:57:24 +01:00