make hir::Ty/ConstArg
methods generic where applicable
This commit is contained in:
parent
3b5ea05142
commit
23e28d3641
4 changed files with 23 additions and 13 deletions
|
@ -315,7 +315,7 @@ impl<'hir> ConstArg<'hir> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'hir> ConstArg<'hir> {
|
impl<'hir, Unambig> ConstArg<'hir, Unambig> {
|
||||||
pub fn anon_const_hir_id(&self) -> Option<HirId> {
|
pub fn anon_const_hir_id(&self) -> Option<HirId> {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
ConstArgKind::Anon(ac) => Some(ac.hir_id),
|
ConstArgKind::Anon(ac) => Some(ac.hir_id),
|
||||||
|
@ -383,7 +383,7 @@ impl GenericArg<'_> {
|
||||||
match self {
|
match self {
|
||||||
GenericArg::Lifetime(l) => l.ident.span,
|
GenericArg::Lifetime(l) => l.ident.span,
|
||||||
GenericArg::Type(t) => t.span,
|
GenericArg::Type(t) => t.span,
|
||||||
GenericArg::Const(c) => c.as_unambig_ct().span(),
|
GenericArg::Const(c) => c.span(),
|
||||||
GenericArg::Infer(i) => i.span,
|
GenericArg::Infer(i) => i.span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3022,7 +3022,25 @@ impl<'hir> Ty<'hir> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'hir> Ty<'hir, AmbigArg> {
|
||||||
|
pub fn peel_refs(&self) -> &Ty<'hir> {
|
||||||
|
let mut final_ty = self.as_unambig_ty();
|
||||||
|
while let TyKind::Ref(_, MutTy { ty, .. }) = &final_ty.kind {
|
||||||
|
final_ty = ty;
|
||||||
|
}
|
||||||
|
final_ty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'hir> Ty<'hir> {
|
impl<'hir> Ty<'hir> {
|
||||||
|
pub fn peel_refs(&self) -> &Self {
|
||||||
|
let mut final_ty = self;
|
||||||
|
while let TyKind::Ref(_, MutTy { ty, .. }) = &final_ty.kind {
|
||||||
|
final_ty = ty;
|
||||||
|
}
|
||||||
|
final_ty
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `true` if `param_def_id` matches the `bounded_ty` of this predicate.
|
/// Returns `true` if `param_def_id` matches the `bounded_ty` of this predicate.
|
||||||
pub fn as_generic_param(&self) -> Option<(DefId, Ident)> {
|
pub fn as_generic_param(&self) -> Option<(DefId, Ident)> {
|
||||||
let TyKind::Path(QPath::Resolved(None, path)) = self.kind else {
|
let TyKind::Path(QPath::Resolved(None, path)) = self.kind else {
|
||||||
|
@ -3039,14 +3057,6 @@ impl<'hir> Ty<'hir> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn peel_refs(&self) -> &Self {
|
|
||||||
let mut final_ty = self;
|
|
||||||
while let TyKind::Ref(_, MutTy { ty, .. }) = &final_ty.kind {
|
|
||||||
final_ty = ty;
|
|
||||||
}
|
|
||||||
final_ty
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn find_self_aliases(&self) -> Vec<Span> {
|
pub fn find_self_aliases(&self) -> Vec<Span> {
|
||||||
use crate::intravisit::Visitor;
|
use crate::intravisit::Visitor;
|
||||||
struct MyVisitor(Vec<Span>);
|
struct MyVisitor(Vec<Span>);
|
||||||
|
|
|
@ -77,7 +77,7 @@ fn gen_args(cx: &LateContext<'_>, segment: &PathSegment<'_>) -> String {
|
||||||
.tcx
|
.tcx
|
||||||
.sess
|
.sess
|
||||||
.source_map()
|
.source_map()
|
||||||
.span_to_snippet(c.as_unambig_ct().span())
|
.span_to_snippet(c.span())
|
||||||
.unwrap_or_else(|_| "_".into()),
|
.unwrap_or_else(|_| "_".into()),
|
||||||
GenericArg::Infer(_) => String::from("_"),
|
GenericArg::Infer(_) => String::from("_"),
|
||||||
})
|
})
|
||||||
|
|
|
@ -197,7 +197,7 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> {
|
||||||
type NestedFilter = nested_filter::OnlyBodies;
|
type NestedFilter = nested_filter::OnlyBodies;
|
||||||
|
|
||||||
fn visit_ty(&mut self, t: &'tcx Ty<'tcx, AmbigArg>) {
|
fn visit_ty(&mut self, t: &'tcx Ty<'tcx, AmbigArg>) {
|
||||||
if let Some((def_id, _)) = t.as_unambig_ty().peel_refs().as_generic_param() {
|
if let Some((def_id, _)) = t.peel_refs().as_generic_param() {
|
||||||
self.ty_params.remove(&def_id);
|
self.ty_params.remove(&def_id);
|
||||||
} else {
|
} else {
|
||||||
walk_ty(self, t);
|
walk_ty(self, t);
|
||||||
|
|
|
@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
|
||||||
|diag| {
|
|diag| {
|
||||||
// If the target type is likely foreign mention the orphan rules as it's a common source of
|
// If the target type is likely foreign mention the orphan rules as it's a common source of
|
||||||
// confusion
|
// confusion
|
||||||
if path_def_id(cx, target_ty.as_unambig_ty().peel_refs()).is_none_or(|id| !id.is_local()) {
|
if path_def_id(cx, target_ty.peel_refs()).is_none_or(|id| !id.is_local()) {
|
||||||
diag.help(
|
diag.help(
|
||||||
"`impl From<Local> for Foreign` is allowed by the orphan rules, for more information see\n\
|
"`impl From<Local> for Foreign` is allowed by the orphan rules, for more information see\n\
|
||||||
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence"
|
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue