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

Don't call env::set_var in rustc_driver::install_ice_hook #125063

Merged
merged 1 commit into from
May 13, 2024

Conversation

tbu-
Copy link
Contributor

@tbu- tbu- commented May 13, 2024

Modifying an environment variable would make the function unsafe to call.

Modifying an environment variable would make the function unsafe to
call.
@rustbot
Copy link
Collaborator

rustbot commented May 13, 2024

r? @michaelwoerister

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 13, 2024
if std::env::var_os("RUST_BACKTRACE").is_none() {
std::env::set_var("RUST_BACKTRACE", "full");
if env::var_os("RUST_BACKTRACE").is_none() {
panic::set_backtrace_style(panic::BacktraceStyle::Full);
Copy link
Contributor

Choose a reason for hiding this comment

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

This only sets the style, but without the env. variable, this will think that backtraces are disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting, TIL.

Do you know if that is relevant in this context?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. I thought that it is, otherwise I wouldn't comment, but now that I look at it, maybe it isn't. The default panic hook does not seem to use Backtrace::capture and reads the style directly.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch, @Kobzol!

Yes, this is relevant here. We want to enable backtraces (unless there is an explicit setting for it).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if the compiler calls Backtrace::capture somewhere explicitly, or if it just depends on the default panic hook. If the latter is true, then maybe we really don't need to set the env. variable.

That being said, wrapping this line with unsafe seems fine to me, it's not like the compiler uses #[forbid_unsafe_code)] anyway, and this line has been clearly working fine in the past.

Copy link
Member

Choose a reason for hiding this comment

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

We want to make the default hook here always print a backtrace. We can't change the default hook to use Backtrace::force_capture. We would have to copy it from libstd into this function instead and make sure to keep it in sync.

Copy link
Member

Choose a reason for hiding this comment

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

We want to make the default hook here always print a backtrace.

This behavior is still preserved, unless I'm mistaken. As @Kobzol pointed out, the default hook does not depend on the RUST_BACKTRACE env var. My comment about force_capture was wrt to @Kobzol's concern that other (possibly future) code somewhere in the compiler might rely on this code setting the RUST_BACKTRACE env var if no explicit setting is provided.

Copy link
Member

Choose a reason for hiding this comment

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

There are uses of Backtrace::capture in compiler/rustc_errors/src/lib.rs and compiler/rustc_log/src/lib.rs. Should those be changed somehow?

Copy link
Member

Choose a reason for hiding this comment

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

It depends on whether these call sites want to depend on the RUST_BACKTRACE env var or not.

For rustc_log, it looks like that should indeed use force_capture.

Copy link
Member

Choose a reason for hiding this comment

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

I've opened #125355 for the rustc_log case.

I'm less sure about the compiler/rustc_errors/src/lib.rs cases but I think these should use force_capture too. @tbu-, do you want to open a PR, so we can engage with the diagnostics team?

Thanks for reporting this, @RalfJung!

@michaelwoerister
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 13, 2024

📌 Commit b98b8d7 has been approved by michaelwoerister

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 13, 2024
fmease added a commit to fmease/rust that referenced this pull request May 13, 2024
…lwoerister

Don't call `env::set_var` in `rustc_driver::install_ice_hook`

Modifying an environment variable would make the function unsafe to call.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 13, 2024
…lwoerister

Don't call `env::set_var` in `rustc_driver::install_ice_hook`

Modifying an environment variable would make the function unsafe to call.
bors added a commit to rust-lang-ci/rust that referenced this pull request May 13, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#119515 (style-guide: Format single associated type `where` clauses on the same line)
 - rust-lang#119959 ([meta] Clarify prioritization alert)
 - rust-lang#123817 (Stabilize `seek_seek_relative`)
 - rust-lang#124532 (elaborate obligations in coherence)
 - rust-lang#125063 (Don't call `env::set_var` in `rustc_driver::install_ice_hook`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request May 13, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#119515 (style-guide: Format single associated type `where` clauses on the same line)
 - rust-lang#119959 ([meta] Clarify prioritization alert)
 - rust-lang#123817 (Stabilize `seek_seek_relative`)
 - rust-lang#125063 (Don't call `env::set_var` in `rustc_driver::install_ice_hook`)
 - rust-lang#125071 (Migrate rustdoc target spec json path)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 472391d into rust-lang:master May 13, 2024
6 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 13, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 13, 2024
Rollup merge of rust-lang#125063 - tbu-:pr_set_ice_hook_env, r=michaelwoerister

Don't call `env::set_var` in `rustc_driver::install_ice_hook`

Modifying an environment variable would make the function unsafe to call.
fmease added a commit to fmease/rust that referenced this pull request May 22, 2024
…pture, r=nnethercote

Use Backtrace::force_capture instead of Backtrace::capture in rustc_log

After rust-lang#125063, the compiler and custom drivers won't automatically set the RUST_BACKTRACE environment variable anymore, so we have to call `Backtrace::force_capture` instead of `Backtrace::capture` to unconditionally capture a backtrace.

rustc_log handles enabling backtraces via env vars itself, so we don't want RUST_BACKTRACE to make a difference.
fmease added a commit to fmease/rust that referenced this pull request May 22, 2024
…pture, r=nnethercote

Use Backtrace::force_capture instead of Backtrace::capture in rustc_log

After rust-lang#125063, the compiler and custom drivers won't automatically set the RUST_BACKTRACE environment variable anymore, so we have to call `Backtrace::force_capture` instead of `Backtrace::capture` to unconditionally capture a backtrace.

rustc_log handles enabling backtraces via env vars itself, so we don't want RUST_BACKTRACE to make a difference.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 22, 2024
Rollup merge of rust-lang#125355 - michaelwoerister:rust_log_force_capture, r=nnethercote

Use Backtrace::force_capture instead of Backtrace::capture in rustc_log

After rust-lang#125063, the compiler and custom drivers won't automatically set the RUST_BACKTRACE environment variable anymore, so we have to call `Backtrace::force_capture` instead of `Backtrace::capture` to unconditionally capture a backtrace.

rustc_log handles enabling backtraces via env vars itself, so we don't want RUST_BACKTRACE to make a difference.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request May 23, 2024
…nnethercote

Use Backtrace::force_capture instead of Backtrace::capture in rustc_log

After rust-lang/rust#125063, the compiler and custom drivers won't automatically set the RUST_BACKTRACE environment variable anymore, so we have to call `Backtrace::force_capture` instead of `Backtrace::capture` to unconditionally capture a backtrace.

rustc_log handles enabling backtraces via env vars itself, so we don't want RUST_BACKTRACE to make a difference.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants