Skip to content

Fix name() functions for local defs in rustc_public - #149401

Merged
bors merged 2 commits into
rust-lang:mainfrom
celinval:smir-109-name
Dec 6, 2025
Merged

Fix name() functions for local defs in rustc_public#149401
bors merged 2 commits into
rust-lang:mainfrom
celinval:smir-109-name

Conversation

@celinval

@celinval celinval commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

This change fixes the behavior of the name() function for CrateDef and Instance which should return absolute path of items. For local items, the crate name was missing.

This resolves: rust-lang/rustc_public#109

@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 Nov 27, 2025
@rustbot

rustbot commented Nov 27, 2025

Copy link
Copy Markdown
Collaborator

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

@rust-log-analyzer

This comment has been minimized.

@celinval

celinval commented Nov 27, 2025

Copy link
Copy Markdown
Contributor Author

It looks like I need to do some debugging. It's not clear to me why this change affected these tests. I.e., why:

std::task::Poll::Ready -> Poll::Ready
std::option::Option::None -> Option::None

It seems to only affect std ADTs variants.

EDIT: Looking at the pretty print file, before this change, the types Option and Arguments did not include absolute path, but the variant std::option::Option::None did. This uses display not path.

@rustbot

rustbot commented Nov 28, 2025

Copy link
Copy Markdown
Collaborator

This PR changes rustc_public

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

@oli-obk

oli-obk commented Nov 28, 2025

Copy link
Copy Markdown
Contributor

You removed with_no_trimmed_paths. If an import in a file exists that allows accessing sth via a shorter path, it gets trimmed. Std is always imported, and some types are also in the prelude. Those always get trimmed

@celinval

Copy link
Copy Markdown
Contributor Author

You removed with_no_trimmed_paths. If an import in a file exists that allows accessing sth via a shorter path, it gets trimmed. Std is always imported, and some types are also in the prelude. Those always get trimmed

Thanks @oli-obk. So how should I use with_resolve_crate_name ? Do I need to use it together with with_no_trimmed_path?

@celinval

celinval commented Nov 29, 2025

Copy link
Copy Markdown
Contributor Author

Beautiful. @oli-obk it worked like a charm. I changed the pretty printer to use trimmed_name to make it less verbose. Thanks!

@makai410

Copy link
Copy Markdown
Member

Seems like this PR also fixes rust-lang/rustc_public#41?

@celinval

Copy link
Copy Markdown
Contributor Author

Seems like this PR also fixes rust-lang/project-stable-mir#41?

Good question. I haven't tried it yet

