Skip to content

False positive for unstable_name_collisions lint #83834

@coolreader18

Description

@coolreader18

Cargo.toml:

[package]
name = "playground"
version = "0.1.0"
edition = "2018"

[dependencies]
lexical-core = "0.7"

lib.rs:

fn link_lexical_core() {
    let _ = lexical_core::get_inf_string();
}

fn huh() {
    let _x = 1u32 >> 32.wrapping_sub(1usize) as u32;
}

on cargo c:

warning: a method with this name may be added to the standard library in the future
 --> src/lib.rs:6:25
  |
6 |     let _x = 1u32 >> 32.wrapping_sub(1usize) as u32;
  |                         ^^^^^^^^^^^^
  |
  = 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 <https://github.com/rust-lang/rust/issues/48919>
  = help: call with fully qualified syntax `lexical_core::Integer::wrapping_sub(...)` to keep using the current method

error[E0689]: can't call method `wrapping_sub` on ambiguous numeric type `{integer}`
 --> src/lib.rs:6:25
  |
6 |     let _x = 1u32 >> 32.wrapping_sub(1usize) as u32;
  |                         ^^^^^^^^^^^^
  |
help: you must specify a concrete type for this numeric value, like `i32`
  |
6 |     let _x = 1u32 >> 32_i32.wrapping_sub(1usize) as u32;
  |                      ^^^^^^

error: aborting due to previous error; 1 warning emitted

Fixing the original error by adding a suffix to the integer literal gets rid of the unstable_name_collisions warning as well. This doesn't give the unstable_name_collisions warning:

fn link_lexical_core() {
    let _ = lexical_core::get_inf_string();
}

fn huh() {
    let _x = 1u32 >> 32usize.wrapping_sub(1usize) as u32;
}

Maybe rustc is noticing that Integer is implemented for exactly the same set of types that a bare integer literal could be? And it assumes that since that method wasn't fully resolved, that it's an unstable method, and doesn't check that it's already stable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-trait-systemArea: Trait systemT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions