Skip to content
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

rustc overwrites input file when it has no extension #13019

Closed
comex opened this issue Mar 19, 2014 · 8 comments · Fixed by #46814
Closed

rustc overwrites input file when it has no extension #13019

comex opened this issue Mar 19, 2014 · 8 comments · Fixed by #46814
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@comex
Copy link
Contributor

comex commented Mar 19, 2014

% echo 'fn main() {}' > test
% rustc test
% ./test # input has been replaced with the output binary

Tested on OS X, af93684. Not that it makes sense to write Rust files with no extension, but if you do, rustc should not overwrite the input file by default.

@SiegeLord
Copy link
Contributor

If/when #9826 gets implemented, it'll make sense to have an extension-less Rust file. I'm not sure where rustc --run would place the compilation output, however, so it might not hit this specific bug.

@pongad
Copy link
Contributor

pongad commented Apr 9, 2014

Will simply failing if the input file has no extension fix the issue? rustc --run can probably put the compilation output in a tmp file somewhere right?

@steveklabnik
Copy link
Member

Triage: this still happens today.

@frewsxcv
Copy link
Member

frewsxcv commented Oct 2, 2015

This still happens

coreyf@frewbook-pro /tmp> cat hi
fn main() {}
coreyf@frewbook-pro /tmp> file hi
hi: ASCII text
coreyf@frewbook-pro /tmp> rustc hi
coreyf@frewbook-pro /tmp> file hi
hi: Mach-O 64-bit executable x86_64

@jonas-schievink
Copy link
Contributor

We just had 2 new Rust learners hit this...

@cyplo
Copy link
Contributor

cyplo commented May 6, 2017

It's still an issue with rustc 1.18.0-nightly (28a7429 2017-04-13)

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 20, 2017
@varkor
Copy link
Member

varkor commented Dec 17, 2017

@estebank: I have a fix for this, based on your patch — are you happy for me to submit it, or would you like to finish it off?

@estebank
Copy link
Contributor

@varkor feel free to go ahead and submit the PR. Thank you for picking this up!

varkor added a commit to varkor/rust that referenced this issue Dec 18, 2017
If rustc is invoked on a file that would be overwritten by the
compilation, the compilation now fails, to avoid accidental loss. This
resolves rust-lang#13019.
kennytm added a commit to kennytm/rust that referenced this issue Dec 21, 2017
Prevent rustc overwriting input files

If rustc is invoked on a file that would be overwritten by the
compilation, the compilation now fails, to avoid accidental loss. This
resolves rust-lang#13019. Kudos to @estebank, whose patch I finished off.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants