Skip to content

Tweak private re-export errors to point at correct span and have more context - #164218

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
estebank:priv-span-fix
Nov 11, 2026
Merged

rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
estebank:priv-span-fix

Conversation

@estebank

@estebank estebank commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Use the correct span when talking about imported module that should be marked as public:

error[E0364]: `f` is private, and cannot be re-exported
  --> $DIR/privacy-early.rs:10:13
   |
LL |     pub macro m() {
LL |         use f as g;
   |             ^^^^^^
...
LL |     foo::m!();
   |     --------- in this macro invocation
   |
note: consider marking `f` as `pub` in the imported module
  --> $DIR/privacy-early.rs:6:5
   |
LL |     fn f() {}
   |     ^^^^^^^^^

where it was:

error[E0364]: `f` is private, and cannot be re-exported
  --> $DIR/privacy-early.rs:10:13
   |
LL |     pub macro m() {
LL |         use f as g;
   |             ^^^^^^
...
LL |     foo::m!();
   |     --------- in this macro invocation
   |
note: consider marking `f` as `pub` in the imported module
  --> $DIR/privacy-early.rs:10:13
   |
LL |         use f as g;
   |             ^^^^^^
...
LL |     foo::m!();
   |     --------- in this macro invocation

Use span when suggesting making module public:

note: consider declaring module `foo` with `pub`
  --> $DIR/E0365.rs:1:1
   |
LL | / mod foo {
LL | |     pub const X: u32 = 1;
LL | | }
   | |_^

Show container when talking about enclosing module:

note: consider marking `f` as `pub` in the imported module
  --> $DIR/privacy-early.rs:6:5
   |
LL | mod foo {
LL |     fn f() {}
   |     ^^^^^^^^^

Use accurate descriptor for enclosing item:

note: consider declaring struct `S1` with `pub`
  --> $DIR/crate-private-reexport.rs:3:1
   |
LL | / struct S1 {
LL | |     #[rustfmt::skip]
LL | |     bar: i32,
LL | | }
   | |_^
note: consider marking `Full` as `pub` in the imported variant
  --> $DIR/issue-46209-private-enum-variant-reexport.rs:26:9
   |
LL |     enum Lieutenant {
LL |         JuniorGrade,
LL |         Full,
   |         ^^^^

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 12, 2026
@rustbot

rustbot commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

r? @tiif

rustbot has assigned @tiif.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 22 candidates

@estebank estebank changed the title Fix incorrect span to point at private item that should be marked pub Tweak private re-export errors to point at correct span and have more context Oct 12, 2026

@tiif tiif left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice change! I just have a nit.

View changes since this review

Comment on lines +7 to +8
note: consider marking `V` as `pub` in the imported variant
--> $DIR/private-variant-reexport.rs:21:10

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the change from imported module to imported variant intended? I am a bit confused because I interpret this as there is a variant being imported, and we need to mark V as pub within that imported variant 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed: changed to "the imported enum".

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 9, 2026
@rustbot

rustbot commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot

This comment has been minimized.

@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 9, 2026

@tiif tiif left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making diagnostics better!

@bors r+ rollup

View changes since this review

@rust-bors

rust-bors Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a6abf4f has been approved by tiif

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 9, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 10, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #165575 (Upgrade bundled musl to 1.2.6)
 - #163992 (add `core::arch::{x86, x86_64}::x87_f80`)
 - #165117 (std: use skip_unsupported_miri_tests to control when tests should be skipped in Miri due to missing shims)
 - #165458 (fix incorrect byte count suffix on MSVC)
 - #165487 (Migrate built-in macros `pattern_type` & `view_type` to macros 2.0 that expand to internal syntax)
 - #165490 (Mark the compile unit for `-Zdebuginfo-for-profiling`)
 - #165586 (Remove `backend_optimization_level`.)
 - #165646 (fix NumScalableVectors::from_field_count)
 - #165655 (Unignore passing GCC backend tests)
 - #165740 (miri subtree update)
 - #164559 (Windows: fix Dir::remove and Dir::rename following symlinks)
 - #165682 (interpret: ensure newly created unions have uninit in their padding)
 - #165693 (Move `check_attr` to attribute parsing)
 - #165715 (windows: check for null before wide encoding)
 - #165717 (mpsc_sync::stream_send_recv_stress: wait for all threads to finish)
 - #165733 (docs(num): remove needless whitespaces)

Failed merges:

 - #165727 (Normalize "beta release channel" in `const-supertrait-unstable` test)
 - #153261 (Partially stabilize `ptr_alignment_type` as `alignment_type`)
 - #164218 (Tweak private re-export errors to point at correct span and have more context)
 - #165709 (remove 'x miri' smoke test from PR CI)
rust-bors Bot pushed a commit that referenced this pull request Nov 10, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #165575 (Upgrade bundled musl to 1.2.6)
 - #163992 (add `core::arch::{x86, x86_64}::x87_f80`)
 - #165117 (std: use skip_unsupported_miri_tests to control when tests should be skipped in Miri due to missing shims)
 - #165458 (fix incorrect byte count suffix on MSVC)
 - #165490 (Mark the compile unit for `-Zdebuginfo-for-profiling`)
 - #165586 (Remove `backend_optimization_level`.)
 - #165646 (fix NumScalableVectors::from_field_count)
 - #165655 (Unignore passing GCC backend tests)
 - #165740 (miri subtree update)
 - #153261 (Partially stabilize `ptr_alignment_type` as `alignment_type`)
 - #164559 (Windows: fix Dir::remove and Dir::rename following symlinks)
 - #165682 (interpret: ensure newly created unions have uninit in their padding)
 - #165693 (Move `check_attr` to attribute parsing)
 - #165715 (windows: check for null before wide encoding)
 - #165717 (mpsc_sync::stream_send_recv_stress: wait for all threads to finish)
 - #165733 (docs(num): remove needless whitespaces)

Failed merges:

 - #165727 (Normalize "beta release channel" in `const-supertrait-unstable` test)
 - #164218 (Tweak private re-export errors to point at correct span and have more context)
 - #165709 (remove 'x miri' smoke test from PR CI)
rust-bors Bot pushed a commit that referenced this pull request Nov 10, 2026
…uwer

Rollup of 24 pull requests

Successful merges:

 - #165709 (remove 'x miri' smoke test from PR CI)
 - #164217 (Prepare to make `rustc_trivial_field_reads` usable in user code)
 - #165569 (`Move` trait feature gate)
 - #165575 (Upgrade bundled musl to 1.2.6)
 - #163241 (Add enclosing item context when pointing at `FnMut` bound)
 - #163992 (add `core::arch::{x86, x86_64}::x87_f80`)
 - #165047 (Change the span building of paths from first-to-last to chained)
 - #165458 (fix incorrect byte count suffix on MSVC)
 - #165490 (Mark the compile unit for `-Zdebuginfo-for-profiling`)
 - #165586 (Remove `backend_optimization_level`.)
 - #165646 (fix NumScalableVectors::from_field_count)
 - #165655 (Unignore passing GCC backend tests)
 - #165740 (miri subtree update)
 - #165753 (avoid Terminator:None in MIR inliner)
 - #153261 (Partially stabilize `ptr_alignment_type` as `alignment_type`)
 - #164559 (Windows: fix Dir::remove and Dir::rename following symlinks)
 - #165562 (stop using gce in a test)
 - #165681 (Add safety requirements for Pattern and Searcher)
 - #165682 (interpret: ensure newly created unions have uninit in their padding)
 - #165693 (Move `check_attr` to attribute parsing)
 - #165715 (windows: check for null before wide encoding)
 - #165717 (mpsc_sync::stream_send_recv_stress: wait for all threads to finish)
 - #165733 (docs(num): remove needless whitespaces)
 - #165739 (remove NOP File::flush from fs tests)

Failed merges:

 - #165727 (Normalize "beta release channel" in `const-supertrait-unstable` test)
 - #164218 (Tweak private re-export errors to point at correct span and have more context)
rust-bors Bot pushed a commit that referenced this pull request Nov 10, 2026
…uwer

Rollup of 24 pull requests

Successful merges:

 - #165709 (remove 'x miri' smoke test from PR CI)
 - #164217 (Prepare to make `rustc_trivial_field_reads` usable in user code)
 - #165569 (`Move` trait feature gate)
 - #165575 (Upgrade bundled musl to 1.2.6)
 - #163241 (Add enclosing item context when pointing at `FnMut` bound)
 - #163992 (add `core::arch::{x86, x86_64}::x87_f80`)
 - #165047 (Change the span building of paths from first-to-last to chained)
 - #165458 (fix incorrect byte count suffix on MSVC)
 - #165490 (Mark the compile unit for `-Zdebuginfo-for-profiling`)
 - #165586 (Remove `backend_optimization_level`.)
 - #165646 (fix NumScalableVectors::from_field_count)
 - #165655 (Unignore passing GCC backend tests)
 - #165740 (miri subtree update)
 - #165753 (avoid Terminator:None in MIR inliner)
 - #153261 (Partially stabilize `ptr_alignment_type` as `alignment_type`)
 - #164559 (Windows: fix Dir::remove and Dir::rename following symlinks)
 - #165562 (stop using gce in a test)
 - #165681 (Add safety requirements for Pattern and Searcher)
 - #165682 (interpret: ensure newly created unions have uninit in their padding)
 - #165693 (Move `check_attr` to attribute parsing)
 - #165715 (windows: check for null before wide encoding)
 - #165717 (mpsc_sync::stream_send_recv_stress: wait for all threads to finish)
 - #165733 (docs(num): remove needless whitespaces)
 - #165739 (remove NOP File::flush from fs tests)

Failed merges:

 - #165727 (Normalize "beta release channel" in `const-supertrait-unstable` test)
 - #164218 (Tweak private re-export errors to point at correct span and have more context)
@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 10, 2026
@rust-bors

This comment has been minimized.

```
error[E0364]: `f` is private, and cannot be re-exported
  --> $DIR/privacy-early.rs:10:13
   |
LL |     pub macro m() {
LL |         use f as g;
   |             ^^^^^^
...
LL |     foo::m!();
   |     --------- in this macro invocation
   |
note: consider marking `f` as `pub` in the imported module
  --> $DIR/privacy-early.rs:6:5
   |
LL |     fn f() {}
   |     ^^^^^^^^^
```
where it was
```
error[E0364]: `f` is private, and cannot be re-exported
  --> $DIR/privacy-early.rs:10:13
   |
LL |     pub macro m() {
LL |         use f as g;
   |             ^^^^^^
...
LL |     foo::m!();
   |     --------- in this macro invocation
   |
note: consider marking `f` as `pub` in the imported module
  --> $DIR/privacy-early.rs:10:13
   |
LL |         use f as g;
   |             ^^^^^^
...
LL |     foo::m!();
   |     --------- in this macro invocation
```
Use span when suggesting making module public:

```
note: consider declaring module `foo` with `pub`
  --> $DIR/E0365.rs:1:1
   |
LL | / mod foo {
LL | |     pub const X: u32 = 1;
LL | | }
   | |_^
```

Show container when talking about enclosing module:

```
note: consider marking `f` as `pub` in the imported module
  --> $DIR/privacy-early.rs:6:5
   |
LL | mod foo {
LL |     fn f() {}
   |     ^^^^^^^^^
```

Use accurate descriptor for enclosing item:

```
note: consider declaring struct `S1` with `pub`
  --> $DIR/crate-private-reexport.rs:3:1
   |
LL | / struct S1 {
LL | |     #[rustfmt::skip]
LL | |     bar: i32,
LL | | }
   | |_^
```
```
note: consider marking `Full` as `pub` in the imported variant
  --> $DIR/issue-46209-private-enum-variant-reexport.rs:26:9
   |
LL |     enum Lieutenant {
LL |         JuniorGrade,
LL |         Full,
   |         ^^^^
```
@rustbot

rustbot commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main 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.

@estebank

Copy link
Copy Markdown
Contributor Author

@bors r=tiif

@rust-bors

rust-bors Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

📌 Commit bef8da0 has been approved by tiif

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 11, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 11, 2026
Rollup of 9 pull requests

Successful merges:

 - #165117 (std: use skip_unsupported_miri_tests to control when tests should be skipped in Miri due to missing shims)
 - #165727 (Normalize "beta release channel" in `const-supertrait-unstable` test)
 - #165750 (Wrap proc-macro `EscapeError` enum into a struct)
 - #164218 (Tweak private re-export errors to point at correct span and have more context)
 - #165021 (In irrefutable patterns, the FieldPat is skipped, which means the name: field is not printed)
 - #165537 (Canonicalization cleanups)
 - #165772 (Remove unnecessary mut from HirIdValidator::check_nested_id)
 - #165779 (make improper_ctypes accept `x87_f80`)
 - #165780 (std: map more errno values to ErrorKind on Hermit)
@rust-bors
rust-bors Bot merged commit 28e8e1b into rust-lang:main Nov 11, 2026
14 checks passed
rust-bors Bot pushed a commit that referenced this pull request Nov 11, 2026
Rollup merge of #164218 - estebank:priv-span-fix, r=tiif

Tweak private re-export errors to point at correct span and have more context

Use the correct span when talking about imported module that should be marked as public:
```
error[E0364]: `f` is private, and cannot be re-exported
  --> $DIR/privacy-early.rs:10:13
   |
LL |     pub macro m() {
LL |         use f as g;
   |             ^^^^^^
...
LL |     foo::m!();
   |     --------- in this macro invocation
   |
note: consider marking `f` as `pub` in the imported module
  --> $DIR/privacy-early.rs:6:5
   |
LL |     fn f() {}
   |     ^^^^^^^^^
```
where it was:
```
error[E0364]: `f` is private, and cannot be re-exported
  --> $DIR/privacy-early.rs:10:13
   |
LL |     pub macro m() {
LL |         use f as g;
   |             ^^^^^^
...
LL |     foo::m!();
   |     --------- in this macro invocation
   |
note: consider marking `f` as `pub` in the imported module
  --> $DIR/privacy-early.rs:10:13
   |
LL |         use f as g;
   |             ^^^^^^
...
LL |     foo::m!();
   |     --------- in this macro invocation
```

Use span when suggesting making module public:

```
note: consider declaring module `foo` with `pub`
  --> $DIR/E0365.rs:1:1
   |
LL | / mod foo {
LL | |     pub const X: u32 = 1;
LL | | }
   | |_^
```

Show container when talking about enclosing module:

```
note: consider marking `f` as `pub` in the imported module
  --> $DIR/privacy-early.rs:6:5
   |
LL | mod foo {
LL |     fn f() {}
   |     ^^^^^^^^^
```

Use accurate descriptor for enclosing item:

```
note: consider declaring struct `S1` with `pub`
  --> $DIR/crate-private-reexport.rs:3:1
   |
LL | / struct S1 {
LL | |     #[rustfmt::skip]
LL | |     bar: i32,
LL | | }
   | |_^
```
```
note: consider marking `Full` as `pub` in the imported variant
  --> $DIR/issue-46209-private-enum-variant-reexport.rs:26:9
   |
LL |     enum Lieutenant {
LL |         JuniorGrade,
LL |         Full,
   |         ^^^^
```
@rustbot rustbot added this to the 1.102.0 milestone Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants