Skip to content

Suggest function-local constructors without enclosing function path#156889

Open
onehr wants to merge 1 commit into
rust-lang:mainfrom
onehr:fix-local-tuple-constructor-suggestion-144319
Open

Suggest function-local constructors without enclosing function path#156889
onehr wants to merge 1 commit into
rust-lang:mainfrom
onehr:fix-local-tuple-constructor-suggestion-144319

Conversation

@onehr
Copy link
Copy Markdown
Contributor

@onehr onehr commented May 24, 2026

Closes #144319

This fixes a mismatched-type wrapper suggestion for constructors defined inside
function-like scopes. The previous diagnostic used def_path_str directly, so a
function-local tuple struct could be suggested as main::Foo(false), even though
main is not a module path that can name the constructor.

The suggestion now prints the constructor path under rustc's existing suggestion
printer mode. That mode omits path segments that cannot be written in source,
while preserving real path segments such as local modules and enum names.

The regression test covers:

  • a function-local tuple struct constructor
  • a function-local enum variant
  • a tuple struct inside a function-local module
  • a tuple struct inside a closure body
  • a tuple struct inside an inline const block

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 24, 2026
@onehr onehr marked this pull request as ready for review May 25, 2026 00:59
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 25, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 25, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 25, 2026

r? @jieyouxu

rustbot has assigned @jieyouxu.
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 73 candidates
  • Random selection from 19 candidates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid suggestion for wrapping unnamable types, uses function name as module

3 participants