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

Tracking issue for future-incompatibility lint unstable_name_collisions #48919

Open
2 tasks
kennytm opened this issue Mar 10, 2018 · 15 comments
Open
2 tasks

Tracking issue for future-incompatibility lint unstable_name_collisions #48919

kennytm opened this issue Mar 10, 2018 · 15 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-future-incompatibility Category: Future-incompatibility lints C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kennytm
Copy link
Member

kennytm commented Mar 10, 2018

This is the summary issue for the unstable_name_collisions future-incompatibility lint and other related errors. The goal of this page is describe why this change was made and how you can fix code that is affected by it. It also provides a place to ask questions or register a complaint if you feel the change should not be made. For more information on the policy around future-compatibility warnings, see our breaking change policy guidelines.

What is the warning for?

Rust's standard library is evolving, and will sometimes add new functions we found useful, e.g. Ord::clamp or Iterator::flatten. Unfortunately, there will often be popular third-party packages already implemented the same function with the same name. The compiler, when seeing the name flatten, cannot decide whether you want the one from the standard library or the third-party library, and gives up with the multiple applicable items in scope error.

As an inference breakage canary, the compiler will emit a warning whenever it detected a name conflict with an unstable standard library function.

extern crate itertools;
use itertools::Itertools;

fn main() {
    println!(
        "{:?}",
        [[1, 2], [3, 4]].iter().flatten().collect::<Vec<_>>()
        //~^ WARN a method with this name will be added to the standard library in the future
    );
}

To stop this warning and the future hard error, you could use fully-qualified name to explicitly tell the compiler to use the third-party function:

extern crate itertools;
use itertools::Itertools;

fn main() {
    println!(
        "{:?}",
        Itertools::flatten([[1, 2], [3, 4]].iter()).collect::<Vec<_>>()
//      ^~~~~~~~~~~~~~~~~~~.......................~
//      explicitly use the `flatten` method from the `Itertools` trait.
    );
}

When will this warning become a hard error?

This warning will be emitted for every unstable library feature having name conflicts. When a particular library feature is stabilized, this name conflict will cause a hard error.

Please follow the tracking issue for each library feature for their stabilization progress. Some current unstable method which is known to cause conflict in the wild are:

@kennytm kennytm added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. labels Mar 10, 2018
stuhood added a commit to twitter/pants that referenced this issue May 10, 2018
stuhood added a commit to twitter/pants that referenced this issue May 11, 2018
stuhood added a commit to twitter/pants that referenced this issue May 13, 2018
illicitonion pushed a commit to twitter/pants that referenced this issue May 15, 2018
illicitonion pushed a commit to twitter/pants that referenced this issue May 15, 2018
illicitonion pushed a commit to twitter/pants that referenced this issue May 15, 2018
illicitonion pushed a commit to twitter/pants that referenced this issue May 15, 2018
stuhood added a commit to twitter/pants that referenced this issue May 20, 2018
mati865 added a commit to mati865/rustup.rs that referenced this issue Jun 25, 2018
mati865 added a commit to mati865/rustup.rs that referenced this issue Jul 2, 2018
mati865 added a commit to mati865/rustup.rs that referenced this issue Jul 6, 2018
@infinity0
Copy link
Contributor

In the case of Itertools::flatten would it not be better to just ignore the warning and wait for it to be added to the standard library and then removed from Itertools? Presumably the two functions do the same thing, so eventually everyone does want to migrate to the std version, to reduce cruft.

@kennytm
Copy link
Member Author

kennytm commented Jul 7, 2018

@infinity0 .flatten has already been stabilized and will be available in 1.29...

psftw added a commit to psftw/rust-cfn that referenced this issue Jun 12, 2019
@bstrie
Copy link
Contributor

bstrie commented Feb 21, 2020

Given that the lint definition itself says:

        // Note: this item represents future incompatibility of all unstable functions in the
        //       standard library, and thus should never be removed or changed to an error.

it sort of feels like having a tracking issue is somewhat misleading... Should this issue be closed, or is it expected that this issue will instead be permanently open?

@jonas-schievink jonas-schievink added C-future-incompatibility Category: Future-incompatibility lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. labels Apr 20, 2020
yvt added a commit to r3-os/r3 that referenced this issue Oct 1, 2020
`int_bits_const` feature [1] adds `i32::BITS`, etc. We already have
`BitInteger` trait, which has `BitInteger::BITS`, and using it triggers
`unstable_name_collision` compatibility lint [2] unless `int_bits_const`
is explicitly enabled, gets stabilized or gets rejected and removed from
the compiler.

[1]: rust-lang/rust#76492
[2]: rust-lang/rust#48919
yvt added a commit to r3-os/r3 that referenced this issue Oct 1, 2020
`int_bits_const` feature [1] adds `i32::BITS`, etc. We already have
`BitInteger` trait, which has `BitInteger::BITS`, and using it triggers
`unstable_name_collision` compatibility lint [2] unless `int_bits_const`
is explicitly enabled, gets stabilized or gets rejected and removed from
the compiler.

[1]: rust-lang/rust#76492
[2]: rust-lang/rust#48919
yvt added a commit to r3-os/r3 that referenced this issue Oct 1, 2020
`int_bits_const` feature [1] adds `i32::BITS`, etc. We already have
`BitInteger` trait, which has `BitInteger::BITS`, and using it triggers
`unstable_name_collision` compatibility lint [2] unless `int_bits_const`
is explicitly enabled, gets stabilized or gets rejected and removed from
the compiler.

[1]: rust-lang/rust#76492
[2]: rust-lang/rust#48919
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 22, 2020
Update `compiler_builtins` to 0.1.36

So, the libc build with cargo's `build-std` feature emits a lot of warnings like:
```
 warning: a method with this name may be added to the standard library in the future
   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.35/src/int/udiv.rs:98:23
    |
98  |             q = n << (<$ty>::BITS - sr);
    |                       ^^^^^^^^^^^
...
268 |         udivmod_inner!(n, d, rem, u128)
    |         ------------------------------- in this macro invocation
    |
    = warning: once this method is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue rust-lang#48919 <rust-lang/issues/48919>
    = help: call with fully qualified syntax `Int::BITS(...)` to keep using the current method
    = help: add `#![feature(int_bits_const)]` to the crate attributes to enable `num::<impl u128>::BITS`
    = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
```

(You can find the full log in https://github.com/rust-lang/libc/runs/1283695796?check_suite_focus=true for example.)

0.1.36 contains rust-lang/compiler-builtins#332 so this version should remove this warning.

cc rust-lang/libc#1942
JohnTitor added a commit to JohnTitor/rust that referenced this issue Oct 25, 2020
Update `compiler_builtins` to 0.1.36

So, the libc build with cargo's `build-std` feature emits a lot of warnings like:
```
 warning: a method with this name may be added to the standard library in the future
   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.35/src/int/udiv.rs:98:23
    |
98  |             q = n << (<$ty>::BITS - sr);
    |                       ^^^^^^^^^^^
...
268 |         udivmod_inner!(n, d, rem, u128)
    |         ------------------------------- in this macro invocation
    |
    = warning: once this method is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue rust-lang#48919 <rust-lang/issues/48919>
    = help: call with fully qualified syntax `Int::BITS(...)` to keep using the current method
    = help: add `#![feature(int_bits_const)]` to the crate attributes to enable `num::<impl u128>::BITS`
    = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
```

(You can find the full log in https://github.com/rust-lang/libc/runs/1283695796?check_suite_focus=true for example.)

0.1.36 contains rust-lang/compiler-builtins#332 so this version should remove this warning.

cc rust-lang/libc#1942
facebook-github-bot pushed a commit to facebook/sapling that referenced this issue Jan 28, 2021
Summary:
The name is being taken by stdlib:

  warning: a method with this name may be added to the standard library in the future
     --> eden/scm/lib/dag/src/spanset.rs:228:14
      |
  228 |             .binary_search_by(|probe| span.low.cmp(&probe.low))
      |              ^^^^^^^^^^^^^^^^
      |
      = note: `#[warn(unstable_name_collisions)]` on by default
      = warning: once this method is added to the standard library, the ambiguity may cause an error or change in behavior!
      = note: for more information, see issue #48919 <rust-lang/rust#48919>
      = help: call with fully qualified syntax `BinarySearchBy::binary_search_by(...)` to keep using the current method
      = help: add `#![feature(vecdeque_binary_search)]` to the crate attributes to enable `VecDeque::<T>::binary_search_by`

Reviewed By: sfilipco

Differential Revision: D26092424

fbshipit-source-id: d2cdf7d73d2f808f038817c9dc9f4c531ff643bd
adrien-zinger added a commit to massalabs/massa that referenced this issue Dec 28, 2021
It seems that we need to change something quick! The standard library will pass over

```bash
   Compiling massa_consensus v0.1.0 (/home/adrien/Documents/repos/massa/massa-consensus)
warning: an associated function with this name may be added to the standard library in the future
   --> massa-consensus/src/pos.rs:522:37
    |
522 |         let bits_u8_len = n_entries.div_ceil(&u8::BITS) as usize;
    |                                     ^^^^^^^^
    |
    = note: `#[warn(unstable_name_collisions)]` on by default
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <rust-lang/rust#48919>
    = help: call with fully qualified syntax `num::Integer::div_ceil(...)` to keep using the current method
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable `core::num::<impl u32>::div_ceil`
```

Opt for the fully qualified syntax
adrien-zinger added a commit to massalabs/massa that referenced this issue Dec 29, 2021
It seems that we need to change something quick! The standard library will pass over

```bash
   Compiling massa_consensus v0.1.0 (/home/adrien/Documents/repos/massa/massa-consensus)
warning: an associated function with this name may be added to the standard library in the future
   --> massa-consensus/src/pos.rs:522:37
    |
522 |         let bits_u8_len = n_entries.div_ceil(&u8::BITS) as usize;
    |                                     ^^^^^^^^
    |
    = note: `#[warn(unstable_name_collisions)]` on by default
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <rust-lang/rust#48919>
    = help: call with fully qualified syntax `num::Integer::div_ceil(...)` to keep using the current method
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable `core::num::<impl u32>::div_ceil`
```

Opt for the fully qualified syntax
bors bot added a commit to massalabs/massa that referenced this issue Dec 30, 2021
2046: Fix a compilation error (maybe temporary) r=adrien-zinger a=adrien-zinger

It seems that we need to change something quick! The standard library will pass over

```bash
   Compiling massa_consensus v0.1.0 (/home/adrien/Documents/repos/massa/massa-consensus)
warning: an associated function with this name may be added to the standard library in the future
   --> massa-consensus/src/pos.rs:522:37
    |
522 |         let bits_u8_len = n_entries.div_ceil(&u8::BITS) as usize;
    |                                     ^^^^^^^^
    |
    = note: `#[warn(unstable_name_collisions)]` on by default
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <rust-lang/rust#48919>
    = help: call with fully qualified syntax `num::Integer::div_ceil(...)` to keep using the current method
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable `core::num::<impl u32>::div_ceil`
```

Opt for the fully qualified syntax

Co-authored-by: Adrien Zinger <zinger.ad@gmail.com>
bors bot added a commit to massalabs/massa that referenced this issue Dec 30, 2021
2046: Fix a compilation error (maybe temporary) r=damip a=adrien-zinger

It seems that we need to change something quick! The standard library will pass over

```bash
   Compiling massa_consensus v0.1.0 (/home/adrien/Documents/repos/massa/massa-consensus)
warning: an associated function with this name may be added to the standard library in the future
   --> massa-consensus/src/pos.rs:522:37
    |
522 |         let bits_u8_len = n_entries.div_ceil(&u8::BITS) as usize;
    |                                     ^^^^^^^^
    |
    = note: `#[warn(unstable_name_collisions)]` on by default
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <rust-lang/rust#48919>
    = help: call with fully qualified syntax `num::Integer::div_ceil(...)` to keep using the current method
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable `core::num::<impl u32>::div_ceil`
```

Opt for the fully qualified syntax

Co-authored-by: Adrien Zinger <zinger.ad@gmail.com>
bors bot added a commit to massalabs/massa that referenced this issue Jan 3, 2022
2046: Fix a compilation error (maybe temporary) r=damip a=adrien-zinger

It seems that we need to change something quick! The standard library will pass over

```bash
   Compiling massa_consensus v0.1.0 (/home/adrien/Documents/repos/massa/massa-consensus)
warning: an associated function with this name may be added to the standard library in the future
   --> massa-consensus/src/pos.rs:522:37
    |
522 |         let bits_u8_len = n_entries.div_ceil(&u8::BITS) as usize;
    |                                     ^^^^^^^^
    |
    = note: `#[warn(unstable_name_collisions)]` on by default
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <rust-lang/rust#48919>
    = help: call with fully qualified syntax `num::Integer::div_ceil(...)` to keep using the current method
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable `core::num::<impl u32>::div_ceil`
```

Opt for the fully qualified syntax

Co-authored-by: Adrien Zinger <zinger.ad@gmail.com>
bors bot added a commit to massalabs/massa that referenced this issue Jan 3, 2022
2046: Fix a compilation error (maybe temporary) r=damip a=adrien-zinger

It seems that we need to change something quick! The standard library will pass over

```bash
   Compiling massa_consensus v0.1.0 (/home/adrien/Documents/repos/massa/massa-consensus)
warning: an associated function with this name may be added to the standard library in the future
   --> massa-consensus/src/pos.rs:522:37
    |
522 |         let bits_u8_len = n_entries.div_ceil(&u8::BITS) as usize;
    |                                     ^^^^^^^^
    |
    = note: `#[warn(unstable_name_collisions)]` on by default
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <rust-lang/rust#48919>
    = help: call with fully qualified syntax `num::Integer::div_ceil(...)` to keep using the current method
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable `core::num::<impl u32>::div_ceil`
```

Opt for the fully qualified syntax

Co-authored-by: Adrien Zinger <zinger.ad@gmail.com>
Co-authored-by: damip <damipator@gmail.com>
bors bot added a commit to massalabs/massa that referenced this issue Jan 3, 2022
2046: Fix a compilation error (maybe temporary) r=damip a=adrien-zinger

It seems that we need to change something quick! The standard library will pass over

```bash
   Compiling massa_consensus v0.1.0 (/home/adrien/Documents/repos/massa/massa-consensus)
warning: an associated function with this name may be added to the standard library in the future
   --> massa-consensus/src/pos.rs:522:37
    |
522 |         let bits_u8_len = n_entries.div_ceil(&u8::BITS) as usize;
    |                                     ^^^^^^^^
    |
    = note: `#[warn(unstable_name_collisions)]` on by default
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <rust-lang/rust#48919>
    = help: call with fully qualified syntax `num::Integer::div_ceil(...)` to keep using the current method
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable `core::num::<impl u32>::div_ceil`
```

Opt for the fully qualified syntax

Co-authored-by: Adrien Zinger <zinger.ad@gmail.com>
Co-authored-by: damip <damipator@gmail.com>
@joshtriplett
Copy link
Member

I'd like to propose that we reconsider our current approach to this warning.

I just committed the following code to one of my projects:

// Ignore the warnings about div_ceil and next_multiple_of, to avoid rewriting code twice, once
// to use num_integer explicitly and a second time to use the methods from std.
#![allow(unstable_name_collisions)]

I hope that rust-lang/rfcs#3240 will provide a better solution to this problem. Once that RFC is merged, I'd like to propose that we drop this lint.

@your-diary
Copy link

Is it possible to suppress this warning only for some specified method?

Pseudo code:

#![allow(unstable_name_collisions(target = num::Integer::div_ceil))]

If not, I think this warning is too broad.

@VorpalBlade
Copy link

The lint suggests calling this with the full method name. It isn't clear to me how to do that in a chained call while keeping the chained syntax. E.g.

myIter.filter(...).intersperse(...).map(...).collect(...)

Here the warning is about intersperse (Itertools vs unstable standard library). How would I go about calling it as itertools::Itertools::intersperse(...) (which the warning suggests) without adding an arbitrary let temp = step? I.e. keeping it as a single chain?

If that is not possible, this seems like a major deficiency in the recommendation from this lint.

@your-diary
Copy link

your-diary commented Apr 7, 2023

@VorpalBlade

Try

itertools::Itertools::intersperse(myIter.filter(...), &item).map(...).collect(...)

This is known as fully qualified syntax.

@VorpalBlade
Copy link

@VorpalBlade

Try

itertools::Itertools::intersperse(myIter.filter(...), &item).map(...).collect(...)

This is known as fully qualified syntax.

Thanks, this works but reverses the reading order in the middle of the expression, which is suboptimal. While the solution with a temporary variable keeps the order, it introduces clutter. Neither approach is optimal.

@tv42
Copy link
Contributor

tv42 commented Jun 12, 2023

I would really like to be able to opt-out of this per colliding method.

I want to use Result::inspect_err without needing a nightly build, and thus ended up with https://github.com/matthiasbeyer/result-inspect and now I'm getting repeat warnings because of that. When Result::inspect_err is stable, I'll happily throw away the dependency, but until that time it seems I can't use #[warn(future_incompatible)] without huge pain.

@ChrisJefferson
Copy link
Contributor

ChrisJefferson commented Sep 15, 2023

I came here from a warning in my code. I was told to replace div_floor with num_integer::Integer::div_floor.

Except, if I do that, I then get a compile error. Looking at higher-up issues I can see I'm "doing it wrong", but I do think if possible it would be better to improve the error message to link somewhere how to actually fix your code, as the error doing a simple replace isn't helpful at all:

error: expected one of `(`, `.`, `;`, `?`, `}`, or an operator, found `::`
   --> src/constraint_def.rs:498:44
    |
498 |                         v[0][0].num_integer::Integer::div_floor(&v[1][0])
    |                                            ^^ expected one of `(`, `.`, `;`, `?`, `}`, or an operator

@ChrisJefferson
Copy link
Contributor

Suggestion: Could clippy's --fix framework be used to automatically fix code with this issue? I'm not sure of the right way to do this, could the same issue also be added to clippy, or clippy automatically pick up rewrite the compiler wants?

@withoutboats
Copy link
Contributor

withoutboats commented Mar 4, 2024

(NOT A CONTRIBUTION)

I was shown this lint for calling Range::is_empty on &mut Range<usize>. I'm guessing this is a conflict with an API that may be added to Iterator (which would take a mutable reference and therefore shadow the shared reference inherent method? I'm not 100% sure the method resolution rules in a case like that).

I'm not sure if this is the case because nothing links me to the unstable API that I am in a collision with.

Also, the lint suggested I change my code to std::ops::Range<Idx>, even though Range was in scope and the type was Range<usize>.

I found this to be a pretty bad user experience. I was given a lint that I have no realistic choice but to suppress somehow, which the lint provides wrong advice for how to do. This resulted from calling a method in std, not even using a third party crate. There was no way to reference to the change of behavior that may come, though I assume it will not be relevant to me, because I assume in the case of Range either implementation of is_empty will behave the same.

bioinformatist added a commit to bioinformatist/thaw that referenced this issue May 7, 2024
luoxiaozero pushed a commit to thaw-ui/thaw that referenced this issue May 7, 2024
* perf: replace `expect` with `unwrap_or_else`

The macro/functions in `expect` is not lazy, which means it will always be called

* style: remove needless borrowing

* perf: remove needless clone

* style: remove needless `format!`

* style: use `and_then` instead

* style: use `?` instead

* style: remove needless closure

* fix: use fully qualified syntax instead

rust-lang/rust#48919

* style: formatted

* style: fix some other clippy issues
@ijackson
Copy link
Contributor

IMO this lint ought to be withdrawn, and instead the Rust project should commit to finding a better way to deal with this situation. There have been RFCs proposed, including rust-lang/rfcs#3240

The current compiler behaviour is to make complaints with no good solution. (Using the fully qualified syntax is not a good solution.) This keeps coming up in projects I work on and I'm finding myself adding #[allow] for it. I'm sure this is the case for others too.

Ie, this lint is not meeting its objective, of allowing std to implement these methods without breaking downstream code.

@kennytm
Copy link
Member Author

kennytm commented Aug 21, 2024

@ijackson That's the point of rust-lang/rfcs#3624

@fmease fmease changed the title Tracking issue for unstable_name_collision compatibility lint Tracking issue for future-incompatibility lint unstable_name_collisions Sep 14, 2024
@fmease fmease added the C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. label Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-future-incompatibility Category: Future-incompatibility lints C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Archived in project
Development

No branches or pull requests