Commit Graph

672 Commits

Author SHA1 Message Date
Esteban Küber
e46416eed6 Change pattern borrowing suggestions to be verbose
Synthesize a more accurate span and use verbose suggestion output to
make the message clearer.
2022-12-13 10:06:13 -08:00
Takayuki Maeda
ee40a67cd9 remove unnecessary uses of clone 2022-12-13 02:06:24 +09:00
Jakob Degen
9fb8da8f8f Remove unneeded field from SwitchTargets 2022-12-09 04:53:10 -08: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
Maybe Waffle
c75817fb1b rustc_borrowck: remove ref patterns 2022-12-06 14:45:58 +00:00
Michael Goulet
e940f845be drive-by: Default param for ToPredicate 2022-12-06 00:19:55 +00:00
Oli Scherer
4f593ce5d8 Create format_args as late as possible 2022-12-01 08:49:51 +00:00
bors
24606deaf4 Auto merge of #104905 - compiler-errors:normalization-changes, r=spastorino
Some initial normalization method changes

1. Rename `AtExt::normalize` to `QueryNormalizeExt::query_normalize` (using the `QueryNormalizer`)
2. Introduce `NormalizeExt::normalize` to replace `partially_normalize_associated_types_in` (using the `AssocTypeNormalizer`)
3. Rename `FnCtxt::normalize_associated_types_in` to `FnCtxt::normalize`
4. Remove some unused other normalization fns in `Inherited` and `FnCtxt`

Also includes one drive-by where we're no longer creating a `FnCtxt` inside of `check_fn`, but passing it in. This means we don't need such weird `FnCtxt` construction logic.

Stacked on top of #104835 for convenience.

r? types
2022-11-30 11:13:09 +00:00
Matthias Krüger
3617adfaee
Rollup merge of #103876 - oli-obk:tait_implications, r=lcnr
type alias impl trait: add tests showing that hidden type only outlives lifetimes that occur in bounds

fixes #103642

https://github.com/rust-lang/rust/pull/102417 only made sure that hidden types cannot outlive lifetimes other than the ones mentioned on bounds, but didn't allow us to actually infer anything from that.

cc `@aliemjay`
2022-11-29 22:43:15 +01:00
Matthias Krüger
c81605ca91
Rollup merge of #104951 - Swatinem:async-kind, r=compiler-errors
Simplify checking for `GeneratorKind::Async`

Adds a helper method around `generator_kind` that makes matching async constructs simpler.
2022-11-29 05:24:21 +01:00
Arpad Borsos
2db0dc3297
Simplify checking for GeneratorKind::Async
Adds a helper method around `generator_kind` that makes matching async constructs simpler.
2022-11-28 23:12:01 +01:00
Michael Goulet
1e236acd05 Make ObligationCtxt::normalize take cause by borrow 2022-11-28 17:35:40 +00:00
Michael Goulet
fc710832ea partially_normalize_... -> At::normalize 2022-11-28 17:35:39 +00:00
Matthias Krüger
db2850c1fb
Rollup merge of #104956 - mucinoab:issue-104870, r=compiler-errors
Avoid ICE if the Clone trait is not found while building error suggestions

Fixes #104870

r? `@compiler-errors`
2022-11-28 17:25:49 +01:00
Bruno A. Muciño
7a378dd0fb Avoid ICE if the Clone trait is not found while building error suggestions 2022-11-27 20:50:13 -06:00
Matthias Krüger
86304f5149
Rollup merge of #104976 - WaffleLapkin:move_comments, r=cjgillot
Prefer doc comments over `//`-comments in compiler

Doc comments are generally nicer: they show up in the documentation, they are shown in IDEs when you hover other mentions of items, etc. Thus it makes sense to use them instead of `//`-comments.
2022-11-27 22:14:08 +01:00
bors
454784afba Auto merge of #104048 - cjgillot:split-lifetime, r=compiler-errors
Separate lifetime ident from lifetime resolution in HIR

Drive-by: change how suggested generic args are computed.
Fixes https://github.com/rust-lang/rust/issues/103815

I recommend reviewing commit-by-commit.
2022-11-27 14:30:19 +00:00
Maybe Waffle
1d42936b18 Prefer doc comments over //-comments in compiler 2022-11-27 11:19:04 +00:00
Guillaume Gomez
a2e485c25c
Rollup merge of #104786 - WaffleLapkin:amp-mut-help, r=compiler-errors
Use the power of adding helper function to simplify code w/ `Mutability`

r? `@compiler-errors`
2022-11-26 17:47:23 +01:00
Santiago Pastorino
974e2837bb
Introduce PredicateKind::Clause 2022-11-25 00:04:54 -03:00
Matthias Krüger
9a558b68e1
Rollup merge of #104773 - oli-obk:overlap, r=lcnr
OpaqueCast projections are always overlapping, they can't possibly be disjoint

