about summary refs log tree commit diff
path: root/tests/ui/traits
AgeCommit message (Collapse)AuthorLines
2024-10-04Elaborate supertrait span correctly to label the error betterMichael Goulet-0/+3
2024-10-04Check elaborated projections from dyn don't mention unconstrained late bound ↵Michael Goulet-14/+36
lifetimes
2024-10-02Auto merge of #130821 - lcnr:nalgebra-hang-2, r=compiler-errorsbors-2/+74
add caching to most type folders, rm region uniquification Fixes the new minimization of the hang in nalgebra and nalgebra itself :3 this is a bit iffy, especially the cache in `TypeRelating`. I believe all the caches are correct, but it definitely adds some non-local complexity in places. The first commit removes region uniquification, reintroducing the ICE from https://github.com/rust-lang/trait-system-refactor-initiative/issues/27. This does not affect coherence and I would like to fix this by introducing OR-region constraints r? `@compiler-errors`
2024-10-01Rollup merge of #131042 - compiler-errors:supertrait-vtable, r=lcnrGuillaume Gomez-7/+8
Instantiate binders in `supertrait_vtable_slot` `supertrait_vtable_slot` was previously using structural equality when probing for the vtable slot, which led to an ICE since we need a *subtype* match, not an exact match. Fixes #131027 r? lcnr
2024-10-01add testslcnr-2/+74
2024-09-30Instantiate binders in supertrait_vtable_slotMichael Goulet-7/+8
2024-09-29fix(hir_analysis/wfcheck): don't leak {type error}Barrett Ray-2/+2
avoid `{type error}` being leaked in user-facing messages, particularly when using the `adt_const_params` feature
2024-09-28Rollup merge of #130866 - compiler-errors:dyn-instantiate-binder, r=lcnrMatthias Krüger-44/+36
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-27Rollup merge of #130826 - fmease:compiler-mv-obj-safe-dyn-compat, ↵Matthias Krüger-35/+35
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-27Rollup merge of #130718 - jackh726:known-bug-cleanup, r=compiler-errorsMatthias Krüger-3/+8
Cleanup some known-bug issues I went through most of the known-bug tests (except those under `tests/crashes`) and made sure the issue had the `S-bug-has-test` label and checked that the linked issue was open. This is a bunch of cleanups, mainly issues that have been closed and the tests should have been updated. Importantly, there are many known-bug tests linking to #110395. This *probably* isn't right - that is a tracking issue. But I don't really know what the "right" thing to do here. Probably, most that are actually *supposed* to be tests for const trait need to be linked to *that* tracking issue. And any other tests that were mislabeled need to be handled accordingly e.g. #130482. cc `@fee1-dead`
2024-09-27Cleanup some known-bug issuesJack Huey-3/+8
2024-09-26Rollup merge of #130912 - estebank:point-at-arg-type, r=compiler-errorsJubilee-10/+10
On implicit `Sized` bound on fn argument, point at type instead of pattern Instead of ``` error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time --> $DIR/issue-59324.rs:23:20 | LL | fn with_factory<H>(factory: dyn ThriftService<()>) {} | ^^^^^^^ doesn't have a size known at compile-time ``` output ``` error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time --> $DIR/issue-59324.rs:23:29 | LL | fn with_factory<H>(factory: dyn ThriftService<()>) {} | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time ```
2024-09-26Check allow instantiating object trait binder when upcasting and in new solverMichael Goulet-44/+36
2024-09-26diagnostics: wrap fn cast suggestions in parensMichael Howell-6/+90
Fixes #121632
2024-09-27On implicit `Sized` bound on fn argument, point at type instead of patternEsteban Küber-10/+10
Instead of ``` error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time --> $DIR/issue-59324.rs:23:20 | LL | fn with_factory<H>(factory: dyn ThriftService<()>) {} | ^^^^^^^ doesn't have a size known at compile-time ``` output ``` error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time --> $DIR/issue-59324.rs:23:29 | LL | fn with_factory<H>(factory: dyn ThriftService<()>) {} | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time ```
2024-09-25Compiler: Rename "object safe" to "dyn compatible"León Orell Valerian Liehr-35/+35
2024-09-24Rollup merge of #130764 - compiler-errors:inherent, r=estebankTrevor Gross-0/+25
Separate collection of crate-local inherent impls from error tracking #119895 changed the return type of the `crate_inherent_impls` query from `CrateInherentImpls` to `Result<CrateInherentImpls, ErrorGuaranteed>` to avoid needing to use the non-parallel-friendly `track_errors()` to track if an error was reporting from within the query... This was mostly fine until #121113, which stopped halting compilation when we hit an `Err(ErrorGuaranteed)` in the `crate_inherent_impls` query. Thus we proceed onwards to typeck, and since a return type of `Result<CrateInherentImpls, ErrorGuaranteed>` means that the query can *either* return one of "the list inherent impls" or "error has been reported", later on when we want to assemble method or associated item candidates for inherent impls, we were just treating any `Err(ErrorGuaranteed)` return value as if Rust had no inherent impls defined anywhere at all! This leads to basically every inherent method call failing with an error, lol, which was reported in #127798. This PR changes the `crate_inherent_impls` query to return `(CrateInherentImpls, Result<(), ErrorGuaranteed>)`, i.e. returning the inherent impls collected *and* whether an error was reported in the query itself. It firewalls the latter part of that query into a new `crate_inherent_impls_validity_check` just for the `ensure()` call. This fixes #127798.
2024-09-24improve errors for invalid pointer castsLukas Markeffsky-7/+5
2024-09-24replace "cast" with "coercion" where applicableLukas Markeffsky-2/+2
This changes the remaining span for the cast, because the new `Cast` category has a higher priority (lower `Ord`) than the old `Coercion` category, so we no longer report the region error for the "unsizing" coercion from `*const Trait` to itself.
2024-09-24use more accurate spans for user type ascriptionsLukas Markeffsky-8/+8
2024-09-24Separate collection of crate-local inherent impls from error reportingMichael Goulet-0/+25
2024-09-22Don't call const normalize in error reportingMichael Goulet-3/+3
2024-09-20Auto merge of #130631 - GuillaumeGomez:rollup-jpgy1iv, r=GuillaumeGomezbors-1/+16
Rollup of 7 pull requests Successful merges: - #128209 (Remove macOS 10.10 dynamic linker bug workaround) - #130526 (Begin experimental support for pin reborrowing) - #130611 (Address diagnostics regression for `const_char_encode_utf8`.) - #130614 (Add arm64e-apple-tvos target) - #130617 (bail if there are too many non-region infer vars in the query response) - #130619 (Fix scraped examples height) - #130624 (Add `Vec::as_non_null`) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-20Rollup merge of #130617 - lcnr:nalgebra-hang-3, r=compiler-errorsGuillaume Gomez-1/+16
bail if there are too many non-region infer vars in the query response A minimal fix for the hang in nalgebra. If the query response would result in too many distinct non-region inference variables, simply overwrite the result with overflow. This should either happen if the result already has too many distinct type inference variables, or if evaluating the query encountered a lot of ambiguous associated types. In both cases it's straightforward to wait until the aliases are no longer ambiguous and then try again. r? `@compiler-errors`
2024-09-20Auto merge of #124895 - obeis:static-mut-hidden-ref, r=compiler-errorsbors-1/+4
Disallow hidden references to mutable static Closes #123060 Tracking: - https://github.com/rust-lang/rust/issues/123758
2024-09-20update testslcnr-1/+14
2024-09-20bail if there are too many non-region infer varslcnr-0/+2
2024-09-20Rollup merge of #129542 - zachs18:cow-self-test, r=compiler-errorsGuillaume Gomez-0/+14
Add regression test for #129541 (maybe?) closes #129541 by adding a test that the code in question continues to compile.
2024-09-13Update tests for hidden references to mutable staticObei Sideg-1/+4
2024-09-12Rollup merge of #130276 - compiler-errors:nalgebra-hang, r=lcnrMatthias Krüger-0/+23
Add test for nalgebra hang in coherence r? lcnr
2024-09-12Rollup merge of #130273 - lcnr:overflow-no-constraints, r=compiler-errorsMatthias Krüger-0/+2
more eagerly discard constraints on overflow We always discard the results of overflowing goals inside of the trait solver. We previously did so when instantiating the response in `evaluate_goal`. Canonicalizing results only to later discard them is also inefficient :shrug: It's simpler and nicer to debug to eagerly discard constraints inside of the query itself. r? ``@compiler-errors``
2024-09-12Add test for nalgebra hang in coherenceMichael Goulet-0/+23
2024-09-12more eagerly discard constraints on overflowlcnr-0/+2
2024-09-12Auto merge of #130249 - compiler-errors:sad-new-solver-coherence, r=lcnrbors-24/+35
Revert "Stabilize `-Znext-solver=coherence`" This is a clean revert of #121848, prepared by running: ``` $ git revert 17b322fa69eed7216dccc9f097eb68237cf62234 -m1 ``` Which effectively reverts: * a138a9261536ac2bdbb7c01a8aa9dc7d43299cae, 69fdd1457d367ce4de044e9784e58a38acf3d847, d93e047c9f1b33892a604273ab3931815f5604a1, 1a893ac648e03732aaa8b5371b602ab683970b0d see: https://rust-lang.zulipchat.com/#narrow/stream/364551-t-types.2Ftrait-system-refactor/topic/nalgebra.20hang Closes #130056 r? lcnr
2024-09-11Revert 'Stabilize -Znext-solver=coherence'Michael Goulet-24/+35
2024-09-11Rollup merge of #130123 - FedericoBruzzone:master, r=compiler-errorsMatthias Krüger-0/+51
Report the `note` when specified in `diagnostic::on_unimplemented` Before this PR the `note` field was completely ignored for some reason, now it is shown (I think) correctly during the hir typechecking phase. 1. Report the `note` when specified in `diagnostic::on_unimplemented` 2. Added a test for unimplemented trait diagnostic 3. Added a test for custom unimplemented trait diagnostic Close #130084 P.S. This is my first PR to rustc.
2024-09-11Regression test for #129541Zachary S-0/+14
2024-09-10Report the `note` when specified in `diagnostic::on_unimplemented`FedericoBruzzone-0/+51
Signed-off-by: FedericoBruzzone <federico.bruzzone.i@gmail.com>
2024-09-09compiler: Inform the solver of concurrencyJubilee Young-0/+51
Parallel compilation of a program can cause unexpected event sequencing. Inform the solver when this is true so it can skip invalid asserts, then assert replaced solutions are equal if Some
2024-09-05stabilize `-Znext-solver=coherence`lcnr-35/+24
2024-08-22Pretty-print own args of existential projectionsLeón Orell Valerian Liehr-15/+42
2024-08-13Use the right type when coercing fn items to pointersMichael Goulet-1/+8
2024-08-03Revert "Rollup merge of #125572 - mu001999-contrib:dead/enhance, r=pnkfelix"Michael Goulet-1/+0
This reverts commit 13314df21b0bb0cdd02c6760581d1b9f1052fa7e, reversing changes made to 6e534c73c35f569492ed5fb5f349075d58ed8b7e.
2024-07-30Rollup merge of #128357 - compiler-errors:shadowed-non-lifetime-binder, ↵Matthias Krüger-0/+62
r=petrochenkov Detect non-lifetime binder params shadowing item params We should check that `for<T>` shadows `T` from an item in the same way that `for<'a>` shadows `'a` from an item. r? ``@petrochenkov`` since you're familiar w the nuances of rib kinds
2024-07-29Detect non-lifetime binder params shadowing item paramsMichael Goulet-0/+62
2024-07-29Rollup merge of #128174 - compiler-errors:trait-alias-marker, r=oli-obkMatthias Krüger-0/+18
Don't record trait aliases as marker traits Don't record `#[marker]` on trait aliases, since we use that to check for the (non-presence of) associated types and other things which don't make sense of trait aliases. We already enforce this attr is only applied to a trait. Also do the same for `#[const_trait]`, which we also enforce is only applied to a trait. This is a drive-by change, but also worthwhile just in case. Fixes #127222
2024-07-26Auto merge of #121676 - Bryanskiy:polarity, r=petrochenkovbors-7/+104
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-26Forbid `?Trait` bounds repetitionsBryanskiy-0/+30
2024-07-25Auto merge of #127042 - GrigorenkoPV:derivative, r=compiler-errorsbors-4/+4
Switch from `derivative` to `derive-where` This is a part of the effort to get rid of `syn 1.*` in compiler's dependencies: #109302 Derivative has not been maintained in nearly 3 years[^1]. It also depends on `syn 1.*`. This PR replaces `derivative` with `derive-where`[^2], a not dead alternative, which uses `syn 2.*`. A couple of `Debug` formats have changed around the skipped fields[^3], but I doubt this is an issue. [^1]: https://github.com/mcarton/rust-derivative/issues/117 [^2]: https://lib.rs/crates/derive-where [^3]: See the changes in `tests/ui`
2024-07-25Support ?Trait bounds in supertraits and dyn Trait under a feature gateBryanskiy-7/+74