Skip to content

diagnostics: "try using a conversion method: `*i.to_string().to_string()" #53348

Closed
@matthiaskrgr

Description

@matthiaskrgr

Example I came up with (tried to reduce from a larger set of code I found this in)

fn main() {
	let mut v = vec!["hello", "this", "is", "a", "test"];

	let v2 = Vec::new();
	
	v.into_iter().map(|s|s.to_owned()).collect::<Vec<_>>();
	
	let mut a = String::new();
	for i in v {
		a = *i.to_string();
		v2.push(a);
	}
}

This gives a rather confusing error message:

error[E0308]: mismatched types
  --> src/main.rs:10:7
   |
10 |         a = *i.to_string();
   |             ^^^^^^^^^^^^^^
   |             |
   |             expected struct `std::string::String`, found str
   |             help: try using a conversion method: `*i.to_string().to_string()`
   |
   = note: expected type `std::string::String`
              found type `str`

meta:

rustc 1.30.0-nightly (d5a448b3f 2018-08-13)
binary: rustc
commit-hash: d5a448b3f47b22c9cb010198bdcc49d4392b090b
commit-date: 2018-08-13
host: x86_64-unknown-linux-gnu
release: 1.30.0-nightly
LLVM version: 7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions