Commit Graph

2712 Commits

Author SHA1 Message Date
lcnr
6691c4cdad forbid escaping bound vars in combine
removes the `CollectAllMismatches` in favor of a slightly
more manual approach.
2023-05-05 13:51:19 +02:00
Michael Goulet
964fb67a5f Use fulfillment to check Drop impl compatibility 2023-05-04 18:05:58 +00:00
León Orell Valerian Liehr
cd6dec33c2
IAT: Proper WF computation 2023-05-04 17:00:33 +02:00
León Orell Valerian Liehr
e8139dfd5a
IAT: Introduce AliasKind::Inherent 2023-05-04 16:59:10 +02:00
bors
6f8c0557e0 Auto merge of #110806 - WaffleLapkin:unmkI, r=lcnr
Replace `tcx.mk_trait_ref` with `TraitRef::new`

First step in implementing https://github.com/rust-lang/compiler-team/issues/616
r? `@lcnr`
2023-05-04 05:54:09 +00:00
Michael Goulet
fef2f5b815 Rename things to reflect that they're not item specific 2023-05-03 20:13:32 +00:00
Dylan DPC
80df4ab403
Rollup merge of #110791 - compiler-errors:negative-bounds, r=oli-obk
Implement negative bounds for internal testing purposes

Implements partial support the `!` negative polarity on trait bounds. This is incomplete, but should allow us to at least be able to play with the feature.

