Skip to content

Commit 940b45f

Browse files
authored
Rollup merge of #136281 - nnethercote:rustc_hir_analysis, r=lcnr
`rustc_hir_analysis` cleanups Just some improvements I found while looking through this code. r? `@lcnr`
2 parents c19c4b9 + 483307f commit 940b45f

File tree

22 files changed

+224
-315
lines changed

22 files changed

+224
-315
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,12 @@ fn compare_method_predicate_entailment<'tcx>(
424424
Ok(())
425425
}
426426

427-
struct RemapLateParam<'a, 'tcx> {
427+
struct RemapLateParam<'tcx> {
428428
tcx: TyCtxt<'tcx>,
429-
mapping: &'a FxIndexMap<ty::LateParamRegionKind, ty::LateParamRegionKind>,
429+
mapping: FxIndexMap<ty::LateParamRegionKind, ty::LateParamRegionKind>,
430430
}
431431

432-
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateParam<'_, 'tcx> {
432+
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateParam<'tcx> {
433433
fn cx(&self) -> TyCtxt<'tcx> {
434434
self.tcx
435435
}

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
299299
})
300300
.collect();
301301

302-
let mut return_ty =
303-
trait_m_sig.output().fold_with(&mut super::RemapLateParam { tcx, mapping: &mapping });
302+
let mut return_ty = trait_m_sig.output().fold_with(&mut super::RemapLateParam { tcx, mapping });
304303

305304
if tcx.asyncness(impl_m_def_id).is_async() && tcx.asyncness(trait_m_def_id).is_async() {
306305
let ty::Alias(ty::Projection, future_ty) = return_ty.kind() else {

compiler/rustc_hir_analysis/src/check/dropck.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// FIXME(@lcnr): Move this module out of `rustc_hir_analysis`.
2-
//
3-
// We don't do any drop checking during hir typeck.
4-
51
use rustc_data_structures::fx::FxHashSet;
62
use rustc_errors::codes::*;
73
use rustc_errors::{ErrorGuaranteed, struct_span_code_err};
@@ -32,7 +28,10 @@ use crate::hir::def_id::{DefId, LocalDefId};
3228
/// struct/enum definition for the nominal type itself (i.e.
3329
/// cannot do `struct S<T>; impl<T:Clone> Drop for S<T> { ... }`).
3430
///
35-
pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), ErrorGuaranteed> {
31+
pub(crate) fn check_drop_impl(
32+
tcx: TyCtxt<'_>,
33+
drop_impl_did: DefId,
34+
) -> Result<(), ErrorGuaranteed> {
3635
match tcx.impl_polarity(drop_impl_did) {
3736
ty::ImplPolarity::Positive => {}
3837
ty::ImplPolarity::Negative => {

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ pub fn check_intrinsic_type(
199199
let split: Vec<&str> = name_str.split('_').collect();
200200
assert!(split.len() >= 2, "Atomic intrinsic in an incorrect format");
201201

202-
//We only care about the operation here
202+
// Each atomic op has variants with different suffixes (`_seq_cst`, `_acquire`, etc.). Use
203+
// string ops to strip the suffixes, because the variants all get the same treatment here.
203204
let (n_tps, inputs, output) = match split[1] {
204205
"cxchg" | "cxchgweak" => (
205206
1,

compiler/rustc_hir_analysis/src/check/mod.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -455,18 +455,14 @@ fn fn_sig_suggestion<'tcx>(
455455
let mut output = sig.output();
456456

457457
let asyncness = if tcx.asyncness(assoc.def_id).is_async() {
458-
output = if let ty::Alias(_, alias_ty) = *output.kind() {
459-
tcx.explicit_item_self_bounds(alias_ty.def_id)
458+
output = if let ty::Alias(_, alias_ty) = *output.kind()
459+
&& let Some(output) = tcx
460+
.explicit_item_self_bounds(alias_ty.def_id)
460461
.iter_instantiated_copied(tcx, alias_ty.args)
461462
.find_map(|(bound, _)| {
462463
bound.as_projection_clause()?.no_bound_vars()?.term.as_type()
463-
})
464-
.unwrap_or_else(|| {
465-
span_bug!(
466-
ident.span,
467-
"expected async fn to have `impl Future` output, but it returns {output}"
468-
)
469-
})
464+
}) {
465+
output
470466
} else {
471467
span_bug!(
472468
ident.span,

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -2267,14 +2267,12 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
22672267

22682268
fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) -> Result<(), ErrorGuaranteed> {
22692269
let items = tcx.hir_module_items(module);
2270-
let mut res = items.par_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id));
2271-
res =
2272-
res.and(items.par_impl_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)));
2273-
res =
2274-
res.and(items.par_trait_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)));
2275-
res = res
2276-
.and(items.par_foreign_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)));
2277-
res = res.and(items.par_opaques(|item| tcx.ensure().check_well_formed(item)));
2270+
let res = items
2271+
.par_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id))
2272+
.and(items.par_impl_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)))
2273+
.and(items.par_trait_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)))
2274+
.and(items.par_foreign_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)))
2275+
.and(items.par_opaques(|item| tcx.ensure().check_well_formed(item)));
22782276
if module == LocalModDefId::CRATE_DEF_ID {
22792277
super::entry::check_for_entry_fn(tcx);
22802278
}

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,12 @@ pub(crate) fn coerce_unsized_info<'tcx>(
404404
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ref(tcx, r_b, ty))
405405
}
406406

