diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-05-11 16:02:20 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-05-30 08:52:25 +0000 |
| commit | 4d390de4a3de9e73a51f1edfcecaf8519d94b3ee (patch) | |
| tree | a8346c48e62d287cbf50406924bbc923d509473b /compiler/rustc_ty_utils | |
| parent | 257f06587c7cb271517ca9a02c4ed3fd4581f71e (diff) | |
| download | rust-4d390de4a3de9e73a51f1edfcecaf8519d94b3ee.tar.gz rust-4d390de4a3de9e73a51f1edfcecaf8519d94b3ee.zip | |
Add a helper function for checking whether a default function in a trait can be treated as `const`
Diffstat (limited to 'compiler/rustc_ty_utils')
| -rw-r--r-- | compiler/rustc_ty_utils/src/ty.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index b52ee817509..a18ddd42183 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -5,7 +5,7 @@ use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{ self, Binder, EarlyBinder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt, }; -use rustc_span::{sym, Span}; +use rustc_span::Span; use rustc_trait_selection::traits; fn sized_constraint_for_ty<'tcx>( @@ -152,7 +152,9 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { let constness = match hir_id { Some(hir_id) => match tcx.hir().get(hir_id) { - hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. }) if matches!(tcx.trait_of_item(def_id), Some(trait_id) if tcx.has_attr(trait_id, sym::const_trait)) => { + hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. }) + if tcx.is_const_default_method(def_id) => + { hir::Constness::Const } |
