litble/Multi-Docker-Eval huggingface dataset:
Repository: servo/rust-url (rust)

Issue:
Implement `Hash` for `Origin`
Seems like this could reasonable be used as a key, and `Hash` is a trait we implement eagerly.


Discussion:

Patch:
diff --git a/src/origin.rs b/src/origin.rs
--- a/src/origin.rs
+++ b/src/origin.rs
@@ -50,7 +50,7 @@ pub fn url_origin(url: &Url) -> Origin {
 ///   the URL does not have the same origin as any other URL.
 ///
 /// For more information see https://url.spec.whatwg.org/#origin
-#[derive(PartialEq, Eq, Clone, Debug)]
+#[derive(PartialEq, Eq, Hash, Clone, Debug)]
 pub enum Origin {
     /// A globally unique identifier
     Opaque(OpaqueOrigin),
@@ -123,7 +123,7 @@ impl Origin {
 }
 
 /// Opaque identifier for URLs that have file or other schemes
-#[derive(Eq, PartialEq, Clone, Debug)]
+#[derive(Eq, PartialEq, Hash, Clone, Debug)]
 pub struct OpaqueOrigin(usize);
 
 #[cfg(feature = "heapsize")]


Test patch:
diff --git a/tests/unit.rs b/tests/unit.rs
--- a/tests/unit.rs
+++ b/tests/unit.rs
@@ -372,3 +372,45 @@ fn define_encode_set_scopes() {
 
     m::test();
 }
+
+#[test]
+/// https://github.com/servo/rust-url/issues/302
+fn test_origin_hash() {
+    use std::hash::{Hash,Hasher};
+    use std::collections::hash_map::DefaultHasher;
+
+    fn hash<T: Hash>(value: &T) -> u64 {
+        let mut hasher = DefaultHasher::new();
+        value.hash(&mut hasher);
+        hasher.finish()
+    }
+
+    let origin = &Url::parse("http://example.net/").unwrap().origin();
+
+    let origins_to_compare = [
+        Url::parse("http://example.net:80/").unwrap().origin(),
+        Url::parse("http://example.net:81/").unwrap().origin(),
+        Url::parse("http://example.net").unwrap().origin(),
+        Url::parse("http://example.net/hello").unwrap().origin(),
+        Url::parse("https://example.net").unwrap().origin(),
+        Url::parse("ftp://example.net").unwrap().origin(),
+        Url::parse("file://example.net").unwrap().origin(),
+        Url::parse("http://user@example.net/").unwrap().origin(),
+        Url::parse("http://user:pass@example.net/").unwrap().origin(),
+    ];
+
+    for origin_to_compare in &origins_to_compare {
+        if origin == origin_to_compare {
+            assert_eq!(hash(origin), hash(origin_to_compare));
+        } else {
+            assert_ne!(hash(origin), hash(origin_to_compare));
+        }
+    }
+
+    let opaque_origin = Url::parse("file://example.net").unwrap().origin();
+    let same_opaque_origin = Url::parse("file://example.net").unwrap().origin();
+    let other_opaque_origin = Url::parse("file://other").unwrap().origin();
+
+    assert_ne!(hash(&opaque_origin), hash(&same_opaque_origin));
+    assert_ne!(hash(&opaque_origin), hash(&other_opaque_origin));
+}
Repository: servo/rust-url (rust)

Issue:
Panic 'index out of bounds: the len is 7 but the index is 7'
This program:

``` rust
extern crate url;

use url::Url;

fn main() {
    let mut url = Url::from_file_path("/").unwrap();
    url.path_segments_mut().unwrap().pop_if_empty();
}
```

will panic with:

```
thread '<main>' panicked at 'index out of bounds: the len is 7 but the index is 7', src/lib.rs:1095
note: Run with `RUST_BACKTRACE=1` for a backtrace.
```

Oddly enough the "equivalent" program of `Url::parse("file://")` works just fine!



Discussion:

Patch:
diff --git a/Cargo.toml b/Cargo.toml
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 
 name = "url"
-version = "1.1.0"
+version = "1.1.1"
 authors = ["The rust-url developers"]
 
 description = "URL library for Rust, based on the WHATWG URL Standard"
diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1243,11 +1243,17 @@ fn path_to_file_url_segments(path: &Path, serialization: &mut String) -> Result<
     if !path.is_absolute() {
         return Err(())
     }
+    let mut empty = true;
     // skip the root component
     for component in path.components().skip(1) {
+        empty = false;
         serialization.push('/');
         serialization.extend(percent_encode(
-            component.as_os_str().as_bytes(), PATH_SEGMENT_ENCODE_SET))
+            component.as_os_str().as_bytes(), PATH_SEGMENT_ENCODE_SET));
+    }
+    if empty {
+        // An URL’s path must not be empty.
+        serialization.push('/');
     }
     Ok(())
 }


Test patch:
diff --git a/tests/unit.rs b/tests/unit.rs
--- a/tests/unit.rs
+++ b/tests/unit.rs
@@ -259,3 +259,12 @@ fn issue_61() {
     assert_eq!(url.port_or_known_default(), Some(443));
     url.assert_invariants();
 }
+
+#[test]
+/// https://github.com/servo/rust-url/issues/197
+fn issue_197() {
+    let mut url = Url::from_file_path("/").unwrap();
+    url.assert_invariants();
+    assert_eq!(url, Url::parse("file:///").unwrap());
+    url.path_segments_mut().unwrap().pop_if_empty();
+}
Repository: servo/rust-url (rust)

Issue:
Implement `Display` for `Host` and `HostAndPort`
Probably using the obvious serialization for "host:port". Looks like `HostAndPort` impl needs to be parameterized over `S: Display`.


Discussion:
For IPv6 addresses, using `[]` brackets is necessary to distinguish `:` within an address and `:` separating an address and port number. `Display for Host` already does this.

Patch:
diff --git a/src/host.rs b/src/host.rs
--- a/src/host.rs
+++ b/src/host.rs
@@ -192,6 +192,15 @@ impl<'a> HostAndPort<&'a str> {
     }
 }
 
+impl<S: AsRef<str>> fmt::Display for HostAndPort<S> {
+    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+        self.host.fmt(f)?;
+        f.write_str(":")?;
+        self.port.fmt(f)
+    }
+}
+
+
 impl<S: AsRef<str>> ToSocketAddrs for HostAndPort<S> {
     type Iter = SocketAddrs;
 


Test patch:
diff --git a/tests/unit.rs b/tests/unit.rs
--- a/tests/unit.rs
+++ b/tests/unit.rs
@@ -13,7 +13,7 @@ extern crate url;
 use std::borrow::Cow;
 use std::net::{Ipv4Addr, Ipv6Addr};
 use std::path::{Path, PathBuf};
-use url::{Host, Url, form_urlencoded};
+use url::{Host, HostAndPort, Url, form_urlencoded};
 
 #[test]
 fn size() {
@@ -254,6 +254,36 @@ fn test_form_serialize() {
     assert_eq!(encoded, "foo=%C3%A9%26&bar=&foo=%23");
 }
 
+#[test]
+fn host_and_port_display() {
+    assert_eq!(
+        format!(
+            "{}",
+            HostAndPort{ host: Host::Domain("www.mozilla.org"), port: 80}
+        ),
+        "www.mozilla.org:80"
+    );
+    assert_eq!(
+        format!(
+            "{}",
+            HostAndPort::<String>{ host: Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)), port: 65535 }
+        ),
+        "1.35.33.49:65535"
+    );
+    assert_eq!(
+        format!(
+            "{}",
+            HostAndPort::<String>{
+                host: Host::Ipv6(Ipv6Addr::new(
+                    0x2001, 0x0db8, 0x85a3, 0x08d3, 0x1319, 0x8a2e, 0x0370, 0x7344
+                )),
+                port: 1337
+            })
+        ,
+        "[2001:db8:85a3:8d3:1319:8a2e:370:7344]:1337"
+    )
+}
+
 #[test]
 /// https://github.com/servo/rust-url/issues/25
 fn issue_25() {