Skip to content

conflicting implementations when attempting to impl<S> Into<S> for ArbitraryStructWithNoOtherImpls<S> #27403

Closed
@codyps

Description

@codyps

At the very least (if this failure is expected), the error needs to be improved to actually point to the conflicting impl rather than simply printing the crate name and repeating the same function output that conflicts (if it is for some reason not possible to print better info about the previously declared conflicting impl, at the very least the compiler should stop repeating the output for the impl generating the error). On the diagnostics side, this appears related to #27218.

Note that simply changing the struct (in this case, GenX<T>) to a non-generic struct allows the build to proceed without issue (example: http://is.gd/lRAhBF).

It appears that somehow the impl<T, U> Into<U> for T where U: From<T> is considered to be conflicting with all Into<U> impls where U is a generic parameter even in cases where U does not impl From<T>.

error:

<anon>:6:1: 10:2 error: conflicting implementations for trait `core::convert::Into` [E0119]
<anon>: 6 impl<S> Into<S> for GenX<S> {
<anon>: 7     fn into(self) -> S {
<anon>: 8         self.inner
<anon>: 9     }
<anon>:10 }
<anon>:6:1: 10:2 help: see the detailed explanation for E0119
<anon>:6:1: 10:2 note: conflicting implementation in crate `core`
<anon>: 6 impl<S> Into<S> for GenX<S> {
<anon>: 7     fn into(self) -> S {
<anon>: 8         self.inner
<anon>: 9     }
<anon>:10 }
error: aborting due to previous error

source:

pub struct GenX<S> {
    inner: S,
}
impl<S> Into<S> for GenX<S> {
    fn into(self) -> S {
        self.inner
    }
}

playpen: http://is.gd/zrwjve

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.P-lowLow priorityT-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions