Skip to content

Commit

Permalink
Auto merge of rust-lang#129076 - matthiaskrgr:rollup-rg8mi2x, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#128410 (Migrate `remap-path-prefix-dwarf` `run-make` test to rmake)
 - rust-lang#128759 (alloc: add ToString specialization for `&&str`)
 - rust-lang#128873 (Add windows-targets crate to std's sysroot)
 - rust-lang#129001 (chore(lib): Enhance documentation for core::fmt::Formatter's write_fm…)
 - rust-lang#129061 (Use `is_lang_item` more)
 - rust-lang#129062 (Remove a no-longer-true assert)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 14, 2024
2 parents e9c965d + e01d614 commit 9859bf2
Show file tree
Hide file tree
Showing 38 changed files with 543 additions and 261 deletions.
10 changes: 3 additions & 7 deletions compiler/rustc_hir_typeck/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,11 @@ pub(super) fn check_fn<'a, 'tcx>(
fcx.demand_suptype(span, ret_ty, actual_return_ty);

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

if let Some(lang_start_defid) = tcx.lang_items().start_fn()
&& lang_start_defid == fn_def_id.to_def_id()
{
if tcx.is_lang_item(fn_def_id.to_def_id(), LangItem::Start) {
check_lang_start_fn(tcx, fn_sig, fn_def_id);
}

Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_lint/src/for_loops_over_fallibles.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hir::{Expr, Pat};
use rustc_hir as hir;
use rustc_hir::{self as hir, LangItem};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::ObligationCause;
use rustc_middle::ty;
Expand Down Expand Up @@ -126,7 +126,10 @@ fn extract_iterator_next_call<'tcx>(
) -> Option<&'tcx Expr<'tcx>> {
// This won't work for `Iterator::next(iter)`, is this an issue?
if let hir::ExprKind::MethodCall(_, recv, _, _) = expr.kind
&& cx.typeck_results().type_dependent_def_id(expr.hir_id) == cx.tcx.lang_items().next_fn()
&& cx
.typeck_results()
.type_dependent_def_id(expr.hir_id)
.is_some_and(|def_id| cx.tcx.is_lang_item(def_id, LangItem::IteratorNext))
{
Some(recv)
} else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
let hir::TyKind::TraitObject(bounds, _lifetime, _syntax) = &ty.kind else { return };
for (bound, modifier) in &bounds[..] {
let def_id = bound.trait_ref.trait_def_id();
if cx.tcx.lang_items().drop_trait() == def_id
if def_id.is_some_and(|def_id| cx.tcx.is_lang_item(def_id, LangItem::Drop))
&& *modifier != hir::TraitBoundModifier::Maybe
{
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use std::ops::ControlFlow;

use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{into_diag_arg_using_display, Applicability, Diag, DiagArgValue, IntoDiagArg};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_hir::{PredicateOrigin, WherePredicate};
use rustc_hir::{self as hir, LangItem, PredicateOrigin, WherePredicate};
use rustc_span::{BytePos, Span};
use rustc_type_ir::TyKind::*;

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

{
let mut sized_constraints =
constraints.extract_if(|(_, def_id)| *def_id == tcx.lang_items().sized_trait());
let mut sized_constraints = constraints.extract_if(|(_, def_id)| {
def_id.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized))
});
if let Some((_, def_id)) = sized_constraints.next() {
applicability = Applicability::MaybeIncorrect;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ impl<'tcx> Instance<'tcx> {
return None;
};

if tcx.lang_items().get(coroutine_callable_item) == Some(trait_item_id) {
if tcx.is_lang_item(trait_item_id, coroutine_callable_item) {
let ty::Coroutine(_, id_args) = *tcx.type_of(coroutine_def_id).skip_binder().kind()
else {
bug!()
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
let term = if let Some(ty) = term.skip_binder().as_type()
&& let ty::Alias(ty::Projection, proj) = ty.kind()
&& let Some(assoc) = tcx.opt_associated_item(proj.def_id)
&& assoc.trait_container(tcx) == tcx.lang_items().coroutine_trait()
&& assoc
.trait_container(tcx)
.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Coroutine))
&& assoc.name == rustc_span::sym::Return
{
if let ty::Coroutine(_, args) = args.type_at(0).kind() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ impl<'tcx> Ty<'tcx> {

pub fn is_c_void(self, tcx: TyCtxt<'_>) -> bool {
match self.kind() {
ty::Adt(adt, _) => tcx.lang_items().get(LangItem::CVoid) == Some(adt.did()),
ty::Adt(adt, _) => tcx.is_lang_item(adt.did(), LangItem::CVoid),
_ => false,
}
}
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,12 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
&& adt.is_enum()
&& let Constructor::Variant(variant_index) = witness_1.ctor()
{
let variant = adt.variant(*variant_index);
let inhabited = variant.inhabited_predicate(self.tcx, *adt).instantiate(self.tcx, args);
assert!(inhabited.apply(self.tcx, cx.param_env, cx.module));
!inhabited.apply_ignore_module(self.tcx, cx.param_env)
let variant_inhabited = adt
.variant(*variant_index)
.inhabited_predicate(self.tcx, *adt)
.instantiate(self.tcx, args);
variant_inhabited.apply(self.tcx, cx.param_env, cx.module)
&& !variant_inhabited.apply_ignore_module(self.tcx, cx.param_env)
} else {
false
};
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_monomorphize/src/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,9 @@ fn characteristic_def_id_of_mono_item<'tcx>(

if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
if tcx.sess.opts.incremental.is_some()
&& tcx.trait_id_of_impl(impl_def_id) == tcx.lang_items().drop_trait()
&& tcx
.trait_id_of_impl(impl_def_id)
.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Drop))
{
// Put `Drop::drop` into the same cgu as `drop_in_place`
// since `drop_in_place` is the only thing that can
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
use rustc_middle::ty::print::{FmtPrinter, Printer};
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty};
use rustc_span::def_id::DefId;
Expand Down Expand Up @@ -313,11 +314,15 @@ impl<T> Trait<T> for X {
(ty::Dynamic(t, _, ty::DynKind::Dyn), _)
if let Some(def_id) = t.principal_def_id() =>
{
let mut impl_def_ids = vec![];
let mut has_matching_impl = false;
tcx.for_each_relevant_impl(def_id, values.found, |did| {
impl_def_ids.push(did)
if DeepRejectCtxt::new(tcx, TreatParams::ForLookup)
.types_may_unify(values.found, tcx.type_of(did).skip_binder())
{
has_matching_impl = true;
}
});
if let [_] = &impl_def_ids[..] {
if has_matching_impl {
let trait_name = tcx.item_name(def_id);
diag.help(format!(
"`{}` implements `{trait_name}` so you could box the found value \
Expand All @@ -330,11 +335,15 @@ impl<T> Trait<T> for X {
(_, ty::Dynamic(t, _, ty::DynKind::Dyn))
if let Some(def_id) = t.principal_def_id() =>
{
let mut impl_def_ids = vec![];
let mut has_matching_impl = false;
tcx.for_each_relevant_impl(def_id, values.expected, |did| {
impl_def_ids.push(did)
if DeepRejectCtxt::new(tcx, TreatParams::ForLookup)
.types_may_unify(values.expected, tcx.type_of(did).skip_binder())
{
has_matching_impl = true;
}
});
if let [_] = &impl_def_ids[..] {
if has_matching_impl {
let trait_name = tcx.item_name(def_id);
diag.help(format!(
"`{}` implements `{trait_name}` so you could change the expected \
Expand All @@ -346,11 +355,15 @@ impl<T> Trait<T> for X {
(ty::Dynamic(t, _, ty::DynKind::DynStar), _)
if let Some(def_id) = t.principal_def_id() =>
{
let mut impl_def_ids = vec![];
let mut has_matching_impl = false;
tcx.for_each_relevant_impl(def_id, values.found, |did| {
impl_def_ids.push(did)
if DeepRejectCtxt::new(tcx, TreatParams::ForLookup)
.types_may_unify(values.found, tcx.type_of(did).skip_binder())
{
has_matching_impl = true;
}
});
if let [_] = &impl_def_ids[..] {
if has_matching_impl {
let trait_name = tcx.item_name(def_id);
diag.help(format!(
"`{}` implements `{trait_name}`, `#[feature(dyn_star)]` is likely \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
post_message,
);

let (err_msg, safe_transmute_explanation) = if Some(main_trait_ref.def_id())
== self.tcx.lang_items().transmute_trait()
let (err_msg, safe_transmute_explanation) = if self.tcx.is_lang_item(main_trait_ref.def_id(), LangItem::TransmuteTrait)
{
// Recompute the safe transmute reason and use that for the error reporting
match self.get_safe_transmute_error_and_reason(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2831,7 +2831,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// Do not suggest relaxing if there is an explicit `Sized` obligation.
&& !bounds.iter()
.filter_map(|bound| bound.trait_ref())
.any(|tr| tr.trait_def_id() == tcx.lang_items().sized_trait())
.any(|tr| tr.trait_def_id().is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized)))
{
let (span, separator) = if let [.., last] = bounds {
(last.span().shrink_to_hi(), " +")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rustc_hir::LangItem;
use rustc_infer::traits::Obligation;
pub use rustc_middle::traits::query::type_op::ProvePredicate;
use rustc_middle::traits::query::NoSolution;
Expand All @@ -20,8 +21,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
// such cases.
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) =
key.value.predicate.kind().skip_binder()
&& let Some(sized_def_id) = tcx.lang_items().sized_trait()
&& trait_ref.def_id() == sized_def_id
&& tcx.is_lang_item(trait_ref.def_id(), LangItem::Sized)
&& trait_ref.self_ty().is_trivially_sized(tcx)
{
return Some(());
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ fn fn_abi_new_uncached<'tcx>(
let rust_abi = matches!(sig.abi, RustIntrinsic | Rust | RustCall);

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

let arg_of = |ty: Ty<'tcx>, arg_idx: Option<usize>| -> Result<_, &'tcx FnAbiError<'tcx>> {
let span = tracing::debug_span!("arg_of");
Expand Down
7 changes: 6 additions & 1 deletion library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ dependencies = [
"std_detect",
"unwind",
"wasi",
"windows-targets 0.0.0",
]

[[package]]
Expand Down Expand Up @@ -421,9 +422,13 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
"windows-targets 0.52.5",
]

[[package]]
name = "windows-targets"
version = "0.0.0"

[[package]]
name = "windows-targets"
version = "0.52.5"
Expand Down
1 change: 1 addition & 0 deletions library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
exclude = [
# stdarch has its own Cargo workspace
"stdarch",
"windows_targets"
]

[profile.release.package.compiler_builtins]
Expand Down
54 changes: 47 additions & 7 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2643,14 +2643,54 @@ impl ToString for i8 {
}
}

#[doc(hidden)]
// Generic/generated code can sometimes have multiple, nested references
// for strings, including `&&&str`s that would never be written
// by hand. This macro generates twelve layers of nested `&`-impl
// for primitive strings.
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
impl ToString for str {
#[inline]
fn to_string(&self) -> String {
String::from(self)
}
macro_rules! to_string_str_wrap_in_ref {
{x $($x:ident)*} => {
&to_string_str_wrap_in_ref! { $($x)* }
};
{} => { str };
}
#[cfg(not(no_global_oom_handling))]
macro_rules! to_string_expr_wrap_in_deref {
{$self:expr ; x $($x:ident)*} => {
*(to_string_expr_wrap_in_deref! { $self ; $($x)* })
};
{$self:expr ;} => { $self };
}
#[cfg(not(no_global_oom_handling))]
macro_rules! to_string_str {
{$($($x:ident)*),+} => {
$(
#[doc(hidden)]
#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
impl ToString for to_string_str_wrap_in_ref!($($x)*) {
#[inline]
fn to_string(&self) -> String {
String::from(to_string_expr_wrap_in_deref!(self ; $($x)*))
}
}
)+
};
}

#[cfg(not(no_global_oom_handling))]
to_string_str! {
x x x x x x x x x x x x,
x x x x x x x x x x x,
x x x x x x x x x x,
x x x x x x x x x,
x x x x x x x x,
x x x x x x x,
x x x x x x,
x x x x x,
x x x x,
x x x,
x x,
x,
}

#[doc(hidden)]
Expand Down
5 changes: 5 additions & 0 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,11 @@ impl<'a> Formatter<'a> {
self.buf.write_str(data)
}

/// Glue for usage of the [`write!`] macro with implementors of this trait.
///
/// This method should generally not be invoked manually, but rather through
/// the [`write!`] macro itself.
///
/// Writes some formatted information into this instance.
///
/// # Examples
Expand Down
5 changes: 4 additions & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ object = { version = "0.36.0", default-features = false, optional = true, featur
'archive',
] }

[target.'cfg(windows)'.dependencies.windows-targets]
path = "../windows_targets"

[dev-dependencies]
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
rand_xorshift = "0.3.0"
Expand Down Expand Up @@ -116,7 +119,7 @@ std_detect_env_override = ["std_detect/std_detect_env_override"]

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

[package.metadata.fortanix-sgx]
# Maximum possible number of threads when testing
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/windows/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::alloc::{GlobalAlloc, Layout, System};
use crate::ffi::c_void;
use crate::ptr;
use crate::sync::atomic::{AtomicPtr, Ordering};
use crate::sys::c::{self, windows_targets};
use crate::sys::c;
use crate::sys::common::alloc::{realloc_fallback, MIN_ALIGN};

#[cfg(test)]
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use core::ffi::{c_uint, c_ulong, c_ushort, c_void, CStr};
use core::{mem, ptr};

pub(super) mod windows_targets;

mod windows_sys;
pub use windows_sys::*;

Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/pal/windows/c/windows_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3317,4 +3317,3 @@ pub struct WSADATA {
#[cfg(target_arch = "arm")]
pub enum CONTEXT {}
// ignore-tidy-filelength
use super::windows_targets;
10 changes: 10 additions & 0 deletions library/windows_targets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "windows-targets"
description = "A drop-in replacement for the real windows-targets crate for use in std only."
version = "0.0.0"
edition = "2021"

[features]
# Enable using raw-dylib for Windows imports.
# This will eventually be the default.
windows_raw_dylib = []
Loading

0 comments on commit 9859bf2

Please sign in to comment.