Skip to content

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

Open
rust-lang/rust
#119106
@compiler-errors

Description

@compiler-errors

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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions