rust icon indicating copy to clipboard operation
rust copied to clipboard

resolve: Preserve ambiguous glob reexports in crate metadata

Open petrochenkov opened this issue 1 month ago • 46 comments

So in cross-crate scenarios they can work in the same way as in crate-local scenarios.

Change Description: https://github.com/rust-lang/rust/pull/147984#issuecomment-3455514826

Resurrection of https://github.com/rust-lang/rust/pull/114682. One of unblocking steps for https://github.com/rust-lang/rust/pull/145108. Fixes https://github.com/rust-lang/rust/issues/36837.

petrochenkov avatar Oct 22 '25 13:10 petrochenkov

r? @jdonszelmann

rustbot has assigned @jdonszelmann. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

rustbot avatar Oct 22 '25 13:10 rustbot

@bors try

petrochenkov avatar Oct 22 '25 13:10 petrochenkov

:hourglass: Trying commit aa2fb6e31354a05e53a34efa4e2e3961c2ced4e7 with merge b4c55082edd8dec08ce8af276d7054d9c4db20c4…

To cancel the try build, run the command @bors try cancel.

Workflow: https://github.com/rust-lang/rust/actions/runs/18717348199

rust-bors[bot] avatar Oct 22 '25 13:10 rust-bors[bot]

cc @LorrensP-2158466 @bvanjoi

petrochenkov avatar Oct 22 '25 13:10 petrochenkov

:sunny: Try build successful (CI) Build commit: b4c55082edd8dec08ce8af276d7054d9c4db20c4 (b4c55082edd8dec08ce8af276d7054d9c4db20c4, parent: f5e2df741b4a9820a7579f0c8eccc951706a8782)

rust-bors[bot] avatar Oct 22 '25 15:10 rust-bors[bot]

@craterbot check

petrochenkov avatar Oct 22 '25 15:10 petrochenkov

:ok_hand: Experiment pr-147984 created and queued. :robot: Automatically detected try build b4c55082edd8dec08ce8af276d7054d9c4db20c4 :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 Oct 22 '25 15:10 craterbot

:construction: Experiment pr-147984 is now running

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

craterbot avatar Oct 22 '25 15:10 craterbot

:tada: Experiment pr-147984 is completed! :bar_chart: 2312 regressed and 2 fixed (721923 total) :bar_chart: 1766 spurious results on the retry-regessed-list.txt, consider a retry[^1] if this is a significant amount. :newspaper: Open the summary report.

:warning: If you notice any spurious failure please add them to the denylist! :information_source: Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more [^1]: re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-147984/retry-regressed-list.txt

craterbot avatar Oct 24 '25 07:10 craterbot

That's a lot of breakage. Mostly from dependencies, including various version of openssl that we've seen previously. I'll demote this error to always be reported as a lint in cross-crate scenarios, and then rerun crater.

petrochenkov avatar Oct 24 '25 12:10 petrochenkov

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

rustbot avatar Oct 24 '25 12:10 rustbot

@bors try

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

petrochenkov avatar Oct 24 '25 12:10 petrochenkov

:hourglass: Trying commit e388d621b8ecf8165631d304028f3d4794ec3978 with merge c6359cd3b4418e8472bae1a89c242796f2b86d56…

To cancel the try build, run the command @bors try cancel.

Workflow: https://github.com/rust-lang/rust/actions/runs/18780466583

rust-bors[bot] avatar Oct 24 '25 12:10 rust-bors[bot]

:sunny: Try build successful (CI) Build commit: c6359cd3b4418e8472bae1a89c242796f2b86d56 (c6359cd3b4418e8472bae1a89c242796f2b86d56, parent: 75948c8bb3bd37f1e8ee20273a04edea4c1f84f8)

rust-bors[bot] avatar Oct 24 '25 15:10 rust-bors[bot]

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

petrochenkov avatar Oct 24 '25 15:10 petrochenkov

:ok_hand: Experiment pr-147984-1 created and queued. :robot: Automatically detected try build c6359cd3b4418e8472bae1a89c242796f2b86d56 :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 Oct 24 '25 15:10 craterbot

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

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

craterbot avatar Oct 25 '25 13:10 craterbot

:tada: Experiment pr-147984-1 is completed! :bar_chart: 75 regressed and 0 fixed (4069 total) :bar_chart: 177 spurious results on the retry-regessed-list.txt, consider a retry[^1] if this is a significant amount. :newspaper: Open the summary report.

:warning: If you notice any spurious failure please add them to the denylist! :information_source: Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more [^1]: re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-147984-1/retry-regressed-list.txt

craterbot avatar Oct 25 '25 22:10 craterbot

74 regressions are just due to ambiguous_glob_imports being deny-by-default. We could potentially introduce a separate warn-by-default lint extern_ambiguous_glob_imports to soften the transition.

