Skip to content

Normalization can skip WF #100041

Description

@CAD97

I tried this code: [playground]

trait WellUnformed {
    type RequestNormalize;
}

impl<T: ?Sized> WellUnformed for T {
    type RequestNormalize = ();
}

const _: <[[[[[[u8]]]]]] as WellUnformed>::RequestNormalize = ();
const _: <Vec<str> as WellUnformed>::RequestNormalize = ();

I expected this to error; [[[[[[u8]]]]]] is clearly not a well-formed type, as

error[E0277]: the size for values of type [u8] cannot be known at compilation time
= help: the trait Sized is not implemented for [u8]
= note: slice and array elements must have Sized type

Vec<str> is perhaps even more cursed.

Instead: it compiles.

This is especially relevant for blanket/builtin traits which have associated types, such as marker::DiscriminantKind and ptr::Pointee.

Meta

1.64.0-nightly (2022-07-31 f9cba63)

@rustbot label +A-associated-items

cc @eddyb who said this was
@rustbot label +I-unsound

Activity

  1. added
    A-associated-itemsArea: Associated items (types, constants & functions)
    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Aug 2, 2022
  2. eddyb commented on Aug 2, 2022

    @eddyb
    Contributor

    cc @rust-lang/types

  3. CAD97 commented on Aug 2, 2022

    @CAD97
    ContributorAuthor

    @rustbot label +T-types

  4. added
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    on Aug 2, 2022
  5. compiler-errors commented on Aug 2, 2022

    @compiler-errors
    Contributor

    I think I found the bug(s). This is:

    1. partly due to Try to normalize associated types before processing obligations #90887, which normalizes WellFormed predicates before we can actually walk through the projection type and register a WF obligation for the projection's self ty,
    2. and partly due to us doing a normalize call before registering a WellFormed predicate in wfcheck code.

    Let me put up a PR.

  6. jackh726 commented on Aug 2, 2022

    @jackh726
    Member

    Is this fixed in #99217?

  7. compiler-errors commented on Aug 2, 2022

    @compiler-errors
    Contributor

    Just checked out that PR, and it's not fixed by #99217.

  8. apiraino commented on Aug 3, 2022

    @apiraino
    Contributor

    WG-prioritization assigning priority (Zulip discussion).

    @rustbot label -I-prioritize +P-high

  9. added
    P-highHigh priority
    and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Aug 3, 2022
  10. 12 remaining items

  11. moved this to blocked on new solver in T-types unsound issueson Nov 15, 2023
  12. added a commit that references this issue on Feb 17, 2024
  13. added a commit that references this issue on Feb 18, 2024
  14. added a commit that references this issue on Feb 18, 2024
  15. lcnr commented on Mar 11, 2024

    @lcnr
    Contributor

    This is currently mostly fixable, except for types in impl headers.

    As stated by @aliemjay in #100046 (comment), we can check unnormalized types for WF if the type is from an item signature.

    We already use their unnormalized type when computing WF in borrowck, so we can first fix #105948 by using the unnormalized types from fn sigs.

    We can then check the wf of function signatures without normalizing them.

  16. added and removed
    P-highHigh priority
    on May 2, 2024
  17. lcnr commented on May 2, 2024

    @lcnr
    Contributor

    lowering this from P-high to P-medium as this cannot directly result in undefined runtime behavior by itself. Fixing this will be straightforward once we've imnplemented the better approach to handling implied bounds on binders, which is still a high priority as it also blocks other issues, such as #25860 and #84591.

  18. added
    fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.
    on Nov 6, 2024
  19. lcnr commented on Feb 25, 2026

    @lcnr
    Contributor

    also the case for types in associated type constraints of opaques which we could in theory fix separately

    trait ToUnit {
        type Assoc;
    }
    impl<T> ToUnit for T {
        type Assoc = ();
    }
    
    // We ever check that the associated type of the opaque
    // is well-formed before normalization
    fn path_ssh_parser() -> impl ToUnit<Assoc = <[str; 2] as ToUnit>::Assoc> {}

    I opened #153082 for that but I actually don't think this warrants a separate issue

  20. removed
    fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.
    on Mar 22, 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-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-typesRelevant to the types team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions