Commit Graph

1423 Commits

Author SHA1 Message Date
bors 027c8507b4 Auto merge of #103902 - vincenzopalazzo:macros/obligation_rulesv2, r=oli-obk
use `LocalDefId` instead of `HirId` in trait resolution to simplify the obligation clause resolution

This commit introduces a refactoring suggested by `@lcnr` to simplify the obligation clause resolution.

This is just the first PR that introduces a type of refactoring, but others PRs will follow this to introduce name changing to change from the variable name from `body_id` to something else.

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

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>

`@rustbot` r? `@lcnr`
2023-01-25 16:39:29 +00:00
Matthew J Perez 1e22280f23
Add suggestions for function pointers
- On compiler-error's suggestion of moving this lower down the stack,
along the path of `report_mismatched_types()`, which is used
by `rustc_hir_analysis` and `rustc_hir_typeck`.
- update ui tests, add test
- add suggestions for references to fn pointers
- modify `TypeErrCtxt::same_type_modulo_infer` to take `T: relate::Relate` instead of `Ty`
2023-01-24 14:02:56 -05:00
Nathan Fenner 2a67e99d7d Point at specific field in struct literal when trait fulfillment fails 2023-01-23 13:37:58 -08:00
Vincenzo Palazzo 7d2c1103d7 fix: use LocalDefId instead of HirId in trait res
use LocalDefId instead of HirId in trait resolution to simplify
the obligation clause resolution

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-01-23 11:42:18 +00:00
Dylan DPC 3d4c3125be
Rollup merge of #104926 - spastorino:calculate_diverging_fallback-cleanups, r=lcnr
Move relationships from FulfillmentContext to Inherited

r? `@lcnr`
2023-01-23 11:52:04 +05:30
Michael Goulet a63f5dce27 Remove confusing 'while checking' note from opaque future type mismatches 2023-01-22 17:02:47 +00:00
Santiago Pastorino 7fe472223e
Store relationships on Inherent 2023-01-22 11:02:28 -03:00
Matthias Krüger 6e79310c55
Rollup merge of #107111 - chenyukang:yukang/fix-107090-fluent-parameters, r=petrochenkov
Fix missing arguments issues and copy-paste bug for fluent

Fixes #107090
2023-01-22 11:43:06 +01:00
Ikko Eltociear Ashimine 1adb4d6e5f
Fix typo in opaque_types.rs
paramters -> parameters
2023-01-20 17:56:29 +09:00
bors 56ee85274e Auto merge of #106090 - WaffleLapkin:dereffffffffff, r=Nilstrieb
Remove some `ref` patterns from the compiler

Previous PR: https://github.com/rust-lang/rust/pull/105368

r? `@Nilstrieb`
2023-01-20 04:52:28 +00:00
Ali MJ Al-Nasrawy a7a842027c even more unify Projection/Opaque in outlives code 2023-01-19 15:31:53 +03:00
yukang 0368adb262 Fix #107090, fix missing arguments for fluent 2023-01-18 22:53:24 +08:00
Scott McMurray 925dc37313 Stop using `BREAK` & `CONTINUE` in compiler
Switching them to `Break(())` and `Continue(())` instead.

libs-api would like to remove these constants, so stop using them in compiler to make the removal PR later smaller.
2023-01-17 23:17:51 -08:00
Matthias Krüger 3d7677d91a
Rollup merge of #106970 - kylematsuda:earlybinder-item-bounds, r=lcnr
Switch to `EarlyBinder` for `item_bounds` query

Part of the work to finish #105779 (also see https://github.com/rust-lang/types-team/issues/78).

Several queries `X` have a `bound_X` variant that wraps the output in `EarlyBinder`. This adds `EarlyBinder` to the return type of the `item_bounds` query and removes `bound_item_bounds`.

r? `@lcnr`
2023-01-17 20:21:28 +01:00
Matthias Krüger 68f12338af
Rollup merge of #104505 - WaffleLapkin:no-double-spaces-in-comments, r=jackh726
Remove double spaces after dots in comments

