Commit Graph

1976 Commits

Author SHA1 Message Date
Matthias Krüger
d8874f259a fix more clippy::style findings
match_result_ok
obfuscated_if_else
single_char_add
writeln_empty_string
collapsible_match
iter_cloned_collect
unnecessary_mut_passed
2022-12-25 17:32:26 +01:00
Matthias Krüger
d23cb738d2
Rollup merge of #105975 - jeremystucki:rustc-remove-needless-lifetimes, r=eholk
rustc: Remove needless lifetimes
2022-12-24 00:31:41 +01:00
nils
fd5af8cc23
Rollup merge of #105661 - lcnr:evaluate-new, r=compiler-errors
implement the skeleton of the updated trait solver

cc ```@rust-lang/initiative-trait-system-refactor```

This is mostly following the architecture discussed in the types team meetup.

After discussing the desired changes for the trait solver, we encountered cyclic dependencies between them. Most notably between changing evaluate to be canonical and returning inference constraints. We cannot canonicalize evaluate without returning inference constraints due to coinductive cycles. However, caching inference constraints also relies on canonicalization. Implementing both of these changes at once in-place is not feasible.

This somewhat closely mirrors the current `evaluate` implementation with the following notable differences:
- it moves `project` into the core solver, allowing us to correctly deal with coinductive projections (will be required for implied bounds, perfect derive)
- it changes trait solver overflow to be non-fatal (required to backcompat breakage from changes to the iteration order of nested goals, deferred projection equality, generally very useful)
- it returns inference constraints and canonicalizes inputs and outputs (required for a lot things, most notably merging fulfill and evaluate, and deferred projection equality)
- it is implemented to work with lazy normalization

A lot of things aren't yet implemented, but the remaining FIXMEs should all be fairly self-contained and parallelizable. If the architecture looks correct and is what we want here, I would like to quickly merge this and then split the work.

r? ```@compiler-errors``` / ```@rust-lang/types``` :3
2022-12-23 18:02:13 +01:00
Michael Goulet
85a9d85435 Don't call typeck if we have no typeck results
This has a 10000000% chance of us causing a cycle if we're not careful
2022-12-21 06:06:47 +00:00
Michael Goulet
c6ef53477e CollectAllMismatches relation should respect int/float infer vars 2022-12-21 06:06:46 +00:00
Michael Goulet
978dd2e3b8 Rename things to be a bit clearer 2022-12-21 06:06:46 +00:00
Michael Goulet
0c09e2bf5a Substitute things correctly 2022-12-21 06:06:46 +00:00
Michael Goulet
c8ebff6aee Remove some unnecessary try_map_bound 2022-12-21 06:06:46 +00:00
Jeremy Stucki
3dde32ca97
rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
lcnr
750bf36c33 dedup assembly 2022-12-20 07:30:24 +00:00
lcnr
a213bb36c9 implement the skeleton of the updated trait solver 2022-12-19 16:46:17 +00:00
Dylan DPC
3350ae9cef
Rollup merge of #105882 - compiler-errors:issue-105832, r=jackh726
Don't ICE in closure arg borrow suggestion

Fixes #105832
2022-12-19 14:41:36 +05:30
Dylan DPC
90035f130e
Rollup merge of #105839 - LegionMammal978:mut-upvar-not-send, r=lcnr
Suggest a `T: Send` bound for `&mut T` upvars in `Send` generators

Right now, we suggest a `T: Sync` bound for both `&T` and `&mut T` upvars. A user on URLO [found this confusing](https://users.rust-lang.org/t/error-complains-about-missing-sync-but-send-is-whats-missing/86021), so I wrote this quick fix to look at the mutability before making the suggestion.
2022-12-19 14:41:35 +05:30
Matthias Krüger
ebe3563764
Rollup merge of #105873 - matthiaskrgr:clippy_fmt, r=Nilstrieb
use &str / String literals instead of format!()
2022-12-18 23:03:07 +01:00
Matthias Krüger
221e71e7a1
Rollup merge of #105869 - matthiaskrgr:clone_on_copy, r=compiler-errors
don't clone Copy types
2022-12-18 23:03:07 +01:00
Matthias Krüger
e96166eb42
Rollup merge of #105867 - matthiaskrgr:rec_param, r=compiler-errors
remove redundant fn params that were only "used" in recursion
2022-12-18 23:03:06 +01:00
Michael Goulet
dd8897eb63 Don't ICE in closure arg borrow suggestion 2022-12-18 21:41:29 +00:00
Matthias Krüger
22379779b5
Rollup merge of #105875 - matthiaskrgr:needless_borrowed_reference, r=oli-obk
don't destuct references just to reborrow
2022-12-18 18:57:05 +01:00
Matthias Krüger
a108d55ce6 don't restuct references just to reborrow 2022-12-18 17:04:32 +01:00
Matthias Krüger
0aa4cde747 avoid .into() conversion to identical types 2022-12-18 16:20:32 +01:00
Matthias Krüger
3af7df91fc use &str / String literals instead of format!() 2022-12-18 16:17:46 +01:00
Matthias Krüger
6e52a0f421 remove redundant fn params that were only "used" in recursion 2022-12-18 14:27:07 +01:00
Matthias Krüger
fec9e9ecf1 don't clone Copy types 2022-12-18 14:25:55 +01:00
Matthew House
ee53452aec Suggest a T: Send bound for &mut T upvars in Send generators 2022-12-17 15:21:37 -05:00
bors
a803f313fd Auto merge of #105717 - compiler-errors:anonymize, r=jackh726
always use `anonymize_bound_vars`

Unless this is perf-sensitive, it's probably best to always use one anonymize function that does the right thing for all bound vars.

r? types
2022-12-16 06:45:08 +00:00
bors
39b2a41b39 Auto merge of #104334 - compiler-errors:ufcs-sugg-wrong-def-id, r=estebank
Use impl's def id when calculating type to specify in UFCS

Fixes #104327
Fixes #104328

Also addresses https://github.com/rust-lang/rust/pull/102670#discussion_r987381197
2022-12-16 03:57:10 +00:00
Matthias Krüger
abfad27fbc
Rollup merge of #105727 - estebank:use-impl-trait, r=oli-obk
Tweak output for bare `dyn Trait` in arguments

Fix #35825.
2022-12-15 22:02:59 +01:00
Matthias Krüger
24e584b991
Rollup merge of #105694 - ouz-a:issue_105689, r=estebank
Don't create dummy if val has escaping bounds var

Skips creating/pushing obligations if val has escaping bounds vars.

Fixes #105689
2022-12-15 22:02:59 +01:00
Esteban Küber
2492235c32 Consider lifetimes when comparing assoc types in method chain
Do not say "Type changed to X here" when the only difference is caused
by lifetimes.
2022-12-15 11:47:40 -08:00
Esteban Küber
30ae261c42 Use with_forced_trimmed_paths more 2022-12-15 11:13:44 -08:00
Esteban Küber
294944dfec Point at method chains on E0271 errors 2022-12-15 11:13:44 -08:00
bors
984eab57f7 Auto merge of #105746 - matthiaskrgr:rollup-sz3grbv, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #104592 (Ensure async trait impls are async (or otherwise return an opaque type))
 - #105623 (Fix `-Z print-type-sizes` for generators with discriminant field ordered first)
 - #105627 (Auto traits in `dyn Trait + Auto` are suggestable)
 - #105633 (Make `report_projection_error` more `Term` agnostic)
 - #105683 (Various cleanups to dest prop)
 - #105692 (Add regression test for #104678)
 - #105707 (rustdoc: remove unnecessary CSS `kbd { cursor: default }`)
 - #105715 (Do not mention long types in E0599 label)
 - #105722 (more clippy::complexity fixes)
 - #105724 (rustdoc: remove no-op CSS `.scrape-example .src-line-numbers { margin: 0 }`)
 - #105730 (rustdoc: remove no-op CSS `.item-info:before { color }`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-15 14:04:24 +00:00
Matthias Krüger
78cf8cc02e
Rollup merge of #105633 - compiler-errors:term-agnostic, r=oli-obk
Make `report_projection_error` more `Term` agnostic

Fixes #105632
2022-12-15 12:46:01 +01:00
bors
397b66e77b Auto merge of #105285 - compiler-errors:conflicting-param-env-2, r=estebank
Highlight conflicting param-env candidates, again

Un-reverts #98794 (i.e. reverts #99290).

The previous time I attempted to land this PR, it was because of an incremental issue (#99233). The repro instructions in the issue is no longer manifest the ICE -- I think it's because this ambiguity code was refactored (I think by `@lcnr)` to no longer store the ambiguities in the fulfillment error, but instead recompute them on the fly.

The main motivation for trying to re-land this is that it fixes #105131 by highlighting the root-cause of the issue, which is conflicting param-env candidates:

```
error[E0283]: type annotations needed: cannot satisfy `Self: Gen<'source>`
   |
note: multiple `impl`s or `where` clauses satisfying `Self: Gen<'source>` found
  --> $DIR/conflicting-bounds.rs:3:1
   |
LL | pub trait Gen<'source> {
   | ^^^^^^^^^^^^^^^^^^^^^^
...
LL |         Self: for<'s> Gen<'s, Output = T>;
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0283`.
```

Fixes #105131.
Fixes (again) #98786
2022-12-15 11:11:49 +00:00
Esteban Küber
124f19485d Tweak output for bare dyn Trait in arguments
Fix #35825.
2022-12-14 18:51:55 -08:00
Michael Goulet
3eb5b62898 always use anonymize_bound_vars 2022-12-14 20:06:25 +00:00
Michael Goulet
34d194d41c Highlight conflicting param-env candidates, again 2022-12-14 18:44:26 +00:00
Michael Goulet
7bf36de6ab Make report_projection_error more term agnostic 2022-12-14 18:32:31 +00:00
Michael Goulet
1225a65389 drive-by: Fix path spans 2022-12-14 18:26:09 +00:00
Michael Goulet
ae60015e76 Use impl's def id when calculating type to specify UFCS 2022-12-14 18:26:09 +00:00
Oli Scherer
9f6ae8828e Fix a freshly detected wrong TraitRef 2022-12-14 15:36:39 +00:00
Oli Scherer
6af3638709 Prevent the creation of TraitRef without dedicated methods 2022-12-14 15:36:39 +00:00
Oli Scherer
a5cd3bde95 Ensure no one constructs AliasTys themselves 2022-12-14 15:36:39 +00:00
Oli Scherer
1bf80249ae Remove many more cases of mk_substs_trait that can now use the iterator scheme` 2022-12-14 15:36:39 +00:00
Oli Scherer
7fd9beedc2 Rename to match similar methods 2022-12-14 15:36:39 +00:00
Oli Scherer
fef872a875 Guard AliasTy creation against passing the wrong number of substs 2022-12-14 15:36:39 +00:00
ouz-a
75cf31faa8 skip if val has ecaping bound vars 2022-12-14 14:05:44 +03:00
Matthias Krüger
939880ab72
Rollup merge of #105595 - TaKO8Ki:suggest-dereferencing-receiver-argument, r=compiler-errors
Suggest dereferencing receiver arguments properly

Fixes #105429
2022-12-14 10:31:07 +01:00
Matthias Krüger
e5fde968db
Rollup merge of #105523 - estebank:suggest-collect-vec, r=compiler-errors
Suggest `collect`ing into `Vec<_>`

Fix #105510.
2022-12-14 10:31:07 +01:00
bors
918d0ac38e Auto merge of #104986 - compiler-errors:opaques, r=oli-obk
Combine `ty::Projection` and `ty::Opaque` into `ty::Alias`

Implements https://github.com/rust-lang/types-team/issues/79.

This PR consolidates `ty::Projection` and `ty::Opaque` into a single `ty::Alias`, with an `AliasKind` and `AliasTy` type (renamed from `ty::ProjectionTy`, which is the inner data of `ty::Projection`) defined as so:

```
enum AliasKind {
  Projection,
  Opaque,
}

struct AliasTy<'tcx> {
  def_id: DefId,
  substs: SubstsRef<'tcx>,
}
```

Since we don't have access to `TyCtxt` in type flags computation, and because repeatedly calling `DefKind` on the def-id is expensive, these two types are distinguished with `ty::AliasKind`, conveniently glob-imported into `ty::{Projection, Opaque}`. For example:

```diff
  match ty.kind() {
-   ty::Opaque(..) =>
+   ty::Alias(ty::Opaque, ..) => {}
    _ => {}
  }
```

This PR also consolidates match arms that treated `ty::Opaque` and `ty::Projection` identically.

r? `@ghost`
2022-12-14 01:19:24 +00:00