summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/diag.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2025-02-04 10:38:31 +0100
committerGitHub <noreply@github.com>2025-02-04 09:38:31 +0000
commit50ccd7d60f078f3617bfed5c4e8e1fd7d45ec340 (patch)
tree22c12abf76d2b2c20b49b569167ddf60fbe5b348 /crates/typst-library/src/diag.rs
parent5b3593e571826ae44a3aeb0e0f6f09face7291ac (diff)
Scope deprecations (#5798)
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 {