Skip to content

Commit 256480b

Browse files
Remove redundant flags that can be inferred from the HIR
1 parent 147bb17 commit 256480b

File tree

4 files changed

+18
-29
lines changed

4 files changed

+18
-29
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1515
///
1616
/// *Bare* trait object types are ones that aren't preceded by the keyword `dyn`.
1717
/// In edition 2021 and onward we emit a hard error for them.
18-
pub(super) fn prohibit_or_lint_bare_trait_object_ty(
19-
&self,
20-
self_ty: &hir::Ty<'_>,
21-
in_path: bool,
22-
) {
18+
pub(super) fn prohibit_or_lint_bare_trait_object_ty(&self, self_ty: &hir::Ty<'_>) {
2319
let tcx = self.tcx();
2420

2521
let hir::TyKind::TraitObject([poly_trait_ref, ..], _, TraitObjectSyntax::None) =
@@ -28,6 +24,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2824
return;
2925
};
3026

27+
let in_path = match tcx.parent_hir_node(self_ty.hir_id) {
28+
hir::Node::Ty(hir::Ty {
29+
kind: hir::TyKind::Path(hir::QPath::TypeRelative(qself, _)),
30+
..
31+
})
32+
| hir::Node::Expr(hir::Expr {
33+
kind: hir::ExprKind::Path(hir::QPath::TypeRelative(qself, _)),
34+
..
35+
}) if qself.hir_id == self_ty.hir_id => true,
36+
_ => false,
37+
};
3138
let needs_bracket = in_path
3239
&& !tcx
3340
.sess

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,16 +1998,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19981998
}
19991999
}
20002000

2001-
/// Lower a type from the HIR to our internal notion of a type.
2002-
pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
2003-
self.lower_ty_common(hir_ty, false, false)
2004-
}
2005-
2006-
/// Lower a type inside of a path from the HIR to our internal notion of a type.
2007-
pub fn lower_ty_in_path(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
2008-
self.lower_ty_common(hir_ty, false, true)
2009-
}
2010-
20112001
fn lower_delegation_ty(&self, idx: hir::InferDelegationKind) -> Ty<'tcx> {
20122002
let delegation_sig = self.tcx().inherit_sig_for_delegation_item(self.item_def_id());
20132003
match idx {
@@ -2025,7 +2015,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20252015
/// 2. `in_path`: Whether the type appears inside of a path.
20262016
/// Used to provide correct diagnostics for bare trait object types.
20272017
#[instrument(level = "debug", skip(self), ret)]
2028-
fn lower_ty_common(&self, hir_ty: &hir::Ty<'tcx>, borrowed: bool, in_path: bool) -> Ty<'tcx> {
2018+
pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
20292019
let tcx = self.tcx();
20302020

20312021
let result_ty = match &hir_ty.kind {
@@ -2035,7 +2025,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20352025
hir::TyKind::Ref(region, mt) => {
20362026
let r = self.lower_lifetime(region, RegionInferReason::Reference);
20372027
debug!(?r);
2038-
let t = self.lower_ty_common(mt.ty, true, false);
2028+
let t = self.lower_ty(mt.ty);
20392029
Ty::new_ref(tcx, r, t, mt.mutbl)
20402030
}
20412031
hir::TyKind::Never => tcx.types.never,
@@ -2064,20 +2054,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20642054
)
20652055
}
20662056
hir::TyKind::TraitObject(bounds, lifetime, repr) => {
2067-
self.prohibit_or_lint_bare_trait_object_ty(hir_ty, in_path);
2057+
self.prohibit_or_lint_bare_trait_object_ty(hir_ty);
20682058

20692059
let repr = match repr {
20702060
TraitObjectSyntax::Dyn | TraitObjectSyntax::None => ty::Dyn,
20712061
TraitObjectSyntax::DynStar => ty::DynStar,
20722062
};
2073-
self.lower_trait_object_ty(
2074-
hir_ty.span,
2075-
hir_ty.hir_id,
2076-
bounds,
2077-
lifetime,
2078-
borrowed,
2079-
repr,
2080-
)
2063+
self.lower_trait_object_ty(hir_ty.span, hir_ty.hir_id, bounds, lifetime, repr)
20812064
}
20822065
hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
20832066
debug!(?maybe_qself, ?path);
@@ -2105,7 +2088,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21052088
}
21062089
hir::TyKind::Path(hir::QPath::TypeRelative(qself, segment)) => {
21072090
debug!(?qself, ?segment);
2108-
let ty = self.lower_ty_common(qself, false, true);
2091+
let ty = self.lower_ty(qself);
21092092
self.lower_assoc_path(hir_ty.hir_id, hir_ty.span, ty, qself, segment, false)
21102093
.map(|(ty, _, _)| ty)
21112094
.unwrap_or_else(|guar| Ty::new_error(tcx, guar))

compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
3030
hir_id: hir::HirId,
3131
hir_trait_bounds: &[(hir::PolyTraitRef<'tcx>, hir::TraitBoundModifier)],
3232
lifetime: &hir::Lifetime,
33-
_borrowed: bool,
3433
representation: DynKind,
3534
) -> Ty<'tcx> {
3635
let tcx = self.tcx();

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
798798
// to be object-safe.
799799
// We manually call `register_wf_obligation` in the success path
800800
// below.
801-
let ty = self.lowerer().lower_ty_in_path(qself);
801+
let ty = self.lowerer().lower_ty(qself);
802802
(LoweredTy::from_raw(self, span, ty), qself, segment)
803803
}
804804
QPath::LangItem(..) => {

0 commit comments

Comments
 (0)