summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/diag.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-library/src/diag.rs')
-rw-r--r--crates/typst-library/src/diag.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/typst-library/src/diag.rs b/crates/typst-library/src/diag.rs
index bd4c90a1..49cbd02c 100644
--- a/crates/typst-library/src/diag.rs
+++ b/crates/typst-library/src/diag.rs
@@ -11,6 +11,7 @@ use ecow::{eco_vec, EcoVec};
use typst_syntax::package::{PackageSpec, PackageVersion};
use typst_syntax::{Span, Spanned, SyntaxError};
+use crate::engine::Engine;
use crate::{World, WorldExt};
/// Early-return with a [`StrResult`] or [`SourceResult`].
@@ -228,6 +229,23 @@ 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).
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Tracepoint {