Skip to content

Commit

Permalink
feat(deps): update to syn2 (#247)
Browse files Browse the repository at this point in the history
Fixes: #243
  • Loading branch information
jtroo authored Mar 30, 2023
1 parent 78fe18e commit a215720
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rust-version = "1.56.0"
exclude = ["images/", "tests/", "miette-derive/"]

[dependencies]
thiserror = "1.0.26"
thiserror = "1.0.40"
miette-derive = { path = "miette-derive", version = "=5.6.0" }
once_cell = "1.8.0"
unicode-width = "0.1.9"
Expand All @@ -35,7 +35,7 @@ futures = { version = "0.3", default-features = false }
indenter = "0.3.0"
rustversion = "1.0"
trybuild = { version = "1.0.19", features = ["diff"] }
syn = { version = "1.0", features = ["full"] }
syn = { version = "2.0", features = ["full"] }
regex = "1.5"
lazy_static = "1.4"

Expand Down
2 changes: 1 addition & 1 deletion miette-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = "1.0.45"
syn = "2.0.11"
4 changes: 2 additions & 2 deletions miette-derive/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl Diagnostic {
let input_attrs = input
.attrs
.iter()
.filter(|x| x.path.is_ident("diagnostic"))
.filter(|x| x.path().is_ident("diagnostic"))
.collect::<Vec<&syn::Attribute>>();
Ok(match input.data {
syn::Data::Struct(data_struct) => {
Expand All @@ -245,7 +245,7 @@ impl Diagnostic {
for var in variants {
let mut variant_attrs = input_attrs.clone();
variant_attrs
.extend(var.attrs.iter().filter(|x| x.path.is_ident("diagnostic")));
.extend(var.attrs.iter().filter(|x| x.path().is_ident("diagnostic")));
let args =
DiagnosticDefArgs::parse(&var.ident, &var.fields, &variant_attrs, true)?;
vars.push(DiagnosticDef {
Expand Down
2 changes: 1 addition & 1 deletion miette-derive/src/diagnostic_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl DiagnosticSource {
fn from_fields_vec(fields: Vec<&syn::Field>) -> syn::Result<Option<Self>> {
for (i, field) in fields.iter().enumerate() {
for attr in &field.attrs {
if attr.path.is_ident("diagnostic_source") {
if attr.path().is_ident("diagnostic_source") {
let diagnostic_source = if let Some(ident) = field.ident.clone() {
syn::Member::Named(ident)
} else {
Expand Down
6 changes: 3 additions & 3 deletions miette-derive/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,21 @@ pub fn parse_token_expr(input: ParseStream, mut begin_expr: bool) -> Result<Toke
let delimiter = parenthesized!(content in input);
let nested = parse_token_expr(&content, true)?;
let mut group = Group::new(Delimiter::Parenthesis, nested);
group.set_span(delimiter.span);
group.set_span(delimiter.span.join());
TokenTree::Group(group)
} else if input.peek(syn::token::Brace) {
let content;
let delimiter = braced!(content in input);
let nested = parse_token_expr(&content, true)?;
let mut group = Group::new(Delimiter::Brace, nested);
group.set_span(delimiter.span);
group.set_span(delimiter.span.join());
TokenTree::Group(group)
} else if input.peek(syn::token::Bracket) {
let content;
let delimiter = bracketed!(content in input);
let nested = parse_token_expr(&content, true)?;
let mut group = Group::new(Delimiter::Bracket, nested);
group.set_span(delimiter.span);
group.set_span(delimiter.span.join());
TokenTree::Group(group)
} else {
input.parse()?
Expand Down
2 changes: 1 addition & 1 deletion miette-derive/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Help {
fn from_fields_vec(fields: Vec<&syn::Field>) -> syn::Result<Option<Self>> {
for (i, field) in fields.iter().enumerate() {
for attr in &field.attrs {
if attr.path.is_ident("help") {
if attr.path().is_ident("help") {
let help = if let Some(ident) = field.ident.clone() {
syn::Member::Named(ident)
} else {
Expand Down
17 changes: 15 additions & 2 deletions miette-derive/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ struct LabelAttr {

impl Parse for LabelAttr {
fn parse(input: ParseStream) -> syn::Result<Self> {
// Skip a token.
// This should receive one of:
// - label = "..."
// - label("...")
let _ = input.step(|cursor| {
if let Some((_, next)) = cursor.token_tree() {
Ok(((), next))
} else {
Err(cursor.error("unexpected empty attribute"))
}
});
let la = input.lookahead1();
let label = if la.peek(syn::token::Paren) {
// #[label("{}", x)]
Expand Down Expand Up @@ -79,7 +90,7 @@ impl Labels {
let mut labels = Vec::new();
for (i, field) in fields.iter().enumerate() {
for attr in &field.attrs {
if attr.path.is_ident("label") {
if attr.path().is_ident("label") {
let span = if let Some(ident) = field.ident.clone() {
syn::Member::Named(ident)
} else {
Expand All @@ -88,7 +99,9 @@ impl Labels {
span: field.span(),
})
};
let LabelAttr { label } = syn::parse2::<LabelAttr>(attr.tokens.clone())?;
use quote::ToTokens;
let LabelAttr { label } =
syn::parse2::<LabelAttr>(attr.meta.to_token_stream())?;
labels.push(Label {
label,
span,
Expand Down
2 changes: 1 addition & 1 deletion miette-derive/src/related.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Related {
fn from_fields_vec(fields: Vec<&syn::Field>) -> syn::Result<Option<Self>> {
for (i, field) in fields.iter().enumerate() {
for attr in &field.attrs {
if attr.path.is_ident("related") {
if attr.path().is_ident("related") {
let related = if let Some(ident) = field.ident.clone() {
syn::Member::Named(ident)
} else {
Expand Down
2 changes: 1 addition & 1 deletion miette-derive/src/source_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl SourceCode {
fn from_fields_vec(fields: Vec<&syn::Field>) -> syn::Result<Option<Self>> {
for (i, field) in fields.iter().enumerate() {
for attr in &field.attrs {
if attr.path.is_ident("source_code") {
if attr.path().is_ident("source_code") {
let source_code = if let Some(ident) = field.ident.clone() {
syn::Member::Named(ident)
} else {
Expand Down

0 comments on commit a215720

Please sign in to comment.