Can I mark a function as deprecated?

Since Rust 1.9.0 (2016 May 26th) you can use the #[deprecated] attribute in your own crates (RFC 1270). The syntax is:

#[deprecated(since="0.5.0", note="please use `new_method` instead")]
pub fn old_method() { ..; }

It will throw the following warning whenever you use old_method:

<anon>:6:5: 6:15 warning: use of deprecated item: please use `new_method` instead, #[warn(deprecated)] on by default
<anon>:6     old_method()

You may find more information in the RFC.

Leave a Comment