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

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
Labels
A-typesystem Area: The type system

Comments

@andymatuschak
Copy link

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
Copy link

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
Copy link
Contributor

brson commented Nov 3, 2012

I've been annoyed by this a lot lately.

@pnkfelix
Copy link
Member

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

@pnkfelix
Copy link
Member

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

@pnkfelix
Copy link
Member

Not critical for 0.6; de-milestoning

@graydon
Copy link
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
Copy link
Contributor

This relates to #4920, as well.

@huonw
Copy link
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 as completed in c57fde2 Aug 7, 2013
RalfJung pushed a commit to RalfJung/rust that referenced this issue Jun 29, 2024
show proper UB when making a too large allocation request

Fixes rust-lang/miri#3679
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

7 participants