Skip to content

Commit 2afca78

Browse files
committed
Auto merge of rust-lang#103797 - Dylan-DPC:rollup-ps589fi, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#103338 (Fix unreachable_pub suggestion for enum with fields) - rust-lang#103603 (Lang item cleanups) - rust-lang#103732 (Revert "Make the `c` feature for `compiler-builtins` opt-in instead of inferred") - rust-lang#103766 (Add tracking issue to `error_in_core`) - rust-lang#103789 (Update E0382.md) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4596f4f + 4a254d5 commit 2afca78

File tree

49 files changed

+300
-331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+300
-331
lines changed

compiler/rustc_codegen_ssa/src/base.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc_data_structures::sync::ParallelIterator;
2222
use rustc_hir as hir;
2323
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
2424
use rustc_hir::lang_items::LangItem;
25-
use rustc_hir::weak_lang_items::WEAK_ITEMS_SYMBOLS;
2625
use rustc_index::vec::Idx;
2726
use rustc_metadata::EncodedMetadata;
2827
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
@@ -887,14 +886,14 @@ impl CrateInfo {
887886
// by the compiler, but that's ok because all this stuff is unstable anyway.
888887
let target = &tcx.sess.target;
889888
if !are_upstream_rust_objects_already_included(tcx.sess) {
890-
let missing_weak_lang_items: FxHashSet<&Symbol> = info
889+
let missing_weak_lang_items: FxHashSet<Symbol> = info
891890
.used_crates
892891
.iter()
893-
.flat_map(|cnum| {
894-
tcx.missing_lang_items(*cnum)
895-
.iter()
896-
.filter(|l| lang_items::required(tcx, **l))
897-
.filter_map(|item| WEAK_ITEMS_SYMBOLS.get(item))
892+
.flat_map(|&cnum| tcx.missing_lang_items(cnum))
893+
.filter(|l| l.is_weak())
894+
.filter_map(|&l| {
895+
let name = l.link_name()?;
896+
lang_items::required(tcx, l).then_some(name)
898897
})
899898
.collect();
900899
let prefix = if target.is_like_windows && target.arch == "x86" { "_" } else { "" };

compiler/rustc_const_eval/src/util/call_kind.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! context.
44
55
use rustc_hir::def_id::DefId;
6-
use rustc_hir::lang_items::LangItemGroup;
6+
use rustc_hir::lang_items;
77
use rustc_middle::ty::subst::SubstsRef;
88
use rustc_middle::ty::{self, AssocItemContainer, DefIdTree, Instance, ParamEnv, Ty, TyCtxt};
99
use rustc_span::symbol::Ident;
@@ -74,22 +74,24 @@ pub fn call_kind<'tcx>(
7474
}
7575
});
7676

77-
let fn_call = parent
78-
.and_then(|p| tcx.lang_items().group(LangItemGroup::Fn).iter().find(|did| **did == p));
77+
let fn_call = parent.and_then(|p| {
78+
lang_items::FN_TRAITS.iter().filter_map(|&l| tcx.lang_items().get(l)).find(|&id| id == p)
79+
});
7980

80-
let operator = (!from_hir_call)
81-
.then(|| parent)
82-
.flatten()
83-
.and_then(|p| tcx.lang_items().group(LangItemGroup::Op).iter().find(|did| **did == p));
81+
let operator = if !from_hir_call && let Some(p) = parent {
82+
lang_items::OPERATORS.iter().filter_map(|&l| tcx.lang_items().get(l)).find(|&id| id == p)
83+
} else {
84+
None
85+
};
8486

8587
let is_deref = !from_hir_call && tcx.is_diagnostic_item(sym::deref_method, method_did);
8688

8789
// Check for a 'special' use of 'self' -
8890
// an FnOnce call, an operator (e.g. `<<`), or a
8991
// deref coercion.
90-
let kind = if let Some(&trait_id) = fn_call {
92+
let kind = if let Some(trait_id) = fn_call {
9193
Some(CallKind::FnCall { fn_trait_id: trait_id, self_ty: method_substs.type_at(0) })
92-
} else if let Some(&trait_id) = operator {
94+
} else if let Some(trait_id) = operator {
9395
Some(CallKind::Operator { self_arg, trait_id, self_ty: method_substs.type_at(0) })
9496
} else if is_deref {
9597
let deref_target = tcx.get_diagnostic_item(sym::deref_target).and_then(|deref_target| {

compiler/rustc_error_codes/src/error_codes/E0382.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ with `#[derive(Clone)]`.
6161

6262
Some types have no ownership semantics at all and are trivial to duplicate. An
6363
example is `i32` and the other number types. We don't have to call `.clone()` to
64-
clone them, because they are marked `Copy` in addition to `Clone`. Implicit
64+
clone them, because they are marked `Copy` in addition to `Clone`. Implicit
6565
cloning is more convenient in this case. We can mark our own types `Copy` if
6666
all their members also are marked `Copy`.
6767

compiler/rustc_error_messages/locales/en-US/monomorphize.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,3 @@ monomorphize_large_assignments =
2121
moving {$size} bytes
2222
.label = value moved from here
2323
.note = The current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
24-
25-
monomorphize_requires_lang_item =
26-
requires `{$lang_item}` lang_item

compiler/rustc_hir/src/lang_items.rs

+106-101
Large diffs are not rendered by default.

compiler/rustc_hir/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#![feature(associated_type_defaults)]
66
#![feature(closure_track_caller)]
77
#![feature(const_btree_len)]
8-
#![feature(once_cell)]
98
#![feature(min_specialization)]
109
#![feature(never_type)]
1110
#![feature(rustc_attrs)]
11+
#![feature(variant_count)]
1212
#![recursion_limit = "256"]
1313
#![deny(rustc::untranslatable_diagnostic)]
1414
#![deny(rustc::diagnostic_outside_of_impl)]
+19-41
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,31 @@
11
//! Validity checking for weak lang items
22
3-
use crate::def_id::DefId;
4-
use crate::{lang_items, LangItem, LanguageItems};
3+
use crate::LangItem;
54

6-
use rustc_ast as ast;
7-
use rustc_data_structures::fx::FxIndexMap;
85
use rustc_span::symbol::{sym, Symbol};
96

10-
use std::sync::LazyLock;
11-
127
macro_rules! weak_lang_items {
13-
($($name:ident, $item:ident, $sym:ident;)*) => (
14-
15-
pub static WEAK_ITEMS_REFS: LazyLock<FxIndexMap<Symbol, LangItem>> = LazyLock::new(|| {
16-
let mut map = FxIndexMap::default();
17-
$(map.insert(sym::$name, LangItem::$item);)*
18-
map
19-
});
20-
21-
pub static WEAK_ITEMS_SYMBOLS: LazyLock<FxIndexMap<LangItem, Symbol>> = LazyLock::new(|| {
22-
let mut map = FxIndexMap::default();
23-
$(map.insert(LangItem::$item, sym::$sym);)*
24-
map
25-
});
26-
27-
pub fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol>
28-
{
29-
lang_items::extract(attrs).and_then(|(name, _)| {
30-
$(if name == sym::$name {
31-
Some(sym::$sym)
32-
} else)* {
33-
None
8+
($($item:ident, $sym:ident;)*) => {
9+
pub static WEAK_LANG_ITEMS: &[LangItem] = &[$(LangItem::$item,)*];
10+
11+
impl LangItem {
12+
pub fn is_weak(self) -> bool {
13+
matches!(self, $(LangItem::$item)|*)
14+
}
15+
16+
pub fn link_name(self) -> Option<Symbol> {
17+
match self {
18+
$( LangItem::$item => Some(sym::$sym),)*
19+
_ => None,
20+
}
21+
}
3422
}
35-
})
36-
}
37-
38-
impl LanguageItems {
39-
pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
40-
let did = Some(item_def_id);
41-
42-
$(self.$name() == did)||*
4323
}
4424
}
4525

46-
) }
47-
4826
weak_lang_items! {
49-
panic_impl, PanicImpl, rust_begin_unwind;
50-
eh_personality, EhPersonality, rust_eh_personality;
51-
eh_catch_typeinfo, EhCatchTypeinfo, rust_eh_catch_typeinfo;
52-
oom, Oom, rust_oom;
27+
PanicImpl, rust_begin_unwind;
28+
EhPersonality, rust_eh_personality;
29+
EhCatchTypeinfo, rust_eh_catch_typeinfo;
30+
Oom, rust_oom;
5331
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc_hir as hir;
2323
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
2424
use rustc_hir::def_id::{DefId, LocalDefId};
2525
use rustc_hir::intravisit::{walk_generics, Visitor as _};
26-
use rustc_hir::lang_items::LangItem;
2726
use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
2827
use rustc_middle::middle::stability::AllowUnstable;
2928
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef};
@@ -884,9 +883,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
884883
}
885884
}
886885

887-
let sized_def_id = tcx.lang_items().require(LangItem::Sized);
886+
let sized_def_id = tcx.lang_items().sized_trait();
888887
match (&sized_def_id, unbound) {
889-
(Ok(sized_def_id), Some(tpb))
888+
(Some(sized_def_id), Some(tpb))
890889
if tpb.path.res == Res::Def(DefKind::Trait, *sized_def_id) =>
891890
{
892891
// There was in fact a `?Sized` bound, return without doing anything
@@ -906,7 +905,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
906905
// There was no `?Sized` bound; add implicitly sized if `Sized` is available.
907906
}
908907
}
909-
if sized_def_id.is_err() {
908+
if sized_def_id.is_none() {
910909
// No lang item for `Sized`, so we can't add it as a bound.
911910
return;
912911
}

compiler/rustc_hir_analysis/src/collect.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use rustc_hir as hir;
2727
use rustc_hir::def::CtorKind;
2828
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
2929
use rustc_hir::intravisit::{self, Visitor};
30-
use rustc_hir::weak_lang_items;
31-
use rustc_hir::{GenericParamKind, Node};
30+
use rustc_hir::weak_lang_items::WEAK_LANG_ITEMS;
31+
use rustc_hir::{lang_items, GenericParamKind, LangItem, Node};
3232
use rustc_middle::hir::nested_filter;
3333
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
3434
use rustc_middle::mir::mono::Linkage;
@@ -2104,12 +2104,15 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
21042104
// strippable by the linker.
21052105
//
21062106
// Additionally weak lang items have predetermined symbol names.
2107-
if tcx.is_weak_lang_item(did.to_def_id()) {
2107+
if WEAK_LANG_ITEMS.iter().any(|&l| tcx.lang_items().get(l) == Some(did.to_def_id())) {
21082108
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
21092109
}
2110-
if let Some(name) = weak_lang_items::link_name(attrs) {
2111-
codegen_fn_attrs.export_name = Some(name);
2112-
codegen_fn_attrs.link_name = Some(name);
2110+
if let Some((name, _)) = lang_items::extract(attrs)
2111+
&& let Some(lang_item) = LangItem::from_name(name)
2112+
&& let Some(link_name) = lang_item.link_name()
2113+
{
2114+
codegen_fn_attrs.export_name = Some(link_name);
2115+
codegen_fn_attrs.link_name = Some(link_name);
21132116
}
21142117
check_link_name_xor_ordinal(tcx, &codegen_fn_attrs, link_ordinal_span);
21152118

compiler/rustc_lint/src/builtin.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, Gate
4040
use rustc_hir as hir;
4141
use rustc_hir::def::{DefKind, Res};
4242
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
43-
use rustc_hir::{ForeignItemKind, GenericParamKind, HirId, PatKind, PredicateOrigin};
43+
use rustc_hir::{ForeignItemKind, GenericParamKind, HirId, Node, PatKind, PredicateOrigin};
4444
use rustc_index::vec::Idx;
4545
use rustc_middle::lint::in_external_macro;
4646
use rustc_middle::ty::layout::{LayoutError, LayoutOf};
@@ -1423,7 +1423,11 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
14231423
}
14241424

14251425
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
1426-
let def_id = cx.tcx.hir().local_def_id(field.hir_id);
1426+
let map = cx.tcx.hir();
1427+
let def_id = map.local_def_id(field.hir_id);
1428+
if matches!(map.get(map.get_parent_node(field.hir_id)), Node::Variant(_)) {
1429+
return;
1430+
}
14271431
self.perform_lint(cx, "field", def_id, field.vis_span, false);
14281432
}
14291433

compiler/rustc_metadata/src/rmeta/decoder.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
1515
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
1616
use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
1717
use rustc_hir::diagnostic_items::DiagnosticItems;
18-
use rustc_hir::lang_items;
1918
use rustc_index::vec::{Idx, IndexVec};
2019
use rustc_middle::metadata::ModChild;
2120
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
@@ -967,7 +966,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
967966
}
968967

969968
/// Iterates over the language items in the given crate.
970-
fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, usize)] {
969+
fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, LangItem)] {
971970
tcx.arena.alloc_from_iter(
972971
self.root
973972
.lang_items
@@ -1319,7 +1318,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13191318
)
13201319
}
13211320

1322-
fn get_missing_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [lang_items::LangItem] {
1321+
fn get_missing_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [LangItem] {
13231322
tcx.arena.alloc_from_iter(self.root.lang_items_missing.decode(self))
13241323
}
13251324

compiler/rustc_metadata/src/rmeta/encoder.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_hir::def_id::{
1717
};
1818
use rustc_hir::definitions::DefPathData;
1919
use rustc_hir::intravisit::{self, Visitor};
20-
use rustc_hir::lang_items;
20+
use rustc_hir::lang_items::LangItem;
2121
use rustc_middle::hir::nested_filter;
2222
use rustc_middle::middle::dependency_format::Linkage;
2323
use rustc_middle::middle::exported_symbols::{
@@ -1905,22 +1905,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19051905
self.lazy_array(diagnostic_items.iter().map(|(&name, def_id)| (name, def_id.index)))
19061906
}
19071907

1908-
fn encode_lang_items(&mut self) -> LazyArray<(DefIndex, usize)> {
1908+
fn encode_lang_items(&mut self) -> LazyArray<(DefIndex, LangItem)> {
19091909
empty_proc_macro!(self);
1910-
let tcx = self.tcx;
1911-
let lang_items = tcx.lang_items();
1912-
let lang_items = lang_items.items().iter();
1913-
self.lazy_array(lang_items.enumerate().filter_map(|(i, &opt_def_id)| {
1914-
if let Some(def_id) = opt_def_id {
1915-
if def_id.is_local() {
1916-
return Some((def_id.index, i));
1917-
}
1918-
}
1919-
None
1910+
let lang_items = self.tcx.lang_items().iter();
1911+
self.lazy_array(lang_items.filter_map(|(lang_item, def_id)| {
1912+
def_id.as_local().map(|id| (id.local_def_index, lang_item))
19201913
}))
19211914
}
19221915

1923-
fn encode_lang_items_missing(&mut self) -> LazyArray<lang_items::LangItem> {
1916+
fn encode_lang_items_missing(&mut self) -> LazyArray<LangItem> {
19241917
empty_proc_macro!(self);
19251918
let tcx = self.tcx;
19261919
self.lazy_array(&tcx.lang_items().missing)

compiler/rustc_metadata/src/rmeta/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir as hir;
1212
use rustc_hir::def::{CtorKind, DefKind};
1313
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, DefPathHash, StableCrateId};
1414
use rustc_hir::definitions::DefKey;
15-
use rustc_hir::lang_items;
15+
use rustc_hir::lang_items::LangItem;
1616
use rustc_index::bit_set::{BitSet, FiniteBitSet};
1717
use rustc_index::vec::IndexVec;
1818
use rustc_middle::metadata::ModChild;
@@ -230,8 +230,8 @@ pub(crate) struct CrateRoot {
230230
dylib_dependency_formats: LazyArray<Option<LinkagePreference>>,
231231
lib_features: LazyArray<(Symbol, Option<Symbol>)>,
232232
stability_implications: LazyArray<(Symbol, Symbol)>,
233-
lang_items: LazyArray<(DefIndex, usize)>,
234-
lang_items_missing: LazyArray<lang_items::LangItem>,
233+
lang_items: LazyArray<(DefIndex, LangItem)>,
234+
lang_items_missing: LazyArray<LangItem>,
235235
diagnostic_items: LazyArray<(Symbol, DefIndex)>,
236236
native_libraries: LazyArray<NativeLib>,
237237
foreign_modules: LazyArray<ForeignModule>,

compiler/rustc_middle/src/middle/lang_items.rs

-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ impl<'tcx> TyCtxt<'tcx> {
3636
_ => None,
3737
}
3838
}
39-
40-
pub fn is_weak_lang_item(self, item_def_id: DefId) -> bool {
41-
self.lang_items().is_weak_lang_item(item_def_id)
42-
}
4339
}
4440

4541
/// Returns `true` if the specified `lang_item` must be present for this

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ rustc_queries! {
17051705
}
17061706

17071707
/// Returns the lang items defined in another crate by loading it from metadata.
1708-
query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1708+
query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, LangItem)] {
17091709
desc { "calculating the lang items defined in a crate" }
17101710
separate_provide_extern
17111711
}

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,7 @@ impl<'tcx> TyCtxt<'tcx> {
24562456

24572457
#[inline]
24582458
pub fn mk_lang_item(self, ty: Ty<'tcx>, item: LangItem) -> Option<Ty<'tcx>> {
2459-
let def_id = self.lang_items().require(item).ok()?;
2459+
let def_id = self.lang_items().get(item)?;
24602460
Some(self.mk_generic_adt(def_id, ty))
24612461
}
24622462

compiler/rustc_monomorphize/src/collector.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ use std::iter;
201201
use std::ops::Range;
202202
use std::path::PathBuf;
203203

204-
use crate::errors::{LargeAssignmentsLint, RecursionLimit, RequiresLangItem, TypeLengthLimit};
204+
use crate::errors::{LargeAssignmentsLint, RecursionLimit, TypeLengthLimit};
205205

206206
#[derive(PartialEq)]
207207
pub enum MonoItemCollectionMode {
@@ -1298,14 +1298,7 @@ impl<'v> RootCollector<'_, 'v> {
12981298
return;
12991299
};
13001300

1301-
let start_def_id = match self.tcx.lang_items().require(LangItem::Start) {
1302-
Ok(s) => s,
1303-
Err(lang_item_err) => {
1304-
self.tcx
1305-
.sess
1306-
.emit_fatal(RequiresLangItem { lang_item: lang_item_err.0.name().to_string() });
1307-
}
1308-
};
1301+
let start_def_id = self.tcx.require_lang_item(LangItem::Start, None);
13091302
let main_ret_ty = self.tcx.fn_sig(main_def_id).output();
13101303

13111304
// Given that `main()` has no arguments,

0 commit comments

Comments
 (0)