-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow
&mut self
receivers in declare_class!
when not mutable
These are clearly unsound, and even though the error messages are pretty terrible, it is still better to disallow them.
- Loading branch information
Showing
5 changed files
with
147 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use objc2::rc::Id; | ||
use objc2::runtime::NSObject; | ||
use objc2::{declare_class, mutability, ClassType}; | ||
|
||
declare_class!( | ||
struct CustomObject; | ||
|
||
unsafe impl ClassType for CustomObject { | ||
type Super = NSObject; | ||
type Mutability = mutability::InteriorMutable; | ||
const NAME: &'static str = "CustomObject"; | ||
} | ||
|
||
unsafe impl CustomObject { | ||
#[method(initTest)] | ||
fn initTest(&mut self) -> &mut Self { | ||
unimplemented!() | ||
} | ||
|
||
#[method(testMethod)] | ||
fn test_method(&mut self) { | ||
unimplemented!() | ||
} | ||
|
||
#[method_id(testMethodId)] | ||
fn test_method_id(&mut self) -> Id<Self> { | ||
unimplemented!() | ||
} | ||
} | ||
); | ||
|
||
fn main() {} |
80 changes: 80 additions & 0 deletions
80
crates/test-ui/ui/declare_class_mut_self_not_mutable.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
error[E0277]: the trait bound `InteriorMutable: mutability::private::MutabilityIsMutable` is not satisfied | ||
--> ui/declare_class_mut_self_not_mutable.rs | ||
| | ||
| / declare_class!( | ||
| | struct CustomObject; | ||
| | | ||
| | unsafe impl ClassType for CustomObject { | ||
... | | ||
| | } | ||
| | ); | ||
| | ^ | ||
| | | | ||
| |_the trait `mutability::private::MutabilityIsMutable` is not implemented for `InteriorMutable` | ||
| required by a bound introduced by this call | ||
| | ||
= help: the following other types implement trait `mutability::private::MutabilityIsMutable`: | ||
Mutable | ||
MutableWithImmutableSuperclass<IS> | ||
= note: required for `CustomObject` to implement `IsMutable` | ||
= note: required for `extern "C" fn(&mut CustomObject, objc2::runtime::Sel) -> &mut CustomObject` to implement `MethodImplementation` | ||
note: required by a bound in `ClassBuilder::add_method` | ||
--> $WORKSPACE/crates/objc2/src/declare/mod.rs | ||
| | ||
| F: MethodImplementation<Callee = T>, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilder::add_method` | ||
= note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the trait bound `InteriorMutable: mutability::private::MutabilityIsMutable` is not satisfied | ||
--> ui/declare_class_mut_self_not_mutable.rs | ||
| | ||
| / declare_class!( | ||
| | struct CustomObject; | ||
| | | ||
| | unsafe impl ClassType for CustomObject { | ||
... | | ||
| | } | ||
| | ); | ||
| | ^ | ||
| | | | ||
| |_the trait `mutability::private::MutabilityIsMutable` is not implemented for `InteriorMutable` | ||
| required by a bound introduced by this call | ||
| | ||
= help: the following other types implement trait `mutability::private::MutabilityIsMutable`: | ||
Mutable | ||
MutableWithImmutableSuperclass<IS> | ||
= note: required for `CustomObject` to implement `IsMutable` | ||
= note: required for `extern "C" fn(&mut CustomObject, objc2::runtime::Sel)` to implement `MethodImplementation` | ||
note: required by a bound in `ClassBuilder::add_method` | ||
--> $WORKSPACE/crates/objc2/src/declare/mod.rs | ||
| | ||
| F: MethodImplementation<Callee = T>, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilder::add_method` | ||
= note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the trait bound `InteriorMutable: mutability::private::MutabilityIsMutable` is not satisfied | ||
--> ui/declare_class_mut_self_not_mutable.rs | ||
| | ||
| / declare_class!( | ||
| | struct CustomObject; | ||
| | | ||
| | unsafe impl ClassType for CustomObject { | ||
... | | ||
| | } | ||
| | ); | ||
| | ^ | ||
| | | | ||
| |_the trait `mutability::private::MutabilityIsMutable` is not implemented for `InteriorMutable` | ||
| required by a bound introduced by this call | ||
| | ||
= help: the following other types implement trait `mutability::private::MutabilityIsMutable`: | ||
Mutable | ||
MutableWithImmutableSuperclass<IS> | ||
= note: required for `CustomObject` to implement `IsMutable` | ||
= note: required for `extern "C" fn(&mut CustomObject, objc2::runtime::Sel) -> __IdReturnValue` to implement `MethodImplementation` | ||
note: required by a bound in `ClassBuilder::add_method` | ||
--> $WORKSPACE/crates/objc2/src/declare/mod.rs | ||
| | ||
| F: MethodImplementation<Callee = T>, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilder::add_method` | ||
= note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) |