Skip to content

surprising behaviour when relating opaque types in winnowing #117310

Closed
@aliemjay

Description

@aliemjay

The statements of test has an arguably inconsistent behvaiour here:

#![feature(type_alias_impl_trait)]
use std::ops::Deref;

trait Trait {}
impl<A, B> Trait for (A, B, u8) where A: Deref, B: Deref<Target = A::Target>, {}
impl<A, B> Trait for (A, B, i8) {}

type TaitSized = impl Sized;
fn def_tait1() -> TaitSized {}

type TaitCopy = impl Copy;
fn def_tait2() -> TaitCopy {}

fn impl_trait<T: Trait> () {}

fn test() {
    impl_trait::<(&TaitSized, &TaitCopy, _)>(); // Pass
    impl_trait::<(&TaitCopy, &TaitSized, _)>(); //~ ERROR type annotation needed

    impl_trait::<(&TaitCopy, &String, _)>(); // Pass
    impl_trait::<(&TaitSized, &String, _)>(); //~ ERROR type annotation needed
}

Additionally, all the statements pass when TAIT's are put in a different module:

#![feature(type_alias_impl_trait)]
use std::ops::Deref;

trait Trait {}
impl<A, B> Trait for (A, B, u8) where A: Deref, B: Deref<Target = A::Target>, {}
impl<A, B> Trait for (A, B, i8) {}

mod taits {
    pub type TaitSized = impl Sized;
    fn def_tait1() -> TaitSized {}
    
    pub type TaitCopy = impl Copy;
    fn def_tait2() -> TaitCopy {}
}
    
fn impl_trait<T: Trait> () {}

fn test() {
    use taits::*;

    impl_trait::<(&TaitSized, &TaitCopy, _)>(); // Pass
    impl_trait::<(&TaitCopy, &TaitSized, _)>(); // Pass

    impl_trait::<(&TaitCopy, &String, _)>(); // Pass
    impl_trait::<(&TaitSized, &String, _)>(); // Pass
}

rustc version: 1.75.0-nightly (2023-10-21 1c05d50)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions