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

Use expect for current_dir on librustc/session mod #45505

Merged
merged 3 commits into from
Oct 28, 2017

Conversation

spk
Copy link
Contributor

@spk spk commented Oct 24, 2017

Reference bug https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=871638

Like described on the reference bug report:

$ mkdir dir
$ cd dir
$ rm -rf ../dir
$ RUST_BACKTRACE=1 rustc -C target-cpu=help
error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: Error { repr: Os { code: 2, message: "No such file or directory" } }', src/libcore/result.rs:837
stack backtrace:
   1:     0x7f7d23970dda - <unknown>
   2:     0x7f7d2398305f - <unknown>
   3:     0x7f7d2397f8a5 - <unknown>
   4:     0x7f7d2397ffc7 - std::panicking::rust_panic_with_hook::h109e116a3a861224
   5:     0x7f7d2397fe54 - <unknown>
   6:     0x7f7d2397fd79 - std::panicking::begin_panic_fmt::h26713cea9bce3ab0
   7:     0x7f7d2397fd07 - rust_begin_unwind
   8:     0x7f7d239cb41d - core::panicking::panic_fmt::hcfbb59eeb7f27f75
   9:     0x7f7d20be63d3 - <unknown>
  10:     0x7f7d20d6ebcc - rustc::session::build_session_::h7a3559f2373a5d05
  11:     0x7f7d20d6dd7e - rustc::session::build_session_with_codemap::h68bc7bcd2f34eee4
  12:     0x7f7d20d6d72c - rustc::session::build_session::h437fda3c327a8bde
  13:     0x7f7d23d26030 - <rustc_driver::RustcDefaultCalls as rustc_driver::CompilerCalls<'a>>::no_input::h8047df7741757d1c
  14:     0x7f7d23d21d27 - rustc_driver::run_compiler::hafe7bbfedf95a825
  15:     0x7f7d23c57378 - <unknown>
  16:     0x7f7d2398ae0a - __rust_maybe_catch_panic
  17:     0x7f7d23c76fa8 - <unknown>
  18:     0x7f7d2397eb74 - <unknown>
  19:     0x7f7d1ed4f493 - start_thread
  20:     0x7f7d23645afe - __clone
  21:                0x0 - <unknown>

With this patch this will give instead:

error: Current directory is invalid: No such file or directory (os error 2)

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (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.

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 25, 2017
@kennytm
Copy link
Member

kennytm commented Oct 26, 2017

I think it is better to change it to a fatal error, so the compiler will immediately quit without crashing.

Something like this maybe:

let working_dir = match env::current_dir() {
    Ok(dir) => dir.to_string_lossy().into_owned(),
    Err(e) => panic!(p_s.span_diagnostic.fatal(&format!("Current directory is invalid: {}", e))),
};

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 26, 2017
@spk spk force-pushed the use-expect-instead-unwrap branch from 79c5aa2 to 5773efa Compare October 27, 2017 17:15
let working_dir = env::current_dir().unwrap().to_string_lossy().into_owned();
let working_dir = match env::current_dir() {
Ok(dir) => dir.to_string_lossy().into_owned(),
Err(e) => panic!(p_s.span_diagnostic.fatal(&format!("Current directory is invalid: {}", e))),
Copy link
Member

@kennytm kennytm Oct 27, 2017

Choose a reason for hiding this comment

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

This line is currently too long. This repository requires a 100-column limit.

[00:03:17] tidy error: /checkout/src/librustc/session/mod.rs:781: line longer than 100 chars

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops fixed in cfc916e

Copy link
Member

@kennytm kennytm left a comment

Choose a reason for hiding this comment

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

r=me after Travis passed.

@kennytm
Copy link
Member

kennytm commented Oct 27, 2017

@bors r+ rollup

Thanks!

@bors
Copy link
Contributor

bors commented Oct 27, 2017

📌 Commit cfc916e has been approved by kennytm

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Oct 28, 2017
…nnytm

Use expect for current_dir on librustc/session mod

Reference bug https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=871638

Like described on the reference bug report:

~~~
$ mkdir dir
$ cd dir
$ rm -rf ../dir
$ RUST_BACKTRACE=1 rustc -C target-cpu=help
error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: Error { repr: Os { code: 2, message: "No such file or directory" } }', src/libcore/result.rs:837
stack backtrace:
   1:     0x7f7d23970dda - <unknown>
   2:     0x7f7d2398305f - <unknown>
   3:     0x7f7d2397f8a5 - <unknown>
   4:     0x7f7d2397ffc7 - std::panicking::rust_panic_with_hook::h109e116a3a861224
   5:     0x7f7d2397fe54 - <unknown>
   6:     0x7f7d2397fd79 - std::panicking::begin_panic_fmt::h26713cea9bce3ab0
   7:     0x7f7d2397fd07 - rust_begin_unwind
   8:     0x7f7d239cb41d - core::panicking::panic_fmt::hcfbb59eeb7f27f75
   9:     0x7f7d20be63d3 - <unknown>
  10:     0x7f7d20d6ebcc - rustc::session::build_session_::h7a3559f2373a5d05
  11:     0x7f7d20d6dd7e - rustc::session::build_session_with_codemap::h68bc7bcd2f34eee4
  12:     0x7f7d20d6d72c - rustc::session::build_session::h437fda3c327a8bde
  13:     0x7f7d23d26030 - <rustc_driver::RustcDefaultCalls as rustc_driver::CompilerCalls<'a>>::no_input::h8047df7741757d1c
  14:     0x7f7d23d21d27 - rustc_driver::run_compiler::hafe7bbfedf95a825
  15:     0x7f7d23c57378 - <unknown>
  16:     0x7f7d2398ae0a - __rust_maybe_catch_panic
  17:     0x7f7d23c76fa8 - <unknown>
  18:     0x7f7d2397eb74 - <unknown>
  19:     0x7f7d1ed4f493 - start_thread
  20:     0x7f7d23645afe - __clone
  21:                0x0 - <unknown>
~~~

With this patch this will give instead:

~~~
error: Current directory is invalid: No such file or directory (os error 2)
~~~
kennytm added a commit to kennytm/rust that referenced this pull request Oct 28, 2017
…nnytm

Use expect for current_dir on librustc/session mod

Reference bug https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=871638

Like described on the reference bug report:

~~~
$ mkdir dir
$ cd dir
$ rm -rf ../dir
$ RUST_BACKTRACE=1 rustc -C target-cpu=help
error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: Error { repr: Os { code: 2, message: "No such file or directory" } }', src/libcore/result.rs:837
stack backtrace:
   1:     0x7f7d23970dda - <unknown>
   2:     0x7f7d2398305f - <unknown>
   3:     0x7f7d2397f8a5 - <unknown>
   4:     0x7f7d2397ffc7 - std::panicking::rust_panic_with_hook::h109e116a3a861224
   5:     0x7f7d2397fe54 - <unknown>
   6:     0x7f7d2397fd79 - std::panicking::begin_panic_fmt::h26713cea9bce3ab0
   7:     0x7f7d2397fd07 - rust_begin_unwind
   8:     0x7f7d239cb41d - core::panicking::panic_fmt::hcfbb59eeb7f27f75
   9:     0x7f7d20be63d3 - <unknown>
  10:     0x7f7d20d6ebcc - rustc::session::build_session_::h7a3559f2373a5d05
  11:     0x7f7d20d6dd7e - rustc::session::build_session_with_codemap::h68bc7bcd2f34eee4
  12:     0x7f7d20d6d72c - rustc::session::build_session::h437fda3c327a8bde
  13:     0x7f7d23d26030 - <rustc_driver::RustcDefaultCalls as rustc_driver::CompilerCalls<'a>>::no_input::h8047df7741757d1c
  14:     0x7f7d23d21d27 - rustc_driver::run_compiler::hafe7bbfedf95a825
  15:     0x7f7d23c57378 - <unknown>
  16:     0x7f7d2398ae0a - __rust_maybe_catch_panic
  17:     0x7f7d23c76fa8 - <unknown>
  18:     0x7f7d2397eb74 - <unknown>
  19:     0x7f7d1ed4f493 - start_thread
  20:     0x7f7d23645afe - __clone
  21:                0x0 - <unknown>
~~~

With this patch this will give instead:

~~~
error: Current directory is invalid: No such file or directory (os error 2)
~~~
bors added a commit that referenced this pull request Oct 28, 2017
Rollup of 7 pull requests

- Successful merges: #45421, #45449, #45505, #45535, #45549, #45574, #45585
- Failed merges:
@bors bors merged commit cfc916e into rust-lang:master Oct 28, 2017
@spk spk deleted the use-expect-instead-unwrap branch November 1, 2017 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants