mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-31 09:04:18 +00:00
Prefer "allow list" structure to check a type
This commit is contained in:
parent
462c74007e
commit
9323a2824b
@ -43,8 +43,8 @@ use rustc_hir::definitions::Definitions;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_hir::{
|
||||
Constness, HirId, ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet, Node, TraitCandidate,
|
||||
TraitItemKind,
|
||||
Constness, ExprKind, HirId, ImplItemKind, ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet,
|
||||
Node, TraitCandidate, TraitItemKind,
|
||||
};
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_macros::HashStable;
|
||||
@ -1499,24 +1499,14 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}
|
||||
|
||||
pub fn return_type_impl_trait(self, scope_def_id: LocalDefId) -> Option<(Ty<'tcx>, Span)> {
|
||||
// HACK: `type_of()` will fail on these (#55796), so return `None`.
|
||||
// `type_of()` will fail on these (#55796, #86483), so only allow `fn`s or closures.
|
||||
let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id);
|
||||
match self.hir().get(hir_id) {
|
||||
Node::Item(item) => {
|
||||
match item.kind {
|
||||
ItemKind::Fn(..) => { /* `type_of()` will work */ }
|
||||
_ => {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
Node::TraitItem(item) => {
|
||||
// #86483: Return early if it doesn't have a concrete type.
|
||||
if let TraitItemKind::Type(_, None) = item.kind {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
_ => { /* `type_of()` will work or panic */ }
|
||||
Node::Item(&hir::Item { kind: ItemKind::Fn(..), .. }) => {}
|
||||
Node::TraitItem(&hir::TraitItem { kind: TraitItemKind::Fn(..), .. }) => {}
|
||||
Node::ImplItem(&hir::ImplItem { kind: ImplItemKind::Fn(..), .. }) => {}
|
||||
Node::Expr(&hir::Expr { kind: ExprKind::Closure(..), .. }) => {}
|
||||
_ => return None,
|
||||
}
|
||||
|
||||
let ret_ty = self.type_of(scope_def_id);
|
||||
|
Loading…
Reference in New Issue
Block a user