|
1 | 1 | //! Values computed by queries that use MIR.
|
2 | 2 |
|
3 |
| -use crate::ty::{self, Ty}; |
| 3 | +use crate::mir::{Body, Promoted}; |
| 4 | +use crate::ty::{self, Ty, TyCtxt}; |
4 | 5 | use rustc_data_structures::fx::FxHashMap;
|
5 | 6 | use rustc_data_structures::sync::Lrc;
|
6 | 7 | use rustc_hir as hir;
|
7 |
| -use rustc_hir::def_id::DefId; |
| 8 | +use rustc_hir::def_id::{DefId, LocalDefId}; |
8 | 9 | use rustc_index::bit_set::BitMatrix;
|
9 | 10 | use rustc_index::vec::IndexVec;
|
10 | 11 | use rustc_span::{Span, Symbol};
|
@@ -323,3 +324,38 @@ pub struct CoverageInfo {
|
323 | 324 | /// The total number of coverage region counters added to the MIR `Body`.
|
324 | 325 | pub num_counters: u32,
|
325 | 326 | }
|
| 327 | + |
| 328 | +impl<'tcx> TyCtxt<'tcx> { |
| 329 | + pub fn mir_borrowck_opt_const_arg( |
| 330 | + self, |
| 331 | + def: ty::WithOptConstParam<LocalDefId>, |
| 332 | + ) -> &'tcx BorrowCheckResult<'tcx> { |
| 333 | + if let Some(param_did) = def.const_param_did { |
| 334 | + self.mir_borrowck_const_arg((def.did, param_did)) |
| 335 | + } else { |
| 336 | + self.mir_borrowck(def.did) |
| 337 | + } |
| 338 | + } |
| 339 | + |
| 340 | + pub fn mir_const_qualif_opt_const_arg( |
| 341 | + self, |
| 342 | + def: ty::WithOptConstParam<LocalDefId>, |
| 343 | + ) -> ConstQualifs { |
| 344 | + if let Some(param_did) = def.const_param_did { |
| 345 | + self.mir_const_qualif_const_arg((def.did, param_did)) |
| 346 | + } else { |
| 347 | + self.mir_const_qualif(def.did) |
| 348 | + } |
| 349 | + } |
| 350 | + |
| 351 | + pub fn promoted_mir_of_opt_const_arg( |
| 352 | + self, |
| 353 | + def: ty::WithOptConstParam<DefId>, |
| 354 | + ) -> &'tcx IndexVec<Promoted, Body<'tcx>> { |
| 355 | + if let Some((did, param_did)) = def.as_const_arg() { |
| 356 | + self.promoted_mir_of_const_arg((did, param_did)) |
| 357 | + } else { |
| 358 | + self.promoted_mir(def.did) |
| 359 | + } |
| 360 | + } |
| 361 | +} |
0 commit comments