Skip to content

Commit 71cee31

Browse files
committed
Move more logic into lower_qpath_shared
1 parent 7ce5272 commit 71cee31

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

+33-47
Original file line numberDiff line numberDiff line change
@@ -1775,31 +1775,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
17751775
trait_segment: &hir::PathSegment<'tcx>,
17761776
item_segment: &hir::PathSegment<'tcx>,
17771777
) -> Ty<'tcx> {
1778-
let tcx = self.tcx();
1779-
1780-
let trait_def_id = tcx.parent(item_def_id);
1781-
debug!(?trait_def_id);
1782-
1783-
let Some(self_ty) = opt_self_ty else {
1784-
let guar = self.error_missing_qpath_self_ty(
1785-
trait_def_id,
1786-
span,
1787-
item_segment,
1788-
ty::AssocKind::Type,
1789-
);
1790-
return Ty::new_error(tcx, guar);
1791-
};
1792-
debug!(?self_ty);
1793-
1794-
let (item_def_id, item_args) = self.lower_qpath_shared(
1778+
match self.lower_qpath_shared(
17951779
span,
1796-
self_ty,
1797-
trait_def_id,
1780+
opt_self_ty,
17981781
item_def_id,
17991782
trait_segment,
18001783
item_segment,
1801-
);
1802-
Ty::new_projection_from_args(tcx, item_def_id, item_args)
1784+
ty::AssocKind::Type,
1785+
) {
1786+
Ok((item_def_id, item_args)) => {
1787+
Ty::new_projection_from_args(self.tcx(), item_def_id, item_args)
1788+
}
1789+
Err(guar) => Ty::new_error(self.tcx(), guar),
1790+
}
18031791
}
18041792

18051793
/// Lower a qualified path to a const.
@@ -1812,52 +1800,50 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
18121800
trait_segment: &hir::PathSegment<'tcx>,
18131801
item_segment: &hir::PathSegment<'tcx>,
18141802
) -> Const<'tcx> {
1815-
let tcx = self.tcx();
1816-
1817-
let trait_def_id = tcx.parent(item_def_id);
1818-
debug!(?trait_def_id);
1819-
1820-
let Some(self_ty) = opt_self_ty else {
1821-
let guar = self.error_missing_qpath_self_ty(
1822-
trait_def_id,
1823-
span,
1824-
item_segment,
1825-
ty::AssocKind::Const,
1826-
);
1827-
return Const::new_error(tcx, guar);
1828-
};
1829-
debug!(?self_ty);
1830-
1831-
let (item_def_id, item_args) = self.lower_qpath_shared(
1803+
match self.lower_qpath_shared(
18321804
span,
1833-
self_ty,
1834-
trait_def_id,
1805+
opt_self_ty,
18351806
item_def_id,
18361807
trait_segment,
18371808
item_segment,
1838-
);
1839-
let uv = ty::UnevaluatedConst::new(item_def_id, item_args);
1840-
Const::new_unevaluated(tcx, uv)
1809+
ty::AssocKind::Const,
1810+
) {
1811+
Ok((item_def_id, item_args)) => {
1812+
let uv = ty::UnevaluatedConst::new(item_def_id, item_args);
1813+
Const::new_unevaluated(self.tcx(), uv)
1814+
}
1815+
Err(guar) => Const::new_error(self.tcx(), guar),
1816+
}
18411817
}
18421818

18431819
#[instrument(level = "debug", skip_all)]
18441820
fn lower_qpath_shared(
18451821
&self,
18461822
span: Span,
1847-
self_ty: Ty<'tcx>,
1848-
trait_def_id: DefId,
1823+
opt_self_ty: Option<Ty<'tcx>>,
18491824
item_def_id: DefId,
18501825
trait_segment: &hir::PathSegment<'tcx>,
18511826
item_segment: &hir::PathSegment<'tcx>,
1852-
) -> (DefId, GenericArgsRef<'tcx>) {
1827+
kind: ty::AssocKind,
1828+
) -> Result<(DefId, GenericArgsRef<'tcx>), ErrorGuaranteed> {
1829+
let tcx = self.tcx();
1830+
1831+
let trait_def_id = tcx.parent(item_def_id);
1832+
debug!(?trait_def_id);
1833+
1834+
let Some(self_ty) = opt_self_ty else {
1835+
return Err(self.error_missing_qpath_self_ty(trait_def_id, span, item_segment, kind));
1836+
};
1837+
debug!(?self_ty);
1838+
18531839
let trait_ref =
18541840
self.lower_mono_trait_ref(span, trait_def_id, self_ty, trait_segment, false);
18551841
debug!(?trait_ref);
18561842

18571843
let item_args =
18581844
self.lower_generic_args_of_assoc_item(span, item_def_id, item_segment, trait_ref.args);
18591845

1860-
(item_def_id, item_args)
1846+
Ok((item_def_id, item_args))
18611847
}
18621848

18631849
fn error_missing_qpath_self_ty(

0 commit comments

Comments
 (0)