Skip to content
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

incorrect unstable_name_collision warning for unstable inherent method name #50232

Closed
tspiteri opened this issue Apr 25, 2018 · 4 comments
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tspiteri
Copy link
Contributor

Compiling the code below with nightly produces an unstable_name_collision warning. However the code works after enabling the feature gate, I presume because the unstable method is inherent and takes precedence over trait methods. In this particular case, it can still be worth warning that the behaviour of the standard library method can be different, but the current “warning: once this method is added to the standard library, there will be ambiguity here, which will cause a hard error!” is incorrect.

//#![feature(euclidean_division)]
trait DivEuc {
    fn div_euc(self, rhs: Self) -> Self;
}
impl DivEuc for u32 {
    fn div_euc(self, rhs: Self) -> Self { self / rhs }
}
fn main() {
    println!("{}", 12u32.div_euc(3));
}
@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Apr 26, 2018
@varkor
Copy link
Member

varkor commented Apr 26, 2018

cc @kennytm, as this lint comes from #48552.

@kennytm kennytm added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools and removed T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Apr 26, 2018
@kennytm
Copy link
Member

kennytm commented Apr 26, 2018

What about this?

warning: once this method is added to the standard library, there will be ambiguity here, which will cause a hard error or change of behavior!

It seems the message is too long though.

@varkor
Copy link
Member

varkor commented Apr 26, 2018

Or simply:

warning: once this method is added to the standard library, the ambiguity may cause an error or change in behaviour!

(which is even shorter than the original.)

@tspiteri
Copy link
Contributor Author

If the trait method parameters are different from the inherent method parameters, it could end up leading to a hard error for a different reason. For example for the code below, opening the feature gate will cause a hard error, but because of a type mismatch rather than because of ambiguity.

//#![feature(euclidean_division)]
trait DivEuc {
    fn div_euc(self, rhs: u8) -> Self;
}
impl DivEuc for u32 {
    fn div_euc(self, rhs: u8) -> Self { self / rhs as u32 }
}
fn main() {
    println!("{}", 12u32.div_euc(3u8));
}

So a more generic error like @varkor suggests is better.

@kennytm kennytm self-assigned this Apr 26, 2018
kennytm added a commit to kennytm/rust that referenced this issue May 1, 2018
Stabilizing an inherent method may cause change in behavior instead of
inference error. Updated to use the wording from [varkor's comment].

Closes rust-lang#50232.

[varkor's comment]: rust-lang#50232 (comment)
kennytm added a commit to kennytm/rust that referenced this issue May 3, 2018
…name-collision, r=nikomatsakis

Clarify wordings of the `unstable_name_collision` lint.

Stabilizing an inherent method may cause change in behavior instead of inference error. Updated to use the wording from [varkor's comment].

Closes rust-lang#50232.

[varkor's comment]: rust-lang#50232 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants