Repository: rust
Issue: Inconsistent failure in byte slice &[u8] comparison caused by unrelated code
Labels: A-type-system,T-compiler,A-inference,C-bug,A-slice,T-types

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code:

```toml
[package]
name = "rbup"
version = "0.1.0"
authors = ["Aidan Hobson Sayers <aidanhs@cantab.net>"]
edition = "2018"

[dependencies]
assert_fs = "1.0"
```

```rust
use std::os::unix::ffi::OsStrExt;
use std::path::PathBuf;

fn main() {}

pub fn foo() {
    //let temp = assert_fs::TempDir::new().unwrap(); // XXX
}

pub fn x() {
    let prefix: &[u8] = &[];
    let name: &Vec<u8> = &vec![];
    let _ = prefix > name.as_slice(); // works
    let _ = prefix > name; // broken iff XXX is uncommented
}

pub fn y() {
    let lastfile: &PathBuf = &PathBuf::new();
    let path: PathBuf = PathBuf::new();
    assert!(lastfile.as_os_str().as_bytes() > path.as_os_str().as_bytes()); // works
    assert!(lastfile.as_os_str().as_bytes() > &path.as_os_str().as_bytes()); // broken iff XXX is uncommented
}
```

I expected to see this happen: the code either consistently compiles or fails to compile.

Instead, this happened: depending on whether the line marked `XXX` is commented or not, the unrelated lines marked `broken` cause compilation failures (in turn, commenting those out allows compilation to succeed). i.e. `broken` and `XXX` lines are mutually exclusive.

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.48.0-nightly (623fb90b5 2020-09-26)
binary: rustc
commit-hash: 623fb90b5a1f324e0ec44085116bf858cef19a00
commit-date: 2020-09-26
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
+ cargo --color=always build --release
   Compiling rbup v0.1.0 (/tmp/x)
error[E0277]: can't compare `[u8]` with `Vec<u8>`
  --> src/main.rs:14:20
   |
14 |     let _ = prefix > name; // broken iff XXX is uncommented
   |                    ^ no implementation for `[u8] < Vec<u8>` and `[u8] > Vec<u8>`
   |
   = help: the trait `PartialOrd<Vec<u8>>` is not implemented for `[u8]`
   = note: required because of the requirements on the impl of `PartialOrd<&Vec<u8>>` for `&[u8]`

error[E0277]: can't compare `[u8]` with `&[u8]`
  --> src/main.rs:21:45
   |
21 |     assert!(lastfile.as_os_str().as_bytes() > &path.as_os_str().as_bytes()); // broken iff XXX is uncommented
   |                                             ^ no implementation for `[u8] < &[u8]` and `[u8] > &[u8]`
   |
   = help: the trait `PartialOrd<&[u8]>` is not implemented for `[u8]`
   = note: required because of the requirements on the impl of `PartialOrd<&&[u8]>` for `&[u8]`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
error: could not compile `rbup`

To learn more, run the command again with --verbose.
```

</p>
</details>