about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2025-01-14Make sure we can produce ConstArgHasWrongType errors for valtree constsMichael Goulet-2/+3
2025-01-14Rollup merge of #135466 - compiler-errors:leak-check-impossible, r=lcnrMatthias Krüger-3/+12
Leak check in `impossible_predicates` to avoid monomorphizing impossible instances Fixes #135462 r? lcnr
2025-01-14Prefer lower TraitUpcasting candidatesMichael Goulet-1/+17
2025-01-14Auto merge of #135278 - tgross35:ignore-std-dep-crates, r=SparrowLiibors-1/+1
Exclude dependencies of `std` for diagnostics Currently crates in the sysroot can show up in diagnostic suggestions, such as in https://github.com/rust-lang/rust/issues/135232. To prevent this, duplicate `all_traits` into `visible_traits` which only shows traits in non-private crates. Setting `#![feature(rustc_private)]` overrides this and makes items in private crates visible as well, since `rustc_private` enables use of `std`'s private dependencies. This may be reviewed per-commit. Fixes: https://github.com/rust-lang/rust/issues/135232
2025-01-14Add `tcx.visible_traits()` and use it for producing diagnosticsTrevor Gross-1/+1
Add an alternative to `tcx.all_traits()` that only shows traits that the user might be able to use, for diagnostic purposes. With this available, make use of it for diagnostics including associated type errors, which is part of the problem with [1]. Includes a few comment updates for related API. [1]: https://github.com/rust-lang/rust/issues/135232
2025-01-14Rollup merge of #135464 - lukas-code:project-infinite-to-error, ↵Matthias Krüger-3/+4
r=FedericoBruzzone,oli-obk fix ICE with references to infinite structs in consts fixes https://github.com/rust-lang/rust/issues/114484 Normalizing `<Type as Pointee>::Metadata` may emit a (non-fatal) error during trait selection if finding the struct tail of `Type` hits the recursion limit. When this happens, prior this PR, we would treat the projection as rigid, i.e. don't normalize it further. This PR changes it so that we normalize to `ty::Error` instead. This is important, because to compute the layout of `&Type` we need to compute the layout of `<Type as Pointee>::Metadata` https://github.com/rust-lang/rust/blob/2ae9916816a448fcaab3b2da461de754eda0055a/compiler/rustc_ty_utils/src/layout.rs#L247-L273 and computing the layout of a rigid alias will (correctly) fail and needs to report an error to the user. For example: ```rust trait Project { type Assoc; } fn foo<T: Project>() { [(); { let _: Option<T::Assoc> = None; // ^^^^^^^^ this projection is rigid, so we can't know it's layout 0 }]; } ``` ``` error: constant expression depends on a generic parameter --> src/lib.rs:6:10 | 6 | [(); { | __________^ 7 | | let _: Option<T::Assoc> = None; 8 | | // ^^^^^^^^ this projection is rigid, so we can't know it's layout 9 | | 0 10 | | }]; | |_____^ | = note: this may fail depending on what value the parameter takes ``` For non-generic rigid projections we will currently ICE, because we incorrectly assume that `LayoutError::Unknown` means that a const must be generic (https://github.com/rust-lang/rust/issues/135138). This is being fixed and turned into a proper error in https://github.com/rust-lang/rust/pull/135158. ```rust #![feature(trivial_bounds)] trait Project { type Assoc; } fn foo() where u8: Project, { [(); { let _: Option<<u8 as Project>::Assoc> = None; // ICEs currently, but will be an error 0 }]; } ``` However, if we hit the recursion limit when normalizing `<Type as Pointee>::Metadata` we don't want to report a layout error, because we already emitted the recursion error. So by normalizing to `ty::Error` here, we get a `LayoutError::ReferencesError` instead of a `LayoutError::Unknown` and don't report the layout error to the user.
2025-01-14Leak check in impossible_predicates to avoid monomorphizing impossible instancesMichael Goulet-3/+12
2025-01-14fix ICE with references to infinite structs in constsLukas Markeffsky-3/+4
2025-01-13Assert that Instance::try_resolve is only used on body-like thingsMichael Goulet-0/+156
2025-01-10mir_transform: implement forced inliningDavid Wood-4/+14
Adds `#[rustc_force_inline]` which is similar to always inlining but reports an error if the inlining was not possible, and which always attempts to inline annotated items, regardless of optimisation levels. It can only be applied to free functions to guarantee that the MIR inliner will be able to resolve calls.
2025-01-09Rollup merge of #135269 - estebank:unneeded-into, r=compiler-errorsMatthias Krüger-2/+2
Remove some unnecessary `.into()` calls
2025-01-09Rollup merge of #135247 - tgross35:stdlib-sym-list, r=oli-obkMatthias Krüger-2/+2
Add a list of symbols for stable standard library crates There are a few locations where the crate name is checked against an enumerated list of `std`, `core`, `alloc`, and `proc_macro`, or some subset thereof. In most cases when we are looking for any "standard library" crate, all four crates should be treated the same. Change this so the crates are listed in one place, and that list is used wherever a list of `std` crates is needed. `test` could be considered relevant in some of these cases, but generally treating it separate from the others seems preferable while it is unstable. There are also a few places that Clippy will be able to use this.
2025-01-09Rollup merge of #134875 - compiler-errors:const-destruct-old-solver, r=lcnrMatthias Krüger-1/+105
Implement `const Destruct` in old solver Self-explanatory. Not totally settled that this is the best structure for built-in trait impls for effect goals in the new solver, but it's almost certainly the simplest. r? lcnr or re-roll
2025-01-09Rollup merge of #128110 - veera-sivarajan:bugfix-80173, r=cjgillotMatthias Krüger-0/+6
Suggest Replacing Comma with Semicolon in Incorrect Repeat Expressions Fixes #80173 This PR detects typos in repeat expressions like `["_", 10]` and `vec![String::new(), 10]` and suggests replacing comma with semicolon. Also, improves code in other place by adding doc comments and making use of a helper function to check if a type implements `Clone`. References: 1. For `vec![T; N]`: https://doc.rust-lang.org/std/macro.vec.html 2. For `[T; N]`: https://doc.rust-lang.org/std/primitive.array.html
2025-01-08Add a list of symbols for stable standard library cratesTrevor Gross-2/+2
There are a few locations where the crate name is checked against an enumerated list of `std`, `core`, `alloc`, and `proc_macro`, or some subset thereof. In most of these cases, all four crates should likely be treated the same. Change this so the crates are listed in one place, and that list is used wherever a list of `std` crates is needed. `test` could be considered relevant in some of these cases, but generally treating it separate from the others seems preferable while it is unstable. There are also a few places that Clippy will be able to use this.
2025-01-08Remove some unnecessary `.into()` callsEsteban Küber-2/+2
2025-01-08Implement const Destruct in old solverMichael Goulet-1/+105
2025-01-06Rollup merge of #132345 - compiler-errors:fx-diag, r=lcnrJacob Pratt-14/+154
Improve diagnostics for `HostEffectPredicate` in the new solver Adds derived cause for host effect predicates. Some diagnostics regress, but that's connected to the fact that our predicate visitor doesn't play well with aliases just yet.
2025-01-06Rollup merge of #134951 - compiler-errors:double-trait-err-msg, r=davidtwcoMatthias Krüger-19/+38
Suppress host effect predicates if underlying trait doesn't hold Don't report two errors for when the (`HostEffectPredicate`) `T: const Trait` isn't implemented because (`TraitPredicate`) `T: Trait` doesn't even hold.
2025-01-06Rollup merge of #134771 - compiler-errors:const-arg-has-type-err, r=lcnrMatthias Krüger-1/+18
Report correct `SelectionError` for `ConstArgHasType` in new solver fulfill r? ``@BoxyUwU``
2025-01-06Recurse on GAT where clauses in fulfillment error proof tree visitorMichael Goulet-5/+9
2025-01-06Add derived causes for host effect predicatesMichael Goulet-13/+149
2025-01-04Auto merge of #135031 - RalfJung:intrinsics-without-body, r=oli-obkbors-15/+27
rustc_intrinsic: support functions without body We synthesize a HIR body `loop {}` but such bodyless intrinsics. Most of the diff is due to turning `ItemKind::Fn` into a brace (named-field) enum variant, because it carries a `bool`-typed field now. This is to remember whether the function has a body. MIR building panics to avoid ever translating the fake `loop {}` body, and the intrinsic logic uses the lack of a body to implicitly mark that intrinsic as must-be-overridden. I first tried actually having no body rather than generating the fake body, but there's a *lot* of code that assumes that all function items have HIR and MIR, so this didn't work very well. Then I noticed that even `rustc_intrinsic_must_be_overridden` intrinsics have MIR generated (they are filled with an `Unreachable` terminator) so I guess I am not the first to discover this. ;) r? `@oli-obk`
2025-01-04turn hir::ItemKind::Fn into a named-field variantRalf Jung-15/+27
2025-01-04Rollup merge of #135069 - matthiaskrgr:param_rec_usage, r=jieyouxuMatthias Krüger-4/+3
remove unused function params
2025-01-04Auto merge of #135057 - compiler-errors:project-unconstrained, r=oli-obkbors-32/+50
Project to `TyKind::Error` when there are unconstrained non-lifetime (ty/const) impl params It splits the `enforce_impl_params_are_constrained` function into lifetime/non-lifetime, and queryfies the latter. We can then use the result of the latter query (`Result<(), ErrorGuaranteed>`) to intercept projection and constrain the projected type to `TyKind::Error`, which ensures that we leak no ty or const vars to places that don't expect them, like `normalize_erasing_regions`. The reason we split `enforce_impl_params_are_constrained` into two parts is because we only error for *lifetimes* if the lifetime ends up showing up in any of the associated types of the impl (e.g. we allow `impl<'a> Foo { type Assoc = (); }`). However, in order to compute the `type_of` query for the anonymous associated type of an RPITIT, we need to do trait solving (in `query collect_return_position_impl_trait_in_trait_tys`). That would induce cycles. Luckily, it turns out for lifetimes we don't even care about if they're unconstrained, since they're erased in all contexts that we are trying to fix ICEs. So it's sufficient to keep this check separated out of the query. I think this is a bit less invasive of an approach compared to #127973. The major difference between this PR and that PR is that we queryify the check instead of merging it into the `explicit_predicates_of` query, and we use the result to taint just projection goals, rather than trait goals too. This doesn't require a lot of new tracking in `ItemCtxt` and `GenericPredicates`, and it also seems to not require any other changes to typeck like that PR did. Fixes #123141 Fixes #125874 Fixes #126942 Fixes #127804 Fixes #130967 r? oli-obk
2025-01-03remove unused function paramsMatthias Krüger-4/+3
2025-01-03Also in the new solverMichael Goulet-3/+2
2025-01-03Do not project when there are unconstrained impl paramsMichael Goulet-29/+48
2025-01-02Remove unused fields from RepeatElementCopy obligationTaylor Cramer-6/+1
2025-01-01Rollup merge of #133292 - dianne:e0277-suggest-deref, r=estebankStuart Cook-113/+85
E0277: suggest dereferencing function arguments in more cases This unifies and generalizes some of the logic in `TypeErrCtxt::suggest_dereferences` so that it will suggest dereferencing arguments to function/method calls in order to satisfy trait bounds in more cases. Previously it would only fire on reference types, and it had two separate cases (one specifically to get through custom `Deref` impls when passing by-reference, and one specifically to catch #87437). I've based the new checks loosely on what's done for `E0308` in `FnCtxt::suggest_deref_or_ref`: it will suggest dereferences to satisfy trait bounds whenever the referent is `Copy`, is boxed (& so can be moved out of the boxes), or is being passed by reference. This doesn't make the suggestion fire in contexts other than function arguments or binary operators (which are in a separate case that this doesn't touch), and doesn't make it suggest a combination of `&`-removal and dereferences. Those would require a bit more restructuring, so I figured just doing this would be a decent first step. Closes #90997
2024-12-31Rollup merge of #134949 - compiler-errors:froms, r=jieyouxuStuart Cook-6/+6
Convert some `Into` impls into `From` impls From the [`From`](https://doc.rust-lang.org/std/convert/trait.From.html) docs: > One should always prefer implementing `From` over [`Into`](https://doc.rust-lang.org/std/convert/trait.Into.html) because implementing `From` automatically provides one with an implementation of [`Into`](https://doc.rust-lang.org/std/convert/trait.Into.html) thanks to the blanket implementation in the standard library. > > Only implement [`Into`](https://doc.rust-lang.org/std/convert/trait.Into.html) when targeting a version prior to Rust 1.41 and converting to a type outside the current crate. `From` was not able to do these types of conversions in earlier versions because of Rust’s orphaning rules. See [Into](https://doc.rust-lang.org/std/convert/trait.Into.html) for more details. Some of these impls are likely from before 1.41, and then some others were probably just mistakes. Building nightly rust is definitely not supported on 1.41, so let's modernize these impls :D
2024-12-31nit: what the heck is `o`Michael Goulet-2/+2
2024-12-31Suppress host effect predicates if underlying trait doesn't holdMichael Goulet-17/+36
2024-12-31Convert some Into impls into From implsMichael Goulet-6/+6
2024-12-31Make sure we check the future type is Sized in AsyncFn*Michael Goulet-3/+20
2024-12-27Rollup merge of #134827 - compiler-errors:borrowck-nits, r=lqdDavid Tolnay-2/+1
Some random region tweaks Remove a redundant function and add an assertion that I think is useful
2024-12-27Rollup merge of #134823 - chloefeal:fix, r=tgross35,dtolnayDavid Tolnay-1/+1
Fix typos This PR focuses on correcting typos and improving clarity in documentation files. Thank you.
2024-12-27Fix typoschloefeal-1/+1
Signed-off-by: chloefeal <188809157+chloefeal@users.noreply.github.com>
2024-12-26Make ty::Error implement auto traitsMichael Goulet-1/+3
2024-12-26nit: Remove redundant functionMichael Goulet-2/+1
2024-12-25Report correct SelectionError for ConstArgHasType in new solver fulfillMichael Goulet-1/+18
2024-12-24Auto merge of #134716 - Zalathar:rollup-1h4q8cc, r=Zalatharbors-28/+137
Rollup of 5 pull requests Successful merges: - #134638 (Fix effect predicates from item bounds in old solver) - #134662 (Fix safety docs for `dyn Any + Send {+ Sync}`) - #134689 (core: fix const ptr::swap_nonoverlapping when there are pointers at odd offsets) - #134699 (Belay new reviews for workingjubilee) - #134701 (Correctly note item kind in `NonConstFunctionCall` error message) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-24Rollup merge of #134638 - compiler-errors:fx-item-bounds, r=lcnrStuart Cook-28/+137
Fix effect predicates from item bounds in old solver r? lcnr
2024-12-22Begin to implement type system layer of unsafe bindersMichael Goulet-3/+33
2024-12-22Rollup merge of #134639 - compiler-errors:negative-ambiguity-causes, r=oli-obkMatthias Krüger-9/+13
Make sure we note ambiguity causes on positive/negative impl conflicts Fixes https://github.com/rust-lang/rust/issues/134632 by explaining why the error must be
2024-12-22Make sure we note ambiguity causes on positive/negative impl conflictsMichael Goulet-9/+13
2024-12-22Fix item bounds in old solverMichael Goulet-28/+137
2024-12-21Auto merge of #134501 - lcnr:member-constraints-yeet, r=oli-obkbors-15/+5
handle member constraints directly in the mir type checker cleaner, faster, easier to change going forward :> fixes #109654 r? `@oli-obk` `@compiler-errors`
2024-12-21Suggest Semicolon in Incorrect Repeat ExpressionsVeera-0/+6