Collect lang items from AST
This commit is contained in:
parent
4d1bd0db7f
commit
ad00641b74
@ -453,6 +453,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
|
||||
tcx.ensure_with_value().output_filenames(());
|
||||
tcx.ensure_with_value().early_lint_checks(());
|
||||
tcx.ensure_with_value().debugger_visualizers(LOCAL_CRATE);
|
||||
tcx.ensure_with_value().get_lang_items(());
|
||||
let (mut resolver, krate) = tcx.resolver_for_lowering(()).steal();
|
||||
|
||||
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);
|
||||
|
@ -7,18 +7,18 @@
|
||||
//! * Traits that represent operators; e.g., `Add`, `Sub`, `Index`.
|
||||
//! * Functions called by the compiler itself.
|
||||
|
||||
use crate::check_attr::target_from_impl_item;
|
||||
use crate::errors::{
|
||||
DuplicateLangItem, IncorrectTarget, LangItemOnIncorrectTarget, UnknownLangItem,
|
||||
};
|
||||
use crate::weak_lang_items;
|
||||
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::visit;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::lang_items::{extract, GenericRequirement};
|
||||
use rustc_hir::{LangItem, LanguageItems, Target};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_hir::{LangItem, LanguageItems, MethodKind, Target};
|
||||
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
|
||||
use rustc_session::cstore::ExternCrate;
|
||||
use rustc_span::symbol::kw::Empty;
|
||||
use rustc_span::Span;
|
||||
@ -31,28 +31,55 @@ pub(crate) enum Duplicate {
|
||||
CrateDepends,
|
||||
}
|
||||
|
||||
struct LanguageItemCollector<'tcx> {
|
||||
struct LanguageItemCollector<'ast, 'tcx> {
|
||||
items: LanguageItems,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
resolver: &'ast ResolverAstLowering,
|
||||
// FIXME(#118552): We should probably feed def_span eagerly on def-id creation
|
||||
// so we can avoid constructing this map for local def-ids.
|
||||
item_spans: FxHashMap<DefId, Span>,
|
||||
parent_item: Option<&'ast ast::Item>,
|
||||
}
|
||||
|
||||
impl<'tcx> LanguageItemCollector<'tcx> {
|
||||
fn new(tcx: TyCtxt<'tcx>) -> LanguageItemCollector<'tcx> {
|
||||
LanguageItemCollector { tcx, items: LanguageItems::new() }
|
||||
impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
|
||||
fn new(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
resolver: &'ast ResolverAstLowering,
|
||||
) -> LanguageItemCollector<'ast, 'tcx> {
|
||||
LanguageItemCollector {
|
||||
tcx,
|
||||
resolver,
|
||||
items: LanguageItems::new(),
|
||||
item_spans: FxHashMap::default(),
|
||||
parent_item: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn check_for_lang(&mut self, actual_target: Target, def_id: LocalDefId) {
|
||||
let attrs = self.tcx.hir().attrs(self.tcx.local_def_id_to_hir_id(def_id));
|
||||
if let Some((name, span)) = extract(attrs) {
|
||||
fn check_for_lang(
|
||||
&mut self,
|
||||
actual_target: Target,
|
||||
def_id: LocalDefId,
|
||||
attrs: &'ast [ast::Attribute],
|
||||
item_span: Span,
|
||||
generics: Option<&'ast ast::Generics>,
|
||||
) {
|
||||
if let Some((name, attr_span)) = extract(attrs) {
|
||||
match LangItem::from_name(name) {
|
||||
// Known lang item with attribute on correct target.
|
||||
Some(lang_item) if actual_target == lang_item.target() => {
|
||||
self.collect_item_extended(lang_item, def_id, span);
|
||||
self.collect_item_extended(
|
||||
lang_item,
|
||||
def_id,
|
||||
item_span,
|
||||
attr_span,
|
||||
generics,
|
||||
actual_target,
|
||||
);
|
||||
}
|
||||
// Known lang item with attribute on incorrect target.
|
||||
Some(lang_item) => {
|
||||
self.tcx.sess.emit_err(LangItemOnIncorrectTarget {
|
||||
span,
|
||||
span: attr_span,
|
||||
name,
|
||||
expected_target: lang_item.target(),
|
||||
actual_target,
|
||||
@ -60,127 +87,123 @@ impl<'tcx> LanguageItemCollector<'tcx> {
|
||||
}
|
||||
// Unknown lang item.
|
||||
_ => {
|
||||
self.tcx.sess.emit_err(UnknownLangItem { span, name });
|
||||
self.tcx.sess.emit_err(UnknownLangItem { span: attr_span, name });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_item(&mut self, lang_item: LangItem, item_def_id: DefId) {
|
||||
fn collect_item(&mut self, lang_item: LangItem, item_def_id: DefId, item_span: Option<Span>) {
|
||||
// Check for duplicates.
|
||||
if let Some(original_def_id) = self.items.get(lang_item) {
|
||||
if original_def_id != item_def_id {
|
||||
let local_span = self.tcx.hir().span_if_local(item_def_id);
|
||||
let lang_item_name = lang_item.name();
|
||||
let crate_name = self.tcx.crate_name(item_def_id.krate);
|
||||
let mut dependency_of = Empty;
|
||||
let is_local = item_def_id.is_local();
|
||||
let path = if is_local {
|
||||
String::new()
|
||||
} else {
|
||||
self.tcx
|
||||
.crate_extern_paths(item_def_id.krate)
|
||||
.iter()
|
||||
.map(|p| p.display().to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
};
|
||||
let first_defined_span = self.tcx.hir().span_if_local(original_def_id);
|
||||
let mut orig_crate_name = Empty;
|
||||
let mut orig_dependency_of = Empty;
|
||||
let orig_is_local = original_def_id.is_local();
|
||||
let orig_path = if orig_is_local {
|
||||
String::new()
|
||||
} else {
|
||||
self.tcx
|
||||
.crate_extern_paths(original_def_id.krate)
|
||||
.iter()
|
||||
.map(|p| p.display().to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
};
|
||||
if first_defined_span.is_none() {
|
||||
orig_crate_name = self.tcx.crate_name(original_def_id.krate);
|
||||
if let Some(ExternCrate { dependency_of: inner_dependency_of, .. }) =
|
||||
self.tcx.extern_crate(original_def_id)
|
||||
{
|
||||
orig_dependency_of = self.tcx.crate_name(*inner_dependency_of);
|
||||
}
|
||||
if let Some(original_def_id) = self.items.get(lang_item)
|
||||
&& original_def_id != item_def_id
|
||||
{
|
||||
let lang_item_name = lang_item.name();
|
||||
let crate_name = self.tcx.crate_name(item_def_id.krate);
|
||||
let mut dependency_of = Empty;
|
||||
let is_local = item_def_id.is_local();
|
||||
let path = if is_local {
|
||||
String::new()
|
||||
} else {
|
||||
self.tcx
|
||||
.crate_extern_paths(item_def_id.krate)
|
||||
.iter()
|
||||
.map(|p| p.display().to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
};
|
||||
|
||||
let first_defined_span = self.item_spans.get(&original_def_id).copied();
|
||||
let mut orig_crate_name = Empty;
|
||||
let mut orig_dependency_of = Empty;
|
||||
let orig_is_local = original_def_id.is_local();
|
||||
let orig_path = if orig_is_local {
|
||||
String::new()
|
||||
} else {
|
||||
self.tcx
|
||||
.crate_extern_paths(original_def_id.krate)
|
||||
.iter()
|
||||
.map(|p| p.display().to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
};
|
||||
|
||||
if first_defined_span.is_none() {
|
||||
orig_crate_name = self.tcx.crate_name(original_def_id.krate);
|
||||
if let Some(ExternCrate { dependency_of: inner_dependency_of, .. }) =
|
||||
self.tcx.extern_crate(original_def_id)
|
||||
{
|
||||
orig_dependency_of = self.tcx.crate_name(*inner_dependency_of);
|
||||
}
|
||||
}
|
||||
|
||||
let duplicate = if local_span.is_some() {
|
||||
Duplicate::Plain
|
||||
} else {
|
||||
match self.tcx.extern_crate(item_def_id) {
|
||||
Some(ExternCrate { dependency_of: inner_dependency_of, .. }) => {
|
||||
dependency_of = self.tcx.crate_name(*inner_dependency_of);
|
||||
Duplicate::CrateDepends
|
||||
}
|
||||
_ => Duplicate::Crate,
|
||||
let duplicate = if item_span.is_some() {
|
||||
Duplicate::Plain
|
||||
} else {
|
||||
match self.tcx.extern_crate(item_def_id) {
|
||||
Some(ExternCrate { dependency_of: inner_dependency_of, .. }) => {
|
||||
dependency_of = self.tcx.crate_name(*inner_dependency_of);
|
||||
Duplicate::CrateDepends
|
||||
}
|
||||
};
|
||||
_ => Duplicate::Crate,
|
||||
}
|
||||
};
|
||||
|
||||
self.tcx.sess.emit_err(DuplicateLangItem {
|
||||
local_span,
|
||||
lang_item_name,
|
||||
crate_name,
|
||||
dependency_of,
|
||||
is_local,
|
||||
path,
|
||||
first_defined_span,
|
||||
orig_crate_name,
|
||||
orig_dependency_of,
|
||||
orig_is_local,
|
||||
orig_path,
|
||||
duplicate,
|
||||
});
|
||||
self.tcx.sess.emit_err(DuplicateLangItem {
|
||||
local_span: item_span,
|
||||
lang_item_name,
|
||||
crate_name,
|
||||
dependency_of,
|
||||
is_local,
|
||||
path,
|
||||
first_defined_span,
|
||||
orig_crate_name,
|
||||
orig_dependency_of,
|
||||
orig_is_local,
|
||||
orig_path,
|
||||
duplicate,
|
||||
});
|
||||
} else {
|
||||
// Matched.
|
||||
self.items.set(lang_item, item_def_id);
|
||||
// Collect span for error later
|
||||
if let Some(item_span) = item_span {
|
||||
self.item_spans.insert(item_def_id, item_span);
|
||||
}
|
||||
}
|
||||
|
||||
// Matched.
|
||||
self.items.set(lang_item, item_def_id);
|
||||
}
|
||||
|
||||
// Like collect_item() above, but also checks whether the lang item is declared
|
||||
// with the right number of generic arguments.
|
||||
fn collect_item_extended(&mut self, lang_item: LangItem, item_def_id: LocalDefId, span: Span) {
|
||||
fn collect_item_extended(
|
||||
&mut self,
|
||||
lang_item: LangItem,
|
||||
item_def_id: LocalDefId,
|
||||
item_span: Span,
|
||||
attr_span: Span,
|
||||
generics: Option<&'ast ast::Generics>,
|
||||
target: Target,
|
||||
) {
|
||||
let name = lang_item.name();
|
||||
|
||||
// Now check whether the lang_item has the expected number of generic
|
||||
// arguments. Generally speaking, binary and indexing operations have
|
||||
// one (for the RHS/index), unary operations have none, the closure
|
||||
// traits have one for the argument list, coroutines have one for the
|
||||
// resume argument, and ordering/equality relations have one for the RHS
|
||||
// Some other types like Box and various functions like drop_in_place
|
||||
// have minimum requirements.
|
||||
if let Some(generics) = generics {
|
||||
// Now check whether the lang_item has the expected number of generic
|
||||
// arguments. Generally speaking, binary and indexing operations have
|
||||
// one (for the RHS/index), unary operations have none, the closure
|
||||
// traits have one for the argument list, coroutines have one for the
|
||||
// resume argument, and ordering/equality relations have one for the RHS
|
||||
// Some other types like Box and various functions like drop_in_place
|
||||
// have minimum requirements.
|
||||
|
||||
if let hir::Node::Item(hir::Item { kind, span: item_span, .. }) =
|
||||
self.tcx.hir_node_by_def_id(item_def_id)
|
||||
{
|
||||
let (actual_num, generics_span) = match kind.generics() {
|
||||
Some(generics) => (
|
||||
generics
|
||||
.params
|
||||
.iter()
|
||||
.filter(|p| {
|
||||
!matches!(
|
||||
p.kind,
|
||||
hir::GenericParamKind::Const { is_host_effect: true, .. }
|
||||
)
|
||||
})
|
||||
.count(),
|
||||
generics.span,
|
||||
),
|
||||
None => (0, *item_span),
|
||||
};
|
||||
let actual_num = generics.params.len();
|
||||
|
||||
let mut at_least = false;
|
||||
let required = match lang_item.required_generics() {
|
||||
GenericRequirement::Exact(num) if num != actual_num => Some(num),
|
||||
GenericRequirement::Minimum(num) if actual_num < num => {
|
||||
at_least = true;
|
||||
Some(num)}
|
||||
,
|
||||
Some(num)
|
||||
}
|
||||
// If the number matches, or there is no requirement, handle it normally
|
||||
_ => None,
|
||||
};
|
||||
@ -190,10 +213,10 @@ impl<'tcx> LanguageItemCollector<'tcx> {
|
||||
// item kind of the target is correct, the target is still wrong
|
||||
// because of the wrong number of generic arguments.
|
||||
self.tcx.sess.emit_err(IncorrectTarget {
|
||||
span,
|
||||
generics_span,
|
||||
span: attr_span,
|
||||
generics_span: generics.span,
|
||||
name: name.as_str(),
|
||||
kind: kind.descr(),
|
||||
kind: target.name(),
|
||||
num,
|
||||
actual_num,
|
||||
at_least,
|
||||
@ -204,58 +227,117 @@ impl<'tcx> LanguageItemCollector<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
self.collect_item(lang_item, item_def_id.to_def_id());
|
||||
self.collect_item(lang_item, item_def_id.to_def_id(), Some(item_span));
|
||||
}
|
||||
}
|
||||
|
||||
/// Traverses and collects all the lang items in all crates.
|
||||
fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
|
||||
let resolver = tcx.resolver_for_lowering(()).borrow();
|
||||
let (resolver, krate) = &*resolver;
|
||||
|
||||
// Initialize the collector.
|
||||
let mut collector = LanguageItemCollector::new(tcx);
|
||||
let mut collector = LanguageItemCollector::new(tcx, resolver);
|
||||
|
||||
// Collect lang items in other crates.
|
||||
for &cnum in tcx.crates(()).iter() {
|
||||
for &(def_id, lang_item) in tcx.defined_lang_items(cnum).iter() {
|
||||
collector.collect_item(lang_item, def_id);
|
||||
collector.collect_item(lang_item, def_id, None);
|
||||
}
|
||||
}
|
||||
|
||||
// Collect lang items in this crate.
|
||||
let crate_items = tcx.hir_crate_items(());
|
||||
|
||||
for id in crate_items.items() {
|
||||
collector
|
||||
.check_for_lang(Target::from_def_kind(tcx.def_kind(id.owner_id)), id.owner_id.def_id);
|
||||
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Enum) {
|
||||
let item = tcx.hir().item(id);
|
||||
if let hir::ItemKind::Enum(def, ..) = &item.kind {
|
||||
for variant in def.variants {
|
||||
collector.check_for_lang(Target::Variant, variant.def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: avoid calling trait_item() when possible
|
||||
for id in crate_items.trait_items() {
|
||||
let item = tcx.hir().trait_item(id);
|
||||
collector.check_for_lang(Target::from_trait_item(item), item.owner_id.def_id)
|
||||
}
|
||||
|
||||
// FIXME: avoid calling impl_item() when possible
|
||||
for id in crate_items.impl_items() {
|
||||
let item = tcx.hir().impl_item(id);
|
||||
collector.check_for_lang(target_from_impl_item(tcx, item), item.owner_id.def_id)
|
||||
}
|
||||
|
||||
// Extract out the found lang items.
|
||||
let LanguageItemCollector { mut items, .. } = collector;
|
||||
// Collect lang items local to this crate.
|
||||
visit::Visitor::visit_crate(&mut collector, krate);
|
||||
|
||||
// Find all required but not-yet-defined lang items.
|
||||
weak_lang_items::check_crate(tcx, &mut items);
|
||||
weak_lang_items::check_crate(tcx, &mut collector.items, krate);
|
||||
|
||||
items
|
||||
// Return all the lang items that were found.
|
||||
collector.items
|
||||
}
|
||||
|
||||
impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
|
||||
fn visit_item(&mut self, i: &'ast ast::Item) {
|
||||
let (target, generics) = match &i.kind {
|
||||
ast::ItemKind::ExternCrate(_) => (Target::ExternCrate, None),
|
||||
ast::ItemKind::Use(_) => (Target::Use, None),
|
||||
ast::ItemKind::Static(_) => (Target::Static, None),
|
||||
ast::ItemKind::Const(ct) => (Target::Const, Some(&ct.generics)),
|
||||
ast::ItemKind::Fn(fun) => (Target::Fn, Some(&fun.generics)),
|
||||
ast::ItemKind::Mod(_, _) => (Target::Mod, None),
|
||||
ast::ItemKind::ForeignMod(_) => (Target::ForeignFn, None),
|
||||
ast::ItemKind::GlobalAsm(_) => (Target::GlobalAsm, None),
|
||||
ast::ItemKind::TyAlias(alias) => (Target::TyAlias, Some(&alias.generics)),
|
||||
ast::ItemKind::Enum(_, generics) => (Target::Enum, Some(generics)),
|
||||
ast::ItemKind::Struct(_, generics) => (Target::Struct, Some(generics)),
|
||||
ast::ItemKind::Union(_, generics) => (Target::Union, Some(generics)),
|
||||
ast::ItemKind::Trait(tr) => (Target::Trait, Some(&tr.generics)),
|
||||
ast::ItemKind::TraitAlias(generics, _) => (Target::TraitAlias, Some(generics)),
|
||||
ast::ItemKind::Impl(_) => (Target::Impl, None),
|
||||
ast::ItemKind::MacroDef(_) => (Target::MacroDef, None),
|
||||
ast::ItemKind::MacCall(_) => unreachable!("macros should have been expanded"),
|
||||
};
|
||||
|
||||
self.check_for_lang(
|
||||
target,
|
||||
self.resolver.node_id_to_def_id[&i.id],
|
||||
&i.attrs,
|
||||
i.span,
|
||||
generics,
|
||||
);
|
||||
|
||||
let parent_item = self.parent_item.replace(i);
|
||||
visit::walk_item(self, i);
|
||||
self.parent_item = parent_item;
|
||||
}
|
||||
|
||||
fn visit_enum_def(&mut self, enum_definition: &'ast ast::EnumDef) {
|
||||
for variant in &enum_definition.variants {
|
||||
self.check_for_lang(
|
||||
Target::Variant,
|
||||
self.resolver.node_id_to_def_id[&variant.id],
|
||||
&variant.attrs,
|
||||
variant.span,
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
visit::walk_enum_def(self, enum_definition);
|
||||
}
|
||||
|
||||
fn visit_assoc_item(&mut self, i: &'ast ast::AssocItem, ctxt: visit::AssocCtxt) {
|
||||
let (target, generics) = match &i.kind {
|
||||
ast::AssocItemKind::Fn(fun) => (
|
||||
match &self.parent_item.unwrap().kind {
|
||||
ast::ItemKind::Impl(i) => {
|
||||
if i.of_trait.is_some() {
|
||||
Target::Method(MethodKind::Trait { body: fun.body.is_some() })
|
||||
} else {
|
||||
Target::Method(MethodKind::Inherent)
|
||||
}
|
||||
}
|
||||
ast::ItemKind::Trait(_) => {
|
||||
Target::Method(MethodKind::Trait { body: fun.body.is_some() })
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
&fun.generics,
|
||||
),
|
||||
ast::AssocItemKind::Const(ct) => (Target::AssocConst, &ct.generics),
|
||||
ast::AssocItemKind::Type(ty) => (Target::AssocTy, &ty.generics),
|
||||
ast::AssocItemKind::MacCall(_) => unreachable!("macros should have been expanded"),
|
||||
};
|
||||
|
||||
self.check_for_lang(
|
||||
target,
|
||||
self.resolver.node_id_to_def_id[&i.id],
|
||||
&i.attrs,
|
||||
i.span,
|
||||
Some(generics),
|
||||
);
|
||||
|
||||
visit::walk_assoc_item(self, i, ctxt);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
//! Validity checking for weak lang items
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::visit;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::lang_items::{self, LangItem};
|
||||
use rustc_hir::weak_lang_items::WEAK_LANG_ITEMS;
|
||||
@ -11,7 +13,7 @@ use crate::errors::{MissingLangItem, MissingPanicHandler, UnknownExternLangItem}
|
||||
|
||||
/// Checks the crate for usage of weak lang items, returning a vector of all the
|
||||
/// language items required by this crate, but not defined yet.
|
||||
pub fn check_crate(tcx: TyCtxt<'_>, items: &mut lang_items::LanguageItems) {
|
||||
pub fn check_crate(tcx: TyCtxt<'_>, items: &mut lang_items::LanguageItems, krate: &ast::Crate) {
|
||||
// These are never called by user code, they're generated by the compiler.
|
||||
// They will never implicitly be added to the `missing` array unless we do
|
||||
// so here.
|
||||
@ -22,24 +24,30 @@ pub fn check_crate(tcx: TyCtxt<'_>, items: &mut lang_items::LanguageItems) {
|
||||
items.missing.push(LangItem::EhCatchTypeinfo);
|
||||
}
|
||||
|
||||
let crate_items = tcx.hir_crate_items(());
|
||||
for id in crate_items.foreign_items() {
|
||||
let attrs = tcx.hir().attrs(id.hir_id());
|
||||
if let Some((lang_item, _)) = lang_items::extract(attrs) {
|
||||
visit::Visitor::visit_crate(&mut WeakLangItemVisitor { tcx, items }, krate);
|
||||
|
||||
verify(tcx, items);
|
||||
}
|
||||
|
||||
struct WeakLangItemVisitor<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
items: &'a mut lang_items::LanguageItems,
|
||||
}
|
||||
|
||||
impl<'ast> visit::Visitor<'ast> for WeakLangItemVisitor<'_, '_> {
|
||||
fn visit_foreign_item(&mut self, i: &'ast ast::ForeignItem) {
|
||||
if let Some((lang_item, _)) = lang_items::extract(&i.attrs) {
|
||||
if let Some(item) = LangItem::from_name(lang_item)
|
||||
&& item.is_weak()
|
||||
{
|
||||
if items.get(item).is_none() {
|
||||
items.missing.push(item);
|
||||
if self.items.get(item).is_none() {
|
||||
self.items.missing.push(item);
|
||||
}
|
||||
} else {
|
||||
let span = tcx.def_span(id.owner_id);
|
||||
tcx.sess.emit_err(UnknownExternLangItem { span, lang_item });
|
||||
self.tcx.sess.emit_err(UnknownExternLangItem { span: i.span, lang_item });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
verify(tcx, items);
|
||||
}
|
||||
|
||||
fn verify(tcx: TyCtxt<'_>, items: &lang_items::LanguageItems) {
|
||||
|
@ -1,8 +1,11 @@
|
||||
error[E0152]: found duplicate lang item `panic_impl`
|
||||
--> $DIR/duplicate_entry_error.rs:11:1
|
||||
|
|
||||
LL | fn panic_impl(info: &PanicInfo) -> ! {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | / fn panic_impl(info: &PanicInfo) -> ! {
|
||||
LL | |
|
||||
LL | | loop {}
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= note: the lang item is first defined in crate `std` (which `duplicate_entry_error` depends on)
|
||||
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
|
||||
|
@ -2,7 +2,7 @@ error[E0152]: found duplicate lang item `owned_box`
|
||||
--> $DIR/E0152.rs:5:1
|
||||
|
|
||||
LL | struct Foo<T>(T);
|
||||
| ^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the lang item is first defined in crate `alloc` (which `std` depends on)
|
||||
= note: first definition in `alloc` loaded from SYSROOT/liballoc-*.rlib
|
||||
|
@ -2,7 +2,7 @@ error[E0264]: unknown external lang item: `cake`
|
||||
--> $DIR/E0264.rs:5:5
|
||||
|
|
||||
LL | fn cake();
|
||||
| ^^^^^^^^^
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -22,6 +22,8 @@ trait MyIndex<'a, T> {}
|
||||
#[lang = "phantom_data"]
|
||||
//~^ ERROR `phantom_data` language item must be applied to a struct with 1 generic argument
|
||||
struct MyPhantomData<T, U>;
|
||||
//~^ ERROR parameter `T` is never used
|
||||
//~| ERROR parameter `U` is never used
|
||||
|
||||
#[lang = "owned_box"]
|
||||
//~^ ERROR `owned_box` language item must be applied to a struct with at least 1 generic argument
|
||||
@ -40,6 +42,7 @@ fn ice() {
|
||||
let r = 5;
|
||||
let a = 6;
|
||||
r + a;
|
||||
//~^ ERROR cannot add `{integer}` to `{integer}`
|
||||
|
||||
// Use drop in place
|
||||
my_ptr_drop();
|
||||
|
@ -33,7 +33,7 @@ LL | struct MyPhantomData<T, U>;
|
||||
| ------ this struct has 2 generic arguments
|
||||
|
||||
error[E0718]: `owned_box` language item must be applied to a struct with at least 1 generic argument
|
||||
--> $DIR/lang-item-generic-requirements.rs:26:1
|
||||
--> $DIR/lang-item-generic-requirements.rs:28:1
|
||||
|
|
||||
LL | #[lang = "owned_box"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -42,7 +42,7 @@ LL | struct Foo;
|
||||
| - this struct has 0 generic arguments
|
||||
|
||||
error[E0718]: `start` language item must be applied to a function with 1 generic argument
|
||||
--> $DIR/lang-item-generic-requirements.rs:32:1
|
||||
--> $DIR/lang-item-generic-requirements.rs:34:1
|
||||
|
|
||||
LL | #[lang = "start"]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
@ -50,6 +50,35 @@ LL |
|
||||
LL | fn start(_: *const u8, _: isize, _: *const *const u8) -> isize {
|
||||
| - this function has 0 generic arguments
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error[E0392]: parameter `T` is never used
|
||||
--> $DIR/lang-item-generic-requirements.rs:24:22
|
||||
|
|
||||
LL | struct MyPhantomData<T, U>;
|
||||
| ^ unused parameter
|
||||
|
|
||||
= help: consider removing `T` or referring to it in a field
|
||||
= help: if you intended `T` to be a const parameter, use `const T: usize` instead
|
||||
|
||||
For more information about this error, try `rustc --explain E0718`.
|
||||
error[E0392]: parameter `U` is never used
|
||||
--> $DIR/lang-item-generic-requirements.rs:24:25
|
||||
|
|
||||
LL | struct MyPhantomData<T, U>;
|
||||
| ^ unused parameter
|
||||
|
|
||||
= help: consider removing `U` or referring to it in a field
|
||||
= help: if you intended `U` to be a const parameter, use `const U: usize` instead
|
||||
|
||||
error[E0369]: cannot add `{integer}` to `{integer}`
|
||||
--> $DIR/lang-item-generic-requirements.rs:44:7
|
||||
|
|
||||
LL | r + a;
|
||||
| - ^ - {integer}
|
||||
| |
|
||||
| {integer}
|
||||
|
||||
error: requires `copy` lang_item
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0369, E0392, E0718.
|
||||
For more information about an error, try `rustc --explain E0369`.
|
||||
|
@ -1,14 +1,18 @@
|
||||
error[E0152]: found duplicate lang item `panic_impl`
|
||||
--> $DIR/panic-handler-duplicate.rs:15:1
|
||||
|
|
||||
LL | fn panic2(info: &PanicInfo) -> ! {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | / fn panic2(info: &PanicInfo) -> ! {
|
||||
LL | | loop {}
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
note: the lang item is first defined here
|
||||
--> $DIR/panic-handler-duplicate.rs:10:1
|
||||
|
|
||||
LL | fn panic(info: &PanicInfo) -> ! {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | / fn panic(info: &PanicInfo) -> ! {
|
||||
LL | | loop {}
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
error[E0152]: found duplicate lang item `panic_impl`
|
||||
--> $DIR/panic-handler-std.rs:8:1
|
||||
|
|
||||
LL | fn panic(info: PanicInfo) -> ! {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | / fn panic(info: PanicInfo) -> ! {
|
||||
LL | | loop {}
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= note: the lang item is first defined in crate `std` (which `panic_handler_std` depends on)
|
||||
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
|
||||
|
@ -7,6 +7,7 @@ trait Sized { } //~ ERROR found duplicate lang item `sized`
|
||||
fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
|
||||
//~^ ERROR `self` parameter is only allowed in associated functions
|
||||
//~| ERROR cannot find type `Struct` in this scope
|
||||
//~| ERROR mismatched types
|
||||
let x = x << 1;
|
||||
//~^ ERROR cannot find value `x` in this scope
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
|
||||
| ^^^^^^ not found in this scope
|
||||
|
||||
error[E0425]: cannot find value `x` in this scope
|
||||
--> $DIR/issue-102989.rs:10:13
|
||||
--> $DIR/issue-102989.rs:11:13
|
||||
|
|
||||
LL | let x = x << 1;
|
||||
| ^ help: a local variable with a similar name exists: `f`
|
||||
@ -22,13 +22,27 @@ error[E0152]: found duplicate lang item `sized`
|
||||
--> $DIR/issue-102989.rs:5:1
|
||||
|
|
||||
LL | trait Sized { }
|
||||
| ^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the lang item is first defined in crate `core` (which `std` depends on)
|
||||
= note: first definition in `core` loaded from SYSROOT/libcore-*.rlib
|
||||
= note: second definition in the local crate (`issue_102989`)
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-102989.rs:7:42
|
||||
|
|
||||
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
|
||||
| ---------- ^^^^ expected `&u32`, found `()`
|
||||
| |
|
||||
| implicitly returns `()` as its body has no tail or `return` expression
|
||||
|
|
||||
help: consider returning the local binding `f`
|
||||
|
|
||||
LL ~ let x = x << 1;
|
||||
LL + f
|
||||
|
|
||||
|
||||
Some errors have detailed explanations: E0152, E0412, E0425.
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0152, E0308, E0412, E0425.
|
||||
For more information about an error, try `rustc --explain E0152`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user