Skip to content

Commit f2a1e85

Browse files
committed
Add some #[must_use] to manually implemented builder types
... or improve their messages a bit.
1 parent 3d87909 commit f2a1e85

File tree

6 files changed

+10
-3
lines changed

6 files changed

+10
-3
lines changed

gio/src/io_extension_point.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::io_extension::IOExtension;
99

1010
/// Builder for extension points.
1111
#[derive(Debug)]
12-
#[must_use = "Builder doesn't do anything unless built"]
12+
#[must_use = "The builder must be built to be used"]
1313
pub struct IOExtensionPointBuilder<'a> {
1414
name: &'a str,
1515
required_type: Option<Type>,
@@ -31,6 +31,7 @@ impl<'a> IOExtensionPointBuilder<'a> {
3131
}
3232
}
3333

34+
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
3435
pub fn build(self) -> IOExtensionPoint {
3536
unsafe {
3637
let ep = IOExtensionPoint::from_glib_none(ffi::g_io_extension_point_register(

gio/src/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use glib::translate::{from_glib_borrow, from_glib_none, IntoGlib, ToGlibPtr};
66
use glib::variant::FromVariant;
77
use glib::{BoolError, IsA, ToVariant};
88

9-
#[must_use]
9+
#[must_use = "The builder must be built to be used"]
1010
pub struct BindingBuilder<'a> {
1111
settings: &'a Settings,
1212
key: &'a str,

glib/src/enums.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ impl Eq for FlagsValue {}
675675
/// ```
676676
///
677677
/// If setting/unsetting any value fails, `build()` returns `None`.
678+
#[must_use = "The builder must be built to be used"]
678679
pub struct FlagsBuilder<'a>(&'a FlagsClass, Option<Value>);
679680
impl<'a> FlagsBuilder<'a> {
680681
fn new(flags_class: &FlagsClass) -> FlagsBuilder {
@@ -741,6 +742,7 @@ impl<'a> FlagsBuilder<'a> {
741742
}
742743

743744
/// Converts to the final `Value`, unless any previous setting/unsetting of flags failed.
745+
#[must_use = "Value returned from the builder should probably be used"]
744746
pub fn build(self) -> Option<Value> {
745747
self.1
746748
}

glib/src/gstring_builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::str;
1313
wrapper! {
1414
/// A mutable text buffer that grows automatically.
1515
#[doc(alias = "GString")]
16+
#[must_use = "The builder must be built to be used"]
1617
pub struct GStringBuilder(Boxed<ffi::GString>);
1718

1819
match fn {
@@ -96,6 +97,7 @@ impl GStringBuilder {
9697
/// # Panics
9798
///
9899
/// If the string builder contains invalid UTF-8 this function panics.
100+
#[must_use = "String returned from the builder should probably be used"]
99101
pub fn into_string(self) -> crate::GString {
100102
unsafe {
101103
let s = mem::ManuallyDrop::new(self);

glib/src/object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3317,7 +3317,7 @@ type TransformFn =
33173317
Option<Box<dyn Fn(&crate::Binding, &Value) -> Option<Value> + Send + Sync + 'static>>;
33183318

33193319
/// Builder for object property bindings.
3320-
#[must_use]
3320+
#[must_use = "The builder must be built to be used"]
33213321
pub struct BindingBuilder<'a> {
33223322
source: &'a ObjectRef,
33233323
source_property: &'a str,

glib/src/subclass/signal.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::{fmt, num::NonZeroU32};
1313

1414
/// Builder for signals.
1515
#[allow(clippy::type_complexity)]
16+
#[must_use = "The builder must be built to be used"]
1617
pub struct SignalBuilder<'a> {
1718
name: &'a str,
1819
flags: SignalFlags,
@@ -442,6 +443,7 @@ impl<'a> SignalBuilder<'a> {
442443
///
443444
/// This does not register the signal yet, which only happens as part of object type
444445
/// registration.
446+
#[must_use = "Signal returned from the builder must be used for it to be registered"]
445447
pub fn build(self) -> Signal {
446448
let flags = if self.flags
447449
& (SignalFlags::RUN_FIRST | SignalFlags::RUN_LAST | SignalFlags::RUN_CLEANUP)

0 commit comments

Comments
 (0)