tidy + move logic to fn
This commit is contained in:
parent
ca5a6e43dd
commit
b3425587a6
3 changed files with 30 additions and 31 deletions
|
@ -2418,6 +2418,30 @@ impl<'hir> Ty<'hir> {
|
||||||
}
|
}
|
||||||
final_ty
|
final_ty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_self_aliases(&self) -> Vec<Span> {
|
||||||
|
use crate::intravisit::Visitor;
|
||||||
|
struct MyVisitor(Vec<Span>);
|
||||||
|
impl<'v> Visitor<'v> for MyVisitor {
|
||||||
|
fn visit_ty(&mut self, t: &'v Ty<'v>) {
|
||||||
|
if matches!(
|
||||||
|
&t.kind,
|
||||||
|
TyKind::Path(QPath::Resolved(
|
||||||
|
_,
|
||||||
|
Path { res: crate::def::Res::SelfTyAlias { .. }, .. },
|
||||||
|
))
|
||||||
|
) {
|
||||||
|
self.0.push(t.span);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
crate::intravisit::walk_ty(self, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut my_visitor = MyVisitor(vec![]);
|
||||||
|
my_visitor.visit_ty(self);
|
||||||
|
my_visitor.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Not represented directly in the AST; referred to by name through a `ty_path`.
|
/// Not represented directly in the AST; referred to by name through a `ty_path`.
|
||||||
|
|
|
@ -319,33 +319,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ItemKind::TyAlias(self_ty, _) => icx.to_ty(self_ty),
|
ItemKind::TyAlias(self_ty, _) => icx.to_ty(self_ty),
|
||||||
ItemKind::Impl(
|
ItemKind::Impl(hir::Impl { self_ty, .. }) => {
|
||||||
hir::Impl { self_ty, .. }
|
match self_ty.find_self_aliases() {
|
||||||
) => {
|
|
||||||
struct MyVisitor(Vec<Span>);
|
|
||||||
impl<'v> hir::intravisit::Visitor<'v> for MyVisitor {
|
|
||||||
fn visit_ty(&mut self, t: &'v Ty<'v>) {
|
|
||||||
if matches!(
|
|
||||||
&t.kind,
|
|
||||||
TyKind::Path(hir::QPath::Resolved(
|
|
||||||
_,
|
|
||||||
Path {
|
|
||||||
res: hir::def::Res::SelfTyAlias { .. },
|
|
||||||
..
|
|
||||||
},
|
|
||||||
))
|
|
||||||
) {
|
|
||||||
self.0.push(t.span);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
hir::intravisit::walk_ty(self, t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut my_visitor = MyVisitor(vec![]);
|
|
||||||
my_visitor.visit_ty(self_ty);
|
|
||||||
|
|
||||||
match my_visitor.0 {
|
|
||||||
spans if spans.len() > 0 => {
|
spans if spans.len() > 0 => {
|
||||||
tcx.sess.emit_err(crate::errors::SelfInImplSelf { span: spans.into(), note: (), });
|
tcx.sess.emit_err(crate::errors::SelfInImplSelf { span: spans.into(), note: (), });
|
||||||
tcx.ty_error()
|
tcx.ty_error()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue