-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto merge of #11449 : rcatolino/rust/assign-binop-handling, r=alexcr…
…ichton So far the following code ``` struct Foo; fn main() { let mut t = Foo; let ref b = Foo; a += *b; } ``` errors with ``` test.rs:15:3: 13:11 error: binary operation + cannot be applied to type `Foo` test.rs:15 *a += *b; ``` Since assignment-operators are no longer expanded to ```left = left OP right``` but are independents operators it should be ``` test.rs:15:3: 13:11 error: binary operation += cannot be applied to type `Foo` test.rs:15 *a += *b; ``` to make it clear that implementing Add for Foo is not gonna work. (cf issues #11143, #11344) Besides that, we also need to typecheck the rhs expression even if the operator has no implementation, or we end up with unknown types for the nodes of the rhs and an ICE later on while resolving types. (once again cf #11143 and #11344). This probably would get fixed with #5992, but in the meantime it's a confusing error to stumble upon. @pcwalton, you wrote the original code, what do you think? (closes #11143 and #11344)
- Loading branch information
Showing
3 changed files
with
34 additions
and
14 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
17 changes: 17 additions & 0 deletions
17
src/test/compile-fail/assignment-operator-unimplemented.rs
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,17 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
struct Foo; | ||
|
||
fn main() { | ||
let mut a = Foo; | ||
let ref b = Foo; | ||
a += *b; //~ Error: binary assignment operation += cannot be applied to type `Foo` | ||
} |
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