TAIT decision on "may not define may guide inference"
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Nominating for T-lang to decide whether the following rule should hold for the stabilization of TAIT:
The compiler is allowed to rely on whether or not an item is allowed to define the hidden type of an opaque type to guide inference.
If this rule is adopted, then after TAIT is stabilized, it will not be possible in a fully backward compatible way to later change the rules that determine whether or not an item is allowed to define the hidden type in such a way that an item in existing code that uses an opaque type could switch (without any code changes) from being not allowed to define its hidden type to being allowed to define it.
For the purposes of this question, please set aside how we know whether an item is allowed to define the hidden type; this question is invariant to the details of that.
This rule is of particular importance to the new trait solver.
For example, consider:
pub trait Trait {
fn method(&self) {
println!("Trait::method");
}
}
impl<T> Trait for T {}
pub struct X<T>(T);
impl X<()> {
pub fn method(&self) {
println!("X<()>::method");
}
}
pub type Tait = impl Trait;
// Defines the hidden type of `Tait`.
pub fn new() -> X<Tait> {
X(())
}
// Whether or not `foo` may define the hidden type of `Tait` may
// determine how the call to `method` is resolved.
pub fn foo() {
let x = new();
// If `foo` may define the hidden type, this may print:
//
// X<()>::method
//
// Otherwise, it will print:
//
// Trait::method
//
x.method();
}
fn main() {
foo();
}
Please set aside how we know that new is allowed to define the hidden type and how we determine whether or not foo is allowed to do so. There are many ways this could be notated, and the question here is orthogonal to that. In this issue, we're only asking, whatever we decide, is the compiler allowed to rely on this to guide inference?
This rule was described and proposed in the 2023-11-08 T-lang Mini-TAIT design meeting (minutes): rust-lang/lang-team#233.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TAIT question and the 2023-11-08 T-lang Mini-TAIT design meeting minutes in rust-lang/lang-team#233. Review the example involving new, foo, and method resolution; done means recording a T-lang decision on whether hidden-type eligibility may guide inference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100