Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump dependencies and update crates to use syn 2.0 #5749

Merged
merged 3 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
422 changes: 312 additions & 110 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ annotate-snippets = { version = "0.9", features = ["color"] }
anyhow = "1.0"
bytecount = "0.6"
cargo_metadata = "0.14"
clap = { version = "3.1", features = ["derive"] }
derive-new = "0.5"
clap = { version = "4.2.1", features = ["derive"] }
diff = "0.1"
dirs = "4.0"
env_logger = "0.9"
Expand All @@ -48,10 +47,10 @@ itertools = "0.10"
lazy_static = "1.4"
log = "0.4"
regex = "1.5"
serde = { version = "1.0", features = ["derive"] }
serde = { version = "1.0.160", features = ["derive"] }
serde_json = "1.0"
term = "0.7"
thiserror = "1.0"
thiserror = "1.0.40"
toml = "0.5"
unicode-segmentation = "1.9"
unicode-width = "0.1"
Expand Down
30 changes: 15 additions & 15 deletions config_proc_macro/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions config_proc_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["full", "visit"] }
syn = { version = "2.0", features = ["full", "visit"] }

[dev-dependencies]
serde = { version = "1.0", features = ["derive"] }
serde = { version = "1.0.160", features = ["derive"] }

[features]
default = []
Expand Down
18 changes: 9 additions & 9 deletions config_proc_macro/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,26 @@ pub fn is_unstable_variant(attr: &syn::Attribute) -> bool {
}

fn is_attr_name_value(attr: &syn::Attribute, name: &str) -> bool {
attr.parse_meta().ok().map_or(false, |meta| match meta {
syn::Meta::NameValue(syn::MetaNameValue { ref path, .. }) if path.is_ident(name) => true,
match &attr.meta {
syn::Meta::NameValue(syn::MetaNameValue { path, .. }) if path.is_ident(name) => true,
_ => false,
})
}
}

fn is_attr_path(attr: &syn::Attribute, name: &str) -> bool {
attr.parse_meta().ok().map_or(false, |meta| match meta {
match &attr.meta {
syn::Meta::Path(path) if path.is_ident(name) => true,
_ => false,
})
}
}

fn get_name_value_str_lit(attr: &syn::Attribute, name: &str) -> Option<String> {
attr.parse_meta().ok().and_then(|meta| match meta {
match &attr.meta {
syn::Meta::NameValue(syn::MetaNameValue {
ref path,
lit: syn::Lit::Str(ref lit_str),
path,
value: syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Str(lit_str), .. }),
..
}) if path.is_ident(name) => Some(lit_str.value()),
_ => None,
})
}
}
7 changes: 6 additions & 1 deletion src/attr/doc_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ use crate::comment::CommentStyle;
use std::fmt::{self, Display};

/// Formats a string as a doc comment using the given [`CommentStyle`].
#[derive(new)]
pub(super) struct DocCommentFormatter<'a> {
literal: &'a str,
style: CommentStyle<'a>,
}

impl<'a> DocCommentFormatter<'a> {
pub(super) const fn new(literal: &'a str, style: CommentStyle<'a>) -> Self {
Self { literal, style }
}
}

impl Display for DocCommentFormatter<'_> {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let opener = self.style.opener().trim_end();
Expand Down
6 changes: 3 additions & 3 deletions src/cargo-fmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use std::str;

use clap::{AppSettings, CommandFactory, Parser};
use clap::{CommandFactory, Parser};

#[path = "test/mod.rs"]
#[cfg(test)]
mod cargo_fmt_tests;

#[derive(Parser)]
#[clap(
global_setting(AppSettings::NoAutoVersion),
disable_version_flag = true,
bin_name = "cargo fmt",
about = "This utility formats all bin and lib files of \
the current crate using rustfmt."
Expand All @@ -45,7 +45,7 @@ pub struct Opts {
short = 'p',
long = "package",
value_name = "package",
multiple_values = true
num_args = 1..
)]
packages: Vec<String>,

Expand Down
17 changes: 16 additions & 1 deletion src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ fn format_project<T: FormatHandler>(
}

// Used for formatting files.
#[derive(new)]
struct FormatContext<'a, T: FormatHandler> {
krate: &'a ast::Crate,
report: FormatReport,
Expand All @@ -185,6 +184,22 @@ struct FormatContext<'a, T: FormatHandler> {
}

impl<'a, T: FormatHandler + 'a> FormatContext<'a, T> {
fn new(
krate: &'a ast::Crate,
report: FormatReport,
parse_session: ParseSess,
config: &'a Config,
handler: &'a mut T,
) -> Self {
FormatContext {
krate,
report,
parse_session,
config,
handler,
}
}

fn ignore_file(&self, path: &FileName) -> bool {
self.parse_session.ignore_file(path)
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#![recursion_limit = "256"]
#![allow(clippy::match_like_matches_macro)]

#[macro_use]
extern crate derive_new;
#[cfg(test)]
#[macro_use]
extern crate lazy_static;
Expand Down
5 changes: 4 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,12 +1119,15 @@ pub(crate) fn macro_style(mac: &ast::MacCall, context: &RewriteContext<'_>) -> D

// A very simple parser that just parses a macros 2.0 definition into its branches.
// Currently we do not attempt to parse any further than that.
#[derive(new)]
struct MacroParser {
toks: Cursor,
}

impl MacroParser {
const fn new(toks: Cursor) -> Self {
Self { toks }
}

// (`(` ... `)` `=>` `{` ... `}`)*
fn parse(&mut self) -> Option<Macro> {
let mut branches = vec![];
Expand Down
9 changes: 8 additions & 1 deletion src/pairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ use crate::utils::{
};

/// Sigils that decorate a binop pair.
#[derive(new, Clone, Copy)]
#[derive(Clone, Copy)]
pub(crate) struct PairParts<'a> {
prefix: &'a str,
infix: &'a str,
suffix: &'a str,
}

impl<'a> PairParts<'a> {
pub(crate) const fn new(prefix: &'a str, infix: &'a str, suffix: &'a str) -> Self {
Self {
prefix,
infix,
suffix,
}
}
pub(crate) fn infix(infix: &'a str) -> PairParts<'a> {
PairParts {
prefix: "",
Expand Down
Loading