Skip to content

Commit a59cc32

Browse files
qnighynikomatsakis
authored andcommitted
Add tests for intercrate ambiguity hints.
1 parent bebd622 commit a59cc32

File tree

5 files changed

+89
-1
lines changed

5 files changed

+89
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that we consider `Box<U>: !Sugar` to be ambiguous, even
12+
// though we see no impl of `Sugar` for `Box`. Therefore, an overlap
13+
// error is reported for the following pair of impls (#23516).
14+
15+
pub trait Sugar {}
16+
17+
struct Cake<X>(X);
18+
19+
impl<T:Sugar> Cake<T> { fn dummy(&self) { } }
20+
//~^ ERROR E0592
21+
//~| NOTE duplicate definitions for `dummy`
22+
//~| NOTE upstream crates may add new impl for `Sugar` in future versions
23+
impl<U:Sugar> Cake<Box<U>> { fn dummy(&self) { } }
24+
//~^ NOTE other definition for `dummy`
25+
26+
fn main() { }

src/test/compile-fail/coherence-overlap-issue-23516.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,10 @@
1515
pub trait Sugar { fn dummy(&self) { } }
1616
pub trait Sweet { fn dummy(&self) { } }
1717
impl<T:Sugar> Sweet for T { }
18-
impl<U:Sugar> Sweet for Box<U> { } //~ ERROR E0119
18+
//~^ NOTE first implementation here
19+
impl<U:Sugar> Sweet for Box<U> { }
20+
//~^ ERROR E0119
21+
//~| NOTE conflicting implementation for `std::boxed::Box<_>`
22+
//~| NOTE upstream crates may add new impl for `Sugar` in future versions
23+
1924
fn main() { }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that we consider `i16: Remote` to be ambiguous, even
12+
// though the upstream crate doesn't implement it for now.
13+
14+
// aux-build:coherence_lib.rs
15+
16+
extern crate coherence_lib;
17+
18+
use coherence_lib::Remote;
19+
20+
struct A<X>(X);
21+
impl<T> A<T> where T: Remote { fn dummy(&self) { } }
22+
//~^ ERROR E0592
23+
//~| NOTE duplicate definitions for `dummy`
24+
//~| NOTE upstream crates may add new impl for `coherence_lib::Remote` in future versions
25+
impl A<i16> { fn dummy(&self) { } }
26+
//~^ NOTE other definition for `dummy`
27+
28+
fn main() {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that we consider `i16: Remote` to be ambiguous, even
12+
// though the upstream crate doesn't implement it for now.
13+
14+
// aux-build:coherence_lib.rs
15+
16+
extern crate coherence_lib;
17+
18+
use coherence_lib::Remote;
19+
20+
trait Foo {}
21+
impl<T> Foo for T where T: Remote {}
22+
//~^ NOTE first implementation here
23+
impl Foo for i16 {}
24+
//~^ ERROR E0119
25+
//~| NOTE conflicting implementation for `i16`
26+
//~| NOTE upstream crates may add new impl for `coherence_lib::Remote` in future versions
27+
28+
fn main() {}

src/test/ui/codemap_tests/overlapping_inherent_impls.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ error[E0592]: duplicate definitions with name `baz`
2424
...
2525
43 | fn baz(&self) {}
2626
| ---------------- other definition for `baz`
27+
= note: upstream crates may add new impl for `std::marker::Copy` in future versions
2728

2829
error: aborting due to 3 previous errors
2930

0 commit comments

Comments
 (0)