Skip to content

Document module resolution inside include!#158001

Closed
ChronoCoders wants to merge 1 commit into
rust-lang:mainfrom
ChronoCoders:docs-include-mod-resolution
Closed

Document module resolution inside include!#158001
ChronoCoders wants to merge 1 commit into
rust-lang:mainfrom
ChronoCoders:docs-include-mod-resolution

Conversation

@ChronoCoders

@ChronoCoders ChronoCoders commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

include! resolves mod declarations in the included file relative to that file's directory, not the file holding the include! call. The docs never said so and people hit it, for instance with build-script output that contains mod. This adds a short note and points at #[path] for overriding it.

Fixes #149810

A `mod` declaration in an included file is resolved relative to the
included file's directory, not the directory of the file that contains
the `include!` invocation. That trips people up, so spell it out in the
macro docs and point at the `#[path]` attribute for overriding it.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 17, 2026
@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aapoalas (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 11 candidates
  • Random selection from 7 candidates

@aapoalas aapoalas left a comment

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.

Thank you for the doc improvement: this looks good to me, I'll try get a second pair of (more experienced) eyes on this as well to make sure this is fine just to be sure, as I'm very new to this whole review stuff :)

View changes since this review

@aapoalas

Copy link
Copy Markdown
Contributor

r? lang

Perhaps best that lang blesses this as it's more of a language primitive just exposed from the std.

@rustbot rustbot added the T-lang Relevant to the language team label Jun 23, 2026
@rustbot rustbot assigned nikomatsakis and unassigned aapoalas Jun 23, 2026
@petrochenkov

petrochenkov commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

This behavior is actually accidental, but it's probably too late to fix it at this point.
#69838 is the PR that properly implemented module loading in presence of macro expansions and encountered the issue with include!. Then #70184 added a hack to preserve the old behavior of include! for compatibility.

Upd: ah, the tracking issue actually talks about this too - #149810 (comment).

@ChronoCoders ChronoCoders closed this by deleting the head repository Jun 28, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-lang Relevant to the language team T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

include! docs don't explain how mod is resolved

5 participants