Explain each variant of TAIT usage with examples
This commit is contained in:
parent
6109d73112
commit
c2683aa569
1 changed files with 44 additions and 1 deletions
|
@ -88,16 +88,59 @@ pub(super) fn check_fn<'a, 'tcx>(
|
||||||
let declared_ret_ty = fn_sig.output();
|
let declared_ret_ty = fn_sig.output();
|
||||||
|
|
||||||
let feature = match tcx.hir().get(fn_id) {
|
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(..), .. }) |
|
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 {
|
Node::ImplItem(hir::ImplItem {
|
||||||
kind: hir::ImplItemKind::Fn(..), ..
|
kind: hir::ImplItemKind::Fn(..), ..
|
||||||
}) => None,
|
}) => 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 {
|
Node::TraitItem(hir::TraitItem {
|
||||||
kind: hir::TraitItemKind::Fn(..),
|
kind: hir::TraitItemKind::Fn(..),
|
||||||
..
|
..
|
||||||
}) |
|
}) |
|
||||||
// Forbid TAIT in closure return position for now.
|
// 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::Expr(hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => Some(sym::type_alias_impl_trait),
|
||||||
node => bug!("Item being checked wasn't a function/closure: {:?}", node),
|
node => bug!("Item being checked wasn't a function/closure: {:?}", node),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue