Skip to content

Commit 53fc6ad

Browse files
committed
make itemctxt structurally resolve field types
1 parent 674f94a commit 53fc6ad

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! crate as a kind of pass. This should eventually be factored away.
1616
1717
use std::assert_matches::assert_matches;
18-
use std::cell::Cell;
18+
use std::cell::{Cell, RefCell};
1919
use std::iter;
2020
use std::ops::Bound;
2121

@@ -33,19 +33,21 @@ use rustc_hir::def_id::{DefId, LocalDefId};
3333
use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt};
3434
use rustc_hir::{self as hir, GenericParamKind, HirId, Node, PreciseCapturingArgKind, find_attr};
3535
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
36-
use rustc_infer::traits::{DynCompatibilityViolation, ObligationCause};
36+
use rustc_infer::traits::{DynCompatibilityViolation, ObligationCause, TraitEngine};
3737
use rustc_middle::query::Providers;
3838
use rustc_middle::ty::util::{Discr, IntTypeExt};
3939
use rustc_middle::ty::{
40-
self, AdtKind, Const, FieldPath, FieldPathKind, IsSuggestable, Ty, TyCtxt, TypeVisitableExt,
41-
TypingMode, fold_regions,
40+
self, AdtKind, Const, FieldPath, FieldPathKind, IsSuggestable, ParamEnv, Ty, TyCtxt,
41+
TypeVisitableExt, TypingMode, fold_regions,
4242
};
4343
use rustc_middle::{bug, span_bug};
4444
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
45+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
4546
use rustc_trait_selection::error_reporting::traits::suggestions::NextTypeParamName;
4647
use rustc_trait_selection::infer::InferCtxtExt;
4748
use rustc_trait_selection::traits::{
48-
FulfillmentError, ObligationCtxt, hir_ty_lowering_dyn_compatibility_violations,
49+
FulfillmentError, ObligationCtxt, StructurallyNormalizeExt, TraitEngineExt,
50+
hir_ty_lowering_dyn_compatibility_violations,
4951
};
5052
use tracing::{debug, instrument};
5153

@@ -368,9 +370,17 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
368370
infcx = Some(self.tcx().infer_ctxt().build(ty::TypingMode::non_body_analysis()));
369371
infcx.as_ref().unwrap()
370372
});
373+
let cause = ObligationCause::misc(span, self.item_def_id);
374+
let at = infcx.at(&cause, ParamEnv::empty());
375+
let ty_ch_cx = RefCell::new(<dyn TraitEngine<'_, FulfillmentError<'tcx>>>::new(&infcx));
371376

372377
while let Some(&field) = fields.next() {
373-
let container = infcx.shallow_resolve(current_container);
378+
let result =
379+
at.structurally_normalize_ty(current_container, &mut **ty_ch_cx.borrow_mut());
380+
let container = match result {
381+
Ok(normalized_ty) => normalized_ty,
382+
Err(errors) => return Err(infcx.err_ctxt().report_fulfillment_errors(errors)),
383+
};
374384
match container.kind() {
375385
ty::Adt(def, args) if !def.is_enum() => {
376386
let block = self.tcx.local_def_id_to_hir_id(self.item_def_id);

0 commit comments

Comments
 (0)