407-
(&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(ty_b, mutbl_b)) => check_mutbl(
408-
ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a },
409-
ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b },
410-
&|ty| Ty::new_imm_ptr(tcx, ty),
411-
),
412-
413-
(&ty::RawPtr(ty_a, mutbl_a), &ty::RawPtr(ty_b, mutbl_b)) => check_mutbl(
414-
ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a },
415-
ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b },
416-
&|ty| Ty::new_imm_ptr(tcx, ty),
417-
),
407+
(&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(ty_b, mutbl_b))
408+
| (&ty::RawPtr(ty_a, mutbl_a), &ty::RawPtr(ty_b, mutbl_b)) => {
409+
let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a };
410+
let mt_b = ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b };
411+
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ptr(tcx, ty))
412+
}
418413

419414
(&ty::Adt(def_a, args_a), &ty::Adt(def_b, args_b))
420415
if def_a.is_struct() && def_b.is_struct() =>

compiler/rustc_hir_analysis/src/coherence/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
158158
let trait_ref = trait_header.trait_ref.instantiate_identity();
159159
let trait_def = tcx.trait_def(trait_ref.def_id);
160160

161-
res = res.and(check_impl(tcx, impl_def_id, trait_ref, trait_def));
162-
res = res.and(check_object_overlap(tcx, impl_def_id, trait_ref));
163-
164-
res = res.and(unsafety::check_item(tcx, impl_def_id, trait_header, trait_def));
165-
res = res.and(tcx.ensure().orphan_check_impl(impl_def_id));
166-
res = res.and(builtin::check_trait(tcx, def_id, impl_def_id, trait_header));
161+
res = res
162+
.and(check_impl(tcx, impl_def_id, trait_ref, trait_def))
163+
.and(check_object_overlap(tcx, impl_def_id, trait_ref))
164+
.and(unsafety::check_item(tcx, impl_def_id, trait_header, trait_def))
165+
.and(tcx.ensure().orphan_check_impl(impl_def_id))
166+
.and(builtin::check_trait(tcx, def_id, impl_def_id, trait_header));
167167
}
168168

169169
res

compiler/rustc_hir_analysis/src/collect.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ mod type_of;
5757

5858
///////////////////////////////////////////////////////////////////////////
5959

60-
pub fn provide(providers: &mut Providers) {
60+
pub(crate) fn provide(providers: &mut Providers) {
6161
resolve_bound_vars::provide(providers);
6262
*providers = Providers {
6363
type_of: type_of::type_of,
@@ -122,7 +122,7 @@ pub fn provide(providers: &mut Providers) {
122122
/// `ItemCtxt` is parameterized by a `DefId` that it uses to satisfy
123123
/// `probe_ty_param_bounds` requests, drawing the information from
124124
/// the HIR (`hir::Generics`), recursively.
125-
pub struct ItemCtxt<'tcx> {
125+
pub(crate) struct ItemCtxt<'tcx> {
126126
tcx: TyCtxt<'tcx>,
127127
item_def_id: LocalDefId,
128128
tainted_by_errors: Cell<Option<ErrorGuaranteed>>,
@@ -148,7 +148,7 @@ impl<'v> Visitor<'v> for HirPlaceholderCollector {
148148
}
149149
}
150150

151-
pub struct CollectItemTypesVisitor<'tcx> {
151+
pub(crate) struct CollectItemTypesVisitor<'tcx> {
152152
pub tcx: TyCtxt<'tcx>,
153153
}
154154

@@ -364,19 +364,19 @@ fn bad_placeholder<'cx, 'tcx>(
364364
}
365365

366366
impl<'tcx> ItemCtxt<'tcx> {
367-
pub fn new(tcx: TyCtxt<'tcx>, item_def_id: LocalDefId) -> ItemCtxt<'tcx> {
367+
pub(crate) fn new(tcx: TyCtxt<'tcx>, item_def_id: LocalDefId) -> ItemCtxt<'tcx> {
368368
ItemCtxt { tcx, item_def_id, tainted_by_errors: Cell::new(None) }
369369
}
370370

371-
pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
371+
pub(crate) fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
372372
self.lowerer().lower_ty(hir_ty)
373373
}
374374

375-
pub fn hir_id(&self) -> hir::HirId {
375+
pub(crate) fn hir_id(&self) -> hir::HirId {
376376
self.tcx.local_def_id_to_hir_id(self.item_def_id)
377377
}
378378

379-
pub fn node(&self) -> hir::Node<'tcx> {
379+
pub(crate) fn node(&self) -> hir::Node<'tcx> {
380380
self.tcx.hir_node(self.hir_id())
381381
}
382382

0 commit comments

Comments
 (0)