diff --git a/components/clarity-jupyter-kernel/src/jupyter/install.rs b/components/clarity-jupyter-kernel/src/jupyter/install.rs index e83046329..ef1ba4f09 100644 --- a/components/clarity-jupyter-kernel/src/jupyter/install.rs +++ b/components/clarity-jupyter-kernel/src/jupyter/install.rs @@ -1,7 +1,7 @@ use dirs; use failure::Error; use std::io::Write; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::{env, fs}; pub fn install() -> Result<(), Error> { @@ -24,7 +24,7 @@ pub fn install() -> Result<(), Error> { Ok(()) } -pub fn install_resource(dir: &PathBuf, filename: &str, bytes: &'static [u8]) -> Result<(), Error> { +pub fn install_resource(dir: &Path, filename: &str, bytes: &'static [u8]) -> Result<(), Error> { let res_path = dir.join(filename); println!("Writing {}", res_path.to_string_lossy()); let mut file = fs::File::create(res_path)?; diff --git a/components/clarity-repl/src/analysis/cache/bindings.rs b/components/clarity-repl/src/analysis/cache/bindings.rs index 136e5f00d..da81b9270 100644 --- a/components/clarity-repl/src/analysis/cache/bindings.rs +++ b/components/clarity-repl/src/analysis/cache/bindings.rs @@ -48,7 +48,7 @@ pub type BindingMap<'a> = HashMap, BindingData<'a>>; pub struct BindingMapBuilder<'a> { clarity_version: ClarityVersion, - annotations: &'a Vec, + annotations: &'a [Annotation], /// Names of all `let` bindings and function args currently in scope active_bindings: HashMap<&'a ClarityName, BindingData<'a>>, /// Variables which went out of scope without being referenced @@ -59,7 +59,7 @@ impl<'a> BindingMapBuilder<'a> { pub fn build( clarity_version: ClarityVersion, contract_analysis: &'a ContractAnalysis, - annotations: &'a Vec, + annotations: &'a [Annotation], ) -> BindingMap<'a> { let mut builder = Self { clarity_version, diff --git a/components/clarity-repl/src/analysis/cache/constants.rs b/components/clarity-repl/src/analysis/cache/constants.rs index 11913cf5e..490bc102b 100644 --- a/components/clarity-repl/src/analysis/cache/constants.rs +++ b/components/clarity-repl/src/analysis/cache/constants.rs @@ -30,7 +30,7 @@ pub type ConstantMap<'a> = IndexMap<&'a ClarityName, ConstantData<'a>>; pub struct ConstantMapBuilder<'a> { clarity_version: ClarityVersion, - annotations: &'a Vec, + annotations: &'a [Annotation], map: ConstantMap<'a>, } @@ -38,7 +38,7 @@ impl<'a> ConstantMapBuilder<'a> { pub fn build( clarity_version: ClarityVersion, contract_analysis: &'a ContractAnalysis, - annotations: &'a Vec, + annotations: &'a [Annotation], ) -> ConstantMap<'a> { let mut builder = Self { clarity_version, diff --git a/components/clarity-repl/src/analysis/cache/data_vars.rs b/components/clarity-repl/src/analysis/cache/data_vars.rs index aaf79a364..86c68687b 100644 --- a/components/clarity-repl/src/analysis/cache/data_vars.rs +++ b/components/clarity-repl/src/analysis/cache/data_vars.rs @@ -33,7 +33,7 @@ pub type DataVarMap<'a> = IndexMap<&'a ClarityName, DataVarData<'a>>; pub struct DataVarMapBuilder<'a> { clarity_version: ClarityVersion, - annotations: &'a Vec, + annotations: &'a [Annotation], map: DataVarMap<'a>, } @@ -41,7 +41,7 @@ impl<'a> DataVarMapBuilder<'a> { pub fn build( clarity_version: ClarityVersion, contract_analysis: &'a ContractAnalysis, - annotations: &'a Vec, + annotations: &'a [Annotation], ) -> DataVarMap<'a> { let mut builder = Self { clarity_version, diff --git a/components/clarity-repl/src/analysis/cache/functions.rs b/components/clarity-repl/src/analysis/cache/functions.rs index c8d2cc6eb..c4d7eaf21 100644 --- a/components/clarity-repl/src/analysis/cache/functions.rs +++ b/components/clarity-repl/src/analysis/cache/functions.rs @@ -50,7 +50,7 @@ pub struct FnMaps<'a> { pub struct FnMapBuilder<'a> { clarity_version: ClarityVersion, - annotations: &'a Vec, + annotations: &'a [Annotation], public: FnMap<'a>, read_only: FnMap<'a>, private: PrivateFnMap<'a>, @@ -60,7 +60,7 @@ impl<'a> FnMapBuilder<'a> { pub fn build( clarity_version: ClarityVersion, contract_analysis: &'a ContractAnalysis, - annotations: &'a Vec, + annotations: &'a [Annotation], ) -> FnMaps<'a> { let mut builder = Self { clarity_version, diff --git a/components/clarity-repl/src/analysis/cache/maps.rs b/components/clarity-repl/src/analysis/cache/maps.rs index 9c6e4c2a0..4cb877c40 100644 --- a/components/clarity-repl/src/analysis/cache/maps.rs +++ b/components/clarity-repl/src/analysis/cache/maps.rs @@ -52,7 +52,7 @@ pub type MapDefinitionMap<'a> = IndexMap<&'a ClarityName, MapData<'a>>; pub struct MapDefinitionMapBuilder<'a> { clarity_version: ClarityVersion, - annotations: &'a Vec, + annotations: &'a [Annotation], map: MapDefinitionMap<'a>, } @@ -60,7 +60,7 @@ impl<'a> MapDefinitionMapBuilder<'a> { pub fn build( clarity_version: ClarityVersion, contract_analysis: &'a ContractAnalysis, - annotations: &'a Vec, + annotations: &'a [Annotation], ) -> MapDefinitionMap<'a> { let mut builder = Self { clarity_version, diff --git a/components/clarity-repl/src/analysis/cache/mod.rs b/components/clarity-repl/src/analysis/cache/mod.rs index 52a061bf9..2f76de745 100644 --- a/components/clarity-repl/src/analysis/cache/mod.rs +++ b/components/clarity-repl/src/analysis/cache/mod.rs @@ -24,7 +24,7 @@ use crate::analysis::annotation::Annotation; /// All fields are lazy-initialized, and only created if used in at least one pass pub struct AnalysisCache<'a> { pub contract_analysis: &'a ContractAnalysis, - pub annotations: &'a Vec, + pub annotations: &'a [Annotation], constants: Option>, bindings: Option>, @@ -36,7 +36,7 @@ pub struct AnalysisCache<'a> { } impl<'a> AnalysisCache<'a> { - pub fn new(contract_analysis: &'a ContractAnalysis, annotations: &'a Vec) -> Self { + pub fn new(contract_analysis: &'a ContractAnalysis, annotations: &'a [Annotation]) -> Self { Self { contract_analysis, annotations, diff --git a/components/clarity-repl/src/analysis/cache/tokens.rs b/components/clarity-repl/src/analysis/cache/tokens.rs index f509668fd..e1749bf99 100644 --- a/components/clarity-repl/src/analysis/cache/tokens.rs +++ b/components/clarity-repl/src/analysis/cache/tokens.rs @@ -35,7 +35,7 @@ pub struct TokenMaps<'a> { pub struct TokenMapBuilder<'a> { clarity_version: ClarityVersion, - annotations: &'a Vec, + annotations: &'a [Annotation], pub fts: TokenMap<'a>, pub nfts: TokenMap<'a>, } @@ -44,7 +44,7 @@ impl<'a> TokenMapBuilder<'a> { pub fn build( clarity_version: ClarityVersion, contract_analysis: &'a ContractAnalysis, - annotations: &'a Vec, + annotations: &'a [Annotation], ) -> TokenMaps<'a> { let mut builder = Self { clarity_version, diff --git a/components/clarity-repl/src/analysis/cache/traits.rs b/components/clarity-repl/src/analysis/cache/traits.rs index 1140c8b86..b4d2e4ed7 100644 --- a/components/clarity-repl/src/analysis/cache/traits.rs +++ b/components/clarity-repl/src/analysis/cache/traits.rs @@ -62,7 +62,7 @@ pub struct TraitMaps<'a> { pub struct TraitMapBuilder<'a> { clarity_version: ClarityVersion, - annotations: &'a Vec, + annotations: &'a [Annotation], declared: DeclaredTraitMap<'a>, imported: ImportedTraitMap<'a>, } @@ -71,7 +71,7 @@ impl<'a> TraitMapBuilder<'a> { pub fn build( clarity_version: ClarityVersion, contract_analysis: &'a ContractAnalysis, - annotations: &'a Vec, + annotations: &'a [Annotation], ) -> TraitMaps<'a> { let mut builder = Self { clarity_version, diff --git a/components/clarity-repl/src/analysis/check_checker/mod.rs b/components/clarity-repl/src/analysis/check_checker/mod.rs index f70004de4..1477757e8 100644 --- a/components/clarity-repl/src/analysis/check_checker/mod.rs +++ b/components/clarity-repl/src/analysis/check_checker/mod.rs @@ -113,7 +113,7 @@ pub struct CheckChecker<'a> { tainted_nodes: HashMap, TaintedNode<'a>>, /// Map expression ID to a generated diagnostic diagnostics: HashMap>, - annotations: &'a Vec, + annotations: &'a [Annotation], active_annotation: Option, /// Record all public functions defined public_funcs: HashSet<&'a ClarityName>, @@ -129,7 +129,7 @@ pub struct CheckChecker<'a> { impl<'a> CheckChecker<'a> { fn new( clarity_version: ClarityVersion, - annotations: &'a Vec, + annotations: &'a [Annotation], level: Level, settings: Settings, ) -> CheckChecker<'a> { diff --git a/components/clarity-repl/src/analysis/lints/at_block.rs b/components/clarity-repl/src/analysis/lints/at_block.rs index 2b7b1bd40..8b588c47c 100644 --- a/components/clarity-repl/src/analysis/lints/at_block.rs +++ b/components/clarity-repl/src/analysis/lints/at_block.rs @@ -15,17 +15,13 @@ use crate::analysis::{self, AnalysisPass, AnalysisResult, LintName}; pub struct AtBlock<'a> { clarity_version: ClarityVersion, diagnostics: Vec, - annotations: &'a Vec, + annotations: &'a [Annotation], level: Level, active_annotation: Option, } impl<'a> AtBlock<'a> { - fn new( - clarity_version: ClarityVersion, - annotations: &'a Vec, - level: Level, - ) -> Self { + fn new(clarity_version: ClarityVersion, annotations: &'a [Annotation], level: Level) -> Self { Self { clarity_version, level, diff --git a/components/clarity-repl/src/analysis/lints/noop.rs b/components/clarity-repl/src/analysis/lints/noop.rs index 1e1b689cd..c8e8fd5fd 100644 --- a/components/clarity-repl/src/analysis/lints/noop.rs +++ b/components/clarity-repl/src/analysis/lints/noop.rs @@ -145,7 +145,7 @@ pub struct NoopChecker<'a> { clarity_version: ClarityVersion, _settings: NoopCheckerSettings, diagnostics: Vec, - annotations: &'a Vec, + annotations: &'a [Annotation], /// Clarity diagnostic level level: Level, active_annotation: Option, @@ -154,7 +154,7 @@ pub struct NoopChecker<'a> { impl<'a> NoopChecker<'a> { fn new( clarity_version: ClarityVersion, - annotations: &'a Vec, + annotations: &'a [Annotation], level: Level, settings: NoopCheckerSettings, ) -> NoopChecker<'a> { diff --git a/components/clarity-repl/src/analysis/lints/panic.rs b/components/clarity-repl/src/analysis/lints/panic.rs index 1bd49222f..c069e6ee7 100644 --- a/components/clarity-repl/src/analysis/lints/panic.rs +++ b/components/clarity-repl/src/analysis/lints/panic.rs @@ -17,17 +17,13 @@ use crate::analysis::{self, AnalysisPass, AnalysisResult, LintName}; pub struct PanicChecker<'a> { clarity_version: ClarityVersion, diagnostics: HashMap>, - annotations: &'a Vec, + annotations: &'a [Annotation], level: Level, active_annotation: Option, } impl<'a> PanicChecker<'a> { - fn new( - clarity_version: ClarityVersion, - annotations: &'a Vec, - level: Level, - ) -> Self { + fn new(clarity_version: ClarityVersion, annotations: &'a [Annotation], level: Level) -> Self { Self { clarity_version, level, diff --git a/components/clarity-repl/src/analysis/lints/unnecessary_as_max_len.rs b/components/clarity-repl/src/analysis/lints/unnecessary_as_max_len.rs index 4866069a6..5b265ddf5 100644 --- a/components/clarity-repl/src/analysis/lints/unnecessary_as_max_len.rs +++ b/components/clarity-repl/src/analysis/lints/unnecessary_as_max_len.rs @@ -18,7 +18,7 @@ use crate::analysis::{self, AnalysisPass, AnalysisResult, LintName}; pub struct UnnecessaryAsMaxLen<'a> { clarity_version: ClarityVersion, diagnostics: Vec, - annotations: &'a Vec, + annotations: &'a [Annotation], type_map: Option<&'a TypeMap>, level: Level, active_annotation: Option, @@ -27,7 +27,7 @@ pub struct UnnecessaryAsMaxLen<'a> { impl<'a> UnnecessaryAsMaxLen<'a> { fn new( clarity_version: ClarityVersion, - annotations: &'a Vec, + annotations: &'a [Annotation], type_map: Option<&'a TypeMap>, level: Level, ) -> Self { diff --git a/components/clarity-repl/src/analysis/lints/unnecessary_public.rs b/components/clarity-repl/src/analysis/lints/unnecessary_public.rs index 868adea99..e9c9bdfdf 100644 --- a/components/clarity-repl/src/analysis/lints/unnecessary_public.rs +++ b/components/clarity-repl/src/analysis/lints/unnecessary_public.rs @@ -30,7 +30,7 @@ use crate::analysis::{self, AnalysisPass, AnalysisResult, LintName}; pub struct UnnecessaryPublic<'a, 'b, 'c> { clarity_version: ClarityVersion, diagnostics: Vec, - annotations: &'a Vec, + annotations: &'a [Annotation], analysis_db: &'b mut AnalysisDatabase<'c>, epoch: StacksEpochId, level: Level, @@ -50,7 +50,7 @@ pub struct UnnecessaryPublic<'a, 'b, 'c> { impl<'a, 'b, 'c> UnnecessaryPublic<'a, 'b, 'c> { fn new( clarity_version: ClarityVersion, - annotations: &'a Vec, + annotations: &'a [Annotation], analysis_db: &'b mut AnalysisDatabase<'c>, epoch: StacksEpochId, level: Level, diff --git a/components/clarity-repl/src/analysis/mod.rs b/components/clarity-repl/src/analysis/mod.rs index e38b3ce2f..69544871c 100644 --- a/components/clarity-repl/src/analysis/mod.rs +++ b/components/clarity-repl/src/analysis/mod.rs @@ -294,7 +294,7 @@ impl From for Settings { pub fn run_analysis( contract_analysis: &mut ContractAnalysis, analysis_db: &mut AnalysisDatabase, - annotations: &Vec, + annotations: &[Annotation], settings: &Settings, ) -> Result, Vec> { let mut errors: Vec = vec![]; diff --git a/components/clarity-repl/src/repl/interpreter.rs b/components/clarity-repl/src/repl/interpreter.rs index 4cf4be789..863bd4939 100644 --- a/components/clarity-repl/src/repl/interpreter.rs +++ b/components/clarity-repl/src/repl/interpreter.rs @@ -283,7 +283,7 @@ impl ClarityInterpreter { &mut self, contract: &ClarityContract, contract_ast: &ContractAST, - annotations: &Vec, + annotations: &[Annotation], ) -> Result<(ContractAnalysis, Vec), Diagnostic> { let mut analysis_db = AnalysisDatabase::new(&mut self.clarity_datastore); diff --git a/components/observer/src/event_handler/http.rs b/components/observer/src/event_handler/http.rs index 0895c407e..f39540fc7 100644 --- a/components/observer/src/event_handler/http.rs +++ b/components/observer/src/event_handler/http.rs @@ -270,7 +270,7 @@ async fn handle_new_mempool_tx( let transactions = match raw_txs .iter() .map(|tx_data| { - indexer::stacks::get_tx_description(tx_data, &vec![]).map(|(tx_description, ..)| { + indexer::stacks::get_tx_description(tx_data, &[]).map(|(tx_description, ..)| { MempoolAdmissionData { tx_data: tx_data.clone(), tx_description, diff --git a/components/observer/src/indexer/bitcoin/mod.rs b/components/observer/src/indexer/bitcoin/mod.rs index dc18412d7..703f88e40 100644 --- a/components/observer/src/indexer/bitcoin/mod.rs +++ b/components/observer/src/indexer/bitcoin/mod.rs @@ -484,7 +484,7 @@ pub fn standardize_bitcoin_block( fn try_parse_stacks_operation( block_height: u64, - _inputs: &Vec, + _inputs: &[BitcoinTransactionInputFullBreakdown], outputs: &[BitcoinTransactionOutputFullBreakdown], pox_config: &PoxConfig, expected_magic_bytes: &[u8; 2], diff --git a/components/observer/src/indexer/stacks/mod.rs b/components/observer/src/indexer/stacks/mod.rs index 41f2d4060..444325f6f 100644 --- a/components/observer/src/indexer/stacks/mod.rs +++ b/components/observer/src/indexer/stacks/mod.rs @@ -1029,7 +1029,7 @@ pub fn get_value_description(raw_value: &str, ctx: &Context) -> String { pub fn get_tx_description( raw_tx: &str, - tx_events: &Vec<&NewEvent>, + tx_events: &[&NewEvent], ) -> Result< ( String, // Human readable transaction's description (contract-call, publish, ...) diff --git a/components/stacks-codec/src/codec.rs b/components/stacks-codec/src/codec.rs index d76cb40a3..4ac93d12c 100644 --- a/components/stacks-codec/src/codec.rs +++ b/components/stacks-codec/src/codec.rs @@ -1565,7 +1565,7 @@ impl std::str::FromStr for StacksString { type Err = String; fn from_str(s: &str) -> Result { - if !StacksString::is_valid_string(&String::from(s)) { + if !StacksString::is_valid_string(s) { return Err("Invalid string".to_string()); } Ok(StacksString(s.as_bytes().to_vec())) @@ -1601,11 +1601,11 @@ impl From for StacksString { impl StacksString { /// Is the given string a valid Clarity string? - pub fn is_valid_string(s: &String) -> bool { + pub fn is_valid_string(s: &str) -> bool { s.is_ascii() && StacksString::is_printable(s) } - pub fn is_printable(s: &String) -> bool { + pub fn is_printable(s: &str) -> bool { if !s.is_ascii() { return false; } @@ -1624,7 +1624,7 @@ impl StacksString { ClarityName::try_from(self.to_string()).is_ok() } - pub fn from_string(s: &String) -> Option { + pub fn from_string(s: &str) -> Option { if !StacksString::is_valid_string(s) { return None; } @@ -1634,7 +1634,7 @@ impl StacksString { #[test] fn test_display() { - let stxstr = StacksString::from_string(&"hello".to_string()).unwrap(); + let stxstr = StacksString::from_string("hello").unwrap(); println!("log: {stxstr:#?}"); println!("log: {:#?}", stxstr.to_string()); }