Commit graph

200 commits

Author SHA1 Message Date
Dylan DPC ccf99bd769
Rollup merge of #111980 - compiler-errors:unmapped-substs, r=lcnr
Preserve substs in opaques recorded in typeck results

This means that we now prepopulate MIR with opaques with the right substs.

The first commit is a hack that I think we discussed, having to do with `DefiningAnchor::Bubble` basically being equivalent to `DefiningAnchor::Error` in the new solver, so having to use `DefiningAnchor::Bind` instead, lol.

r? `@lcnr`
2023-06-01 11:09:43 +05:30
Boxy 21cf9ea7ed update test to not rely on super_relate_consts hack 2023-05-31 02:14:15 +01:00
lcnr dccc8db17d coinductive cycle leak check test 2023-05-30 13:04:27 +02:00
Michael Goulet 3d09b990d7 Wait until type_of to remap HIR opaques back to their defn params 2023-05-26 14:42:52 +00:00
Michael Goulet 97c11ffb22 Strongly prefer alias and param-env bounds 2023-05-25 03:35:14 +00:00
bors 4400d8fce7 Auto merge of #110204 - compiler-errors:new-solver-hir-typeck-hacks, r=lcnr
Deal with unnormalized projections when structurally resolving types with new solver

1. Normalize types in `structurally_resolved_type` when the new solver is enabled
2. Normalize built-in autoderef targets in `Autoderef` when the new solver is enabled
3. Normalize-erasing-regions in `resolve_type` in writeback

This is motivated by the UI test provided, which currently fails with:

```
error[E0609]: no field `x` on type `<usize as SliceIndex<[Foo]>>::Output`
 --> <source>:9:11
  |
9 |     xs[0].x = 1;
  |           ^
```

 I'm pretty happy with the approach in (1.) and (2.) and think we'll inevitably need something like this in the long-term, but (3.) seems like a hack to me. It's a *lot* of work to add tons of new calls to every user of these typeck results though (mir build, late lints, etc). Happy to discuss further.

r? `@lcnr`
2023-05-23 04:41:44 +00:00
Michael Goulet 4cfafb275e Structurally normalize in the new solver 2023-05-22 21:18:20 +00:00
bors 8b4b20836b Auto merge of #111848 - Dylan-DPC:rollup-7jqydzg, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #111501 (MIR drive-by cleanups)
 - #111609 (Mark internal functions and traits unsafe to reflect preconditions)
 - #111612 (Give better error when collecting into `&[T]`)
 - #111756 (Rename `{drop,forget}_{copy,ref}` lints to more consistent naming)
 - #111843 (move lcnr to only review types stuff)
 - #111844 (Migrate GUI colors test to original CSS color format)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-22 20:33:51 +00:00
Urgau c93d9c1794 Rename drop_ref lint to dropping_references 2023-05-21 14:16:41 +02:00
Urgau 1c7ab18c08 Rename drop_copy lint to dropping_copy_types 2023-05-21 13:37:32 +02:00
lcnr c5ec1b8bc5 add test 2023-05-19 10:44:38 +02:00
bors 19ca5692f6 Auto merge of #110100 - compiler-errors:no-infer-pred-must-hold, r=jackh726
do not allow inference in `predicate_must_hold` (alternative approach)

See the FCP description for more info, but tl;dr is that we should not return `EvaluatedToOkModuloRegions` if an obligation may hold only with some choice of inference vars being constrained.

Attempts to solve this in the approach laid out by lcnr here: https://github.com/rust-lang/rust/pull/109558#discussion_r1147318134, rather than by eagerly replacing infer vars with placeholders which is a bit too restrictive.

r? `@ghost`
2023-05-19 03:36:37 +00:00
Dylan DPC 291ced5e9a
Rollup merge of #111588 - MU001999:diag/improve-e0782, r=fee1-dead
Emits E0599 when meeting `MyTrait::missing_method`

Fixes #111312
2023-05-17 19:11:55 +05:30
mu001999 db64512422 Emits E0599 when meeting MyTrait::missing_method 2023-05-17 16:59:39 +08:00
Michael Goulet 6d0b6c0d2c Tweaks and a test 2023-05-15 16:40:42 +00:00
Dylan DPC 05ca3e31df
Rollup merge of #111451 - compiler-errors:note-cast-origin, r=b-naber
Note user-facing types of coercion failure

When coercing, for example, `Box<A>` into `Box<dyn B>`, make sure that any failure notes mention *those* specific types, rather than mentioning inner types, like "the cast from `A` to `dyn B`".

I expect end-users are often confused when we skip layers of types and only mention the "innermost" part of a coercion, especially when other notes point at HIR, e.g. #111406.
2023-05-13 11:05:33 +05:30
Michael Goulet c06e61151c do not allow inference in pred_known_to_hold_modulo_regions 2023-05-12 18:47:45 +00:00
bors 077fc26f0a Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwco
Uplift `clippy::{drop,forget}_{ref,copy}` lints

This PR aims at uplifting the `clippy::drop_ref`, `clippy::drop_copy`, `clippy::forget_ref` and `clippy::forget_copy` lints.

Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted.

## `drop_ref` and `forget_ref`

The `drop_ref` and `forget_ref` lint checks for calls to `std::mem::drop` or `std::mem::forget` with a reference instead of an owned value.

### Example

```rust
let mut lock_guard = mutex.lock();
std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex
// still locked
operation_that_requires_mutex_to_be_unlocked();
```

### Explanation

Calling `drop` or `forget` on a reference will only drop the reference itself, which is a no-op. It will not call the `drop` or `forget` method on the underlying referenced value, which is likely what was intended.

## `drop_copy` and `forget_copy`

The `drop_copy` and `forget_copy` lint checks for calls to `std::mem::forget` or `std::mem::drop` with a value that derives the Copy trait.

### Example

```rust
let x: i32 = 42; // i32 implements Copy
std::mem::forget(x) // A copy of x is passed to the function, leaving the
                    // original unaffected
```

### Explanation

Calling `std::mem::forget` [does nothing for types that implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the value will be copied and moved into the function on invocation.

-----

Followed the instructions for uplift a clippy describe here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

cc `@m-ou-se` (as T-libs-api leader because the uplifting was discussed in a recent meeting)
2023-05-12 12:04:32 +00:00
Michael Goulet 14bf909e71 Note base types of coercion 2023-05-12 00:10:52 +00:00
Urgau 61ff2718f7 Adjust tests for new drop and forget lints 2023-05-10 19:36:02 +02:00
Michael Goulet 0dbaae4165 Make alias bounds sound in the new solver 2023-05-09 20:37:50 +00:00
Yuki Okushi c145d93395
Rollup merge of #111211 - compiler-errors:negative-bounds-super, r=TaKO8Ki
Don't compute trait super bounds unless they're positive

Fixes #111207

The comment is modified to explain the rationale for why we even have this recursive call to supertraits in the first place, which doesn't apply to negative bounds since they don't elaborate at all.
2023-05-08 19:41:49 +09:00
Michael Goulet 9d44f9b4e2 Add test for #110557 2023-05-04 18:06:07 +00:00
Michael Goulet 930eece9d3 Don't compute trait super bounds unless they're positive 2023-05-04 17:24:13 +00:00
Manish Goregaokar 48c78248a3
Rollup merge of #111146 - petrochenkov:decident, r=compiler-errors
rustc_middle: Fix `opt_item_ident` for non-local def ids

Noticed while working on https://github.com/rust-lang/rust/pull/110855.
2023-05-03 16:42:51 -07:00
Vadim Petrochenkov 6f6c379ee0 rustc_middle: Fix opt_item_ident for non-local def ids 2023-05-03 20:09:10 +03:00
Michael Goulet 03469c3f2e Make negative trait bounds work with the old trait solver 2023-05-02 22:36:25 +00:00
Michael Goulet 86f50b9f5c Disallow associated type constraints on negative bounds 2023-05-02 22:36:24 +00:00
Michael Goulet 6e01e910cb Implement negative bounds 2023-05-02 22:36:24 +00:00
Michael Goulet bec7193072 Don't use implied trait predicates in gather_explicit_predicates_of 2023-05-01 15:45:28 +00:00
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
Michael Goulet f0fc4f9acf Tweak await span 2023-04-27 17:18:11 +00:00
Michael Goulet 5fa82092ae Clear response values for overflow in new solver 2023-04-26 21:54:30 +00:00
bors f33379b0a6 Auto merge of #110811 - compiler-errors:vars-are-question-mark, r=WaffleLapkin
Use `?0` notation for ty/ct/int/float/region vars

Aligns the notation for infer vars that T-types and friends most often uses for inference variables with the notation in the compiler (which is kinda a sigil nightmare IMO: `_#`) by adopting `?0` style infer vars.

This mostly affects debug output since verbose infer vars shouldn't show up in user-facing places.

Does this need an MCP? It's debug output, so I'm thinking no, but happy to open one. 🤔

r? types
2023-04-25 22:11:09 +00:00
Michael Goulet bb99cdc7cd vars are ? 2023-04-25 19:53:09 +00:00
Michael Goulet bb2cb89ead Negative coherence test 2023-04-25 05:02:39 +00:00
bors 4396ceca05 Auto merge of #109753 - compiler-errors:replenish-region-constraints, r=aliemjay
Clone region var origins instead of taking them in borrowck

Fixes an issue with the new solver where reporting a borrow-checker error ICEs because it calls `InferCtxt::evaluate_obligation`.

This also removes a handful of unnecessary `tcx.infer_ctxt().build()` calls that are only there to mitigate this same exact issue, but with the old solver.

Fixes compiler-errors/next-solver-hir-issues#12.

----

This implements `@aliemjay's` solution where we just don't *take* the region constraints, but clone them. This potentially makes it easier to write a bug about taking region constraints twice or never at all, but again, not many folks are touching this code.
2023-04-22 15:15:51 +00:00
Michael Goulet 964600b38e Clone region var origins instead of taking in borrowck 2023-04-21 00:31:43 +00:00
Caio 4adc5f9281 Move test files 2023-04-20 15:06:17 -03: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
Michael Goulet c68c6c3942 Add test for uniquifying regions 2023-04-14 03:22:12 +00:00
Matthias Krüger 958413cc08
Rollup merge of #110195 - compiler-errors:issue-110052, r=aliemjay
Erase lifetimes above `ty::INNERMOST` when probing ambiguous types

Turns out that `TyCtxt::replace_escaping_bound_vars_uncached` only erases bound vars exactly at `ty::INNERMOST`, and not everything above. This regresses the suggestions for non-lifetime binders, but oh well, I don't really care about those.

Fixes #110052
2023-04-13 11:21:00 +02:00
bors d37e2f74af Auto merge of #109786 - estebank:tweak-add-line-sugg, r=compiler-errors
Tweak output for 'add line' suggestion

Closes #108174
2023-04-13 07:02:53 +00:00
Esteban Küber 9fadcc143a Special-case item attributes in the suggestion output 2023-04-12 22:50:10 +00:00
Esteban Küber 5b40aa5eb4 Tweak output for 'add line' suggestion 2023-04-12 22:50:10 +00: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
Michael Goulet 7ec72efe10 Allow the elaborator to only filter to real supertraits 2023-04-11 17:45:42 +00:00
Michael Goulet 4560b61cd1 Broken tests 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 5eb0528483 Erase lifetimes above ty::INNERMOST when probing ambiguous types 2023-04-11 17:17:32 +00:00