Commit Graph

1265 Commits

Author SHA1 Message Date
Nikita Tomashevich
2a8b17dbc5
Fix formatting 2022-12-28 14:53:48 +03:00
Nikita Tomashevich
dda3ebad0a
Fix broken rebase 2022-12-28 14:53:48 +03:00
Nikita Tomashevich
a86173766c
Fix nits 2022-12-28 14:53:48 +03:00
Nikita Tomashevich
62f9962eaf
Made ty_or_sig and trait_path use their actual types instead of String 2022-12-28 14:53:48 +03:00
Nikita Tomashevich
7ecd064bbe
Split infer_explicit_lifetime_required into several diags 2022-12-28 14:53:48 +03:00
Nikita Tomashevich
19b8579803
Address changes of pr 103345 2022-12-28 14:53:48 +03:00
Nikita Tomashevich
40b221814e
Rename subdiagnostic fields that do not need to be unique now 2022-12-28 14:53:48 +03:00
Nikita Tomashevich
eb7ce1703b
Use eager translation 2022-12-28 14:53:47 +03:00
Nikita Tomashevich
71d24da665
Split into several messages 2022-12-28 14:53:47 +03:00
Nikita Tomashevich
6c19c08140
More descriptive names for ActualImplExplNotes variants 2022-12-28 14:53:47 +03:00
Nikita Tomashevich
57fdd196ae
Rebase and fix 2022-12-28 14:53:47 +03:00
Nikita Tomashevich
0634b0119c
Partial work on static_impl_trait.rs 2022-12-28 14:53:47 +03:00
Nikita Tomashevich
3935a81d47
Migrate trait_impl_difference.rs 2022-12-28 14:53:47 +03:00
Nikita Tomashevich
2118ff401f
Migrate placeholder_error.rs 2022-12-28 14:53:47 +03:00
Nikita Tomashevich
8360a40a8a
Migrate named_anon_conflict.rs 2022-12-28 14:53:47 +03:00
fee1-dead
5e9c91c6dd
Rollup merge of #106205 - compiler-errors:oopsy, r=fee1-dead
Remove some totally duplicated files in `rustc_infer`

I have no idea why or how I duplicated these files from `compiler/rustc_infer/src/infer/error_reporting/note.rs`, but I did by accident, and nothing caught it 🤦
2022-12-28 15:51:43 +08:00
Michael Goulet
605ad65f6a Remove some totally duplicated files 2022-12-28 05:45:12 +00:00
Michael Goulet
c7b414adb6 Rename module compare_method -> compare_impl_item 2022-12-28 04:18:37 +00:00
Esteban Küber
05e8ba126c Account for match expr in single line
When encountering `match Some(42) { Some(x) => x, None => "" };`, output

```
error[E0308]: `match` arms have incompatible types
 --> f53.rs:2:52
  |
2 |     let _ = match Some(42) { Some(x) => x, None => "" };
  |             --------------              -          ^^ expected integer, found `&str`
  |             |                           |
  |             |                           this is found to be of type `{integer}`
  |             `match` arms have incompatible types
  ```
2022-12-27 16:45:55 -08:00
Michael Goulet
8973b3e3cc Bubble up ErrorGuaranteed from region constraints in method item compare 2022-12-24 21:37:00 +00:00
Michael Goulet
6161758b6d Rename some compare_method functions 2022-12-24 21:36:58 +00: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
Jeremy Stucki
3dde32ca97
rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
bors
eb9e5e711d Auto merge of #105880 - Nilstrieb:make-newtypes-less-not-rust, r=oli-obk
Improve syntax of `newtype_index`

This makes it more like proper Rust and also makes the implementation a lot simpler.

Mostly just turns weird flags in the body into proper attributes.

It should probably also be converted to an attribute macro instead of function-like, but that can be done in a future PR.
2022-12-20 07:27:01 +00:00
bors
7f42e58eff Auto merge of #105575 - compiler-errors:impl-wf-lint, r=oli-obk
Add `IMPLIED_BOUNDS_ENTAILMENT` lint

Implements a lint (#105572) version of the hard-error introduced in #105483. Context is in that PR.

r? `@lcnr`
cc `@oli-obk` who had asked for this to be a lint first

Not sure if this needs to be an FCP, since it's a lint for now.
2022-12-20 03:52:43 +00:00
bors
935dc07218 Auto merge of #103600 - compiler-errors:early-binder-nits, r=spastorino
Address some `EarlyBinder` nits
2022-12-19 19:21:35 +00:00
Michael Goulet
96154d7fa7 Add IMPLIED_BOUNDS_ENTAILMENT lint 2022-12-19 18:16:22 +00:00
lcnr
a213bb36c9 implement the skeleton of the updated trait solver 2022-12-19 16:46:17 +00:00
Dylan DPC
a9005b6cc0
Rollup merge of #105864 - matthiaskrgr:compl, r=Nilstrieb
clippy::complexity fixes

filter_next
needless_question_mark
bind_instead_of_map
manual_find
derivable_impls
map_identity
redundant_slicing
skip_while_next
unnecessary_unwrap
needless_bool

r? `@compiler-errors`
2022-12-19 14:41:35 +05:30
Matthias Krüger
1da4a49912 clippy::complexity fixes
filter_next
needless_question_mark
bind_instead_of_map
manual_find
derivable_impls
map_identity
redundant_slicing
skip_while_next
unnecessary_unwrap
needless_bool
2022-12-19 00:04:28 +01:00
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
Nilstrieb
8bfd6450c7 A few small cleanups for newtype_index
Remove the `..` from the body, only a few invocations used it and it's
inconsistent with rust syntax.

Use `;` instead of `,` between consts. As the Rust syntax gods inteded.
2022-12-18 21:47:28 +01:00
Nilstrieb
d679764fb6 Make #[debug_format] an attribute in newtype_index
This removes the `custom` format functionality as its only user was
trivially migrated to using a normal format.

If a new use case for a custom formatting impl pops up, you can add it
back.
2022-12-18 21:37:38 +01: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
bors
a8847df167 Auto merge of #105657 - oli-obk:mk_projection_ty, r=lcnr
Guard ProjectionTy creation against passing the wrong number of substs

r? `@lcnr`
2022-12-15 04:21:25 +00:00
bors
fbf8b937b4 Auto merge of #105233 - mejrs:always_eager, r=estebank
Always evaluate vecs of subdiagnostics eagerly

See https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20lists!/near/310186705 for context
2022-12-14 16:16:50 +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
Matthias Krüger
01469693de
Rollup merge of #105611 - BoxyUwU:more_granular_placeholderification, r=wesleywiser
fold instead of obliterating args

Fixes #105608

we call `const_eval_resolve` on the following constant:
```
def: playground::{impl#0}::and::{constant#0},
substs: [
  ConstKind::Unevaluated {
    def: playground::{impl#0}::and::{constant#0},
    substs: [
      ConstKind::Value(0x0),
      _,
    ]
  }
  _,
],
```
when expanded out to `ConstKind::Expr` there are no infer vars so we attempt to evaluate it after replacing infer vars with garbage, however the current logic for replacing with garbage replaces _the whole arg containing the infer var_ rather than just the infer var. This means that after garbage replacement has occured we attempt to evaluate:
```
def: playground::{impl#0}::and::{constant#0},
substs: [
  PLACEHOLDER,
  PLACEHOLDER,
],
```
Which then leads to ctfe being unable to evaluate the const. With this PR we attempt to evaluate:
```
def: playground::{impl#0}::and::{constant#0},
substs: [
  ConstKind::Unevaluated {
    def: playground::{impl#0}::and::{constant#0},
    substs: [
      ConstKind::Value(0x0),
      PLACEHOLDER,
    ]
  }
  PLACEHOLDER,
],
```
which ctfe _can_ handle.

I am not entirely sure why this function is supposed to replace params with placeholders rather than just inference vars 🤔
2022-12-14 10:31:08 +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
Esteban Küber
40a62758a7 rename argument 2022-12-13 13:23:19 -08:00
Esteban Küber
165efabbee review comments 2022-12-13 11:36:43 -08:00
Esteban Küber
7d1e47aeb0 Suggest : Type instead of : _ 2022-12-13 10:39:44 -08:00
Esteban Küber
b3fba5e18a Remove unnecessary code and account for turbofish suggestion
Remove previously existing fallback that tried to give a good turbofish
suggestion, `need_type_info` is already good enough.

Special case `::<Vec<_>` suggestion for `Iterator::collect`.
2022-12-13 10:39:44 -08:00
Esteban Küber
9d5e7d3c04 Suggest collecting into Vec<_> 2022-12-13 10:39:44 -08:00
Michael Goulet
99417d54af Address a few more nits 2022-12-13 17:56:04 +00:00
Michael Goulet
96cb18e864 Combine identical alias arms 2022-12-13 17:48:55 +00:00
Michael Goulet
61adaf8187 Combine projection and opaque into alias 2022-12-13 17:48:55 +00:00
Michael Goulet
c13bd83528 squash OpaqueTy and ProjectionTy into AliasTy 2022-12-13 17:40:27 +00:00
Michael Goulet
5c6afb850c ProjectionTy.item_def_id -> ProjectionTy.def_id 2022-12-13 17:34:44 +00:00
Michael Goulet
7f3af72606 Use ty::OpaqueTy everywhere 2022-12-13 17:29:26 +00:00
bors
109cccbe4f Auto merge of #105350 - compiler-errors:faster-binder-relate, r=oli-obk
Fast-path some binder relations

A simpler approach than #104598

Fixes #104583

r? types
2022-12-13 07:10:53 +00:00
Michael Goulet
5dea1d1c6e EarlyBinder nits 2022-12-13 04:53:36 +00:00
Michael Goulet
2025a96ee1 Fast path some binder relations 2022-12-13 03:17:14 +00:00
Takayuki Maeda
ee40a67cd9 remove unnecessary uses of clone 2022-12-13 02:06:24 +09:00
Boxy
dd19656df3 fold instead of obliterating args 2022-12-12 14:30:01 +00:00
Matthias Krüger
6111a7345b
Rollup merge of #105443 - compiler-errors:move-more, r=oli-obk
Move some queries and methods

Each commit's title should be self-explanatory. Motivated to break up some large, general files and move queries into leaf crates.
2022-12-09 07:25:46 +01:00
Matthias Krüger
086bdbbd73
Rollup merge of #104922 - estebank:fur-elize, r=oli-obk
Detect long types in E0308 and write them to disk

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

Print the widest possible short type while still fitting in the terminal.
2022-12-08 12:57:28 +01:00
Michael Goulet
3b9daac6a2 Move some suggestions from error_reporting to error_reporting::suggest 2022-12-08 05:58:30 +00:00
Michael Goulet
da929fa63c Make get_impl_future_output_ty work with AFIT 2022-12-05 17:34:42 +00:00
mejrs
a7838d8bd7 Always evaluate vecs of subdiagnostics eagerly 2022-12-04 01:13:21 +01:00
Yuki Okushi
7d4af8852c
Rollup merge of #105188 - compiler-errors:verbose-ty-err, r=TaKO8Ki
Don't elide type information when printing E0308 with `-Zverbose`

When we pass `-Zverbose`, we kinda expect for all `_` to be replaced with more descriptive information, for example --

```
   = note: expected fn pointer `fn(_, u32)`
                 found fn item `fn(_, i32) {foo}`
```

Where `_` is the "identical" part of the fn signatures, now gets rendered as:

```
   = note: expected fn pointer `fn(i32, u32)`
                 found fn item `fn(i32, i32) {foo}`
```
2022-12-03 12:51:30 +09:00
Michael Goulet
5c642d7d1c Don't elide information when printing E0308 with Zverbose 2022-12-02 21:01:59 +00:00
Matthias Krüger
8e0d83a70c
Rollup merge of #105185 - compiler-errors:normalize_fn_sig-in-err-ctxt, r=lcnr
Move `normalize_fn_sig` to `TypeErrCtxt`

r? `@lcnr`
2022-12-02 21:22:50 +01:00
Michael Goulet
ffca711760 Move normalize_fn_sig to TypeErrCtxt 2022-12-02 19:29:14 +00:00
Michael Goulet
e45daa9856 Drive-by: remove unused type alias 2022-12-01 19:00:09 +00:00
bors
90711a86e5 Auto merge of #99814 - aliemjay:patch-2, r=jackh726
fix universe map in ifcx.instantiate_canonical_*

Previously, `infcx.instantiate_canonical_*` maps the root universe in `canonical` into `ty::UniverseIndex::Root`, I think because it assumes it works with a fresh `infcx` but this is not true for the use cases in mir typeck. Now the root universe is mapped into `infcx.universe()`.

I catched this accidentally while reviewing the code. I'm not sure if this is the right fix or if it is really a bug!
2022-11-30 14:03:36 +00:00
bors
e0098a5cc3 Auto merge of #105012 - WaffleLapkin:into, r=oli-obk
Make `tcx.mk_const` more permissive wrt `kind` argument (`impl Into`)

r? `@oli-obk` you've asked for this >:)
2022-11-29 13:28:44 +00:00
Esteban Küber
360c0a7a3e Tweak shortening logic to be less trigger happy 2022-11-28 14:08:19 -08:00
Esteban Küber
7674edeeba Detect long types in E0308 and write them to disk
On type error with long types, print an abridged type and write the full
type to disk.

Print the widest possible short type while still fitting in the
terminal.
2022-11-28 14:08:18 -08:00
Maybe Waffle
f4d00fe785 Remove Const::from_value
...it's just `mk_const` but without the sparcles
2022-11-28 17:28:30 +00:00
Maybe Waffle
26b87bf8ff Simplify calls to tcx.mk_const
`mk_const(ty::ConstKind::X(...), ty)` can now be simplified to
`mk_cosnt(...,                   ty)`.

I searched with the following regex: \mk_const\([\n\s]*(ty::)?ConstKind\
I've left `ty::ConstKind::{Bound, Error}` as-is, they seem clearer this
way.
2022-11-28 17:27:20 +00:00
Maybe Waffle
7087d9b2a0 Remove tcx.mk_const_var
... `tcx.mk_const` can now be used instead
2022-11-28 17:27:20 +00:00
Matthias Krüger
60d136000e
Rollup merge of #104936 - cjgillot:self-rpit-orig-too, r=oli-obk
Ignore bivariant parameters in test_type_match.

https://github.com/rust-lang/rust/pull/103491 made opaque types bivariant with respect of some of their lifetime parameters.  Because of this bivariance, some lifetime variables were not unified to anything during borrowck, and were considered as unequal by borrowck type test.

This PR makes type test ignore the bivariant parameters in test_type_match.

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

r? `@oli-obk`
2022-11-28 17:25:47 +01:00
Dylan DPC
8a84dd8fcc
Rollup merge of #104890 - lcnr:small-cleanup, r=fee1-dead
small method code cleanup
2022-11-28 15:42:11 +05:30
Dylan DPC
f90484df8a
Rollup merge of #104732 - WaffleLapkin:from_def_idn't, r=compiler-errors
Refactor `ty::ClosureKind` related stuff

I've tried to fix all duplication and weirdness, but if I missed something do tell :p

r? `@compiler-errors`
2022-11-28 15:42:10 +05:30
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
Maybe Waffle
5ba0056346 Use TyCtxt::is_fn_trait is a couple more places 2022-11-27 07:20:28 +00:00
Maybe Waffle
881862ecb7 Rename fn_trait_kind_from_{from_lang=>def_id} to better convey meaning 2022-11-27 07:14:49 +00:00
Guillaume Gomez
4019c8aaf7
Rollup merge of #104921 - compiler-errors:no-binder-on-fut-ty, r=cjgillot
Remove unnecessary binder from `get_impl_future_output_ty`

We never construct an `async fn` with a higher-ranked `impl Future` bound anyways, and basically all the call-sites already skip the binder.
2022-11-26 17:47:24 +01:00
Guillaume Gomez
e6c83d9e42
Rollup merge of #104788 - compiler-errors:unresolved-ct-in-gen, r=fee1-dead
Do not record unresolved const vars in generator interior

Don't record types in the generator interior when we see unresolved const variables.

We already do this for associated types -- this is important to avoid unresolved inference variables in the generator results during writeback, since the writeback results get stable hashed in incremental mode.

Fixes #104787
2022-11-26 17:47:23 +01: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
Camille GILLOT
89afda7811 Ignore bivariant parameters in test_type_match. 2022-11-26 09:50:01 +00:00
Michael Goulet
6210812494 Do not record unresolved const vars in generator interior 2022-11-26 05:38:43 +00:00
Michael Goulet
1472b38039 Remove unnecessary binder from get_impl_future_output_ty 2022-11-26 05:22:52 +00:00
bors
aff003becd Auto merge of #99798 - JulianKnodt:ac1, r=BoxyUwU
Add `ConstKind::Expr`

Starting to implement `ty::ConstKind::Abstract`, most of the match cases are stubbed out, some I was unsure what to add, others I didn't want to add until a more complete implementation was ready.

r? `@lcnr`
2022-11-25 22:56:59 +00:00
lcnr
a215b7b4df remove TypeError::ObjectUnsafeCoercion 2022-11-25 16:39:23 +01:00
Boxy
2ac5d91d63 Make expand_abstract_consts infallible 2022-11-25 09:28:44 +00:00
kadmin
5bb1a9febc Add expand_abstract_const
Adds the ability to directly expand a const to an expr without having to deal with intermediate
steps.
2022-11-25 09:28:43 +00:00
kadmin
f9750c1554 Add empty ConstKind::Abstract
Initial pass at expr/abstract const/s

Address comments

Switch to using a list instead of &[ty::Const], rm `AbstractConst`

Remove try_unify_abstract_consts

Update comments

Add edits

Recurse more

More edits

Prevent equating associated consts

Move failing test to ui

Changes this test from incremental to ui, and mark it as failing and a known bug.
Does not cause the compiler to ICE, so should be ok.
2022-11-25 09:28:43 +00:00
Santiago Pastorino
974e2837bb
Introduce PredicateKind::Clause 2022-11-25 00:04:54 -03:00
Santiago Pastorino
1930c77de1
Remove normalize_projection_type 2022-11-24 09:02:55 -03: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