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

Stabilize slice::strip_prefix and slice::strip_suffix #77853

Merged
merged 5 commits into from
Jan 7, 2021

Commits on Dec 27, 2020

  1. Stablize slice::strip_prefix and strip_suffix, with SlicePattern

    We hope later to extend `core::str::Pattern` to slices too, perhaps as
    part of stabilising that.  We want to minimise the amount of type
    inference breakage when we do that, so we don't want to stabilise
    strip_prefix and strip_suffix taking a simple `&[T]`.
    
    @KodrAus suggested the approach of introducing a new perma-unstable
    trait, which reduces this future inference break risk.
    
    I found it necessary to make two impls of this trait, as the unsize
    coercion don't apply when hunting for trait implementations.
    
    Since SlicePattern's only method returns a reference, and the whole
    trait is just a wrapper for slices, I made the trait type be the
    non-reference type [T] or [T;N] rather than the reference.  Otherwise
    the trait would have a lifetime parameter.
    
    I marked both the no-op conversion functions `#[inline]`.  I'm not
    sure if that is necessary but it seemed at the very least harmless.
    
    Signed-off-by: Ian Jackson <[email protected]>
    ijackson committed Dec 27, 2020
    Configuration menu
    Copy the full SHA
    274e299 View commit details
    Browse the repository at this point in the history
  2. Use existing slice_pattern feature for SlicePattern

    Co-authored-by: Ashley Mannix <[email protected]>
    ijackson and KodrAus committed Dec 27, 2020
    Configuration menu
    Copy the full SHA
    f51b681 View commit details
    Browse the repository at this point in the history
  3. Drop pointless as_slice call.

    Co-authored-by: David Tolnay <[email protected]>
    ijackson and dtolnay committed Dec 27, 2020
    Configuration menu
    Copy the full SHA
    beb293d View commit details
    Browse the repository at this point in the history
  4. Mark SlicePattern trait uses as ?Sized

    This trait is ?Sized and is often slices.
    
    Signed-off-by: Ian Jackson <[email protected]>
    ijackson committed Dec 27, 2020
    Configuration menu
    Copy the full SHA
    03b4ea4 View commit details
    Browse the repository at this point in the history
  5. Add test for slice as prefix/suffix pattern

    Signed-off-by: Ian Jackson <[email protected]>
    ijackson committed Dec 27, 2020
    Configuration menu
    Copy the full SHA
    8b2e79d View commit details
    Browse the repository at this point in the history