Most of the comments do not have double spaces, so I assume these are typos.
2023-01-17 20:21:25 +01:00
Kyle Matsuda fc942eed7f change item_bounds query to return EarlyBinder; remove bound_item_bounds query 2023-01-17 08:55:28 -07:00
Maybe Waffle 6a28fb42a8 Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
Maybe Waffle 360e978437 Don't call closures immediately, use `try{}` blocks 2023-01-17 07:48:19 +00:00
Matthias Krüger 6b49435480
Rollup merge of #106829 - compiler-errors:more-alias-combine, r=spastorino
Unify `Opaque`/`Projection` handling in region outlives code

They share basically identical paths in most places which are even easier to unify now that they're both `ty::Alias`

r? types
2023-01-17 05:25:22 +01:00
Michael Goulet 90df86f474 Remove bound_{explicit,}_item_bounds 2023-01-15 15:36:06 +00:00
Matthias Krüger 980bf1979e
Rollup merge of #106859 - tialaramex:master, r=Nilstrieb
Suggestion for type mismatch when we need a u8 but the programmer wrote a char literal

Today Rust just points out that we have a char and we need a u8, but if I wrote 'A' then I could fix this by just writing b'A' instead. This code should detect the case where we're about to report a type mismatch of this kind, and the programmer wrote a char literal, and the char they wrote is ASCII, so therefore just prefixing b to make a byte literal will do what they meant.

I have definitely written this mistake more than once, it's not difficult to figure out what to do, but the compiler might as well tell us anyway.

I provided a test with two simple examples where the suggestion is appropriate, and one where it is not because the char literal is not ASCII, showing that the suggestion is only triggered in the former cases.

I have contributed only a small typo doc fix before, so this is my first substantive rustc change.
2023-01-15 01:01:36 +01:00
Nick Lamb 130d02b62e Improve E0308: suggest user meant to use byte literal, w/ tests and fix
suggested by Nilstrieb

Co-authored-by: nils <48135649+Nilstrieb@users.noreply.github.com>
2023-01-14 21:27:14 +00:00
bors b8f9cb345a Auto merge of #106696 - kylematsuda:early-binder, r=lcnr
Switch to `EarlyBinder` for `const_param_default` and `impl_trait_ref` queries

Part of the work to close #105779 and implement https://github.com/rust-lang/types-team/issues/78.

Several queries `X` have a `bound_X` variant that wraps the output in `EarlyBinder`. This PR adds `EarlyBinder` to the return type of  `const_param_default` and `impl_trait_ref`, and removes their `bound_X` variants.

r? `@lcnr`
2023-01-14 17:44:30 +00:00
Kyle Matsuda f29a334c90 change impl_trait_ref query to return EarlyBinder; remove bound_impl_trait_ref query; add EarlyBinder to impl_trait_ref in metadata 2023-01-14 00:29:56 -07:00
Kyle Matsuda be130b57d4 change usages of impl_trait_ref to bound_impl_trait_ref 2023-01-14 00:23:32 -07:00
Michael Goulet 1ea6862db3 Unify Opaque/Projection handling in region outlives code 2023-01-13 23:53:28 +00:00
Esteban Küber 3d6b09e53e Keep obligation chain when elaborating obligations 2023-01-13 18:20:23 +00:00
Michael Goulet 8e27211dbc is_ty_infer -> is_ty_or_numeric_infer 2023-01-12 23:57:41 +00:00
nils c61f29ca52
Rollup merge of #106714 - Ezrashaw:remove-e0490, r=davidtwco
remove unreachable error code `E0490`

AFAIK, the untested and undocumented error code `E0490` is now unreachable, it was from the days of the original borrow checker.

cc ``@GuillaumeGomez`` #61137
2023-01-12 15:44:52 +01:00
bors 606c390725 Auto merge of #106760 - compiler-errors:rollup-0bogyco, r=compiler-errors
Rollup of 8 pull requests

Successful merges:

 - #103236 (doc: rewrite doc for signed int::{carrying_add,borrowing_sub})
 - #103800 (Stabilize `::{core,std}::pin::pin!`)
 - #106097 (Migrate mir_build diagnostics 2 of 3)
 - #106170 (Move autoderef to `rustc_hir_analysis`)
 - #106323 (Stabilize f16c_target_feature)
 - #106360 (Tweak E0277 `&`-removal suggestions)
 - #106524 (Label `struct/enum constructor` instead of `fn item`, mention that it should be called on type mismatch)
 - #106739 (Remove `<dyn AstConv<'tcx>>::fun(c, ...)` calls in favour of `c.astconv().fun(...)`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-12 10:46:19 +00:00
Ezra Shaw 02005e9f22
remove unreachable error code `E0490` 2023-01-12 14:15:21 +13:00
yanchen4791 621d412241
Fix invalid syntax in impl Trait parameter type suggestions for E0311 2023-01-11 14:49:55 -08:00
Michael Goulet c8334ce60c Move autoderef to rustc_hir_analysis 2023-01-11 20:12:57 +00:00
Albert Larsan 40ba0e84d5
Change `src/test` to `tests` in source files, fix tidy and tests 2023-01-11 09:32:13 +00:00
Yuki Okushi e5e116dca9
Rollup merge of #106204 - compiler-errors:no-take-opaques-in-compare, r=oli-obk
No need to take opaques in `check_type_bounds`

`InferCtxt` already has its defining use anchor set to err

r? ``@oli-obk``
2023-01-10 08:05:34 +09:00
Michael Goulet f769d34291 Assert defining anchor is set in take_opaque_types 2023-01-09 18:14:28 +00:00
fee1-dead f8319bb403
Rollup merge of #106389 - compiler-errors:no-canonicalized, r=lcnr
Simplify some canonical type alias names

* delete the `Canonicalized<'tcx>` type alias in favor for `Canonical<'tcx>`
* `CanonicalizedQueryResponse` -> `CanonicalQueryResponse`

I don't particularly care about the latter, but it should be consistent. We could alternatively delete the first alias and rename the struct to `Canonicalized`, and then keep the name of `CanonicalizedQueryResponse` untouched.
2023-01-09 23:35:30 +08:00
fee1-dead 7779386a3a
Rollup merge of #106164 - compiler-errors:check-region-tweak, r=oli-obk
Move `check_region_obligations_and_report_errors` to `TypeErrCtxt`

Makes sense for this function to live with its sibling `resolve_regions_and_report_errors`, around which it's basically just a wrapper.
2023-01-09 23:35:29 +08:00
Michael Goulet 6afd16171d
Rollup merge of #106131 - compiler-errors:not-ptrs, r=davidtwco
Mention "signature" rather than "fn pointer" when impl/trait methods are incompatible

Fixes #80929
Fixes #67296
2023-01-08 19:57:53 -08:00
Michael Goulet 49f849a3d2 Mention signature rather than fn pointers when comparing impl/trait methods 2023-01-08 03:49:24 +00:00
Ezra Shaw 93c0d8d5d5
remove unreachable error code `E0313` 2023-01-08 14:47:12 +13:00
Matthias Krüger 405e48f1ac
Rollup merge of #101936 - IntQuant:issue-100717-infer-4, r=compiler-errors
Migrating rustc_infer to session diagnostics (part 3)

``@rustbot`` label +A-translation
r? rust-lang/diagnostics
cc https://github.com/rust-lang/rust/issues/100717

Seems like a part of static_impl_trait.rs emits suggestions in a loop, and note.rs needs to have two instances of the same subdiagnostic, so these will need to wait until we have eager translation/list support.
Other than that, there is only error_reporting/mod.rs left to migrate.
2023-01-07 20:43:18 +01:00
bors 7bbbaabbb6 Auto merge of #105805 - yanchen4791:issue-105227-fix, r=estebank
Suggest adding named lifetime when the return contains value borrowed from more than one lifetimes of function inputs

fix for #105227.

The problem: The suggestion of adding an explicit `'_` lifetime bound is **incorrect** when the function's return type contains a value which could be borrowed from more than one lifetimes of the function's inputs. Instead, a named lifetime parameter can be introduced in such a case.

The solution: Checking the number of elided lifetimes in the function signature. If more than one lifetimes found in the function inputs when the suggestion of adding explicit `'_` lifetime, change it to using named lifetime parameter `'a` instead.
2023-01-06 12:08:49 +00:00
yanchen4791 523fe7a121 Suggests adding named lifetime when the return contains value borrowed from more than one lifetimes of the function's inputs 2023-01-05 21:09:27 -08:00
Esteban Küber ad82eedfa1 Use `BottomUpFolder` 2023-01-05 16:51:16 +00:00
Michael Goulet 5ce6311f34
Rollup merge of #106403 - compiler-errors:rename-hir-methods, r=cjgillot
Rename `hir::Map::{get_,find_}parent_node` to `hir::Map::{,opt_}parent_id`, and add `hir::Map::{get,find}_parent`

The `hir::Map::get_parent_node` function doesn't return a `Node`, and I think that's quite confusing. Let's rename it to something that sounds more like something that gets the parent hir id => `hir::Map::parent_id`. Same with `find_parent_node` => `opt_parent_id`.

Also, combine `hir.get(hir.parent_id(hir_id))` and similar `hir.find(hir.parent_id(hir_id))` function into new functions that actually retrieve the parent node in one call. This last commit is the only one that might need to be looked at closely.
2023-01-04 20:36:28 -08:00
Michael Goulet 2baee88bdb Address comments 2023-01-04 00:51:50 +00:00
Michael Goulet 7690fe3bc6 Simplify some iterator combinators 2023-01-04 00:48:07 +00:00
Michael Goulet b1b19bd851 get_parent and find_parent 2023-01-04 00:43:13 +00:00
Michael Goulet a313ef05a7 rename get_parent_node to parent_id 2023-01-04 00:43:13 +00:00
Michael Goulet c104ee9f6d Move check_region_obligations_and_report_errors to TypeErrCtxt 2023-01-03 23:58:12 +00:00
Michael Goulet 50ab306015 Simplify some canonical type alias names 2023-01-03 01:16:10 +00:00
Matthias Krüger c610aeb592
Rollup merge of #106221 - Nilstrieb:rptr-more-like-ref-actually, r=compiler-errors
Rename `Rptr` to `Ref` in AST and HIR

The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
2022-12-29 13:16:04 +01:00
Michael Goulet 6e794dcc8b Address review comments 2022-12-28 18:41:22 +00:00
Michael Goulet 01d784131f Make trait/impl where clause mismatch on region error a bit more actionable 2022-12-28 18:09:27 +00:00
Nilstrieb 9067e4417e Rename `Rptr` to `Ref` in AST and HIR
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already
as well.
2022-12-28 18:52:36 +01:00
bors 83a28ef095 Auto merge of #106129 - compiler-errors:compare_method-tweaks, r=BoxyUwU
Some `compare_method` tweaks

1. Make some of the comparison functions' names more regular
2. Reduce pub scope of some of the things in `compare_method`
~3. Remove some unnecessary opaque type handling code -- `InferCtxt` already is in a mode that doesn't define opaque types~
  * moved to a different PR
4. Bubble up `ErrorGuaranteed` for region constraint errors in `compare_method` - Improves a redundant error message in one unit test.
5. Move the `compare_method` module to have a more general name, since it's more like `compare_impl_item` :)
6. Rename `collect_trait_impl_trait_tys`
2022-12-28 13:07:30 +00:00
Nikita Tomashevich 0c50e1f146
eager is the default now 2022-12-28 15:24:18 +03:00
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 `AliasTy`s 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 `collect`ing 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
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
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 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
Vadim Petrochenkov 7a5376d23c Unreserve braced enum variants in value namespace 2022-11-21 22:40:06 +03: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
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
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
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
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
Michael Goulet c36ff28d42 drive-by: PolyExistentialPredicate 2022-11-19 04:04:27 +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 9c510048fd `InferCtxt::is_tainted_by_errors` returns `ErrorGuaranteed` 2022-11-18 13:25:17 +00:00
Oli Scherer 4f11f3b257 Convert predicates into Predicate in the Obligation constructor 2022-11-16 09:25:19 +00:00
lcnr 6aa611a84c mv utility methods into separate module 2022-11-15 13:50:13 +01:00
lcnr 45f441a7b4 nll: correctly deal with bivariance 2022-11-15 13:34:08 +01:00
Camille GILLOT 3afec247cb Deduplicate visitor. 2022-11-14 18:20:49 +00:00
Camille GILLOT d470ac9334 Drop `relate_opaque_item_substs`. 2022-11-14 18:05:14 +00:00
Camille GILLOT 5fc261e9a0 Inherit generics for impl-trait. 2022-11-12 09:59:36 +00:00
Dylan DPC 662df1ec86
Rollup merge of #104206 - compiler-errors:ocx-more-2, r=lcnr
Remove `save_and_restore_in_snapshot_flag`, use `ObligationCtxt` more

r? ```@lcnr```
2022-11-12 12:02:52 +05:30
bors 11fa0850f0 Auto merge of #103636 - chenyukang:yukang/fix-103587-sugg-if-let, r=jackh276,davidtwco
Recover from common if let syntax mistakes/typos

Fixes #103587
2022-11-10 05:19:10 +00:00
Michael Goulet ed6a7cc228 Remove save_and_restore_in_snapshot_flag 2022-11-09 22:58:39 +00:00
bors cc9b259b5e Auto merge of #103723 - CastilloDel:master, r=jackh726
Remove allow(rustc::potential_query_instability) in rustc_trait_selection

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

This PR needs to be benchmarked to check for regressions.
2022-11-09 13:45:27 +00:00
bors bc2504a83c Auto merge of #103171 - jackh726:gen-interior-hrtb-error, r=cjgillot
Better error for HRTB error from generator interior

cc #100013

This is just a first pass at an error. It could be better, and shouldn't really be emitted in the first place. But this is better than what was being emitted before.
2022-11-09 02:02:28 +00:00
CastilloDel 755ca4b9aa Reduce the scope of allow(rustc::potential_query_instability) in rustc_trait_selection
Make InferCtxtExt use a FxIndexMap

This should be faster, because the map is only being used to iterate,
which is supposed to be faster with the IndexMap

Make the user_computed_preds use an IndexMap

It is being used mostly for iteration, so the change shouldn't result in
a perf hit

Make the RegionDeps fields use an IndexMap

This change could be a perf hit. Both `larger` and `smaller` are used
for iteration, but they are also used for insertions.

Make types_without_default_bounds use an IndexMap

It uses extend, but it also iterates and removes items. Not sure if
this will be a perf hit.

Make InferTtxt.reported_trait_errors use an IndexMap

This change brought a lot of other changes. The map seems to have been
mostly used for iteration, so the performance shouldn't suffer.

Add FIXME to change ProvisionalEvaluationCache.map to use an IndexMap

Right now this results in a perf hit. IndexMap doesn't have
the `drain_filter` API, so in `on_completion` we now need to iterate two
times over the map.
2022-11-08 19:41:48 +01:00
yukang 9e7d2287cd use subdiagnostic for sugesting add let 2022-11-08 16:25:37 +08:00
yukang 667b15bb0e fix #103587, Recover from common if let syntax mistakes/typos 2022-11-08 14:10:04 +08:00
Dylan DPC 77a44ab568
Rollup merge of #103865 - compiler-errors:fallback-has-occurred-tracking, r=eholk
Move `fallback_has_occurred` state tracking to `FnCtxt`

Removes a ton of callsites that defaulted to `false`
2022-11-08 11:23:51 +05:30
Jack Huey 3c71fafd6d Add a known that this is a known limitation 2022-11-07 17:52:08 -05:00
Jack Huey cececca7c7 Get spans for a couple more region types, add some optimizations, and extend test 2022-11-07 17:39:30 -05:00
Jack Huey 00e314d5ed Add an optional Span to BrAnon and use it to print better error for HRTB error from generator interior 2022-11-07 17:39:29 -05:00
bors ca08a32655 Auto merge of #103218 - CastilloDel:infer, r=jackh726
Remove #![allow(rustc::potential_query_instability)] from rustc_infer

Related to #84447

This PR probably needs to be benchmarked to check for regressions.
2022-11-07 07:38:05 +00:00