diff options
author | Karel Peeters <karel.peeters.leuven@gmail.com> | 2021-07-23 18:40:23 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2021-07-31 13:47:39 +0200 |
commit | 01a7a4d7158c2d227dc55199fe1a4306dcbe68cf (patch) | |
tree | a6e8ee560363abec287fe680faa4fcea20e238d6 /src | |
parent | 9833b6745d74896620ea760f3bf81f344a105f30 (diff) |
Also implement div-style must_use_type annotation.
Diffstat (limited to 'src')
-rw-r--r-- | src/codegen/mod.rs | 2 | ||||
-rw-r--r-- | src/ir/annotations.rs | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 76c64e4a..2522922a 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2023,7 +2023,7 @@ impl CodeGenerator for CompInfo { attributes.push(attributes::derives(&derives)) } - if ctx.must_use_type_by_name(item) { + if item.annotations().must_use_type() || ctx.must_use_type_by_name(item) { attributes.push(attributes::must_use()); } diff --git a/src/ir/annotations.rs b/src/ir/annotations.rs index 12664f60..4b571eaa 100644 --- a/src/ir/annotations.rs +++ b/src/ir/annotations.rs @@ -42,6 +42,8 @@ pub struct Annotations { disallow_debug: bool, /// Manually disable deriving/implement default on this type. disallow_default: bool, + /// Whether to add a #[must_use] annotation to this type. + must_use_type: bool, /// Whether fields should be marked as private or not. You can set this on /// structs (it will apply to all the fields), or individual fields. private_fields: Option<bool>, @@ -84,6 +86,7 @@ impl Default for Annotations { disallow_copy: false, disallow_debug: false, disallow_default: false, + must_use_type: false, private_fields: None, accessor_kind: None, constify_enum_variant: false, @@ -163,6 +166,11 @@ impl Annotations { self.disallow_default } + /// Should this type get a `#[must_use]` annotation? + pub fn must_use_type(&self) -> bool { + self.must_use_type + } + /// Should the fields be private? pub fn private_fields(&self) -> Option<bool> { self.private_fields @@ -190,6 +198,7 @@ impl Annotations { "nocopy" => self.disallow_copy = true, "nodebug" => self.disallow_debug = true, "nodefault" => self.disallow_default = true, + "mustusetype" => self.must_use_type = true, "replaces" => { self.use_instead_of = Some( attr.value.split("::").map(Into::into).collect(), |