1
Fork 0

Rollup merge of #104724 - WaffleLapkin:to_def_idn't, r=compiler-errors

Fix `ClosureKind::to_def_id`

`Fn` and `FnOnce` were mixed up in https://github.com/rust-lang/rust/pull/99131.
This commit is contained in:
Yuki Okushi 2022-11-23 06:40:24 +09:00 committed by GitHub
commit dcbfb9776d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 14 deletions

View file

@ -5,6 +5,7 @@ use crate::{mir, ty};
use std::fmt::Write;
use hir::LangItem;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
@ -130,11 +131,14 @@ impl<'tcx> ClosureKind {
}
pub fn to_def_id(&self, tcx: TyCtxt<'_>) -> DefId {
match self {
ClosureKind::Fn => tcx.lang_items().fn_once_trait().unwrap(),
ClosureKind::FnMut => tcx.lang_items().fn_mut_trait().unwrap(),
ClosureKind::FnOnce => tcx.lang_items().fn_trait().unwrap(),
}
tcx.require_lang_item(
match self {
ClosureKind::Fn => LangItem::Fn,
ClosureKind::FnMut => LangItem::FnMut,
ClosureKind::FnOnce => LangItem::FnOnce,
},
None,
)
}
}