Skip to content

Rustc does not warn about use with paths incompatible with uniform_paths for edition 2018 #53797

Open
@orium

Description

@orium

Updated Description:

This code generates no warnings when compiled with the 2015 edition:

#![deny(rust_2018_compatibility)]
#![allow(unused_imports)]

extern crate rayon;

mod foo {
    mod rayon {}
    
    use rayon::Scope;
}

but when compiled with the 2018 edition fails to compile:

error[E0432]: unresolved import `rayon::Scope`
 --> src/lib.rs:9:9
  |
9 |     use rayon::Scope;
  |         ^^^^^^^^^^^^ no `Scope` in `foo::rayon`

error[E0659]: `rayon` is ambiguous (name vs any other name during import resolution)
 --> src/lib.rs:9:9
  |
9 |     use rayon::Scope;
  |         ^^^^^ ambiguous name
  |
note: `rayon` could refer to the module defined here
 --> src/lib.rs:7:5
  |
7 |     mod rayon {}
  |     ^^^^^^^^^^^^
  = help: use `self::rayon` to refer to this module unambiguously
note: `rayon` could also refer to the extern crate imported here
 --> src/lib.rs:4:1
  |
4 | extern crate rayon;
  | ^^^^^^^^^^^^^^^^^^^
  = help: use `::rayon` to refer to this extern crate unambiguously

error: aborting due to 2 previous errors

Some errors occurred: E0432, E0659.
For more information about an error, try `rustc --explain E0432`.

Old Description

Rustc does not warn about use with paths incompatible with uniform_paths for edition 2018. This means that rustfix it will not fix your code for edition 2018.

To reproduce create the following project:

Cargo.toml:

[package]
name = "foobar"
version = "0.0.0"
authors = ["Foo <example@example.com>"]

[dependencies]
criterion = "0.2"

src/lib.rs:

#![allow(unused)]
#![feature(rust_2018_preview, uniform_paths)]
extern crate criterion;
use criterion::Criterion;

If you run cargo +nightly check you will not get any warning, which means that when you run cargo +nightly fix --edition nothing will change, but the code is not compilable in rust 2018. Change Cargo.toml to enable edition 2018 (by adding cargo-features = ["edition"] and package.edition = "2018") and run cargo +nightly build:

$ cargo +nightly build
[...]
error: `criterion` import is ambiguous
 --> src/lib.rs:4:5
  |
3 | extern crate criterion;
  | ----------------------- can refer to `self::criterion`
4 | use criterion::Criterion;
  |     ^^^^^^^^^ can refer to external crate `::criterion`
  |
  = help: write `::criterion` or `self::criterion` explicitly instead
  = note: relative `use` paths enabled by `#![feature(uniform_paths)]`
[...]

cargo +nightly fix --edition should have changed line 4 to use ::criterion::Criterion.

Ref: Bug in cargo: rust-lang/cargo#5905

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2018Area: The 2018 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.C-future-incompatibilityCategory: Future-incompatibility lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    Idea

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions