Skip to content

bounds on trait impls are used in implied bounds  #109628

Description

@aliemjay

The following compiles although it shouldn't:

trait Trait {
    type Assoc;
}

impl<T: 'static> Trait for Box<T> {
    type Assoc = ();
}

struct MyTy<U>(U)
where
    U: Trait,
    U::Assoc: Sized, // any predicate naming U::Assoc
;

fn fn_test<T>(_: MyTy<Box<T>>) {}

fn_test should fail with an error requiring an explicit T: 'static bound.

This is a compiler bug for the following reasons:

  • It certainly does not follow from the rules of RFC 1214 and RFC 2089. The implied bounds from a trait reference (Box<T>: Trait) includes only the where-clauses of the trait itself, not the trait impl.
  • It breaks stability guarantees in the sense that relaxing region constraints on trait impls is now a breaking change. Removing the useless bound U::Assoc: Sized is also a breaking change.
  • It requires remote reasoning when dealing with implied bounds.
  • It is a surprising behavior: why does the trivial bound U::Assoc: Sized make any meaningful difference?

Activity

  1. added
    C-bugCategory: This is a bug.
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    A-implied-boundsArea: Implied bounds / inferred outlives-bounds
    on Mar 26, 2023
  2. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 5, 2023
  3. added a commit that references this issue on Nov 17, 2023
  4. jackh726 commented on Nov 29, 2023

    @jackh726
    Member

    Just for reference: This is a stable-to-stable regression, first passing in 1.29.0.

    🤷‍♀️ on adding the label

  5. added a commit that references this issue on Jan 18, 2024
    a34faab
  6. lcnr commented on Jan 19, 2024

    @lcnr
    Contributor

    this still applies to bevy and during MIR typeck due to #119956, reopening.

  7. reopened this on Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-implied-boundsArea: Implied bounds / inferred outlives-boundsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types 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