Commit Graph

2281 Commits

Author SHA1 Message Date
lcnr
033047a72c new_outside_solver -> evaluate_root_goal 2023-01-23 15:58:28 +01: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
Yuki Okushi
17023496a2
Rollup merge of #107101 - compiler-errors:perf-106309-1, r=petrochenkov
Filter param-env predicates for errors before calling `to_opt_poly_trait_pred`

cc #106309 https://github.com/rust-lang/rust/pull/106757#issuecomment-1396616318

r? `@ghost`
2023-01-23 19:29:59 +09: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
Santiago Pastorino
7fe472223e
Store relationships on Inherent 2023-01-22 11:02:28 -03:00
Michael Goulet
444cbcd729 Address goal nits 2023-01-21 17:15:00 +00:00
Michael Goulet
d6a411c086 Implement some more predicates 2023-01-21 16:37:33 +00:00
Michael Goulet
3452104715
Rollup merge of #107061 - compiler-errors:new-solver-new-candidates-3, r=lcnr
Implement some more new solver candidates and fix some bugs

First, fix some bugs:

1. `IndexVec::drain_enumerated(a..b)` does not give us an iterator of index keys + items enumerated from `a..b`, but from `0..(b-a)`... That caused a bug. See first commit for the fix.
2. Implement the `_: Trait` ambiguity hack. I put it in assemble, let me know if it should live elsewhere. This is important, since we otherwise consider `_: Sized` to have no solutions, and nothing passes!
3. Swap `Ambiguity` and `Unimplemented` cases for the new solver. Sorry for accidentally swapping them 😄
4. Check GATs' own predicates during projection confirmation.

Then implement a few builtin traits:

5. Implement `PointerSized`. Pretty independent.
6. Implement `Fn` family of traits for fnptr, fndef, and closures. Closures are currently broken because `FulfillCtxt::relationships` is intentionally left unimplemented. See comment in the test.

r? ```@lcnr```
2023-01-20 21:33:22 -05:00
bors
94a300b9b8 Auto merge of #105102 - compiler-errors:copy-impl-considering-regions, r=lcnr
Check ADT fields for copy implementations considering regions

Fixes #88901
r? `@ghost`
2023-01-20 21:29:52 +00:00
bors
a6269dad38 Auto merge of #107106 - matthiaskrgr:rollup-g7r1ep0, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #106699 ([drop tracking] Visit break expressions )
 - #106738 (Fix known-bug annotations)
 - #106891 (Tweak "borrow closure argument" suggestion)
 - #106928 (add raw identifier for keyword in suggestion)
 - #107065 (Clippy: Make sure to include in beta: Move `unchecked_duration_subtraction` to pedantic)
 - #107068 (autoderive Subdiagnostic for AddtoExternBlockSuggestion)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-20 15:28:40 +00:00
bors
04a41f889f Auto merge of #107105 - matthiaskrgr:rollup-rkz9t7r, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #106783 (Recover labels written as identifiers)
 - #106973 (Don't treat closures from other crates as local)
 - #106979 (Document how to get the type of a default associated type)
 - #107053 (signal update string representation for haiku.)
 - #107058 (Recognise double-equals homoglyph)
 - #107067 (Custom MIR: Support storage statements)
 - #107076 (Added const-generic ui test case for issue #106419)
 - #107091 (Fix broken format strings in `infer.ftl`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-20 12:58:13 +00:00
Matthias Krüger
5f2ad80e18
Rollup merge of #106891 - estebank:issue-45727, r=petrochenkov
Tweak "borrow closure argument" suggestion

Fix #45727.
2023-01-20 07:25:28 +01:00
Matthias Krüger
240cc81768
Rollup merge of #106973 - oli-obk:tait_ice_closure_in_impl_header, r=lcnr
Don't treat closures from other crates as local

fixes #104817

r? `@lcnr`

Specialization can prefer an impl for an opaque type over a blanket impls that also matches. If the blanket impl only applies if an auto-trait applies, we look at the hidden type of the opaque type to see if that implements the auto trait. The hidden type can be a closure or generator, and thus we will end up seeing these types in coherence and have to handle them properly.
2023-01-20 07:16:09 +01: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
Michael Goulet
096f454774 Filter predicates first for fast-path type flags 2023-01-20 03:20:17 +00:00
Esteban Küber
33e11a3b2e Tweak "borrow closure argument" suggestion
Fix #45727.
2023-01-19 19:35:49 +00:00
Michael Goulet
ed6aebbfec trait solver: Implement Fn traits and tuple trait 2023-01-19 16:15:28 +00:00
Michael Goulet
69890b2df4 trait solver: PointerSized 2023-01-19 16:15:28 +00:00
Michael Goulet
f53f5b4463 swap Ambiguity and Unimplemented in new trait engine 2023-01-19 16:15:28 +00:00
Michael Goulet
aee75f25cb Assert goal is fully normalized during assemble 2023-01-19 16:15:28 +00:00
Michael Goulet
200f466d1a Encode whether foreign opaques are TAITs or not 2023-01-19 15:45:49 +00:00
Michael Goulet
c9c8e294d2 HACK: self ty ambiguity hack 2023-01-19 15:31:57 +00:00
Michael Goulet
280f69d858 Fix IndexVec::drain_enumerated 2023-01-19 15:25:33 +00:00
Oli Scherer
42f1f54a5e Don't treat closures from other crates as local 2023-01-19 11:29:40 +00:00
Michael Goulet
5d562be33d
Rollup merge of #107030 - albertlarsan68:patch-3, r=lcnr
Correct typo

https://github.com/rust-lang/rust/pull/106718#discussion_r1073508490
2023-01-18 18:00:30 -05:00
Michael Goulet
2eef516b30
Rollup merge of #107023 - scottmcm:stop-shouting, r=Nilstrieb
Stop using `BREAK` & `CONTINUE` in compiler

Switching them to `Break(())` and `Continue(())` instead.

Entirely search-and-replace, though there's one spot where rustfmt insisted on a reformatting too.

libs-api would like to remove these constants (https://github.com/rust-lang/rust/pull/102697#issuecomment-1385705202), so stop using them in compiler to make the removal PR later smaller.
2023-01-18 18:00:30 -05:00
Michael Goulet
f672436f04 Handle structural traits more gracefully 2023-01-18 14:59:15 +00:00
Michael Goulet
34127c5080 no subtyping in the new trait solver 2023-01-18 14:59:15 +00:00
Michael Goulet
685c32fd85 Sized, Copy/Clone 2023-01-18 14:59:15 +00:00
Michael Goulet
45aa5c0f90 Auto and alias traits 2023-01-18 14:59:15 +00:00
Michael Goulet
3d87a8e848 Assemble object bound candidates 2023-01-18 14:28:14 +00:00
Michael Goulet
f99b273d57 implement consider_assumption 2023-01-18 14:28:14 +00:00
Michael Goulet
b84b1da2db Canonicalize trait solver response inside probe 2023-01-18 14:28:14 +00:00
Albert Larsan
5a685a10ec
Correct typo 2023-01-18 14:08:41 +01: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
lcnr
369f9aa099 add comment 2023-01-18 08:11:15 +01:00
lcnr
415aa663a2 add note about indirect cycles 2023-01-18 08:11:15 +01:00
lcnr
31ac29d989 update project to emulate a projection cache 2023-01-18 08:11:15 +01:00
lcnr
9a757d6ee4 add eq to InferCtxtExt 2023-01-18 08:11:15 +01:00
lcnr
660c28391c remove assembly context and impl a bit more 2023-01-18 08:11:15 +01:00
lcnr
bf7dbff921 instantiate canonical vars eagerly 2023-01-18 08:11:13 +01:00
lcnr
b738b06160 update cache 2023-01-18 08:09:01 +01: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
fc9e2c1081
Rollup merge of #106834 - compiler-errors:new-solver-did-changed, r=lcnr
new trait solver: only consider goal changed if response is not identity

I think this is the right way of implementing it..

r? `@lcnr`
2023-01-17 20:21:26 +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
Michael Goulet
148e4f73dc new trait solver: only consider goal changed if response is not identity 2023-01-17 17:40:38 +00: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
4a6d9de828 Untouch back perf sensetive code 😅 2023-01-17 07:48:20 +00:00
Maybe Waffle
8d3c90ae13 Review suggestions 2023-01-17 07:48:20 +00:00
Maybe Waffle
360e978437 Don't call closures immediately, use try{} blocks 2023-01-17 07:48:19 +00:00
Matthias Krüger
8ea26ca17f
Rollup merge of #106835 - compiler-errors:new-solver-gat-rebase-oops, r=lcnr
new trait solver: rebase impl substs for gats correctly

you might've caught this while working on projection code, if so then you can close this pr

r? `@lcnr`
2023-01-16 20:29:38 +01:00
bors
d12412c90f Auto merge of #106395 - compiler-errors:rework-predicates, r=eholk
Rework some `predicates_of`/`{Generic,Instantiated}Predicates` code

1. Make `instantiate_own` return an iterator, since it's a bit more efficient and easier to work with
2. Remove `bound_{explicit,}_predicates_of` -- these `bound_` methods in particular were a bit awkward to work with since `ty::GenericPredicates` *already* acts kinda like an `EarlyBinder` with its own `instantiate_*` methods, and had only a few call sites anyways.
3. Implement `IntoIterator` for `InstantiatedPredicates`, since it's *very* commonly being `zip`'d together.
2023-01-16 05:55:59 +00:00
Esteban Küber
656db98bd9 Tweak E0597
CC #99430
2023-01-15 19:46:20 +00:00
Michael Goulet
90df86f474 Remove bound_{explicit,}_item_bounds 2023-01-15 15:36:06 +00:00
Michael Goulet
9b28edb6d7 Make InstantiatedPredicates impl IntoIterator 2023-01-15 15:36:06 +00:00
Michael Goulet
91fd862df0 instantiate_own doesn't need to return a pair of vectors 2023-01-15 15:29:53 +00:00
bors
ae4d89dfb5 Auto merge of #106742 - compiler-errors:new-solver-make-it-not-ice, r=lcnr
Implement some FIXME methods in the new trait solver

Implement just enough of the solver's response logic to make it not ICE.

Also, fix a bug with `no_bound_vars` call failing due to canonical bound vars.

r? `@lcnr`
2023-01-15 15:07:27 +00:00
bors
fc11ee02ee Auto merge of #106171 - compiler-errors:consolidate-extract_callable_info, r=estebank,lcnr
Consolidate two almost duplicated fn info extraction routines

Moves `extract_callable_info` up to trait selection, because it was being (almost) duplicated fully there for similar diagnostic purposes. This also generalizes the diagnostics we can give slightly (see UI test).
2023-01-15 12:10:36 +00:00
Matthias Krüger
cc02ecc010
Rollup merge of #106863 - anden3:compiler-double-spaces, r=Nilstrieb
Remove various double spaces in compiler source comments.

Was asked to do it by `@Nilstrieb`
2023-01-15 01:01:37 +01:00
bors
afaf3e07aa Auto merge of #106866 - matthiaskrgr:rollup-r063s44, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #105526 (libcore: make result of iter::from_generator Clone)
 - #106563 (Fix `unused_braces` on generic const expr macro call)
 - #106661 (Stop probing for statx unless necessary)
 - #106820 (Deprioritize fulfillment errors that come from expansions.)
 - #106828 (rustdoc: remove `docblock` class from notable trait popover)
 - #106849 (Allocate one less vec while parsing arrays)
 - #106855 (rustdoc: few small cleanups)
 - #106860 (Remove various double spaces in the libraries.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-14 20:53:37 +00:00
Matthias Krüger
f04f97cea4
Rollup merge of #106820 - m-ou-se:macro-type-error-thing, r=estebank
Deprioritize fulfillment errors that come from expansions.

Fixes (part of?) #69455
2023-01-14 18:45:27 +01: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
André Vennberg
da3623abab Removed various double spaces in compiler source comments. 2023-01-14 17:34:59 +01:00
Mara Bos
6821adb651 Deprioritize fulfillment errors that come from expansions. 2023-01-14 14:05:26 +01:00
kadmin
2de9d679ad Add note when FnPtr vs. FnDef impl trait
I encountered an instance where an `FnPtr` implemented a trait, but I was passing an `FnDef`. To
the end user, there is really no way to differentiate each of them, but it is necessary to cast
to the generic function in order to compile. It is thus useful to suggest `as` in the help note,
(even if the Fn output implements the trait).
2023-01-14 10:37:56 +00:00
Kyle Matsuda
6e969ea85e fix various subst_identity vs skip_binder 2023-01-14 00:30:03 -07: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
05f664a441 new trait solver: rebase impl substs for gats correctly 2023-01-14 04:47:10 +00:00
Michael Goulet
75074e0e52 Delay normalization bugs instead of reporting them 2023-01-13 23:19:36 +00:00
Michael Goulet
16cfadbfe8 Suggest lifetime bound in illegal Copy impl 2023-01-13 23:06:29 +00:00
Michael Goulet
333c6bf523 copy self type is implied wf 2023-01-13 23:06:29 +00:00
Michael Goulet
8cf7f40a89 Check ADT fields for copy implementations considering regions 2023-01-13 23:06:29 +00:00
Michael Goulet
c1a7dbc0e3 Rebase conflicts 2023-01-13 22:43:17 +00:00
Michael Goulet
b2df88bae1 Consolidate two almost duplicated fn info extraction routines 2023-01-13 22:43:17 +00:00
Yuki Okushi
d4ad96cf6e
Rollup merge of #106754 - compiler-errors:ty-infer-method-is-confusing, r=lcnr
Rename `Ty::is_ty_infer` -> `Ty::is_ty_or_numeric_infer`

Makes sure people are aware that they may have a type variable *or* an int/float variable.

r? `@oli-obk` https://github.com/rust-lang/rust/pull/106322#issuecomment-1376913539 but I could instead implement your solution, let me know.

(This will conflict with #106322 for now, ignore that 😄)
2023-01-13 16:54:23 +09:00
bors
279f1c9d8c Auto merge of #106004 - fee1-dead-contrib:const-closures, r=oli-obk
Const closures

cc https://github.com/rust-lang/rust/issues/106003
2023-01-13 05:04:48 +00:00
Michael Goulet
8e27211dbc is_ty_infer -> is_ty_or_numeric_infer 2023-01-12 23:57:41 +00:00
Michael Goulet
1de196fef3 HACK: Handle escaping bound vars from the canonical query 2023-01-12 21:01:34 +00:00
Michael Goulet
5a31d5ebe2 Implement dummy query responses and a jank instantiate 2023-01-12 21:01:34 +00:00
nils
35cf81d707
Rollup merge of #106322 - compiler-errors:CollectAllMismatches-infer-vars, r=oli-obk
Handle inference variables in `CollectAllMismatches` correctly

1. Fix #106240
2. Treat int/float type variables correctly (see `src/test/ui/iterators/invalid-iterator-chain-with-int-infer.rs`), so we can point out things like "`Iterator::Item` changed to `{integer}` here"
2023-01-12 15:44:51 +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
Michael Goulet
54f6fea818
Rollup merge of #106360 - estebank:remove-borrow-suggestion, r=compiler-errors
Tweak E0277 `&`-removal suggestions

Fix #64068, fix #84837.
2023-01-11 22:25:49 -08:00
Michael Goulet
9928b14772
Rollup merge of #106170 - compiler-errors:autoderef-to-analysis, r=lcnr
Move autoderef to `rustc_hir_analysis`

Not sure if this is a change we actually want, but autoderef really is only (functionally) used by `rustc_hir_analysis` and `rustc_hir_typeck`, so it probably should live there.

Instead, implement a separate autoderef helper in `TypeErrCtxt` for the one use-case that  goes against the ordering of the crate graph..
2023-01-11 22:25:48 -08:00
Matthias Krüger
e8ef83e4c0
Rollup merge of #106748 - clubby789:on-unimplemented-fmt-verify, r=compiler-errors
Clean up `OnUnimplementedFormatString::verify`

Lift the always-allowed symbols to a static array and replace a `match iter().find(...)` with `iter().any(...)`
2023-01-12 06:52:39 +01:00
Matthias Krüger
890bc3ca90
Rollup merge of #106596 - estebank:verbose-e0271, r=compiler-errors
Hide more of long types in E0271

Fix #40186.
2023-01-12 06:52:36 +01:00
Matthias Krüger
9b538e8e62
Rollup merge of #106309 - compiler-errors:prefer-non-err-candidates, r=oli-obk
Prefer non-`[type error]` candidates during selection

Fixes #102130
Fixes #106351

r? types

note: Alternatively we could filter out error where-clauses during param-env construction? But we still need to filter out impls with errors during `match_impl`, I think.
2023-01-12 06:52:34 +01:00
Deadbeef
b0aa859c24 fix fmt and bless 2023-01-12 02:28:38 +00:00
Deadbeef
6e63f7be54 attempt to make a minimal example work 2023-01-12 02:28:37 +00:00
clubby789
b78a571ce1 Clean up OnUnimplementedFormatString::verify 2023-01-11 22:54:46 +00:00
Esteban Küber
f1ffe823cf Hide more of long types in E0271
Fix #40186.
2023-01-11 21:40:39 +00:00
Esteban Küber
8b8cce16bf Use the root trait predicate to determine whether to remove references
Fix #84837.
2023-01-11 21:39:07 +00:00
Esteban Küber
bb7211702e fix rebase 2023-01-11 21:38:56 +00:00
Esteban Küber
ce83be4af8 Account for type params 2023-01-11 21:38:56 +00:00
Esteban Küber
2024aa48b4 Make &-removal suggestion verbose 2023-01-11 21:38:54 +00:00
Michael Goulet
c8334ce60c Move autoderef to rustc_hir_analysis 2023-01-11 20:12:57 +00:00
Matthias Krüger
865d83e87a
Rollup merge of #106705 - compiler-errors:new-solver-err-properly, r=lcnr
Report fulfillment errors in new trait solver

Causes fewer ICEs when testing the new solver 😄
2023-01-11 21:08:09 +01:00
Matthias Krüger
90f9c681d4
Rollup merge of #106703 - compiler-errors:impl-derived-span, r=estebank
Note predicate span on `ImplDerivedObligation`

Seems obvious to point out the where-clause that introduces the `ImplDerivedObligation` :)

r? `@estebank`
2023-01-11 21:08:08 +01:00
Michael Goulet
83fbc71d02 Filter impl and where-clause candidates that reference errors 2023-01-11 20:03:29 +00:00
Michael Goulet
959616ef44 Handle inference variables in CollectAllMismatches correctly 2023-01-11 20:01:24 +00:00
Michael Goulet
9a39d7e441 Note predicate span on ImplDerivedObligation 2023-01-11 19:46:45 +00:00
Michael Goulet
104ec48c64 Report fulfillment errors in new trait solver 2023-01-11 18:05:50 +00:00
nils
16938915a4
Rollup merge of #106397 - compiler-errors:new-solver-impl-wc, r=lcnr
Check `impl`'s `where` clauses in `consider_impl_candidate` in experimental solver

Check impl's nested predicates as part of the recursive evaluate in `consider_impl_candidate`.

<sub>Unless, for some reason, these are intentionally **not** checked here -- in which case, I really don't understand where they're being checked...<sub>

r? ```@lcnr```
2023-01-11 17:30:53 +01: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
12b124283c
Rollup merge of #106521 - oskgo:remove-E0280, r=jackh726
remove E0280

After looking at #61137 I tried my hand at E0280. I'm unable to find a reasonable example that emits the error. There are a couple of old examples that compile with the current compiler ([#26217](https://github.com/rust-lang/rust/issues/26217), [#42114](https://github.com/rust-lang/rust/issues/42114), [#27113](https://github.com/rust-lang/rust/issues/27113)) and there is a [bug with chalk](b7cdb635c4/src/test/ui/chalkify/bugs/async.rs) that makes it emit the error, with a couple more chalk bugs on zulip.

It seems like the error is supposed to be emitted from unfulfilled where bounds, of which two are related to borrow checking (error in where T: 'a or where 'a: 'b) and thus tend to emit errors like "lifetime may not live long enough" from borrow checking instead. The final case is with type equality constraints (where <T as Iterator>::Item == u32), which is unimplemented ([#20041](https://github.com/rust-lang/rust/issues/20041)). That such different problems are supposed to have the same error code also seems strange to me.

Since the error seems to only be emitted when using chalk I propose to remove it and replace it with an ICE instead. A crater run might be warranted.

Pinging `@jackh726` due to removal of chalk test that now ICEs.
2023-01-11 14:18:53 +09:00
bowlerman
f75eb24f4f remove E0280 and ICE instead 2023-01-10 03:04:28 +01: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
Michael Goulet
36ee66c6c5 Check impl's where clauses in consider_impl_candidate in experimental solver 2023-01-09 17:24:36 +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
c1f8a3ffb2
Rollup merge of #105655 - RedDocMD:bug-105645, r=oli-obk
Remove invalid case for mutable borrow suggestion

If we have a call such as `foo(&mut buf)` and after reference
collapsing the type is inferred as `&T` where-as the required type is
`&mut T`, don't suggest `foo(&mut mut buf)`. This is wrong syntactically
and the issue lies elsewhere, not in the borrow.

Fixes #105645
2023-01-09 23:35:27 +08:00
kadmin
21c5ffe008 Clean up
Simplify match statement

Add multiple tests
- 1 test for checking `N + 1 + 1` does not unify with `N+1`
- 2 tests for checking that a function that uses two parameters only returns the parameter that
  is actually used.
- Check exact repeat predicates
2023-01-09 08:41:21 +00:00
kadmin
7c5cb73735 Check for duplicates 2023-01-09 08:41:21 +00:00
kadmin
b79a9a0900 Set !const_evaluatable if ambig. and not inferred
This prevents an ICE due to a value not actually being evaluatable later.
2023-01-09 08:41:21 +00:00
kadmin
77b61379b6 Change based on comments
Instead of just switching to a probe, check for different matches, and see how many there are.
If one, unify it, otherwise return true and let it be unified later.
2023-01-09 08:41:21 +00:00
kadmin
abe040d876 Change commit_if_ok to probe 2023-01-09 08:41:21 +00:00
Michael Goulet
eefc44b7e2
Rollup merge of #106497 - chenyukang:yukang/fix-106443-sugg-clone, r=estebank
Suggest using clone when we have &T and T implemented Clone

Fixes #106443
2023-01-08 19:57:54 -08:00
Michael Goulet
3c41003873 Add type flags support for Ty and Const late-bound regions 2023-01-08 03:37:20 +00:00
bors
a2112fcb0a Auto merge of #106519 - estebank:tail-unit, r=cjgillot
Detect bindings assigned blocks without tail expressions

Fix #44173.
2023-01-07 13:24:12 +00:00
Michael Goulet
258257a029
Rollup merge of #106525 - compiler-errors:new-solver-wf, r=jackh726
Report WF error for chalk *and* new solver

addressing this nit https://github.com/rust-lang/rust/pull/106385#discussion_r1062571070

No test yet because new solver is currently unusable, lol

r? `@lcnr`
2023-01-06 21:53:59 -08:00
yukang
6082729646 use type_implements_trait to check Param clone 2023-01-07 09:20:05 +08:00
yukang
ce4afed2ef comments feedback 2023-01-07 05:00:49 +08:00
yukang
e7a777805a Suggest possible clone when we have &T 2023-01-07 04:43:57 +08:00
Dylan DPC
a8f7ec2c48
Rollup merge of #106499 - lyming2007:issue-105946-fix, r=estebank
fix [type error] for error E0029 and E0277

check explicitly for the type references error
if ty.references_error() is true change the error to be err.delay_as_bug() and prevent the error E0029 and E0277 from emitting out this fix #105946
2023-01-06 11:38:57 +05:30
Yiming Lei
10dbcf0630 fix [type error] for error E0029 and E0277
check explicitly for the type references error
if ty.references_error() is true change the error to be err.delay_as_bug()
and prevent the error E0029 and E0277 from emitting out
this fix #105946
2023-01-05 21:21:13 -08:00
Esteban Küber
031e085450 Tweak output 2023-01-06 04:37:29 +00:00
Michael Goulet
a9d093bd6b Report WF error for new solver too 2023-01-06 04:09:44 +00:00
Esteban Küber
1fa6ada9dd Detect bindings assigned blocks without tail expressions in trait errors
Address  #44173 for trait errors.
2023-01-06 02:43:16 +00:00
bors
1429899700 Auto merge of #106482 - compiler-errors:rollup-g7n1p39, r=compiler-errors
Rollup of 6 pull requests

Successful merges:

 - #105846 (Account for return-position `impl Trait` in trait in `opt_suggest_box_span`)
 - #106385 (Split `-Zchalk` flag into `-Ztrait-solver=(classic|chalk|next)` flag)
 - #106403 (Rename `hir::Map::{get_,find_}parent_node` to `hir::Map::{,opt_}parent_id`, and add `hir::Map::{get,find}_parent`)
 - #106462 (rustdoc: remove unnecessary wrapper around sidebar and mobile logos)
 - #106464 (Update Fuchsia walkthrough with new configs)
 - #106478 (Tweak wording of fn call with wrong number of args)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-05 06:47:02 +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
bors
03b9e1d154 Auto merge of #105409 - compiler-errors:closure-infer-cycle, r=jackh726
Don't deduce a signature that makes a closure cyclic

Sometimes when elaborating supertrait bounds for closure signature inference, we end up deducing a closure signature that is cyclical because either a parameter or the return type references a projection mentioning `Self` that also has escaping bound vars, which means that it's not eagerly replaced with an inference variable.

Interestingly, this is not *just* related to my PR that elaborates supertrait bounds for closure signature deduction. The committed test `supertrait-hint-cycle-3.rs` shows **stable** code that is fixed by this PR:

```rust
trait Foo<'a> {
    type Input;
}

impl<F: Fn(u32)> Foo<'_> for F {
    type Input = u32;
}

fn needs_super<F: for<'a> Fn(<F as Foo<'a>>::Input) + for<'a> Foo<'a>>(_: F) {}

fn main() {
    needs_super(|_: u32| {});
}
```

Fixes #105401
Fixes #105396

r? types
2023-01-05 03:59:31 +00:00
Michael Goulet
8b0f43b19d Rename stock solver to classic 2023-01-04 18:40:02 +00:00
Michael Goulet
a4974fa9c7 Split -Zchalk flag into -Ztrait-solver=(stock|chalk|next) flag 2023-01-04 18:12:42 +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
50ab306015 Simplify some canonical type alias names 2023-01-03 01:16:10 +00:00
Michael Goulet
b2317a642d has_overflow only if value is *not* within limit 2023-01-03 01:09:08 +00:00
Esteban Küber
5bfcfeee2a Merge multiple mutable borrows of immutable binding errors
Fix #53466.
2023-01-01 10:09:26 -08:00
bors
973a4db8d5 Auto merge of #106210 - fee1-dead-contrib:const-closure-trait-method, r=compiler-errors
Allow trait method paths to satisfy const Fn bounds

r? `@oli-obk`
2022-12-30 01:09:31 +00:00
bors
ad8ae0504c Auto merge of #106266 - matthiaskrgr:rollup-cxrdbzy, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #104531 (Provide a better error and a suggestion for `Fn` traits with lifetime params)
 - #105899 (`./x doc library --open` opens `std`)
 - #106190 (Account for multiple multiline spans with empty padding)
 - #106202 (Trim more paths in obligation types)
 - #106234 (rustdoc: simplify settings, help, and copy button CSS by not reusing)
 - #106236 (docs/test: add docs and a UI test for `E0514` and `E0519`)
 - #106259 (Update Clippy)
 - #106260 (Fix index out of bounds issues in rustdoc)
 - #106263 (Formatter should not try to format non-Rust files)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-29 19:40:06 +00:00
Matthias Krüger
6b792e9178
Rollup merge of #106202 - estebank:trim-paths, r=Nilstrieb
Trim more paths in obligation types
2022-12-29 18:24:31 +01:00
Matthias Krüger
313541c766
Rollup merge of #106223 - estebank:suggest-let-ty-borrow, r=compiler-errors
On unsized locals with explicit types suggest `&`

Fix #72742.
2022-12-29 13:16:04 +01: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
Esteban Küber
083eb936ec On unsized locals with explicit types suggest &
Fix #72742.
2022-12-28 11:03:28 -08: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
Deadbeef
983606d367 Allow trait method paths to satisfy const Fn bounds 2022-12-28 09:06:31 +00:00
Michael Goulet
96d8011fa8 better names and a comment 2022-12-28 04:18:37 +00:00
Esteban Küber
b6453a454f Trim more paths in obligation types 2022-12-27 18:56:00 -08:00
Michael Goulet
9f59ab55e6 Restore cyclic closure message 2022-12-27 17:56:57 +00:00
fee1-dead
24265827c8
Rollup merge of #106151 - TaKO8Ki:remove-unused-imports, r=jackh726
Remove unused imports
2022-12-27 00:34:53 +08:00
Takayuki Maeda
a8f468f5c6 remove unused imports 2022-12-26 15:01:20 +09:00
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