Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to concatenate strings with operator += results in an Internal Compiler Error #11344

Closed
Matthias247 opened this issue Jan 6, 2014 · 3 comments

Comments

@Matthias247
Copy link
Contributor

The following code produces an internal compiler error:

fn main() {
    let mut mystr = ~"";
    mystr += ~"abc";
    println(mystr);
}

Compiler output:

$ rustc.exe main.rs
main.rs:7:5: 7:20 error: binary operation + cannot be applied to type `~str`
main.rs:7     mystr += ~"abc";
              ^~~~~~~~~~~~~~~
error: internal compiler error: no type for node 48: expr "abc" (id=48) in fcx 0
x65041c0
This message reflects a bug in the Rust compiler.
We would appreciate a bug report: https://github.com/mozilla/rust/wiki/HOWTO-submit-a-Rust-bug-report
task 'rustc' failed at 'explicit failure', C:\Rust\rust\src\libsyntax\diagnostic.rs:75
task '<main>' failed at 'explicit failure', C:\Rust\rust\src\librustc\lib.rs:440
bors added a commit that referenced this issue Jan 10, 2014
…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)
@RichardlL
Copy link

Is There anyway around this?

@thestinger
Copy link
Contributor

Closed by #11449 (wasn't listed properly in the commit message).

@thestinger
Copy link
Contributor

@RichardlL: This bug isn't present anymore. It's correctly reporting that += cannot be applied without an ICE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants