Skip to content

implied bounds from impl header are not used in associated functions/consts #98852

Closed

Description

@aliemjay

The following fails to compile although it shouldn't: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f7287b6897a385360f7190001b58348d

/// A type with an implied bound `'b: 'a`
struct Ty<'a, 'b>(&'a &'b ());

impl<'a, 'b> Ty<'a, 'b> // <- tait or inherent impl
where
    //'b: 'a, // <- fixed by an explicit bound
{
    fn f() { // <- no `Self` in signature
        Self;
        //~^ ERROR lifetime bound not satisfied
        // Cannot prove WF of `Self` because `'b: 'a` is not known to hold
    }
}

Another repro:

struct Ty<'a, 'b>(&'a &'b ());

impl<'a, 'b> Ty<'a, 'b>{
    fn f() {
        None::<&'a &'b ()>;
        //~^ ERROR lifetime bound not satisfied
    }
}

The first repro regressed in 1.43 while the second one is as old as implied bounds.

@rustbot label A-implied-bounds A-associated-items regression-from-stable-to-stable T-types

Meta

Nightly version: 1.64.0-nightly

(2022-07-01 46b8c23)

Backtrace

<backtrace>

Activity

  1. added
    A-associated-itemsArea: Associated items (types, constants & functions)
    A-implied-boundsArea: Implied bounds / inferred outlives-bounds
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jul 3, 2022
  2. apiraino commented on Jul 4, 2022

    @apiraino
    Contributor

    WG-prioritization assigning priority (Zulip discussion).

    @rustbot label -I-prioritize +P-medium

  3. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jul 4, 2022
  4. added 2 commits that reference this issue on Nov 8, 2023
    6c5ba88
    a7ce432
  5. aliemjay commented on Nov 13, 2023

    @aliemjay
    ContributorAuthor

    The same issue exists for associated consts:

    /// A type with an implied bound `'b: 'a`
    struct Ty<'a, 'b>(&'a &'b ());
    
    impl<'a, 'b> Ty<'a, 'b> {
        const CONST_1: () = ();
        const CONST_2: () = {
            Self::CONST_1
            //~^ ERROR lifetime may not live long enough
        };
    }
  6. changed the title [-]implied bounds from impl header are not used in associated functions[/-] [+]implied bounds from impl header are not used in associated functions/consts[/+] on Nov 13, 2023
  7. added a commit that references this issue on Nov 20, 2023
    66ac3f1
  8. added a commit that references this issue on Jan 17, 2024
    6bf600b
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-associated-itemsArea: Associated items (types, constants & functions)A-implied-boundsArea: Implied bounds / inferred outlives-boundsC-bugCategory: This is a bug.P-mediumMedium priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions