summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
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-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-10impossible obligations check fast pathlcnr-1/+12
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-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-26Check allow instantiating object trait binder when upcasting and in new solverMichael Goulet-3/+3
2024-09-25Compiler: Rename "object safe" to "dyn compatible"León Orell Valerian Liehr-62/+58
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-22Reformat using the new identifier sorting from rustfmtMichael Goulet-212/+171
2024-09-22Introduce structurally_normalize_const, use it in hir_typeckMichael Goulet-0/+40
2024-09-19skip normalizing param env if it is already normalizedLukas Markeffsky-0/+3
2024-09-13Rename and reorder lots of lifetimes.Nicholas Nethercote-17/+17
- Replace non-standard names like 's, 'p, 'rg, 'ck, 'parent, 'this, and 'me with vanilla 'a. These are cases where the original name isn't really any more informative than 'a. - Replace names like 'cx, 'mir, and 'body with vanilla 'a when the lifetime applies to multiple fields and so the original lifetime name isn't really accurate. - Put 'tcx last in lifetime lists, and 'a before 'b.
2024-09-12Auto merge of #130269 - Zalathar:rollup-coxzt2t, r=Zalatharbors-32/+25
Rollup of 8 pull requests Successful merges: - #125060 (Expand documentation of PathBuf, discussing lack of sanitization) - #129367 (Fix default/minimum deployment target for Aarch64 simulator targets) - #130156 (Add test for S_OBJNAME & update test for LF_BUILDINFO cl and cmd) - #130160 (Fix `slice::first_mut` docs) - #130235 (Simplify some nested `if` statements) - #130250 (Fix `clippy::useless_conversion`) - #130252 (Properly report error on `const gen fn`) - #130256 (Re-run coverage tests if `coverage-dump` was modified) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-12Rollup merge of #130250 - compiler-errors:useless-conversion, r=jieyouxuStuart Cook-2/+2
Fix `clippy::useless_conversion` Self-explanatory. Probably the last clippy change I'll actually put up since this is the only other one I've actually seen in the wild.
2024-09-11Revert 'Stabilize -Znext-solver=coherence'Michael Goulet-1/+3
2024-09-11clippy::useless_conversionMichael Goulet-2/+2
2024-09-11Also fix if in elseMichael Goulet-6/+4
2024-09-11Simplify some nested if statementsMichael Goulet-24/+19
2024-09-06Auto merge of #128776 - Bryanskiy:deep-reject-ctxt, r=lcnrbors-8/+22
Use `DeepRejectCtxt` to quickly reject `ParamEnv` candidates The description is on the [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/.5Basking.20for.20help.5D.20.60DeepRejectCtxt.60.20for.20param.20env.20candidates) r? `@lcnr`
2024-09-05stabilize `-Znext-solver=coherence`lcnr-3/+1
2024-09-03do not attempt to prove unknowable goalslcnr-72/+66
2024-09-03Auto merge of #129777 - nnethercote:unreachable_pub-4, r=Urgaubors-16/+16
Add `unreachable_pub`, round 4 A follow-up to #129732. r? `@Urgau`
2024-09-03Add `warn(unreachable_pub)` to `rustc_trait_selection`.Nicholas Nethercote-16/+16
2024-09-02Rollup merge of #129878 - Sajjon:sajjon_fix_typos_batch_3, r=jieyouxuMatthias Krüger-3/+3
chore: Fix typos in 'compiler' (batch 3) Batch 3/3: Fixes typos in `compiler` (See [issue](https://github.com/rust-lang/rust/issues/129874) tracking all PRs with typos fixes)
2024-09-02Use `DeepRejectCtxt` to quickly reject `ParamEnv` candidatesBryanskiy-8/+22
2024-09-02chore: Fix typos in 'compiler' (batch 3)Alexander Cyon-3/+3
2024-09-01Revert "Auto merge of #127537 - veluca93:struct_tf, r=BoxyUwU"Jakub Beránek-2/+0
This reverts commit acb4e8b6251f1d8da36f08e7a70fa23fc581839e, reversing changes made to 100fde5246bf56f22fb5cc85374dd841296fce0e.
2024-08-31Rollup merge of #129767 - nnethercote:rm-extern-crate-tracing-4, r=jieyouxuMatthias Krüger-0/+23
Remove `#[macro_use] extern crate tracing`, round 4 Because explicit importing of macros via use items is nicer (more standard and readable) than implicit importing via #[macro_use]. Continuing the work from #124511, #124914, and #125434. After this PR no `rustc_*` crates use `#[macro_use] extern crate tracing` except for `rustc_codegen_gcc` which is a special case and I will do separately. r? ```@jieyouxu```
2024-08-31Rollup merge of #129725 - compiler-errors:predicates-of, r=fmeaseMatthias Krüger-16/+11
Stop using `ty::GenericPredicates` for non-predicates_of queries `GenericPredicates` is a struct of several parts: A list of of an item's own predicates, and a parent def id (and some effects related stuff, but ignore that since it's kinda irrelevant). When instantiating these generic predicates, it calls `predicates_of` on the parent and instantiates its predicates, and appends the item's own instantiated predicates too: https://github.com/rust-lang/rust/blob/acb4e8b6251f1d8da36f08e7a70fa23fc581839e/compiler/rustc_middle/src/ty/generics.rs#L407-L413 Notice how this should result in a recursive set of calls to `predicates_of`... However, `GenericPredicates` is *also* misused by a bunch of *other* queries as a convenient way of passing around a list of predicates. For these queries, we don't ever set the parent def id of the `GenericPredicates`, but if we did, then this would be very easy to mistakenly call `predicates_of` instead of some other intended parent query. Given that footgun, and the fact that we don't ever even *use* the parent def id in the `GenericPredicates` returned from queries like `explicit_super_predicates_of`, It really has no benefit over just returning `&'tcx [(Clause<'tcx>, Span)]`. This PR additionally opts to wrap the results of `EarlyBinder`, as we've tended to use that in the return type of these kinds of queries to properly convey that the user has params to deal with, and it also gives a convenient way of iterating over a slice of things after instantiating.
2024-08-30Remove `#[macro_use] extern crate tracing` from `rustc_trait_selection`.Nicholas Nethercote-0/+23
2024-08-29Stop using ty::GenericPredicates for non-predicates_of queriesMichael Goulet-16/+11
2024-08-28Implement RFC 3525.Luca Versari-0/+2
2024-08-21Simplify some redundant field namesMichael Goulet-1/+1
2024-08-19Rollup merge of #129217 - jswrenn:transmute-lifetimes, r=compiler-errorsMatthias Krüger-73/+103
safe transmute: check lifetimes Modifies `BikeshedIntrinsicFrom` to forbid lifetime extensions on references. This static check can be opted out of with the `Assume::lifetimes` flag. Fixes #129097 Tracking Issue: https://github.com/rust-lang/rust/issues/99571 r​? `@compiler-errors`
2024-08-18safe transmute: forbid reference lifetime extensionJack Wrenn-73/+103
Modifies `BikeshedIntrinsicFrom` to forbid lifetime extensions on references. This static check can be opted out of with the `Assume::lifetimes` flag. Fixes #129097
2024-08-18Fix order of normalization and recursion in const folding.Luca Versari-4/+4
Fixes #126831. Without this patch, type normalization is not always idempotent, which leads to all sorts of bugs in places that assume that normalizing a normalized type does nothing.
2024-08-15Rollup merge of #129078 - lcnr:scrape_region_constraints-use-ocx, ↵Jubilee-35/+3
r=compiler-errors `ParamEnvAnd::fully_perform`: we have an `ocx`, use it cc #123669 r? ``@compiler-errors``
2024-08-15Rollup merge of #129106 - compiler-errors:unused-type-ops, r=jieyouxuMatthias Krüger-65/+0
Remove redundant type ops: `Eq`/`Subtype` r? lcnr or anyone really
2024-08-14Remove redundant type opsMichael Goulet-65/+0
2024-08-14if we have an `ocx`, use itlcnr-35/+3
2024-08-14Auto merge of #129076 - matthiaskrgr:rollup-rg8mi2x, r=matthiaskrgrbors-2/+2
Rollup of 6 pull requests Successful merges: - #128410 (Migrate `remap-path-prefix-dwarf` `run-make` test to rmake) - #128759 (alloc: add ToString specialization for `&&str`) - #128873 (Add windows-targets crate to std's sysroot) - #129001 (chore(lib): Enhance documentation for core::fmt::Formatter's write_fm…) - #129061 (Use `is_lang_item` more) - #129062 (Remove a no-longer-true assert) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-14Rollup merge of #129061 - compiler-errors:lang-item, r=UrgauMatthias Krüger-2/+2
Use `is_lang_item` more Few places that I missed since introducing `TyCtxt::is_lang_item`.
2024-08-14Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errorsbors-16/+16
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-2/+2