Skip to content

Commit e7176db

Browse files
authored
Rollup merge of #111648 - Nilstrieb:language-items, r=WaffleLapkin
Remove `LangItems::require` It's just a short wrapper used by `tcx.require_lang_item`. Deleting it gives us a negative diff.
2 parents 5b58471 + c3efa51 commit e7176db

File tree

9 files changed

+20
-38
lines changed

9 files changed

+20
-38
lines changed

compiler/rustc_codegen_cranelift/src/base.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -966,11 +966,7 @@ fn codegen_panic_inner<'tcx>(
966966
args: &[Value],
967967
span: Span,
968968
) {
969-
let def_id = fx
970-
.tcx
971-
.lang_items()
972-
.require(lang_item)
973-
.unwrap_or_else(|e| fx.tcx.sess.span_fatal(span, e.to_string()));
969+
let def_id = fx.tcx.require_lang_item(lang_item, Some(span));
974970

975971
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
976972
let symbol_name = fx.tcx.symbol_name(instance).name;

compiler/rustc_hir/src/errors.rs

-10
This file was deleted.

compiler/rustc_hir/src/lang_items.rs

-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
//! * Functions called by the compiler itself.
99
1010
use crate::def_id::DefId;
11-
use crate::errors::LangItemError;
1211
use crate::{MethodKind, Target};
1312

1413
use rustc_ast as ast;
@@ -42,13 +41,6 @@ impl LanguageItems {
4241
self.items[item as usize] = Some(def_id);
4342
}
4443

45-
/// Requires that a given `LangItem` was bound and returns the corresponding `DefId`.
46-
/// If it wasn't bound, e.g. due to a missing `#[lang = "<it.name()>"]`,
47-
/// returns an error encapsulating the `LangItem`.
48-
pub fn require(&self, it: LangItem) -> Result<DefId, LangItemError> {
49-
self.get(it).ok_or_else(|| LangItemError(it))
50-
}
51-
5244
pub fn iter(&self) -> impl Iterator<Item = (LangItem, DefId)> + '_ {
5345
self.items
5446
.iter()

compiler/rustc_hir/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ pub mod def;
3030
pub mod def_path_hash_map;
3131
pub mod definitions;
3232
pub mod diagnostic_items;
33-
pub mod errors;
3433
pub use rustc_span::def_id;
3534
mod hir;
3635
pub mod hir_id;

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: LocalDefId) -> Coe
298298

299299
let coerce_unsized_trait = tcx.require_lang_item(LangItem::CoerceUnsized, Some(span));
300300

301-
let unsize_trait = tcx.lang_items().require(LangItem::Unsize).unwrap_or_else(|err| {
302-
tcx.sess.fatal(format!("`CoerceUnsized` implementation {}", err.to_string()));
303-
});
301+
let unsize_trait = tcx.require_lang_item(LangItem::Unsize, Some(span));
304302

305303
let source = tcx.type_of(impl_did).subst_identity();
306304
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().subst_identity();

compiler/rustc_middle/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ middle_strict_coherence_needs_negative_coherence =
3939
to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled
4040
.label = due to this attribute
4141
42+
middle_requires_lang_item = requires `{$name}` lang_item
43+
4244
middle_const_not_used_in_type_alias =
4345
const parameter `{$ct}` is part of concrete type but not used in parameter list for the `impl Trait` type alias

compiler/rustc_middle/src/error.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_macros::Diagnostic;
2-
use rustc_span::Span;
2+
use rustc_span::{Span, Symbol};
33

44
use crate::ty::Ty;
55

@@ -73,6 +73,14 @@ pub(crate) struct StrictCoherenceNeedsNegativeCoherence {
7373
pub attr_span: Option<Span>,
7474
}
7575

76+
#[derive(Diagnostic)]
77+
#[diag(middle_requires_lang_item)]
78+
pub(crate) struct RequiresLangItem {
79+
#[primary_span]
80+
pub span: Option<Span>,
81+
pub name: Symbol,
82+
}
83+
7684
#[derive(Diagnostic)]
7785
#[diag(middle_const_not_used_in_type_alias)]
7886
pub(super) struct ConstNotUsedTraitAlias {

compiler/rustc_middle/src/middle/lang_items.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@ impl<'tcx> TyCtxt<'tcx> {
1818
/// Returns the `DefId` for a given `LangItem`.
1919
/// If not found, fatally aborts compilation.
2020
pub fn require_lang_item(self, lang_item: LangItem, span: Option<Span>) -> DefId {
21-
self.lang_items().require(lang_item).unwrap_or_else(|err| {
22-
if let Some(span) = span {
23-
self.sess.span_fatal(span, err.to_string())
24-
} else {
25-
self.sess.fatal(err.to_string())
26-
}
21+
self.lang_items().get(lang_item).unwrap_or_else(|| {
22+
self.sess.emit_fatal(crate::error::RequiresLangItem { span, name: lang_item.name() });
2723
})
2824
}
2925

src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,11 @@ fn is_pat_variant(cx: &LateContext<'_>, pat: &Pat<'_>, path: &QPath<'_>, expecte
289289
let Some(id) = cx.typeck_results().qpath_res(path, pat.hir_id).opt_def_id() else { return false };
290290

291291
match expected_item {
292-
Item::Lang(expected_lang_item) => {
293-
let expected_id = cx.tcx.lang_items().require(expected_lang_item).unwrap();
294-
cx.tcx.parent(id) == expected_id
295-
},
292+
Item::Lang(expected_lang_item) => cx
293+
.tcx
294+
.lang_items()
295+
.get(expected_lang_item)
296+
.map_or(false, |expected_id| cx.tcx.parent(id) == expected_id),
296297
Item::Diag(expected_ty, expected_variant) => {
297298
let ty = cx.typeck_results().pat_ty(pat);
298299

0 commit comments

Comments
 (0)