Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trait-based structural match implementation #65519

Merged

Commits on Oct 25, 2019

  1. fix typo in test.

    pnkfelix committed Oct 25, 2019
    Configuration menu
    Copy the full SHA
    c2b4c43 View commit details
    Browse the repository at this point in the history
  2. fix typo in filename.

    pnkfelix committed Oct 25, 2019
    Configuration menu
    Copy the full SHA
    f0e370f View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    4f7b922 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    620083a View commit details
    Browse the repository at this point in the history
  5. Migrate from #[structural_match] attribute a lang-item trait.

    (Or more precisely, a pair of such traits: one for `derive(PartialEq)` and one
    for `derive(Eq)`.)
    
    ((The addition of the second marker trait, `StructuralEq`, is largely a hack to
    work-around `fn (&T)` not implementing `PartialEq` and `Eq`; see also issue
    rust-lang#46989; otherwise I would just check if `Eq` is implemented.))
    
    Note: this does not use trait fulfillment error-reporting machinery; it just
    uses the trait system to determine if the ADT was tagged or not. (Nonetheless, I
    have kept an `on_unimplemented` message on the new trait for structural_match
    check, even though it is currently not used.)
    
    Note also: this does *not* resolve the ICE from rust-lang#65466, as noted
    in a comment added in this commit. Further work is necessary to resolve that and
    other problems with the structural match checking, especially to do so without
    breaking stable code (adapted from test fn-ptr-is-structurally-matchable.rs):
    
    ```rust
    fn r_sm_to(_: &SM) {}
    
    fn main() {
        const CFN6: Wrap<fn(&SM)> = Wrap(r_sm_to);
        let input: Wrap<fn(&SM)> = Wrap(r_sm_to);
        match Wrap(input) {
            Wrap(CFN6) => {}
            Wrap(_) => {}
        };
    }
    ```
    
    where we would hit a problem with the strategy of unconditionally checking for
    `PartialEq` because the type `for <'a> fn(&'a SM)` does not currently even
    *implement* `PartialEq`.
    
    ----
    
    added review feedback:
    * use an or-pattern
    * eschew `return` when tail position will do.
    * don't need fresh_expansion; just add `structural_match` to appropriate `allow_internal_unstable` attributes.
    
    also fixed example in doc comment so that it actually compiles.
    pnkfelix committed Oct 25, 2019
    Configuration menu
    Copy the full SHA
    98f5b11 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    86f7d6f View commit details
    Browse the repository at this point in the history
  7. Update test output.

    (My inference is that the number changed from 4 to 5 because `derive(PartialEq)` now injects an extra trait impl before.)
    pnkfelix committed Oct 25, 2019
    Configuration menu
    Copy the full SHA
    f645e90 View commit details
    Browse the repository at this point in the history