about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
AgeCommit message (Collapse)AuthorLines
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-770/+785
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-34/+36
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-728/+58
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-34/+36
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-26/+26
2024-02-16Use extension trait deriveMichael Goulet-727/+51
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/+98
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/+98
2024-02-15Consider principal trait ref's auto-trait super-traits in dyn upcastingMichael Goulet-44/+64
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/+14
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/+8
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-13Rollup merge of #121002 - lcnr:cleanup-commit_if_ok, r=oli-obkMatthias Krüger-6/+6
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-13Bump `indexmap`clubby789-5/+10
`swap` has been deprecated in favour of `swap_remove` - the behaviour is the same though.
2024-02-13Do not assemble candidates for default implsMichael Goulet-0/+8
2024-02-13remove questionable calls to `commit_if_ok`lcnr-6/+6
2024-02-13Auto merge of #120919 - oli-obk:impl_polarity, r=compiler-errorsbors-26/+33
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-12Rollup merge of #120958 - ShoyuVanilla:remove-subst, r=oli-obkMatthias Krüger-62/+62
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-12Auto merge of #120980 - matthiaskrgr:rollup-dsjsqql, r=matthiaskrgrbors-6/+0
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-12Rollup merge of #120917 - chenyukang:yukang-dead-parameters, r=compiler-errorsMatthias Krüger-6/+0
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-12Stop calling `impl_polarity` when `impl_trait_ref` was also calledOli Scherer-26/+33
2024-02-12Dejargnonize substShoyu Vanilla-62/+62
2024-02-12Check representation of unnamed fieldsFrank King-5/+3
2024-02-12Lowering field access for anonymous adtsFrank King-2/+2
2024-02-12Lower anonymous structs or unions to HIRFrank King-0/+10
2024-02-12Fix suggestion span for ?SizedOdenShirataki-3/+3
when param type has default and type in trait is generic.
2024-02-12remove a bunch of dead parameters in fnyukang-6/+0
2024-02-11Rollup merge of #120872 - petrochenkov:opthirpar, r=cjgillotMatthias Krüger-15/+11
hir: Refactor getters for HIR parents See individual commits. I ended up removing on of the FIXMEs from https://github.com/rust-lang/rust/pull/120206 instead of addressing it.
2024-02-11Ignore own item bounds in parent alias types in `for_each_item_bound`Michael Goulet-0/+16
2024-02-10Auto merge of #120771 - oli-obk:useless_non_ensure_query_call, r=davidtwcobors-1/+1
Use `ensure` when the result of the query is not needed beyond its `Result`ness while I would like to just remove the `tcx` methods for ensure-only queries, that is hard to do without another query annotation or by turning the `define_callbacks` macro into a proc macro to get more control should fix perf regression of https://github.com/rust-lang/rust/pull/120558