about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection
AgeCommit message (Collapse)AuthorLines
2024-02-23delay cloning of iterator itemsMatthias Krüger-16/+19
2024-02-23Rollup merge of #121434 - nnethercote:fix-121208-fallout, r=lcnrMatthias Krüger-3/+1
Fix #121208 fallout #121208 converted lots of delayed bugs to bugs. Unsurprisingly, there were a few invalid conversion found via fuzzing. r? `@lcnr`
2024-02-23Revert some `span_bug`s to `span_delayed_bug`.Nicholas Nethercote-3/+1
Fixes #121410. Fixes #121414. Fixes #121418. Fixes #121431.
2024-02-22Auto merge of #119989 - lcnr:sub_relations-bye-bye, r=compiler-errorsbors-72/+97
remove `sub_relations` from the `InferCtxt` While doing so, I tried to remove the `delay_span_bug` in `rematch_impl` again, which lead me to discover another `freshen` bug, fixing that one in the second commit. See commit descriptions for the reasoning behind each change. r? `@compiler-errors`
2024-02-22change error messages to be incorrect, but more helpfullcnr-1/+1
2024-02-22Rollup merge of #121386 - oli-obk:no_higher_ranked_opaques, r=lcnrMatthias Krüger-2/+4
test that we do not support higher-ranked regions in opaque type inference We already do all the right checks in `check_opaque_type_parameter_valid`, and we have done so since at least 2 years. I collected the tests from https://github.com/rust-lang/rust/pull/116935 and https://github.com/rust-lang/rust/pull/100503 and added some more cc https://github.com/rust-lang/rust/issues/96146 r? `@lcnr`
2024-02-22Rollup merge of #120598 - compiler-errors:no-rigid-check, r=lcnrMatthias Krüger-115/+1
No need to `validate_alias_bound_self_from_param_env` in `assemble_alias_bound_candidates` We already fully normalize the self type before we reach `assemble_alias_bound_candidates`, so there's no reason to double check that a projection is truly rigid by checking param-env bounds. I think this is also blocked on us making sure to always normalize opaques: #120549. r? lcnr
2024-02-22do not use <: in subtyping overflow msglcnr-7/+20
2024-02-22overflow errors: change source to a concrete enumlcnr-49/+78
2024-02-22freshen: resolve root varslcnr-23/+2
Without doing so we use the same candidate cache entry for `?0: Trait<?1>` and `?0: Trait<?0>`. These goals are different and we must not use the same entry for them.
2024-02-22remove `sub_relations` from infcx, recompute in diagnosticslcnr-0/+4
we don't track them when canonicalizing or when freshening, resulting in instable caching in the old solver, and issues when instantiating query responses in the new one.
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-30/+115
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-30/+115
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