diff options
| author | Yuki Okushi <yuki.okushi@huawei.com> | 2021-06-24 14:59:43 +0900 |
|---|---|---|
| committer | Yuki Okushi <yuki.okushi@huawei.com> | 2021-06-24 15:02:50 +0900 |
| commit | 9323a2824b188ddb741e702fd632a9061f5c4fc4 (patch) | |
| tree | 66beeff5f477f6265400e9120454bfae8e094925 /compiler | |
| parent | 462c74007eea1b71a62aa5565352e82ef481a129 (diff) | |
| download | rust-9323a2824b188ddb741e702fd632a9061f5c4fc4.tar.gz rust-9323a2824b188ddb741e702fd632a9061f5c4fc4.zip | |
Prefer "allow list" structure to check a type
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 1988bc17376..77f955e93b9 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -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); |
