-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Do not overwrite input file if it has no extension #34005
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Aatch (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
// the source file. | ||
let output_filenames = driver::build_output_filenames(&input, &odir, &ofile, &[], &sess); | ||
match input_file_path { | ||
Some(ifile) => if output_filenames.path(OutputType::Exe) == ifile { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... Why checking only the executable output type? rustc can generate bytecode or assembly too and, as far as I know, all could overwrite the input file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
|
||
pub fn is_path_used(&self, path: PathBuf) -> bool { | ||
for flavor in self.outputs.keys() { | ||
if self.path(*flavor) == path { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a .iter()
method that directly returns an iterator over (key, value) pairs. In fact, in this context, I think you do not even care about keys and could even use .values()
to iterate over values only instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I felt that doing it this way I was hedging against path
ever changing behaviour. Having said that, I just pushed a change that doesn't use path
for this check.
r? @LeoTestard |
r? @pnkfelix
Thanks, @LeoTestard!
I've been seeing travis failures when setting up the state, I have no idea why that is, but all PRs seemed to be affected for the last couple of days. Just rebased -i and pushed to trigger the build. |
e2ef035
to
cc6cd1f
Compare
@estebank Travis fail is legit |
In particular here is the error:
I have not attempted to dissect the problem completely; I thought the problem might be that its interpreted the test as overwriting @estebank in any case, you may want to revise your error message to actual include the input file name your code is predicting will be overwritten. That will make it easier for users trying to understand your message to connect it up to the potentially erroneous input they provided. |
☔ The latest upstream changes (presumably #34830) made this pull request unmergeable. Please resolve the merge conflicts. |
Breaking change for anybody scripting such behaviour. |
f3c2f86
to
b5f8cdf
Compare
Check wether the source file has the same path as the executable to be generated and fail early if it would overwrite the source file with the executable. ```bash % echo 'fn main(){}' > file && ./rustc file error: the input file "file" would be overwritten by the generated executable error: aborting due to previous error % echo 'fn main(){}' > file.rs && ./rustc file.rs -o file.rs error: the input file "file.rs" would be overwritten by the generated executable error: aborting due to previous error ```
b5f8cdf
to
9745d4e
Compare
I'm closing due to inactivity, but feel free to open a new pull request if you rebase and fix the aforementioned problems. |
Check wether the source file has the same path as the executable to be
generated and fail early if it would overwrite the source file with the
executable.
Fixes #13019