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

String concatenation with + only type-checks if the first operand is an owned pointer #3682

Closed
andymatuschak opened this Issue Oct 6, 2012 · 8 comments

Comments

Projects
None yet
7 participants
@andymatuschak

andymatuschak commented Oct 6, 2012

I've got the following source file, with various permutations to the parameter on line 2:

fn main() {
    io::println(~"foo" + ~"foo");
}
  • ~"foo" + ~"foo": compiles as expected; outputs foofoo
  • "foo" + ~"foo": fails to compile: error: binary operation + cannot be applied to type &static/str
  • ~"foo" + "foo": compiles as expected; outputs foofoo
  • "foo" + "foo": fails to compile: error: binary operation + cannot be applied to type &static/str
  • ~"foo" + @"foo": compiles as expected; outputs foofoo
  • @"foo" + ~"foo": fails to compile: error: binary operation + cannot be applied to type @str
  • @"foo" + @"foo": fails to compile: error: binary operation + cannot be applied to type @str

This is f96a2a2 running on Mac OS 10.8.2.

@albx79

This comment has been minimized.

Show comment
Hide comment
@albx79

albx79 Nov 2, 2012

Because of this bug, there's an example in the tutorial (http://dl.rust-lang.org/doc/tutorial.html) that fails to compile:

fn main() { io::println("hello " + world::explore()); }

main.rs:2:24: 2:52 error: binary operation + cannot be applied to type &static/str

albx79 commented Nov 2, 2012

Because of this bug, there's an example in the tutorial (http://dl.rust-lang.org/doc/tutorial.html) that fails to compile:

fn main() { io::println("hello " + world::explore()); }

main.rs:2:24: 2:52 error: binary operation + cannot be applied to type &static/str

@brson

This comment has been minimized.

Show comment
Hide comment
@brson

brson Nov 3, 2012

Contributor

I've been annoyed by this a lot lately.

Contributor

brson commented Nov 3, 2012

I've been annoyed by this a lot lately.

@pnkfelix

This comment has been minimized.

Show comment
Hide comment
@pnkfelix

pnkfelix Mar 25, 2013

Member

An easy general workaround is to start any such concatenation expression E1 + E2 + ... with ~"", i.e. ~"" + E1 + E2 + ...

Member

pnkfelix commented Mar 25, 2013

An easy general workaround is to start any such concatenation expression E1 + E2 + ... with ~"", i.e. ~"" + E1 + E2 + ...

@pnkfelix

This comment has been minimized.

Show comment
Hide comment
@pnkfelix

pnkfelix Mar 25, 2013

Member

(obviously the previous suggestion is just allowing for some notational convenience; it is not attempting to address efficiency issues.)

Member

pnkfelix commented Mar 25, 2013

(obviously the previous suggestion is just allowing for some notational convenience; it is not attempting to address efficiency issues.)

@pnkfelix

This comment has been minimized.

Show comment
Hide comment
@pnkfelix

pnkfelix Mar 25, 2013

Member

Not critical for 0.6; de-milestoning

Member

pnkfelix commented Mar 25, 2013

Not critical for 0.6; de-milestoning

@graydon

This comment has been minimized.

Show comment
Hide comment
@graydon

graydon May 22, 2013

Contributor

Reproduced. Still valid. Papercut rather than wrong, though. Wondering if @nikomatsakis dynamic sized types proposal will fix some quantity of this.

Contributor

graydon commented May 22, 2013

Reproduced. Still valid. Papercut rather than wrong, though. Wondering if @nikomatsakis dynamic sized types proposal will fix some quantity of this.

@nikomatsakis

This comment has been minimized.

Show comment
Hide comment
@nikomatsakis

nikomatsakis May 23, 2013

Contributor

This relates to #4920, as well.

Contributor

nikomatsakis commented May 23, 2013

This relates to #4920, as well.

@huonw

This comment has been minimized.

Show comment
Hide comment
@huonw

huonw Aug 5, 2013

Member

Triage 2013-08-05: This was fixed by 30973cc, although the test case I wrote there is subtly wrong (#8012), will be fixed when #8305 lands.

Member

huonw commented Aug 5, 2013

Triage 2013-08-05: This was fixed by 30973cc, although the test case I wrote there is subtly wrong (#8012), will be fixed when #8305 lands.

@huonw huonw closed this in c57fde2 Aug 7, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment