@@ -253,8 +253,8 @@ pub struct Binding {
253253 span : Span ,
254254 /// The category of the binding.
255255 category : Option < Category > ,
256- /// A deprecation message for the definition .
257- deprecation : Option < & ' static str > ,
256+ /// The deprecation information if this item is deprecated .
257+ deprecation : Option < Box < Deprecation > > ,
258258}
259259
260260/// The different kinds of slots.
@@ -284,8 +284,8 @@ impl Binding {
284284 }
285285
286286 /// Marks this binding as deprecated, with the given `message`.
287- pub fn deprecated ( & mut self , message : & ' static str ) -> & mut Self {
288- self . deprecation = Some ( message ) ;
287+ pub fn deprecated ( & mut self , deprecation : Deprecation ) -> & mut Self {
288+ self . deprecation = Some ( Box :: new ( deprecation ) ) ;
289289 self
290290 }
291291
@@ -300,8 +300,8 @@ impl Binding {
300300 /// - pass `()` to ignore the message.
301301 /// - pass `(&mut engine, span)` to emit a warning into the engine.
302302 pub fn read_checked ( & self , sink : impl DeprecationSink ) -> & Value {
303- if let Some ( message ) = self . deprecation {
304- sink. emit ( message) ;
303+ if let Some ( info ) = & self . deprecation {
304+ sink. emit ( info . message , info . until ) ;
305305 }
306306 & self . value
307307 }
@@ -337,8 +337,8 @@ impl Binding {
337337 }
338338
339339 /// A deprecation message for the value, if any.
340- pub fn deprecation ( & self ) -> Option < & ' static str > {
341- self . deprecation
340+ pub fn deprecation ( & self ) -> Option < & Deprecation > {
341+ self . deprecation . as_deref ( )
342342 }
343343
344344 /// The category of the value, if any.
@@ -356,6 +356,51 @@ pub enum Capturer {
356356 Context ,
357357}
358358
359+ /// Information about a deprecated binding.
360+ #[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash ) ]
361+ pub struct Deprecation {
362+ /// A deprecation message for the definition.
363+ message : & ' static str ,
364+ /// A version in which the deprecated binding is planned to be removed.
365+ until : Option < & ' static str > ,
366+ }
367+
368+ impl Deprecation {
369+ /// Creates new deprecation info with a default message to display when
370+ /// emitting the deprecation warning.
371+ pub fn new ( ) -> Self {
372+ Self { message : "item is deprecated" , until : None }
373+ }
374+
375+ /// Set the message to display when emitting the deprecation warning.
376+ pub fn with_message ( mut self , message : & ' static str ) -> Self {
377+ self . message = message;
378+ self
379+ }
380+
381+ /// Set the version in which the binding is planned to be removed.
382+ pub fn with_until ( mut self , version : & ' static str ) -> Self {
383+ self . until = Some ( version) ;
384+ self
385+ }
386+
387+ /// The message to display when emitting the deprecation warning.
388+ pub fn message ( & self ) -> & ' static str {
389+ self . message
390+ }
391+
392+ /// The version in which the binding is planned to be removed.
393+ pub fn until ( & self ) -> Option < & ' static str > {
394+ self . until
395+ }
396+ }
397+
398+ impl Default for Deprecation {
399+ fn default ( ) -> Self {
400+ Self :: new ( )
401+ }
402+ }
403+
359404/// The error message when trying to mutate a variable from the standard
360405/// library.
361406#[ cold]
0 commit comments