There are 3 other non-spurious regressions from this change:

  • polywrap_http_plugin-0.1.11 - when resolving to an ambigous glob recovery picks up a different resolution than previously (polywrap_msgpack_serde::Result -> serde_json::Result), it has some chain effects resulting in errors
  • polywrap_logger_plugin-0.1.11 - same as polywrap_http_plugin-0.1.11
  • Dhayson.six-degrees-bot.96f810355aa802b6df7a51f2d5c5cdd3d4aba468 - when resolving to an ambigous glob recovery picks up a different resolution than previously (crate::client::Error -> nostr_relay_pool::prelude::Error), it has some chain effects resulting in errors

I think this amount of breakage is acceptable. Fixes to polywrap_* crates were already sent (https://github.com/polywrap/rust-wrap-client/pull/259), but ignored. Dhayson.six-degrees-bot.96f810355aa802b6df7a51f2d5c5cdd3d4aba468 is unpublished, so probably no need to send a fix.

petrochenkov avatar Oct 28 '25 09:10 petrochenkov

Change description for the lang team

This PR implements a long stanging missing piece in cross-crate reexports.

Currently ambiguous glob imports/reexports produce an error like this on local use.

// Crate `mylib`

mod m1 {
    pub struct S {}
}
mod m2 {
    pub struct S {}
}

pub use m1::*;
pub use m2::*;

fn main() {
	let s = self::S {}; // ERROR `S` is ambiguous
}

However, from other crates such reexports are entirely invisible, because they are ignored when encoding rlib metadata.

let s = mylib::S {}; // ERROR cannot resolve `S` in module `mylib`

use mylib::*; // OK, empty glob import, puts no names into the current module

This PR implements the missing metadata encoding and the reexports can now be observed from other crates, so the behavior becomes identical in cross-crate and crate-local scenarios.

let s = mylib::S {}; // ERROR `S` is ambiguous

use mylib::*; // OK, puts one name `S` into the current module, that will produce errors on actual use

// In particular, if we had another glob import importing `S` here, then there will be a new conflict (only on actual use).
// That's why the change is potentially breaking, see the breakage analysis in the comment above.
use thylib::*; // Also imports `S`

petrochenkov avatar Oct 28 '25 09:10 petrochenkov

We talked about this and ended up liking it. This preserves what I might call "ambiguity monotonicity" -- adding ambiguity should never reduce ambiguity warnings.

We'd also like to see a def-site warning about these cases paired with this -- in this PR or otherwise concurrently -- if possible.

@rfcbot fcp merge

traviscross avatar Oct 29 '25 18:10 traviscross

Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

  • [x] @joshtriplett
  • [x] @nikomatsakis
  • [ ] @scottmcm
  • [x] @tmandry
  • [x] @traviscross

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. See this document for info about what commands tagged team members can give me.

rust-rfcbot avatar Oct 29 '25 18:10 rust-rfcbot

@rfcbot reviewed

nikomatsakis avatar Oct 29 '25 18:10 nikomatsakis

FWIW I'd personally like to see that proposed additional warning be in a separate PR, not mixed into this one. I do want to see that warning too, though.

joshtriplett avatar Oct 29 '25 18:10 joshtriplett

I think a def-site warning is important to "shift left" failures like this.

We won't be catching cases where the ambiguity comes from a dependency adding an item in a subsequent version. @nikomatsakis made a suggestion to lint anytime we glob export from two different crates, which I liked. Otherwise, we can at least catch cases where there is a known conflict at the time of writing the code.

@rfcbot reviewed

tmandry avatar Oct 29 '25 18:10 tmandry

:bell: This is now entering its final comment period, as per the review above. :bell:

rust-rfcbot avatar Oct 29 '25 18:10 rust-rfcbot

We'd also like to see a def-site warning about these cases paired with this

I think a def-site warning is important to "shift left" failures like this.

We already have a lint for this - https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#ambiguous-glob-reexports

petrochenkov avatar Oct 29 '25 18:10 petrochenkov

@traviscross

74 regressions are just due to ambiguous_glob_imports being deny-by-default. We could potentially introduce a separate warn-by-default lint extern_ambiguous_glob_imports to soften the transition.

Is there some decision on this ^^^ ?

petrochenkov avatar Oct 29 '25 18:10 petrochenkov

The FCP, as proposed, is to accept that soft breakage.

(I.e., "soft breakage" due to this being from a deny-by-default lint, that could be allowed and is affected by cap-lints, rather than due to a hard error.)

traviscross avatar Oct 29 '25 19:10 traviscross

We already have a lint for this - https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#ambiguous-glob-reexports

Thanks. Yes, that is the lint we were looking for.

traviscross avatar Oct 29 '25 19:10 traviscross