Skip to content

Rollup of 9 pull requests #141133

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

Merged
merged 30 commits into from
May 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
701b194
impl Display for Conv
tiif Jan 21, 2025
17c6eae
Add test and change ub message wording
tiif Feb 3, 2025
43c51e9
Remove unnecessary assert
tiif Feb 3, 2025
d463c5d
Implement Display by mapping Conv to ExternAbi
tiif Mar 11, 2025
3079213
Remove test
tiif Mar 11, 2025
c8197b7
fmt
tiif Mar 11, 2025
71c4b24
Remove invalid Conv
tiif Mar 11, 2025
650c8a2
bless test
tiif Mar 12, 2025
e74fe7a
Bless more test
tiif Mar 12, 2025
f96fb61
checktools.sh: fix bashism
RalfJung May 11, 2025
41a2260
Use unreachable instead of panic
tiif May 12, 2025
55ad9cd
silence unexpected lld warning on old gccs
lqd May 15, 2025
b7f2cd3
deduplicate abort implementations
joboet Mar 29, 2025
6647cbb
improve internal fastfail explainer
joboet Apr 21, 2025
f77c160
normalize abort calls in miri tests
joboet May 15, 2025
7d9f437
Add as_ascii_unchecked() methods to char, str, and u8
Feb 22, 2025
101e24a
Add assert_unsafe_precondition!()s to as_ascii_unchecked() methods
May 13, 2025
1c9f20f
Enable rust-analyzer to go from query definition to the corresponding…
Veykril May 17, 2025
9578b59
Only select true errors in impossible_predicates
compiler-errors May 17, 2025
667504b
check coroutines with TypingMode::Borrowck to avoid cyclic reasoning
lcnr May 17, 2025
a4765c9
Make some `match`es slightly more ergonomic in `librustdoc`
yotamofek May 17, 2025
836db3c
Rollup merge of #135808 - tiif:conv_display, r=workingjubilee
matthiaskrgr May 17, 2025
eb01ba0
Rollup merge of #137432 - djscythe:char_u8_str_as_ascii_unchecked, r=…
matthiaskrgr May 17, 2025
b9839ab
Rollup merge of #139103 - joboet:abort_dedup, r=tgross35
matthiaskrgr May 17, 2025
f0b1150
Rollup merge of #140917 - RalfJung:checktools, r=WaffleLapkin
matthiaskrgr May 17, 2025
73ea8d7
Rollup merge of #141035 - lqd:lld-warn, r=Mark-Simulacrum
matthiaskrgr May 17, 2025
57a400d
Rollup merge of #141118 - Veykril:lw-ymmtxytkrrqs, r=compiler-errors
matthiaskrgr May 17, 2025
616650b
Rollup merge of #141121 - compiler-errors:ambig-is-not-err, r=lcnr
matthiaskrgr May 17, 2025
9090987
Rollup merge of #141125 - lcnr:coroutine_obligations_use_borrowck, r=…
matthiaskrgr May 17, 2025
339a46c
Rollup merge of #141131 - yotamofek:pr/rustdoc/match-ergo, r=fmease
matthiaskrgr May 17, 2025
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
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ fn link_natively(
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-fuse-ld=lld")
{
info!("linker output: {:?}", out);
warn!("The linker driver does not support `-fuse-ld=lld`. Retrying without it.");
info!("The linker driver does not support `-fuse-ld=lld`. Retrying without it.");
for arg in cmd.take_args() {
if arg.to_string_lossy() != "-fuse-ld=lld" {
cmd.arg(arg);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
if caller_fn_abi.conv != callee_fn_abi.conv {
throw_ub_custom!(
fluent::const_eval_incompatible_calling_conventions,
callee_conv = format!("{:?}", callee_fn_abi.conv),
caller_conv = format!("{:?}", caller_fn_abi.conv),
callee_conv = format!("{}", callee_fn_abi.conv),
caller_conv = format!("{}", caller_fn_abi.conv),
)
}

Expand Down
20 changes: 13 additions & 7 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,17 +1754,19 @@ pub(super) fn check_coroutine_obligations(
debug!(?typeck_results.coroutine_stalled_predicates);

let mode = if tcx.next_trait_solver_globally() {
TypingMode::post_borrowck_analysis(tcx, def_id)
// This query is conceptually between HIR typeck and
// MIR borrowck. We use the opaque types defined by HIR
// and ignore region constraints.
TypingMode::borrowck(tcx, def_id)
} else {
TypingMode::analysis_in_body(tcx, def_id)
};

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

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

Ok(())
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,18 @@ fn add_query_desc_cached_impl(
) {
let Query { name, key, modifiers, .. } = &query;

// This dead code exists to instruct rust-analyzer about the link between the `rustc_queries`
// query names and the corresponding produced provider. The issue is that by nature of this
// macro producing a higher order macro that has all its token in the macro declaration we lose
// any meaningful spans, resulting in rust-analyzer being unable to make the connection between
// the query name and the corresponding providers field. The trick to fix this is to have
// `rustc_queries` emit a field access with the given name's span which allows it to succesfully
// show references / go to definition to the correspondig provider assignment which is usually
// the more interesting place.
let ra_hint = quote! {
let crate::query::Providers { #name: _, .. };
};

// Find out if we should cache the query on disk
let cache = if let Some((args, expr)) = modifiers.cache.as_ref() {
let tcx = args.as_ref().map(|t| quote! { #t }).unwrap_or_else(|| quote! { _ });
Expand All @@ -277,6 +289,7 @@ fn add_query_desc_cached_impl(
#[allow(unused_variables, unused_braces, rustc::pass_by_value)]
#[inline]
pub fn #name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::query::queries::#name::Key<'tcx>) -> bool {
#ra_hint
#expr
}
}
Expand All @@ -286,6 +299,7 @@ fn add_query_desc_cached_impl(
#[allow(rustc::pass_by_value)]
#[inline]
pub fn #name<'tcx>(_: TyCtxt<'tcx>, _: &crate::query::queries::#name::Key<'tcx>) -> bool {
#ra_hint
false
}
}
Expand Down
32 changes: 32 additions & 0 deletions compiler/rustc_target/src/callconv/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::Display;
use std::str::FromStr;
use std::{fmt, iter};

Expand Down Expand Up @@ -895,6 +896,37 @@ impl FromStr for Conv {
}
}

fn conv_to_externabi(conv: &Conv) -> ExternAbi {
match conv {
Conv::C => ExternAbi::C { unwind: false },
Conv::Rust => ExternAbi::Rust,
Conv::PreserveMost => ExternAbi::RustCold,
Conv::ArmAapcs => ExternAbi::Aapcs { unwind: false },
Conv::CCmseNonSecureCall => ExternAbi::CCmseNonSecureCall,
Conv::CCmseNonSecureEntry => ExternAbi::CCmseNonSecureEntry,
Conv::Msp430Intr => ExternAbi::Msp430Interrupt,
Conv::GpuKernel => ExternAbi::GpuKernel,
Conv::X86Fastcall => ExternAbi::Fastcall { unwind: false },
Conv::X86Intr => ExternAbi::X86Interrupt,
Conv::X86Stdcall => ExternAbi::Stdcall { unwind: false },
Conv::X86ThisCall => ExternAbi::Thiscall { unwind: false },
Conv::X86VectorCall => ExternAbi::Vectorcall { unwind: false },
Conv::X86_64SysV => ExternAbi::SysV64 { unwind: false },
Conv::X86_64Win64 => ExternAbi::Win64 { unwind: false },
Conv::AvrInterrupt => ExternAbi::AvrInterrupt,
Conv::AvrNonBlockingInterrupt => ExternAbi::AvrNonBlockingInterrupt,
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Machine } => ExternAbi::RiscvInterruptM,
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Supervisor } => ExternAbi::RiscvInterruptS,
Conv::Cold | Conv::PreserveAll => unreachable!(),
}
}

impl Display for Conv {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", conv_to_externabi(self))
}
}

// Some types are used a lot. Make sure they don't unintentionally get bigger.
#[cfg(target_pointer_width = "64")]
mod size_asserts {
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,15 @@ pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec<ty::Clause
let obligation = Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate);
ocx.register_obligation(obligation);
}
let errors = ocx.select_all_or_error();

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

Expand Down
1 change: 0 additions & 1 deletion library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ name = "panic_abort"
version = "0.0.0"
dependencies = [
"alloc",
"cfg-if",
"compiler_builtins",
"core",
"libc",
Expand Down
21 changes: 21 additions & 0 deletions library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::*;
use crate::panic::const_panic;
use crate::slice;
use crate::str::from_utf8_unchecked_mut;
use crate::ub_checks::assert_unsafe_precondition;
use crate::unicode::printable::is_printable;
use crate::unicode::{self, conversions};

Expand Down Expand Up @@ -1202,6 +1203,26 @@ impl char {
}
}

/// Converts this char into an [ASCII character](`ascii::Char`), without
/// checking whether it is valid.
///
/// # Safety
///
/// This char must be within the ASCII range, or else this is UB.
#[must_use]
#[unstable(feature = "ascii_char", issue = "110998")]
#[inline]
pub const unsafe fn as_ascii_unchecked(&self) -> ascii::Char {
assert_unsafe_precondition!(
check_library_ub,
"as_ascii_unchecked requires that the char is valid ASCII",
(it: &char = self) => it.is_ascii()
);

// SAFETY: the caller promised that this char is ASCII.
unsafe { ascii::Char::from_u8_unchecked(*self as u8) }
}

/// Makes a copy of the value in its ASCII upper case equivalent.
///
/// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z',
Expand Down
20 changes: 20 additions & 0 deletions library/core/src/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,26 @@ impl u8 {
ascii::Char::from_u8(*self)
}

/// Converts this byte to an [ASCII character](ascii::Char), without
/// checking whether or not it's valid.
///
/// # Safety
///
/// This byte must be valid ASCII, or else this is UB.
#[must_use]
#[unstable(feature = "ascii_char", issue = "110998")]
#[inline]
pub const unsafe fn as_ascii_unchecked(&self) -> ascii::Char {
assert_unsafe_precondition!(
check_library_ub,
"as_ascii_unchecked requires that the byte is valid ASCII",
(it: &u8 = self) => it.is_ascii()
);

// SAFETY: the caller promised that this byte is ASCII.
unsafe { ascii::Char::from_u8_unchecked(*self) }
}

/// Makes a copy of the value in its ASCII upper case equivalent.
///
/// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z',
Expand Down
22 changes: 22 additions & 0 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use self::pattern::{DoubleEndedSearcher, Pattern, ReverseSearcher, Searcher};
use crate::char::{self, EscapeDebugExtArgs};
use crate::ops::Range;
use crate::slice::{self, SliceIndex};
use crate::ub_checks::assert_unsafe_precondition;
use crate::{ascii, mem};

pub mod pattern;
Expand Down Expand Up @@ -2634,6 +2635,27 @@ impl str {
self.as_bytes().as_ascii()
}

/// Converts this string slice into a slice of [ASCII characters](ascii::Char),
/// without checking whether they are valid.
///
/// # Safety
///
/// Every character in this string must be ASCII, or else this is UB.
#[unstable(feature = "ascii_char", issue = "110998")]
#[must_use]
#[inline]
pub const unsafe fn as_ascii_unchecked(&self) -> &[ascii::Char] {
assert_unsafe_precondition!(
check_library_ub,
"as_ascii_unchecked requires that the string is valid ASCII",
(it: &str = self) => it.is_ascii()
);

// SAFETY: the caller promised that every byte of this string slice
// is ASCII.
unsafe { self.as_bytes().as_ascii_unchecked() }
}

/// Checks that two strings are an ASCII case-insensitive match.
///
/// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`,
Expand Down
7 changes: 4 additions & 3 deletions library/panic_abort/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ bench = false
doc = false

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

[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
[target.'cfg(target_os = "android")'.dependencies]
libc = { version = "0.2", default-features = false }

[target.'cfg(any(target_os = "android", target_os = "zkvm"))'.dependencies]
alloc = { path = "../alloc" }
76 changes: 5 additions & 71 deletions library/panic_abort/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
#![unstable(feature = "panic_abort", issue = "32837")]
#![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
#![panic_runtime]
#![allow(unused_features)]
#![feature(asm_experimental_arch)]
#![feature(core_intrinsics)]
#![feature(panic_runtime)]
#![feature(std_internals)]
#![feature(staged_api)]
#![feature(rustc_attrs)]
#![allow(internal_features)]
#![deny(unsafe_op_in_unsafe_fn)]

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

unsafe {
abort();
unsafe extern "Rust" {
// This is defined in std::rt.
#[rustc_std_internal_symbol]
safe fn __rust_abort() -> !;
}

cfg_if::cfg_if! {
if #[cfg(any(unix, target_os = "solid_asp3"))] {
unsafe fn abort() -> ! {
unsafe { libc::abort(); }
}
} else if #[cfg(any(target_os = "hermit",
all(target_vendor = "fortanix", target_env = "sgx"),
target_os = "xous",
target_os = "uefi",
))] {
unsafe fn abort() -> ! {
// call std::sys::abort_internal
unsafe extern "C" {
pub fn __rust_abort() -> !;
}
unsafe { __rust_abort(); }
}
} else if #[cfg(all(windows, not(miri)))] {
// On Windows, use the processor-specific __fastfail mechanism. In Windows 8
// and later, this will terminate the process immediately without running any
// in-process exception handlers. In earlier versions of Windows, this
// sequence of instructions will be treated as an access violation,
// terminating the process but without necessarily bypassing all exception
// handlers.
//
// https://docs.microsoft.com/en-us/cpp/intrinsics/fastfail
//
// Note: this is the same implementation as in std's `abort_internal`
unsafe fn abort() -> ! {
#[allow(unused)]
const FAST_FAIL_FATAL_APP_EXIT: usize = 7;
cfg_if::cfg_if! {
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
unsafe {
core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
}
} else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] {
unsafe {
core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
}
} else if #[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))] {
unsafe {
core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
}
} else {
core::intrinsics::abort();
}
}
}
} else if #[cfg(target_os = "teeos")] {
mod teeos {
unsafe extern "C" {
pub fn TEE_Panic(code: u32) -> !;
}
}

unsafe fn abort() -> ! {
unsafe { teeos::TEE_Panic(1); }
}
} else {
unsafe fn abort() -> ! {
core::intrinsics::abort();
}
}
}
__rust_abort()
}

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