-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve diagnostic of E0119 with extern crate, try to print the conflicting impl. #45455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2017 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use std::marker::PhantomData; | ||
|
||
pub trait External {} | ||
|
||
pub struct M<'a, 'b, 'c, T, U, V> { | ||
a: PhantomData<&'a ()>, | ||
b: PhantomData<&'b ()>, | ||
c: PhantomData<&'c ()>, | ||
d: PhantomData<T>, | ||
e: PhantomData<U>, | ||
f: PhantomData<V>, | ||
} | ||
|
||
impl<'a, 'b, 'c, T, U, V, W> External for (T, M<'a, 'b, 'c, Box<U>, V, W>) | ||
where | ||
'b: 'a, | ||
T: 'a, | ||
U: (FnOnce(T) -> V) + 'static, | ||
V: Iterator<Item=T> + Clone, | ||
W: std::ops::Add, | ||
W::Output: Copy, | ||
{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2017 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Ref: https://github.com/rust-lang/rust/issues/23563#issuecomment-260751672 | ||
|
||
pub trait LolTo<T> { | ||
fn convert_to(&self) -> T; | ||
} | ||
|
||
pub trait LolInto<T>: Sized { | ||
fn convert_into(self) -> T; | ||
} | ||
|
||
pub trait LolFrom<T> { | ||
fn from(T) -> Self; | ||
} | ||
|
||
impl<'a, T: ?Sized, U> LolInto<U> for &'a T where T: LolTo<U> { | ||
fn convert_into(self) -> U { | ||
self.convert_to() | ||
} | ||
} | ||
|
||
impl<T, U> LolFrom<T> for U where T: LolInto<U> { | ||
fn from(t: T) -> U { | ||
t.convert_into() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2017 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// aux-build:complex_impl_support.rs | ||
|
||
extern crate complex_impl_support; | ||
|
||
use complex_impl_support::{External, M}; | ||
|
||
struct Q; | ||
|
||
impl<R> External for (Q, R) {} | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error[E0119]: conflicting implementations of trait `complex_impl_support::External` for type `(Q, complex_impl_support::M<'_, '_, '_, std::boxed::Box<_>, _, _>)`: | ||
--> $DIR/complex-impl.rs:19:1 | ||
| | ||
19 | impl<R> External for (Q, R) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: conflicting implementation in crate `complex_impl_support`: | ||
- impl<'a, 'b, 'c, T, U, V, W> complex_impl_support::External for (T, complex_impl_support::M<'a, 'b, 'c, std::boxed::Box<U>, V, W>) | ||
where <U as std::ops::FnOnce<(T,)>>::Output == V, <V as std::iter::Iterator>::Item == T, 'b : 'a, T : 'a, U: std::ops::FnOnce<(T,)>, U : 'static, V: std::iter::Iterator, V: std::clone::Clone, W: std::ops::Add, <W as std::ops::Add>::Output: std::marker::Copy; | ||
|
||
error[E0210]: type parameter `R` must be used as the type parameter for some local type (e.g. `MyStruct<T>`); only traits defined in the current crate can be implemented for a type parameter | ||
--> $DIR/complex-impl.rs:19:1 | ||
| | ||
19 | impl<R> External for (Q, R) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2017 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(try_from)] | ||
|
||
use std::marker::PhantomData; | ||
use std::convert::{TryFrom, AsRef}; | ||
|
||
struct Q; | ||
impl AsRef<Q> for Box<Q> { | ||
fn as_ref(&self) -> &Q { | ||
&**self | ||
} | ||
} | ||
|
||
struct S; | ||
impl From<S> for S { | ||
fn from(s: S) -> S { | ||
s | ||
} | ||
} | ||
|
||
struct X; | ||
impl TryFrom<X> for X { | ||
type Error = (); | ||
fn try_from(u: X) -> Result<X, ()> { | ||
Ok(u) | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
error[E0119]: conflicting implementations of trait `std::convert::AsRef<Q>` for type `std::boxed::Box<Q>`: | ||
--> $DIR/conflict-with-std.rs:17:1 | ||
| | ||
17 | / impl AsRef<Q> for Box<Q> { | ||
18 | | fn as_ref(&self) -> &Q { | ||
19 | | &**self | ||
20 | | } | ||
21 | | } | ||
| |_^ | ||
| | ||
= note: conflicting implementation in crate `alloc`: | ||
- impl<T> std::convert::AsRef<T> for std::boxed::Box<T> | ||
where T: ?Sized; | ||
|
||
error[E0119]: conflicting implementations of trait `std::convert::From<S>` for type `S`: | ||
--> $DIR/conflict-with-std.rs:24:1 | ||
| | ||
24 | / impl From<S> for S { | ||
25 | | fn from(s: S) -> S { | ||
26 | | s | ||
27 | | } | ||
28 | | } | ||
| |_^ | ||
| | ||
= note: conflicting implementation in crate `core`: | ||
- impl<T> std::convert::From<T> for T; | ||
|
||
error[E0119]: conflicting implementations of trait `std::convert::TryFrom<X>` for type `X`: | ||
--> $DIR/conflict-with-std.rs:31:1 | ||
| | ||
31 | / impl TryFrom<X> for X { | ||
32 | | type Error = (); | ||
33 | | fn try_from(u: X) -> Result<X, ()> { | ||
34 | | Ok(u) | ||
35 | | } | ||
36 | | } | ||
| |_^ | ||
| | ||
= note: conflicting implementation in crate `core`: | ||
- impl<T, U> std::convert::TryFrom<U> for T | ||
where T: std::convert::From<U>; | ||
|
||
error: aborting due to 3 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2017 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// aux-build:issue_23563_a.rs | ||
|
||
// Ref: https://github.com/rust-lang/rust/issues/23563#issuecomment-260751672 | ||
|
||
extern crate issue_23563_a as a; | ||
|
||
use a::LolFrom; | ||
use a::LolInto; | ||
use a::LolTo; | ||
|
||
struct LocalType<T>(Option<T>); | ||
|
||
impl<'a, T> LolFrom<&'a [T]> for LocalType<T> { | ||
fn from(_: &'a [T]) -> LocalType<T> { LocalType(None) } | ||
} | ||
|
||
impl<T> LolInto<LocalType<T>> for LocalType<T> { | ||
fn convert_into(self) -> LocalType<T> { | ||
self | ||
} | ||
} | ||
|
||
impl LolTo<LocalType<u8>> for [u8] { | ||
fn convert_to(&self) -> LocalType<u8> { | ||
LocalType(None) | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0119]: conflicting implementations of trait `a::LolFrom<&[_]>` for type `LocalType<_>`: | ||
--> $DIR/issue-23563.rs:23:1 | ||
| | ||
23 | / impl<'a, T> LolFrom<&'a [T]> for LocalType<T> { | ||
24 | | fn from(_: &'a [T]) -> LocalType<T> { LocalType(None) } | ||
25 | | } | ||
| |_^ | ||
| | ||
= note: conflicting implementation in crate `issue_23563_a`: | ||
- impl<T, U> a::LolFrom<T> for U | ||
where T: a::LolInto<U>; | ||
|
||
error: aborting due to previous error | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2017 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
pub struct GenX<S> { | ||
inner: S, | ||
} | ||
|
||
impl<S> Into<S> for GenX<S> { | ||
fn into(self) -> S { | ||
self.inner | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error[E0119]: conflicting implementations of trait `std::convert::Into<_>` for type `GenX<_>`: | ||
--> $DIR/issue-27403.rs:15:1 | ||
| | ||
15 | / impl<S> Into<S> for GenX<S> { | ||
16 | | fn into(self) -> S { | ||
17 | | self.inner | ||
18 | | } | ||
19 | | } | ||
| |_^ | ||
| | ||
= note: conflicting implementation in crate `core`: | ||
- impl<T, U> std::convert::Into<U> for T | ||
where U: std::convert::From<T>; | ||
|
||
error: aborting due to previous error | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clearly we could do a better job on the formatting here, both for individual where clauses (which could be simplified) and for the listing itself (which could be spread across multiple lines or something. Still, not sure it's worth blocking this PR on that.