Skip to content

Disable compilation on some extensionless files #17945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Disable compilation on some extensionless files #17945

wants to merge 2 commits into from

Conversation

natepisarski
Copy link

This commit prevents the compiler from overwriting certain extensionless source files with a binary.

As it stands, if you have /home/joe/file1:

 fn main(){}

and compile it

rustc /home/joe/file1

It will replace the source (file1) with a binary called file1, destroying the source without warning or error.

This commit completely disallows compiling without a file extension, but still allows compiling with an inccorect (i.e not .rs) extension.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon.

@alexcrichton
Copy link
Member

Thanks @natepisarski! The tracking issue for this is #13019, so you could actually put Closes #13019 in one of the commits as well if you'd like to close the issue when this is merged.

I think there may also be some more cases that need to be handled here (can you add tests for all these as well?)

  • Compiling an extensionless file into a library should be ok as suffixes/prefixes are added
  • rustc foo -o bar should be ok
  • rustc foo -o foo should probably be ok because it was explicitly requested

When adding tests, could you add them to the src/test/run-pass test suite? Thanks again!

@natepisarski
Copy link
Author

@alexcrichton I can do all of these. Probably not in the most timely manor, but I can get them done.

@alexcrichton
Copy link
Member

Ok, thanks @natepisarski!

@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to reopen with comments addressed!

lnicola pushed a commit to lnicola/rust that referenced this pull request Sep 25, 2024
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.

4 participants