diff options
| author | Oli Scherer <github35764891676564198441@oli-obk.de> | 2021-03-15 11:02:35 +0000 |
|---|---|---|
| committer | Oli Scherer <github35764891676564198441@oli-obk.de> | 2021-03-15 17:39:18 +0000 |
| commit | c2683aa5694878120bee5dd8cbb361a04e512ebb (patch) | |
| tree | bfc12e8261f4ca7d63ea496c20124896f3e16439 /compiler | |
| parent | 6109d731120b1d326be863434c9de5b6dd674aa4 (diff) | |
| download | rust-c2683aa5694878120bee5dd8cbb361a04e512ebb.tar.gz rust-c2683aa5694878120bee5dd8cbb361a04e512ebb.zip | |
Explain each variant of TAIT usage with examples
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_typeck/src/check/check.rs | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 5e0a0524690..e2fc1da5c78 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -88,16 +88,59 @@ pub(super) fn check_fn<'a, 'tcx>( let declared_ret_ty = fn_sig.output(); let feature = match tcx.hir().get(fn_id) { + // TAIT usage in function return position. + // Example: + // + // ```rust + // type Foo = impl Debug; + // fn bar() -> Foo { 42 } + // ``` Node::Item(hir::Item { kind: ItemKind::Fn(..), .. }) | + // TAIT usage in associated function return position. + // + // Example with a free type alias: + // + // ```rust + // type Foo = impl Debug; + // impl SomeTrait for SomeType { + // fn bar() -> Foo { 42 } + // } + // ``` + // + // Example with an associated TAIT: + // + // ```rust + // impl SomeTrait for SomeType { + // type Foo = impl Debug; + // fn bar() -> Self::Foo { 42 } + // } + // ``` Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) => None, - // I don't know if TAIT uses in trait declarations make sense at all + // Forbid TAIT in trait declarations for now. + // Examples: + // + // ```rust + // type Foo = impl Debug; + // trait Bar { + // fn bar() -> Foo; + // } + // trait Bop { + // type Bop: PartialEq<Foo>; + // } + // ``` Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. }) | // Forbid TAIT in closure return position for now. + // Example: + // + // ```rust + // type Foo = impl Debug; + // let x = |y| -> Foo { 42 + y }; + // ``` Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => Some(sym::type_alias_impl_trait), node => bug!("Item being checked wasn't a function/closure: {:?}", node), }; |
