|
2 | 2 |
|
3 | 3 | use rustc_abi::ExternAbi; |
4 | 4 | use rustc_errors::DiagMessage; |
5 | | -use rustc_hir::{self as hir}; |
6 | | -use rustc_middle::bug; |
| 5 | +use rustc_hir::{self as hir, LangItem}; |
7 | 6 | use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; |
8 | 7 | use rustc_middle::ty::{self, Ty, TyCtxt}; |
9 | 8 | use rustc_span::def_id::LocalDefId; |
@@ -173,23 +172,22 @@ pub(crate) fn check_intrinsic_type( |
173 | 172 | ty::BoundVariableKind::Region(ty::BoundRegionKind::ClosureEnv), |
174 | 173 | ]); |
175 | 174 | let mk_va_list_ty = |mutbl| { |
176 | | - tcx.lang_items().va_list().map(|did| { |
177 | | - let region = ty::Region::new_bound( |
178 | | - tcx, |
179 | | - ty::INNERMOST, |
180 | | - ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BoundRegionKind::Anon }, |
181 | | - ); |
182 | | - let env_region = ty::Region::new_bound( |
183 | | - tcx, |
184 | | - ty::INNERMOST, |
185 | | - ty::BoundRegion { |
186 | | - var: ty::BoundVar::from_u32(2), |
187 | | - kind: ty::BoundRegionKind::ClosureEnv, |
188 | | - }, |
189 | | - ); |
190 | | - let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]); |
191 | | - (Ty::new_ref(tcx, env_region, va_list_ty, mutbl), va_list_ty) |
192 | | - }) |
| 175 | + let did = tcx.require_lang_item(LangItem::VaList, Some(span)); |
| 176 | + let region = ty::Region::new_bound( |
| 177 | + tcx, |
| 178 | + ty::INNERMOST, |
| 179 | + ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BoundRegionKind::Anon }, |
| 180 | + ); |
| 181 | + let env_region = ty::Region::new_bound( |
| 182 | + tcx, |
| 183 | + ty::INNERMOST, |
| 184 | + ty::BoundRegion { |
| 185 | + var: ty::BoundVar::from_u32(2), |
| 186 | + kind: ty::BoundRegionKind::ClosureEnv, |
| 187 | + }, |
| 188 | + ); |
| 189 | + let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]); |
| 190 | + (Ty::new_ref(tcx, env_region, va_list_ty, mutbl), va_list_ty) |
193 | 191 | }; |
194 | 192 |
|
195 | 193 | let (n_tps, n_lts, n_cts, inputs, output, safety) = if name_str.starts_with("atomic_") { |
@@ -548,23 +546,17 @@ pub(crate) fn check_intrinsic_type( |
548 | 546 | ) |
549 | 547 | } |
550 | 548 |
|
551 | | - sym::va_start | sym::va_end => match mk_va_list_ty(hir::Mutability::Mut) { |
552 | | - Some((va_list_ref_ty, _)) => (0, 0, vec![va_list_ref_ty], tcx.types.unit), |
553 | | - None => bug!("`va_list` lang item needed for C-variadic intrinsics"), |
554 | | - }, |
| 549 | + sym::va_start | sym::va_end => { |
| 550 | + (0, 0, vec![mk_va_list_ty(hir::Mutability::Mut).0], tcx.types.unit) |
| 551 | + } |
555 | 552 |
|
556 | | - sym::va_copy => match mk_va_list_ty(hir::Mutability::Not) { |
557 | | - Some((va_list_ref_ty, va_list_ty)) => { |
558 | | - let va_list_ptr_ty = Ty::new_mut_ptr(tcx, va_list_ty); |
559 | | - (0, 0, vec![va_list_ptr_ty, va_list_ref_ty], tcx.types.unit) |
560 | | - } |
561 | | - None => bug!("`va_list` lang item needed for C-variadic intrinsics"), |
562 | | - }, |
| 553 | + sym::va_copy => { |
| 554 | + let (va_list_ref_ty, va_list_ty) = mk_va_list_ty(hir::Mutability::Not); |
| 555 | + let va_list_ptr_ty = Ty::new_mut_ptr(tcx, va_list_ty); |
| 556 | + (0, 0, vec![va_list_ptr_ty, va_list_ref_ty], tcx.types.unit) |
| 557 | + } |
563 | 558 |
|
564 | | - sym::va_arg => match mk_va_list_ty(hir::Mutability::Mut) { |
565 | | - Some((va_list_ref_ty, _)) => (1, 0, vec![va_list_ref_ty], param(0)), |
566 | | - None => bug!("`va_list` lang item needed for C-variadic intrinsics"), |
567 | | - }, |
| 559 | + sym::va_arg => (1, 0, vec![mk_va_list_ty(hir::Mutability::Mut).0], param(0)), |
568 | 560 |
|
569 | 561 | sym::nontemporal_store => { |
570 | 562 | (1, 0, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], tcx.types.unit) |
|
0 commit comments