]> git.lizzy.rs Git - rust.git/blobdiff - crates/syntax/src/ast.rs
Merge #11294
[rust.git] / crates / syntax / src / ast.rs
index 19261686cb96431be767bbdd5c5af4683c60ed3d..5c1aed3cd4809fd0c39ce7a46dae2df5cebd5524 100644 (file)
@@ -5,6 +5,7 @@
 mod token_ext;
 mod node_ext;
 mod expr_ext;
+mod operators;
 pub mod edit;
 pub mod edit_in_place;
 pub mod make;
 };
 
 pub use self::{
-    expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp},
+    expr_ext::{ArrayExprKind, BlockModifier, CallableExpr, ElseBranch, LiteralKind},
     generated::{nodes::*, tokens::*},
     node_ext::{
         AttrKind, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind, SelfParamKind,
         SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind,
     },
-    token_ext::*,
-    traits::*,
+    operators::{ArithOp, BinaryOp, CmpOp, LogicOp, Ordering, RangeOp, UnaryOp},
+    token_ext::{CommentKind, CommentPlacement, CommentShape, IsString, QuoteOffsets, Radix},
+    traits::{
+        DocCommentIter, HasArgList, HasAttrs, HasDocComments, HasGenericParams, HasLoopBody,
+        HasModuleItem, HasName, HasTypeBounds, HasVisibility,
+    },
 };
 
 /// The main trait to go from untyped `SyntaxNode`  to a typed ast. The
@@ -47,6 +52,12 @@ fn clone_for_update(&self) -> Self
     {
         Self::cast(self.syntax().clone_for_update()).unwrap()
     }
+    fn clone_subtree(&self) -> Self
+    where
+        Self: Sized,
+    {
+        Self::cast(self.syntax().clone_subtree()).unwrap()
+    }
 }
 
 /// Like `AstNode`, but wraps tokens rather than interior nodes.
@@ -104,7 +115,7 @@ pub(super) fn token(parent: &SyntaxNode, kind: SyntaxKind) -> Option<SyntaxToken
 
 #[test]
 fn assert_ast_is_object_safe() {
-    fn _f(_: &dyn AstNode, _: &dyn NameOwner) {}
+    fn _f(_: &dyn AstNode, _: &dyn HasName) {}
 }
 
 #[test]
@@ -118,7 +129,7 @@ mod foo {}
     .ok()
     .unwrap();
     let module = file.syntax().descendants().find_map(Module::cast).unwrap();
-    assert!(module.doc_comment_text().is_none());
+    assert!(module.doc_comments().doc_comment_text().is_none());
 }
 
 #[test]
@@ -133,7 +144,7 @@ mod foo {}
     .ok()
     .unwrap();
     let module = file.syntax().descendants().find_map(Module::cast).unwrap();
-    assert_eq!("doc", module.doc_comment_text().unwrap());
+    assert_eq!(" doc", module.doc_comments().doc_comment_text().unwrap());
 }
 
 #[test]
@@ -148,7 +159,7 @@ mod foo {}
     .ok()
     .unwrap();
     let module = file.syntax().descendants().find_map(Module::cast).unwrap();
-    assert!(module.doc_comment_text().is_none());
+    assert!(module.doc_comments().doc_comment_text().is_none());
 }
 
 #[test]
@@ -162,7 +173,7 @@ fn test_doc_comment_of_statics() {
     .ok()
     .unwrap();
     let st = file.syntax().descendants().find_map(Static::cast).unwrap();
-    assert_eq!("Number of levels", st.doc_comment_text().unwrap());
+    assert_eq!(" Number of levels", st.doc_comments().doc_comment_text().unwrap());
 }
 
 #[test]
@@ -181,7 +192,10 @@ mod foo {}
     .ok()
     .unwrap();
     let module = file.syntax().descendants().find_map(Module::cast).unwrap();
-    assert_eq!("doc1\n```\nfn foo() {\n    // ...\n}\n```", module.doc_comment_text().unwrap());
+    assert_eq!(
+        " doc1\n ```\n fn foo() {\n     // ...\n }\n ```",
+        module.doc_comments().doc_comment_text().unwrap()
+    );
 }
 
 #[test]
@@ -198,7 +212,7 @@ mod foo {}
     .ok()
     .unwrap();
     let module = file.syntax().descendants().find_map(Module::cast).unwrap();
-    assert_eq!("this\nis\nmod\nfoo", module.doc_comment_text().unwrap());
+    assert_eq!(" this\n is\n mod\n foo", module.doc_comments().doc_comment_text().unwrap());
 }
 
 #[test]
@@ -212,7 +226,7 @@ mod foo {}
     .ok()
     .unwrap();
     let module = file.syntax().descendants().find_map(Module::cast).unwrap();
-    assert_eq!("this is mod foo", module.doc_comment_text().unwrap());
+    assert_eq!(" this is mod foo", module.doc_comments().doc_comment_text().unwrap());
 }
 
 #[test]
@@ -226,7 +240,7 @@ mod foo {}
     .ok()
     .unwrap();
     let module = file.syntax().descendants().find_map(Module::cast).unwrap();
-    assert_eq!("this is mod foo ", module.doc_comment_text().unwrap());
+    assert_eq!(" this is mod foo ", module.doc_comments().doc_comment_text().unwrap());
 }
 
 #[test]
@@ -245,8 +259,8 @@ mod foo {}
     .unwrap();
     let module = file.syntax().descendants().find_map(Module::cast).unwrap();
     assert_eq!(
-        "        this\n        is\n        mod foo\n        ",
-        module.doc_comment_text().unwrap()
+        "\n        this\n        is\n        mod foo\n        ",
+        module.doc_comments().doc_comment_text().unwrap()
     );
 }
 
@@ -259,8 +273,8 @@ fn test_comments_preserve_trailing_whitespace() {
     .unwrap();
     let def = file.syntax().descendants().find_map(Struct::cast).unwrap();
     assert_eq!(
-        "Representation of a Realm.   \nIn the specification these are called Realm Records.",
-        def.doc_comment_text().unwrap()
+        " Representation of a Realm.   \n In the specification these are called Realm Records.",
+        def.doc_comments().doc_comment_text().unwrap()
     );
 }
 
@@ -276,7 +290,7 @@ mod foo {}
     .ok()
     .unwrap();
     let module = file.syntax().descendants().find_map(Module::cast).unwrap();
-    assert_eq!("doc comment", module.doc_comment_text().unwrap());
+    assert_eq!(" doc comment", module.doc_comments().doc_comment_text().unwrap());
 }
 
 #[test]