// WARNING: This is highly experimental output it's intended for rustc_public developers only.
// If you find a bug or want to improve the output open a issue at https://github.com/rust-lang/project-stable-mir.
fn operands(_1: u8) -> () {
fn operands::operands(_1: u8) -> () {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's slightly odd, that the body item gets a full path but things inside the body are local. wfm, just a small oddity

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.

Indeed. I probably missed something. Let me check

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

The `name()` function specifies that it returns absolute path of items,
however it wasn't including the crate name for local items.

This change fixes that.

This was reported here: rust-lang/rustc_public#109
@rustbot

rustbot commented Dec 1, 2025

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.

@scottmcm

scottmcm commented Dec 6, 2025

Copy link
Copy Markdown
Member

I'm far from an expert on names, but the code change here looks non-scary to me, and the (admittedly not nearly all) tests I skimmed seemed like the output update was reasonable, so sure!

@bors r+

@bors

bors commented Dec 6, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit bb2bfc3 has been approved by scottmcm

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 Dec 6, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Dec 6, 2025
Fix `name()` functions for local defs in rustc_public

This change fixes the behavior of the `name()` function for `CrateDef` and `Instance` which should return absolute path of items. For local items, the crate name was missing.

This resolves: rust-lang/rustc_public#109
bors added a commit that referenced this pull request Dec 6, 2025
Rollup of 5 pull requests

Successful merges:

 - #146826 (Implement `Allocator` for `&mut A` where `A: Allocator + ?Sized`)
 - #148487 (add Option::into_flat_iter)
 - #148814 (stabilize `array_windows`)
 - #149401 (Fix `name()` functions for local defs in rustc_public)
 - #149683 (Fix armv8r-none-eabihf tier)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 4c8c967 into rust-lang:main Dec 6, 2025
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Dec 6, 2025
rust-timer added a commit that referenced this pull request Dec 6, 2025
Rollup merge of #149401 - celinval:smir-109-name, r=scottmcm

Fix `name()` functions for local defs in rustc_public

This change fixes the behavior of the `name()` function for `CrateDef` and `Instance` which should return absolute path of items. For local items, the crate name was missing.

This resolves: rust-lang/rustc_public#109
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Dec 13, 2025
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#146826 (Implement `Allocator` for `&mut A` where `A: Allocator + ?Sized`)
 - rust-lang/rust#148487 (add Option::into_flat_iter)
 - rust-lang/rust#148814 (stabilize `array_windows`)
 - rust-lang/rust#149401 (Fix `name()` functions for local defs in rustc_public)
 - rust-lang/rust#149683 (Fix armv8r-none-eabihf tier)

r? `@ghost`
`@rustbot` modify labels: rollup
makai410 pushed a commit to makai410/rustc_public that referenced this pull request Dec 16, 2025
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#146826 (Implement `Allocator` for `&mut A` where `A: Allocator + ?Sized`)
 - rust-lang/rust#148487 (add Option::into_flat_iter)
 - rust-lang/rust#148814 (stabilize `array_windows`)
 - rust-lang/rust#149401 (Fix `name()` functions for local defs in rustc_public)
 - rust-lang/rust#149683 (Fix armv8r-none-eabihf tier)

r? `@ghost`
`@rustbot` modify labels: rollup
makai410 pushed a commit to makai410/rust that referenced this pull request Dec 16, 2025
Fix `name()` functions for local defs in rustc_public

This change fixes the behavior of the `name()` function for `CrateDef` and `Instance` which should return absolute path of items. For local items, the crate name was missing.

This resolves: rust-lang/rustc_public#109
makai410 pushed a commit to makai410/rust that referenced this pull request Dec 16, 2025
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#146826 (Implement `Allocator` for `&mut A` where `A: Allocator + ?Sized`)
 - rust-lang#148487 (add Option::into_flat_iter)
 - rust-lang#148814 (stabilize `array_windows`)
 - rust-lang#149401 (Fix `name()` functions for local defs in rustc_public)
 - rust-lang#149683 (Fix armv8r-none-eabihf tier)

r? `@ghost`
`@rustbot` modify labels: rollup
makai410 pushed a commit to makai410/rustc_public that referenced this pull request Mar 19, 2026
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#146826 (Implement `Allocator` for `&mut A` where `A: Allocator + ?Sized`)
 - rust-lang/rust#148487 (add Option::into_flat_iter)
 - rust-lang/rust#148814 (stabilize `array_windows`)
 - rust-lang/rust#149401 (Fix `name()` functions for local defs in rustc_public)
 - rust-lang/rust#149683 (Fix armv8r-none-eabihf tier)

r? `@ghost`
`@rustbot` modify labels: rollup
makai410 pushed a commit to makai410/rustc_public that referenced this pull request Mar 27, 2026
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#146826 (Implement `Allocator` for `&mut A` where `A: Allocator + ?Sized`)
 - rust-lang/rust#148487 (add Option::into_flat_iter)
 - rust-lang/rust#148814 (stabilize `array_windows`)
 - rust-lang/rust#149401 (Fix `name()` functions for local defs in rustc_public)
 - rust-lang/rust#149683 (Fix armv8r-none-eabihf tier)

r? `@ghost`
`@rustbot` modify labels: rollup
tautschnig added a commit to tautschnig/kani that referenced this pull request Jul 8, 2026
rust-lang/rust#149401 fixed rustc_public's `Instance::name()` (and
`CrateItem::name()`) to return the true absolute path, which now includes
the crate name for *local* items too (e.g. `my_crate::my_fn` instead of
`my_fn`, and `<my_crate::T as my_crate::Tr>::m` instead of `<T as Tr>::m`).
Kani feeds these names into user-facing output ("Checking harness ...",
"Verification failed for - ...", stubbing diagnostics) and into CBMC symbol
pretty-names ("in function ..."), so the bump to nightly-2025-12-16 made
~160 `expected` tests fail on the newly crate-qualified names.

Add `strip_local_crate_prefix` (and the `readable_name` wrapper) in
kani_middle, which removes the local crate name at each path-component
*qualifier* position (start, or after a delimiter such as `<`, `,`, ` `),
while preserving continuation segments after `::` so a module/item that
shares the crate's name (e.g. crate `main` with `fn main`) is not
over-stripped. Non-local paths (`std::...`) are unaffected. Apply it at the
harness pretty-name, function/static symbol pretty-name, current-function
readable name, and the two stubbing diagnostics.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig added a commit to tautschnig/kani that referenced this pull request Jul 8, 2026
The contract-recursion tests (e.g. generic_infinity_recursion,
gcd_rec_simple_pass) regressed on nightly-2025-12-16: the recursive-call
precondition was spuriously falsifiable. Root cause is the same
rust-lang/rust#149401 name change: `find_recursion_tracker` builds the
`--nondet-static-exclude` value from `static_item.name()`, which is now
crate-qualified (`t::foo::{closure#0}::REENTRY`). CBMC matches that value
against the static's crate-relative pretty name, so the qualified value no
longer matches, `REENTRY` is not excluded from `--nondet-static`, and the
recursion tracker is havocked to a nondet value. With `REENTRY` nondet the
top-level contract call can take the REPLACE path (which *asserts* the
precondition) instead of the CHECK path (which *assumes* it), so the
precondition fails on a nondet input.

Strip the local crate prefix here too (matching `readable_name`), restoring
the match. Verified: the full `expected` suite is green again.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig added a commit to tautschnig/kani that referenced this pull request Jul 8, 2026
Extend the rust-lang/rust#149401 crate-prefix stripping (`strip_local_crate_prefix`
/ `readable_name`) to the stubbing validation error messages that still emitted
crate-qualified item names, which broke the `ui` stubbing tests: the arity- and
generic-parameter-mismatch errors, the trait-mismatch ("cannot be stubbed by")
error, the "does not have a body" resolution notes, and the "stub verified
target ... does not have a corresponding proof_for_contract harness" error.

The `ui` suite is green again (144 passed, 0 failed).

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig added a commit to tautschnig/kani that referenced this pull request Jul 9, 2026
Three follow-ups from the nightly-2025-12-31 bump surfaced by CI:

- clippy `result_large_err` on `ensure_non_empty_span`: the `Err` type is
  rustc's `SpanSnippetError`, which grew and now trips the lint. `#[allow]` it
  (we can't shrink an upstream type).
- LLBC backend (`--features llbc`, not built in the default job): its
  `translate_operand` needs an arm for the new `Operand::RuntimeChecks`
  (rust-lang/rust#148766); left as `todo!()` like the backend's other
  unmodeled cases.
- The stub-cycle error ("Stub configuration for harness `..` has a cycle") also
  embedded a crate-qualified harness name (rust-lang/rust#149401); strip it,
  fixing cargo-kani/stubbing-double-extern-path.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig added a commit to tautschnig/kani that referenced this pull request Jul 9, 2026
rust-lang/rust#149401 made `name()` crate-qualify local items, which broke
the autoharness and `list` features:

- metadata.rs: the automatic-contract-harness lookup matched the (now
  crate-relative) harness `target_fn` against the fully-qualified
  `ContractedFunction.function`, panicking on the `.unwrap()`. Store all
  contract/harness names crate-relative so display and lookup are consistent.
- codegen_units.rs: strip the crate prefix from the autoharness `chosen` and
  `skipped` function names (the `Selected Function` list column), and from the
  autoharness filter name, which #149401 had made doubly crate-qualified
  (`crate::crate::fn`).

Fixes the script-based-pre autoharness/list/autoderive regression tests.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
feliperodri pushed a commit to AlexanderPortland/kani that referenced this pull request Jul 11, 2026
Upgrade the toolchain to `nightly-2025-12-31` and adapt Kani to the
corresponding
`rustc`/`rustc_public` changes:

- **Crate-qualified names** (rust-lang/rust#149401): `name()` now
qualifies local
items with the crate name. Add a `strip_local_crate_prefix` helper and
keep
  harness/function/static pretty names, the recursion-tracker
`--nondet-static-exclude`, stubbing diagnostics, and the
autoharness/`list`
output crate-relative; fix the automatic contract-harness lookup
accordingly.
- **MIR runtime checks** (rust-lang/rust#148766):
`Rvalue::NullaryOp`/`NullOp`
  were removed and the `ub`/`contract`/`overflow` checks moved to
`Operand::RuntimeChecks`; update the CPROVER and LLBC codegen and the
related
  analyses.
- **`unsized_fn_params`**: the updated std passes unsized values by
value (e.g.
`impl … for [&str]`). Represent unsized-by-value arguments as fat
pointers so
they codegen instead of triggering an ICE (test under
`tests/kani/UnsizedFnParams`).
- Smaller adaptations: `FieldsShape::…::in_memory_order`
(rust-lang/rust#150116),
the new `ValueAbi::ScalableVector` variant, the `HumanReadableErrorType`
struct
  form, coercion/safety cleanups (rust-lang/rust#148602), a refreshed
`pointer_generator_error` expected file, and a
`clippy::result_large_err` allow.

Resolves: model-checking#4623

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.

---------

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
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.

Function path is stripped of root for local crate

7 participants