From 02503029b83a295f1a03160472556fea491491f1 Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Tue, 29 May 2018 19:16:49 +0300 Subject: [PATCH 1/3] Implement PartialEq between &str and OsString Allows for example `os_string == "something"` --- src/libstd/ffi/os_str.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 0a3148029d053..1940a1da8a0af 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -417,6 +417,20 @@ impl PartialEq for str { } } +#[stable(feature = "rust1", since = "1.28.0")] +impl<'a> PartialEq<&'a str> for OsString { + fn eq(&self, other: &&'a str) -> bool { + **self == **other + } +} + +#[stable(feature = "rust1", since = "1.28.0")] +impl<'a> PartialEq for &'a str { + fn eq(&self, other: &OsString) -> bool { + **other == **self + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Eq for OsString {} From fdcee4da79a61028bc7d32a74648b913e924545a Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Wed, 30 May 2018 08:26:24 +0300 Subject: [PATCH 2/3] Fix stability attributes --- src/libstd/ffi/os_str.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 1940a1da8a0af..4ada6a77a8eec 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -417,14 +417,14 @@ impl PartialEq for str { } } -#[stable(feature = "rust1", since = "1.28.0")] +#[stable(feature = "os_str_str_ref_eq", since = "1.28.0")] impl<'a> PartialEq<&'a str> for OsString { fn eq(&self, other: &&'a str) -> bool { **self == **other } } -#[stable(feature = "rust1", since = "1.28.0")] +#[stable(feature = "os_str_str_ref_eq", since = "1.28.0")] impl<'a> PartialEq for &'a str { fn eq(&self, other: &OsString) -> bool { **other == **self From fbd3c92a885b02a5397eaf65d36beae8e1ed999c Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Tue, 5 Jun 2018 08:50:06 +0300 Subject: [PATCH 3/3] Add run-pass test --- src/test/run-pass/issue-49854.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/run-pass/issue-49854.rs diff --git a/src/test/run-pass/issue-49854.rs b/src/test/run-pass/issue-49854.rs new file mode 100644 index 0000000000000..5bb80b5e2c6a1 --- /dev/null +++ b/src/test/run-pass/issue-49854.rs @@ -0,0 +1,18 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::ffi::OsString; + +fn main() { + let os_str = OsString::from("Hello Rust!"); + + assert_eq!(os_str, "Hello Rust!"); + assert_eq!("Hello Rust!", os_str); +}