File tree 1 file changed +21
-0
lines changed
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 ;
@@ -1784,6 +1785,26 @@ pub struct Ty {
1784
1785
pub span : Span ,
1785
1786
}
1786
1787
1788
+ impl Ty {
1789
+ /// Returns `true` if the kind of this type or any types contained within are `impl Trait`.
1790
+ pub fn contains_impl_trait ( & self ) -> bool {
1791
+ struct ContainsImplTrait ( bool ) ;
1792
+
1793
+ impl < ' ast > Visitor < ' ast > for ContainsImplTrait {
1794
+ fn visit_ty ( & mut self , t : & ' ast Ty ) {
1795
+ self . 0 |= matches ! ( t. kind, TyKind :: ImplTrait ( ..) ) ;
1796
+ if !self . 0 {
1797
+ walk_ty ( self , t) ;
1798
+ }
1799
+ }
1800
+ }
1801
+
1802
+ let mut vis = ContainsImplTrait ( false ) ;
1803
+ vis. visit_ty ( self ) ;
1804
+ vis. 0
1805
+ }
1806
+ }
1807
+
1787
1808
#[ derive( Clone , RustcEncodable , RustcDecodable , Debug ) ]
1788
1809
pub struct BareFnTy {
1789
1810
pub unsafety : Unsafe ,
You can’t perform that action at this time.
0 commit comments