From b6101184537b1165cfdd5fc473e04ad4c5b7bffa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 2 Nov 2020 13:13:32 +0100 Subject: Deny unreachable-pub It's very useful when `pub` is equivalent to "this is crate's public API", let's enforce this! Ideally, we should enforce it for local `cargo test`, and only during CI, but that needs https://github.com/rust-lang/cargo/issues/5034. --- crates/syntax/src/ast.rs | 2 +- crates/syntax/src/ast/generated.rs | 6 +++--- crates/syntax/src/lib.rs | 11 +++++++---- crates/syntax/src/parsing.rs | 4 ++-- crates/syntax/src/parsing/text_token_source.rs | 2 +- crates/syntax/src/syntax_node.rs | 6 +----- 6 files changed, 15 insertions(+), 16 deletions(-) (limited to 'crates/syntax/src') diff --git a/crates/syntax/src/ast.rs b/crates/syntax/src/ast.rs index d536bb1e7..8a0e3d27b 100644 --- a/crates/syntax/src/ast.rs +++ b/crates/syntax/src/ast.rs @@ -17,7 +17,7 @@ use crate::{ pub use self::{ expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp}, - generated::*, + generated::{nodes::*, tokens::*}, node_ext::{ AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind, diff --git a/crates/syntax/src/ast/generated.rs b/crates/syntax/src/ast/generated.rs index 4a6f41ee7..843b43cf0 100644 --- a/crates/syntax/src/ast/generated.rs +++ b/crates/syntax/src/ast/generated.rs @@ -1,8 +1,8 @@ //! This file is actually hand-written, but the submodules are indeed generated. #[rustfmt::skip] -mod nodes; +pub(crate) mod nodes; #[rustfmt::skip] -mod tokens; +pub(crate) mod tokens; use crate::{ AstNode, @@ -10,7 +10,7 @@ use crate::{ SyntaxNode, }; -pub use {nodes::*, tokens::*}; +pub(crate) use nodes::*; // Stmt is the only nested enum, so it's easier to just hand-write it impl AstNode for Stmt { diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs index 849a1cdd6..e753b11bb 100644 --- a/crates/syntax/src/lib.rs +++ b/crates/syntax/src/lib.rs @@ -46,16 +46,19 @@ use text_edit::Indel; pub use crate::{ algo::InsertPosition, ast::{AstNode, AstToken}, - parsing::{lex_single_syntax_kind, lex_single_valid_syntax_kind, tokenize, Token}, + parsing::lexer::{lex_single_syntax_kind, lex_single_valid_syntax_kind, tokenize, Token}, ptr::{AstPtr, SyntaxNodePtr}, syntax_error::SyntaxError, syntax_node::{ - Direction, GreenNode, NodeOrToken, SyntaxElement, SyntaxElementChildren, SyntaxNode, - SyntaxNodeChildren, SyntaxToken, SyntaxTreeBuilder, + SyntaxElement, SyntaxElementChildren, SyntaxNode, SyntaxNodeChildren, SyntaxToken, + SyntaxTreeBuilder, }, }; pub use parser::{SyntaxKind, T}; -pub use rowan::{SmolStr, SyntaxText, TextRange, TextSize, TokenAtOffset, WalkEvent}; +pub use rowan::{ + Direction, GreenNode, NodeOrToken, SmolStr, SyntaxText, TextRange, TextSize, TokenAtOffset, + WalkEvent, +}; /// `Parse` is the result of the parsing: a syntax tree and a collection of /// errors. diff --git a/crates/syntax/src/parsing.rs b/crates/syntax/src/parsing.rs index 68a39eb21..333bde54a 100644 --- a/crates/syntax/src/parsing.rs +++ b/crates/syntax/src/parsing.rs @@ -1,7 +1,7 @@ //! Lexing, bridging to parser (which does the actual parsing) and //! incremental reparsing. -mod lexer; +pub(crate) mod lexer; mod text_token_source; mod text_tree_sink; mod reparsing; @@ -10,7 +10,7 @@ use crate::{syntax_node::GreenNode, AstNode, SyntaxError, SyntaxNode}; use text_token_source::TextTokenSource; use text_tree_sink::TextTreeSink; -pub use lexer::*; +pub(crate) use lexer::*; pub(crate) use self::reparsing::incremental_reparse; use parser::SyntaxKind; diff --git a/crates/syntax/src/parsing/text_token_source.rs b/crates/syntax/src/parsing/text_token_source.rs index df866dc2b..0614194a5 100644 --- a/crates/syntax/src/parsing/text_token_source.rs +++ b/crates/syntax/src/parsing/text_token_source.rs @@ -65,7 +65,7 @@ fn mk_token(pos: usize, token_offset_pairs: &[(Token, TextSize)]) -> parser::Tok impl<'t> TextTokenSource<'t> { /// Generate input from tokens(expect comment and whitespace). - pub fn new(text: &'t str, raw_tokens: &'t [Token]) -> TextTokenSource<'t> { + pub(crate) fn new(text: &'t str, raw_tokens: &'t [Token]) -> TextTokenSource<'t> { let token_offset_pairs: Vec<_> = raw_tokens .iter() .filter_map({ diff --git a/crates/syntax/src/syntax_node.rs b/crates/syntax/src/syntax_node.rs index b2abcbfbb..cc30138fa 100644 --- a/crates/syntax/src/syntax_node.rs +++ b/crates/syntax/src/syntax_node.rs @@ -10,9 +10,7 @@ use rowan::{GreenNodeBuilder, Language}; use crate::{Parse, SmolStr, SyntaxError, SyntaxKind, TextSize}; -pub use rowan::GreenNode; - -pub(crate) use rowan::GreenToken; +pub(crate) use rowan::{GreenNode, GreenToken, NodeOrToken}; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum RustLanguage {} @@ -34,8 +32,6 @@ pub type SyntaxElement = rowan::SyntaxElement; pub type SyntaxNodeChildren = rowan::SyntaxNodeChildren; pub type SyntaxElementChildren = rowan::SyntaxElementChildren; -pub use rowan::{Direction, NodeOrToken}; - #[derive(Default)] pub struct SyntaxTreeBuilder { errors: Vec, -- cgit v1.2.3