From ba8d6d1e4ea2590b31470171efc175b0301c5e1c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 2 Nov 2020 16:31:38 +0100 Subject: Remove more unreachable pubs --- crates/assists/src/utils/import_assets.rs | 6 ++--- crates/assists/src/utils/insert_use.rs | 4 +-- .../src/completions/postfix/format_like.rs | 6 ++--- crates/hir/src/code_model.rs | 14 ++++------ crates/hir/src/from_id.rs | 8 +++--- crates/hir/src/has_source.rs | 3 +-- crates/hir/src/lib.rs | 3 ++- crates/hir_def/src/body/diagnostics.rs | 4 +-- crates/hir_expand/src/test_db.rs | 2 +- crates/hir_ty/src/infer.rs | 2 +- crates/hir_ty/src/infer/unify.rs | 2 +- crates/hir_ty/src/traits/chalk.rs | 2 +- crates/hir_ty/src/traits/chalk/interner.rs | 30 +++++++++++----------- crates/hir_ty/src/traits/chalk/mapping.rs | 6 ++--- crates/ide/src/diagnostics/fixes.rs | 2 +- crates/ide/src/doc_links.rs | 9 +++---- crates/ide/src/file_structure.rs | 2 +- crates/ide/src/join_lines.rs | 2 +- crates/ide/src/lib.rs | 14 +++++----- crates/ide/src/markdown_remove.rs | 3 +-- crates/ide/src/matching_brace.rs | 2 +- crates/ide/src/references.rs | 8 ++---- crates/ide/src/syntax_highlighting.rs | 9 ++++--- crates/mbe/src/subtree_source.rs | 2 +- crates/project_model/src/cargo_workspace.rs | 4 +-- crates/project_model/src/sysroot.rs | 2 +- crates/rust-analyzer/src/bin/main.rs | 2 +- crates/rust-analyzer/src/cli/progress_report.rs | 16 ++++++------ crates/rust-analyzer/src/document.rs | 4 +-- crates/rust-analyzer/src/global_state.rs | 2 +- crates/rust-analyzer/src/semantic_tokens.rs | 10 ++++---- .../rust-analyzer/tests/rust-analyzer/support.rs | 28 ++++++++++---------- .../rust-analyzer/tests/rust-analyzer/testdir.rs | 8 +++--- crates/ssr/src/parsing.rs | 2 +- crates/vfs/src/vfs_path.rs | 4 +-- 35 files changed, 110 insertions(+), 117 deletions(-) (limited to 'crates') diff --git a/crates/assists/src/utils/import_assets.rs b/crates/assists/src/utils/import_assets.rs index 23db3a74b..f47edbb76 100644 --- a/crates/assists/src/utils/import_assets.rs +++ b/crates/assists/src/utils/import_assets.rs @@ -26,13 +26,13 @@ pub(crate) enum ImportCandidate { #[derive(Debug)] pub(crate) struct TraitImportCandidate { - pub ty: hir::Type, - pub name: ast::NameRef, + pub(crate) ty: hir::Type, + pub(crate) name: ast::NameRef, } #[derive(Debug)] pub(crate) struct PathImportCandidate { - pub name: ast::NameRef, + pub(crate) name: ast::NameRef, } #[derive(Debug)] diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs index 033fbcedc..a76bd5ebf 100644 --- a/crates/assists/src/utils/insert_use.rs +++ b/crates/assists/src/utils/insert_use.rs @@ -17,13 +17,13 @@ use syntax::{ use test_utils::mark; #[derive(Debug)] -pub enum ImportScope { +pub(crate) enum ImportScope { File(ast::SourceFile), Module(ast::ItemList), } impl ImportScope { - pub fn from(syntax: SyntaxNode) -> Option { + pub(crate) fn from(syntax: SyntaxNode) -> Option { if let Some(module) = ast::Module::cast(syntax.clone()) { module.item_list().map(ImportScope::Module) } else if let this @ Some(_) = ast::SourceFile::cast(syntax.clone()) { diff --git a/crates/completion/src/completions/postfix/format_like.rs b/crates/completion/src/completions/postfix/format_like.rs index f35114ed1..88ba86acb 100644 --- a/crates/completion/src/completions/postfix/format_like.rs +++ b/crates/completion/src/completions/postfix/format_like.rs @@ -88,7 +88,7 @@ enum State { } impl FormatStrParser { - pub fn new(input: String) -> Self { + pub(crate) fn new(input: String) -> Self { Self { input: input.into(), output: String::new(), @@ -98,7 +98,7 @@ impl FormatStrParser { } } - pub fn parse(&mut self) -> Result<(), ()> { + pub(crate) fn parse(&mut self) -> Result<(), ()> { let mut current_expr = String::new(); let mut placeholder_id = 1; @@ -194,7 +194,7 @@ impl FormatStrParser { Ok(()) } - pub fn into_suggestion(&self, macro_name: &str) -> String { + pub(crate) fn into_suggestion(&self, macro_name: &str) -> String { assert!(self.parsed, "Attempt to get a suggestion from not parsed expression"); let expressions_as_string = self.extracted_expressions.join(", "); diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 563145f92..30a5e4580 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -4,7 +4,6 @@ use std::{iter, sync::Arc}; use arrayvec::ArrayVec; use base_db::{CrateDisplayName, CrateId, Edition, FileId}; use either::Either; -use hir_def::find_path::PrefixKind; use hir_def::{ adt::ReprKind, adt::StructKind, @@ -12,16 +11,18 @@ use hir_def::{ builtin_type::BuiltinType, expr::{BindingAnnotation, Pat, PatId}, import_map, + item_tree::ItemTreeNode, lang_item::LangItemTarget, path::ModPath, per_ns::PerNs, resolver::{HasResolver, Resolver}, src::HasSource as _, type_ref::{Mutability, TypeRef}, - AdtId, AssocContainerId, AttrDefId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, - HasModule, ImplId, LocalEnumVariantId, LocalFieldId, LocalModuleId, Lookup, ModuleId, StaticId, - StructId, TraitId, TypeAliasId, TypeParamId, UnionId, + AdtId, AssocContainerId, AssocItemId, AssocItemLoc, AttrDefId, ConstId, DefWithBodyId, EnumId, + FunctionId, GenericDefId, HasModule, ImplId, LocalEnumVariantId, LocalFieldId, LocalModuleId, + Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, }; +use hir_def::{find_path::PrefixKind, item_scope::ItemInNs, visibility::Visibility}; use hir_expand::{ diagnostics::DiagnosticSink, name::{name, AsName}, @@ -275,11 +276,6 @@ impl ModuleDef { } } -pub use hir_def::{ - attr::Attrs, item_scope::ItemInNs, item_tree::ItemTreeNode, visibility::Visibility, - AssocItemId, AssocItemLoc, -}; - impl Module { pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module { Module { id: ModuleId { krate: krate.id, local_id: crate_module_id } } diff --git a/crates/hir/src/from_id.rs b/crates/hir/src/from_id.rs index 033f53ac2..265ef6d1f 100644 --- a/crates/hir/src/from_id.rs +++ b/crates/hir/src/from_id.rs @@ -4,13 +4,13 @@ //! are splitting the hir. use hir_def::{ - expr::PatId, AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, GenericDefId, - ModuleDefId, VariantId, + expr::PatId, item_scope::ItemInNs, AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, + GenericDefId, ModuleDefId, VariantId, }; use crate::{ - code_model::ItemInNs, Adt, AssocItem, DefWithBody, EnumVariant, Field, GenericDef, Local, - MacroDef, ModuleDef, VariantDef, + Adt, AssocItem, DefWithBody, EnumVariant, Field, GenericDef, Local, MacroDef, ModuleDef, + VariantDef, }; macro_rules! from_id { diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index 3bad2338a..c77494152 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs @@ -6,6 +6,7 @@ use hir_def::{ src::{HasChildSource, HasSource as _}, Lookup, VariantId, }; +use hir_expand::InFile; use syntax::ast; use crate::{ @@ -13,8 +14,6 @@ use crate::{ Module, Static, Struct, Trait, TypeAlias, TypeParam, Union, }; -pub use hir_expand::InFile; - pub trait HasSource { type Ast; fn source(self, db: &dyn HirDatabase) -> InFile; diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 4094a76cb..0d184379f 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -36,7 +36,7 @@ pub use crate::{ Access, Adt, AsAssocItem, AssocItem, AssocItemContainer, Callable, CallableKind, Const, Crate, CrateDependency, DefWithBody, Enum, EnumVariant, Field, FieldSource, Function, GenericDef, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, - Struct, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, + Struct, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, }, has_source::HasSource, semantics::{original_range, PathResolution, Semantics, SemanticsScope}, @@ -53,6 +53,7 @@ pub use hir_def::{ nameres::ModuleSource, path::{ModPath, PathKind}, type_ref::{Mutability, TypeRef}, + visibility::Visibility, }; pub use hir_expand::{ name::known, name::AsName, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, diff --git a/crates/hir_def/src/body/diagnostics.rs b/crates/hir_def/src/body/diagnostics.rs index cfa47d189..e57bdc133 100644 --- a/crates/hir_def/src/body/diagnostics.rs +++ b/crates/hir_def/src/body/diagnostics.rs @@ -5,12 +5,12 @@ use hir_expand::diagnostics::DiagnosticSink; use crate::diagnostics::InactiveCode; #[derive(Debug, Eq, PartialEq)] -pub enum BodyDiagnostic { +pub(crate) enum BodyDiagnostic { InactiveCode(InactiveCode), } impl BodyDiagnostic { - pub fn add_to(&self, sink: &mut DiagnosticSink<'_>) { + pub(crate) fn add_to(&self, sink: &mut DiagnosticSink<'_>) { match self { BodyDiagnostic::InactiveCode(diag) => { sink.push(diag.clone()); diff --git a/crates/hir_expand/src/test_db.rs b/crates/hir_expand/src/test_db.rs index 86a5d867e..fca501e1f 100644 --- a/crates/hir_expand/src/test_db.rs +++ b/crates/hir_expand/src/test_db.rs @@ -14,7 +14,7 @@ use rustc_hash::FxHashSet; crate::db::AstDatabaseStorage )] #[derive(Default)] -pub struct TestDB { +pub(crate) struct TestDB { storage: salsa::Storage, events: Mutex>>, } diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index f4c1fa2f2..a14d67c06 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs @@ -94,7 +94,7 @@ enum BindingMode { } impl BindingMode { - pub fn convert(annotation: BindingAnnotation) -> BindingMode { + fn convert(annotation: BindingAnnotation) -> BindingMode { match annotation { BindingAnnotation::Unannotated | BindingAnnotation::Mutable => BindingMode::Move, BindingAnnotation::Ref => BindingMode::Ref(Mutability::Shared), diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 2406a7361..76984242e 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -35,7 +35,7 @@ where #[derive(Debug)] pub(super) struct Canonicalized { - pub value: Canonical, + pub(super) value: Canonical, free_vars: Vec, } diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index a6c247f87..55e2c3a3e 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs @@ -27,7 +27,7 @@ use mapping::{ TypeAliasAsValue, }; -pub use self::interner::*; +pub(crate) use self::interner::*; pub(super) mod tls; mod interner; diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs index f65873872..39569e690 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/traits/chalk/interner.rs @@ -10,21 +10,21 @@ use std::{fmt, sync::Arc}; #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct Interner; -pub type AssocTypeId = chalk_ir::AssocTypeId; -pub type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum; -pub type ForeignDefId = chalk_ir::ForeignDefId; -pub type TraitId = chalk_ir::TraitId; -pub type TraitDatum = chalk_solve::rust_ir::TraitDatum; -pub type AdtId = chalk_ir::AdtId; -pub type StructDatum = chalk_solve::rust_ir::AdtDatum; -pub type ImplId = chalk_ir::ImplId; -pub type ImplDatum = chalk_solve::rust_ir::ImplDatum; -pub type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId; -pub type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue; -pub type FnDefId = chalk_ir::FnDefId; -pub type FnDefDatum = chalk_solve::rust_ir::FnDefDatum; -pub type OpaqueTyId = chalk_ir::OpaqueTyId; -pub type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum; +pub(crate) type AssocTypeId = chalk_ir::AssocTypeId; +pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum; +pub(crate) type ForeignDefId = chalk_ir::ForeignDefId; +pub(crate) type TraitId = chalk_ir::TraitId; +pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum; +pub(crate) type AdtId = chalk_ir::AdtId; +pub(crate) type StructDatum = chalk_solve::rust_ir::AdtDatum; +pub(crate) type ImplId = chalk_ir::ImplId; +pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum; +pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId; +pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue; +pub(crate) type FnDefId = chalk_ir::FnDefId; +pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum; +pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId; +pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum; impl chalk_ir::interner::Interner for Interner { type InternedType = Arc>; diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 58c337b40..86cbc4c7e 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -464,7 +464,7 @@ impl ToChalk for CallableDefId { } } -pub struct TypeAliasAsAssocType(pub TypeAliasId); +pub(crate) struct TypeAliasAsAssocType(pub(crate) TypeAliasId); impl ToChalk for TypeAliasAsAssocType { type Chalk = AssocTypeId; @@ -478,7 +478,7 @@ impl ToChalk for TypeAliasAsAssocType { } } -pub struct TypeAliasAsForeignType(pub TypeAliasId); +pub(crate) struct TypeAliasAsForeignType(pub(crate) TypeAliasId); impl ToChalk for TypeAliasAsForeignType { type Chalk = ForeignDefId; @@ -492,7 +492,7 @@ impl ToChalk for TypeAliasAsForeignType { } } -pub struct TypeAliasAsValue(pub TypeAliasId); +pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); impl ToChalk for TypeAliasAsValue { type Chalk = AssociatedTyValueId; diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs index 0c950003e..02e17ba43 100644 --- a/crates/ide/src/diagnostics/fixes.rs +++ b/crates/ide/src/diagnostics/fixes.rs @@ -25,7 +25,7 @@ use crate::{diagnostics::Fix, references::rename::rename_with_semantics, FilePos /// A [Diagnostic] that potentially has a fix available. /// /// [Diagnostic]: hir::diagnostics::Diagnostic -pub trait DiagnosticWithFix: Diagnostic { +pub(crate) trait DiagnosticWithFix: Diagnostic { fn fix(&self, sema: &Semantics) -> Option; } diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 250f10f9f..10263537a 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -1,7 +1,6 @@ //! Resolves and rewrites links in markdown documentation. -use std::convert::TryFrom; -use std::iter::once; +use std::{convert::TryFrom, iter::once}; use itertools::Itertools; use pulldown_cmark::{BrokenLink, CowStr, Event, InlineStr, LinkType, Options, Parser, Tag}; @@ -21,10 +20,10 @@ use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, use crate::{FilePosition, Semantics}; -pub type DocumentationLink = String; +pub(crate) type DocumentationLink = String; /// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs) -pub fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String { +pub(crate) fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String { let mut cb = |link: BrokenLink| { Some(( /*url*/ link.reference.to_owned().into(), @@ -63,7 +62,7 @@ pub fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) } /// Remove all links in markdown documentation. -pub fn remove_links(markdown: &str) -> String { +pub(crate) fn remove_links(markdown: &str) -> String { let mut drop_link = false; let mut opts = Options::empty(); diff --git a/crates/ide/src/file_structure.rs b/crates/ide/src/file_structure.rs index 6168fb837..415795e8c 100644 --- a/crates/ide/src/file_structure.rs +++ b/crates/ide/src/file_structure.rs @@ -27,7 +27,7 @@ pub struct StructureNode { // // | VS Code | kbd:[Ctrl+Shift+O] // |=== -pub fn file_structure(file: &SourceFile) -> Vec { +pub(crate) fn file_structure(file: &SourceFile) -> Vec { let mut res = Vec::new(); let mut stack = Vec::new(); diff --git a/crates/ide/src/join_lines.rs b/crates/ide/src/join_lines.rs index e37702acd..b5a6f66fd 100644 --- a/crates/ide/src/join_lines.rs +++ b/crates/ide/src/join_lines.rs @@ -18,7 +18,7 @@ use text_edit::{TextEdit, TextEditBuilder}; // // | VS Code | **Rust Analyzer: Join lines** // |=== -pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit { +pub(crate) fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit { let range = if range.is_empty() { let syntax = file.syntax(); let text = syntax.text().slice(range.start()..); diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 4bc733b70..6288f7ea7 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -72,18 +72,20 @@ pub use crate::{ inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, markup::Markup, prime_caches::PrimeCachesProgress, - references::{ - Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult, RenameError, - }, + references::{rename::RenameError, Declaration, ReferenceSearchResult}, runnables::{Runnable, RunnableKind, TestId}, syntax_highlighting::{ - Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, + tags::{Highlight, HighlightModifier, HighlightModifiers, HighlightTag}, + HighlightedRange, }, }; pub use completion::{ CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, }; -pub use ide_db::call_info::CallInfo; +pub use ide_db::{ + call_info::CallInfo, + search::{Reference, ReferenceAccess, ReferenceKind}, +}; pub use assists::{ utils::MergeBehaviour, Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist, @@ -503,7 +505,7 @@ impl Analysis { position: FilePosition, new_name: &str, ) -> Cancelable, RenameError>> { - self.with_db(|db| references::rename(db, position, new_name)) + self.with_db(|db| references::rename::rename(db, position, new_name)) } pub fn structural_search_replace( diff --git a/crates/ide/src/markdown_remove.rs b/crates/ide/src/markdown_remove.rs index 02ad39dfb..3ec5c629e 100644 --- a/crates/ide/src/markdown_remove.rs +++ b/crates/ide/src/markdown_remove.rs @@ -1,11 +1,10 @@ //! Removes markdown from strings. - use pulldown_cmark::{Event, Parser, Tag}; /// Removes all markdown, keeping the text and code blocks /// /// Currently limited in styling, i.e. no ascii tables or lists -pub fn remove_markdown(markdown: &str) -> String { +pub(crate) fn remove_markdown(markdown: &str) -> String { let mut out = String::new(); let parser = Parser::new(markdown); diff --git a/crates/ide/src/matching_brace.rs b/crates/ide/src/matching_brace.rs index cb6abb0db..d70248afe 100644 --- a/crates/ide/src/matching_brace.rs +++ b/crates/ide/src/matching_brace.rs @@ -15,7 +15,7 @@ use test_utils::mark; // // | VS Code | **Rust Analyzer: Find matching brace** // |=== -pub fn matching_brace(file: &SourceFile, offset: TextSize) -> Option { +pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option { const BRACES: &[SyntaxKind] = &[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>], T![|], T![|]]; let (brace_token, brace_idx) = file diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index a517081d5..e05465b32 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -14,7 +14,8 @@ pub(crate) mod rename; use hir::Semantics; use ide_db::{ defs::{Definition, NameClass, NameRefClass}, - search::SearchScope, + search::Reference, + search::{ReferenceAccess, ReferenceKind, SearchScope}, RootDatabase, }; use syntax::{ @@ -25,11 +26,6 @@ use syntax::{ use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeInfo}; -pub(crate) use self::rename::rename; -pub use self::rename::RenameError; - -pub use ide_db::search::{Reference, ReferenceAccess, ReferenceKind}; - #[derive(Debug, Clone)] pub struct ReferenceSearchResult { declaration: Declaration, diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 624a63075..efcc8ecfe 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -2,7 +2,7 @@ mod format; mod html; mod injection; mod macro_rules; -mod tags; +pub(crate) mod tags; #[cfg(test)] mod tests; @@ -20,12 +20,13 @@ use syntax::{ }; use crate::{ - syntax_highlighting::{format::FormatStringHighlighter, macro_rules::MacroRulesHighlighter}, - FileId, + syntax_highlighting::{ + format::FormatStringHighlighter, macro_rules::MacroRulesHighlighter, tags::Highlight, + }, + FileId, HighlightModifier, HighlightTag, }; pub(crate) use html::highlight_as_html; -pub use tags::{Highlight, HighlightModifier, HighlightModifiers, HighlightTag}; #[derive(Debug, Clone)] pub struct HighlightedRange { diff --git a/crates/mbe/src/subtree_source.rs b/crates/mbe/src/subtree_source.rs index 38237cdcf..ccc56c479 100644 --- a/crates/mbe/src/subtree_source.rs +++ b/crates/mbe/src/subtree_source.rs @@ -21,7 +21,7 @@ pub(crate) struct SubtreeTokenSource<'a> { impl<'a> SubtreeTokenSource<'a> { // Helper function used in test #[cfg(test)] - pub fn text(&self) -> SmolStr { + pub(crate) fn text(&self) -> SmolStr { match *self.get(self.curr.1) { Some(ref tt) => tt.text.clone(), _ => SmolStr::new(""), diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs index e5c2d2b25..d5f6a4025 100644 --- a/crates/project_model/src/cargo_workspace.rs +++ b/crates/project_model/src/cargo_workspace.rs @@ -278,13 +278,13 @@ impl CargoWorkspace { } #[derive(Debug, Clone, Default)] -pub struct ExternResources { +pub(crate) struct ExternResources { out_dirs: FxHashMap, proc_dylib_paths: FxHashMap, cfgs: FxHashMap>, } -pub fn load_extern_resources( +pub(crate) fn load_extern_resources( cargo_toml: &Path, cargo_features: &CargoConfig, ) -> Result { diff --git a/crates/project_model/src/sysroot.rs b/crates/project_model/src/sysroot.rs index f6e883ad1..3fe494729 100644 --- a/crates/project_model/src/sysroot.rs +++ b/crates/project_model/src/sysroot.rs @@ -17,7 +17,7 @@ pub struct Sysroot { crates: Arena, } -pub type SysrootCrate = Idx; +pub(crate) type SysrootCrate = Idx; #[derive(Debug, Clone, Eq, PartialEq)] pub struct SysrootCrateData { diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 4175e569e..21fba8302 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -81,7 +81,7 @@ mod tracing_setup { use tracing_subscriber::Registry; use tracing_tree::HierarchicalLayer; - pub fn setup_tracing() -> super::Result<()> { + pub(crate) fn setup_tracing() -> super::Result<()> { let filter = EnvFilter::from_env("CHALK_DEBUG"); let layer = HierarchicalLayer::default() .with_indent_lines(true) diff --git a/crates/rust-analyzer/src/cli/progress_report.rs b/crates/rust-analyzer/src/cli/progress_report.rs index 31867a1e9..bdbe565e6 100644 --- a/crates/rust-analyzer/src/cli/progress_report.rs +++ b/crates/rust-analyzer/src/cli/progress_report.rs @@ -4,7 +4,7 @@ use std::io::Write; /// A Simple ASCII Progress Bar -pub struct ProgressReport { +pub(crate) struct ProgressReport { curr: f32, text: String, hidden: bool, @@ -15,7 +15,7 @@ pub struct ProgressReport { } impl ProgressReport { - pub fn new(len: u64) -> ProgressReport { + pub(crate) fn new(len: u64) -> ProgressReport { ProgressReport { curr: 0.0, text: String::new(), @@ -26,7 +26,7 @@ impl ProgressReport { } } - pub fn hidden() -> ProgressReport { + pub(crate) fn hidden() -> ProgressReport { ProgressReport { curr: 0.0, text: String::new(), @@ -37,18 +37,18 @@ impl ProgressReport { } } - pub fn set_message(&mut self, msg: &str) { + pub(crate) fn set_message(&mut self, msg: &str) { self.msg = msg.to_string(); self.tick(); } - pub fn println>(&mut self, msg: I) { + pub(crate) fn println>(&mut self, msg: I) { self.clear(); println!("{}", msg.into()); self.tick(); } - pub fn inc(&mut self, delta: u64) { + pub(crate) fn inc(&mut self, delta: u64) { self.pos += delta; if self.len == 0 { self.set_value(0.0) @@ -58,11 +58,11 @@ impl ProgressReport { self.tick(); } - pub fn finish_and_clear(&mut self) { + pub(crate) fn finish_and_clear(&mut self) { self.clear(); } - pub fn tick(&mut self) { + pub(crate) fn tick(&mut self) { if self.hidden { return; } diff --git a/crates/rust-analyzer/src/document.rs b/crates/rust-analyzer/src/document.rs index e882c9865..04c7ee150 100644 --- a/crates/rust-analyzer/src/document.rs +++ b/crates/rust-analyzer/src/document.rs @@ -6,11 +6,11 @@ /// client notifications. #[derive(Debug, Clone)] pub(crate) struct DocumentData { - pub version: Option, + pub(crate) version: Option, } impl DocumentData { - pub fn new(version: i64) -> Self { + pub(crate) fn new(version: i64) -> Self { DocumentData { version: Some(version) } } } diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 673a2eebc..63c70a09d 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -87,7 +87,7 @@ pub(crate) struct GlobalStateSnapshot { pub(crate) check_fixes: CheckFixes, pub(crate) latest_requests: Arc>, mem_docs: FxHashMap, - pub semantic_tokens_cache: Arc>>, + pub(crate) semantic_tokens_cache: Arc>>, vfs: Arc)>>, pub(crate) workspaces: Arc>, } diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs index 7df28c9dd..e7991fd28 100644 --- a/crates/rust-analyzer/src/semantic_tokens.rs +++ b/crates/rust-analyzer/src/semantic_tokens.rs @@ -101,12 +101,12 @@ pub(crate) struct SemanticTokensBuilder { } impl SemanticTokensBuilder { - pub fn new(id: String) -> Self { + pub(crate) fn new(id: String) -> Self { SemanticTokensBuilder { id, prev_line: 0, prev_char: 0, data: Default::default() } } /// Push a new token onto the builder - pub fn push(&mut self, range: Range, token_index: u32, modifier_bitset: u32) { + pub(crate) fn push(&mut self, range: Range, token_index: u32, modifier_bitset: u32) { let mut push_line = range.start.line as u32; let mut push_char = range.start.character as u32; @@ -134,12 +134,12 @@ impl SemanticTokensBuilder { self.prev_char = range.start.character as u32; } - pub fn build(self) -> SemanticTokens { + pub(crate) fn build(self) -> SemanticTokens { SemanticTokens { result_id: Some(self.id), data: self.data } } } -pub fn diff_tokens(old: &[SemanticToken], new: &[SemanticToken]) -> Vec { +pub(crate) fn diff_tokens(old: &[SemanticToken], new: &[SemanticToken]) -> Vec { let offset = new.iter().zip(old.iter()).take_while(|&(n, p)| n == p).count(); let (_, old) = old.split_at(offset); @@ -165,7 +165,7 @@ pub fn diff_tokens(old: &[SemanticToken], new: &[SemanticToken]) -> Vec u32 { +pub(crate) fn type_index(type_: SemanticTokenType) -> u32 { SUPPORTED_TYPES.iter().position(|it| *it == type_).unwrap() as u32 } diff --git a/crates/rust-analyzer/tests/rust-analyzer/support.rs b/crates/rust-analyzer/tests/rust-analyzer/support.rs index 784cbda79..fe9362bc0 100644 --- a/crates/rust-analyzer/tests/rust-analyzer/support.rs +++ b/crates/rust-analyzer/tests/rust-analyzer/support.rs @@ -24,7 +24,7 @@ use vfs::AbsPathBuf; use crate::testdir::TestDir; -pub struct Project<'a> { +pub(crate) struct Project<'a> { fixture: &'a str, with_sysroot: bool, tmp_dir: Option, @@ -33,11 +33,11 @@ pub struct Project<'a> { } impl<'a> Project<'a> { - pub fn with_fixture(fixture: &str) -> Project { + pub(crate) fn with_fixture(fixture: &str) -> Project { Project { fixture, tmp_dir: None, roots: vec![], with_sysroot: false, config: None } } - pub fn tmp_dir(mut self, tmp_dir: TestDir) -> Project<'a> { + pub(crate) fn tmp_dir(mut self, tmp_dir: TestDir) -> Project<'a> { self.tmp_dir = Some(tmp_dir); self } @@ -47,17 +47,17 @@ impl<'a> Project<'a> { self } - pub fn with_sysroot(mut self, sysroot: bool) -> Project<'a> { + pub(crate) fn with_sysroot(mut self, sysroot: bool) -> Project<'a> { self.with_sysroot = sysroot; self } - pub fn with_config(mut self, config: impl Fn(&mut Config) + 'static) -> Project<'a> { + pub(crate) fn with_config(mut self, config: impl Fn(&mut Config) + 'static) -> Project<'a> { self.config = Some(Box::new(config)); self } - pub fn server(self) -> Server { + pub(crate) fn server(self) -> Server { let tmp_dir = self.tmp_dir.unwrap_or_else(|| TestDir::new()); static INIT: Once = Once::new(); INIT.call_once(|| { @@ -103,11 +103,11 @@ impl<'a> Project<'a> { } } -pub fn project(fixture: &str) -> Server { +pub(crate) fn project(fixture: &str) -> Server { Project::with_fixture(fixture).server() } -pub struct Server { +pub(crate) struct Server { req_id: Cell, messages: RefCell>, _thread: jod_thread::JoinHandle<()>, @@ -128,12 +128,12 @@ impl Server { Server { req_id: Cell::new(1), dir, messages: Default::default(), client, _thread } } - pub fn doc_id(&self, rel_path: &str) -> TextDocumentIdentifier { + pub(crate) fn doc_id(&self, rel_path: &str) -> TextDocumentIdentifier { let path = self.dir.path().join(rel_path); TextDocumentIdentifier { uri: Url::from_file_path(path).unwrap() } } - pub fn notification(&self, params: N::Params) + pub(crate) fn notification(&self, params: N::Params) where N: lsp_types::notification::Notification, N::Params: Serialize, @@ -142,7 +142,7 @@ impl Server { self.send_notification(r) } - pub fn request(&self, params: R::Params, expected_resp: Value) + pub(crate) fn request(&self, params: R::Params, expected_resp: Value) where R: lsp_types::request::Request, R::Params: Serialize, @@ -159,7 +159,7 @@ impl Server { } } - pub fn send_request(&self, params: R::Params) -> Value + pub(crate) fn send_request(&self, params: R::Params) -> Value where R: lsp_types::request::Request, R::Params: Serialize, @@ -202,7 +202,7 @@ impl Server { } panic!("no response"); } - pub fn wait_until_workspace_is_loaded(self) -> Server { + pub(crate) fn wait_until_workspace_is_loaded(self) -> Server { self.wait_for_message_cond(1, &|msg: &Message| match msg { Message::Notification(n) if n.method == "$/progress" => { match n.clone().extract::("$/progress").unwrap() { @@ -241,7 +241,7 @@ impl Server { self.client.sender.send(Message::Notification(not)).unwrap(); } - pub fn path(&self) -> &Path { + pub(crate) fn path(&self) -> &Path { self.dir.path() } } diff --git a/crates/rust-analyzer/tests/rust-analyzer/testdir.rs b/crates/rust-analyzer/tests/rust-analyzer/testdir.rs index 7487e7429..36271344b 100644 --- a/crates/rust-analyzer/tests/rust-analyzer/testdir.rs +++ b/crates/rust-analyzer/tests/rust-analyzer/testdir.rs @@ -4,13 +4,13 @@ use std::{ sync::atomic::{AtomicUsize, Ordering}, }; -pub struct TestDir { +pub(crate) struct TestDir { path: PathBuf, keep: bool, } impl TestDir { - pub fn new() -> TestDir { + pub(crate) fn new() -> TestDir { let base = std::env::temp_dir().join("testdir"); let pid = std::process::id(); @@ -27,11 +27,11 @@ impl TestDir { panic!("Failed to create a temporary directory") } #[allow(unused)] - pub fn keep(mut self) -> TestDir { + pub(crate) fn keep(mut self) -> TestDir { self.keep = true; self } - pub fn path(&self) -> &Path { + pub(crate) fn path(&self) -> &Path { &self.path } } diff --git a/crates/ssr/src/parsing.rs b/crates/ssr/src/parsing.rs index 05b66dcd7..f3b084baf 100644 --- a/crates/ssr/src/parsing.rs +++ b/crates/ssr/src/parsing.rs @@ -42,7 +42,7 @@ pub(crate) struct Placeholder { /// Represents a `$var` in an SSR query. #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub(crate) struct Var(pub String); +pub(crate) struct Var(pub(crate) String); #[derive(Clone, Debug, PartialEq, Eq)] pub(crate) enum Constraint { diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs index 7a213fc3e..815697597 100644 --- a/crates/vfs/src/vfs_path.rs +++ b/crates/vfs/src/vfs_path.rs @@ -120,7 +120,7 @@ impl VfsPath { #[cfg(windows)] mod windows_paths { - pub trait Encode { + pub(crate) trait Encode { fn encode(&self, buf: &mut Vec); } @@ -149,7 +149,7 @@ mod windows_paths { } } - pub const SEP: &str = "\\"; + pub(crate) const SEP: &str = "\\"; const VERBATIM: &str = "\\\\?\\"; const UNC: &str = "UNC"; const DEVICE: &str = "\\\\.\\"; -- cgit v1.2.3