File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ pub use UnsafeSource::*;
25
25
use crate :: ptr:: P ;
26
26
use crate :: token:: { self , DelimToken } ;
27
27
use crate :: tokenstream:: { DelimSpan , TokenStream , TokenTree } ;
28
+ use crate :: visit:: { walk_ty, Visitor } ;
28
29
29
30
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
30
31
use rustc_data_structures:: sync:: Lrc ;
@@ -1795,6 +1796,26 @@ pub struct Ty {
1795
1796
pub span : Span ,
1796
1797
}
1797
1798
1799
+ impl Ty {
1800
+ /// Returns `true` if the kind of this type or any types contained within are `impl Trait`.
1801
+ pub fn contains_impl_trait ( & self ) -> bool {
1802
+ struct ContainsImplTrait ( bool ) ;
1803
+
1804
+ impl < ' ast > Visitor < ' ast > for ContainsImplTrait {
1805
+ fn visit_ty ( & mut self , t : & ' ast Ty ) {
1806
+ self . 0 |= matches ! ( t. kind, TyKind :: ImplTrait ( ..) ) ;
1807
+ if !self . 0 {
1808
+ walk_ty ( self , t) ;
1809
+ }
1810
+ }
1811
+ }
1812
+
1813
+ let mut vis = ContainsImplTrait ( false ) ;
1814
+ vis. visit_ty ( self ) ;
1815
+ vis. 0
1816
+ }
1817
+ }
1818
+
1798
1819
#[ derive( Clone , RustcEncodable , RustcDecodable , Debug ) ]
1799
1820
pub struct BareFnTy {
1800
1821
pub unsafety : Unsafe ,
You can’t perform that action at this time.
0 commit comments