rust-lang / rust-lang/rust

Path::strip_prefix() improperly strips trailing slash

Open
#148,267 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

use std::path::Path;

let path = Path::new("/foo/bar/baz/");
assert_eq!("/foo/bar/baz/", path.display().to_string());

let stripped_path = path.strip_prefix("/foo").unwrap();
println!("{}", stripped_path.display());

Expected output: bar/baz/ (input with the to-strip part removed)

Actual output: bar/baz (input with the to-strip part and the trailing slash removed)

Playground

This is particularly relevant when/if #142503 lands, which further surfaces that inconsistency: playground

Meta

Reproduces in the stable and nightly builds currently on playground: 1.90.0 and 1.93.0-nightly (2025-10-28 278a90913daf77077910).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the std::path::Path::strip_prefix entry point and reproduce the stable or nightly example from the issue. Compare the returned display with the expected bar/baz/ result, then add coverage for the trailing-slash case so the corrected behavior is verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.