Skip to content

Commit bf5a38d

Browse files
committed
Auto merge of #141133 - matthiaskrgr:rollup-u8ndxyz, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #135808 (Implement Display for ``rustc_target::callconv::Conv``) - #137432 (Add as_ascii_unchecked() methods to char, u8, and str) - #139103 (deduplicate abort implementations) - #140917 (checktools.sh: fix bashism) - #141035 (turn lld warning on old gccs into info log) - #141118 (Enable rust-analyzer to go from query definition to the corresponding provider field) - #141121 (Only select true errors in `impossible_predicates`) - #141125 (check coroutines with `TypingMode::Borrowck` to avoid cyclic reasoning) - #141131 (Make some `match`es slightly more ergonomic in `librustdoc`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2c12b4a + 339a46c commit bf5a38d

File tree

69 files changed

+427
-311
lines changed

Some content is hidden

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

69 files changed

+427
-311
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ fn link_natively(
768768
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-fuse-ld=lld")
769769
{
770770
info!("linker output: {:?}", out);
771-
warn!("The linker driver does not support `-fuse-ld=lld`. Retrying without it.");
771+
info!("The linker driver does not support `-fuse-ld=lld`. Retrying without it.");
772772
for arg in cmd.take_args() {
773773
if arg.to_string_lossy() != "-fuse-ld=lld" {
774774
cmd.arg(arg);

compiler/rustc_const_eval/src/interpret/call.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
353353
if caller_fn_abi.conv != callee_fn_abi.conv {
354354
throw_ub_custom!(
355355
fluent::const_eval_incompatible_calling_conventions,
356-
callee_conv = format!("{:?}", callee_fn_abi.conv),
357-
caller_conv = format!("{:?}", caller_fn_abi.conv),
356+
callee_conv = format!("{}", callee_fn_abi.conv),
357+
caller_conv = format!("{}", caller_fn_abi.conv),
358358
)
359359
}
360360

compiler/rustc_hir_analysis/src/check/check.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1754,17 +1754,19 @@ pub(super) fn check_coroutine_obligations(
17541754
debug!(?typeck_results.coroutine_stalled_predicates);
17551755

17561756
let mode = if tcx.next_trait_solver_globally() {
1757-
TypingMode::post_borrowck_analysis(tcx, def_id)
1757+
// This query is conceptually between HIR typeck and
1758+
// MIR borrowck. We use the opaque types defined by HIR
1759+
// and ignore region constraints.
1760+
TypingMode::borrowck(tcx, def_id)
17581761
} else {
17591762
TypingMode::analysis_in_body(tcx, def_id)
17601763
};
17611764

1762-
let infcx = tcx
1763-
.infer_ctxt()
1764-
// typeck writeback gives us predicates with their regions erased.
1765-
// As borrowck already has checked lifetimes, we do not need to do it again.
1766-
.ignoring_regions()
1767-
.build(mode);
1765+
// Typeck writeback gives us predicates with their regions erased.
1766+
// We only need to check the goals while ignoring lifetimes to give good
1767+
// error message and to avoid breaking the assumption of `mir_borrowck`
1768+
// that all obligations already hold modulo regions.
1769+
let infcx = tcx.infer_ctxt().ignoring_regions().build(mode);
17681770

17691771
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
17701772
for (predicate, cause) in &typeck_results.coroutine_stalled_predicates {
@@ -1785,6 +1787,10 @@ pub(super) fn check_coroutine_obligations(
17851787
let key = infcx.resolve_vars_if_possible(key);
17861788
sanity_check_found_hidden_type(tcx, key, hidden_type)?;
17871789
}
1790+
} else {
1791+
// We're not checking region constraints here, so we can simply drop the
1792+
// added opaque type uses in `TypingMode::Borrowck`.
1793+
let _ = infcx.take_opaque_types();
17881794
}
17891795

17901796
Ok(())

compiler/rustc_macros/src/query.rs

+14
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,18 @@ fn add_query_desc_cached_impl(
267267
) {
268268
let Query { name, key, modifiers, .. } = &query;
269269

270+
// This dead code exists to instruct rust-analyzer about the link between the `rustc_queries`
271+
// query names and the corresponding produced provider. The issue is that by nature of this
272+
// macro producing a higher order macro that has all its token in the macro declaration we lose
273+
// any meaningful spans, resulting in rust-analyzer being unable to make the connection between
274+
// the query name and the corresponding providers field. The trick to fix this is to have
275+
// `rustc_queries` emit a field access with the given name's span which allows it to succesfully
276+
// show references / go to definition to the correspondig provider assignment which is usually
277+
// the more interesting place.
278+
let ra_hint = quote! {
279+
let crate::query::Providers { #name: _, .. };
280+
};
281+
270282
// Find out if we should cache the query on disk
271283
let cache = if let Some((args, expr)) = modifiers.cache.as_ref() {
272284
let tcx = args.as_ref().map(|t| quote! { #t }).unwrap_or_else(|| quote! { _ });
@@ -277,6 +289,7 @@ fn add_query_desc_cached_impl(
277289
#[allow(unused_variables, unused_braces, rustc::pass_by_value)]
278290
#[inline]
279291
pub fn #name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::query::queries::#name::Key<'tcx>) -> bool {
292+
#ra_hint
280293
#expr
281294
}
282295
}
@@ -286,6 +299,7 @@ fn add_query_desc_cached_impl(
286299
#[allow(rustc::pass_by_value)]
287300
#[inline]
288301
pub fn #name<'tcx>(_: TyCtxt<'tcx>, _: &crate::query::queries::#name::Key<'tcx>) -> bool {
302+
#ra_hint
289303
false
290304
}
291305
}

compiler/rustc_target/src/callconv/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::fmt::Display;
12
use std::str::FromStr;
23
use std::{fmt, iter};
34

@@ -895,6 +896,37 @@ impl FromStr for Conv {
895896
}
896897
}
897898

899+
fn conv_to_externabi(conv: &Conv) -> ExternAbi {
900+
match conv {
901+
Conv::C => ExternAbi::C { unwind: false },
902+
Conv::Rust => ExternAbi::Rust,
903+
Conv::PreserveMost => ExternAbi::RustCold,
904+
Conv::ArmAapcs => ExternAbi::Aapcs { unwind: false },
905+
Conv::CCmseNonSecureCall => ExternAbi::CCmseNonSecureCall,
906+
Conv::CCmseNonSecureEntry => ExternAbi::CCmseNonSecureEntry,
907+
Conv::Msp430Intr => ExternAbi::Msp430Interrupt,
908+
Conv::GpuKernel => ExternAbi::GpuKernel,
909+
Conv::X86Fastcall => ExternAbi::Fastcall { unwind: false },
910+
Conv::X86Intr => ExternAbi::X86Interrupt,
911+
Conv::X86Stdcall => ExternAbi::Stdcall { unwind: false },
912+
Conv::X86ThisCall => ExternAbi::Thiscall { unwind: false },
913+
Conv::X86VectorCall => ExternAbi::Vectorcall { unwind: false },
914+
Conv::X86_64SysV => ExternAbi::SysV64 { unwind: false },
915+
Conv::X86_64Win64 => ExternAbi::Win64 { unwind: false },
916+
Conv::AvrInterrupt => ExternAbi::AvrInterrupt,
917+
Conv::AvrNonBlockingInterrupt => ExternAbi::AvrNonBlockingInterrupt,
918+
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Machine } => ExternAbi::RiscvInterruptM,
919+
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Supervisor } => ExternAbi::RiscvInterruptS,
920+
Conv::Cold | Conv::PreserveAll => unreachable!(),
921+
}
922+
}
923+
924+
impl Display for Conv {
925+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
926+
write!(f, "{}", conv_to_externabi(self))
927+
}
928+
}
929+
898930
// Some types are used a lot. Make sure they don't unintentionally get bigger.
899931
#[cfg(target_pointer_width = "64")]
900932
mod size_asserts {

compiler/rustc_trait_selection/src/traits/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,15 @@ pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec<ty::Clause
701701
let obligation = Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate);
702702
ocx.register_obligation(obligation);
703703
}
704-
let errors = ocx.select_all_or_error();
705704

706-
if !errors.is_empty() {
705+
// Use `select_where_possible` to only return impossible for true errors,
706+
// and not ambiguities or overflows. Since the new trait solver forces
707+
// some currently undetected overlap between `dyn Trait: Trait` built-in
708+
// vs user-written impls to AMBIGUOUS, this may return ambiguity even
709+
// with no infer vars. There may also be ways to encounter ambiguity due
710+
// to post-mono overflow.
711+
let true_errors = ocx.select_where_possible();
712+
if !true_errors.is_empty() {
707713
return true;
708714
}
709715

library/Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ name = "panic_abort"
196196
version = "0.0.0"
197197
dependencies = [
198198
"alloc",
199-
"cfg-if",
200199
"compiler_builtins",
201200
"core",
202201
"libc",

library/core/src/char/methods.rs

+21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::*;
44
use crate::panic::const_panic;
55
use crate::slice;
66
use crate::str::from_utf8_unchecked_mut;
7+
use crate::ub_checks::assert_unsafe_precondition;
78
use crate::unicode::printable::is_printable;
89
use crate::unicode::{self, conversions};
910

@@ -1202,6 +1203,26 @@ impl char {
12021203
}
12031204
}
12041205

1206+
/// Converts this char into an [ASCII character](`ascii::Char`), without
1207+
/// checking whether it is valid.
1208+
///
1209+
/// # Safety
1210+
///
1211+
/// This char must be within the ASCII range, or else this is UB.
1212+
#[must_use]
1213+
#[unstable(feature = "ascii_char", issue = "110998")]
1214+
#[inline]
1215+
pub const unsafe fn as_ascii_unchecked(&self) -> ascii::Char {
1216+
assert_unsafe_precondition!(
1217+
check_library_ub,
1218+
"as_ascii_unchecked requires that the char is valid ASCII",
1219+
(it: &char = self) => it.is_ascii()
1220+
);
1221+
1222+
// SAFETY: the caller promised that this char is ASCII.
1223+
unsafe { ascii::Char::from_u8_unchecked(*self as u8) }
1224+
}
1225+
12051226
/// Makes a copy of the value in its ASCII upper case equivalent.
12061227
///
12071228
/// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z',

library/core/src/num/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,26 @@ impl u8 {
492492
ascii::Char::from_u8(*self)
493493
}
494494

495+
/// Converts this byte to an [ASCII character](ascii::Char), without
496+
/// checking whether or not it's valid.
497+
///
498+
/// # Safety
499+
///
500+
/// This byte must be valid ASCII, or else this is UB.
501+
#[must_use]
502+
#[unstable(feature = "ascii_char", issue = "110998")]
503+
#[inline]
504+
pub const unsafe fn as_ascii_unchecked(&self) -> ascii::Char {
505+
assert_unsafe_precondition!(
506+
check_library_ub,
507+
"as_ascii_unchecked requires that the byte is valid ASCII",
508+
(it: &u8 = self) => it.is_ascii()
509+
);
510+
511+
// SAFETY: the caller promised that this byte is ASCII.
512+
unsafe { ascii::Char::from_u8_unchecked(*self) }
513+
}
514+
495515
/// Makes a copy of the value in its ASCII upper case equivalent.
496516
///
497517
/// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z',

library/core/src/str/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use self::pattern::{DoubleEndedSearcher, Pattern, ReverseSearcher, Searcher};
1717
use crate::char::{self, EscapeDebugExtArgs};
1818
use crate::ops::Range;
1919
use crate::slice::{self, SliceIndex};
20+
use crate::ub_checks::assert_unsafe_precondition;
2021
use crate::{ascii, mem};
2122

2223
pub mod pattern;
@@ -2634,6 +2635,27 @@ impl str {
26342635
self.as_bytes().as_ascii()
26352636
}
26362637

2638+
/// Converts this string slice into a slice of [ASCII characters](ascii::Char),
2639+
/// without checking whether they are valid.
2640+
///
2641+
/// # Safety
2642+
///
2643+
/// Every character in this string must be ASCII, or else this is UB.
2644+
#[unstable(feature = "ascii_char", issue = "110998")]
2645+
#[must_use]
2646+
#[inline]
2647+
pub const unsafe fn as_ascii_unchecked(&self) -> &[ascii::Char] {
2648+
assert_unsafe_precondition!(
2649+
check_library_ub,
2650+
"as_ascii_unchecked requires that the string is valid ASCII",
2651+
(it: &str = self) => it.is_ascii()
2652+
);
2653+
2654+
// SAFETY: the caller promised that every byte of this string slice
2655+
// is ASCII.
2656+
unsafe { self.as_bytes().as_ascii_unchecked() }
2657+
}
2658+
26372659
/// Checks that two strings are an ASCII case-insensitive match.
26382660
///
26392661
/// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`,

library/panic_abort/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ bench = false
1212
doc = false
1313

1414
[dependencies]
15-
alloc = { path = "../alloc" }
16-
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1715
core = { path = "../core" }
1816
compiler_builtins = "0.1.0"
1917

20-
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
18+
[target.'cfg(target_os = "android")'.dependencies]
2119
libc = { version = "0.2", default-features = false }
20+
21+
[target.'cfg(any(target_os = "android", target_os = "zkvm"))'.dependencies]
22+
alloc = { path = "../alloc" }

library/panic_abort/src/lib.rs

+5-71
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77
#![unstable(feature = "panic_abort", issue = "32837")]
88
#![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
99
#![panic_runtime]
10-
#![allow(unused_features)]
11-
#![feature(asm_experimental_arch)]
12-
#![feature(core_intrinsics)]
1310
#![feature(panic_runtime)]
1411
#![feature(std_internals)]
1512
#![feature(staged_api)]
1613
#![feature(rustc_attrs)]
1714
#![allow(internal_features)]
18-
#![deny(unsafe_op_in_unsafe_fn)]
1915

2016
#[cfg(target_os = "android")]
2117
mod android;
@@ -45,75 +41,13 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
4541
zkvm::zkvm_set_abort_message(_payload);
4642
}
4743

48-
unsafe {
49-
abort();
44+
unsafe extern "Rust" {
45+
// This is defined in std::rt.
46+
#[rustc_std_internal_symbol]
47+
safe fn __rust_abort() -> !;
5048
}
5149

52-
cfg_if::cfg_if! {
53-
if #[cfg(any(unix, target_os = "solid_asp3"))] {
54-
unsafe fn abort() -> ! {
55-
unsafe { libc::abort(); }
56-
}
57-
} else if #[cfg(any(target_os = "hermit",
58-
all(target_vendor = "fortanix", target_env = "sgx"),
59-
target_os = "xous",
60-
target_os = "uefi",
61-
))] {
62-
unsafe fn abort() -> ! {
63-
// call std::sys::abort_internal
64-
unsafe extern "C" {
65-
pub fn __rust_abort() -> !;
66-
}
67-
unsafe { __rust_abort(); }
68-
}
69-
} else if #[cfg(all(windows, not(miri)))] {
70-
// On Windows, use the processor-specific __fastfail mechanism. In Windows 8
71-
// and later, this will terminate the process immediately without running any
72-
// in-process exception handlers. In earlier versions of Windows, this
73-
// sequence of instructions will be treated as an access violation,
74-
// terminating the process but without necessarily bypassing all exception
75-
// handlers.
76-
//
77-
// https://docs.microsoft.com/en-us/cpp/intrinsics/fastfail
78-
//
79-
// Note: this is the same implementation as in std's `abort_internal`
80-
unsafe fn abort() -> ! {
81-
#[allow(unused)]
82-
const FAST_FAIL_FATAL_APP_EXIT: usize = 7;
83-
cfg_if::cfg_if! {
84-
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
85-
unsafe {
86-
core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
87-
}
88-
} else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] {
89-
unsafe {
90-
core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
91-
}
92-
} else if #[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))] {
93-
unsafe {
94-
core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
95-
}
96-
} else {
97-
core::intrinsics::abort();
98-
}
99-
}
100-
}
101-
} else if #[cfg(target_os = "teeos")] {
102-
mod teeos {
103-
unsafe extern "C" {
104-
pub fn TEE_Panic(code: u32) -> !;
105-
}
106-
}
107-
108-
unsafe fn abort() -> ! {
109-
unsafe { teeos::TEE_Panic(1); }
110-
}
111-
} else {
112-
unsafe fn abort() -> ! {
113-
core::intrinsics::abort();
114-
}
115-
}
116-
}
50+
__rust_abort()
11751
}
11852

11953
// This... is a bit of an oddity. The tl;dr; is that this is required to link

0 commit comments

Comments
 (0)