about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2024-11-21Stop being so bail-y in candidate assemblyMichael Goulet-32/+0
2024-11-20Rip out built-in PointerLike implMichael Goulet-31/+0
2024-11-19additional `TypingEnv` cleanupslcnr-6/+5
2024-11-19rustdoc: yeet `TypingEnv::from_param_env`lcnr-9/+4
2024-11-19move `fn is_item_raw` to `TypingEnv`lcnr-1/+3
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-23/+37
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-13Rollup merge of #132971 - BoxyUwU:handle_infers_in_anon_consts, ↵Jubilee-9/+21
r=compiler-errors Handle infer vars in anon consts on stable Fixes #132955 Diagnostics will sometimes try to replace generic parameters with inference variables in failing goals. This means that if we have some failing goal with an array repeat expr count anon const in it, we will wind up with some `ty::ConstKind::Unevaluated(anon_const_def, [?x])` during diagnostics which will then ICE if we do not handle inference variables correctly on stable when normalizing type system consts. r? ```@compiler-errors```
2024-11-12Handle infer vars in anon consts on stableBoxy-9/+21
2024-11-12Rollup merge of #132938 - compiler-errors:ed2024-apit-sugg, r=chenyukangMatthias Krüger-1/+9
Make precise capturing suggestion machine-applicable only if it has no APITs cc https://github.com/rust-lang/rust/issues/132932 The only case where this suggestion is not machine-applicable is when we suggest turning arg-position impl trait into type parameters, which may expose type parameters that were not turbofishable before.
2024-11-12Make precise capturing suggestion machine-applicable only if it has not APITsMichael Goulet-1/+9
2024-11-12Consolidate type system const evaluation under `traits::evaluate_const`Boxy-86/+291
mew
2024-11-09Dont suggest use<APIT>Michael Goulet-13/+20
2024-11-09Suggest turning APITs into generics in opaque overcapturesMichael Goulet-3/+121
2024-11-08Rollup merge of #132757 - compiler-errors:yeet-check-wf, r=lcnrJubilee-0/+16
Get rid of `check_opaque_type_well_formed` Instead, replicate it by improving the span of the opaque in `check_opaque_meets_bounds`. This has two consequences: 1. We now prefer "concrete type differs" errors, since we'll hit those first before we check the opaque is WF. 2. Spans have gotten slightly worse. Specifically, (2.) could be improved by adding a new obligation cause that explains that the definition's environment has stronger assumptions than the declaration. r? lcnr
2024-11-08Manually register some bounds for a better spanMichael Goulet-0/+16
2024-11-08Auto merge of #128849 - estebank:issue-89143, r=jackh726bors-45/+90
Tweak detection of multiple crate versions to be more encompassing Previously, we only emitted the additional context if the type was in the same crate as the trait that appeared multiple times in the dependency tree. Now, we look at all traits looking for two with the same name in different crates with the same crate number, and we are more flexible looking for the types involved. This will work even if the type that implements the wrong trait version is from a different crate entirely. ``` error[E0277]: the trait bound `CustomErrorHandler: ErrorHandler` is not satisfied because the trait comes from a different crate version --> src/main.rs:5:17 | 5 | cnb_runtime(CustomErrorHandler {}); | ^^^^^^^^^^^^^^^^^^^^^ the trait `ErrorHandler` is not implemented for `CustomErrorHandler` | note: there are multiple different versions of crate `c` in the dependency graph --> /home/gh-estebank/testcase-rustc-crate-version-mismatch/c-v0.2/src/lib.rs:1:1 | 1 | pub trait ErrorHandler {} | ^^^^^^^^^^^^^^^^^^^^^^ this is the required trait | ::: src/main.rs:1:5 | 1 | use b::CustomErrorHandler; | - one version of crate `c` is used here, as a dependency of crate `b` 2 | use c::cnb_runtime; | - one version of crate `c` is used here, as a direct dependency of the current crate | ::: /home/gh-estebank/testcase-rustc-crate-version-mismatch/b/src/lib.rs:1:1 | 1 | pub struct CustomErrorHandler {} | ----------------------------- this type doesn't implement the required trait | ::: /home/gh-estebank/testcase-rustc-crate-version-mismatch/c-v0.1/src/lib.rs:1:1 | 1 | pub trait ErrorHandler {} | ---------------------- this is the found trait = note: two types coming from two different versions of the same crate are different types even if they look the same = help: you can use `cargo tree` to explore your dependency tree ``` Fix #89143.
2024-11-07Only show "same type from differnt version" note when relevantEsteban Küber-7/+15
2024-11-07Remove less relevant info from diagnosticEsteban Küber-0/+18
``` error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied because the trait comes from a different crate version --> multiple-dep-versions.rs:7:18 | 7 | do_something(Type); | ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type` | note: there are multiple different versions of crate `dependency` in the dependency graph --> /home/gh-estebank/rust/build/x86_64-unknown-linux-gnu/test/run-make/crate-loading/rmake_out/multiple-dep-versions-1.rs:4:1 | 3 | pub struct Type(pub i32); | --------------- this type implements the required trait 4 | pub trait Trait { | ^^^^^^^^^^^^^^^ this is the required trait | ::: multiple-dep-versions.rs:1:1 | 1 | extern crate dep_2_reexport; | ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo` 2 | extern crate dependency; | ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate | ::: /home/gh-estebank/rust/build/x86_64-unknown-linux-gnu/test/run-make/crate-loading/rmake_out/multiple-dep-versions-2.rs:3:1 | 3 | pub struct Type; | --------------- this type doesn't implement the required trait 4 | pub trait Trait { | --------------- this is the found trait = note: two types coming from two different versions of the same crate are different types even if they look the same = help: you can use `cargo tree` to explore your dependency tree ``` The approach to accomplish this is a HACK, and we'd want a better way to do this. I believe that moving E0277 to be a structured diagnostic would help in that regard.
2024-11-07Tweak diagnostic outputEsteban Küber-19/+21
``` error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied because the trait comes from a different crate version --> multiple-dep-versions.rs:7:18 | 7 | do_something(Type); | ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type` | note: there are multiple different versions of crate `dependency` in the dependency graph --> /home/gh-estebank/rust/build/x86_64-unknown-linux-gnu/test/run-make/crate-loading/rmake_out/multiple-dep-versions-1.rs:4:1 | 3 | pub struct Type(pub i32); | --------------- this type implements the required trait 4 | pub trait Trait { | ^^^^^^^^^^^^^^^ this is the required trait | ::: multiple-dep-versions.rs:1:1 | 1 | extern crate dep_2_reexport; | ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo` 2 | extern crate dependency; | ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate | ::: /home/gh-estebank/rust/build/x86_64-unknown-linux-gnu/test/run-make/crate-loading/rmake_out/multiple-dep-versions-2.rs:3:1 | 3 | pub struct Type; | --------------- this type doesn't implement the required trait 4 | pub trait Trait { | --------------- this is the found trait = note: two types coming from two different versions of the same crate are different types even if they look the same = help: you can use `cargo tree` to explore your dependency tree note: required by a bound in `do_something` --> /home/gh-estebank/rust/build/x86_64-unknown-linux-gnu/test/run-make/crate-loading/rmake_out/multiple-dep-versions-1.rs:12:24 | 12 | pub fn do_something<X: Trait>(_: X) {} | ^^^^^ required by this bound in `do_something` ```
2024-11-07Tweak detection of multiple crate versions to be more ecompassingEsteban Küber-39/+56
Previously, we only emitted the additional context if the type was in the same crate as the trait that appeared multiple times in the dependency tree. Now, we look at all traits looking for two with the same name in different crates with the same crate number, and we are more flexible looking for the types involved. This will work even if the type that implements the wrong trait version is from a different crate entirely. ``` error[E0277]: the trait bound `CustomErrorHandler: ErrorHandler` is not satisfied --> src/main.rs:5:17 | 5 | cnb_runtime(CustomErrorHandler {}); | ----------- ^^^^^^^^^^^^^^^^^^^^^ the trait `ErrorHandler` is not implemented for `CustomErrorHandler` | | | required by a bound introduced by this call | help: you have multiple different versions of crate `c` in your dependency graph --> src/main.rs:1:5 | 1 | use b::CustomErrorHandler; | ^ one version of crate `c` is used here, as a dependency of crate `b` 2 | use c::cnb_runtime; | ^ one version of crate `c` is used here, as a direct dependency of the current crate note: two types coming from two different versions of the same crate are different types even if they look the same --> /home/gh-estebank/testcase-rustc-crate-version-mismatch/c-v0.2/src/lib.rs:1:1 | 1 | pub trait ErrorHandler {} | ^^^^^^^^^^^^^^^^^^^^^^ this is the required trait | ::: /home/gh-estebank/testcase-rustc-crate-version-mismatch/b/src/lib.rs:1:1 | 1 | pub struct CustomErrorHandler {} | ----------------------------- this type doesn't implement the required trait | ::: /home/gh-estebank/testcase-rustc-crate-version-mismatch/c-v0.1/src/lib.rs:1:1 | 1 | pub trait ErrorHandler {} | ---------------------- this is the found trait = help: you can use `cargo tree` to explore your dependency tree note: required by a bound in `cnb_runtime` --> /home/gh-estebank/testcase-rustc-crate-version-mismatch/c-v0.2/src/lib.rs:3:41 | 3 | pub fn cnb_runtime(_error_handler: impl ErrorHandler) {} | ^^^^^^^^^^^^ required by this bound in `cnb_runtime` ``` Fix #89143.
2024-11-06Auto merge of #132625 - compiler-errors:cache-only-if-opaque, r=lcnrbors-6/+18
Only disable cache if predicate has opaques within it This is an alternative to https://github.com/rust-lang/rust/pull/132075. This refines the check implemented in https://github.com/rust-lang/rust/pull/126024 to only disable the global cache if the predicate being considered has opaques in it. This is still theoretically unsound, since goals can indirectly rely on opaques in the defining scope, but we're much less likely to hit it. It doesn't totally fix https://github.com/rust-lang/rust/issues/132064: for example, `lemmy` goes from 1:29 (on rust 1.81) to 9:53 (on nightly) to 4:07 (after this PR). But I think it's at least *more* sound than a total revert :/ r? lcnr
2024-11-05Only disable cache if predicate has opaques within itMichael Goulet-6/+18
2024-11-05Auto merge of #132580 - compiler-errors:globs, r=Noratriebbors-32/+40
Remove unnecessary pub enum glob-imports from `rustc_middle::ty` We used to have an idiom in the compiler where we'd prefix or suffix all the variants of an enum, for example `BoundRegionKind`, with something like `Br`, and then *glob-import* that enum variant directly. `@noratrieb` brought this up, and I think that it's easier to read when we just use the normal style `EnumName::Variant`. This PR is a bit large, but it's just naming. The only somewhat opinionated change that this PR does is rename `BorrowKind::Imm` to `BorrowKind::Immutable` and same for the other variants. I think these enums are used sparingly enough that the extra length is fine. r? `@noratrieb` or reassign
2024-11-04Rollup merge of #132608 - mejrs:type_impls_trait, r=compiler-errorsJubilee-0/+18
document `type_implements_trait` Rendered: ![image](https://github.com/user-attachments/assets/60c00e50-24fd-4b04-bb22-e71b479c0b29) r? `@compiler-errors`
2024-11-05Explain how to evaluate an obligationmejrs-3/+9
2024-11-04Rollup merge of #132583 - mejrs:tuples, r=compiler-errorsMatthias Krüger-0/+39
Suggest creating unary tuples when types don't match a trait When you want to have a variadic function, a common workaround to implement this is to create a trait and then implement that trait for various tuples. For example in `pyo3` there exists ```rust /// Calls the object with only positional arguments. pub fn call1(&self, args: impl IntoPy<Py<PyTuple>>) -> PyResult<&PyAny> { ... } ``` with various impls like ```rust impl<A: IntoPy<PyObject> IntoPy<Py<PyAny>> for (A,) impl<A: IntoPy<PyObject, B: IntoPy<PyObject> IntoPy<Py<PyAny>> for (A, B) ... etc ``` This means that if you want to call the method with a single item you have to create a unary tuple, like `(x,)`, rather than just `x`. This PR implements a suggestion to do that, if applicable.
2024-11-04Rollup merge of #132486 - compiler-errors:no-binder, r=lcnrMatthias Krüger-9/+3
No need to instantiate binder in `confirm_async_closure_candidate` Removes a FIXME that is redundant. No longer needed since #122267.
2024-11-04document `type_implements_trait`mejrs-0/+12
2024-11-04Suggest creating unary tuplesmejrs-0/+39
2024-11-04ty::BrK -> ty::BoundRegionKind::KMichael Goulet-24/+32
2024-11-04ty::KContainer -> ty::AssocItemContainer::KMichael Goulet-2/+2
2024-11-04Remove the trivial constkind importsMichael Goulet-6/+6
2024-11-03Rename the FIXMEs, remove a few that dont matter anymoreMichael Goulet-7/+5
2024-11-02compiler: Replace rustc_target with _abi in _trait_selectionJubilee Young-8/+8
2024-11-02Use extract_callable_info, generalize it to async closureMichael Goulet-80/+97
2024-11-02Fix closure arg extraction in extract_callable_infoMichael Goulet-2/+2
2024-11-02No need to instantiate binder in confirm_async_closure_candidateMichael Goulet-9/+3
2024-11-02Account for negative bounds in E0277 note and suggestionEsteban Küber-1/+8
Do not suggest `#[derive(Copy)]` when we wanted a `!Copy` type. Do not say "`Copy` is not implemented for `T` but `Copy` is". Do not talk about `Trait` having no implementations when `!Trait` was desired.
2024-11-02On long E0277 primary span label, move it to a `help`Esteban Küber-0/+5
Long span labels don't read well.
2024-11-02Point at tail expression on rpit E0277Esteban Küber-11/+28
``` error[E0277]: the trait bound `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}: Coroutine` is not satisfied --> $DIR/gen_block_is_coro.rs:6:13 | LL | fn foo() -> impl Coroutine<Yield = u32, Return = ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine` is not implemented for `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}` LL | gen { yield 42 } | ---------------- return type was inferred to be `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}` here ``` The secondary span label is new.
2024-11-02Use `short_ty_string`Esteban Küber-1/+3
2024-11-02Trim output of E0277 in some casesEsteban Küber-2/+18
Remove default note for "trait is not implemented" in favor of the more colorful diff output from the previous commit. Removes duplicated output.
2024-11-02Add trait diff highlighting logic and use it in E0277Esteban Küber-13/+116
When a trait is not implemented for a type, but there *is* an `impl` for another type or different trait params, we format the output to use highlighting in the same way that E0308 does for types. The logic accounts for 3 cases: - When both the type and trait in the expected predicate and the candidate are different - When only the types are different - When only the trait generic params are different For each case, we use slightly different formatting and wording.
2024-10-31Rollup merge of #132403 - lcnr:typing-mode, r=compiler-errorsJubilee-37/+47
continue `TypingMode` refactor There are still quite a few places which (indirectly) rely on the `Reveal` of a `ParamEnv`, but we're slowly getting there r? `@compiler-errors`
2024-10-31normalization folders, yeet `ParamEnv::reveal`lcnr-24/+31
2024-10-31traits::project: yeet `ParamEnv::reveal`lcnr-13/+16
2024-10-31Auto merge of #132301 - compiler-errors:adjust, r=lcnrbors-4/+1
Remove region from adjustments It's not necessary to store this region, because it's only used in THIR and MemCat/ExprUse, both of which already basically only deal with erased regions anyways.
2024-10-31Auto merge of #131186 - compiler-errors:precise-capturing-borrowck, r=estebankbors-2/+5
Try to point out when edition 2024 lifetime capture rules cause borrowck issues Lifetime capture rules in 2024 are modified to capture more lifetimes, which sometimes lead to some non-local borrowck errors. This PR attempts to link these back together with a useful note pointing out the capture rule changes. This is not a blocking concern, but I'd appreciate feedback (though, again, I'd like to stress that I don't want to block this PR on this): I'm worried about this note drowning in the sea of other diagnostics that borrowck emits. I was tempted to change the level of the note to `.span_warn` just so it would show up in a different color. Thoughts? Fixes #130545 Opening as a draft first since it's stacked on #131183. r? `@ghost`
2024-10-31Encode cross-crate opaque type originMichael Goulet-2/+5
2024-10-31Auto merge of #132377 - matthiaskrgr:rollup-3p1c6hs, r=matthiaskrgrbors-6/+0
Rollup of 3 pull requests Successful merges: - #132368 (Remove `do_not_const_check` from `Iterator` methods) - #132373 (Make sure `type_param_predicates` resolves correctly for RPITIT) - #132374 (Remove dead code stemming from the old effects desugaring) r? `@ghost` `@rustbot` modify labels: rollup