Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9859bf2

Browse files
committed
Auto merge of rust-lang#129076 - matthiaskrgr:rollup-rg8mi2x, r=matthiaskrgr
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
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

Lines changed: 3 additions & 7 deletions
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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 4 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 22 additions & 9 deletions
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 \

0 commit comments

Comments
 (0)