rust icon indicating copy to clipboard operation
rust copied to clipboard

resolve: re-export ambiguity as warning

Open bvanjoi opened this issue 2 years ago • 43 comments

Fixes #36837

Expose these ambiguous bindings as warnings instead of simply concealing them. This change introduces potential breaking alterations. For instance, code that previously compiled successfully may now fail to compile as expected:

// lib.rs
mod a {
  pub type C = i8;
}

mod b {
  pub type C = i16;
}

pub use a::*;
pub use b::*;

// main.rs
extern crate lib;

mod a {
    pub type C = i32;
}

use lib::*;
use a::*;

fn main() {
    let _: C = 1; // it will throw an ambiguity error but previous it will not.
}

r? @petrochenkov

bvanjoi avatar Aug 10 '23 03:08 bvanjoi

I will proceed with this PR once https://github.com/rust-lang/rust/pull/115269 is merged, therefore, it is currently marked as a draft.

bvanjoi avatar Sep 12 '23 16:09 bvanjoi

Our labels are better for tracking this stuff than github's draft status. Blocked on https://github.com/rust-lang/rust/pull/115269. @rustbot blocked

petrochenkov avatar Sep 13 '23 05:09 petrochenkov

https://github.com/rust-lang/rust/pull/115269 has landed. @rustbot author

petrochenkov avatar Oct 07 '23 11:10 petrochenkov

I will proceed with this PR once #115269 is merged, therefore, it is currently marked as a draft. this has been merged

@bvanjoi

ping from triage - can you post your status on this PR? There hasn't been an update in a few months. Thanks!

FYI: when a PR is ready for review, send a message containing @rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

JohnCSimon avatar Nov 12 '23 18:11 JohnCSimon

I nearly overlooked this task, but I intend to continue with it within this week.

bvanjoi avatar Nov 13 '23 05:11 bvanjoi

ci is green @rustbot ready

bvanjoi avatar Nov 18 '23 17:11 bvanjoi

