Skip to content

Commit f3d1d47

Browse files
committed
Auto merge of rust-lang#135789 - matthiaskrgr:rollup-4cvw8s4, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#133695 (Reexport likely/unlikely in std::hint) - rust-lang#135330 (Respect --sysroot for rustc -vV and -Cpasses=list) - rust-lang#135333 (Partial progress on rust-lang#132735: Replace extern "rust-intrinsic" with #[rustc_intrinsic] across the codebase) - rust-lang#135741 (Recognise new IPv6 documentation range from IETF RFC 9637) - rust-lang#135770 (Update contributing docs for submodule/subtree changes) - rust-lang#135775 (Subtree update of `rust-analyzer`) - rust-lang#135776 (Subtree sync for rustc_codegen_cranelift) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9f4d9dc + 67b609a commit f3d1d47

File tree

331 files changed

+9572
-3037
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

331 files changed

+9572
-3037
lines changed

Diff for: CONTRIBUTING.md

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ Documentation for contributing to the compiler or tooling is located in the [Gui
1212
Development][rustc-dev-guide], commonly known as the [rustc-dev-guide]. Documentation for the
1313
standard library in the [Standard library developers Guide][std-dev-guide], commonly known as the [std-dev-guide].
1414

15+
## Making changes to subtrees and submodules
16+
17+
For submodules, changes need to be made against the repository corresponding the
18+
submodule, and not the main `rust-lang/rust` repository.
19+
20+
For subtrees, prefer sending a PR against the subtree's repository if it does
21+
not need to be made against the main `rust-lang/rust` repostory (e.g. a
22+
rustc-dev-guide change that does not accompany a compiler change).
23+
1524
## About the [rustc-dev-guide]
1625

1726
The [rustc-dev-guide] is meant to help document how rustc –the Rust compiler– works,

Diff for: compiler/rustc_codegen_cranelift/rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "nightly-2025-01-10"
2+
channel = "nightly-2025-01-20"
33
components = ["rust-src", "rustc-dev", "llvm-tools"]
44
profile = "minimal"

Diff for: compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,11 @@ diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-supp
176176
index 9607ff02f96..b7d97caf9a2 100644
177177
--- a/src/tools/run-make-support/src/external_deps/rustdoc.rs
178178
+++ b/src/tools/run-make-support/src/external_deps/rustdoc.rs
179-
@@ -34,8 +34,6 @@ pub fn bare() -> Self {
179+
@@ -34,7 +34,6 @@ pub fn bare() -> Self {
180180
#[track_caller]
181181
pub fn new() -> Self {
182182
let mut cmd = setup_common();
183-
- let target_rpath_dir = env_var_os("TARGET_RPATH_DIR");
184-
- cmd.arg(format!("-L{}", target_rpath_dir.to_string_lossy()));
183+
- cmd.arg("-L").arg(env_var_os("TARGET_RPATH_DIR"));
185184
Self { cmd }
186185
}
187186

Diff for: compiler/rustc_codegen_cranelift/src/driver/aot.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,17 @@ fn make_module(sess: &Session, name: String) -> UnwindModule<ObjectModule> {
333333

334334
let mut builder =
335335
ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap();
336+
337+
// Disable function sections by default on MSVC as it causes significant slowdowns with link.exe.
338+
// Maybe link.exe has exponential behavior when there are many sections with the same name? Also
339+
// explicitly disable it on MinGW as rustc already disables it by default on MinGW and as such
340+
// isn't tested. If rustc enables it in the future on MinGW, we can re-enable it too once it has
341+
// been on MinGW.
342+
let default_function_sections = sess.target.function_sections && !sess.target.is_like_windows;
336343
builder.per_function_section(
337-
sess.opts.unstable_opts.function_sections.unwrap_or(sess.target.function_sections),
344+
sess.opts.unstable_opts.function_sections.unwrap_or(default_function_sections),
338345
);
346+
339347
UnwindModule::new(ObjectModule::new(builder), true)
340348
}
341349

Diff for: compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Codegen of intrinsics. This includes `extern "rust-intrinsic"`,
2+
//! functions marked with the `#[rustc_intrinsic]` attribute
23
//! and LLVM intrinsics that have symbol names starting with `llvm.`.
34
45
macro_rules! intrinsic_args {

Diff for: compiler/rustc_driver_impl/src/lib.rs

+22-15
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use rustc_middle::ty::TyCtxt;
5353
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
5454
use rustc_session::config::{
5555
CG_OPTIONS, ErrorOutputType, Input, OptionDesc, OutFileName, OutputType, UnstableOptions,
56-
Z_OPTIONS, nightly_options,
56+
Z_OPTIONS, nightly_options, parse_target_triple,
5757
};
5858
use rustc_session::getopts::{self, Matches};
5959
use rustc_session::lint::{Lint, LintId};
@@ -916,13 +916,7 @@ pub fn version_at_macro_invocation(
916916
safe_println!("host: {}", config::host_tuple());
917917
safe_println!("release: {release}");
918918

919-
let debug_flags = matches.opt_strs("Z");
920-
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
921-
let opts = config::Options::default();
922-
let sysroot = filesearch::materialize_sysroot(opts.maybe_sysroot.clone());
923-
let target = config::build_target_config(early_dcx, &opts, &sysroot);
924-
925-
get_codegen_backend(early_dcx, &sysroot, backend_name, &target).print_version();
919+
get_backend_from_raw_matches(early_dcx, matches).print_version();
926920
}
927921
}
928922

@@ -1125,19 +1119,32 @@ pub fn describe_flag_categories(early_dcx: &EarlyDiagCtxt, matches: &Matches) ->
11251119
}
11261120

11271121
if cg_flags.iter().any(|x| *x == "passes=list") {
1128-
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
1129-
1130-
let opts = config::Options::default();
1131-
let sysroot = filesearch::materialize_sysroot(opts.maybe_sysroot.clone());
1132-
let target = config::build_target_config(early_dcx, &opts, &sysroot);
1133-
1134-
get_codegen_backend(early_dcx, &sysroot, backend_name, &target).print_passes();
1122+
get_backend_from_raw_matches(early_dcx, matches).print_passes();
11351123
return true;
11361124
}
11371125

11381126
false
11391127
}
11401128

1129+
/// Get the codegen backend based on the raw [`Matches`].
1130+
///
1131+
/// `rustc -vV` and `rustc -Cpasses=list` need to get the codegen backend before we have parsed all
1132+
/// arguments and created a [`Session`]. This function reads `-Zcodegen-backend`, `--target` and
1133+
/// `--sysroot` without validating any other arguments and loads the codegen backend based on these
1134+
/// arguments.
1135+
fn get_backend_from_raw_matches(
1136+
early_dcx: &EarlyDiagCtxt,
1137+
matches: &Matches,
1138+
) -> Box<dyn CodegenBackend> {
1139+
let debug_flags = matches.opt_strs("Z");
1140+
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
1141+
let target = parse_target_triple(early_dcx, matches);
1142+
let sysroot = filesearch::materialize_sysroot(matches.opt_str("sysroot").map(PathBuf::from));
1143+
let target = config::build_target_config(early_dcx, &target, &sysroot);
1144+
1145+
get_codegen_backend(early_dcx, &sysroot, backend_name, &target)
1146+
}
1147+
11411148
fn describe_debug_flags() {
11421149
safe_println!("\nAvailable options:\n");
11431150
print_flag_list("-Z", config::Z_OPTIONS);

Diff for: compiler/rustc_interface/src/interface.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
383383
crate::callbacks::setup_callbacks();
384384

385385
let sysroot = filesearch::materialize_sysroot(config.opts.maybe_sysroot.clone());
386-
let target = config::build_target_config(&early_dcx, &config.opts, &sysroot);
386+
let target = config::build_target_config(&early_dcx, &config.opts.target_triple, &sysroot);
387387
let file_loader = config.file_loader.unwrap_or_else(|| Box::new(RealFileLoader));
388388
let path_mapping = config.opts.file_path_mapping();
389389
let hash_kind = config.opts.unstable_opts.src_hash_algorithm(&target);

Diff for: compiler/rustc_interface/src/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ where
4242
let matches = optgroups().parse(args).unwrap();
4343
let sessopts = build_session_options(&mut early_dcx, &matches);
4444
let sysroot = filesearch::materialize_sysroot(sessopts.maybe_sysroot.clone());
45-
let target = rustc_session::config::build_target_config(&early_dcx, &sessopts, &sysroot);
45+
let target =
46+
rustc_session::config::build_target_config(&early_dcx, &sessopts.target_triple, &sysroot);
4647
let hash_kind = sessopts.unstable_opts.src_hash_algorithm(&target);
4748
let checksum_hash_kind = sessopts.unstable_opts.checksum_hash_algorithm();
4849
let sm_inputs = Some(SourceMapInputs {

Diff for: compiler/rustc_session/src/config.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,12 @@ pub fn build_configuration(sess: &Session, mut user_cfg: Cfg) -> Cfg {
13461346
user_cfg
13471347
}
13481348

1349-
pub fn build_target_config(early_dcx: &EarlyDiagCtxt, opts: &Options, sysroot: &Path) -> Target {
1350-
match Target::search(&opts.target_triple, sysroot) {
1349+
pub fn build_target_config(
1350+
early_dcx: &EarlyDiagCtxt,
1351+
target: &TargetTuple,
1352+
sysroot: &Path,
1353+
) -> Target {
1354+
match Target::search(target, sysroot) {
13511355
Ok((target, warnings)) => {
13521356
for warning in warnings.warning_messages() {
13531357
early_dcx.early_warn(warning)

Diff for: library/core/src/hint.rs

+135
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,138 @@ pub const fn black_box<T>(dummy: T) -> T {
597597
pub const fn must_use<T>(value: T) -> T {
598598
value
599599
}
600+
601+
/// Hints to the compiler that a branch condition is likely to be true.
602+
/// Returns the value passed to it.
603+
///
604+
/// It can be used with `if` or boolean `match` expressions.
605+
///
606+
/// When used outside of a branch condition, it may still influence a nearby branch, but
607+
/// probably will not have any effect.
608+
///
609+
/// It can also be applied to parts of expressions, such as `likely(a) && unlikely(b)`, or to
610+
/// compound expressions, such as `likely(a && b)`. When applied to compound expressions, it has
611+
/// the following effect:
612+
/// ```text
613+
/// likely(!a) => !unlikely(a)
614+
/// likely(a && b) => likely(a) && likely(b)
615+
/// likely(a || b) => a || likely(b)
616+
/// ```
617+
///
618+
/// See also the function [`cold_path()`] which may be more appropriate for idiomatic Rust code.
619+
///
620+
/// # Examples
621+
///
622+
/// ```
623+
/// #![feature(likely_unlikely)]
624+
/// use core::hint::likely;
625+
///
626+
/// fn foo(x: i32) {
627+
/// if likely(x > 0) {
628+
/// println!("this branch is likely to be taken");
629+
/// } else {
630+
/// println!("this branch is unlikely to be taken");
631+
/// }
632+
///
633+
/// match likely(x > 0) {
634+
/// true => println!("this branch is likely to be taken"),
635+
/// false => println!("this branch is unlikely to be taken"),
636+
/// }
637+
///
638+
/// // Use outside of a branch condition may still influence a nearby branch
639+
/// let cond = likely(x != 0);
640+
/// if cond {
641+
/// println!("this branch is likely to be taken");
642+
/// }
643+
/// }
644+
/// ```
645+
///
646+
///
647+
#[unstable(feature = "likely_unlikely", issue = "26179")]
648+
#[inline(always)]
649+
pub const fn likely(b: bool) -> bool {
650+
crate::intrinsics::likely(b)
651+
}
652+
653+
/// Hints to the compiler that a branch condition is unlikely to be true.
654+
/// Returns the value passed to it.
655+
///
656+
/// It can be used with `if` or boolean `match` expressions.
657+
///
658+
/// When used outside of a branch condition, it may still influence a nearby branch, but
659+
/// probably will not have any effect.
660+
///
661+
/// It can also be applied to parts of expressions, such as `likely(a) && unlikely(b)`, or to
662+
/// compound expressions, such as `unlikely(a && b)`. When applied to compound expressions, it has
663+
/// the following effect:
664+
/// ```text
665+
/// unlikely(!a) => !likely(a)
666+
/// unlikely(a && b) => a && unlikely(b)
667+
/// unlikely(a || b) => unlikely(a) || unlikely(b)
668+
/// ```
669+
///
670+
/// See also the function [`cold_path()`] which may be more appropriate for idiomatic Rust code.
671+
///
672+
/// # Examples
673+
///
674+
/// ```
675+
/// #![feature(likely_unlikely)]
676+
/// use core::hint::unlikely;
677+
///
678+
/// fn foo(x: i32) {
679+
/// if unlikely(x > 0) {
680+
/// println!("this branch is unlikely to be taken");
681+
/// } else {
682+
/// println!("this branch is likely to be taken");
683+
/// }
684+
///
685+
/// match unlikely(x > 0) {
686+
/// true => println!("this branch is unlikely to be taken"),
687+
/// false => println!("this branch is likely to be taken"),
688+
/// }
689+
///
690+
/// // Use outside of a branch condition may still influence a nearby branch
691+
/// let cond = unlikely(x != 0);
692+
/// if cond {
693+
/// println!("this branch is likely to be taken");
694+
/// }
695+
/// }
696+
/// ```
697+
#[unstable(feature = "likely_unlikely", issue = "26179")]
698+
#[inline(always)]
699+
pub const fn unlikely(b: bool) -> bool {
700+
crate::intrinsics::unlikely(b)
701+
}
702+
703+
/// Hints to the compiler that given path is cold, i.e., unlikely to be taken. The compiler may
704+
/// choose to optimize paths that are not cold at the expense of paths that are cold.
705+
///
706+
/// # Examples
707+
///
708+
/// ```
709+
/// #![feature(cold_path)]
710+
/// use core::hint::cold_path;
711+
///
712+
/// fn foo(x: &[i32]) {
713+
/// if let Some(first) = x.get(0) {
714+
/// // this is the fast path
715+
/// } else {
716+
/// // this path is unlikely
717+
/// cold_path();
718+
/// }
719+
/// }
720+
///
721+
/// fn bar(x: i32) -> i32 {
722+
/// match x {
723+
/// 1 => 10,
724+
/// 2 => 100,
725+
/// 3 => { cold_path(); 1000 }, // this branch is unlikely
726+
/// _ => { cold_path(); 10000 }, // this is also unlikely
727+
/// }
728+
/// }
729+
/// ```
730+
#[unstable(feature = "cold_path", issue = "26179")]
731+
#[inline(always)]
732+
pub const fn cold_path() {
733+
crate::intrinsics::cold_path()
734+
}

Diff for: library/core/src/net/ip_addr.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1539,8 +1539,9 @@ impl Ipv6Addr {
15391539
/// // Addresses reserved for benchmarking (`2001:2::/48`)
15401540
/// assert_eq!(Ipv6Addr::new(0x2001, 2, 0, 0, 0, 0, 0, 1,).is_global(), false);
15411541
///
1542-
/// // Addresses reserved for documentation (`2001:db8::/32`)
1542+
/// // Addresses reserved for documentation (`2001:db8::/32` and `3fff::/20`)
15431543
/// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1).is_global(), false);
1544+
/// assert_eq!(Ipv6Addr::new(0x3fff, 0, 0, 0, 0, 0, 0, 0).is_global(), false);
15441545
///
15451546
/// // Unique local addresses (`fc00::/7`)
15461547
/// assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 1).is_global(), false);
@@ -1686,11 +1687,12 @@ impl Ipv6Addr {
16861687
}
16871688

16881689
/// Returns [`true`] if this is an address reserved for documentation
1689-
/// (`2001:db8::/32`).
1690+
/// (`2001:db8::/32` and `3fff::/20`).
16901691
///
1691-
/// This property is defined in [IETF RFC 3849].
1692+
/// This property is defined by [IETF RFC 3849] and [IETF RFC 9637].
16921693
///
16931694
/// [IETF RFC 3849]: https://tools.ietf.org/html/rfc3849
1695+
/// [IETF RFC 9637]: https://tools.ietf.org/html/rfc9637
16941696
///
16951697
/// # Examples
16961698
///
@@ -1701,12 +1703,13 @@ impl Ipv6Addr {
17011703
///
17021704
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_documentation(), false);
17031705
/// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_documentation(), true);
1706+
/// assert_eq!(Ipv6Addr::new(0x3fff, 0, 0, 0, 0, 0, 0, 0).is_documentation(), true);
17041707
/// ```
17051708
#[unstable(feature = "ip", issue = "27709")]
17061709
#[must_use]
17071710
#[inline]
17081711
pub const fn is_documentation(&self) -> bool {
1709-
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8)
1712+
matches!(self.segments(), [0x2001, 0xdb8, ..] | [0x3fff, 0..=0x0fff, ..])
17101713
}
17111714

17121715
/// Returns [`true`] if this is an address reserved for benchmarking (`2001:2::/48`).

Diff for: library/core/tests/net/ip_addr.rs

+10
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ fn ip_properties() {
332332
check!("ff08::", global | multicast);
333333
check!("ff0e::", global | multicast);
334334
check!("2001:db8:85a3::8a2e:370:7334", doc);
335+
check!("3fff:fff:ffff:ffff:ffff:ffff:ffff:ffff", doc);
335336
check!("2001:2::ac32:23ff:21", benchmarking);
336337
check!("102:304:506:708:90a:b0c:d0e:f10", global);
337338
}
@@ -790,6 +791,15 @@ fn ipv6_properties() {
790791
documentation
791792
);
792793

794+
check!(
795+
"3fff:fff:ffff:ffff:ffff:ffff:ffff:ffff",
796+
&[
797+
0x3f, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
798+
0xff, 0xff
799+
],
800+
documentation
801+
);
802+
793803
check!(
794804
"2001:2::ac32:23ff:21",
795805
&[0x20, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0xac, 0x32, 0x23, 0xff, 0, 0x21],

Diff for: src/tools/miri/tests/fail/intrinsics/copy_overlapping.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#![feature(intrinsics)]
22

33
// Directly call intrinsic to avoid debug assertions in libstd
4-
extern "rust-intrinsic" {
5-
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
6-
}
4+
#[rustc_intrinsic]
5+
unsafe fn copy_nonoverlapping<T>(_src: *const T, _dst: *mut T, _count: usize);
76

87
fn main() {
98
let mut data = [0u8; 16];

Diff for: src/tools/miri/tests/fail/intrinsics/copy_unaligned.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#![feature(intrinsics)]
22

33
// Directly call intrinsic to avoid debug assertions in libstd
4-
extern "rust-intrinsic" {
5-
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
6-
}
4+
#[rustc_intrinsic]
5+
unsafe fn copy_nonoverlapping<T>(_src: *const T, _dst: *mut T, _count: usize);
76

87
fn main() {
98
let mut data = [0u16; 8];

Diff for: src/tools/miri/tests/fail/intrinsics/ctlz_nonzero.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#![feature(intrinsics)]
22

33
mod rusti {
4-
extern "rust-intrinsic" {
5-
pub fn ctlz_nonzero<T>(x: T) -> u32;
6-
}
4+
#[rustc_intrinsic]
5+
pub unsafe fn ctlz_nonzero<T>(_x: T) -> u32;
76
}
87

98
pub fn main() {

0 commit comments

Comments
 (0)