Not even gonna consider them as a public-facing feature, but I'm implementing them because would've been nice to have in UI tests, for example in #110671.
2023-05-04 00:17:23 +05:30
Nicholas Nethercote
6b62f37402 Restrict From<S> for {D,Subd}iagnosticMessage.
Currently a `{D,Subd}iagnosticMessage` can be created from any type that
impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static,
str>`, which are reasonable. It also includes `&String`, which is pretty
weird, and results in many places making unnecessary allocations for
patterns like this:
```
self.fatal(&format!(...))
```
This creates a string with `format!`, takes a reference, passes the
reference to `fatal`, which does an `into()`, which clones the
reference, doing a second allocation. Two allocations for a single
string, bleh.

This commit changes the `From` impls so that you can only create a
`{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static,
str>`. This requires changing all the places that currently create one
from a `&String`. Most of these are of the `&format!(...)` form
described above; each one removes an unnecessary static `&`, plus an
allocation when executed. There are also a few places where the existing
use of `&String` was more reasonable; these now just use `clone()` at
the call site.

As well as making the code nicer and more efficient, this is a step
towards possibly using `Cow<'static, str>` in
`{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing
the `From<&'a str>` impls to `From<&'static str>`, which is doable, but
I'm not yet sure if it's worthwhile.
2023-05-03 08:44:39 +10:00
Michael Goulet
03469c3f2e Make negative trait bounds work with the old trait solver 2023-05-02 22:36:25 +00:00
Michael Goulet
6e01e910cb Implement negative bounds 2023-05-02 22:36:24 +00:00
Dylan DPC
b727132e23
Rollup merge of #108161 - WaffleLapkin:const_param_ty, r=BoxyUwU
Add `ConstParamTy` trait

This is a bit sketch, but idk.
r? `@BoxyUwU`

Yet to be done:
- [x] ~~Figure out if it's okay to implement `StructuralEq` for primitives / possibly remove their special casing~~ (it should be okay, but maybe not in this PR...)
- [ ] Maybe refactor the code a little bit
- [x] Use a macro to make impls a bit nicer

Future work:
- [ ] Actually™ use the trait when checking if a `const` generic type is allowed
- [ ] _Really_ refactor the surrounding code
- [ ] Refactor `marker.rs` into multiple modules for each "theme" of markers
2023-05-02 11:44:50 +05:30
Matthias Krüger
1b262b8b56
Rollup merge of #110823 - compiler-errors:tweak-await-span, r=b-naber
Tweak await span to not contain dot

Fixes a discrepancy between method calls and await expressions where the latter are desugared to have a span that *contains* the dot (i.e. `.await`) but method call identifiers don't contain the dot. This leads to weird suggestions suggestions in borrowck -- see linked issue.

Fixes #110761

This mostly touches a bunch of tests to tighten their `await` span.
2023-05-01 01:09:47 +02:00
Dylan DPC
6da62a40f2
Rollup merge of #110614 - compiler-errors:new-solver-overflow-response, r=lcnr
Clear response values for overflow in new solver

When we have an overflow, return a trivial query response. This fixes an ICE with the code described in #110544:

```rust
trait Trait {}

struct W<T>(T);

impl<T, U> Trait for W<(W<T>, W<U>)>
where
    W<T>: Trait,
    W<U>: Trait,
{}

fn impls<T: Trait>() {}

fn main() {
    impls::<W<_>>()
}
```

Where, while proving `W<?0>: Trait`, we overflow but still apply the query response of `?0 = (W<?1>, W<?2>)`. Then while re-processing the query to validate that our evaluation result was stable, we get a different query response that looks like `?1 = (W<?3>, W<?4>), ?2 = (W<?5>, W<?6>)`, and so we trigger the ICE.

Also, by returning a trivial query response we also avoid the infinite-loop/OOM behavior of the old solver.

r? ``@lcnr``
2023-04-29 11:27:54 +05:30
Michael Goulet
6d6c904431 Make async removal span more resilient to macro expansions 2023-04-27 18:25:07 +00:00
Michael Goulet
e6077fc1b8 tweak removal span 2023-04-27 17:18:12 +00:00
Michael Goulet
f0fc4f9acf Tweak await span 2023-04-27 17:18:11 +00:00
Maybe Waffle
1bf6bbb1bd Impl StructuralEq & ConstParamTy for str, &T, [T; N] and [T] 2023-04-27 15:59:07 +00:00
Maybe Waffle
1c544108b1 Check the correct trait when checking ConstParamTy impls 2023-04-27 15:46:23 +00:00
Maybe Waffle
9a716dafbe Add a ConstParamTy trait 2023-04-27 15:46:21 +00:00
Boxy
842419712a rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
Boxy
f04b8fe0af rename needs_infer to has_infer 2023-04-27 08:35:19 +01:00
Michael Goulet
ee8942138a Split out make_ambiguous_response_no_constraints 2023-04-26 22:33:49 +00:00
Michael Goulet
5fa82092ae Clear response values for overflow in new solver 2023-04-26 21:54:30 +00:00
Maybe Waffle
39b95c965a Don't return a Binder from TraitRef::identity 2023-04-26 11:59:51 +00:00
Maybe Waffle
1b8c7784e5 Add new ToPredicate impls and TraitRef methods to remove some ty::Binber::dummy calls 2023-04-26 11:48:17 +00:00
Maybe Waffle
4f2532fb53 Switch ty::TraitRef::from_lang_item from using TyCtxtAt to TyCtxt and a Span 2023-04-26 10:55:11 +00:00
Maybe Waffle
071f737a57 Remove some more useless ty::Binder::dummy calls 2023-04-26 10:38:54 +00:00
Nicholas Nethercote
8216b7f229 Make some region folders a little stricter.
Because certain regions cannot occur in them.
2023-04-26 10:14:16 +10:00
Matthias Krüger
95e9f68eb5
Rollup merge of #110671 - compiler-errors:polarity, r=lcnr
Consider polarity in new solver

It's kinda ugly to have a polarity check in all of the builtin impls -- I guess I could consider the polarity at the top of assemble-builtin but that would require adding a polarity fn to `GoalKind`...

🤷 putting this up just so i dont forget, since it's needed to bootstrap core during coherence (this alone does not allow core to bootstrap though, additional work is needed!)

r? ``@lcnr``
2023-04-25 21:06:34 +02:00
Matthias Krüger
297b222066
Rollup merge of #110556 - kylematsuda:earlybinder-explicit-item-bounds, r=compiler-errors
Switch to `EarlyBinder` for `explicit_item_bounds`

Part of the work to finish https://github.com/rust-lang/rust/issues/105779.

This PR adds `EarlyBinder` to the return type of the `explicit_item_bounds` query and removes `bound_explicit_item_bounds`.

r? `@compiler-errors` (hope it's okay to request you, since you reviewed #110299 and #110498 😃)
2023-04-25 21:06:32 +02:00
Maybe Waffle
c727edc0b7 Remove some useless ty::Binder::dummy calls 2023-04-25 16:47:00 +00:00
Maybe Waffle
46b01abbcd Replace tcx.mk_trait_ref with ty::TraitRef::new 2023-04-25 16:12:44 +00:00
Matthias Krüger
5f33a8c026
Rollup merge of #110563 - bryangarza:refactor-trait-selection-error-reporting, r=compiler-errors
Break up long function in trait selection error reporting + clean up nearby code

- Move blocks of code into their own functions
- Replace a few function argument types with their type aliases
- Create "AppendConstMessage" enum to replace a nested `Option`.
2023-04-25 06:46:48 +02:00
Michael Goulet
794cb890de Consider polarity in new solver 2023-04-24 18:59:42 +00:00
Yuki Okushi
a373623d55
Rollup merge of #110681 - klensy:cut-dep, r=lcnr
drop few unused crates, gate libc under unix for rustc_codegen_ssa

Small cleanup.
2023-04-25 02:33:29 +09:00
Maybe Waffle
e496fbec92 Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
Matthias Krüger
8aab707131
Rollup merge of #110566 - compiler-errors:bad-projection-term, r=cjgillot,BoxyUwU
Don't create projection ty for const projection

Fixes #110549
2023-04-24 07:53:24 +02:00
Matthias Krüger
d60c64a0c5
Rollup merge of #110514 - compiler-errors:remove-find_map_relevant_impl, r=b-naber
Remove `find_map_relevant_impl`

Fixes #108895
2023-04-24 07:53:24 +02:00
Michael Goulet
cde5bcafe8 Don't create projection ty for const projection 2023-04-23 18:09:30 +00:00
klensy
3338ee3ca7 drop unused deps, gate libc under unix for one crate 2023-04-22 15:22:21 +03:00
Michael Goulet
6041030c0f Expect that equating a projection term always succeeds in new solver 2023-04-22 06:07:18 +00:00
Bryan Garza
55e5a1d206 Create "AppendConstMessage" enum
This patch creates an enum to replace a nested `Option`.
2023-04-21 14:07:41 -07:00
Bryan Garza
d0d40d2a40 Break up long function in trait selection error reporting
- Move blocks of code into their own functions
- Replace a few function argument types with their type aliases
2023-04-21 09:04:02 -07:00
bors
1f5768bc67 Auto merge of #96840 - cjgillot:query-feed, r=oli-obk
Allow to feed a value in another query's cache and remove `WithOptConstParam`

I used it to remove `WithOptConstParam` queries, as an example.

The idea is that a query (here `typeck(function)`) can write into another query's cache (here `type_of(anon const)`). The dependency node for `type_of` would depend on all the current dependencies of `typeck`.

There is still an issue with cycles: if `type_of(anon const)` is accessed before `typeck(function)`, we will still have the usual cycle.  The way around this issue is to `ensure` that `typeck(function)` is called before accessing `type_of(anon const)`.

When replayed, we may the following cases:
- `typeck` is green, in that case `type_of` is green too, and all is right;
- `type_of` is green, `typeck` may still be marked as red (it depends on strictly more things than `type_of`) -> we verify that the saved value and the re-computed value of `type_of` have the same hash;
- `type_of` is red, then `typeck` is red -> it's the caller responsibility to ensure `typeck` is recomputed *before* `type_of`.

As `anon consts` have their own `DefPathData`, it's not possible to have the def-id of the anon-const point to something outside the original function, but the general case may have to be resolved before using this device more broadly.

There is an open question about loading from the on-disk cache.  If `typeck` is loaded from the on-disk cache, the side-effect does not happen. The regular `type_of` implementation can go and fetch the correct value from the decoded `typeck` results, and the dep-graph will check that the hashes match, but I'm not sure we want to rely on this behaviour.

I specifically allowed to feed the value to `type_of` from inside a call to `type_of`.  In that case, the dep-graph will check that the fingerprints of both values match.

This implementation is still very sensitive to cycles, and requires that we call `typeck(function)` before `typeck(anon const)`.  The reason is that `typeck(anon const)` calls `type_of(anon const)`, which calls `typeck(function)`, which feeds `type_of(anon const)`, and needs to build the MIR so needs `typeck(anon const)`.  The latter call would not cycle, since `type_of(anon const)` has been set, but I'd rather not remove the cycle check.
2023-04-21 08:04:58 +00:00
Michael Goulet
3206100ed9 Result is just bool but special 2023-04-20 18:40:34 +00:00
Kyle Matsuda
e54854f6a9 add subst_identity_iter and subst_identity_iter_copied methods on EarlyBinder; use this to simplify some EarlyBinder noise around explicit_item_bounds calls 2023-04-20 12:36:50 -06:00
Kyle Matsuda
f3b279fcc5 add EarlyBinder to output of explicit_item_bounds; replace bound_explicit_item_bounds usages; remove bound_explicit_item_bounds query 2023-04-20 12:36:50 -06:00
Kyle Matsuda
0892a7380b change usages of explicit_item_bounds to bound_explicit_item_bounds 2023-04-20 12:36:50 -06:00
Camille GILLOT
b275d2c30b Remove WithOptconstParam. 2023-04-20 17:48:32 +00:00
Michael Goulet
4fd7739aac Track if EvalCtxt has been tainted, make sure it can't be used to make query responses after 2023-04-20 16:54:39 +00:00
Matthias Krüger
75de33cd1d
Rollup merge of #110531 - lcnr:type-system-stuff, r=aliemjay
small type system cleanup
2023-04-19 17:54:42 +02:00
lcnr
16d061ea77 small type system cleanup 2023-04-19 10:30:30 +02:00
bors
d7f9e81650 Auto merge of #110407 - Nilstrieb:fluent-macro, r=davidtwco
Add `rustc_fluent_macro` to decouple fluent from `rustc_macros`

Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`).
2023-04-19 08:26:47 +00:00
Matthias Krüger
fdd2f4bde8
Rollup merge of #110510 - bryangarza:issue-110467-safe-transmute, r=compiler-errors
Fix ICE for transmutability in candidate assembly

Don't skip transmutability check just because there may be generics in the ParamEnv.

Fixes #110467
2023-04-19 06:35:36 +02:00
Matthias Krüger
9f0b16b2bb
Rollup merge of #110498 - kylematsuda:earlybinder-rpitit-tys, r=compiler-errors
Switch to `EarlyBinder` for `collect_return_position_impl_trait_in_trait_tys`

Part of the work to finish https://github.com/rust-lang/rust/issues/105779.

This PR adds `EarlyBinder` to the return type of the `collect_return_position_impl_trait_in_trait_tys` query and removes `bound_return_position_impl_trait_in_trait_tys`.

r? `@lcnr`
2023-04-19 06:35:35 +02:00
Michael Goulet
14678778dc Remove find_map_relevant_impl 2023-04-19 02:01:55 +00:00
Bryan Garza
238756e45d Fix ICE for transmutability in candidate assembly
Don't skip transmutability check just because there may be generics in the
ParamEnv.

Fixes #110467
2023-04-18 17:33:46 -07:00
Kyle Matsuda
522bc5f817 add EarlyBinder to return type of collect_return_position_impl_trait_in_trait_tys query; remove bound_X version 2023-04-18 16:33:06 -06:00
Nilstrieb
b5d3d970fa Add rustc_fluent_macro to decouple fluent from rustc_macros
Fluent, with all the icu4x it brings in, takes quite some time to
compile. `fluent_messages!` is only needed in further downstream rustc
crates, but is blocking more upstream crates like `rustc_index`. By
splitting it out, we allow `rustc_macros` to be compiled earlier, which
speeds up `x check compiler` by about 5 seconds (and even more after the
needless dependency on `serde_json` is removed from
`rustc_data_structures`).
2023-04-18 18:56:22 +00:00
Josh Soref
e09d0d2a29 Spelling - compiler
* account
* achieved
* advising
* always
* ambiguous
* analysis
* annotations
* appropriate
* build
* candidates
* cascading
* category
* character
* clarification
* compound
* conceptually
* constituent
* consts
* convenience
* corresponds
* debruijn
* debug
* debugable
* debuggable
* deterministic
* discriminant
* display
* documentation
* doesn't
* ellipsis
* erroneous
* evaluability
* evaluate
* evaluation
* explicitly
* fallible
* fulfill
* getting
* has
* highlighting
* illustrative
* imported
* incompatible
* infringing
* initialized
* into
* intrinsic
* introduced
* javascript
* liveness
* metadata
* monomorphization
* nonexistent
* nontrivial
* obligation
* obligations
* offset
* opaque
* opportunities
* opt-in
* outlive
* overlapping
* paragraph
* parentheses
* poisson
* precisely
* predecessors
* predicates
* preexisting
* propagated
* really
* reentrant
* referent
* responsibility
* rustonomicon
* shortcircuit
* simplifiable
* simplifications
* specify
* stabilized
* structurally
* suggestibility
* translatable
* transmuting
* two
* unclosed
* uninhabited
* visibility
* volatile
* workaround

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-17 16:09:18 -04:00
Matthias Krüger
0790996a07
Rollup merge of #110394 - scottmcm:less-idx-new, r=WaffleLapkin
Various minor Idx-related tweaks

Nothing particularly exciting here, but a couple of things I noticed as I was looking for more index conversions to simplify.

cc https://github.com/rust-lang/compiler-team/issues/606
r? `@WaffleLapkin`
2023-04-17 18:13:35 +02:00
Matthias Krüger
1795bf8222
Rollup merge of #110404 - matthiaskrgr:mapmap, r=Nilstrieb
fix clippy::toplevel_ref_arg and ::manual_map

r? ``@Nilstrieb``
2023-04-17 08:09:40 +02:00
Michael Goulet
f6bfb4bf8e Erase regions when confirming transmutability candidate 2023-04-16 19:12:34 +00:00
Matthias Krüger
543f8bc38c fix clippy::toplevel_ref_arg and ::manual_map 2023-04-16 13:28:13 +02:00
fee1-dead
eba419195c
Rollup merge of #110345 - nnethercote:rm-Super-impls-for-Region, r=compiler-errors
Remove `TypeSuper{Foldable,Visitable}` impls for `Region`.

These traits exist so that folders/visitors can recurse into types of interest: binders, types, regions, predicates, and consts. But `Region` is non-recursive and cannot contain other types of interest, so its methods in these traits are trivial.

This commit inlines and removes those trivial methods.

r? `@compiler-errors`
2023-04-16 18:55:38 +08:00
fee1-dead
a5136f14ae
Rollup merge of #109665 - fee1-dead-contrib:rm-remap-queries, r=oli-obk
Remove `remap_env_constness` in queries

This removes some of the complexities with const traits. #88119 used to be caused by this but was fixed by `param_env = param_env.without_const()`.
2023-04-16 18:55:38 +08:00
Scott McMurray
c98895d9f2 Various minor Idx-related tweaks
Nothing particularly exciting here, but a couple of things I noticed as I was looking for more index conversions to simplify.
2023-04-16 02:42:50 -07:00
Nicholas Nethercote
4460a1dc28 Remove TypeSuper{Foldable,Visitable} impls for Region.
These traits exist so that folders/visitors can recurse into types of
interest: binders, types, regions, predicates, and consts. But `Region`
is non-recursive and cannot contain other types of interest, so its
methods in these traits are trivial.

This commit inlines and removes those trivial methods.
2023-04-16 09:11:43 +10:00
Yuki Okushi
99e59dbef3
Rollup merge of #110364 - matthiaskrgr:anti_clone, r=Nilstrieb
remove redundant clones
2023-04-16 06:55:23 +09:00
Yuki Okushi
52d23c9253
Rollup merge of #110272 - Ezrashaw:fix-unconned-lt-in-implbounds, r=aliemjay
fix: skip implied bounds if unconstrained lifetime exists

Fixes #110161

r? ````@aliemjay````
2023-04-16 06:55:21 +09:00
Matthias Krüger
1077d574cf remove redundant clones 2023-04-15 18:04:51 +02:00
Ali MJ Al-Nasrawy
4c80f58d41
Update compiler/rustc_trait_selection/src/traits/outlives_bounds.rs 2023-04-15 15:41:42 +03:00
Ezra Shaw
b506d966a3
implement review suggestions 2023-04-14 20:18:28 +12:00
Matthias Krüger
610bc68675
Rollup merge of #110299 - kylematsuda:earlybinder-impl-subject, r=compiler-errors
Switch to `EarlyBinder` for `impl_subject` query

Part of the work to finish https://github.com/rust-lang/rust/issues/105779.

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

r? ```@lcnr```
2023-04-14 07:58:42 +02:00
Matthias Krüger
69d7172b8e
Rollup merge of #110207 - compiler-errors:new-solver-unpin, r=lcnr
Assemble `Unpin` candidates specially for generators in new solver

Fixes compiler-errors/next-solver-hir-issues#16

r? ``@lcnr``
2023-04-14 07:58:40 +02:00
Matthias Krüger
44db7c3b5a
Rollup merge of #110180 - lcnr:canonicalize, r=compiler-errors
don't uniquify regions when canonicalizing

uniquifying causes a bunch of issues, most notably it causes `AliasEq(<?x as Trait<'a>>::Assoc, <?x as Trait<'a>>::Assoc)` to result in ambiguity because both `normalizes-to` paths result in ambiguity and substs equate should trivially succeed but doesn't because we uniquified `'a` to two different regions.

I originally added uniquification to make it easier to deal with requirement 6 from the dev-guide: https://rustc-dev-guide.rust-lang.org/solve/trait-solving.html#requirements

> ### 6. Trait solving must be (free) lifetime agnostic
>
> Trait solving during codegen should have the same result as during typeck. As we erase
> all free regions during codegen we must not rely on them during typeck. A noteworthy example
> is special behavior for `'static`.

cc https://github.com/rust-lang/rustc-dev-guide/pull/1671