:umbrella: The latest upstream changes (presumably #116092) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Nov 21 '23 02:11 bors

ci is green. @rustbot ready

bvanjoi avatar Dec 15 '23 09:12 bvanjoi

r=me after the style/wording fixes. @rustbot author

petrochenkov avatar Dec 15 '23 13:12 petrochenkov

Should we need to run the regression test?

bvanjoi avatar Dec 15 '23 14:12 bvanjoi

I forgot about crater, yes. We should run it.

petrochenkov avatar Dec 15 '23 14:12 petrochenkov

@bors try

petrochenkov avatar Dec 15 '23 14:12 petrochenkov

:hourglass: Trying commit 135d52265191cbd97f8b10af8c99d93a3da327a2 with merge 785364c7e5e0804473a3fddfb579798ea14e3493...

bors avatar Dec 15 '23 14:12 bors

:sunny: Try build successful - checks-actions Build commit: 785364c7e5e0804473a3fddfb579798ea14e3493 (785364c7e5e0804473a3fddfb579798ea14e3493)

bors avatar Dec 15 '23 16:12 bors

@craterbot check

petrochenkov avatar Dec 15 '23 16:12 petrochenkov

:ok_hand: Experiment pr-114682 created and queued. :robot: Automatically detected try build 785364c7e5e0804473a3fddfb579798ea14e3493 :mag: You can check out the queue and this experiment's details.

:information_source: Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

craterbot avatar Dec 15 '23 16:12 craterbot

:construction: Experiment pr-114682 is now running

:information_source: Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

craterbot avatar Dec 23 '23 23:12 craterbot

:tada: Experiment pr-114682 is completed! :bar_chart: 360 regressed and 6 fixed (399777 total) :newspaper: Open the full report.

:warning: If you notice any spurious failure please add them to the blacklist! :information_source: Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

craterbot avatar Dec 25 '23 22:12 craterbot

Many "No space left on device" errors, need a second crater iteration.

petrochenkov avatar Dec 26 '23 12:12 petrochenkov

@craterbot check p=1 crates=https://crater-reports.s3.amazonaws.com/pr-114682/retry-regressed-list.txt

petrochenkov avatar Dec 26 '23 12:12 petrochenkov

:ok_hand: Experiment pr-114682-1 created and queued. :robot: Automatically detected try build 785364c7e5e0804473a3fddfb579798ea14e3493 :mag: You can check out the queue and this experiment's details.

:information_source: Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

craterbot avatar Dec 26 '23 12:12 craterbot

:construction: Experiment pr-114682-1 is now running

:information_source: Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

craterbot avatar Dec 27 '23 12:12 craterbot

:tada: Experiment pr-114682-1 is completed! :bar_chart: 296 regressed and 0 fixed (360 total) :newspaper: Open the full report.

:warning: If you notice any spurious failure please add them to the blacklist! :information_source: Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

craterbot avatar Dec 27 '23 15:12 craterbot

Waiting on the author to triage regressions. @rustbot author

petrochenkov avatar Dec 27 '23 23:12 petrochenkov

I plan to check this over the weekend.

bvanjoi avatar Jan 03 '24 14:01 bvanjoi

Most of the regressions were caused by [email protected]:

// extern-crate.rs
macro_rules! m {
  () => {
      pub fn max() {}
      pub(crate) mod max {}
  };
}

mod d {
    m!{}
}

mod e {
    pub type max = i32;
}

pub use self::d::*;
pub use self::e::*;

// code.rs
extern crate extern_crate;

use extern_crate::max; // regression error: max is ambigous name
fn main() {};

bvanjoi avatar Jan 07 '24 09:01 bvanjoi

reduced for wry:

// extern-crate.rs
mod gio {
    pub trait SettingsExt {
        fn abc(&self) {}
    }
    impl<T> SettingsExt for T {}
}

mod gtk {
    pub trait SettingsExt {
        fn efg(&self) {}
    }
    impl<T> SettingsExt for T {}
}

pub use gtk::*;
pub use gio::*;

// code.rs

extern crate extern_crate;
use extern_crate::*;

mod auto {
    pub trait SettingsExt {
        fn ext(&self) {}
    }

    impl<T> SettingsExt for T {}
}

pub use self::auto::*;

pub fn main() {
    let a: u8 = 1;
    a.ext(); // regression, no method named `ext` found for type `u8` in the current scope
}

bvanjoi avatar Jan 08 '24 09:01 bvanjoi

reduced for polywrap_xxx

// extern-crate.rs
mod a {
    pub type Result<T> = std::result::Result<T, ()>;
}

mod b {
    pub type Result<T> = std::result::Result<T, ()>;
}

pub use a::*;
pub use b::*;

// code.rs
extern crate extern_crate;

use extern_crate::*;
fn a() -> Result<i32, ()> { // regression: type alias takes 1 generic argument but 2 generic arguments were supplied
    Ok(1)
}
pub fn main() {}

reduced for manage_relay_users:

// extern1.rs
pub struct Url;

// extern2.rs
extern crate extern1;

pub mod p {
    pub use crate::types::*;    
    pub use crate::*;
}
mod types {
    pub mod extern1 {}
}
pub use extern1;

// code.rs
extern crate extern1;
extern crate extern2;

use extern2::p::*;
use extern1::Url; // regression: extern1 is ambigous

fn main() {}

reduced for https://github.com/loganstone/playground:

// extern-crate.rs
mod a {
    pub fn log() {}
}
mod b {
    pub fn log() {}
}

pub use self::a::*;
pub use self::b::*;


// code.rs
extern crate extern_crate;
use extern_crate::*;
fn main() {
    let log = 2; // regression: log` is ambiguous
    let _ = log;
}

bvanjoi avatar Jan 08 '24 10:01 bvanjoi

It seems these regressions are within our expectations. Should we add this as a lint?

bvanjoi avatar Jan 08 '24 12:01 bvanjoi

Yes, these errors should be reported as a deprecation lint for some time.

petrochenkov avatar Jan 08 '24 14:01 petrochenkov