Description
during the stabilization of TAITs (type alias impl trait) in #63063 (comment) a concern was raised: it's not obvious for the compiler (and IDEs), which items' bodies are allowed to register hidden types for TAITs. For RPIT (return position impl trait) it was obvious: the body of the function in whose return type the impl Trait
was in. For TAITs the status quo is point 1 in the list of options below. This may require some interesting module juggling to avoid cycle errors that can occur due to revealing the hidden type to prove Send
or Sync
bounds, and that revealing again looking at the item to look for things registering the hidden type (see example and passing example).
The possible schemes we know about currently are:
- any item that is (recursively) within the parent of the TAIT is allowed to register the hidden type
- any item that follows the rules of 1. and additionally has the TAIT in its signature or
where
bounds is allowed to register the hidden type. this change has a prospective impl at- Require TAITs to appear in the signature of items that register a hidden type #107073
- not much wiggle room for changing things after stabilization, as any change can quickly leed to then-stable code to have cycle errors
- same as 2. but not permitting
where
bounds to register hidden types - any item in the defining scope can register hidden types, but we error out if the TAIT is not mentioned in the signature or
where
bounds- Require TAITs to appear in the signature of items that register a hidden type #107809
- similar to 2., but since we still look at all functions in the defining scope, there's no change in cycle errors to 1.
- forward compatible with choosing 2. or 1. later
- same as 4. but not permitting
where
bounds to register hidden types- forward compatible with choosing 4. later
Ruled out schemes:
- any item that follows the rules of 1. and has a
#[defines(NameOfTheTypeAlias)]
attribute is allowed to register the hidden type- probably undesirable due to the verbosity in "obvious" cases (like using a TAIT in function return position)
- only allow explicitly registering hidden types with a magic libcore function that syntactically mentions the TAIT by its path. This will still require looking at the body, but we don't need to typecheck the body, just do name resolution on it.
- this option is just listed for completeness, it's the worst option :)
I am nominating this issue for T-lang to discuss which options they prefer.