about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2024-08-14Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errorsbors-45/+50
Shrink `TyKind::FnPtr`. By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI. r? `@compiler-errors`
2024-08-13Use is_lang_item moreMichael Goulet-5/+4
2024-08-13diagnostics: use `DeepRejectCtxt` for checkMichael Howell-9/+28
This makes more things match, particularly applicable blankets.
2024-08-12Rollup merge of #128912 - compiler-errors:do-not-recommend-impl, r=lcnrMatthias Krüger-20/+4
Store `do_not_recommend`-ness in impl header Alternative to #128674 It's less flexible, but also less invasive. Hopefully it's also performant. I'd recommend we think separately about the design for how to gate arbitrary diagnostic attributes moving forward.
2024-08-12Rollup merge of #128712 - compiler-errors:normalize-borrowck, r=lcnrMatthias Krüger-3/+3
Normalize struct tail properly for `dyn` ptr-to-ptr casting in new solver Realized that the new solver didn't handle ptr-to-ptr casting correctly. r? lcnr Built on #128694
2024-08-12reword messageEsteban Küber-2/+2
2024-08-12Rollup merge of #128978 - compiler-errors:assert-matches, r=jieyouxuGuillaume Gomez-4/+9
Use `assert_matches` around the compiler more It's a useful assertion, especially since it actually prints out the LHS.
2024-08-12do not use the global solver cache for proof treeslcnr-7/+3
doing so requires overwriting global cache entries and generally adds significant complexity to the solver. This is also only ever done for root goals, so it feels easier to wrap the `evaluate_canonical_goal` in an ordinary query if necessary.
2024-08-11Remove struct_tail_no_normalizationMichael Goulet-2/+2
2024-08-11Rename normalization functions to rawMichael Goulet-1/+1
2024-08-11Use assert_matches around the compilerMichael Goulet-4/+9
2024-08-11Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errorsMatthias Krüger-7/+7
Use more slice patterns inside the compiler Nothing super noteworthy. Just replacing the common 'fragile' pattern of "length check followed by indexing or unwrap" with slice patterns for legibility and 'robustness'. r? ghost
2024-08-10Auto merge of #128746 - compiler-errors:cache-super-outlives, r=lcnrbors-26/+16
Cache supertrait outlives of impl header for soundness check This caches the results of computing the transitive supertraits of an impl and filtering it to its outlives obligations. This is purely an optimization to improve https://github.com/rust-lang/rust/pull/124336.
2024-08-09Store do_not_recommend-ness in impl headerMichael Goulet-20/+4
2024-08-09Shrink `TyKind::FnPtr`.Nicholas Nethercote-45/+50
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI.
2024-08-09Rollup merge of #128791 - compiler-errors:async-fn-unsafe, r=lcnrMatthias Krüger-2/+14
Don't implement `AsyncFn` for `FnDef`/`FnPtr` that wouldnt implement `Fn` Due to unsafety, ABI, or the presence of target features, some `FnDef`/`FnPtr` types don't implement `Fn*`. Do the same for `AsyncFn*`. Noticed this due to #128764, but this isn't really related to that ICE, which is fixed in #128792.
2024-08-08Don't implement AsyncFn for FnDef/FnPtr that wouldnt implement FnMichael Goulet-2/+14
2024-08-08Detect `*` operator on `!Sized` expressionEsteban Küber-7/+42
``` error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/unsized-str-in-return-expr-arg-and-local.rs:15:9 | LL | let x = *""; | ^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature help: references are always `Sized`, even if they point to unsized data; consider not dereferencing the expression | LL - let x = *""; LL + let x = ""; | ```
2024-08-07Rollup merge of #128527 - estebank:ambiguity-suggestion, r=NadrierilGuillaume Gomez-21/+49
More information for fully-qualified suggestion when there are multiple impls ``` error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type --> $DIR/E0283.rs:30:21 | LL | fn create() -> u32; | ------------------- `Coroutine::create` defined here ... LL | let cont: u32 = Coroutine::create(); | ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait | help: use a fully-qualified path to a specific available implementation | LL | let cont: u32 = <Impl as Coroutine>::create(); | ++++++++ + LL | let cont: u32 = <AnotherImpl as Coroutine>::create(); | +++++++++++++++ + ```
2024-08-07Use more slice patterns inside the compilerLeón Orell Valerian Liehr-7/+7
2024-08-06diagnostics: `Box<dyn Trait>` suggestion with multiple matching implMichael Howell-15/+9
The two altered expectation messages both seem like improvements: - `coerce-expect-unsized-ascribed.stderr` says you can go `Box<char> -> Box<dyn Debug>`, which you can. - `upcast_soundness_bug.stderr` used to say that you could go `Box<dyn Trait<u8, u8>> -> Box<dyn Trait>`, which you can't, because the type parameters are missing in the destination and the only ones that work aren't what's needed.
2024-08-06fix rebaseEsteban Küber-2/+3
2024-08-06Add `help` about using `cargo tree`Esteban Küber-0/+1
2024-08-06On trait bound mismatch, detect multiple crate versions in dep treeEsteban Küber-39/+124
When encountering an E0277, if the type and the trait both come from a crate with the same name but different crate number, we explain that there are multiple crate versions in the dependency tree. If there's a type that fulfills the bound, and it has the same name as the passed in type and has the same crate name, we explain that the same type in two different versions of the same crate *are different*. ``` error[E0277]: the trait bound `Type: dependency::Trait` is not satisfied --> src/main.rs:4:18 | 4 | do_something(Type); | ------------ ^^^^ the trait `dependency::Trait` is not implemented for `Type` | | | required by a bound introduced by this call | help: you have multiple different versions of crate `dependency` in your dependency graph --> src/main.rs:1:5 | 1 | use bar::do_something; | ^^^ one version of crate `dependency` is used here, as a dependency of crate `bar` 2 | use dependency::Type; | ^^^^^^^^^^ one version of crate `dependency` 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/crate_versions/baz-2/src/lib.rs:1:1 | 1 | pub struct Type; | ^^^^^^^^^^^^^^^ this type doesn't implement the required trait | ::: /home/gh-estebank/crate_versions/baz/src/lib.rs:1:1 | 1 | pub struct Type; | ^^^^^^^^^^^^^^^ this type implements the required trait 2 | pub trait Trait {} | --------------- this is the required trait note: required by a bound in `bar::do_something` --> /home/gh-estebank/crate_versions/baz/src/lib.rs:4:24 | 4 | pub fn do_something<X: Trait>(_: X) {} | ^^^^^ required by this bound in `do_something` ``` Address #22750.
2024-08-06Cache supertrait outlives of impl header for soundness checkMichael Goulet-26/+16
2024-08-05Auto merge of #128689 - matthiaskrgr:rollup-ukyn8wq, r=matthiaskrgrbors-1/+1
Rollup of 5 pull requests Successful merges: - #128385 (rustdoc-json: discard non-local inherent impls for primitives) - #128559 (Don't re-elaborated already elaborated caller bounds in method probe) - #128631 (handle crates when they are not specified for std docs) - #128664 (Add `Debug` impls to API types in `rustc_codegen_ssa`) - #128686 (fix the invalid argument type) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-05Don't re-elaborated already elaborated caller bounds in method probeMichael Goulet-1/+1
2024-08-05Elaborate supertraits in dyn candidatesMichael Goulet-0/+1
2024-08-05Enforce supertrait outlives obligations hold when confirming implMichael Goulet-2/+32
2024-08-02More information for fully-qualified suggestion when there are multiple implsEsteban Küber-21/+49
``` error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type --> $DIR/E0283.rs:30:21 | LL | fn create() -> u32; | ------------------- `Coroutine::create` defined here ... LL | let cont: u32 = Coroutine::create(); | ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait | help: use a fully-qualified path to a specific available implementation | LL | let cont: u32 = <Impl as Coroutine>::create(); | ++++++++ + LL | let cont: u32 = <AnotherImpl as Coroutine>::create(); | +++++++++++++++ + ```
2024-07-31Rollup merge of #128438 - Bryanskiy:empty-array-dropck, r=lcnrMatthias Krüger-2/+9
Add special-case for [T, 0] in dropck_outlives implements/fixes #110288. r? `@lcnr`
2024-07-31Add special-case for [T, 0] in dropckBryanskiy-2/+9
2024-07-30Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68bors-4/+1
Bump bootstrap compiler to new beta https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-07-29only accept adt type during infer source visitorbohan-4/+4
2024-07-29Reformat `use` declarations.Nicholas Nethercote-452/+412
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28step cfg(bootstrap)Mark Rousskov-4/+1
2024-07-26Rollup merge of #128201 - compiler-errors:closure-clone, r=oli-obkTrevor Gross-2/+15
Implement `Copy`/`Clone` for async closures We can do so in the same cases that regular closures do. For the purposes of cloning, coroutine-closures are actually precisely the same as regular closures, specifically in the aspect that `Clone` impls care about which is the upvars. The only difference b/w coroutine-closures and regular closures is the type that they *return*, but this type has not been *created* yet, so we don't really have a problem. IDK why I didn't add this impl initially -- I went back and forth a bit on the internal representation for coroutine-closures before settling on a design which largely models regular closures. Previous (not published) iterations of coroutine-closures used to be represented as a special (read: cursed) kind of coroutine, which would probably suffer from the pitfalls that coroutines have that oli mentioned below in https://github.com/rust-lang/rust/pull/128201#issuecomment-2251230274. r? oli-obk
2024-07-26Auto merge of #121676 - Bryanskiy:polarity, r=petrochenkovbors-5/+5
Support ?Trait bounds in supertraits and dyn Trait under a feature gate This patch allows `maybe` polarity bounds under a feature gate. The only language change here is that corresponding hard errors are replaced by feature gates. Example: ```rust #![feature(allow_maybe_polarity)] ... trait Trait1 : ?Trait { ... } // ok fn foo(_: Box<(dyn Trait2 + ?Trait)>) {} // ok fn bar<T: ?Sized + ?Trait>(_: &T) {} // ok ``` Maybe bounds still don't do anything (except for `Sized` trait), however this patch will allow us to [experiment with default auto traits](https://github.com/rust-lang/rust/pull/120706#issuecomment-1934006762). This is a part of the [MCP: Low level components for async drop](https://github.com/rust-lang/compiler-team/issues/727)
2024-07-26Make coroutine-closures possible to be clonedMichael Goulet-2/+15
2024-07-26Rollup merge of #126090 - compiler-errors:supertrait-assoc-ty-unsoundness, ↵Matthias Krüger-114/+194
r=lcnr Fix supertrait associated type unsoundness ### What? Object safety allows us to name `Self::Assoc` associated types in certain positions if they come from our trait or one of our supertraits. When this check was implemented, I think it failed to consider that supertraits can have different args, and it was only checking def-id equality. This is problematic, since we can sneak different implementations in by implementing `Supertrait<NotActuallyTheSupertraitSubsts>` for a `dyn` type. This can be used to implement an unsound transmute function. See the committed test. ### How do we fix it? We consider the whole trait ref when checking for supertraits. Right now, this is implemented using equality *without* normalization. We erase regions since those don't affect trait selection. This is a limitation that could theoretically affect code that should be accepted, but doesn't matter in practice -- there are 0 crater regression. We could make this check stronger, but I would be worried about cycle issues. I assume that most people are writing `Self::Assoc` so they don't really care about the trait ref being normalized. --- ### What is up w the stacked commit This is built on top of https://github.com/rust-lang/rust/pull/122804 though that's really not related, it's just easier to make this modification with the changes to the object safety code that I did in that PR. The only thing is that PR may make this unsoundness slightly easier to abuse, since there are more positions that allow self-associated-types -- I am happy to stall that change until this PR merges. --- Fixes #126079 r? lcnr
2024-07-25Support ?Trait bounds in supertraits and dyn Trait under a feature gateBryanskiy-5/+5
2024-07-25Rollup merge of #128160 - compiler-errors:auto, r=jackh726Matthias Krüger-0/+6
Don't ICE when auto trait has assoc ty in old solver Kinda a pointless change to make, but it's observable w/o the feature gate, so let's just fix it. I reintroduced this ICE when I removed the "auto impl" kind from `ImplSource` in #112687. Fixes #117829 Fixes #127746
2024-07-24Don't ICE when auto trait has assoc ty in old solverMichael Goulet-0/+6
2024-07-24Do not assemble candidates for auto traits of opaque types in their defining ↵Oli Scherer-1/+6
scope
2024-07-24Do not try to reveal hidden types when trying to prove Freeze in the ↵Oli Scherer-7/+11
defining scope
2024-07-24Don't use global caches if opaques can be definedOli Scherer-1/+7
2024-07-23Rollup merge of #128076 - compiler-errors:infer_ctxt_ext, r=lcnrMatthias Krüger-248/+233
Get rid of `InferCtxtExt` from `error_reporting::traits` One more cleanup. r? lcnr
2024-07-23Suggest adding Result return type for associated method in E0277.surechen-5/+36
For following: ```rust struct A; impl A { fn test4(&self) { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method } ``` Suggest: ```rust impl A { fn test4(&self) -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method Ok(()) } } ``` For #125997
2024-07-22Get rid of infer_ctxt_extMichael Goulet-248/+233
2024-07-22Get rid of can_eq_shallowMichael Goulet-2/+3