about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2024-02-22Preserve the `Span` from `prove_predicate` all the way to registering opaque ↵Oli Scherer-2/+4
types
2024-02-22Replace unnecessary `abort_if_errors`.Nicholas Nethercote-9/+2
Replace `abort_if_errors` calls that are certain to abort -- because we emit an error immediately beforehand -- with `FatalErro.raise()`.
2024-02-21Rollup merge of #121359 - lcnr:typesystem-cleanup, r=compiler-errorsLeón Orell Valerian Liehr-63/+62
miscellaneous type system improvements see review comments for rationale r? `@compiler-errors`
2024-02-21Rollup merge of #121328 - ffmancera:ff/verbose_long_type, r=compiler-errorsDylan DPC-0/+12
Make --verbose imply -Z write-long-types-to-disk=no When shortening the type it is necessary to take into account the `--verbose` flag, if it is activated, we must always show the entire type and not write it in a file. Fixes: https://github.com/rust-lang/rust/issues/119130
2024-02-21Rollup merge of #121208 - nnethercote:delayed_bug-to-bug, r=lcnrDylan DPC-20/+16
Convert `delayed_bug`s to `bug`s. I have a suspicion that quite a few delayed bug paths are impossible to reach, so I did an experiment. I converted every `delayed_bug` to a `bug`, ran the full test suite, then converted back every `bug` that was hit. A surprising number were never hit. This is too dangerous to merge. Increased coverage (fuzzing or a crater run) would likely hit more cases. But it might be useful for people to look at and think about which paths are genuinely unreachable. r? `@ghost`
2024-02-21Convert `bug`s back to `delayed_bug`s.Nicholas Nethercote-10/+10
This commit undoes some of the previous commit's mechanical changes, based on human judgment.
2024-02-21Convert `delayed_bug`s to `bug`s.Nicholas Nethercote-15/+11
I have a suspicion that quite a few delayed bug paths are impossible to reach, so I did an experiment. I converted every `delayed_bug` to a `bug`, ran the full test suite, then converted back every `bug` that was hit. A surprising number were never hit. The next commit will convert some more back, based on human judgment.
2024-02-20Suggest using --verbose when writing type to a fileFernando Fernandez Mancera-0/+12
2024-02-20some type system cleanuplcnr-63/+62
2024-02-20Rollup merge of #121344 - fmease:lta-constr-by-input, r=oli-obkMatthias Krüger-21/+17
Expand weak alias types before collecting constrained/referenced late bound regions + refactorings Fixes #114220. Follow-up to #120780. r? `@oli-obk`
2024-02-20Rollup merge of #121322 - compiler-errors:next-solver-fulfillment-ice, r=lcnrMatthias Krüger-1/+4
Don't ICE when hitting overflow limit in fulfillment loop in next solver As the title says, let's not ICE when hitting the overflow limit in fulfill. On the other hand, we don't want to treat these as true errors, since it means that whether something is considered a true error or an ambiguity is dependent on overflow handling in the solver, which seems not worth it. Now that we use the presence of true errors in fulfillment for implicit negative coherence, we especially don't want to tie together coherence and overflow. I guess I could also drain these errors out of fulfillment and put them into some `ambiguities` storage so we could return them in `select_all_or_error` without having to re-process them every time we call `select_where_possible`. Let me know if that's desired. r? lcnr
2024-02-20Introduce expand_weak_alias_tysLeón Orell Valerian Liehr-11/+9
2024-02-20Rename some normalization-related itemsLeón Orell Valerian Liehr-10/+8
2024-02-20Add newtype for first input typeclubby789-4/+19
2024-02-20Auto merge of #120576 - nnethercote:merge-Diagnostic-DiagnosticBuilder, ↵bors-84/+105
r=davidtwco Overhaul `Diagnostic` and `DiagnosticBuilder` Implements the first part of https://github.com/rust-lang/compiler-team/issues/722, which moves functionality and use away from `Diagnostic`, onto `DiagnosticBuilder`. Likely follow-ups: - Move things around, because this PR was written to minimize diff size, so some things end up in sub-optimal places. E.g. `DiagnosticBuilder` has impls in both `diagnostic.rs` and `diagnostic_builder.rs`. - Rename `Diagnostic` as `DiagInner` and `DiagnosticBuilder` as `Diag`. r? `@davidtwco`
2024-02-20Rollup merge of #121307 - estebank:drive-by, r=compiler-errorsNilstrieb-3/+2
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-20Reduce capabilities of `Diagnostic`.Nicholas Nethercote-3/+7
Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-20Simply do not ICEMichael Goulet-1/+4
2024-02-19Drive-by `DUMMY_SP` -> `Span` and fmt changesEsteban Küber-3/+2
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-19Prefer `DiagnosticBuilder` over `Diagnostic` in diagnostic modifiers.Nicholas Nethercote-81/+98
There are lots of functions that modify a diagnostic. This can be via a `&mut Diagnostic` or a `&mut DiagnosticBuilder`, because the latter type wraps the former and impls `DerefMut`. This commit converts all the `&mut Diagnostic` occurrences to `&mut DiagnosticBuilder`. This is a step towards greatly simplifying `Diagnostic`. Some of the relevant function are made generic, because they deal with both errors and warnings. No function bodies are changed, because all the modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`.
2024-02-19remove outdated commentlcnr-1/+1
2024-02-19split `project` into multiple fileslcnr-773/+787
2024-02-19remove `pred_known_to_hold_modulo_regions`lcnr-47/+3
2024-02-19never normalize without eager inference replacementlcnr-82/+11
2024-02-18Rollup merge of #121100 - estebank:issue-71252, r=compiler-errorsLeón Orell Valerian Liehr-1/+19
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-17Rollup merge of #121193 - compiler-errors:coherence-fulfillment, r=lcnrMatthias Krüger-37/+41
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-17Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercoteMatthias Krüger-2/+5
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-17Rollup merge of #121059 - compiler-errors:extension, r=davidtwco,NilstriebGuillaume Boisseau-826/+94
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-16Use fulfillment in next trait solver coherenceMichael Goulet-37/+41
2024-02-16Rollup merge of #121111 - trevyn:associated-type-suggestion, r=davidtwcoGuillaume Gomez-0/+9
For E0038, suggest associated type if available Closes #116434
2024-02-16NitsMichael Goulet-0/+6
2024-02-16Move trait into attr so it's greppableMichael Goulet-40/+40
2024-02-16Use extension trait deriveMichael Goulet-824/+86
2024-02-16Detect when method call on argument could be removed to fulfill failed trait ↵Esteban Küber-1/+19
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-16Rollup merge of #121119 - compiler-errors:async-fn-kind-errs, r=oli-obkGuillaume Gomez-25/+108
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-15make better async fn kind errorsMichael Goulet-25/+108
2024-02-15Consider principal trait ref's auto-trait super-traits in dyn upcastingMichael Goulet-52/+79
2024-02-15errors: only eagerly translate subdiagnosticsDavid Wood-2/+5
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-15Rollup merge of #121105 - compiler-errors:no-const-ty-overflow, r=oli-obkMatthias Krüger-12/+15
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-14For E0038, suggest associated type if availabletrevyn-0/+9
2024-02-14Auto merge of #120847 - oli-obk:track_errors9, r=compiler-errorsbors-2/+3
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-14Do not report overflow errors on ConstArgHasType goalsMichael Goulet-12/+15
2024-02-14Continue compilation after check_mod_type_wf errorsOli Scherer-2/+3
2024-02-14Rollup merge of #121071 - nnethercote:fewer-delayed-bugs, r=oli-obkOli Scherer-15/+18
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-14Rollup merge of #120915 - OdenShirataki:master, r=fmeaseOli Scherer-3/+3
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-14Use fewer delayed bugs.Nicholas Nethercote-15/+18
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-14Auto merge of #120454 - clubby789:cargo-update, r=Nilstriebbors-5/+10
`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-14Auto merge of #121055 - matthiaskrgr:rollup-bzn5sda, r=matthiaskrgrbors-6/+28
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-14Auto merge of #120942 - compiler-errors:deep-assoc-hang, r=lcnrbors-0/+16
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-13Rollup merge of #121047 - compiler-errors:default-impls, r=lcnrMatthias Krüger-0/+22
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