Relying on regions being identical may cause ICE during MIR typeck, but even without this PR we can end up relying on that as type inference vars can resolve to types which contain an identical region. Let's land this and deal with any ICE that crop up as we go. Will look at this issue again before stabilization.

r? ```@compiler-errors```
2023-04-14 07:58:40 +02:00
Matthias Krüger
c6223e198d
Rollup merge of #109800 - bryangarza:safe-transmute-improved-errors, r=compiler-errors
Improve safe transmute error reporting

This patch updates the error reporting when Safe Transmute is not possible between 2 types by including the reason.

Also, fix some small bugs that occur when computing the `Answer` for transmutability.
2023-04-14 07:58:39 +02:00
Michael Goulet
319c790600 Move auto trait built-in candidate disqualification to a separate method 2023-04-14 03:14:02 +00:00
Michael Goulet
b335c2d49f Assemble Unpin candidates specially for generators in new solver 2023-04-14 03:13:56 +00:00
Bryan Garza
36febe1f4d Improve safe transmute error reporting
This patch updates the error reporting when Safe Transmute is not
possible between 2 types by including the reason.

Also, fix some small bugs that occur when computing the `Answer` for
transmutability.
2023-04-13 21:57:08 +00:00
Kyle Matsuda
e2f5a5a71f make tcx.impl_subject return EarlyBinder, remove bound_impl_subject, rename usages of bound_impl_subject to impl_subject 2023-04-13 15:56:00 -06:00
Kyle Matsuda
dcc51f1ef5 change usage of bound_impl_subject to impl_subject 2023-04-13 15:55:54 -06:00
Matthias Krüger
232eb698ed
Rollup merge of #110193 - compiler-errors:body-owner-issue, r=WaffleLapkin
Check for body owner fallibly in error reporting

Sometimes the "body id" we use for an obligation cause is not actually a body owner, like when we're doing WF checking on items.

Fixes #110157
2023-04-13 21:58:36 +02:00
Matthias Krüger
6f1500aec2
Rollup merge of #110220 - lcnr:regionzz, r=compiler-errors
cleanup our region error API

- require `TypeErrCtxt` to always result in an error, closing #108810
- move `resolve_regions_and_report_errors` to the `ObligationCtxt`
- call `process_registered_region_obligations` in `resolve_regions`
- move `resolve_regions` into the `outlives` submodule
- add `#[must_use]` to functions returning lists of errors

r? types
2023-04-13 11:21:05 +02:00
Ezra Shaw
ecf2a9b75e
fix: skip implied bounds if unconstrained lifetime exists 2023-04-13 20:29:41 +12:00
Nicholas Nethercote
72605cd267 Remove some unused type folders.
I'm surprised the compiler doesn't warn about these. It appears having
an `impl` on a struct is enough to avoid a warning about it never being
constructed.
2023-04-13 12:20:44 +10:00
bors
9693b178fc Auto merge of #110252 - matthiaskrgr:rollup-ovaixra, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #109810 (Replace rustdoc-ui/{c,z}-help tests with a stable run-make test )
 - #110035 (fix: ensure bad `#[test]` invocs retain correct AST)
 - #110089 (sync::mpsc: synchronize receiver disconnect with initialization)
 - #110103 (Report overflows gracefully with new solver)
 - #110122 (Fix x check --stage 1 when download-ci-llvm=false)
 - #110133 (Do not use ImplDerivedObligationCause for inherent impl method error reporting)
 - #110135 (Revert "Don't recover lifetimes/labels containing emojis as character literals")
 - #110235 (Fix `--extend-css` option)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-04-12 22:19:29 +00:00
lcnr
c0d3d32922 fix comment 2023-04-12 22:07:07 +02:00
Matthias Krüger
92eb36461b
Rollup merge of #110103 - compiler-errors:new-solver-overflows, r=lcnr
Report overflows gracefully with new solver

avoid reporting overflows as ambiguity errors, so that the error message is clearer.

r? ```@lcnr```
2023-04-12 22:04:33 +02:00
Matthias Krüger
331e7c3659
Rollup merge of #110153 - DaniPopes:compiler-typos, r=Nilstrieb
Fix typos in compiler

I ran [`typos -w compiler`](https://github.com/crate-ci/typos) to fix typos in the `compiler` directory.

Refs #110150
2023-04-12 20:56:21 +02:00
lcnr
cc82ccb145 #[must_use] for fns returning a list of errors 2023-04-12 10:55:14 +02:00
bors
9be9b5e09a Auto merge of #107614 - compiler-errors:allow-elaborator-to-filter-only-super-traits, r=oli-obk
Split implied and super predicate queries, then allow elaborator to filter only supertraits

Split the `super_predicates_of` query into a new `implied_predicates_of` query. The former now only returns the *real* supertraits of a trait alias, and the latter now returns the implied predicates (which include all of the `where` clauses of the trait alias). The behavior of these queries is identical for regular traits.

Now that the two queries are split, we can add a new filter method to the elaborator, `filter_only_self()`, which can be used in instances that we need only the *supertrait* predicates, such as during the elaboration used in closure signature deduction. This toggles the usage of `super_predicates_of` instead of `implied_predicates_of` during elaboration of a trait predicate.

This supersedes #104745, and fixes the four independent bugs identified in that PR.
Fixes #104719
Fixes #106238
Fixes #110023
Fixes #109514

r? types
2023-04-12 08:39:19 +00:00
lcnr
a19adefa0e region error cleanup
- require `TypeErrCtxt` to always result in an error
- move `resolve_regions_and_report_errors` to the `ObligationCtxt`
- merge `process_registered_region_obligations` into `resolve_regions`
2023-04-12 10:24:36 +02:00
Michael Goulet
87c9b3f35e
Rollup merge of #110126 - compiler-errors:new-solver-safe-transmute, r=oli-obk
Support safe transmute in new solver

Basically copies the same implementation as the old solver, but instead of looking for param types, we look for type or const placeholders.
2023-04-11 20:28:48 -07:00
Michael Goulet
7ec72efe10 Allow the elaborator to only filter to real supertraits 2023-04-11 17:45:42 +00:00
Michael Goulet
25c342f30a Split implied and super predicate queries 2023-04-11 17:45:42 +00:00
Michael Goulet
1178c49a1b Check for body owner fallibly 2023-04-11 16:52:40 +00:00
lcnr
171f541470 don't uniquify regions when canonicalizing 2023-04-11 10:25:49 +02:00
DaniPopes
677357d32b
Fix typos in compiler 2023-04-10 22:02:52 +02:00
Michael Goulet
05a6daab84 Report overflows gracefully with new solver 2023-04-10 16:36:30 +00:00
Michael Goulet
d92f74e43b Support safe transmute in new solver 2023-04-10 16:08:14 +00:00
Michael Goulet
8d2dbba63e Stall auto-trait assembly for int/float vars in new solver 2023-04-10 15:54:14 +00:00
lcnr
3fab7f7c13 review + some small stuff 2023-04-10 09:21:21 +02:00
lcnr
2186847f28 move structural_traits into assembly 2023-04-10 09:18:47 +02:00
lcnr
2b0f5721c1 prioritize param-env candidates 2023-04-10 09:16:33 +02:00
bors
0030465bcc Auto merge of #109413 - compiler-errors:pointer-like-abi, r=cjgillot
Enforce that `PointerLike` requires a pointer-like ABI

At least temporarily, let's ban coercing things that are pointer-sized and pointer-aligned but *not* `Abi::Scalar(..)` into `dyn*`. See: https://github.com/rust-lang/rust/pull/104694#discussion_r1142522073

This can be lifted in the future if we decie that we *want* to be able to coerce something `repr(C)` into a `dyn*`, but we'll have to figure out what to do with Miri and codegen...

r? compiler
2023-04-09 02:41:58 +00:00
bors
f8ed97ecc1 Auto merge of #110031 - compiler-errors:generic-elaboration, r=b-naber
Make elaboration generic over input

Combines all the `elaborate_*` family of functions into just one, which is an iterator over the same type that you pass in (e.g. elaborating `Predicate` gives `Predicate`s, elaborating `Obligation`s gives `Obligation`s, etc.)
2023-04-09 00:18:10 +00:00
Michael Goulet
920c51c526 Enforce that PointerLike requires a pointer-like ABI 2023-04-08 21:11:16 +00:00
Deadbeef
954d9a8f8e Remove remap_env_constness in queries 2023-04-08 09:13:18 +00:00
Andrew Xie
9920baba5f Switched provisional evaluation cache map to FxIndexMap, and replaced map.drain_filter with map.retain 2023-04-07 19:41:08 -04:00
Jack Huey
b15195a304 Remove u32 on BoundTyKind::Anon 2023-04-06 23:08:04 -04:00
Jack Huey
f0edcc8a6f Remove index from BrAnon 2023-04-06 23:01:40 -04:00
Jack Huey
167b70692b Remove expect_anon and expect_anon_placeholder in favor of var 2023-04-06 23:01:38 -04:00
Jack Huey
4646b3df6a Use BoundTy and BoundRegion instead of kind of PlaceholderTy and PlaceholderRegion 2023-04-06 23:01:35 -04:00
Michael Goulet
2cd0729d63 Get rid of elaborate_trait_ref{s} too 2023-04-06 23:30:22 +00:00
Michael Goulet
758bedc104 Make elaborator generic 2023-04-06 23:30:22 +00:00
Matthias Krüger
c86c9339e6
Rollup merge of #109755 - compiler-errors:new-solver-generator-witness-mir, r=cjgillot
Implement support for `GeneratorWitnessMIR` in new solver

r? ```@cjgillot```

I mostly want this to cut down the number of failing UI tests when running the UI test suite with `--compare-mode=next-solver`, but there doesn't seem like much reason to block implementing this since it adds minimal complexity to the existing structural traits impl in the new solver.

If others are against adding this for some reason, then maybe we should just make `GeneratorWitnessMIR` return `NoSolution` for these traits. Anything but an ICE please 😸 🧊
2023-04-06 18:42:57 +02:00
Yuki Okushi
038ece0a42
Rollup merge of #109956 - compiler-errors:tweak-debug-outputs, r=oli-obk
Tweak debug outputs to make debugging new solver easier

1. Move the fields that are "most important" (I know this is subjective) to the beginning of the structs.

For goals, I typically care more about the predicate than the param-env (which is significantly longer in debug output).
For canonicalized things, I typically care more about what is *being* canonicalized.
For a canonical response, I typically care about the response -- or at least, it's typically useful to put it first since it's short and affects the whether the solver recurses or not...

2. Add some more debug and instrument calls to functions to add more structure to tracing lines.

r? `@oli-obk` or `@BoxyUwU` (since I think `@lcnr` is on holiday)
2023-04-05 20:47:24 +09:00
Michael Goulet
786fc90855 Tweak debug outputs to make debugging new solver easier 2023-04-05 03:18:29 +00:00
Michael Goulet
4a4fc3bb5b Implement support for GeneratorWitnessMIR in new solver 2023-04-05 03:04:54 +00:00
bors
be8e5ba157 Auto merge of #109917 - compiler-errors:remove-relation-methods, r=oli-obk
Remove `intercrate` and `mark_ambiguous` from `TypeRelation`

Fixes #109863

Pulls this logic into `super_combine_tys`, which has access to `InferCtxt` and takes a `ObligationEmittingRelation` -- both of which simplify the logic here.

r? `@oli-obk` `@aliemjay`
2023-04-04 11:08:23 +00:00
Michael Goulet
a368316905 Remove intercrate and mark_ambiguous from Relation 2023-04-04 00:09:12 +00:00
Nilstrieb
ca79b82c6c Never consider int and float vars for FnPtr candidates
This solves a regression where `0.0.cmp()` was ambiguous when a custom
trait with a `cmp` method was in scope.

FOr integers it shouldn't be a problem in practice so I wasn't able to
add a test.
2023-04-03 15:25:06 +00:00
Nilstrieb
59f394bf86
Rollup merge of #109846 - matthiaskrgr:clippy2023_04_III, r=Nilstrieb
more clippy::complexity fixes (iter_kv_map, map_flatten, nonminimal_bool)
2023-04-02 10:08:35 +02:00
Matthias Krüger
5a07e33d2c use and_then/flat_map for map().flatten() 2023-04-01 23:50:45 +02:00
Matthias Krüger
8ef3bf29fe a couple clippy::complexity fixes
map_identity
filter_next
option_as_ref_deref
unnecessary_find_map
redundant_slicing
unnecessary_unwrap
bool_comparison
derivable_impls
manual_flatten
needless_borrowed_reference
2023-04-01 23:16:33 +02:00
bors
eb3e9c1f45 Auto merge of #109762 - scottmcm:variantdef-indexvec, r=WaffleLapkin
Update `ty::VariantDef` to use `IndexVec<FieldIdx, FieldDef>`

And while doing the updates for that, also uses `FieldIdx` in `ProjectionKind::Field` and `TypeckResults::field_indices`.

There's more places that could use it (like `rustc_const_eval` and `LayoutS`), but I tried to keep this PR from exploding to *even more* places.

Part 2/? of https://github.com/rust-lang/compiler-team/issues/606
2023-03-31 03:36:18 +00:00
Michael Goulet
7cd96ae2d7
Rollup merge of #109739 - compiler-errors:new-solver-closure-fnonce, r=lcnr
Closures always implement `FnOnce` in new solver

We should process `[closure]: FnOnce(Tys...) -> Ty` obligations *before* fallback and closure analysis. We can do this by taking advantage of the fact that `FnOnce` is always implemented by closures, even before we definitely know the closure kind.

Fixes compiler-errors/next-solver-hir-issues#15

r? ``@oli-obk`` (trying to spread the reviewer load for new trait solver prs, and this one is pretty self-contained, though feel free to reassign 😸)
2023-03-30 12:42:20 -07:00
Michael Goulet
1ffb1afea7
Rollup merge of #109679 - compiler-errors:normalizes-to-hack-2, r=lcnr,BoxyUwU
Freshen normalizes-to hack goal RHS in the evaluate loop

Ensure that we repeatedly equate the unconstrained RHS of the normalizes-to hack goal with the *actual* RHS of the goal, even if the normalizes-to goal loops several times and thus we replace the unconstrained RHS var repeatedly.

Alternative to #109583.
2023-03-30 12:42:18 -07:00
Scott McMurray
4abb455529 Update ty::VariantDef to use IndexVec<FieldIdx, FieldDef>
And while doing the updates for that, also uses `FieldIdx` in `ProjectionKind::Field` and `TypeckResults::field_indices`.

There's more places that could use it (like `rustc_const_eval` and `LayoutS`), but I tried to keep this PR from exploding to *even more* places.

Part 2/? of https://github.com/rust-lang/compiler-team/issues/606
2023-03-30 09:23:40 -07:00
Michael Goulet
177997e383 Closures always implement FnOnce in new solver 2023-03-30 15:11:42 +00:00
Yuki Okushi
e1f4ddfdd9
Rollup merge of #109749 - compiler-errors:new-solver-float-var, r=lcnr
Canonicalize float var as float in new solver

Typo in new canonicalizer -- we should be canonicalizing float vars as `CanonicalTyVarKind::Float`, not `CanonicalTyVarKind::Int`.

Fixes compiler-errors/next-solver-hir-issues#9
2023-03-30 21:07:02 +09:00
Yuki Okushi
c1b28c3435
Rollup merge of #109748 - compiler-errors:new-solver-discr-kind-ice, r=lcnr
Don't ICE on `DiscriminantKind` projection in new solver

As title says, since we now actually call `Ty::discriminant_kind` on placeholder types 😃

Also drive-by simplify `Pointee::Metadata` projection logic, and fix the UI test because the `<T as Pointee>::Metadata` tests weren't actually exercising the new projection logic, since we still eagerly normalize (which hits `project.rs` in the old solver) in HIR typeck.

r? `@lcnr` tho feel free to re-roll, this pr is very low-priority and not super specific to the new trait solver.

Fixes compiler-errors/next-solver-hir-issues#14
2023-03-30 21:07:02 +09:00
Michael Goulet
977694aaec canonicalize float var as float in new solver 2023-03-30 01:15:37 +00:00
Michael Goulet
321a5dba9e Check pointee metadata correctly in ui test 2023-03-30 00:53:17 +00:00
Michael Goulet
f5c78c4d3a Don't ICE on DiscriminantKind projection in new solver 2023-03-30 00:53:16 +00:00
Matthias Krüger
80e988d7a6
Rollup merge of #109675 - compiler-errors:object-heck, r=lcnr
Do not consider elaborated projection predicates for objects in new solver

Object types have projection bounds which are elaborated during astconv. There's no need to do it again for projection goals, since that'll give us duplicate projection candidatesd that are distinct up to regions due to the fact that we canonicalize every region to a separate variable. See quick example below the break for a better explanation.

Discussed this with lcnr, and adding a stop-gap until we get something like intersection region constraints (or modify canonicalization to canonicalize identical regions to the same canonical regions) -- after which, this will hopefully not matter and may be removed.

r? `@lcnr`

---

See `tests/ui/traits/new-solver/more-object-bound.rs`:

Consider a goal: `<dyn Iter<'a, ()> as Iterator>::Item = &'a ()`.

After canonicalization: `<dyn Iter<'!0r, (), Item = '!1r ()> as Iterator>::Item == &!'2r ()`
* First object candidate comes from the item bound in the dyn's bounds itself, giving us `<dyn Iter<'!0r, (), Item = '?!r ()> as Iterator>::Item == &!'1r ()`. This gives us one region constraint: `!'1r == !'2r`.
* Second object candidate comes from elaborating the principal trait ref, gives us `<dyn Iter<'!0r, (), Item = '!1r ()> as Iterator>::Item == &!'0r ()`. This gives us one region constraint: `!'0r == !'2r`.
* Oops! Ambiguity!
2023-03-29 21:19:49 +02:00
Matthias Krüger
9f28c98357
Rollup merge of #109511 - compiler-errors:eval-ctxt-infcx-private, r=lcnr
Make `EvalCtxt`'s `infcx` private

To better protect against people doing bad things with the inner `InferCtxt`

r? `@lcnr`
2023-03-29 21:19:48 +02:00
Michael Goulet
0542b0d04d Freshen normalizes-to hack goal RHS in the evaluate loop 2023-03-29 16:22:17 +00:00
Michael Goulet
a61616a016 Move canonicalization code around 2023-03-29 16:19:40 +00:00
Michael Goulet
d62238d6a8 Do not consider elaborated projection predicates for objects in new solver 2023-03-29 16:13:05 +00:00
Dylan DPC
14157561fb
Rollup merge of #109718 - scottmcm:indexvec-last, r=Nilstrieb
Rename `IndexVec::last` → `last_index`

As I've been trying to replace a `Vec` with an `IndexVec`, having `last` exist on both but returning very different types makes the transition a bit awkward -- the errors are later, where you get things like "there's no `ty` method on `mir::Field`" rather than a more localized error like "hey, there's no `last` on `IndexVec`".

So I propose renaming `last` to `last_index` to help distinguish `Vec::last`, which returns an element, and `IndexVec::last_index`, which returns an index.

(Similarly, `Iterator::last` also returns an element, not an index.)
2023-03-29 14:07:31 +05:30
Dylan DPC
09e937744a
Rollup merge of #109683 - compiler-errors:self-ty-overflow, r=lcnr
Check for overflow in `assemble_candidates_after_normalizing_self_ty`

Prevents a stack overflow (⚠️ ) in the new solver when we have param-env candidates that look like: `T: Trait<Assoc = <T as Trait>::Assoc>`

The current error message looks bad, but that's because we don't distinguish overflow and other ambiguity errors. I'll break that out into a separate PR since the fix may be controversial.

r? `@lcnr`
2023-03-29 14:07:29 +05:30
Scott McMurray
843c5e361e Rename IndexVec::lastlast_index
As I've been trying to replace a `Vec` with an `IndexVec`, having `last` exist on both but returning very different types makes the transition a bit awkward -- the errors are later, where you get things like "there's no `ty` method on `mir::Field`" rather than a more localized error like "hey, there's no `last` on `IndexVec`".

So I propose renaming `last` to `last_index` to help distinguish `Vec::last`, which returns an element, and `IndexVec::last_index`, which returns an index.

(Similarly, `Iterator::last` also returns an element, not an index.)
2023-03-29 00:27:24 -07:00
Matthias Krüger
9d6c36e70b
Rollup merge of #109705 - lcnr:coherence-caching, r=compiler-errors
new solver: check for intercrate mode when accessing the cache

r? ``@compiler-errors``
2023-03-29 06:02:43 +02:00
Nicholas Nethercote
03923661af Inline and remove SelectionContext::fast_reject_trait_refs.
Because it has a single call site, and it lets us move a small amount of
the work outside the loop.
2023-03-29 06:48:52 +11:00
Nicholas Nethercote
47225e8700 Introduce DeepRejectCtxt::substs_refs_may_unify.
It factors out a repeated code pattern.
2023-03-29 06:48:48 +11:00
lcnr
27a3b10ed2 check for intercrate mode when accessing the cache 2023-03-28 21:45:35 +02:00
Michael Goulet
ef5f773bff Check for overflow in assemble_candidates_after_normalizing_self_ty 2023-03-28 17:07:01 +00:00
bors
478cbb42b7 Auto merge of #109692 - Nilstrieb:rollup-hq65rps, r=Nilstrieb
Rollup of 8 pull requests

Successful merges:

 - #91793 (socket ancillary data implementation for FreeBSD (from 13 and above).)
 - #92284 (Change advance(_back)_by to return the remainder instead of the number of processed elements)
 - #102472 (stop special-casing `'static` in evaluation)
 - #108480 (Use Rayon's TLV directly)
 - #109321 (Erase impl regions when checking for impossible to eagerly monomorphize items)
 - #109470 (Correctly substitute GAT's type used in `normalize_param_env` in `check_type_bounds`)
 - #109562 (Update ar_archive_writer to 0.1.3)
 - #109629 (remove obsolete `givens` from regionck)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-28 15:18:16 +00:00