Skip to content

Commit

Permalink
Remove confusing default from token stream types
Browse files Browse the repository at this point in the history
commit-id:e6e81399
  • Loading branch information
maciektr committed Nov 21, 2024
1 parent 67935fe commit e687bf8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
23 changes: 4 additions & 19 deletions plugins/cairo-lang-macro/src/types/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::rc::Rc;
/// This is both input and part of an output of a procedural macro.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(try_from = "deserializer::TokenStream"))]
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TokenStream {
pub tokens: Vec<TokenTree>,
pub metadata: TokenStreamMetadata,
Expand Down Expand Up @@ -85,12 +85,6 @@ pub enum TokenTree {
Ident(Token),
}

impl Default for TokenTree {
fn default() -> Self {
Self::Ident(Default::default())
}
}

impl TokenTree {
/// Get the size hint for the [`TokenTree`].
/// This can be used to estimate size of a buffer needed for allocating this [`TokenTree`].
Expand All @@ -103,7 +97,7 @@ impl TokenTree {

/// A range of text offsets that form a span (like text selection).
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TextSpan {
pub start: usize,
pub end: usize,
Expand All @@ -113,7 +107,7 @@ pub struct TextSpan {
///
/// The most atomic item of Cairo code representation.
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Token {
pub content: InternedStr,
pub span: TextSpan,
Expand Down Expand Up @@ -157,15 +151,6 @@ impl InternedStr {
}
}

impl Default for InternedStr {
fn default() -> Self {
Self {
ptr: "" as *const str,
_bump: Rc::default(),
}
}
}

impl AsRef<str> for InternedStr {
fn as_ref(&self) -> &str {
self.deref()
Expand Down Expand Up @@ -202,7 +187,7 @@ impl Hash for InternedStr {
}

/// This wrapper de-allocates the underlying buffer on drop.
#[derive(Debug, Default)]
#[derive(Debug)]
struct BumpWrap(pub Bump);

impl Drop for BumpWrap {
Expand Down
6 changes: 3 additions & 3 deletions scarb/tests/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn expand_attribute() {
args: TokenStream::empty(),
item: TokenStream::new(vec![TokenTree::Ident(Token::new(
"fn some_test_fn(){}",
TextSpan::default(),
TextSpan::new(0, 0),
))]),
})
.unwrap();
Expand Down Expand Up @@ -125,7 +125,7 @@ fn expand_derive() {

let item = TokenStream::new(vec![TokenTree::Ident(Token::new(
"fn some_test_fn(){}",
TextSpan::default(),
TextSpan::new(0, 0),
))]);

let response = proc_macro_server
Expand Down Expand Up @@ -182,7 +182,7 @@ fn expand_inline() {
name: "replace_all_15_with_25".to_string(),
args: TokenStream::new(vec![TokenTree::Ident(Token::new(
"struct A { field: 15 , other_field: macro_call!(12)}",
TextSpan::default(),
TextSpan::new(0, 0),
))]),
})
.unwrap();
Expand Down
11 changes: 10 additions & 1 deletion utils/scarb-proc-macro-server-types/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ pub trait Method {
///
/// This struct encapsulates both the resulting token stream from macro expansion
/// and any diagnostic messages (e.g., errors or warnings) that were generated during processing.
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ProcMacroResult {
/// The resultant token stream produced after the macro expansion.
pub token_stream: TokenStream,
/// A list of diagnostics produced during the macro execution.
pub diagnostics: Vec<cairo_lang_macro::Diagnostic>,
}

impl Default for ProcMacroResult {
fn default() -> Self {
Self {
token_stream: TokenStream::empty(),
diagnostics: Vec::new(),
}
}
}

0 comments on commit e687bf8

Please sign in to comment.