Skip to content

Commit 782eccb

Browse files
Upgrade syn crate to 2.0 version (#1157)
- replace `proc-macro-error` crate with simplified `common::diagnostic::pollyfill` - migrate `juniper_codegen_tests` to stable Rust Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kai Ren <[email protected]>
1 parent 2598045 commit 782eccb

File tree

123 files changed

+810
-665
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+810
-665
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ jobs:
141141
strategy:
142142
fail-fast: false
143143
matrix:
144-
msrv: ["1.65.0"]
144+
msrv: ["1.73.0"]
145145
crate:
146146
- juniper_codegen
147147
- juniper
148148
- juniper_subscriptions
149149
- juniper_graphql_ws
150-
#- juniper_actix
150+
- juniper_actix
151151
- juniper_hyper
152152
#- juniper_iron
153153
- juniper_rocket
@@ -156,10 +156,6 @@ jobs:
156156
- ubuntu
157157
- macOS
158158
- windows
159-
include:
160-
- { msrv: "1.68.0", crate: "juniper_actix", os: "ubuntu" }
161-
- { msrv: "1.68.0", crate: "juniper_actix", os: "macOS" }
162-
- { msrv: "1.68.0", crate: "juniper_actix", os: "windows" }
163159
runs-on: ${{ matrix.os }}-latest
164160
steps:
165161
- uses: actions/checkout@v4
@@ -217,10 +213,10 @@ jobs:
217213
- beta
218214
- nightly
219215
exclude:
220-
- crate: juniper_codegen_tests
221-
toolchain: stable
222216
- crate: juniper_codegen_tests
223217
toolchain: beta
218+
- crate: juniper_codegen_tests
219+
toolchain: nightly
224220
- crate: juniper_codegen_tests
225221
os: macOS
226222
- crate: juniper_codegen_tests

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ ifeq ($(shell rustup component list --toolchain=nightly \
120120
rustup component add --toolchain=nightly rust-src
121121
endif
122122
endif
123-
cargo $(if $(call eq,$(careful),yes),+nightly careful,\
124-
$(if $(call eq,$(crate),juniper_codegen_tests),+nightly,)) \
123+
cargo $(if $(call eq,$(careful),yes),+nightly careful,) \
125124
test $(if $(call eq,$(crate),),--workspace,-p $(crate)) --all-features
126125

127126

juniper/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "juniper"
33
version = "0.16.0-dev"
44
edition = "2021"
5-
rust-version = "1.65"
5+
rust-version = "1.73"
66
description = "GraphQL server library."
77
license = "BSD-2-Clause"
88
authors = [
@@ -68,7 +68,7 @@ time = { version = "0.3", features = ["formatting", "macros", "parsing"], option
6868
url = { version = "2.0", optional = true }
6969
uuid = { version = "1.3", default-features = false, optional = true }
7070

71-
# Fixes for MSRV check.
71+
# Fixes for `minimal-versions` check.
7272
# TODO: Try remove on upgrade of `bigdecimal` crate.
7373
num-bigint = { version = "0.4.2", optional = true }
7474
# TODO: Try remove on upgrade of `chrono-tz` crate.

juniper/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Juniper (GraphQL server library for Rust)
44
[![Crates.io](https://img.shields.io/crates/v/juniper.svg?maxAge=2592000)](https://crates.io/crates/juniper)
55
[![Documentation](https://docs.rs/juniper/badge.svg)](https://docs.rs/juniper)
66
[![CI](https://github.com/graphql-rust/juniper/workflows/CI/badge.svg?branch=master "CI")](https://github.com/graphql-rust/juniper/actions?query=workflow%3ACI+branch%3Amaster)
7-
[![Rust 1.65+](https://img.shields.io/badge/rustc-1.65+-lightgray.svg "Rust 1.65+")](https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html)
7+
[![Rust 1.73+](https://img.shields.io/badge/rustc-1.73+-lightgray.svg "Rust 1.73+")](https://blog.rust-lang.org/2023/10/05/Rust-1.73.0.html)
88

99
- [Juniper Book] ([current][Juniper Book] | [edge][Juniper Book edge])
1010
- [Changelog](https://github.com/graphql-rust/juniper/blob/master/juniper/CHANGELOG.md)

juniper_codegen/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ All user visible changes to `juniper_codegen` crate will be documented in this f
3838

3939
- `#[derive(GraphQLInterface)]` macro allowing using structs as GraphQL interfaces. ([#1026])
4040

41+
### Changed
42+
43+
- Migrated to 2 version of `syn` crate. ([#1157])
44+
4145
### Fixed
4246

4347
- All procedural macros expansion inside `macro_rules!`. ([#1054], [#1051])
@@ -56,6 +60,7 @@ All user visible changes to `juniper_codegen` crate will be documented in this f
5660
[#1028]: /../../pull/1028
5761
[#1051]: /../../issues/1051
5862
[#1054]: /../../pull/1054
63+
[#1157]: /../../pull/1157
5964

6065

6166

juniper_codegen/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "juniper_codegen"
33
version = "0.16.0-dev"
44
edition = "2021"
5-
rust-version = "1.65"
5+
rust-version = "1.73"
66
description = "Code generation for `juniper` crate."
77
license = "BSD-2-Clause"
88
authors = [
@@ -22,10 +22,9 @@ exclude = ["/release.toml"]
2222
proc-macro = true
2323

2424
[dependencies]
25-
proc-macro-error = "1.0.2"
2625
proc-macro2 = "1.0.4"
2726
quote = "1.0.9"
28-
syn = { version = "1.0.90", features = ["extra-traits", "full", "parsing", "visit", "visit-mut"], default-features = false }
27+
syn = { version = "2.0", features = ["extra-traits", "full", "visit", "visit-mut"] }
2928
url = "2.0"
3029

3130
[dev-dependencies]

juniper_codegen/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Crates.io](https://img.shields.io/crates/v/juniper_codegen.svg?maxAge=2592000)](https://crates.io/crates/juniper_codegen)
55
[![Documentation](https://docs.rs/juniper_codegen/badge.svg)](https://docs.rs/juniper_codegen)
66
[![CI](https://github.com/graphql-rust/juniper/workflows/CI/badge.svg?branch=master "CI")](https://github.com/graphql-rust/juniper/actions?query=workflow%3ACI+branch%3Amaster)
7-
[![Rust 1.65+](https://img.shields.io/badge/rustc-1.65+-lightgray.svg "Rust 1.65+")](https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html)
7+
[![Rust 1.73+](https://img.shields.io/badge/rustc-1.73+-lightgray.svg "Rust 1.73+")](https://blog.rust-lang.org/2023/10/05/Rust-1.73.0.html)
88

99
- [Changelog](https://github.com/graphql-rust/juniper/blob/master/juniper_codegen/CHANGELOG.md)
1010

juniper_codegen/src/common/deprecation.rs

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use proc_macro2::TokenStream;
77
use quote::{quote, ToTokens};
88
use syn::{
99
parse::{Parse, ParseStream},
10+
punctuated::Punctuated,
1011
spanned::Spanned as _,
1112
token,
1213
};
@@ -20,7 +21,7 @@ use crate::common::{parse::ParseBufferExt as _, SpanContainer};
2021
/// [0]: https://spec.graphql.org/October2021#sec--deprecated
2122
/// [1]: https://spec.graphql.org/October2021#sec-Language.Fields
2223
/// [2]: https://spec.graphql.org/October2021#sec-Enum-Value
23-
#[derive(Debug, Default)]
24+
#[derive(Debug, Default, Eq, PartialEq)]
2425
pub(crate) struct Directive {
2526
/// Optional [reason][1] attached to this [deprecation][0].
2627
///
@@ -52,16 +53,16 @@ impl Directive {
5253
attrs: &[syn::Attribute],
5354
) -> syn::Result<Option<SpanContainer<Self>>> {
5455
for attr in attrs {
55-
return Ok(match attr.parse_meta() {
56-
Ok(syn::Meta::List(ref list)) if list.path.is_ident("deprecated") => {
56+
return Ok(match &attr.meta {
57+
syn::Meta::List(list) if list.path.is_ident("deprecated") => {
5758
let directive = Self::parse_from_deprecated_meta_list(list)?;
5859
Some(SpanContainer::new(
5960
list.path.span(),
6061
directive.reason.as_ref().map(|r| r.span()),
6162
directive,
6263
))
6364
}
64-
Ok(syn::Meta::Path(ref path)) if path.is_ident("deprecated") => {
65+
syn::Meta::Path(path) if path.is_ident("deprecated") => {
6566
Some(SpanContainer::new(path.span(), None, Self::default()))
6667
}
6768
_ => continue,
@@ -77,20 +78,24 @@ impl Directive {
7778
///
7879
/// If the `#[deprecated(note = ...)]` attribute has incorrect format.
7980
fn parse_from_deprecated_meta_list(list: &syn::MetaList) -> syn::Result<Self> {
80-
for meta in &list.nested {
81-
if let syn::NestedMeta::Meta(syn::Meta::NameValue(nv)) = meta {
81+
for meta in list.parse_args_with(Punctuated::<syn::Meta, token::Comma>::parse_terminated)? {
82+
if let syn::Meta::NameValue(nv) = meta {
8283
return if !nv.path.is_ident("note") {
8384
Err(syn::Error::new(
8485
nv.path.span(),
8586
"unrecognized setting on #[deprecated(..)] attribute",
8687
))
87-
} else if let syn::Lit::Str(strlit) = &nv.lit {
88+
} else if let syn::Expr::Lit(syn::ExprLit {
89+
lit: syn::Lit::Str(strlit),
90+
..
91+
}) = &nv.value
92+
{
8893
Ok(Self {
8994
reason: Some(strlit.clone()),
9095
})
9196
} else {
9297
Err(syn::Error::new(
93-
nv.lit.span(),
98+
nv.value.span(),
9499
"only strings are allowed for deprecation",
95100
))
96101
};
@@ -112,3 +117,43 @@ impl ToTokens for Directive {
112117
.to_tokens(into);
113118
}
114119
}
120+
121+
#[cfg(test)]
122+
mod parse_from_deprecated_attr_test {
123+
use quote::quote;
124+
use syn::parse_quote;
125+
126+
use super::Directive;
127+
128+
#[test]
129+
fn single() {
130+
let desc =
131+
Directive::parse_from_deprecated_attr(&[parse_quote! { #[deprecated(note = "foo")] }])
132+
.unwrap()
133+
.unwrap()
134+
.into_inner();
135+
assert_eq!(
136+
quote! { #desc }.to_string(),
137+
quote! { .deprecated(::core::option::Option::Some("foo")) }.to_string(),
138+
);
139+
}
140+
141+
#[test]
142+
fn no_reason() {
143+
let desc = Directive::parse_from_deprecated_attr(&[parse_quote! { #[deprecated] }])
144+
.unwrap()
145+
.unwrap()
146+
.into_inner();
147+
assert_eq!(
148+
quote! { #desc }.to_string(),
149+
quote! { .deprecated(::core::option::Option::None) }.to_string(),
150+
);
151+
}
152+
153+
#[test]
154+
fn not_deprecation() {
155+
let desc =
156+
Directive::parse_from_deprecated_attr(&[parse_quote! { #[blah = "foo"] }]).unwrap();
157+
assert_eq!(desc, None);
158+
}
159+
}

juniper_codegen/src/common/description.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
66
use proc_macro2::TokenStream;
77
use quote::{quote, ToTokens};
8-
use syn::parse::{Parse, ParseStream};
8+
use syn::{
9+
parse::{Parse, ParseStream},
10+
spanned::Spanned as _,
11+
};
912

1013
use crate::common::SpanContainer;
1114

@@ -36,16 +39,20 @@ impl Description {
3639
) -> syn::Result<Option<SpanContainer<Self>>> {
3740
let (mut first_span, mut descriptions) = (None, Vec::new());
3841
for attr in attrs {
39-
match attr.parse_meta() {
40-
Ok(syn::Meta::NameValue(ref nv)) if nv.path.is_ident("doc") => {
41-
if let syn::Lit::Str(strlit) = &nv.lit {
42+
match attr.meta {
43+
syn::Meta::NameValue(ref nv) if nv.path.is_ident("doc") => {
44+
if let syn::Expr::Lit(syn::ExprLit {
45+
lit: syn::Lit::Str(strlit),
46+
..
47+
}) = &nv.value
48+
{
4249
if first_span.is_none() {
4350
first_span = Some(strlit.span());
4451
}
4552
descriptions.push(strlit.value());
4653
} else {
4754
return Err(syn::Error::new(
48-
nv.lit.span(),
55+
nv.value.span(),
4956
"#[doc] attributes may only have a string literal",
5057
));
5158
}

0 commit comments

Comments
 (0)