Skip to content

Commit 9859bf2

Browse files
committed
Auto merge of #129076 - matthiaskrgr:rollup-rg8mi2x, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #128410 (Migrate `remap-path-prefix-dwarf` `run-make` test to rmake) - #128759 (alloc: add ToString specialization for `&&str`) - #128873 (Add windows-targets crate to std's sysroot) - #129001 (chore(lib): Enhance documentation for core::fmt::Formatter's write_fm…) - #129061 (Use `is_lang_item` more) - #129062 (Remove a no-longer-true assert) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e9c965d + e01d614 commit 9859bf2

File tree

38 files changed

+543
-261
lines changed

38 files changed

+543
-261
lines changed

compiler/rustc_hir_typeck/src/check.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,11 @@ pub(super) fn check_fn<'a, 'tcx>(
160160
fcx.demand_suptype(span, ret_ty, actual_return_ty);
161161

162162
// Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !`
163-
if let Some(panic_impl_did) = tcx.lang_items().panic_impl()
164-
&& panic_impl_did == fn_def_id.to_def_id()
165-
{
166-
check_panic_info_fn(tcx, panic_impl_did.expect_local(), fn_sig);
163+
if tcx.is_lang_item(fn_def_id.to_def_id(), LangItem::PanicImpl) {
164+
check_panic_info_fn(tcx, fn_def_id, fn_sig);
167165
}
168166

169-
if let Some(lang_start_defid) = tcx.lang_items().start_fn()
170-
&& lang_start_defid == fn_def_id.to_def_id()
171-
{
167+
if tcx.is_lang_item(fn_def_id.to_def_id(), LangItem::Start) {
172168
check_lang_start_fn(tcx, fn_sig, fn_def_id);
173169
}
174170

compiler/rustc_lint/src/for_loops_over_fallibles.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use hir::{Expr, Pat};
2-
use rustc_hir as hir;
2+
use rustc_hir::{self as hir, LangItem};
33
use rustc_infer::infer::TyCtxtInferExt;
44
use rustc_infer::traits::ObligationCause;
55
use rustc_middle::ty;
@@ -126,7 +126,10 @@ fn extract_iterator_next_call<'tcx>(
126126
) -> Option<&'tcx Expr<'tcx>> {
127127
// This won't work for `Iterator::next(iter)`, is this an issue?
128128
if let hir::ExprKind::MethodCall(_, recv, _, _) = expr.kind
129-
&& cx.typeck_results().type_dependent_def_id(expr.hir_id) == cx.tcx.lang_items().next_fn()
129+
&& cx
130+
.typeck_results()
131+
.type_dependent_def_id(expr.hir_id)
132+
.is_some_and(|def_id| cx.tcx.is_lang_item(def_id, LangItem::IteratorNext))
130133
{
131134
Some(recv)
132135
} else {

compiler/rustc_lint/src/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
114114
let hir::TyKind::TraitObject(bounds, _lifetime, _syntax) = &ty.kind else { return };
115115
for (bound, modifier) in &bounds[..] {
116116
let def_id = bound.trait_ref.trait_def_id();
117-
if cx.tcx.lang_items().drop_trait() == def_id
117+
if def_id.is_some_and(|def_id| cx.tcx.is_lang_item(def_id, LangItem::Drop))
118118
&& *modifier != hir::TraitBoundModifier::Maybe
119119
{
120120
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };

compiler/rustc_middle/src/ty/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ use std::ops::ControlFlow;
66

77
use rustc_data_structures::fx::FxHashMap;
88
use rustc_errors::{into_diag_arg_using_display, Applicability, Diag, DiagArgValue, IntoDiagArg};
9-
use rustc_hir as hir;
109
use rustc_hir::def::DefKind;
1110
use rustc_hir::def_id::DefId;
12-
use rustc_hir::{PredicateOrigin, WherePredicate};
11+
use rustc_hir::{self as hir, LangItem, PredicateOrigin, WherePredicate};
1312
use rustc_span::{BytePos, Span};
1413
use rustc_type_ir::TyKind::*;
1514

@@ -290,8 +289,9 @@ pub fn suggest_constraining_type_params<'a>(
290289
let Some(param) = param else { return false };
291290

292291
{
293-
let mut sized_constraints =
294-
constraints.extract_if(|(_, def_id)| *def_id == tcx.lang_items().sized_trait());
292+
let mut sized_constraints = constraints.extract_if(|(_, def_id)| {
293+
def_id.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized))
294+
});
295295
if let Some((_, def_id)) = sized_constraints.next() {
296296
applicability = Applicability::MaybeIncorrect;
297297

compiler/rustc_middle/src/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ impl<'tcx> Instance<'tcx> {
838838
return None;
839839
};
840840

841-
if tcx.lang_items().get(coroutine_callable_item) == Some(trait_item_id) {
841+
if tcx.is_lang_item(trait_item_id, coroutine_callable_item) {
842842
let ty::Coroutine(_, id_args) = *tcx.type_of(coroutine_def_id).skip_binder().kind()
843843
else {
844844
bug!()

compiler/rustc_middle/src/ty/print/pretty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
11451145
let term = if let Some(ty) = term.skip_binder().as_type()
11461146
&& let ty::Alias(ty::Projection, proj) = ty.kind()
11471147
&& let Some(assoc) = tcx.opt_associated_item(proj.def_id)
1148-
&& assoc.trait_container(tcx) == tcx.lang_items().coroutine_trait()
1148+
&& assoc
1149+
.trait_container(tcx)
1150+
.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Coroutine))
11491151
&& assoc.name == rustc_span::sym::Return
11501152
{
11511153
if let ty::Coroutine(_, args) = args.type_at(0).kind() {

compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ impl<'tcx> Ty<'tcx> {
19161916

19171917
pub fn is_c_void(self, tcx: TyCtxt<'_>) -> bool {
19181918
match self.kind() {
1919-
ty::Adt(adt, _) => tcx.lang_items().get(LangItem::CVoid) == Some(adt.did()),
1919+
ty::Adt(adt, _) => tcx.is_lang_item(adt.did(), LangItem::CVoid),
19201920
_ => false,
19211921
}
19221922
}

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,12 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
702702
&& adt.is_enum()
703703
&& let Constructor::Variant(variant_index) = witness_1.ctor()
704704
{
705-
let variant = adt.variant(*variant_index);
706-
let inhabited = variant.inhabited_predicate(self.tcx, *adt).instantiate(self.tcx, args);
707-
assert!(inhabited.apply(self.tcx, cx.param_env, cx.module));
708-
!inhabited.apply_ignore_module(self.tcx, cx.param_env)
705+
let variant_inhabited = adt
706+
.variant(*variant_index)
707+
.inhabited_predicate(self.tcx, *adt)
708+
.instantiate(self.tcx, args);
709+
variant_inhabited.apply(self.tcx, cx.param_env, cx.module)
710+
&& !variant_inhabited.apply_ignore_module(self.tcx, cx.param_env)
709711
} else {
710712
false
711713
};

compiler/rustc_monomorphize/src/partitioning.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,9 @@ fn characteristic_def_id_of_mono_item<'tcx>(
648648

649649
if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
650650
if tcx.sess.opts.incremental.is_some()
651-
&& tcx.trait_id_of_impl(impl_def_id) == tcx.lang_items().drop_trait()
651+
&& tcx
652+
.trait_id_of_impl(impl_def_id)
653+
.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Drop))
652654
{
653655
// Put `Drop::drop` into the same cgu as `drop_in_place`
654656
// since `drop_in_place` is the only thing that can

compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_hir as hir;
44
use rustc_hir::def::DefKind;
55
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
66
use rustc_middle::ty::error::{ExpectedFound, TypeError};
7+
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
78
use rustc_middle::ty::print::{FmtPrinter, Printer};
89
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty};
910
use rustc_span::def_id::DefId;
@@ -313,11 +314,15 @@ impl<T> Trait<T> for X {
313314
(ty::Dynamic(t, _, ty::DynKind::Dyn), _)
314315
if let Some(def_id) = t.principal_def_id() =>
315316
{
316-
let mut impl_def_ids = vec![];
317+
let mut has_matching_impl = false;
317318
tcx.for_each_relevant_impl(def_id, values.found, |did| {
318-
impl_def_ids.push(did)
319+
if DeepRejectCtxt::new(tcx, TreatParams::ForLookup)
320+
.types_may_unify(values.found, tcx.type_of(did).skip_binder())
321+
{
322+
has_matching_impl = true;
323+
}
319324
});
320-
if let [_] = &impl_def_ids[..] {
325+
if has_matching_impl {
321326
let trait_name = tcx.item_name(def_id);
322327
diag.help(format!(
323328
"`{}` implements `{trait_name}` so you could box the found value \
@@ -330,11 +335,15 @@ impl<T> Trait<T> for X {
330335
(_, ty::Dynamic(t, _, ty::DynKind::Dyn))
331336
if let Some(def_id) = t.principal_def_id() =>
332337
{
333-
let mut impl_def_ids = vec![];
338+
let mut has_matching_impl = false;
334339
tcx.for_each_relevant_impl(def_id, values.expected, |did| {
335-
impl_def_ids.push(did)
340+
if DeepRejectCtxt::new(tcx, TreatParams::ForLookup)
341+
.types_may_unify(values.expected, tcx.type_of(did).skip_binder())
342+
{
343+
has_matching_impl = true;
344+
}
336345
});
337-
if let [_] = &impl_def_ids[..] {
346+
if has_matching_impl {
338347
let trait_name = tcx.item_name(def_id);
339348
diag.help(format!(
340349
"`{}` implements `{trait_name}` so you could change the expected \
@@ -346,11 +355,15 @@ impl<T> Trait<T> for X {
346355
(ty::Dynamic(t, _, ty::DynKind::DynStar), _)
347356
if let Some(def_id) = t.principal_def_id() =>
348357
{
349-
let mut impl_def_ids = vec![];
358+
let mut has_matching_impl = false;
350359
tcx.for_each_relevant_impl(def_id, values.found, |did| {
351-
impl_def_ids.push(did)
360+
if DeepRejectCtxt::new(tcx, TreatParams::ForLookup)
361+
.types_may_unify(values.found, tcx.type_of(did).skip_binder())
362+
{
363+
has_matching_impl = true;
364+
}
352365
});
353-
if let [_] = &impl_def_ids[..] {
366+
if has_matching_impl {
354367
let trait_name = tcx.item_name(def_id);
355368
diag.help(format!(
356369
"`{}` implements `{trait_name}`, `#[feature(dyn_star)]` is likely \

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
230230
post_message,
231231
);
232232

233-
let (err_msg, safe_transmute_explanation) = if Some(main_trait_ref.def_id())
234-
== self.tcx.lang_items().transmute_trait()
233+
let (err_msg, safe_transmute_explanation) = if self.tcx.is_lang_item(main_trait_ref.def_id(), LangItem::TransmuteTrait)
235234
{
236235
// Recompute the safe transmute reason and use that for the error reporting
237236
match self.get_safe_transmute_error_and_reason(

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2831,7 +2831,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
28312831
// Do not suggest relaxing if there is an explicit `Sized` obligation.
28322832
&& !bounds.iter()
28332833
.filter_map(|bound| bound.trait_ref())
2834-
.any(|tr| tr.trait_def_id() == tcx.lang_items().sized_trait())
2834+
.any(|tr| tr.trait_def_id().is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized)))
28352835
{
28362836
let (span, separator) = if let [.., last] = bounds {
28372837
(last.span().shrink_to_hi(), " +")

compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_hir::LangItem;
12
use rustc_infer::traits::Obligation;
23
pub use rustc_middle::traits::query::type_op::ProvePredicate;
34
use rustc_middle::traits::query::NoSolution;
@@ -20,8 +21,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
2021
// such cases.
2122
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) =
2223
key.value.predicate.kind().skip_binder()
23-
&& let Some(sized_def_id) = tcx.lang_items().sized_trait()
24-
&& trait_ref.def_id() == sized_def_id
24+
&& tcx.is_lang_item(trait_ref.def_id(), LangItem::Sized)
2525
&& trait_ref.self_ty().is_trivially_sized(tcx)
2626
{
2727
return Some(());

compiler/rustc_ty_utils/src/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ fn fn_abi_new_uncached<'tcx>(
621621
let rust_abi = matches!(sig.abi, RustIntrinsic | Rust | RustCall);
622622

623623
let is_drop_in_place =
624-
fn_def_id.is_some() && fn_def_id == cx.tcx.lang_items().drop_in_place_fn();
624+
fn_def_id.is_some_and(|def_id| cx.tcx.is_lang_item(def_id, LangItem::DropInPlace));
625625

626626
let arg_of = |ty: Ty<'tcx>, arg_idx: Option<usize>| -> Result<_, &'tcx FnAbiError<'tcx>> {
627627
let span = tracing::debug_span!("arg_of");

library/Cargo.lock

+6-1
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ dependencies = [
339339
"std_detect",
340340
"unwind",
341341
"wasi",
342+
"windows-targets 0.0.0",
342343
]
343344

344345
[[package]]
@@ -421,9 +422,13 @@ version = "0.52.0"
421422
source = "registry+https://github.com/rust-lang/crates.io-index"
422423
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
423424
dependencies = [
424-
"windows-targets",
425+
"windows-targets 0.52.5",
425426
]
426427

428+
[[package]]
429+
name = "windows-targets"
430+
version = "0.0.0"
431+
427432
[[package]]
428433
name = "windows-targets"
429434
version = "0.52.5"

library/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
exclude = [
99
# stdarch has its own Cargo workspace
1010
"stdarch",
11+
"windows_targets"
1112
]
1213

1314
[profile.release.package.compiler_builtins]

library/alloc/src/string.rs

+47-7
Original file line numberDiff line numberDiff line change
@@ -2643,14 +2643,54 @@ impl ToString for i8 {
26432643
}
26442644
}
26452645

2646-
#[doc(hidden)]
2646+
// Generic/generated code can sometimes have multiple, nested references
2647+
// for strings, including `&&&str`s that would never be written
2648+
// by hand. This macro generates twelve layers of nested `&`-impl
2649+
// for primitive strings.
26472650
#[cfg(not(no_global_oom_handling))]
2648-
#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
2649-
impl ToString for str {
2650-
#[inline]
2651-
fn to_string(&self) -> String {
2652-
String::from(self)
2653-
}
2651+
macro_rules! to_string_str_wrap_in_ref {
2652+
{x $($x:ident)*} => {
2653+
&to_string_str_wrap_in_ref! { $($x)* }
2654+
};
2655+
{} => { str };
2656+
}
2657+
#[cfg(not(no_global_oom_handling))]
2658+
macro_rules! to_string_expr_wrap_in_deref {
2659+
{$self:expr ; x $($x:ident)*} => {
2660+
*(to_string_expr_wrap_in_deref! { $self ; $($x)* })
2661+
};
2662+
{$self:expr ;} => { $self };
2663+
}
2664+
#[cfg(not(no_global_oom_handling))]
2665+
macro_rules! to_string_str {
2666+
{$($($x:ident)*),+} => {
2667+
$(
2668+
#[doc(hidden)]
2669+
#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
2670+
impl ToString for to_string_str_wrap_in_ref!($($x)*) {
2671+
#[inline]
2672+
fn to_string(&self) -> String {
2673+
String::from(to_string_expr_wrap_in_deref!(self ; $($x)*))
2674+
}
2675+
}
2676+
)+
2677+
};
2678+
}
2679+
2680+
#[cfg(not(no_global_oom_handling))]
2681+
to_string_str! {
2682+
x x x x x x x x x x x x,
2683+
x x x x x x x x x x x,
2684+
x x x x x x x x x x,
2685+
x x x x x x x x x,
2686+
x x x x x x x x,
2687+
x x x x x x x,
2688+
x x x x x x,
2689+
x x x x x,
2690+
x x x x,
2691+
x x x,
2692+
x x,
2693+
x,
26542694
}
26552695

26562696
#[doc(hidden)]

library/core/src/fmt/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,11 @@ impl<'a> Formatter<'a> {
16261626
self.buf.write_str(data)
16271627
}
16281628

1629+
/// Glue for usage of the [`write!`] macro with implementors of this trait.
1630+
///
1631+
/// This method should generally not be invoked manually, but rather through
1632+
/// the [`write!`] macro itself.
1633+
///
16291634
/// Writes some formatted information into this instance.
16301635
///
16311636
/// # Examples

library/std/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ object = { version = "0.36.0", default-features = false, optional = true, featur
5757
'archive',
5858
] }
5959

60+
[target.'cfg(windows)'.dependencies.windows-targets]
61+
path = "../windows_targets"
62+
6063
[dev-dependencies]
6164
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
6265
rand_xorshift = "0.3.0"
@@ -116,7 +119,7 @@ std_detect_env_override = ["std_detect/std_detect_env_override"]
116119

117120
# Enable using raw-dylib for Windows imports.
118121
# This will eventually be the default.
119-
windows_raw_dylib = []
122+
windows_raw_dylib = ["windows-targets/windows_raw_dylib"]
120123

121124
[package.metadata.fortanix-sgx]
122125
# Maximum possible number of threads when testing

library/std/src/sys/pal/windows/alloc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::alloc::{GlobalAlloc, Layout, System};
44
use crate::ffi::c_void;
55
use crate::ptr;
66
use crate::sync::atomic::{AtomicPtr, Ordering};
7-
use crate::sys::c::{self, windows_targets};
7+
use crate::sys::c;
88
use crate::sys::common::alloc::{realloc_fallback, MIN_ALIGN};
99

1010
#[cfg(test)]

library/std/src/sys/pal/windows/c.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use core::ffi::{c_uint, c_ulong, c_ushort, c_void, CStr};
99
use core::{mem, ptr};
1010

11-
pub(super) mod windows_targets;
12-
1311
mod windows_sys;
1412
pub use windows_sys::*;
1513

library/std/src/sys/pal/windows/c/windows_sys.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3317,4 +3317,3 @@ pub struct WSADATA {
33173317
#[cfg(target_arch = "arm")]
33183318
pub enum CONTEXT {}
33193319
// ignore-tidy-filelength
3320-
use super::windows_targets;

library/windows_targets/Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "windows-targets"
3+
description = "A drop-in replacement for the real windows-targets crate for use in std only."
4+
version = "0.0.0"
5+
edition = "2021"
6+
7+
[features]
8+
# Enable using raw-dylib for Windows imports.
9+
# This will eventually be the default.
10+
windows_raw_dylib = []

0 commit comments

Comments
 (0)