Skip to content

Comments

Expose Span for all DefIds in rustc_public#152912

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
HKalbasi:rustc_public_def_span
Feb 21, 2026
Merged

Expose Span for all DefIds in rustc_public#152912
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
HKalbasi:rustc_public_def_span

Conversation

@HKalbasi
Copy link
Member

Part of rust-lang/project-stable-mir#118

To be maximally useful, VariantDef and FieldDef should be changed to be a wrapper around DefId instead of holding their parent and index. I can do this change in this PR or a follow-up if it is desired. For now, I added the missing impl Stable for DefId in internals so you can convert from rustc internals.

@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2026

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

@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 Feb 20, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2026

r? @scottmcm

rustbot has assigned @scottmcm.
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: project-stable-mir
  • project-stable-mir expanded to celinval, makai410, oli-obk, scottmcm
  • Random selection from celinval, makai410, scottmcm

@HKalbasi HKalbasi force-pushed the rustc_public_def_span branch from fdce1f8 to 1ded3a6 Compare February 20, 2026 14:30
Copy link
Member

@makai410 makai410 left a comment

Choose a reason for hiding this comment

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

Thanks! r=me when you resolve the comment.

View changes since this review

Comment on lines +85 to +96
impl<'tcx> Stable<'tcx> for rustc_span::def_id::DefId {
type T = crate::DefId;

fn stable<'cx>(
&self,
tables: &mut Tables<'cx, BridgeTys>,
_: &CompilerCtxt<'cx, BridgeTys>,
) -> Self::T {
tables.create_def_id(*self)
}
}

Copy link
Member

Choose a reason for hiding this comment

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

I believe we don't really need this impl. We can just use create_def_id everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

create_def_id is not publicly available. This impl enables rustc_public::rustc_internal::stable for creating DefId for variants, which is not possible using current rustc_public api. Is there any downside for having this impl?

Copy link
Member

@makai410 makai410 Feb 20, 2026

Choose a reason for hiding this comment

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

The Stable trait is also not publicly available and shouldn't be exposed to users, so adding this impl here doesn't make sense for getting the DefId of a variant. I think we probably could add an api to the CompilerInterface for retrieving the DefId of a VariantDef given that we have the Internal trait implemented for VariantDef, then we don't have to store a def_id in that struct.

Copy link
Member Author

Choose a reason for hiding this comment

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

The rustc_public::unstable::Stable trait is not public, but the rustc_public::rustc_internal::stable function is public for users who mix rustc_public with unstable rustc apis (like me).

Adding an api for retrieving DefId from a variant is needed for the completeness of rustc_public, but even with that, I think this impl is useful for the stable function users.

Copy link
Member

Choose a reason for hiding this comment

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

Ah gotcha.

@makai410
Copy link
Member

r? me
@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 20, 2026

📌 Commit 1ded3a6 has been approved by makai410

It is now in the queue for this repository.

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

Rollup of 9 pull requests

Successful merges:

 - #146832 (Not linting irrefutable_let_patterns on let chains)
 - #146972 (Support importing path-segment keyword with renaming)
 - #152241 (For panic=unwind on Wasm targets, define __cpp_exception tag)
 - #152527 (Remove -Zemit-thin-lto flag)
 - #152769 (Do not cancel try builds after first job failure)
 - #152907 (Add tests for delegation generics)
 - #152455 (Remove the translation `-Z` options and the `Translator` type. )
 - #152813 (Skip the `use_existential_projection_new_instead` field in the `Debug` impl)
 - #152912 (Expose Span for all DefIds in rustc_public)
@rust-bors rust-bors bot merged commit 7655d93 into rust-lang:main Feb 21, 2026
11 checks passed
rust-timer added a commit that referenced this pull request Feb 21, 2026
Rollup merge of #152912 - HKalbasi:rustc_public_def_span, r=makai410

Expose Span for all DefIds in rustc_public

Part of rust-lang/project-stable-mir#118

To be maximally useful, `VariantDef` and `FieldDef` should be changed to be a wrapper around `DefId` instead of holding their parent and index. I can do this change in this PR or a follow-up if it is desired. For now, I added the missing `impl Stable for DefId` in internals so you can convert from rustc internals.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Feb 22, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#146832 (Not linting irrefutable_let_patterns on let chains)
 - rust-lang/rust#146972 (Support importing path-segment keyword with renaming)
 - rust-lang/rust#152241 (For panic=unwind on Wasm targets, define __cpp_exception tag)
 - rust-lang/rust#152527 (Remove -Zemit-thin-lto flag)
 - rust-lang/rust#152769 (Do not cancel try builds after first job failure)
 - rust-lang/rust#152907 (Add tests for delegation generics)
 - rust-lang/rust#152455 (Remove the translation `-Z` options and the `Translator` type. )
 - rust-lang/rust#152813 (Skip the `use_existential_projection_new_instead` field in the `Debug` impl)
 - rust-lang/rust#152912 (Expose Span for all DefIds in rustc_public)
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Feb 23, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#146832 (Not linting irrefutable_let_patterns on let chains)
 - rust-lang/rust#146972 (Support importing path-segment keyword with renaming)
 - rust-lang/rust#152241 (For panic=unwind on Wasm targets, define __cpp_exception tag)
 - rust-lang/rust#152527 (Remove -Zemit-thin-lto flag)
 - rust-lang/rust#152769 (Do not cancel try builds after first job failure)
 - rust-lang/rust#152907 (Add tests for delegation generics)
 - rust-lang/rust#152455 (Remove the translation `-Z` options and the `Translator` type. )
 - rust-lang/rust#152813 (Skip the `use_existential_projection_new_instead` field in the `Debug` impl)
 - rust-lang/rust#152912 (Expose Span for all DefIds in rustc_public)
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.

4 participants