rust-lang / trait-system-refactor-initiative

The Rustc Trait System Refactor Initiative
21 stars 0 forks source link

astconv/typeck unnecessarily instantiates type variables in non-root universe #79

Open compiler-errors opened 10 months ago

compiler-errors commented 10 months ago

When instantiating substs for ADTs, confirming methods, etc., we create new type variables in the current universe, rather than the root universe, even though these variables could be in the root universe since they represent the "surface" types of a Rust program.

This causes us to unnecessarily generalize aliases, leading to ambiguity.


TODO: minimize this test case:

use syn::Ident;
use syn::Attribute;
use syn::parse::*;

struct TypeParam {
    pub attrs: Vec<Attribute>,
    pub ident: Ident,
}

impl Parse for TypeParam {
    fn parse(input: ParseStream) -> Result<Self> {
        let attrs = input.call(Attribute::parse_outer)?;
        let ident = input.parse()?;

        Ok(TypeParam {
            attrs,
            ident,
        })
    }
}

which results in:

error[E0284]: type annotations needed: cannot satisfy `<std::result::Result<syn::Ident, syn::Error> as std::ops::Try>::Residual == <std::result::Result<_, syn::Error> as std::ops::Try>::Residual`
  --> src/lib.rs:13:34
   |
13 |         let ident = input.parse()?;
   |                                  ^ cannot satisfy `<std::result::Result<syn::Ident, syn::Error> as std::ops::Try>::Residual == <std::result::Result<_, syn::Error> as std::ops::Try>::Residual`
compiler-errors commented 7 months ago

(for the record this is fixed, but could use a minimized test, which i'm too lazy to make personally)