Skip to content

Commit 18edae4

Browse files
expound on limitations of Rust's trait-based operator overloading
Part of rust-lang#29330
1 parent f65d96f commit 18edae4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/libcore/ops.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010

1111
//! Overloadable operators.
1212
//!
13-
//! Implementing these traits allows you to get an effect similar to
14-
//! overloading operators.
13+
//! Implementing these traits allows you to overload certain operators.
1514
//!
1615
//! Some of these traits are imported by the prelude, so they are available in
17-
//! every Rust program.
16+
//! every Rust program. Only operators backed by traits can be overloaded. For
17+
//! example, the addition operator (`+`) can be overloaded through the `Add`
18+
//! trait, but since the assignment operator (`=`) has no backing trait, there
19+
//! is no way of overloading its semantics. Additionally, this module does not
20+
//! provide any mechanism to create new operators. If traitless overloading or
21+
//! custom operators are required, you should look toward macros or compiler
22+
//! plugins to extend Rust's syntax.
1823
//!
1924
//! Many of the operators take their operands by value. In non-generic
2025
//! contexts involving built-in types, this is usually not a problem.

0 commit comments

Comments
 (0)