Skip to content

Commit 5ff2cd7

Browse files
committed
use the From trait instead of from_expr/ty
1 parent 33ea5d3 commit 5ff2cd7

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

clippy_lints/src/utils/ast_utils/ident_iter.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,28 @@ use rustc_ast::*;
44
use rustc_ast::ptr::P;
55
use rustc_span::symbol::Ident;
66

7-
pub type IdentIter<'a> = Box<dyn Iterator<Item = Ident> + 'a>;
7+
pub struct IdentIterator<'a>(IdentIter<'a>);
88

9-
pub fn from_expr<'expr>(expr: &'expr Expr) -> IdentIter<'expr> {
10-
Box::new(ExprIdentIter::new(expr))
9+
type IdentIter<'a> = Box<dyn Iterator<Item = Ident> + 'a>;
10+
11+
impl <'expr> Iterator for IdentIterator<'expr> {
12+
type Item = Ident;
13+
14+
fn next(&mut self) -> Option<Self::Item> {
15+
self.0.next()
16+
}
1117
}
1218

13-
pub fn from_ty<'ty>(ty: &'ty Ty) -> IdentIter<'ty> {
14-
Box::new(TyIdentIter::new(ty))
19+
impl <'expr> From<&'expr Expr> for IdentIterator<'expr> {
20+
fn from(expr: &'expr Expr) -> Self {
21+
IdentIterator(Box::new(ExprIdentIter::new(expr)))
22+
}
23+
}
24+
25+
impl <'ty> From<&'ty Ty> for IdentIterator<'ty> {
26+
fn from(ty: &'ty Ty) -> Self {
27+
IdentIterator(Box::new(TyIdentIter::new(ty)))
28+
}
1529
}
1630

1731
struct ExprIdentIter<'expr> {

0 commit comments

Comments
 (0)