summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2024-11-14Only disable cache if predicate has opaques within itMichael Goulet-21/+45
(cherry picked from commit 49153739fd01d82ed999c763fd2771cb837d7dd2)
2024-10-11remove outdated FIXMEslcnr-0/+2
2024-10-10Rollup merge of #131475 - fmease:compiler-mv-obj-safe-dyn-compat-2, r=jieyouxuMatthias Krüger-16/+12
Compiler & its UI tests: Rename remaining occurrences of "object safe" to "dyn compatible" Follow-up to #130826. Part of #130852. 1. 1st commit: Fix stupid oversights. Should've been part of #130826. 2. 2nd commit: Rename the unstable feature `object_safe_for_dispatch` to `dyn_compatible_for_dispatch`. Might not be worth the churn, you decide. 3. 3rd commit: Apply the renaming to all UI tests (contents and paths).
2024-10-10Auto merge of #131263 - compiler-errors:solver-relating, r=lcnrbors-6/+0
Introduce SolverRelating type relation to the new solver Redux of #128744. Splits out relate for the new solver so that implementors don't need to implement it themselves. r? lcnr
2024-10-10impossible obligations check fast pathlcnr-8/+21
2024-10-10Use SolverRelating in new solverMichael Goulet-6/+0
2024-10-10Rename feature object_safe_for_dispatch to dyn_compatible_for_dispatchLeón Orell Valerian Liehr-5/+5
2024-10-10Compiler: Replace remaining occurrences of "object safe" with "dyn compatible"León Orell Valerian Liehr-12/+8
2024-10-06Rename NestedMetaItem to MetaItemInnercodemountains-3/+3
2024-10-05Auto merge of #129244 - cjgillot:opaque-hir, r=compiler-errorsbors-27/+21
Make opaque types regular HIR nodes Having opaque types as HIR owner introduces all sorts of complications. This PR proposes to make them regular HIR nodes instead. I haven't gone through all the test changes yet, so there may be a few surprises. Many thanks to `@camelid` for the first draft. Fixes https://github.com/rust-lang/rust/issues/129023 Fixes #129099 Fixes #125843 Fixes #119716 Fixes #121422
2024-10-04Rollup merge of #131273 - estebank:issue-131051, r=compiler-errorsJubilee-1/+21
Account for `impl Trait {` when `impl Trait for Type {` was intended On editions where bare traits are never allowed, detect if the user has written `impl Trait` with no type, silence any dyn-compatibility errors, and provide a structured suggestion for the potentially missing type: ``` error[E0782]: trait objects must include the `dyn` keyword --> $DIR/missing-for-type-in-impl.rs:8:6 | LL | impl Foo<i64> { | ^^^^^^^^ | help: add `dyn` keyword before this trait | LL | impl dyn Foo<i64> { | +++ help: you might have intended to implement this trait for a given type | LL | impl Foo<i64> for /* Type */ { | ++++++++++++++ ``` CC #131051.
2024-10-04rm `ItemKind::OpaqueTy`Noah Lev-27/+21
This introduce an additional collection of opaques on HIR, as they can no longer be listed using the free item list.
2024-10-04Account for `impl Trait {` when `impl Trait for Type {` was intendedEsteban Küber-1/+21
On editions where bare traits are never allowed, detect if the user has written `impl Trait` with no type, silence any dyn-compatibility errors, and provide a structured suggestion for the potentially missing type: ``` error[E0782]: trait objects must include the `dyn` keyword --> $DIR/missing-for-type-in-impl.rs:8:6 | LL | impl Foo<i64> { | ^^^^^^^^ | help: add `dyn` keyword before this trait | LL | impl dyn Foo<i64> { | +++ help: you might have intended to implement this trait for a given type | LL | impl Foo<i64> for /* Type */ { | ++++++++++++++ ```
2024-10-04Rollup merge of #130518 - scottmcm:stabilize-controlflow-extra, r=dtolnayJubilee-1/+0
Stabilize the `map`/`value` methods on `ControlFlow` And fix the stability attribute on the `pub use` in `core::ops`. libs-api in https://github.com/rust-lang/rust/issues/75744#issuecomment-2231214910 seemed reasonably happy with naming for these, so let's try for an FCP. Summary: ```rust impl<B, C> ControlFlow<B, C> { pub fn break_value(self) -> Option<B>; pub fn map_break<T>(self, f: impl FnOnce(B) -> T) -> ControlFlow<T, C>; pub fn continue_value(self) -> Option<C>; pub fn map_continue<T>(self, f: impl FnOnce(C) -> T) -> ControlFlow<B, T>; } ``` Resolves #75744 ``@rustbot`` label +needs-fcp +t-libs-api -t-libs --- Aside, in case it keeps someone else from going down the same dead end: I looked at the `{break,continue}_value` methods and tried to make them `const` as part of this, but that's disallowed because of not having `const Drop`, so put it back to not even unstably-const.
2024-10-04Rollup merge of #131034 - Urgau:cfg-true-false, r=nnethercoteGuillaume Gomez-5/+5
Implement RFC3695 Allow boolean literals as cfg predicates This PR implements https://github.com/rust-lang/rfcs/pull/3695: allow boolean literals as cfg predicates, i.e. `cfg(true)` and `cfg(false)`. r? `@nnethercote` *(or anyone with parser knowledge)* cc `@clubby789`
2024-10-03Rollup merge of #131183 - compiler-errors:opaque-ty-origin, r=estebankMatthias Krüger-4/+4
Refactoring to `OpaqueTyOrigin` Pulled out of a larger PR that uses these changes to do cross-crate encoding of opaque origin, so we can use them for edition 2024 migrations. These changes should be self-explanatory on their own, tho 😄
2024-10-03Rollup merge of #131112 - jswrenn:fix-130413, r=compiler-errorsMatthias Krüger-0/+11
TransmuteFrom: Gracefully handle unnormalized types and normalization errors ~~Refactor to share code between `TransmuteFrom`'s trait selection and error reporting code paths. Additionally normalizes the source and destination types, and gracefully handles normalization errors.~~ Fixes #130413 r​? `@compiler-errors`
2024-10-03Remove crashes, add commentMichael Goulet-0/+2
2024-10-02Move in_trait into OpaqueTyOriginMichael Goulet-1/+1
2024-10-02Use named fields for OpaqueTyOriginMichael Goulet-2/+2
2024-10-02Remove redundant in_trait from hir::TyKind::OpaqueDefMichael Goulet-2/+2
2024-10-02Improve const traits diagnostics for new desugaringDeadbeef-18/+68
2024-10-01TransmuteFrom: Gracefully handle unnormalized types and normalization errorsJack Wrenn-0/+9
Fixes #130413
2024-10-01Implement boolean lit support in cfg predicatesUrgau-1/+3
2024-10-01Use `ast::NestedMetaItem` when evaluating cfg predicateUrgau-7/+5
2024-09-30Also fix first_method_vtable_slotMichael Goulet-13/+12
2024-09-30Extract trait_refs_are_compatible, make it instantiate bindersMichael Goulet-28/+64
2024-09-30Instantiate binders in supertrait_vtable_slotMichael Goulet-10/+30
2024-09-28Rollup merge of #130866 - compiler-errors:dyn-instantiate-binder, r=lcnrMatthias Krüger-20/+73
Allow instantiating object trait binder when upcasting This PR fixes two bugs (that probably need an FCP). ### We use equality rather than subtyping for upcasting dyn conversions This code should be valid: ```rust #![feature(trait_upcasting)] trait Foo: for<'h> Bar<'h> {} trait Bar<'a> {} fn foo(x: &dyn Foo) { let y: &dyn Bar<'static> = x; } ``` But instead: ``` error[E0308]: mismatched types --> src/lib.rs:7:32 | 7 | let y: &dyn Bar<'static> = x; | ^ one type is more general than the other | = note: expected existential trait ref `for<'h> Bar<'h>` found existential trait ref `Bar<'_>` ``` And so should this: ```rust #![feature(trait_upcasting)] fn foo(x: &dyn for<'h> Fn(&'h ())) { let y: &dyn FnOnce(&'static ()) = x; } ``` But instead: ``` error[E0308]: mismatched types --> src/lib.rs:4:39 | 4 | let y: &dyn FnOnce(&'static ()) = x; | ^ one type is more general than the other | = note: expected existential trait ref `for<'h> FnOnce<(&'h (),)>` found existential trait ref `FnOnce<(&(),)>` ``` Specifically, both of these fail because we use *equality* when comparing the supertrait to the *target* of the unsize goal. For the first example, since our supertrait is `for<'h> Bar<'h>` but our target is `Bar<'static>`, there's a higher-ranked type mismatch even though we *should* be able to instantiate that supertrait binder when upcasting. Similarly for the second example. ### New solver uses equality rather than subtyping for no-op (i.e. non-upcasting) dyn conversions This code should be valid in the new solver, like it is with the old solver: ```rust // -Znext-solver fn foo<'a>(x: &mut for<'h> dyn Fn(&'h ())) { let _: &mut dyn Fn(&'a ()) = x; } ``` But instead: ``` error: lifetime may not live long enough --> <source>:2:11 | 1 | fn foo<'a>(x: &mut dyn for<'h> Fn(&'h ())) { | -- lifetime `'a` defined here 2 | let _: &mut dyn Fn(&'a ()) = x; | ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` | = note: requirement occurs because of a mutable reference to `dyn Fn(&())` ``` Specifically, this fails because we try to coerce `&mut dyn for<'h> Fn(&'h ())` to `&mut dyn Fn(&'a ())`, which registers an `dyn for<'h> Fn(&'h ()): dyn Fn(&'a ())` goal. This fails because the new solver uses *equating* rather than *subtyping* in `Unsize` goals. This is *mostly* not a problem... You may wonder why the same code passes on the new solver for immutable references: ``` // -Znext-solver fn foo<'a>(x: &dyn Fn(&())) { let _: &dyn Fn(&'a ()) = x; // works } ``` That's because in this case, we first try to coerce via `Unsize`, but due to the leak check the goal fails. Then, later in coercion, we fall back to a simple subtyping operation, which *does* work. Since `&T` is covariant over `T`, but `&mut T` is invariant, that's where the discrepancy between these two examples crops up. --- r? lcnr or reassign :D
2024-09-27Get rid of a_is_expected from ToTraceMichael Goulet-3/+0
2024-09-27Instantiate binders when checking supertrait upcastingMichael Goulet-20/+76
2024-09-27Rollup merge of #130826 - fmease:compiler-mv-obj-safe-dyn-compat, ↵Matthias Krüger-78/+75
r=compiler-errors Compiler: Rename "object safe" to "dyn compatible" Completed T-lang FCP: https://github.com/rust-lang/lang-team/issues/286#issuecomment-2338905118. Tracking issue: https://github.com/rust-lang/rust/issues/130852 Excludes `compiler/rustc_codegen_cranelift` (to be filed separately). Includes Stable MIR. Regarding https://github.com/rust-lang/rust/labels/relnotes, I guess I will manually open a https://github.com/rust-lang/rust/labels/relnotes-tracking-issue since this change affects everything (compiler, library, tools, docs, books, everyday language). r? ghost
2024-09-26Rollup merge of #130911 - ↵Jubilee-4/+25
notriddle:notriddle/suggest-wrap-parens-fn-pointer, r=compiler-errors diagnostics: wrap fn cast suggestions in parens when needed Fixes #121632
2024-09-26Check allow instantiating object trait binder when upcasting and in new solverMichael Goulet-3/+3
2024-09-26diagnostics: wrap fn cast suggestions in parensMichael Howell-4/+25
Fixes #121632
2024-09-25Stabilize the `map`/`value` methods on `ControlFlow`Scott McMurray-1/+0
And fix the stability attribute on the `pub use` in `core::ops`.
2024-09-25Compiler: Rename "object safe" to "dyn compatible"León Orell Valerian Liehr-78/+75
2024-09-25Fixed diagnostics for coroutines with () as input.Virginia Senioria-37/+35
2024-09-23Rollup merge of #130714 - compiler-errors:try-structurally-resolve-const, ↵Matthias Krüger-0/+40
r=BoxyUwU Introduce `structurally_normalize_const`, use it in `rustc_hir_typeck` Introduces `structurally_normalize_const` to typecking to separate the "eval a const" step from the "try to turn a valtree into a target usize" in HIR typeck, where we may still have infer vars and stuff around. I also changed `check_expr_repeat` to move a double evaluation of a const into a single one. I'll leave inline comments. r? ```@BoxyUwU``` I hesitated to really test this on the new solver where it probably matters for unevaluated consts. If you're worried about the side-effects, I'd be happy to craft some more tests 😄
2024-09-23Rollup merge of #130712 - compiler-errors:const-eval-error-reporting, r=BoxyUwUMatthias Krüger-21/+20
Don't call `ty::Const::normalize` in error reporting We do this to ensure that trait refs with unevaluated consts have those consts simplified to their evaluated forms. Instead, use `try_normalize_erasing_regions`. **NOTE:** This has the side-effect of erasing regions from all of our trait refs. If this is too much to review or you think it's too opinionated of a diagnostics change, then I could split out the effective change (i.e. erasing regions from this impl suggestion) into another PR and have someone else review it.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-348/+298
2024-09-22Don't call try_eval_target_usize in error reportingMichael Goulet-1/+1
2024-09-22Don't call const normalize in error reportingMichael Goulet-20/+19
2024-09-22Introduce structurally_normalize_const, use it in hir_typeckMichael Goulet-0/+40
2024-09-21Auto merge of #127546 - workingjubilee:5-level-paging-exists, r=saethlinbors-2/+2
Correct outdated object size limit The comment here about 48 bit addresses being enough was written in 2016 but was made incorrect in 2019 by 5-level paging, and then persisted for another 5 years before being noticed and corrected. The bolding of the "exclusive" part is merely to call attention to something I missed when reading it and doublechecking the math. try-job: i686-msvc try-job: test-various
2024-09-20TL note: current means targetJubilee Young-2/+2
2024-09-19skip normalizing param env if it is already normalizedLukas Markeffsky-0/+3
2024-09-18Rollup merge of #130116 - veera-sivarajan:freeze-suggestions, r=chenyukangMatthias Krüger-3/+3
Implement a Method to Seal `DiagInner`'s Suggestions This PR adds a method on `DiagInner` called `.seal_suggestions()` to prevent new suggestions from being added while preserving existing suggestions. This is useful because currently there is no way to prevent new suggestions from being added to a diagnostic. `.disable_suggestions()` is the closest but it gets rid of all suggestions before and after the call. Therefore, `.seal_suggestions()` can be used when, for example, misspelled keyword is detected and reported. In such cases, we may want to prevent other suggestions from being added to the diagnostic, as they would likely be meaningless once the misspelled keyword is identified. For context: https://github.com/rust-lang/rust/pull/129899#discussion_r1741307132 To store an additional state, the type of the `suggestions` field in `DiagInner` was changed into a three variant enum. While this change affects files across different crates, care was taken to preserve the existing code's semantics. This is validated by the fact that all UI tests pass without any modifications. r? chenyukang
2024-09-17Rollup merge of #130275 - compiler-errors:extern-crate, r=lcnrMatthias Krüger-0/+1
Don't call `extern_crate` when local crate name is the same as a dependency and we have a trait error #124944 implemented logic to point out when a trait bound failure involves a *trait* and *type* who come from identically named but different crates. This logic calls the `extern_crate` query which is not valid on `LOCAL_CRATE` cnum, so let's filter that out eagerly. Fixes #130272 Fixes #129184
2024-09-14Rollup merge of #130294 - nnethercote:more-lifetimes, r=lcnrLeón Orell Valerian Liehr-21/+21
Lifetime cleanups The last commit is very opinionated, let's see how we go. r? `@oli-obk`