Skip to content

Compiler says string is not it's own type #14089

Closed
@RichardlL

Description

@RichardlL

I have the code
let mut vari = "";
...
vari = vari + str::from_char(chr);

(I cant used an owned string, because i have a large pattern match, and it wont accept ~"String to match", as it interprets it as a a owned static string instead of a owned string, and it wont accept "String to match".to_owned() either)

But back to the problem, it says vari doesnt have an appropriate type for vari?

src/main.rs:161:11: 161:37 error: mismatched types: expected &'static str but found ~str (str storage differs: expected &'static but found ~)

src/main.rs:161             vari = vari + str::from_char(chr); 
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous 

and i cant use += as that results in
binary assignment operation += cannot be applied to type &static str

Im not sure if this is a bug, but it's confusing me

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions