Skip to content

Add default and latest stable edition to --edition in rustc #106094

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 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,8 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
opt::opt_s(
"",
"edition",
"Specify which edition of the compiler to use when compiling code.",
Box::leak(format!("Specify which edition of the compiler to use when compiling code.\
Copy link
Member

Choose a reason for hiding this comment

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

Could you please avoid this Box::leak call? It is possible to invoke rustc multiple times in the same process. Each time would leak memory. You should be able to inline the opt_s function to pub fn opt_s(a: S, b: S, c: &str, d: S) -> R { to allow strings with arbitrary lifetimes and then pass &format(...).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep - I was actually pretty wary of this change but that's what I was recommended to do. I'll rewrite the type signature and see if it still works soon so we can avoid this leak.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I cannot refactor this out as the reference needs to outlive 'static

error[E0521]: borrowed data escapes outside of function
    --> compiler/rustc_session/src/config.rs:1290:9
     |
1289 |     pub fn opt_s(a: S, b: S, c: &str, d: S) -> R {
     |                  -           -  - let's call the lifetime of this reference `'1`
     |                  |           |
     |                  |           `c` is a reference that is only valid in the function body
     |                  `a` declared here, outside of the function body
1290 |         stable(longer(a, b), move |opts| opts.optopt(a, b, c, d))
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |         |
     |         `c` escapes the function body here
     |         argument requires that `'1` must outlive `'static`

There's got to be something I'm missing - the enum variant for the formatted string are all static and embedded, and there's got to be a better option than either allocating, or just manually writing in the strings and commenting above the original variables, "this must be updated in xyz string". I don't know how but I think there might be a way to construct this statically somehow - it's just concatenating all-static strings.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Another option would be to use std::sync::LazyLock to compute the description. If you put it in a static it should allow you to get a single &'static str without leaking anything.

The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE_EDITION}.").into_boxed_str()),
EDITION_NAME_LIST,
),
opt::multi_s(
Expand Down