forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#113690 - aliemjay:opaque-defined-by-trait, r=…
…compiler-errors allow opaques to be defined by trait queries, again This basically reverts rust-lang#112963. Moreover, all call-sites of `enter_canonical_trait_query` can now define opaque types, see the ui test `defined-by-user-annotation.rs`. Fixes rust-lang#113689 r? `@compiler-errors` `@oli-obk`
- Loading branch information
Showing
3 changed files
with
37 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//! The trait query `foo: Fn() -> u8` is a valid defining use of RPIT. | ||
|
||
// build-pass | ||
|
||
fn returns_u8(_: impl Fn() -> u8) {} | ||
|
||
pub fn foo() -> impl Sized { | ||
returns_u8(foo); | ||
0u8 | ||
} | ||
|
||
fn main() {} |
19 changes: 19 additions & 0 deletions
19
tests/ui/type-alias-impl-trait/defined-by-user-annotation.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// User type annotation in fn bodies is a a valid defining site for opaque types. | ||
// check-pass | ||
#![feature(type_alias_impl_trait)] | ||
|
||
trait Equate { type Proj; } | ||
impl<T> Equate for T { type Proj = T; } | ||
|
||
trait Indirect { type Ty; } | ||
impl<A, B: Equate<Proj = A>> Indirect for (A, B) { type Ty = (); } | ||
|
||
type Opq = impl Sized; | ||
fn define_1(_: Opq) { | ||
let _ = None::<<(Opq, u8) as Indirect>::Ty>; | ||
} | ||
fn define_2() -> Opq { | ||
0u8 | ||
} | ||
|
||
fn main() {} |