Skip to content

Normalization fails with where clauses on methods #31760

Open
@nikomatsakis

Description

@nikomatsakis

This code from @jroesch fails to compile:

pub enum Mut {}
pub enum Imm {}

trait MutType<'v, T> {
    type Output;
}

impl<'v, T: 'v> MutType<'v, T> for Mut {
    type Output = &'v mut T;
}

impl<'v, T: 'v> MutType<'v, T> for Imm {
    type Output = &'v T;
}


enum Lit {
    Int(i32)
}

enum Expr {
    Add(Box<Expr>, Box<Expr>),
    Lit(Lit),
}


pub trait Visitor<'v, M> : Sized {
    fn visit_expr(&mut self, expr: M::Output)
    where M : MutType<'v, Expr>;

    fn visit_lit(&mut self, lit: M::Output)
    where M : MutType<'v, Lit>;
}

struct DummyV;

impl<'v> Visitor<'v, Imm> for DummyV {
    fn visit_expr(&mut self, expr: &'v Expr) {
        panic!()
    }

    fn visit_lit(&mut self, lit: &'v Lit) {
        panic!()
    }
}

fn main() {}

with the following error:

<anon>:38:5: 40:6 error: method `visit_expr` has an incompatible type for trait:
 expected associated type,
    found &-ptr [E0053]
<anon>:38     fn visit_expr(&mut self, expr: &'v Expr) {
<anon>:39         panic!()
<anon>:40     }
<anon>:38:5: 40:6 help: see the detailed explanation for E0053
<anon>:42:5: 44:6 error: method `visit_lit` has an incompatible type for trait:
 expected associated type,
    found &-ptr [E0053]
<anon>:42     fn visit_lit(&mut self, lit: &'v Lit) {
<anon>:43         panic!()
<anon>:44     }
<anon>:42:5: 44:6 help: see the detailed explanation for E0053
error: aborting due to 2 previous errors
playpen: application terminated with error code 101

Compilation failed.

but, I think, ought to work. Looks like a problem where we normalize without having all the where clauses from the method available. Lazy normalization would probably fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)A-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions