Compare commits

..

No commits in common. "0ea668077d6a47f64ee3875dbed31f9e8d832ae3" and "5b3593e571826ae44a3aeb0e0f6f09face7291ac" have entirely different histories.

36 changed files with 71 additions and 216 deletions

11
Cargo.lock generated
View File

@ -410,8 +410,7 @@ dependencies = [
[[package]] [[package]]
name = "codex" name = "codex"
version = "0.1.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/typst/codex?rev=343a9b1#343a9b199430681ba3ca0e2242097c6419492d55"
checksum = "2e0ee2092c3513f63588d51c3f81b98e6b1aa8ddcca3b5892b288f093516497d"
[[package]] [[package]]
name = "color-print" name = "color-print"
@ -1567,9 +1566,9 @@ dependencies = [
[[package]] [[package]]
name = "openssl" name = "openssl"
version = "0.10.70" version = "0.10.66"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61cfb4e166a8bb8c9b55c500bc2308550148ece889be90f609377e58140f42c6" checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
"cfg-if", "cfg-if",
@ -1608,9 +1607,9 @@ dependencies = [
[[package]] [[package]]
name = "openssl-sys" name = "openssl-sys"
version = "0.9.105" version = "0.9.103"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b22d5b84be05a8d6947c7cb71f7c849aa0f112acd4bf51c2a7c1c988ac0a9dc" checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6"
dependencies = [ dependencies = [
"cc", "cc",
"libc", "libc",

View File

@ -47,7 +47,7 @@ clap = { version = "4.4", features = ["derive", "env", "wrap_help"] }
clap_complete = "4.2.1" clap_complete = "4.2.1"
clap_mangen = "0.2.10" clap_mangen = "0.2.10"
codespan-reporting = "0.11" codespan-reporting = "0.11"
codex = "0.1.0" codex = { git = "https://github.com/typst/codex", rev = "343a9b1" }
color-print = "0.3.6" color-print = "0.3.6"
comemo = "0.4" comemo = "0.4"
csv = "1" csv = "1"

View File

@ -315,15 +315,13 @@ fn eval_field_call(
(target, args) (target, args)
}; };
let field_span = field.span();
let sink = (&mut vm.engine, field_span);
if let Some(callee) = target.ty().scope().get(&field) { if let Some(callee) = target.ty().scope().get(&field) {
args.insert(0, target_expr.span(), target); args.insert(0, target_expr.span(), target);
Ok(FieldCall::Normal(callee.read_checked(sink).clone(), args)) Ok(FieldCall::Normal(callee.read().clone(), args))
} else if let Value::Content(content) = &target { } else if let Value::Content(content) = &target {
if let Some(callee) = content.elem().scope().get(&field) { if let Some(callee) = content.elem().scope().get(&field) {
args.insert(0, target_expr.span(), target); args.insert(0, target_expr.span(), target);
Ok(FieldCall::Normal(callee.read_checked(sink).clone(), args)) Ok(FieldCall::Normal(callee.read().clone(), args))
} else { } else {
bail!(missing_field_call_error(target, field)) bail!(missing_field_call_error(target, field))
} }
@ -333,7 +331,7 @@ fn eval_field_call(
) { ) {
// Certain value types may have their own ways to access method fields. // Certain value types may have their own ways to access method fields.
// e.g. `$arrow.r(v)$`, `table.cell[..]` // e.g. `$arrow.r(v)$`, `table.cell[..]`
let value = target.field(&field, sink).at(field_span)?; let value = target.field(&field).at(field.span())?;
Ok(FieldCall::Normal(value, args)) Ok(FieldCall::Normal(value, args))
} else { } else {
// Otherwise we cannot call this field. // Otherwise we cannot call this field.
@ -366,7 +364,7 @@ fn missing_field_call_error(target: Value, field: Ident) -> SourceDiagnostic {
field.as_str(), field.as_str(),
)); ));
} }
_ if target.field(&field, ()).is_ok() => { _ if target.field(&field).is_ok() => {
error.hint(eco_format!( error.hint(eco_format!(
"did you mean to access the field `{}`?", "did you mean to access the field `{}`?",
field.as_str(), field.as_str(),

View File

@ -154,13 +154,7 @@ impl Eval for ast::Ident<'_> {
type Output = Value; type Output = Value;
fn eval(self, vm: &mut Vm) -> SourceResult<Self::Output> { fn eval(self, vm: &mut Vm) -> SourceResult<Self::Output> {
let span = self.span(); Ok(vm.scopes.get(&self).at(self.span())?.read().clone())
Ok(vm
.scopes
.get(&self)
.at(span)?
.read_checked((&mut vm.engine, span))
.clone())
} }
} }
@ -316,9 +310,8 @@ impl Eval for ast::FieldAccess<'_> {
fn eval(self, vm: &mut Vm) -> SourceResult<Self::Output> { fn eval(self, vm: &mut Vm) -> SourceResult<Self::Output> {
let value = self.target().eval(vm)?; let value = self.target().eval(vm)?;
let field = self.field(); let field = self.field();
let field_span = field.span();
let err = match value.field(&field, (&mut vm.engine, field_span)).at(field_span) { let err = match value.field(&field).at(field.span()) {
Ok(value) => return Ok(value), Ok(value) => return Ok(value),
Err(err) => err, Err(err) => err,
}; };

View File

@ -35,13 +35,7 @@ impl Eval for ast::MathIdent<'_> {
type Output = Value; type Output = Value;
fn eval(self, vm: &mut Vm) -> SourceResult<Self::Output> { fn eval(self, vm: &mut Vm) -> SourceResult<Self::Output> {
let span = self.span(); Ok(vm.scopes.get_in_math(&self).at(self.span())?.read().clone())
Ok(vm
.scopes
.get_in_math(&self)
.at(span)?
.read_checked((&mut vm.engine, span))
.clone())
} }
} }

View File

@ -414,7 +414,7 @@ fn field_access_completions(
// with method syntax; // with method syntax;
// 2. We can unwrap the field's value since it's a field belonging to // 2. We can unwrap the field's value since it's a field belonging to
// this value's type, so accessing it should not fail. // this value's type, so accessing it should not fail.
ctx.value_completion(field, &value.field(field, ()).unwrap()); ctx.value_completion(field, &value.field(field).unwrap());
} }
match value { match value {

View File

@ -11,7 +11,6 @@ use ecow::{eco_vec, EcoVec};
use typst_syntax::package::{PackageSpec, PackageVersion}; use typst_syntax::package::{PackageSpec, PackageVersion};
use typst_syntax::{Span, Spanned, SyntaxError}; use typst_syntax::{Span, Spanned, SyntaxError};
use crate::engine::Engine;
use crate::{World, WorldExt}; use crate::{World, WorldExt};
/// Early-return with a [`StrResult`] or [`SourceResult`]. /// Early-return with a [`StrResult`] or [`SourceResult`].
@ -229,23 +228,6 @@ impl From<SyntaxError> for SourceDiagnostic {
} }
} }
/// Destination for a deprecation message when accessing a deprecated value.
pub trait DeprecationSink {
/// Emits the given deprecation message into this sink.
fn emit(self, message: &str);
}
impl DeprecationSink for () {
fn emit(self, _: &str) {}
}
impl DeprecationSink for (&mut Engine<'_>, Span) {
/// Emits the deprecation message as a warning.
fn emit(self, message: &str) {
self.0.sink.warn(SourceDiagnostic::warning(self.1, message));
}
}
/// A part of a diagnostic's [trace](SourceDiagnostic::trace). /// A part of a diagnostic's [trace](SourceDiagnostic::trace).
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Tracepoint { pub enum Tracepoint {

View File

@ -9,7 +9,7 @@ use ecow::{eco_format, EcoString};
use typst_syntax::{ast, Span, SyntaxNode}; use typst_syntax::{ast, Span, SyntaxNode};
use typst_utils::{singleton, LazyHash, Static}; use typst_utils::{singleton, LazyHash, Static};
use crate::diag::{bail, At, DeprecationSink, SourceResult, StrResult}; use crate::diag::{bail, At, SourceResult, StrResult};
use crate::engine::Engine; use crate::engine::Engine;
use crate::foundations::{ use crate::foundations::{
cast, repr, scope, ty, Args, Bytes, CastInfo, Content, Context, Element, IntoArgs, cast, repr, scope, ty, Args, Bytes, CastInfo, Content, Context, Element, IntoArgs,
@ -255,15 +255,11 @@ impl Func {
} }
/// Get a field from this function's scope, if possible. /// Get a field from this function's scope, if possible.
pub fn field( pub fn field(&self, field: &str) -> StrResult<&'static Value> {
&self,
field: &str,
sink: impl DeprecationSink,
) -> StrResult<&'static Value> {
let scope = let scope =
self.scope().ok_or("cannot access fields on user-defined functions")?; self.scope().ok_or("cannot access fields on user-defined functions")?;
match scope.get(field) { match scope.get(field) {
Some(binding) => Ok(binding.read_checked(sink)), Some(binding) => Ok(binding.read()),
None => match self.name() { None => match self.name() {
Some(name) => bail!("function `{name}` does not contain field `{field}`"), Some(name) => bail!("function `{name}` does not contain field `{field}`"),
None => bail!("function does not contain field `{field}`"), None => bail!("function does not contain field `{field}`"),

View File

@ -4,7 +4,7 @@ use std::sync::Arc;
use ecow::{eco_format, EcoString}; use ecow::{eco_format, EcoString};
use typst_syntax::FileId; use typst_syntax::FileId;
use crate::diag::{bail, DeprecationSink, StrResult}; use crate::diag::{bail, StrResult};
use crate::foundations::{repr, ty, Content, Scope, Value}; use crate::foundations::{repr, ty, Content, Scope, Value};
/// An module of definitions. /// An module of definitions.
@ -118,9 +118,9 @@ impl Module {
} }
/// Try to access a definition in the module. /// Try to access a definition in the module.
pub fn field(&self, field: &str, sink: impl DeprecationSink) -> StrResult<&Value> { pub fn field(&self, field: &str) -> StrResult<&Value> {
match self.scope().get(field) { match self.scope().get(field) {
Some(binding) => Ok(binding.read_checked(sink)), Some(binding) => Ok(binding.read()),
None => match &self.name { None => match &self.name {
Some(name) => bail!("module `{name}` does not contain `{field}`"), Some(name) => bail!("module `{name}` does not contain `{field}`"),
None => bail!("module does not contain `{field}`"), None => bail!("module does not contain `{field}`"),

View File

@ -10,7 +10,7 @@ use indexmap::IndexMap;
use typst_syntax::Span; use typst_syntax::Span;
use typst_utils::Static; use typst_utils::Static;
use crate::diag::{bail, DeprecationSink, HintedStrResult, HintedString, StrResult}; use crate::diag::{bail, HintedStrResult, HintedString, StrResult};
use crate::foundations::{ use crate::foundations::{
Element, Func, IntoValue, NativeElement, NativeFunc, NativeFuncData, NativeType, Element, Func, IntoValue, NativeElement, NativeFunc, NativeFuncData, NativeType,
Type, Value, Type, Value,
@ -258,8 +258,6 @@ pub struct Binding {
span: Span, span: Span,
/// The category of the binding. /// The category of the binding.
category: Option<Category>, category: Option<Category>,
/// A deprecation message for the definition.
deprecation: Option<&'static str>,
} }
/// The different kinds of slots. /// The different kinds of slots.
@ -279,7 +277,6 @@ impl Binding {
span, span,
kind: BindingKind::Normal, kind: BindingKind::Normal,
category: None, category: None,
deprecation: None,
} }
} }
@ -288,29 +285,11 @@ impl Binding {
Self::new(value, Span::detached()) Self::new(value, Span::detached())
} }
/// Marks this binding as deprecated, with the given `message`.
pub fn deprecated(&mut self, message: &'static str) -> &mut Self {
self.deprecation = Some(message);
self
}
/// Read the value. /// Read the value.
pub fn read(&self) -> &Value { pub fn read(&self) -> &Value {
&self.value &self.value
} }
/// Read the value, checking for deprecation.
///
/// As the `sink`
/// - pass `()` to ignore the message.
/// - pass `(&mut engine, span)` to emit a warning into the engine.
pub fn read_checked(&self, sink: impl DeprecationSink) -> &Value {
if let Some(message) = self.deprecation {
sink.emit(message);
}
&self.value
}
/// Try to write to the value. /// Try to write to the value.
/// ///
/// This fails if the value is a read-only closure capture. /// This fails if the value is a read-only closure capture.
@ -341,11 +320,6 @@ impl Binding {
self.span self.span
} }
/// A deprecation message for the value, if any.
pub fn deprecation(&self) -> Option<&'static str> {
self.deprecation
}
/// The category of the value, if any. /// The category of the value, if any.
pub fn category(&self) -> Option<Category> { pub fn category(&self) -> Option<Category> {
self.category self.category

View File

@ -8,7 +8,7 @@ use std::sync::LazyLock;
use ecow::{eco_format, EcoString}; use ecow::{eco_format, EcoString};
use typst_utils::Static; use typst_utils::Static;
use crate::diag::{bail, DeprecationSink, StrResult}; use crate::diag::{bail, StrResult};
use crate::foundations::{ use crate::foundations::{
cast, func, AutoValue, Func, NativeFuncData, NoneValue, Repr, Scope, Value, cast, func, AutoValue, Func, NativeFuncData, NoneValue, Repr, Scope, Value,
}; };
@ -94,13 +94,9 @@ impl Type {
} }
/// Get a field from this type's scope, if possible. /// Get a field from this type's scope, if possible.
pub fn field( pub fn field(&self, field: &str) -> StrResult<&'static Value> {
&self,
field: &str,
sink: impl DeprecationSink,
) -> StrResult<&'static Value> {
match self.scope().get(field) { match self.scope().get(field) {
Some(binding) => Ok(binding.read_checked(sink)), Some(binding) => Ok(binding.read()),
None => bail!("type {self} does not contain field `{field}`"), None => bail!("type {self} does not contain field `{field}`"),
} }
} }

View File

@ -11,7 +11,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use typst_syntax::{ast, Span}; use typst_syntax::{ast, Span};
use typst_utils::ArcExt; use typst_utils::ArcExt;
use crate::diag::{DeprecationSink, HintedStrResult, HintedString, StrResult}; use crate::diag::{HintedStrResult, HintedString, StrResult};
use crate::foundations::{ use crate::foundations::{
fields, ops, repr, Args, Array, AutoValue, Bytes, CastInfo, Content, Datetime, fields, ops, repr, Args, Array, AutoValue, Bytes, CastInfo, Content, Datetime,
Decimal, Dict, Duration, Fold, FromValue, Func, IntoValue, Label, Module, Decimal, Dict, Duration, Fold, FromValue, Func, IntoValue, Label, Module,
@ -155,15 +155,15 @@ impl Value {
} }
/// Try to access a field on the value. /// Try to access a field on the value.
pub fn field(&self, field: &str, sink: impl DeprecationSink) -> StrResult<Value> { pub fn field(&self, field: &str) -> StrResult<Value> {
match self { match self {
Self::Symbol(symbol) => symbol.clone().modified(field).map(Self::Symbol), Self::Symbol(symbol) => symbol.clone().modified(field).map(Self::Symbol),
Self::Version(version) => version.component(field).map(Self::Int), Self::Version(version) => version.component(field).map(Self::Int),
Self::Dict(dict) => dict.get(field).cloned(), Self::Dict(dict) => dict.get(field).cloned(),
Self::Content(content) => content.field_by_name(field), Self::Content(content) => content.field_by_name(field),
Self::Type(ty) => ty.field(field, sink).cloned(), Self::Type(ty) => ty.field(field).cloned(),
Self::Func(func) => func.field(field, sink).cloned(), Self::Func(func) => func.field(field).cloned(),
Self::Module(module) => module.field(field, sink).cloned(), Self::Module(module) => module.field(field).cloned(),
_ => fields::field(self, field), _ => fields::field(self, field),
} }
} }

View File

@ -270,7 +270,7 @@ pub struct PageElem {
/// margin: (top: 32pt, bottom: 20pt), /// margin: (top: 32pt, bottom: 20pt),
/// header: [ /// header: [
/// #set text(8pt) /// #set text(8pt)
/// #smallcaps[Typst Academy] /// #smallcaps[Typst Academcy]
/// #h(1fr) _Exercise Sheet 3_ /// #h(1fr) _Exercise Sheet 3_
/// ], /// ],
/// ) /// )

View File

@ -38,7 +38,6 @@ impl cbor {
/// This function is deprecated. The [`cbor`] function now accepts bytes /// This function is deprecated. The [`cbor`] function now accepts bytes
/// directly. /// directly.
#[func(title = "Decode CBOR")] #[func(title = "Decode CBOR")]
#[deprecated = "`cbor.decode` is deprecated, directly pass bytes to `cbor` instead"]
pub fn decode( pub fn decode(
engine: &mut Engine, engine: &mut Engine,
/// CBOR data. /// CBOR data.

View File

@ -100,7 +100,6 @@ impl csv {
/// This function is deprecated. The [`csv`] function now accepts bytes /// This function is deprecated. The [`csv`] function now accepts bytes
/// directly. /// directly.
#[func(title = "Decode CSV")] #[func(title = "Decode CSV")]
#[deprecated = "`csv.decode` is deprecated, directly pass bytes to `csv` instead"]
pub fn decode( pub fn decode(
engine: &mut Engine, engine: &mut Engine,
/// CSV data. /// CSV data.

View File

@ -69,7 +69,6 @@ impl json {
/// This function is deprecated. The [`json`] function now accepts bytes /// This function is deprecated. The [`json`] function now accepts bytes
/// directly. /// directly.
#[func(title = "Decode JSON")] #[func(title = "Decode JSON")]
#[deprecated = "`json.decode` is deprecated, directly pass bytes to `json` instead"]
pub fn decode( pub fn decode(
engine: &mut Engine, engine: &mut Engine,
/// JSON data. /// JSON data.

View File

@ -48,7 +48,6 @@ impl toml {
/// This function is deprecated. The [`toml`] function now accepts bytes /// This function is deprecated. The [`toml`] function now accepts bytes
/// directly. /// directly.
#[func(title = "Decode TOML")] #[func(title = "Decode TOML")]
#[deprecated = "`toml.decode` is deprecated, directly pass bytes to `toml` instead"]
pub fn decode( pub fn decode(
engine: &mut Engine, engine: &mut Engine,
/// TOML data. /// TOML data.

View File

@ -81,7 +81,6 @@ impl xml {
/// This function is deprecated. The [`xml`] function now accepts bytes /// This function is deprecated. The [`xml`] function now accepts bytes
/// directly. /// directly.
#[func(title = "Decode XML")] #[func(title = "Decode XML")]
#[deprecated = "`xml.decode` is deprecated, directly pass bytes to `xml` instead"]
pub fn decode( pub fn decode(
engine: &mut Engine, engine: &mut Engine,
/// XML data. /// XML data.

View File

@ -59,7 +59,6 @@ impl yaml {
/// This function is deprecated. The [`yaml`] function now accepts bytes /// This function is deprecated. The [`yaml`] function now accepts bytes
/// directly. /// directly.
#[func(title = "Decode YAML")] #[func(title = "Decode YAML")]
#[deprecated = "`yaml.decode` is deprecated, directly pass bytes to `yaml` instead"]
pub fn decode( pub fn decode(
engine: &mut Engine, engine: &mut Engine,
/// YAML data. /// YAML data.

View File

@ -10,31 +10,6 @@ use crate::foundations::{category, Category, Module, Scope, Symbol, Value};
#[category] #[category]
pub static SYMBOLS: Category; pub static SYMBOLS: Category;
/// Hook up all `symbol` definitions.
pub(super) fn define(global: &mut Scope) {
global.start_category(SYMBOLS);
extend_scope_from_codex_module(global, codex::ROOT);
}
/// Hook up all math `symbol` definitions, i.e., elements of the `sym` module.
pub(super) fn define_math(math: &mut Scope) {
extend_scope_from_codex_module(math, codex::SYM);
}
fn extend_scope_from_codex_module(scope: &mut Scope, module: codex::Module) {
for (name, binding) in module.iter() {
let value = match binding.def {
codex::Def::Symbol(s) => Value::Symbol(s.into()),
codex::Def::Module(m) => Value::Module(Module::new(name, m.into())),
};
let scope_binding = scope.define(name, value);
if let Some(message) = binding.deprecation {
scope_binding.deprecated(message);
}
}
}
impl From<codex::Module> for Scope { impl From<codex::Module> for Scope {
fn from(module: codex::Module) -> Scope { fn from(module: codex::Module) -> Scope {
let mut scope = Self::new(); let mut scope = Self::new();
@ -51,3 +26,24 @@ impl From<codex::Symbol> for Symbol {
} }
} }
} }
fn extend_scope_from_codex_module(scope: &mut Scope, module: codex::Module) {
for (name, definition) in module.iter() {
let value = match definition {
codex::Def::Symbol(s) => Value::Symbol(s.into()),
codex::Def::Module(m) => Value::Module(Module::new(name, m.into())),
};
scope.define(name, value);
}
}
/// Hook up all `symbol` definitions.
pub(super) fn define(global: &mut Scope) {
global.start_category(SYMBOLS);
extend_scope_from_codex_module(global, codex::ROOT);
}
/// Hook up all math `symbol` definitions, i.e., elements of the `sym` module.
pub(super) fn define_math(math: &mut Scope) {
extend_scope_from_codex_module(math, codex::SYM);
}

View File

@ -171,7 +171,6 @@ impl ImageElem {
/// #image.decode(changed) /// #image.decode(changed)
/// ``` /// ```
#[func(title = "Decode Image")] #[func(title = "Decode Image")]
#[deprecated = "`image.decode` is deprecated, directly pass bytes to `image` instead"]
pub fn decode( pub fn decode(
span: Span, span: Span,
/// The data to decode as an image. Can be a string for SVGs. /// The data to decode as an image. Can be a string for SVGs.

View File

@ -24,7 +24,7 @@ pub use self::shape::*;
pub use self::stroke::*; pub use self::stroke::*;
pub use self::tiling::*; pub use self::tiling::*;
use crate::foundations::{category, Category, Element, Scope, Type}; use crate::foundations::{category, Category, Scope, Type};
/// Drawing and data visualization. /// Drawing and data visualization.
/// ///
@ -49,10 +49,8 @@ pub(super) fn define(global: &mut Scope) {
global.define_elem::<CircleElem>(); global.define_elem::<CircleElem>();
global.define_elem::<PolygonElem>(); global.define_elem::<PolygonElem>();
global.define_elem::<CurveElem>(); global.define_elem::<CurveElem>();
global global.define_elem::<PathElem>();
.define("path", Element::of::<PathElem>())
.deprecated("the `path` function is deprecated, use `curve` instead"); // Compatibility.
global global.define("pattern", Type::of::<Tiling>());
.define("pattern", Type::of::<Tiling>())
.deprecated("the name `pattern` is deprecated, use `tiling` instead");
} }

View File

@ -23,7 +23,7 @@ use crate::visualize::{FillRule, Paint, Stroke};
/// ``` /// ```
/// ///
/// # Deprecation /// # Deprecation
/// This function is deprecated. The [`curve`] function should be used instead. /// This element is deprecated. The [`curve`] element should be used instead.
#[elem(Show)] #[elem(Show)]
pub struct PathElem { pub struct PathElem {
/// How to fill the path. /// How to fill the path.

View File

@ -31,37 +31,18 @@ pub fn scope(_: TokenStream, item: syn::Item) -> Result<TokenStream> {
let mut definitions = vec![]; let mut definitions = vec![];
let mut constructor = quote! { None }; let mut constructor = quote! { None };
for child in &mut item.items { for child in &mut item.items {
let bare: BareType; let def = match child {
let (mut def, attrs) = match child { syn::ImplItem::Const(item) => handle_const(&self_ty_expr, item)?,
syn::ImplItem::Const(item) => { syn::ImplItem::Fn(item) => match handle_fn(self_ty, item)? {
(handle_const(&self_ty_expr, item)?, &item.attrs) FnKind::Member(tokens) => tokens,
} FnKind::Constructor(tokens) => {
syn::ImplItem::Fn(item) => ( constructor = tokens;
match handle_fn(self_ty, item)? { continue;
FnKind::Member(tokens) => tokens, }
FnKind::Constructor(tokens) => { },
constructor = tokens; syn::ImplItem::Verbatim(item) => handle_type_or_elem(item)?,
continue;
}
},
&item.attrs,
),
syn::ImplItem::Verbatim(item) => {
bare = syn::parse2(item.clone())?;
(handle_type_or_elem(&bare)?, &bare.attrs)
}
_ => bail!(child, "unexpected item in scope"), _ => bail!(child, "unexpected item in scope"),
}; };
if let Some(message) = attrs.iter().find_map(|attr| match &attr.meta {
syn::Meta::NameValue(pair) if pair.path.is_ident("deprecated") => {
Some(&pair.value)
}
_ => None,
}) {
def = quote! { #def.deprecated(#message) }
}
definitions.push(def); definitions.push(def);
} }
@ -80,7 +61,6 @@ pub fn scope(_: TokenStream, item: syn::Item) -> Result<TokenStream> {
#constructor #constructor
} }
#[allow(deprecated)]
fn scope() -> #foundations::Scope { fn scope() -> #foundations::Scope {
let mut scope = #foundations::Scope::deduplicating(); let mut scope = #foundations::Scope::deduplicating();
#(#definitions;)* #(#definitions;)*
@ -98,7 +78,8 @@ fn handle_const(self_ty: &TokenStream, item: &syn::ImplItemConst) -> Result<Toke
} }
/// Process a type item. /// Process a type item.
fn handle_type_or_elem(item: &BareType) -> Result<TokenStream> { fn handle_type_or_elem(item: &TokenStream) -> Result<TokenStream> {
let item: BareType = syn::parse2(item.clone())?;
let ident = &item.ident; let ident = &item.ident;
let define = if item.attrs.iter().any(|attr| attr.path().is_ident("elem")) { let define = if item.attrs.iter().any(|attr| attr.path().is_ident("elem")) {
quote! { define_elem } quote! { define_elem }

View File

@ -69,7 +69,7 @@ fn resolve_definition(head: &str, base: &str) -> StrResult<String> {
let Some(category) = category else { bail!("{head} has no category") }; let Some(category) = category else { bail!("{head} has no category") };
let name = parts.next().ok_or("link is missing first part")?; let name = parts.next().ok_or("link is missing first part")?;
let value = focus.field(name, ())?; let value = focus.field(name)?;
// Handle grouped functions. // Handle grouped functions.
if let Some(group) = GROUPS.iter().find(|group| { if let Some(group) = GROUPS.iter().find(|group| {
@ -88,7 +88,7 @@ fn resolve_definition(head: &str, base: &str) -> StrResult<String> {
let mut route = format!("{}reference/{}/{name}", base, category.name()); let mut route = format!("{}reference/{}/{name}", base, category.name());
if let Some(next) = parts.next() { if let Some(next) = parts.next() {
if let Ok(field) = value.field(next, ()) { if let Ok(field) = value.field(next) {
route.push_str("/#definitions-"); route.push_str("/#definitions-");
route.push_str(next); route.push_str(next);
if let Some(next) = parts.next() { if let Some(next) = parts.next() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 391 B

View File

@ -1,3 +0,0 @@
--- cbor-decode-deprecated ---
// Warning: 15-21 `cbor.decode` is deprecated, directly pass bytes to `cbor` instead
#let _ = cbor.decode

View File

@ -29,7 +29,3 @@
--- csv-invalid-delimiter --- --- csv-invalid-delimiter ---
// Error: 41-51 delimiter must be an ASCII character // Error: 41-51 delimiter must be an ASCII character
#csv("/assets/data/zoo.csv", delimiter: "\u{2008}") #csv("/assets/data/zoo.csv", delimiter: "\u{2008}")
--- csv-decode-deprecated ---
// Warning: 14-20 `csv.decode` is deprecated, directly pass bytes to `csv` instead
#let _ = csv.decode

View File

@ -9,10 +9,6 @@
// Error: 7-30 failed to parse JSON (expected value at line 3 column 14) // Error: 7-30 failed to parse JSON (expected value at line 3 column 14)
#json("/assets/data/bad.json") #json("/assets/data/bad.json")
--- json-decode-deprecated ---
// Warning: 15-21 `json.decode` is deprecated, directly pass bytes to `json` instead
#let _ = json.decode
--- issue-3363-json-large-number --- --- issue-3363-json-large-number ---
// Big numbers (larger than what i64 can store) should just lose some precision // Big numbers (larger than what i64 can store) should just lose some precision
// but not overflow // but not overflow

View File

@ -39,7 +39,3 @@
--- toml-invalid --- --- toml-invalid ---
// Error: 7-30 failed to parse TOML (expected `.`, `=` at line 1 column 16) // Error: 7-30 failed to parse TOML (expected `.`, `=` at line 1 column 16)
#toml("/assets/data/bad.toml") #toml("/assets/data/bad.toml")
--- toml-decode-deprecated ---
// Warning: 15-21 `toml.decode` is deprecated, directly pass bytes to `toml` instead
#let _ = toml.decode

View File

@ -26,7 +26,3 @@
--- xml-invalid --- --- xml-invalid ---
// Error: 6-28 failed to parse XML (found closing tag 'data' instead of 'hello' in line 3) // Error: 6-28 failed to parse XML (found closing tag 'data' instead of 'hello' in line 3)
#xml("/assets/data/bad.xml") #xml("/assets/data/bad.xml")
--- xml-decode-deprecated ---
// Warning: 14-20 `xml.decode` is deprecated, directly pass bytes to `xml` instead
#let _ = xml.decode

View File

@ -15,7 +15,3 @@
--- yaml-invalid --- --- yaml-invalid ---
// Error: 7-30 failed to parse YAML (did not find expected ',' or ']' at line 2 column 1, while parsing a flow sequence at line 1 column 18) // Error: 7-30 failed to parse YAML (did not find expected ',' or ']' at line 2 column 1, while parsing a flow sequence at line 1 column 18)
#yaml("/assets/data/bad.yaml") #yaml("/assets/data/bad.yaml")
--- yaml-decode-deprecated ---
// Warning: 15-21 `yaml.decode` is deprecated, directly pass bytes to `yaml` instead
#let _ = yaml.decode

View File

@ -147,7 +147,3 @@
repr(envelope.fly), repr(envelope.fly),
`symbol("🖅")`.text, `symbol("🖅")`.text,
) )
--- symbol-sect-deprecated ---
// Warning: 5-9 `sect` is deprecated, use `inter` instead
$ A sect B = A inter B $

View File

@ -161,27 +161,22 @@ A #box(image("/assets/images/tiger.jpg", height: 1cm, width: 80%)) B
--- image-decode-svg --- --- image-decode-svg ---
// Test parsing from svg data // Test parsing from svg data
// Warning: 8-14 `image.decode` is deprecated, directly pass bytes to `image` instead
#image.decode(`<svg xmlns="http://www.w3.org/2000/svg" height="140" width="500"><ellipse cx="200" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2" /></svg>`.text, format: "svg") #image.decode(`<svg xmlns="http://www.w3.org/2000/svg" height="140" width="500"><ellipse cx="200" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2" /></svg>`.text, format: "svg")
--- image-decode-bad-svg --- --- image-decode-bad-svg ---
// Error: 2-168 failed to parse SVG (missing root node) // Error: 2-168 failed to parse SVG (missing root node)
// Warning: 8-14 `image.decode` is deprecated, directly pass bytes to `image` instead
#image.decode(`<svg height="140" width="500"><ellipse cx="200" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2" /></svg>`.text, format: "svg") #image.decode(`<svg height="140" width="500"><ellipse cx="200" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2" /></svg>`.text, format: "svg")
--- image-decode-detect-format --- --- image-decode-detect-format ---
// Test format auto detect // Test format auto detect
// Warning: 8-14 `image.decode` is deprecated, directly pass bytes to `image` instead
#image.decode(read("/assets/images/tiger.jpg", encoding: none), width: 80%) #image.decode(read("/assets/images/tiger.jpg", encoding: none), width: 80%)
--- image-decode-specify-format --- --- image-decode-specify-format ---
// Test format manual // Test format manual
// Warning: 8-14 `image.decode` is deprecated, directly pass bytes to `image` instead
#image.decode(read("/assets/images/tiger.jpg", encoding: none), format: "jpg", width: 80%) #image.decode(read("/assets/images/tiger.jpg", encoding: none), format: "jpg", width: 80%)
--- image-decode-specify-wrong-format --- --- image-decode-specify-wrong-format ---
// Error: 2-91 failed to decode image (Format error decoding Png: Invalid PNG signature.) // Error: 2-91 failed to decode image (Format error decoding Png: Invalid PNG signature.)
// Warning: 8-14 `image.decode` is deprecated, directly pass bytes to `image` instead
#image.decode(read("/assets/images/tiger.jpg", encoding: none), format: "png", width: 80%) #image.decode(read("/assets/images/tiger.jpg", encoding: none), format: "png", width: 80%)
--- image-pixmap-empty --- --- image-pixmap-empty ---

View File

@ -6,7 +6,6 @@
columns: (1fr, 1fr), columns: (1fr, 1fr),
rows: (1fr, 1fr, 1fr), rows: (1fr, 1fr, 1fr),
align: center + horizon, align: center + horizon,
// Warning: 3-7 the `path` function is deprecated, use `curve` instead
path( path(
fill: red, fill: red,
closed: true, closed: true,
@ -15,7 +14,6 @@
((0%, 50%), (4%, 4%)), ((0%, 50%), (4%, 4%)),
((50%, 0%), (4%, 4%)), ((50%, 0%), (4%, 4%)),
), ),
// Warning: 3-7 the `path` function is deprecated, use `curve` instead
path( path(
fill: purple, fill: purple,
stroke: 1pt, stroke: 1pt,
@ -24,7 +22,6 @@
(0pt, 30pt), (0pt, 30pt),
(30pt, 0pt), (30pt, 0pt),
), ),
// Warning: 3-7 the `path` function is deprecated, use `curve` instead
path( path(
fill: blue, fill: blue,
stroke: 1pt, stroke: 1pt,
@ -33,7 +30,6 @@
((30%, 60%), (-20%, 0%), (0%, 0%)), ((30%, 60%), (-20%, 0%), (0%, 0%)),
((50%, 30%), (60%, -30%), (60%, 0%)), ((50%, 30%), (60%, -30%), (60%, 0%)),
), ),
// Warning: 3-7 the `path` function is deprecated, use `curve` instead
path( path(
stroke: 5pt, stroke: 5pt,
closed: true, closed: true,
@ -41,7 +37,6 @@
(30pt, 30pt), (30pt, 30pt),
(15pt, 0pt), (15pt, 0pt),
), ),
// Warning: 3-7 the `path` function is deprecated, use `curve` instead
path( path(
fill: red, fill: red,
fill-rule: "non-zero", fill-rule: "non-zero",
@ -52,7 +47,6 @@
(0pt, 20pt), (0pt, 20pt),
(40pt, 50pt), (40pt, 50pt),
), ),
// Warning: 3-7 the `path` function is deprecated, use `curve` instead
path( path(
fill: red, fill: red,
fill-rule: "even-odd", fill-rule: "even-odd",
@ -67,22 +61,18 @@
--- path-bad-vertex --- --- path-bad-vertex ---
// Error: 7-9 path vertex must have 1, 2, or 3 points // Error: 7-9 path vertex must have 1, 2, or 3 points
// Warning: 2-6 the `path` function is deprecated, use `curve` instead
#path(()) #path(())
--- path-bad-point-count --- --- path-bad-point-count ---
// Error: 7-47 path vertex must have 1, 2, or 3 points // Error: 7-47 path vertex must have 1, 2, or 3 points
// Warning: 2-6 the `path` function is deprecated, use `curve` instead
#path(((0%, 0%), (0%, 0%), (0%, 0%), (0%, 0%))) #path(((0%, 0%), (0%, 0%), (0%, 0%), (0%, 0%)))
--- path-bad-point-array --- --- path-bad-point-array ---
// Error: 7-31 point array must contain exactly two entries // Error: 7-31 point array must contain exactly two entries
// Warning: 2-6 the `path` function is deprecated, use `curve` instead
#path(((0%, 0%), (0%, 0%, 0%))) #path(((0%, 0%), (0%, 0%, 0%)))
--- path-infinite-length --- --- path-infinite-length ---
// Error: 2-42 cannot create path with infinite length // Error: 2-42 cannot create path with infinite length
// Warning: 2-6 the `path` function is deprecated, use `curve` instead
#path((0pt, 0pt), (float.inf * 1pt, 0pt)) #path((0pt, 0pt), (float.inf * 1pt, 0pt))
--- issue-path-in-sized-container --- --- issue-path-in-sized-container ---
@ -92,7 +82,6 @@
fill: aqua, fill: aqua,
width: 20pt, width: 20pt,
height: 15pt, height: 15pt,
// Warning: 3-7 the `path` function is deprecated, use `curve` instead
path( path(
(0pt, 0pt), (0pt, 0pt),
(10pt, 10pt), (10pt, 10pt),

View File

@ -159,7 +159,5 @@
--- tiling-pattern-compatibility --- --- tiling-pattern-compatibility ---
#set page(width: auto, height: auto, margin: 0pt) #set page(width: auto, height: auto, margin: 0pt)
// Warning: 10-17 the name `pattern` is deprecated, use `tiling` instead
#let t = pattern(size: (10pt, 10pt), line(stroke: 4pt, start: (0%, 0%), end: (100%, 100%))) #let t = pattern(size: (10pt, 10pt), line(stroke: 4pt, start: (0%, 0%), end: (100%, 100%)))
#rect(width: 50pt, height: 50pt, fill: t) #rect(width: 50pt, height: 50pt, fill: t)