Skip to content

Commit c57119b

Browse files
committed
Auto merge of #142142 - jhpratt:rollup-frlezq2, r=jhpratt
Rollup of 8 pull requests Successful merges: - #137992 (Stabilise `os_string_pathbuf_leak`) - #141558 (Limit the size of cgu names when using the `-Zhuman-readable-cgu-name…) - #141797 (compiler: set Apple frame pointers by architecture) - #141857 (coretests: move float tests from num to floats module and use a more flexible macro to generate them) - #142045 (Make obligation cause code suggestions verbose) - #142076 (Check documentation of bootstrap in PR CI) - #142110 (Add solaris targets to build-manifest) - #142131 (Make cast suggestions verbose) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1dc9ae6 + fb6977c commit c57119b

File tree

51 files changed

+815
-570
lines changed

Some content is hidden

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

51 files changed

+815
-570
lines changed

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 43 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -380,20 +380,21 @@ impl<'a, 'tcx> CastCheck<'tcx> {
380380
err.span_label(self.span, "invalid cast");
381381
if self.expr_ty.is_numeric() {
382382
if self.expr_ty == fcx.tcx.types.u32 {
383-
match fcx.tcx.sess.source_map().span_to_snippet(self.expr.span) {
384-
Ok(snippet) => err.span_suggestion(
385-
self.span,
386-
"try `char::from_u32` instead",
387-
format!("char::from_u32({snippet})"),
388-
Applicability::MachineApplicable,
389-
),
390-
391-
Err(_) => err.span_help(self.span, "try `char::from_u32` instead"),
392-
};
383+
err.multipart_suggestion(
384+
"consider using `char::from_u32` instead",
385+
vec![
386+
(self.expr_span.shrink_to_lo(), "char::from_u32(".to_string()),
387+
(self.expr_span.shrink_to_hi().to(self.cast_span), ")".to_string()),
388+
],
389+
Applicability::MachineApplicable,
390+
);
393391
} else if self.expr_ty == fcx.tcx.types.i8 {
394-
err.span_help(self.span, "try casting from `u8` instead");
392+
err.span_help(self.span, "consider casting from `u8` instead");
395393
} else {
396-
err.span_help(self.span, "try `char::from_u32` instead (via a `u32`)");
394+
err.span_help(
395+
self.span,
396+
"consider using `char::from_u32` instead (via a `u32`)",
397+
);
397398
};
398399
}
399400
err.emit();
@@ -494,38 +495,31 @@ impl<'a, 'tcx> CastCheck<'tcx> {
494495
self.cast_ty.kind(),
495496
ty::FnDef(..) | ty::FnPtr(..) | ty::Closure(..)
496497
) {
497-
let mut label = true;
498498
// Check `impl From<self.expr_ty> for self.cast_ty {}` for accurate suggestion:
499-
if let Ok(snippet) = fcx.tcx.sess.source_map().span_to_snippet(self.expr_span)
500-
&& let Some(from_trait) = fcx.tcx.get_diagnostic_item(sym::From)
501-
{
499+
if let Some(from_trait) = fcx.tcx.get_diagnostic_item(sym::From) {
502500
let ty = fcx.resolve_vars_if_possible(self.cast_ty);
503501
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
504502
if fcx
505503
.infcx
506504
.type_implements_trait(from_trait, [ty, expr_ty], fcx.param_env)
507505
.must_apply_modulo_regions()
508506
{
509-
label = false;
510-
if let ty::Adt(def, args) = self.cast_ty.kind() {
511-
err.span_suggestion_verbose(
512-
self.span,
513-
"consider using the `From` trait instead",
514-
format!(
515-
"{}::from({})",
516-
fcx.tcx.value_path_str_with_args(def.did(), args),
517-
snippet
518-
),
519-
Applicability::MaybeIncorrect,
520-
);
507+
let to_ty = if let ty::Adt(def, args) = self.cast_ty.kind() {
508+
fcx.tcx.value_path_str_with_args(def.did(), args)
521509
} else {
522-
err.span_suggestion(
523-
self.span,
524-
"consider using the `From` trait instead",
525-
format!("{}::from({})", self.cast_ty, snippet),
526-
Applicability::MaybeIncorrect,
527-
);
510+
self.cast_ty.to_string()
528511
};
512+
err.multipart_suggestion(
513+
"consider using the `From` trait instead",
514+
vec![
515+
(self.expr_span.shrink_to_lo(), format!("{to_ty}::from(")),
516+
(
517+
self.expr_span.shrink_to_hi().to(self.cast_span),
518+
")".to_string(),
519+
),
520+
],
521+
Applicability::MaybeIncorrect,
522+
);
529523
}
530524
}
531525

@@ -548,11 +542,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
548542
)
549543
};
550544

551-
if label {
552-
err.span_label(self.span, msg);
553-
} else {
554-
err.note(msg);
555-
}
545+
err.span_label(self.span, msg);
556546

557547
if let Some(note) = note {
558548
err.note(note);
@@ -654,38 +644,22 @@ impl<'a, 'tcx> CastCheck<'tcx> {
654644
match self.expr_ty.kind() {
655645
ty::Ref(_, _, mt) => {
656646
let mtstr = mt.prefix_str();
657-
match fcx.tcx.sess.source_map().span_to_snippet(self.cast_span) {
658-
Ok(s) => {
659-
err.span_suggestion(
660-
self.cast_span,
661-
"try casting to a reference instead",
662-
format!("&{mtstr}{s}"),
663-
Applicability::MachineApplicable,
664-
);
665-
}
666-
Err(_) => {
667-
let msg = format!("did you mean `&{mtstr}{tstr}`?");
668-
err.span_help(self.cast_span, msg);
669-
}
670-
}
647+
err.span_suggestion_verbose(
648+
self.cast_span.shrink_to_lo(),
649+
"consider casting to a reference instead",
650+
format!("&{mtstr}"),
651+
Applicability::MachineApplicable,
652+
);
671653
}
672654
ty::Adt(def, ..) if def.is_box() => {
673-
match fcx.tcx.sess.source_map().span_to_snippet(self.cast_span) {
674-
Ok(s) => {
675-
err.span_suggestion(
676-
self.cast_span,
677-
"you can cast to a `Box` instead",
678-
format!("Box<{s}>"),
679-
Applicability::MachineApplicable,
680-
);
681-
}
682-
Err(_) => {
683-
err.span_help(
684-
self.cast_span,
685-
format!("you might have meant `Box<{tstr}>`"),
686-
);
687-
}
688-
}
655+
err.multipart_suggestion(
656+
"you can cast to a `Box` instead",
657+
vec![
658+
(self.cast_span.shrink_to_lo(), "Box<".to_string()),
659+
(self.cast_span.shrink_to_hi(), ">".to_string()),
660+
],
661+
Applicability::MachineApplicable,
662+
);
689663
}
690664
_ => {
691665
err.span_help(self.expr_span, "consider using a box or reference as appropriate");

compiler/rustc_middle/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#![feature(negative_impls)]
5252
#![feature(never_type)]
5353
#![feature(ptr_alignment_type)]
54+
#![feature(round_char_boundary)]
5455
#![feature(rustc_attrs)]
5556
#![feature(rustdoc_internals)]
5657
#![feature(trusted_len)]

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Cow;
12
use std::fmt;
23
use std::hash::Hash;
34

@@ -468,6 +469,29 @@ impl<'tcx> CodegenUnit<'tcx> {
468469
hash.as_u128().to_base_fixed_len(CASE_INSENSITIVE)
469470
}
470471

472+
pub fn shorten_name(human_readable_name: &str) -> Cow<'_, str> {
473+
// Set a limit a somewhat below the common platform limits for file names.
474+
const MAX_CGU_NAME_LENGTH: usize = 200;
475+
const TRUNCATED_NAME_PREFIX: &str = "-trunc-";
476+
if human_readable_name.len() > MAX_CGU_NAME_LENGTH {
477+
let mangled_name = Self::mangle_name(human_readable_name);
478+
// Determine a safe byte offset to truncate the name to
479+
let truncate_to = human_readable_name.floor_char_boundary(
480+
MAX_CGU_NAME_LENGTH - TRUNCATED_NAME_PREFIX.len() - mangled_name.len(),
481+
);
482+
format!(
483+
"{}{}{}",
484+
&human_readable_name[..truncate_to],
485+
TRUNCATED_NAME_PREFIX,
486+
mangled_name
487+
)
488+
.into()
489+
} else {
490+
// If the name is short enough, we can just return it as is.
491+
human_readable_name.into()
492+
}
493+
}
494+
471495
pub fn compute_size_estimate(&mut self) {
472496
// The size of a codegen unit as the sum of the sizes of the items
473497
// within it.
@@ -604,7 +628,7 @@ impl<'tcx> CodegenUnitNameBuilder<'tcx> {
604628
let cgu_name = self.build_cgu_name_no_mangle(cnum, components, special_suffix);
605629

606630
if self.tcx.sess.opts.unstable_opts.human_readable_cgu_names {
607-
cgu_name
631+
Symbol::intern(&CodegenUnit::shorten_name(cgu_name.as_str()))
608632
} else {
609633
Symbol::intern(&CodegenUnit::mangle_name(cgu_name.as_str()))
610634
}

compiler/rustc_monomorphize/src/partitioning.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,15 @@ fn merge_codegen_units<'tcx>(
461461

462462
for cgu in codegen_units.iter_mut() {
463463
if let Some(new_cgu_name) = new_cgu_names.get(&cgu.name()) {
464-
if cx.tcx.sess.opts.unstable_opts.human_readable_cgu_names {
465-
cgu.set_name(Symbol::intern(new_cgu_name));
464+
let new_cgu_name = if cx.tcx.sess.opts.unstable_opts.human_readable_cgu_names {
465+
Symbol::intern(&CodegenUnit::shorten_name(new_cgu_name))
466466
} else {
467467
// If we don't require CGU names to be human-readable,
468468
// we use a fixed length hash of the composite CGU name
469469
// instead.
470-
let new_cgu_name = CodegenUnit::mangle_name(new_cgu_name);
471-
cgu.set_name(Symbol::intern(&new_cgu_name));
472-
}
470+
Symbol::intern(&CodegenUnit::mangle_name(new_cgu_name))
471+
};
472+
cgu.set_name(new_cgu_name);
473473
}
474474
}
475475

compiler/rustc_target/src/spec/base/apple/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ pub(crate) fn base(
124124
// to v4, so we do the same.
125125
// https://github.com/llvm/llvm-project/blob/378778a0d10c2f8d5df8ceff81f95b6002984a4b/clang/lib/Driver/ToolChains/Darwin.cpp#L1203
126126
default_dwarf_version: 4,
127-
frame_pointer: FramePointer::Always,
127+
frame_pointer: match arch {
128+
// clang ignores `-fomit-frame-pointer` for Armv7, it only accepts `-momit-leaf-frame-pointer`
129+
Armv7k | Armv7s => FramePointer::Always,
130+
// clang supports omitting frame pointers for the rest, but... don't?
131+
Arm64 | Arm64e | Arm64_32 => FramePointer::NonLeaf,
132+
I386 | I686 | X86_64 | X86_64h => FramePointer::Always,
133+
},
128134
has_rpath: true,
129135
dll_suffix: ".dylib".into(),
130136
archive_format: "darwin".into(),

compiler/rustc_target/src/spec/targets/aarch64_apple_darwin.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::base::apple::{Arch, TargetAbi, base};
2-
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};
2+
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
33

44
pub(crate) fn target() -> Target {
55
let (opts, llvm_target, arch) = base("macos", Arch::Arm64, TargetAbi::Normal);
@@ -17,7 +17,6 @@ pub(crate) fn target() -> Target {
1717
arch,
1818
options: TargetOptions {
1919
mcount: "\u{1}mcount".into(),
20-
frame_pointer: FramePointer::NonLeaf,
2120
cpu: "apple-m1".into(),
2221
max_atomic_width: Some(128),
2322
// FIXME: The leak sanitizer currently fails the tests, see #88132.

compiler/rustc_target/src/spec/targets/aarch64_apple_ios.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::base::apple::{Arch, TargetAbi, base};
2-
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};
2+
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
33

44
pub(crate) fn target() -> Target {
55
let (opts, llvm_target, arch) = base("ios", Arch::Arm64, TargetAbi::Normal);
@@ -18,7 +18,6 @@ pub(crate) fn target() -> Target {
1818
options: TargetOptions {
1919
features: "+neon,+fp-armv8,+apple-a7".into(),
2020
max_atomic_width: Some(128),
21-
frame_pointer: FramePointer::NonLeaf,
2221
supported_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::THREAD,
2322
..opts
2423
},

compiler/rustc_target/src/spec/targets/aarch64_apple_ios_macabi.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::base::apple::{Arch, TargetAbi, base};
2-
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};
2+
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
33

44
pub(crate) fn target() -> Target {
55
let (opts, llvm_target, arch) = base("ios", Arch::Arm64, TargetAbi::MacCatalyst);
@@ -18,7 +18,6 @@ pub(crate) fn target() -> Target {
1818
options: TargetOptions {
1919
features: "+neon,+fp-armv8,+apple-a12".into(),
2020
max_atomic_width: Some(128),
21-
frame_pointer: FramePointer::NonLeaf,
2221
supported_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::THREAD,
2322
..opts
2423
},

compiler/rustc_target/src/spec/targets/aarch64_apple_ios_sim.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::base::apple::{Arch, TargetAbi, base};
2-
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};
2+
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
33

44
pub(crate) fn target() -> Target {
55
let (opts, llvm_target, arch) = base("ios", Arch::Arm64, TargetAbi::Simulator);
@@ -18,7 +18,6 @@ pub(crate) fn target() -> Target {
1818
options: TargetOptions {
1919
features: "+neon,+fp-armv8,+apple-a7".into(),
2020
max_atomic_width: Some(128),
21-
frame_pointer: FramePointer::NonLeaf,
2221
supported_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::THREAD,
2322
..opts
2423
},

compiler/rustc_target/src/spec/targets/aarch64_apple_tvos.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::base::apple::{Arch, TargetAbi, base};
2-
use crate::spec::{FramePointer, Target, TargetMetadata, TargetOptions};
2+
use crate::spec::{Target, TargetMetadata, TargetOptions};
33

44
pub(crate) fn target() -> Target {
55
let (opts, llvm_target, arch) = base("tvos", Arch::Arm64, TargetAbi::Normal);
@@ -18,7 +18,6 @@ pub(crate) fn target() -> Target {
1818
options: TargetOptions {
1919
features: "+neon,+fp-armv8,+apple-a7".into(),
2020
max_atomic_width: Some(128),
21-
frame_pointer: FramePointer::NonLeaf,
2221
..opts
2322
},
2423
}

compiler/rustc_target/src/spec/targets/aarch64_apple_tvos_sim.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::base::apple::{Arch, TargetAbi, base};
2-
use crate::spec::{FramePointer, Target, TargetMetadata, TargetOptions};
2+
use crate::spec::{Target, TargetMetadata, TargetOptions};
33

44
pub(crate) fn target() -> Target {
55
let (opts, llvm_target, arch) = base("tvos", Arch::Arm64, TargetAbi::Simulator);
@@ -18,7 +18,6 @@ pub(crate) fn target() -> Target {
1818
options: TargetOptions {
1919
features: "+neon,+fp-armv8,+apple-a7".into(),
2020
max_atomic_width: Some(128),
21-
frame_pointer: FramePointer::NonLeaf,
2221
..opts
2322
},
2423
}

compiler/rustc_target/src/spec/targets/aarch64_apple_visionos.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::base::apple::{Arch, TargetAbi, base};
2-
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};
2+
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
33

44
pub(crate) fn target() -> Target {
55
let (opts, llvm_target, arch) = base("visionos", Arch::Arm64, TargetAbi::Normal);
@@ -18,7 +18,6 @@ pub(crate) fn target() -> Target {
1818
options: TargetOptions {
1919
features: "+neon,+fp-armv8,+apple-a16".into(),
2020
max_atomic_width: Some(128),
21-
frame_pointer: FramePointer::NonLeaf,
2221
supported_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::THREAD,
2322
..opts
2423
},

compiler/rustc_target/src/spec/targets/aarch64_apple_visionos_sim.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::base::apple::{Arch, TargetAbi, base};
2-
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};
2+
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
33

44
pub(crate) fn target() -> Target {
55
let (opts, llvm_target, arch) = base("visionos", Arch::Arm64, TargetAbi::Simulator);
@@ -18,7 +18,6 @@ pub(crate) fn target() -> Target {
1818
options: TargetOptions {
1919
features: "+neon,+fp-armv8,+apple-a16".into(),
2020
max_atomic_width: Some(128),
21-
frame_pointer: FramePointer::NonLeaf,
2221
supported_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::THREAD,
2322
..opts
2423
},

compiler/rustc_target/src/spec/targets/aarch64_apple_watchos_sim.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::base::apple::{Arch, TargetAbi, base};
2-
use crate::spec::{FramePointer, Target, TargetMetadata, TargetOptions};
2+
use crate::spec::{Target, TargetMetadata, TargetOptions};
33

44
pub(crate) fn target() -> Target {
55
let (opts, llvm_target, arch) = base("watchos", Arch::Arm64, TargetAbi::Simulator);
@@ -18,7 +18,6 @@ pub(crate) fn target() -> Target {
1818
options: TargetOptions {
1919
features: "+neon,+fp-armv8,+apple-a7".into(),
2020
max_atomic_width: Some(128),
21-
frame_pointer: FramePointer::NonLeaf,
2221
..opts
2322
},
2423
}

compiler/rustc_target/src/spec/targets/arm64e_apple_darwin.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::base::apple::{Arch, TargetAbi, base};
2-
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};
2+
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
33

44
pub(crate) fn target() -> Target {
55
let (opts, llvm_target, arch) = base("macos", Arch::Arm64e, TargetAbi::Normal);
@@ -17,7 +17,6 @@ pub(crate) fn target() -> Target {
1717
arch,
1818
options: TargetOptions {
1919
mcount: "\u{1}mcount".into(),
20-
frame_pointer: FramePointer::NonLeaf,
2120
cpu: "apple-m1".into(),
2221
max_atomic_width: Some(128),
2322
// FIXME: The leak sanitizer currently fails the tests, see #88132.

0 commit comments

Comments
 (0)