lang: remove ConstraintLiteral (#2379)
This commit is contained in:
parent
c76641f861
commit
eef9888c82
|
@ -32,6 +32,7 @@ The minor version will be incremented upon a breaking change and the patch versi
|
|||
|
||||
- lang: Remove deprecated account types: `CpiAccount`, `Loader` and `ProgramAccount` ([#2375](https://github.com/coral-xyz/anchor/pull/2375)).
|
||||
- lang: Remove `state` and `interface` attributes ([#2285](https://github.com/coral-xyz/anchor/pull/2285)).
|
||||
- lang: Remove depecrated literal constraint which has been replaced by `#[account(constraint = {})]` ([#2379](https://github.com/coral-xyz/anchor/pull/2379)).
|
||||
- lang: `account(zero_copy)` and `zero_copy` attributes now derive the `bytemuck::Pod` and `bytemuck::Zeroable` traits instead of using `unsafe impl` ([#2330](https://github.com/coral-xyz/anchor/pull/2330)). This imposes useful restrictions on the type, like not having padding bytes and all fields being `Pod` themselves. See [bytemuck::Pod](https://docs.rs/bytemuck/latest/bytemuck/trait.Pod.html) for details. This change requires adding `bytemuck = { version = "1.4.0", features = ["derive", "min_const_generics"]}` to your `cargo.toml`. Legacy applications can still use `#[account(zero_copy(unsafe))]` and `#[zero_copy(unsafe)]` for the old behavior.
|
||||
- ts: Remove `createProgramAddressSync`, `findProgramAddressSync` (now available in `@solana/web3.js`) and update `associatedAddress` to be synchronous ([#2357](https://github.com/coral-xyz/anchor/pull/2357)).
|
||||
|
||||
|
|
|
@ -271,7 +271,6 @@ dependencies = [
|
|||
"bs58 0.3.1",
|
||||
"heck 0.3.3",
|
||||
"proc-macro2 1.0.47",
|
||||
"proc-macro2-diagnostics",
|
||||
"quote 1.0.21",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -2505,19 +2504,6 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2-diagnostics"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.47",
|
||||
"quote 1.0.21",
|
||||
"syn 1.0.103",
|
||||
"version_check",
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "qstring"
|
||||
version = "0.7.2"
|
||||
|
@ -4756,12 +4742,6 @@ dependencies = [
|
|||
"linked-hash-map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
|
||||
|
||||
[[package]]
|
||||
name = "yasna"
|
||||
version = "0.5.0"
|
||||
|
|
|
@ -19,7 +19,6 @@ seeds = []
|
|||
|
||||
[dependencies]
|
||||
proc-macro2 = { version = "1.0", features=["span-locations"]}
|
||||
proc-macro2-diagnostics = "0.9"
|
||||
quote = "1.0"
|
||||
syn = { version = "1.0.60", features = ["full", "extra-traits", "parsing"] }
|
||||
anyhow = "1.0.32"
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use proc_macro2_diagnostics::SpanDiagnosticExt;
|
||||
use quote::quote;
|
||||
use std::collections::HashSet;
|
||||
use syn::Expr;
|
||||
|
@ -59,7 +58,6 @@ pub fn generate_composite(f: &CompositeField) -> proc_macro2::TokenStream {
|
|||
.iter()
|
||||
.filter_map(|c| match c {
|
||||
Constraint::Raw(_) => Some(c),
|
||||
Constraint::Literal(_) => Some(c),
|
||||
_ => panic!("Invariant violation: composite constraints can only be raw or literals"),
|
||||
})
|
||||
.map(|c| generate_constraint_composite(f, c))
|
||||
|
@ -78,7 +76,6 @@ pub fn linearize(c_group: &ConstraintGroup) -> Vec<Constraint> {
|
|||
mutable,
|
||||
signer,
|
||||
has_one,
|
||||
literal,
|
||||
raw,
|
||||
owner,
|
||||
rent_exempt,
|
||||
|
@ -116,7 +113,6 @@ pub fn linearize(c_group: &ConstraintGroup) -> Vec<Constraint> {
|
|||
constraints.push(Constraint::Signer(c));
|
||||
}
|
||||
constraints.append(&mut has_one.into_iter().map(Constraint::HasOne).collect());
|
||||
constraints.append(&mut literal.into_iter().map(Constraint::Literal).collect());
|
||||
constraints.append(&mut raw.into_iter().map(Constraint::Raw).collect());
|
||||
if let Some(c) = owner {
|
||||
constraints.push(Constraint::Owner(c));
|
||||
|
@ -153,7 +149,6 @@ fn generate_constraint(
|
|||
Constraint::Mut(c) => generate_constraint_mut(f, c),
|
||||
Constraint::HasOne(c) => generate_constraint_has_one(f, c, accs),
|
||||
Constraint::Signer(c) => generate_constraint_signer(f, c),
|
||||
Constraint::Literal(c) => generate_constraint_literal(&f.ident, c),
|
||||
Constraint::Raw(c) => generate_constraint_raw(&f.ident, c),
|
||||
Constraint::Owner(c) => generate_constraint_owner(f, c),
|
||||
Constraint::RentExempt(c) => generate_constraint_rent_exempt(f, c),
|
||||
|
@ -171,7 +166,6 @@ fn generate_constraint(
|
|||
fn generate_constraint_composite(f: &CompositeField, c: &Constraint) -> proc_macro2::TokenStream {
|
||||
match c {
|
||||
Constraint::Raw(c) => generate_constraint_raw(&f.ident, c),
|
||||
Constraint::Literal(c) => generate_constraint_literal(&f.ident, c),
|
||||
_ => panic!("Invariant violation"),
|
||||
}
|
||||
}
|
||||
|
@ -301,27 +295,6 @@ pub fn generate_constraint_signer(f: &Field, c: &ConstraintSigner) -> proc_macro
|
|||
}
|
||||
}
|
||||
|
||||
pub fn generate_constraint_literal(
|
||||
ident: &Ident,
|
||||
c: &ConstraintLiteral,
|
||||
) -> proc_macro2::TokenStream {
|
||||
let name_str = ident.to_string();
|
||||
let lit: proc_macro2::TokenStream = {
|
||||
let lit = &c.lit;
|
||||
let constraint = lit.value().replace('\"', "");
|
||||
let message = format!(
|
||||
"Deprecated. Should be used with constraint: #[account(constraint = {constraint})]",
|
||||
);
|
||||
lit.span().warning(message).emit_as_item_tokens();
|
||||
constraint.parse().unwrap()
|
||||
};
|
||||
quote! {
|
||||
if !(#lit) {
|
||||
return Err(anchor_lang::error::Error::from(anchor_lang::error::ErrorCode::Deprecated).with_account_name(#name_str));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_constraint_raw(ident: &Ident, c: &ConstraintRaw) -> proc_macro2::TokenStream {
|
||||
let raw = &c.raw;
|
||||
let error = generate_custom_error(ident, &c.error, quote! { ConstraintRaw }, &None);
|
||||
|
|
|
@ -14,8 +14,8 @@ use syn::punctuated::Punctuated;
|
|||
use syn::spanned::Spanned;
|
||||
use syn::token::Comma;
|
||||
use syn::{
|
||||
Expr, Generics, Ident, ItemEnum, ItemFn, ItemMod, ItemStruct, LitInt, LitStr, PatType, Token,
|
||||
Type, TypePath,
|
||||
Expr, Generics, Ident, ItemEnum, ItemFn, ItemMod, ItemStruct, LitInt, PatType, Token, Type,
|
||||
TypePath,
|
||||
};
|
||||
|
||||
pub mod codegen;
|
||||
|
@ -557,7 +557,6 @@ pub struct ConstraintGroup {
|
|||
pub seeds: Option<ConstraintSeedsGroup>,
|
||||
pub executable: Option<ConstraintExecutable>,
|
||||
pub has_one: Vec<ConstraintHasOne>,
|
||||
pub literal: Vec<ConstraintLiteral>,
|
||||
pub raw: Vec<ConstraintRaw>,
|
||||
pub close: Option<ConstraintClose>,
|
||||
pub address: Option<ConstraintAddress>,
|
||||
|
@ -596,7 +595,6 @@ pub enum Constraint {
|
|||
Mut(ConstraintMut),
|
||||
Signer(ConstraintSigner),
|
||||
HasOne(ConstraintHasOne),
|
||||
Literal(ConstraintLiteral),
|
||||
Raw(ConstraintRaw),
|
||||
Owner(ConstraintOwner),
|
||||
RentExempt(ConstraintRentExempt),
|
||||
|
@ -619,7 +617,6 @@ pub enum ConstraintToken {
|
|||
Mut(Context<ConstraintMut>),
|
||||
Signer(Context<ConstraintSigner>),
|
||||
HasOne(Context<ConstraintHasOne>),
|
||||
Literal(Context<ConstraintLiteral>),
|
||||
Raw(Context<ConstraintRaw>),
|
||||
Owner(Context<ConstraintOwner>),
|
||||
RentExempt(Context<ConstraintRentExempt>),
|
||||
|
@ -698,11 +695,6 @@ pub struct ConstraintHasOne {
|
|||
pub error: Option<Expr>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ConstraintLiteral {
|
||||
pub lit: LitStr,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ConstraintRaw {
|
||||
pub raw: Expr,
|
||||
|
|
|
@ -4,7 +4,7 @@ use syn::parse::{Error as ParseError, Parse, ParseStream, Result as ParseResult}
|
|||
use syn::punctuated::Punctuated;
|
||||
use syn::spanned::Spanned;
|
||||
use syn::token::Comma;
|
||||
use syn::{bracketed, Expr, Ident, LitStr, Token};
|
||||
use syn::{bracketed, Expr, Ident, Token};
|
||||
|
||||
pub fn parse(f: &syn::Field, f_ty: Option<&Ty>) -> ParseResult<ConstraintGroup> {
|
||||
let mut constraints = ConstraintGroupBuilder::new(f_ty);
|
||||
|
@ -26,13 +26,6 @@ pub fn is_account(attr: &&syn::Attribute) -> bool {
|
|||
|
||||
// Parses a single constraint from a parse stream for `#[account(<STREAM>)]`.
|
||||
pub fn parse_token(stream: ParseStream) -> ParseResult<ConstraintToken> {
|
||||
let is_lit = stream.peek(LitStr);
|
||||
if is_lit {
|
||||
let lit: LitStr = stream.parse()?;
|
||||
let c = ConstraintToken::Literal(Context::new(lit.span(), ConstraintLiteral { lit }));
|
||||
return Ok(c);
|
||||
}
|
||||
|
||||
let ident = stream.call(Ident::parse_any)?;
|
||||
let kw = ident.to_string();
|
||||
|
||||
|
@ -328,7 +321,6 @@ pub struct ConstraintGroupBuilder<'ty> {
|
|||
pub mutable: Option<Context<ConstraintMut>>,
|
||||
pub signer: Option<Context<ConstraintSigner>>,
|
||||
pub has_one: Vec<Context<ConstraintHasOne>>,
|
||||
pub literal: Vec<Context<ConstraintLiteral>>,
|
||||
pub raw: Vec<Context<ConstraintRaw>>,
|
||||
pub owner: Option<Context<ConstraintOwner>>,
|
||||
pub rent_exempt: Option<Context<ConstraintRentExempt>>,
|
||||
|
@ -361,7 +353,6 @@ impl<'ty> ConstraintGroupBuilder<'ty> {
|
|||
mutable: None,
|
||||
signer: None,
|
||||
has_one: Vec::new(),
|
||||
literal: Vec::new(),
|
||||
raw: Vec::new(),
|
||||
owner: None,
|
||||
rent_exempt: None,
|
||||
|
@ -561,7 +552,6 @@ impl<'ty> ConstraintGroupBuilder<'ty> {
|
|||
mutable,
|
||||
signer,
|
||||
has_one,
|
||||
literal,
|
||||
raw,
|
||||
owner,
|
||||
rent_exempt,
|
||||
|
@ -710,7 +700,6 @@ impl<'ty> ConstraintGroupBuilder<'ty> {
|
|||
mutable: into_inner!(mutable),
|
||||
signer: into_inner!(signer),
|
||||
has_one: into_inner_vec!(has_one),
|
||||
literal: into_inner_vec!(literal),
|
||||
raw: into_inner_vec!(raw),
|
||||
owner: into_inner!(owner),
|
||||
rent_exempt: into_inner!(rent_exempt),
|
||||
|
@ -731,7 +720,6 @@ impl<'ty> ConstraintGroupBuilder<'ty> {
|
|||
ConstraintToken::Mut(c) => self.add_mut(c),
|
||||
ConstraintToken::Signer(c) => self.add_signer(c),
|
||||
ConstraintToken::HasOne(c) => self.add_has_one(c),
|
||||
ConstraintToken::Literal(c) => self.add_literal(c),
|
||||
ConstraintToken::Raw(c) => self.add_raw(c),
|
||||
ConstraintToken::Owner(c) => self.add_owner(c),
|
||||
ConstraintToken::RentExempt(c) => self.add_rent_exempt(c),
|
||||
|
@ -1060,11 +1048,6 @@ impl<'ty> ConstraintGroupBuilder<'ty> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn add_literal(&mut self, c: Context<ConstraintLiteral>) -> ParseResult<()> {
|
||||
self.literal.push(c);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn add_raw(&mut self, c: Context<ConstraintRaw>) -> ParseResult<()> {
|
||||
self.raw.push(c);
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue