-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add: Support #[deprecated] attribute #860
Changes from 18 commits
f86d749
87561a4
e001222
d75abe9
19845d8
608a31e
ff164fb
6c29ff7
5733bf8
b5ae00e
a9587bb
fbe51c6
6bfb3ff
31fff88
a439a3a
bb39e3a
1a3f566
81bf4ca
50b6171
05d7035
19db2a4
d13bb58
5b119db
507eaa5
5809afc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,13 +35,15 @@ pub enum AnnotationValue { | |
pub struct AnnotationSet { | ||
annotations: HashMap<String, AnnotationValue>, | ||
pub must_use: bool, | ||
pub deprecated: Option<String>, | ||
} | ||
|
||
impl AnnotationSet { | ||
pub fn new() -> AnnotationSet { | ||
AnnotationSet { | ||
annotations: HashMap::new(), | ||
must_use: false, | ||
deprecated: None, | ||
} | ||
} | ||
|
||
|
@@ -53,6 +55,27 @@ impl AnnotationSet { | |
self.must_use && config.language != Language::Cython | ||
} | ||
|
||
pub(crate) fn deprecated_note(&self, config: &Config) -> Option<String> { | ||
sevenc-nanashi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if config.language == Language::Cython { | ||
return None; | ||
} | ||
|
||
self.deprecated.clone() | ||
sevenc-nanashi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
pub(crate) fn format_deprecated_note( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea around where to put these utilities. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't use |
||
&self, | ||
format_without_note: Option<&str>, | ||
format_with_note: Option<&str>, | ||
note: &str, | ||
) -> Option<String> { | ||
if note.is_empty() { | ||
return format_without_note.map(|x| x.to_string()); | ||
} | ||
format_with_note | ||
.map(|format_with_note| format_with_note.replace("{}", format!("{:?}", note).as_str())) | ||
} | ||
|
||
pub fn load(attrs: &[syn::Attribute]) -> Result<AnnotationSet, String> { | ||
let lines = attrs.get_comment_lines(); | ||
let lines: Vec<&str> = lines | ||
|
@@ -68,7 +91,7 @@ impl AnnotationSet { | |
.collect(); | ||
|
||
let must_use = attrs.has_attr_word("must_use"); | ||
|
||
let deprecated = attrs.find_deprecated_note()?; | ||
let mut annotations = HashMap::new(); | ||
|
||
// Look at each line for an annotation | ||
|
@@ -118,6 +141,7 @@ impl AnnotationSet { | |
Ok(AnnotationSet { | ||
annotations, | ||
must_use, | ||
deprecated, | ||
}) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref: #859