Skip to content

Conversation

@TanmayArya-1p
Copy link
Contributor

@TanmayArya-1p TanmayArya-1p commented Dec 4, 2025

What does this PR try to resolve?

Closes #10173

This PR adds early validation of target source paths with clearer error messages.

For context, I tried to solve this issue before ( #16329 ) but ended up making an oversight, I would recommend reading this to understand the issues faced in resolving this.

So what changed in this PR?

  • Root Target Units are validated early on in the compilation pipeline when the BuildContext is generated here. This is right after command line arguments/manifest targets are parsed and just before the build tasks are spawned.
  • Cases that are covered by this PR:
    • If the target path is invalid and points to nothing.
    • If the target path is valid, but is a directory (not a file)
    • If the target path is a valid directory with a main.rs/lib.rs depending on the Target kind: In this case a help: message is emitted.

Doing this also means that Cargo validates each root target's path that is requested to be compiled before spawning any build tasks.
This PR enforces the invariant: No compilation occurs before validating every required target's source path.
I'm not sure if this should be expected behaviour and I'd love to hear from others on this.

@TanmayArya-1p TanmayArya-1p marked this pull request as ready for review December 4, 2025 10:20
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 4, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 4, 2025

r? @epage

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

@TanmayArya-1p TanmayArya-1p force-pushed the validate-target-source-paths branch 2 times, most recently from 6e604ae to 3200b5b Compare December 5, 2025 00:30
@epage
Copy link
Contributor

epage commented Dec 5, 2025

Feel free to edit your commits for how they should be merged.

@TanmayArya-1p TanmayArya-1p force-pushed the validate-target-source-paths branch from e52ea15 to 5e9e6cb Compare December 5, 2025 04:12
@rustbot
Copy link
Collaborator

rustbot commented Dec 5, 2025

This PR was rebased onto a different master 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.

@TanmayArya-1p
Copy link
Contributor Author

TanmayArya-1p commented Dec 5, 2025

Thanks for the review!
I fixed the issues you pointed out, Let me know if it needs to be changed.

Also could you rerun the CI workflow because it failed with this error:

https://github.com/rust-lang/cargo/actions/runs/19952419092/job/57215065207#annotation:2:61

Error: fatal: unable to access 'https://github.com/rust-lang/cargo/': Failed to connect to github.com port 443 after 21029 ms: Could not connect to server
Error: The process 'C:\Program Files\Git\bin\git.exe' failed with exit code 128

@epage
Copy link
Contributor

epage commented Dec 5, 2025

I fixed the issues you pointed out, Let me know if it needs to be changed.

FYI it would be a big help for reviewing if the commits were cleaned up, especially if passing tests are added in their own commit (showing the old behavior) and then the feature work happens in the follow up that updates the tests so they still pass.

@TanmayArya-1p
Copy link
Contributor Author

Sure, i'll clean up the commit history

@TanmayArya-1p TanmayArya-1p force-pushed the validate-target-source-paths branch from 5e9e6cb to b949d9a Compare December 5, 2025 17:30
@TanmayArya-1p TanmayArya-1p force-pushed the validate-target-source-paths branch from b949d9a to 585b8a9 Compare December 5, 2025 17:36
None
}
}
_ => None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we explicitly enumerate all TargetKinds so the compiler can remind us to re-evaluate this if a new variant is added?

@epage
Copy link
Contributor

epage commented Dec 5, 2025

Thanks, this is looking great! Just adjusting the match for maintainability and this is good to go!

@TanmayArya-1p TanmayArya-1p force-pushed the validate-target-source-paths branch from 585b8a9 to f203f09 Compare December 5, 2025 17:52
@epage epage enabled auto-merge December 5, 2025 18:19
@epage epage added this pull request to the merge queue Dec 5, 2025
Merged via the queue into rust-lang:master with commit 88abfa1 Dec 5, 2025
28 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cargo emits confusing errors when trying to use example crates

3 participants