Skip to content

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Oct 7, 2025

Previously, the local crate would always be printed as a leading crate::. Allow resolving it to the crate name instead.

This allows printing a fully qualified path with:

let qualified_name = with_no_visible_paths!(with_resolve_crate_name!(
    with_no_trimmed_paths!(tcx.def_path_str(def_id))
));

I found this useful for an out-of-tree rustc-driver. I do not currently have a usecase in mind upstream; I'm ok if you don't want this PR for that reason. See #t-compiler/help > print a fully qualified path name? @ 💬 for additional context.

This does not currently have tests. I am not aware of an easy way to test def-id printing, since it requires having access to a TyCtxt.

@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 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 7, 2025

r? @nnethercote

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

/// Adds the crate name prefix to paths where appropriate.
/// Unlike `with_crate_prefix`, this unconditionally uses `tcx.crate_name` instead of sometimes
/// using `crate::` for local items.
fn with_resolve_crate_name(CrateNamePrefixGuard, SHOULD_PREFIX_WITH_CRATE_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

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

The interaction between SHOULD_PREFIX_WITH_CRATE and SHOULD_PREFIX_WITH_CRATE_NAME is unclear. This extends an existing problem with these flags, which is how they all interact is confusing. E.g. with_no_trimmed_paths vs with_forced_trimmed_paths. Perhaps some of them need to be tri-state enums instead of booleans?

Copy link
Member Author

Choose a reason for hiding this comment

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

tri-state enums seem reasonable, but the API doesn't expose anything like that currently. we'd need to switch away from with!( ... ) macros to something like with!(CratePrinting::Expanded, ...).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it would be a follow-up for sure.

@nnethercote
Copy link
Contributor

r=me if you (a) clarify how WITH_CRATE interacts with WITH_CRATE_NAME, and (b) add a comment explaining that it's not used in the compiler but might be useful in out-of-tree drivers (so someone like me doesn't come along and remove it as unused).

Previously, the local crate would always be printed as a leading `crate::`.
Allow resolving it to the crate name instead.

This allows printing a fully qualified path with:
```rust
let qualified_name = with_no_visible_paths!(with_resolve_crate_name!(
    with_no_trimmed_paths!(tcx.def_path_str(def_id))
));
```

I found this useful for an out-of-tree rustc-driver. I do not currently
have a usecase in mind upstream; I'm ok if you don't want this PR for
that reason.

This does not currently have tests. I am not aware of an easy way to
test def-id printing, since it requires having access to a TyCtxt.
@jyn514 jyn514 force-pushed the fully-qualified-paths branch from 2e12508 to fa9162d Compare October 8, 2025 12:38
@jyn514
Copy link
Member Author

jyn514 commented Oct 9, 2025

👋 I see you commented but did not approve, so I just wanted to give a heads-up this is ready for re-review ^^

@nnethercote
Copy link
Contributor

Sorry, the r=me was an implicit delegation.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 9, 2025

📌 Commit fa9162d has been approved by nnethercote

It is now in the queue for this repository.

@bors bors 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 Oct 9, 2025
@bors
Copy link
Collaborator

bors commented Oct 10, 2025

⌛ Testing commit fa9162d with merge 627c4bf...

bors added a commit that referenced this pull request Oct 10, 2025
Allow printing a fully-qualified path in `def_path_str`

Previously, the local crate would always be printed as a leading `crate::`. Allow resolving it to the crate name instead.

This allows printing a fully qualified path with:
```rust
let qualified_name = with_no_visible_paths!(with_resolve_crate_name!(
    with_no_trimmed_paths!(tcx.def_path_str(def_id))
));
```

I found this useful for an out-of-tree rustc-driver. I do not currently have a usecase in mind upstream; I'm ok if you don't want this PR for that reason. See [#t-compiler/help > print a fully qualified path name? @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/print.20a.20fully.20qualified.20path.20name.3F/near/541560961) for additional context.

This does not currently have tests. I am not aware of an easy way to test def-id printing, since it requires having access to a TyCtxt.
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-debug failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#10 29.33 Setting up libssl-dev:arm64 (3.5.3-1ubuntu2) ...
#10 29.35 Setting up libmpc3:arm64 (1.3.1-1build3) ...
#10 29.37 Setting up libatomic1:arm64 (15.2.0-4ubuntu4) ...
#10 29.39 Setting up sudo (1.9.17p2-1ubuntu1) ...
#10 29.45 update-alternatives: using /usr/bin/sudo.ws to provide /usr/bin/sudo (sudo) in auto mode
#10 29.45 update-alternatives: warning: skip creation of /usr/share/man/man8/sudo.8.gz because associated file /usr/share/man/man8/sudo.ws.8.gz (of link group sudo) doesn't exist
#10 29.45 update-alternatives: warning: skip creation of /usr/share/man/man8/sudoedit.8.gz because associated file /usr/share/man/man8/sudo.ws.8.gz (of link group sudo) doesn't exist
#10 29.45 update-alternatives: warning: skip creation of /usr/share/man/man5/sudoers.5.gz because associated file /usr/share/man/man5/sudoers.ws.5.gz (of link group sudo) doesn't exist
#10 29.45 update-alternatives: warning: skip creation of /usr/share/man/man8/visudo.8.gz because associated file /usr/share/man/man8/visudo.ws.8.gz (of link group sudo) doesn't exist
#10 29.46 Setting up ucf (3.0052) ...
#10 29.49 Setting up pkgconf-bin (1.8.1-4build1) ...
#10 29.51 Setting up libk5crypto3:arm64 (1.21.3-5ubuntu2) ...
#10 29.53 Setting up libgc1:arm64 (1:8.2.8-1) ...
#10 29.55 Setting up libsasl2-2:arm64 (2.1.28+dfsg1-9ubuntu1) ...
---

  --- stderr
  clang: error: unsupported option '-print-multi-os-directory'
  clang: error: no input files
  config.status: error: in `/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-tools/aarch64-unknown-linux-gnu/release/build/libffi-sys-6562d98fd0e95724/out/libffi-build/aarch64-unknown-linux-gnu':
  config.status: error: Something went wrong bootstrapping makefile fragments
      for automatic dependency tracking.  If GNU make was not used, consider
      re-running the configure script with MAKE="gmake" (or whatever is
      necessary).  You can also try re-running configure with the
      '--disable-dependency-tracking' option to at least be able to build
      the package (albeit without support for automatic dependency tracking).
  See `config.log' for more details

  thread 'main' (101315) panicked at /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libffi-sys-3.3.2/build/not_msvc.rs:154:5:
  Configuring libffi: exit status: 1 (cd "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-tools/aarch64-unknown-linux-gnu/release/build/libffi-sys-6562d98fd0e95724/out/libffi-build" && CC="clang" CFLAGS="-O3 -ffunction-sections -fdata-sections -fPIC -gdwarf-4 -fno-omit-frame-pointer --target=aarch64-unknown-linux-gnu -Wno-implicit-function-declaration" LC_ALL="C" "sh" "./configure" "--with-pic" "--disable-shared" "--disable-docs" "--prefix" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-tools/aarch64-unknown-linux-gnu/release/build/libffi-sys-6562d98fd0e95724/out/libffi-root")
  stack backtrace:
     0: __rustc::rust_begin_unwind
               at /checkout/library/std/src/panicking.rs:698:5
     1: core::panicking::panic_fmt
               at /checkout/library/core/src/panicking.rs:80:14
     2: build_script_build::common::run_command
               at ./build/common.rs:13:13
     3: build_script_build::not_msvc::configure_libffi
               at ./build/not_msvc.rs:154:5
     4: build_script_build::not_msvc::build_and_link
               at ./build/not_msvc.rs:39:5
     5: build_script_build::main
               at ./build/build.rs:16:9
     6: core::ops::function::FnOnce::call_once
               at /checkout/library/core/src/ops/function.rs:250:5
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@bors
Copy link
Collaborator

bors commented Oct 10, 2025

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 10, 2025
@jyn514
Copy link
Member Author

jyn514 commented Oct 10, 2025

Sorry, the r=me was an implicit delegation.

gotcha — just FYI I no longer have bors merge rights.

@nnethercote
Copy link
Contributor

@rustbot author

@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 Oct 13, 2025
@jyn514
Copy link
Member Author

jyn514 commented Oct 13, 2025

i believe the failure was spurious, see #147556

@rustbot ready

@rustbot rustbot 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 Oct 13, 2025
@RalfJung
Copy link
Member

Yeah this should be retried
@bors retry

@bors bors 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 Oct 15, 2025
bors added a commit that referenced this pull request Oct 15, 2025
Rollup of 11 pull requests

Successful merges:

 - #143191 (Stabilize `rwlock_downgrade` library feature)
 - #147444 (Allow printing a fully-qualified path in `def_path_str`)
 - #147527 (Update t-compiler beta nomination Zulip msg)
 - #147670 (some `ErrorGuaranteed` cleanups)
 - #147676 (Return spans out of `is_doc_comment` to reduce reliance on `.span()` on attributes)
 - #147708 (const `mem::drop`)
 - #147710 (Fix ICE when using contracts on async functions)
 - #147716 (Fix some comments)
 - #147718 (miri: use allocator_shim_contents codegen helper)
 - #147729 (ignore boring locals when explaining why a borrow contains a point due to drop of a live local under polonius)
 - #147742 (Revert unintentional whitespace changes to rustfmt-excluded file)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 88efae3 into rust-lang:master Oct 16, 2025
10 of 11 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 16, 2025
rust-timer added a commit that referenced this pull request Oct 16, 2025
Rollup merge of #147444 - jyn514:fully-qualified-paths, r=nnethercote

Allow printing a fully-qualified path in `def_path_str`

Previously, the local crate would always be printed as a leading `crate::`. Allow resolving it to the crate name instead.

This allows printing a fully qualified path with:
```rust
let qualified_name = with_no_visible_paths!(with_resolve_crate_name!(
    with_no_trimmed_paths!(tcx.def_path_str(def_id))
));
```

I found this useful for an out-of-tree rustc-driver. I do not currently have a usecase in mind upstream; I'm ok if you don't want this PR for that reason. See [#t-compiler/help > print a fully qualified path name? @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/print.20a.20fully.20qualified.20path.20name.3F/near/541560961) for additional context.

This does not currently have tests. I am not aware of an easy way to test def-id printing, since it requires having access to a TyCtxt.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Oct 16, 2025
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#143191 (Stabilize `rwlock_downgrade` library feature)
 - rust-lang/rust#147444 (Allow printing a fully-qualified path in `def_path_str`)
 - rust-lang/rust#147527 (Update t-compiler beta nomination Zulip msg)
 - rust-lang/rust#147670 (some `ErrorGuaranteed` cleanups)
 - rust-lang/rust#147676 (Return spans out of `is_doc_comment` to reduce reliance on `.span()` on attributes)
 - rust-lang/rust#147708 (const `mem::drop`)
 - rust-lang/rust#147710 (Fix ICE when using contracts on async functions)
 - rust-lang/rust#147716 (Fix some comments)
 - rust-lang/rust#147718 (miri: use allocator_shim_contents codegen helper)
 - rust-lang/rust#147729 (ignore boring locals when explaining why a borrow contains a point due to drop of a live local under polonius)
 - rust-lang/rust#147742 (Revert unintentional whitespace changes to rustfmt-excluded file)

r? `@ghost`
`@rustbot` modify labels: rollup
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.

6 participants