1

The following code raises an error in all channels. The Rust Language Server does not detect this error and says the types are correct. What did I get wrong?

use std::fs::File;
use std::io::Read;
use std::io::Write;
use std::env;
use std::string::String;
use std::str;

fn main() {
    if let Some(file_name) = env::args().nth(2) {
        let mut file_handle = File::open(file_name)
            .expect(format!("Your File is invaild {}", &file_name as &str));
        let mut text = String::new();
        file_handle
            .read_to_string(&mut text)
            .expect("unable to read file");
        text.replace("test", &env::args().nth(2).unwrap() as &str);
        // file_handle.set_len(text.len() as u64).expect("could not resize file");
        file_handle
            .write(&text.as_bytes())
            .expect("could not write to file");
    } else {
        println!("you did not give me a file")
    }
}
error[E0308]: mismatched types
  --> src/main.rs:11:21
   |
11 |             .expect(format!("Your File is invaild {}", &file_name as &str));
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &str, found struct `std::string::String`
   |
   = note: expected type `&str`
              found type `std::string::String`
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
person
  • 11
  • 4
  • 1
    What versions of your Rust compiler and RLS are installed? – E_net4 May 12 '17 at 17:26
  • 1
    Why do you think you did something wrong? You are using alpha/beta software which is expected to have bugs. This seems like it should just be a bug report. – Shepmaster May 12 '17 at 17:31
  • 1
    In addition to E_net4's requests, you should probably add what *consumer* of the language server protocol you are using (VS Code, emacs, etc.) – Shepmaster May 12 '17 at 17:32
  • most recent rustup channels. But now rls will not start I will update later. – person May 12 '17 at 17:53
  • 1
    This is indeed a bad moment for RLS related questions, if you are using Visual Studio Code. The latest RLS will crash on it: https://github.com/rust-lang-nursery/rls/issues/312 – E_net4 May 12 '17 at 18:01
  • @E_net4 Thanks for pointing this out I would have kept wasting my time. Begaing to think that My move from swift for stability is not bearing fruits:) – person May 12 '17 at 18:15

0 Answers0