Move call trait lang item malformed check to typeck
This commit is contained in:
parent
c5283576ec
commit
3dd638fe6c
12 changed files with 170 additions and 71 deletions
|
@ -16,7 +16,7 @@ use rustc_middle::mir::ConstraintCategory;
|
|||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::trait_def::TraitSpecializationKind;
|
||||
use rustc_middle::ty::{
|
||||
self, ir::TypeVisitor, AdtKind, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable,
|
||||
self, ir::TypeVisitor, AdtKind, GenericParamDefKind, Ty, TyCtxt, TypeFoldable,
|
||||
TypeSuperVisitable,
|
||||
};
|
||||
use rustc_middle::ty::{GenericArgKind, InternalSubsts};
|
||||
|
@ -277,56 +277,6 @@ fn check_trait_item(tcx: TyCtxt<'_>, trait_item: &hir::TraitItem<'_>) {
|
|||
};
|
||||
check_object_unsafe_self_trait_by_name(tcx, trait_item);
|
||||
check_associated_item(tcx, def_id, span, method_sig);
|
||||
|
||||
let encl_trait_def_id = tcx.local_parent(def_id);
|
||||
let encl_trait = tcx.hir().expect_item(encl_trait_def_id);
|
||||
let encl_trait_def_id = encl_trait.owner_id.to_def_id();
|
||||
let fn_lang_item_name = if Some(encl_trait_def_id) == tcx.lang_items().fn_trait() {
|
||||
Some("fn")
|
||||
} else if Some(encl_trait_def_id) == tcx.lang_items().fn_mut_trait() {
|
||||
Some("fn_mut")
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let (Some(fn_lang_item_name), "call") =
|
||||
(fn_lang_item_name, trait_item.ident.name.to_ident_string().as_str())
|
||||
{
|
||||
// We are looking at the `call` function of the `fn` or `fn_mut` lang item.
|
||||
// Do some rudimentary sanity checking to avoid an ICE later (issue #83471).
|
||||
if let Some(hir::FnSig { decl, span, .. }) = method_sig {
|
||||
if let [self_ty, _] = decl.inputs {
|
||||
if !matches!(self_ty.kind, hir::TyKind::Ref(_, _)) {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
self_ty.span,
|
||||
&format!(
|
||||
"first argument of `call` in `{fn_lang_item_name}` lang item must be a reference",
|
||||
),
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
} else {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
*span,
|
||||
&format!(
|
||||
"`call` function in `{fn_lang_item_name}` lang item takes exactly two arguments",
|
||||
),
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
} else {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
trait_item.span,
|
||||
&format!(
|
||||
"`call` trait item in `{fn_lang_item_name}` lang item must be a function",
|
||||
),
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Require that the user writes where clauses on GATs for the implicit
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue