Commit Graph

3633 Commits

Author SHA1 Message Date
León Orell Valerian Liehr
05ce209d20
Rename some normalization-related items 2024-02-20 17:30:49 +01:00
Nilstrieb
ac030bcf05
Rollup merge of #121307 - estebank:drive-by, r=compiler-errors
Drive-by `DUMMY_SP` -> `Span` and fmt changes

Noticed these while doing something else. There's no practical change, but it's preferable to use `DUMMY_SP` as little as possible, particularly when we have perfectlly useful `Span`s available.
2024-02-20 07:35:47 +01:00
Esteban Küber
b4a424feb8 Drive-by DUMMY_SP -> Span and fmt changes
Noticed these while doing something else. There's no practical change, but it's preferable to use `DUMMY_SP` as little as possible, particularly when we have perfectlly useful `Span`s available.
2024-02-19 17:04:23 +00:00
lcnr
0c7672a532 remove outdated comment 2024-02-19 09:17:01 +01:00
lcnr
9771fb08b6 split project into multiple files 2024-02-19 09:17:00 +01:00
lcnr
399a258f46 remove pred_known_to_hold_modulo_regions 2024-02-19 09:06:34 +01:00
lcnr
486c7b6a50 never normalize without eager inference replacement 2024-02-19 09:06:34 +01:00
León Orell Valerian Liehr
6499eb5577
Rollup merge of #121100 - estebank:issue-71252, r=compiler-errors
Detect when method call on argument could be removed to fulfill failed trait bound

When encountering

```rust
struct Foo;
struct Bar;
impl From<Bar> for Foo {
    fn from(_: Bar) -> Self { Foo }
}
fn qux(_: impl From<Bar>) {}
fn main() {
    qux(Bar.into());
}
```

Suggest removing `.into()`:

```
error[E0283]: type annotations needed
 --> f100.rs:8:13
  |
8 |     qux(Bar.into());
  |     ---     ^^^^
  |     |
  |     required by a bound introduced by this call
  |
  = note: cannot satisfy `_: From<Bar>`
note: required by a bound in `qux`
 --> f100.rs:6:16
  |
6 | fn qux(_: impl From<Bar>) {}
  |                ^^^^^^^^^ required by this bound in `qux`
help: try using a fully qualified path to specify the expected types
  |
8 |     qux(<Bar as Into<T>>::into(Bar));
  |         +++++++++++++++++++++++   ~
help: consider removing this method call, as the receiver has type `Bar` and `Bar: From<Bar>` trivially holds
  |
8 -     qux(Bar.into());
8 +     qux(Bar);
  |
```

Fix #71252
2024-02-18 05:10:16 +01:00
Matthias Krüger
df3712ce21
Rollup merge of #121193 - compiler-errors:coherence-fulfillment, r=lcnr
Use fulfillment in next trait solver coherence

Use fulfillment in the new trait solver's `impl_intersection_has_impossible_obligation` routine. This means that inference that falls out of processing other obligations can influence whether we can determine if an obligation is impossible to satisfy. See the committed test.

This should be completely sound, since evaluation and fulfillment both respect intercrate mode equally.

We run the risk of breaking coherence later if we were to change the rules of fulfillment and/or inference during coherence, but this is a problem which affects evaluation, as nested obligations from a trait goal are processed together and can influence each other in the same way.

r? lcnr
cc #114862

Also changed obligationctxt -> fulfillmentctxt because it feels kind of redundant to use an ocx here. I don't really care enough and can change it back if it really matters much.
2024-02-17 18:47:42 +01:00
Matthias Krüger
45d5773704
Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercote
errors: only eagerly translate subdiagnostics

Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context.

This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change).

r? ```@nnethercote```
2024-02-17 18:47:40 +01:00
Guillaume Boisseau
5ff9022306
Rollup merge of #121059 - compiler-errors:extension, r=davidtwco,Nilstrieb
Add and use a simple extension trait derive macro in the compiler

Adds `#[extension]` to `rustc_macros` for implementing an extension trait. This expands an impl (with an optional visibility) into two parallel trait + impl definitions.

before:
```rust
pub trait Extension {
  fn a();
}
impl Extension for () {
  fn a() {}
}
```

to:
```rust
#[extension]
pub impl Extension for () {
  fn a() {}
}
```

Opted to just implement it by hand because I couldn't figure if there was a "canonical" choice of extension trait macro in the ecosystem. It's really lightweight anyways, and can always be changed.

I'm interested in adding this because I'd like to later split up the large `TypeErrCtxtExt` traits into several different files. This should make it one step easier.
2024-02-17 11:23:04 +01:00
Michael Goulet
228441dbd6 Use fulfillment in next trait solver coherence 2024-02-16 23:53:09 +00:00
Guillaume Gomez
670bdbf808
Rollup merge of #121111 - trevyn:associated-type-suggestion, r=davidtwco
For E0038, suggest associated type if available

Closes #116434
2024-02-16 17:08:12 +01:00
Michael Goulet
f624d55ea7 Nits 2024-02-16 15:07:37 +00:00
Michael Goulet
a9dbf63087 Move trait into attr so it's greppable 2024-02-16 15:07:37 +00:00
Michael Goulet
9c25823bb4 Use extension trait derive 2024-02-16 15:07:37 +00:00
Esteban Küber
9b3fcf9ad4 Detect when method call on argument could be removed to fulfill failed trait bound
When encountering

```rust
struct Foo;
struct Bar;
impl From<Bar> for Foo {
    fn from(_: Bar) -> Self { Foo }
}
fn qux(_: impl From<Bar>) {}
fn main() {
    qux(Bar.into());
}
```

Suggest removing `.into()`:

```
error[E0283]: type annotations needed
 --> f100.rs:8:13
  |
8 |     qux(Bar.into());
  |     ---     ^^^^
  |     |
  |     required by a bound introduced by this call
  |
  = note: cannot satisfy `_: From<Bar>`
note: required by a bound in `qux`
 --> f100.rs:6:16
  |
6 | fn qux(_: impl From<Bar>) {}
  |                ^^^^^^^^^ required by this bound in `qux`
help: try using a fully qualified path to specify the expected types
  |
8 |     qux(<Bar as Into<T>>::into(Bar));
  |         +++++++++++++++++++++++   ~
help: consider removing this method call, as the receiver has type `Bar` and `Bar: From<Bar>` can be fulfilled
  |
8 -     qux(Bar.into());
8 +     qux(Bar);
  |
```

Fix #71252
2024-02-16 04:28:05 +00:00
Guillaume Gomez
ddad818b7a
Rollup merge of #121119 - compiler-errors:async-fn-kind-errs, r=oli-obk
Make `async Fn` trait kind errors better

1. Make it so that async closures with the wrong closurekind actually report a useful error
2. Explain why async closures can sometimes not implement `Fn`/`FnMut` (because they capture things)

r? oli-obk
2024-02-16 00:27:33 +01:00
Michael Goulet
acb201af54 make better async fn kind errors 2024-02-15 15:59:35 +00:00
Michael Goulet
ec8e898193 Consider principal trait ref's auto-trait super-traits in dyn upcasting 2024-02-15 15:38:11 +00:00
David Wood
b80fc5d4e8
errors: only eagerly translate subdiagnostics
Subdiagnostics don't need to be lazily translated, they can always be
eagerly translated. Eager translation is slightly more complex as we need
to have a `DiagCtxt` available to perform the translation, which involves
slightly more threading of that context.

This slight increase in complexity should enable later simplifications -
like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages
into the diagnostic structs rather than having them in separate files
(working on that was what led to this change).

Signed-off-by: David Wood <david@davidtw.co>
2024-02-15 10:34:41 +00:00
Matthias Krüger
888fe709e6
Rollup merge of #121105 - compiler-errors:no-const-ty-overflow, r=oli-obk
Do not report overflow errors on ConstArgHasType goals

This is 10% of a fix for #121090, since it at least means that we no longer mention the `ConstArgHasType` goal as the cause for the overflow. Instead, now we mention:
```
overflow evaluating the requirement `{closure@$DIR/overflow-during-mono.rs:13:41: 13:44}: Sized`
```
which is not much better, but slightly.

r? oli-obk
2024-02-15 09:20:21 +01:00
trevyn
220e8a7484 For E0038, suggest associated type if available 2024-02-14 12:42:32 -08:00
bors
ee9c7c940c Auto merge of #120847 - oli-obk:track_errors9, r=compiler-errors
Continue compilation after check_mod_type_wf errors

The ICEs fixed here were probably reachable through const eval gymnastics before, but now they are easily reachable without that, too.

The new errors are often bugfixes, where useful errors were missing, because they were reported after the early abort. In other cases sometimes they are just duplication of already emitted errors, which won't be user-visible due to deduplication.

fixes https://github.com/rust-lang/rust/issues/120860
2024-02-14 18:32:19 +00:00
Michael Goulet
01c974ff98 Do not report overflow errors on ConstArgHasType goals 2024-02-14 18:02:55 +00:00
Oli Scherer
5f6390f947 Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
Oli Scherer
638f5259fe
Rollup merge of #121071 - nnethercote:fewer-delayed-bugs, r=oli-obk
Use fewer delayed bugs.

For some cases where it's clear that an error has already occurred, e.g.:
- there's a comment stating exactly that, or
- things like HIR lowering, where we are lowering an error kind

The commit also tweaks some comments around delayed bug sites.

r? `@oli-obk`
2024-02-14 11:53:42 +01:00
Oli Scherer
f3e66edd63
Rollup merge of #120915 - OdenShirataki:master, r=fmease
Fix suggestion span for `?Sized` when param type has default

Fixes #120878

Diagnostic suggests adding `: ?Sized` in an incorrect place if a type parameter default is present

r? `@fmease`
2024-02-14 11:53:39 +01:00
Nicholas Nethercote
05849e8c2f Use fewer delayed bugs.
For some cases where it's clear that an error has already occurred,
e.g.:
- there's a comment stating exactly that, or
- things like HIR lowering, where we are lowering an error kind

The commit also tweaks some comments around delayed bug sites.
2024-02-14 20:30:37 +11:00
bors
cc1c0990ab Auto merge of #120454 - clubby789:cargo-update, r=Nilstrieb
`cargo update`

Run `cargo update`, with some pinning and fixes necessitated by that. This *should* unblock #112865

There's a couple of places where I only pinned a dependency in one location - this seems like a bit of a hack, but better than duplicating the FIXME across all `Cargo.toml` where a dependency is introduced.

cc `@Nilstrieb`
2024-02-14 05:27:31 +00:00
bors
7508c3e4c1 Auto merge of #121055 - matthiaskrgr:rollup-bzn5sda, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #118882 (Check normalized call signature for WF in mir typeck)
 - #120999 (rustdoc: replace `clean::InstantiationParam` with `clean::GenericArg`)
 - #121002 (remove unnecessary calls to `commit_if_ok`)
 - #121005 (Remove jsha from the rustdoc review rotation)
 - #121014 (Remove `force_print_diagnostic`)
 - #121043 (add lcnr to the compiler-team assignment group)
 - #121046 (Fix incorrect use of `compile_fail`)
 - #121047 (Do not assemble candidates for default impls)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-14 03:21:31 +00:00
bors
37b65339c8 Auto merge of #120942 - compiler-errors:deep-assoc-hang, r=lcnr
Ignore own item bounds in parent alias types in `for_each_item_bound`

Fixes #120912

I want to get a vibe check on this approach, which is very obviously a hack, but I believe something that is forwards-compatible with a more thorough solution and "good enough for now".

The problem here is that for a really deep rigid associated type, we are now repeatedly considering unrelated item bounds from the parent alias types, meaning we're doing a *lot* of extra work in the MIR inliner for deeply substituted rigid projections.

This feels intimately related to #107614. In that PR, we split *supertrait* bounds (bound which share the same `Self` type as the predicate which is being elaborated) and *implied* bounds (anything that is implied by elaborating the predicate).

The problem here is related to the fact that we don't maintain the split between these two for `item_bounds`. If we did, then when recursing into a parent alias type, we'd want to consider only the bounds that are given by [`PredicateFilter::All`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/astconv/enum.PredicateFilter.html#variant.SelfOnly) **except** those given by [`PredicateFilter::SelfOnly`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/astconv/enum.PredicateFilter.html#variant.SelfOnly).
2024-02-14 01:23:46 +00:00
Matthias Krüger
ab1fa19d08
Rollup merge of #121047 - compiler-errors:default-impls, r=lcnr
Do not assemble candidates for default impls

There is no reason (as far as I can tell?) that we should assemble an impl candidate for a default impl. This candidate itself does not prove that the impl holds, and any time that it *does* hold, there will be a more specializing non-default impl that also is assembled.

This is because `default impl<T> Foo for T {}` actually expands to `impl<T> Foo for T where T: Foo {}`. The only way to satisfy that where clause (without coinduction) is via *another* implementation that does hold -- precisely an impl that specializes it.

This should fix the specialization related regressions for #116494. That should lead to one root crate regression that doesn't have to do with specialization, which I think we can regress.

r? lcnr cc ``@rust-lang/types``

cc #31844
2024-02-13 22:51:57 +01:00
Matthias Krüger
147fd3f236
Rollup merge of #121002 - lcnr:cleanup-commit_if_ok, r=oli-obk
remove unnecessary calls to `commit_if_ok`

we propagate the error outwards, so anything which wants to discard the error should do so itself.

r? types
2024-02-13 22:51:55 +01:00
clubby789
4de3a3af4a Bump indexmap
`swap` has been deprecated in favour of `swap_remove` - the behaviour
is the same though.
2024-02-13 21:03:34 +00:00
Michael Goulet
b4eee2e8b3 Do not assemble candidates for default impls 2024-02-13 19:20:13 +00:00
Matthias Krüger
65ab663266
Rollup merge of #120549 - lcnr:errs-showcase, r=compiler-errors
modify alias-relate to also normalize ambiguous opaques

allows a bunch of further cleanups and generally simplifies the type system. To handle https://github.com/rust-lang/trait-system-refactor-initiative/issues/8 we'll have to add a some additional complexity to the `(Alias, Infer)` branches in alias-relate, so removing the opaque type special case here is really valuable.

It does worsen `deduce_closure_signature` and friends even more as they now receive an inference variable which is only constrained via an `AliasRelate` goal. These probably have to look into alias relate goals somehow. Leaving that for a future PR as this is something we'll have to tackle regardless.

r? `@compiler-errors`
2024-02-13 17:38:10 +01:00
lcnr
ae92334c0f remove questionable calls to commit_if_ok 2024-02-13 05:44:46 +01:00
lcnr
3e3e207ad7 use alias-relate to structurally normalize in the solver 2024-02-13 05:08:51 +01:00
lcnr
bbe2f6c0b2 also try to normalize opaque types in alias-relate
with this, alias-relate treats all aliases the same way
and it can be used for structural normalization.
2024-02-13 04:47:32 +01:00
bors
d26b417112 Auto merge of #120919 - oli-obk:impl_polarity, r=compiler-errors
Merge `impl_polarity` and `impl_trait_ref` queries

Hopefully this is perf neutral. I want to finish https://github.com/rust-lang/rust/pull/120835 and stop using the HIR in `coherent_trait`, which should then give us a perf improvement.
2024-02-13 02:48:49 +00:00
Matthias Krüger
cb0d74be28
Rollup merge of #120958 - ShoyuVanilla:remove-subst, r=oli-obk
Dejargonize `subst`

In favor of #110793, replace almost every occurence of `subst` and `substitution` from rustc codes, but they still remains in subtrees under `src/tools/` like clippy and test codes (I'd like to replace them after this)
2024-02-12 23:18:54 +01:00
bors
b381d3ab27 Auto merge of #120980 - matthiaskrgr:rollup-dsjsqql, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #120765 (Reorder diagnostics API)
 - #120833 (More internal emit diagnostics cleanups)
 - #120899 (Gracefully handle non-WF alias in `assemble_alias_bound_candidates_recur`)
 - #120917 (Remove a bunch of dead parameters in functions)
 - #120928 (Add test for recently fixed issue)
 - #120933 (check_consts: fix duplicate errors, make importance consistent)
 - #120936 (improve `btree_cursors` functions documentation)
 - #120944 (Check that the ABI of the instance we are inlining is correct)
 - #120956 (Clean inlined type alias with correct param-env)
 - #120962 (Add myself to library/std review)
 - #120972 (fix ICE for deref coercions with type errors)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-12 17:06:22 +00:00
Matthias Krüger
ebe36ac815
Rollup merge of #120917 - chenyukang:yukang-dead-parameters, r=compiler-errors
Remove a bunch of dead parameters in functions

Found this kind of issue when working on https://github.com/rust-lang/rust/pull/119650
I wrote a trivial toy lint and manual review to find these.
2024-02-12 18:04:08 +01:00
Matthias Krüger
733f93d60c
Rollup merge of #120899 - compiler-errors:non-wf-alias, r=lcnr
Gracefully handle non-WF alias in `assemble_alias_bound_candidates_recur`

See explanation in test. I think it's fine to delay a bug here -- I don't believe we ever construct a non-wf alias on the good path? If so, then we can just remove the delay.

Fixes #120891

r? lcnr
2024-02-12 18:04:08 +01:00
Oli Scherer
b43fbe63e7 Stop calling impl_polarity when impl_trait_ref was also called 2024-02-12 09:44:09 +00:00
Shoyu Vanilla
3856df059e Dejargnonize subst 2024-02-12 15:46:35 +09:00
Frank King
0dbd6e9572 Improve some codes according to the reviews
- improve diagnostics of field uniqueness check and representation check
- simplify the implementation of field uniqueness check
- remove some useless codes and improvement neatness
2024-02-12 12:47:32 +08:00
Frank King
7660d6bf2c Check representation of unnamed fields 2024-02-12 12:47:31 +08:00
Frank King
0c0df4efe0 Lowering field access for anonymous adts 2024-02-12 12:47:30 +08:00