r? ``@lcnr``
2022-11-24 21:34:53 +01:00
bors
5dfb4b0afa Auto merge of #104321 - Swatinem:async-gen, r=oli-obk
Avoid `GenFuture` shim when compiling async constructs

Previously, async constructs would be lowered to "normal" generators, with an additional `from_generator` / `GenFuture` shim in between to convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that async constructs will *directly* implement `Future` without the need to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation detail in stack traces and debuginfo, but it can in theory also help the optimizer as there is less abstractions to see through.

---

Given this demo code:

```rust
pub async fn a(arg: u32) -> Backtrace {
    let bt = b().await;
    let _arg = arg;
    bt
}

pub async fn b() -> Backtrace {
    Backtrace::force_capture()
}
```

I would get the following with the latest stable compiler (on Windows):

```
   4: async_codegen:🅱️:async_fn$0
             at .\src\lib.rs:10
   5: core::future::from_generator::impl$1::poll<enum2$<async_codegen:🅱️:async_fn_env$0> >
             at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\future\mod.rs:91
   6: async_codegen:🅰️:async_fn$0
             at .\src\lib.rs:4
   7: core::future::from_generator::impl$1::poll<enum2$<async_codegen:🅰️:async_fn_env$0> >
             at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\future\mod.rs:91
```

whereas now I get a much cleaner stack trace:

```
   3: async_codegen:🅱️:async_fn$0
             at .\src\lib.rs:10
   4: async_codegen:🅰️:async_fn$0
             at .\src\lib.rs:4
```
2022-11-24 17:14:42 +00:00
Arpad Borsos
9f36f988ad
Avoid GenFuture shim when compiling async constructs
Previously, async constructs would be lowered to "normal" generators,
with an additional `from_generator` / `GenFuture` shim in between to
convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that
async constructs will *directly* implement `Future` without the need
to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation
detail in stack traces and debuginfo, but it can in theory also help
the optimizer as there is less abstractions to see through.
2022-11-24 10:04:27 +01:00
Esteban Küber
78b8d126db Fix rebase 2022-11-23 13:06:27 -08:00
Maybe Waffle
4439f1f6a6 Add Mutability::mutably_str 2022-11-23 20:39:16 +00:00
Maybe Waffle
da40965300 Add Mutability::{is_mut,is_not} 2022-11-23 20:26:31 +00:00
Esteban Küber
0da4c44190 Account for closures 2022-11-23 12:17:48 -08:00
Esteban Küber
3a471b5fd8 Account for x @ y and suggest ref x @ ref y 2022-11-23 12:17:48 -08:00
Esteban Küber
3c905d4ccd review comments: inline bindings and fix typo 2022-11-23 12:17:48 -08:00
Esteban Küber
5993f5d0f8 Tweak output to account for alternative bindings in the same pattern 2022-11-23 12:17:47 -08:00
Esteban Küber
e6e7a6db28 Fix wording 2022-11-23 12:17:47 -08:00
Esteban Küber
d687d46f68 Tweak output in for loops
Do not suggest `.clone()` as we already suggest borrowing the iterated
value.
2022-11-23 12:17:47 -08:00
Esteban Küber
c0e481731b Remove logic duplication 2022-11-23 12:17:47 -08:00
Esteban Küber
42d7174bbc Extract suggestion logic to its own method 2022-11-23 12:17:47 -08:00
Esteban Küber
14a3d572e6 Use type_implements_trait 2022-11-23 12:17:47 -08:00
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
Maybe Waffle
8195e12dd9 Add Mutability::ref_prefix_str, order Mutability, simplify code 2022-11-23 19:36:27 +00:00
Camille GILLOT
fb7d25e978 Separate lifetime ident from resolution in HIR. 2022-11-23 19:33:06 +00:00
Oli Scherer
46b37e20af OpaqueCast projections are always overlapping, they can't possibly be disjoint 2022-11-23 14:37:13 +00: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
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
Maybe Waffle
b80356a5ab Use tcx.require_lang_item instead of unwrapping 2022-11-22 17:19:19 +00:00
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
Oli Scherer
7658e0fccf Stop passing the self-type as a separate argument. 2022-11-21 20:39:46 +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
ec8d01fdcc Allow iterators instead of requiring slices that will get turned into iterators 2022-11-21 20:33:55 +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
ca57832db6 Add more regression tests 2022-11-21 20:16:36 +00:00
Vadim Petrochenkov
7a5376d23c Unreserve braced enum variants in value namespace 2022-11-21 22:40:06 +03:00