Skip to content

Commit 61c5e74

Browse files
committed
Move more logic into lower_qpath_shared
1 parent 84937e1 commit 61c5e74

File tree

1 file changed

+33
-47
lines changed
  • compiler/rustc_hir_analysis/src/hir_ty_lowering

1 file changed

+33
-47
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,31 +1769,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
17691769
trait_segment: &hir::PathSegment<'tcx>,
17701770
item_segment: &hir::PathSegment<'tcx>,
17711771
) -> Ty<'tcx> {
1772-
let tcx = self.tcx();
1773-
1774-
let trait_def_id = tcx.parent(item_def_id);
1775-
debug!(?trait_def_id);
1776-
1777-
let Some(self_ty) = opt_self_ty else {
1778-
let guar = self.error_missing_qpath_self_ty(
1779-
trait_def_id,
1780-
span,
1781-
item_segment,
1782-
ty::AssocKind::Type,
1783-
);
1784-
return Ty::new_error(tcx, guar);
1785-
};
1786-
debug!(?self_ty);
1787-
1788-
let (item_def_id, item_args) = self.lower_qpath_shared(
1772+
match self.lower_qpath_shared(
17891773
span,
1790-
self_ty,
1791-
trait_def_id,
1774+
opt_self_ty,
17921775
item_def_id,
17931776
trait_segment,
17941777
item_segment,
1795-
);
1796-
Ty::new_projection_from_args(tcx, item_def_id, item_args)
1778+
ty::AssocKind::Type,
1779+
) {
1780+
Ok((item_def_id, item_args)) => {
1781+
Ty::new_projection_from_args(self.tcx(), item_def_id, item_args)
1782+
}
1783+
Err(guar) => Ty::new_error(self.tcx(), guar),
1784+
}
17971785
}
17981786

17991787
/// Lower a qualified path to a const.
@@ -1806,52 +1794,50 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
18061794
trait_segment: &hir::PathSegment<'tcx>,
18071795
item_segment: &hir::PathSegment<'tcx>,
18081796
) -> Const<'tcx> {
1809-
let tcx = self.tcx();
1810-
1811-
let trait_def_id = tcx.parent(item_def_id);
1812-
debug!(?trait_def_id);
1813-
1814-
let Some(self_ty) = opt_self_ty else {
1815-
let guar = self.error_missing_qpath_self_ty(
1816-
trait_def_id,
1817-
span,
1818-
item_segment,
1819-
ty::AssocKind::Const,
1820-
);
1821-
return Const::new_error(tcx, guar);
1822-
};
1823-
debug!(?self_ty);
1824-
1825-
let (item_def_id, item_args) = self.lower_qpath_shared(
1797+
match self.lower_qpath_shared(
18261798
span,
1827-
self_ty,
1828-
trait_def_id,
1799+
opt_self_ty,
18291800
item_def_id,
18301801
trait_segment,
18311802
item_segment,
1832-
);
1833-
let uv = ty::UnevaluatedConst::new(item_def_id, item_args);
1834-
Const::new_unevaluated(tcx, uv)
1803+
ty::AssocKind::Const,
1804+
) {
1805+
Ok((item_def_id, item_args)) => {
1806+
let uv = ty::UnevaluatedConst::new(item_def_id, item_args);
1807+
Const::new_unevaluated(self.tcx(), uv)
1808+
}
1809+
Err(guar) => Const::new_error(self.tcx(), guar),
1810+
}
18351811
}
18361812

18371813
#[instrument(level = "debug", skip_all)]
18381814
fn lower_qpath_shared(
18391815
&self,
18401816
span: Span,
1841-
self_ty: Ty<'tcx>,
1842-
trait_def_id: DefId,
1817+
opt_self_ty: Option<Ty<'tcx>>,
18431818
item_def_id: DefId,
18441819
trait_segment: &hir::PathSegment<'tcx>,
18451820
item_segment: &hir::PathSegment<'tcx>,
1846-
) -> (DefId, GenericArgsRef<'tcx>) {
1821+
kind: ty::AssocKind,
1822+
) -> Result<(DefId, GenericArgsRef<'tcx>), ErrorGuaranteed> {
1823+
let tcx = self.tcx();
1824+
1825+
let trait_def_id = tcx.parent(item_def_id);
1826+
debug!(?trait_def_id);
1827+
1828+
let Some(self_ty) = opt_self_ty else {
1829+
return Err(self.error_missing_qpath_self_ty(trait_def_id, span, item_segment, kind));
1830+
};
1831+
debug!(?self_ty);
1832+
18471833
let trait_ref =
18481834
self.lower_mono_trait_ref(span, trait_def_id, self_ty, trait_segment, false);
18491835
debug!(?trait_ref);
18501836

18511837
let item_args =
18521838
self.lower_generic_args_of_assoc_item(span, item_def_id, item_segment, trait_ref.args);
18531839

1854-
(item_def_id, item_args)
1840+
Ok((item_def_id, item_args))
18551841
}
18561842

18571843
fn error_missing_qpath_self_ty(

0 commit comments

Comments
 (0)