Skip to content

rustc doesn't check nested WFness if it's in a higher-ranked predicate #162200

Open

Description

@compiler-errors

#122501 (comment)

This will probably end up complicating implied bounds computation in binders?

Activity

  1. compiler-errors commented on Apr 8, 2024

    @compiler-errors
    ContributorAuthor

    Minimal I think:

    trait Bound {}
    
    struct W<'a, T: Bound>(&'a T);
    
    fn wf<T>() where for<'a> W<'a, T>: Sized {}

    We should recurse on W<'a, T> and see T: Bound must hold, but we don't even recurse on the self arg of the predicate because the trait has escaping bound vars.

  2. jackh726 commented on Apr 11, 2024

    @jackh726
    Member

    That regression list sucks. I think this is something we should consider slowly moving towards error (or at least deny-by-default) by starting with a warn-by-default lint.

    I'm also curious if there's a good MCVE for things that are so "obvious" as the example above. This modification, for example, is pretty clear what the problem is when trying to call wf:

    use std::fmt::Debug;
    
    trait Bound {}
    
    struct W<'a, T: Bound>(&'a T);
    
    fn wf<T>() where for<'a> W<'a, T>: Debug {}
    
    fn main() {
        wf::<u32>();
    }

    But, I could imagine that we can have move subtle things we don't check in e.g. super trait bounds. These could be good candidates to also move towards erroring quicker.

  3. lcnr commented on Jul 25, 2025

    @lcnr
    Contributor

    For where-clauses this check happens during item wf checking, could we FCW on these missing bounds? I think implying T: Bound here is undesirable and if we start the FCW we'll likely be in a fairly good spot once we actually want to finish the hr-implied bounds work

  4. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 2, 2026
  5. added
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 3, 2026
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-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)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