Skip to contentSkip to conversation

rust: compile libcore with edition 2024 for 1.87+

PATCH Applied Gary Guo 4 participants 6 messages May 17, 2025 – Jan 15

Subsystems (2)
lore
Share & tools
lore

Gary Guo

author reviewer
#0 lore raw

PATCH 1/1 rust: compile libcore with edition 2024 for 1.87+

Rust 1.87 (released on 2025-05-15) compiles core library with edition 2024 instead of 2021 [1]. Ensure that the edition matches libcore's expectation to avoid potential breakage.

---
 rust/Makefile | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
rust/Makefile +9 -3
index 3aca903a7d08..9e7f1ec06181 100644
@@ -60,6 +60,12 @@ endif
 core-cfgs = \
     --cfg no_fp_fmt_parse
 
+ifeq ($(call rustc-min-version,108700),y)
+core-cfgs += --edition=2024
+else
+core-cfgs += --edition=2021
+endif
+
 # `rustc` recognizes `--remap-path-prefix` since 1.26.0, but `rustdoc` only
 # since Rust 1.81.0. Moreover, `rustdoc` ICEs on out-of-tree builds since Rust
 # 1.82.0 (https://github.com/rust-lang/rust/issues/138520). Thus workaround both
@@ -106,7 +112,7 @@ rustdoc-macros: $(src)/macros/lib.rs FORCE
 
 # Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should
 # not be needed -- see https://github.com/rust-lang/rust/pull/128307.
-rustdoc-core: private skip_flags = -Wrustdoc::unescaped_backticks
+rustdoc-core: private skip_flags = -Wrustdoc::unescaped_backticks --edition=2021
 rustdoc-core: private rustc_target_flags = $(core-cfgs)
 rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
 	+$(call if_changed,rustdoc)
@@ -416,7 +422,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
       cmd_rustc_library = \
 	OBJTREE=$(abspath $(objtree)) \
 	$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
-		$(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \
+		$(filter-out $(skip_flags),$(rust_flags)) $(rustc_target_flags) \
 		--emit=dep-info=$(depfile) --emit=obj=$@ \
 		--emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
 		--crate-type rlib -L$(objtree)/$(obj) \
@@ -483,7 +489,7 @@ $(obj)/helpers/helpers.o: $(src)/helpers/helpers.c $(recordmcount_source) FORCE
 $(obj)/exports.o: private skip_gendwarfksyms = 1
 
 $(obj)/core.o: private skip_clippy = 1
-$(obj)/core.o: private skip_flags = -Wunreachable_pub
+$(obj)/core.o: private skip_flags = -Wunreachable_pub --edition=2021
 $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
 $(obj)/core.o: private rustc_target_flags = $(core-cfgs)
 $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs \

base-commit: 172a9d94339cea832d89630b89d314e41d622bd8

Signature · 1 line
2.47.2
#1 lore raw
Quoted 9 lines · Gary Guo

Rust 1.87 (released on 2025-05-15) compiles core library with edition 2024 instead of 2021 [1]. Ensure that the edition matches libcore's expectation to avoid potential breakage.

Cc'ing est31 -- I will add:

Thanks!

Cheers,
Miguel

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Gary Guo
Quoted 8 lines · Gary Guo

Rust 1.87 (released on 2025-05-15) compiles core library with edition 2024 instead of 2021 [1]. Ensure that the edition matches libcore's expectation to avoid potential breakage.

Applied
#3 lore raw
In reply to Gary Guo
Quoted 9 lines · Gary Guo

Rust 1.87 (released on 2025-05-15) compiles core library with edition 2024 instead of 2021 [1]. Ensure that the edition matches libcore's expectation to avoid potential breakage.

Applied to rust-next -- thanks everyone!

(I actually applied a couple days ago in advance of Monday's -next, which explains the following report)

[ J3m3 reported in Zulip [2] that the rust-analyzer target was
broken after this patch -- indeed, we need to avoid core-cfgs since those are passed to the rust-analyzer target.

So, instead, I tweaked the patch to create a new core-edition variable and explicitly mention the --edition flag instead of reusing core-cfgs.

In addition, pass a new argument using this new variable to generate_rust_analyzer.py so that we set the right edition there.

By the way, for future reference: the filter-out change is needed for Rust < 1.87, since otherwise we would skip the --edition=2021 we just added, ending up with no edition flag, and thus the compiler would default to the 2015 one.

[2] https://rust-for-linux.zulipchat.com/#narrow/channel/291565/topic/x/near/520206547

- Miguel ]

I also added:

since est31 told Gary in RustWeek, and we discussed the patch there.

@Gary: I hope the changes are OK with you (I can put the generate_rust_analyzer ones in a different commit if you prefer). Thanks!

Cheers,
Miguel

#4 lore raw
Quoted 41 lines · Miguel Ojeda
Quoted 9 lines · Gary Guo

Rust 1.87 (released on 2025-05-15) compiles core library with edition 2024 instead of 2021 [1]. Ensure that the edition matches libcore's expectation to avoid potential breakage.

Applied to rust-next -- thanks everyone!

(I actually applied a couple days ago in advance of Monday's -next, which explains the following report)

[ J3m3 reported in Zulip [2] that the rust-analyzer target was
broken after this patch -- indeed, we need to avoid core-cfgs since those are passed to the rust-analyzer target.

So, instead, I tweaked the patch to create a new core-edition variable and explicitly mention the --edition flag instead of reusing core-cfgs.

In addition, pass a new argument using this new variable to generate_rust_analyzer.py so that we set the right edition there.

By the way, for future reference: the filter-out change is needed for Rust < 1.87, since otherwise we would skip the --edition=2021 we just added, ending up with no edition flag, and thus the compiler would default to the 2015 one.

[2] https://rust-for-linux.zulipchat.com/#narrow/channel/291565/topic/x/near/520206547

- Miguel ]

I also added:

Quoted 9 lines

since est31 told Gary in RustWeek, and we discussed the patch there.

@Gary: I hope the changes are OK with you (I can put the generate_rust_analyzer ones in a different commit if you prefer). Thanks!

Cheers,
Miguel

Hey Miguel, regarding the rust-analyzer changes:

I see only core was changed to use core_edition, but other sysroot crates (alloc, std, and proc_macro) still compile with edition 2021 despite all having been updated in the same upstream PR. Was this intentional, or just an omission?

#5 lore raw
Quoted 7 lines · Tamir Duberstein

Hey Miguel, regarding the rust-analyzer changes:

I see only core was changed to use core_edition, but other sysroot crates (alloc, std, and proc_macro) still compile with edition 2021 despite all having been updated in the same upstream PR. Was this intentional, or just an omission?

Hmm... I guess we overfocused on core here given it was about fixing that for the main build, and I applied the change of the edition for rust-analyzer too, but then we didn't update the others, but hard to say.

I see you replied in the linked Zulip and sent the patches -- thanks for taking a look!

Cheers,
Miguel