title: rustc false positive warning about value never read?
body: <p>Following <a href="https://www.joshmcguigan.com/blog/build-your-own-shell-rust/" rel="nofollow noreferrer">this article</a> about writing a shell in Rust. Compiler outputs a warning about a variable never being read.</p>
  <pre><code>use std::io::stdin;
  use std::io::stdout;
  use std::io::Write;
  use std::process::Command;
  use std::path::Path;
  
   fn main(){
      let mut input = String::new();
  
      loop {
              print!(&quot;&gt; &quot;);
              stdout().flush().unwrap();
  //              input = String::from(&quot;&quot;);  //  **&lt;===== HERE**
              stdin().read_line(&amp;mut input).unwrap();
              let mut parts = input.trim().split_whitespace();
              let command = parts.next().unwrap();
              let args = parts;
              match command {
                  &quot;cd&quot; =&gt; {
                      let new_dir = args.peekable().peek().map_or(&quot;/&quot;, |x| *x);
                      let root = Path::new(new_dir);
                      if let Err(e) = std::env::set_current_dir(&amp;root) {
                          eprintln!(&quot;{}&quot;, e);
                      }
                  },
                  &quot;exit&quot; =&gt; return,
                  command =&gt; {
                      let child = Command::new(command)
                          .args(args)
                          .spawn();
                      // gracefully handle malformed user input
                      match child {
                          Ok(mut child) =&gt; { child.wait().unwrap(); },
                          Err(e) =&gt; eprintln!(&quot;{}&quot;, e),
                      };
                 }
             }
      }
  }
  </code></pre>
  <p>However, commenting out this line causes program to bug: here is the behavior before and after commenting:</p>
  <pre><code>usn@DESKTOP:~/bqy/rust/p2$ cargo run
  warning: value assigned to `input` is never read
   --&gt; src/main.rs:8:10
    |
  8 |     let mut input = String::new();
    |             ^^^^^
    |
    = note: `#[warn(unused_assignments)]` on by default
    = help: maybe it is overwritten before being read?
  
      Finished dev [unoptimized + debuginfo] target(s) in 0.02s
       Running `target/debug/p2`
  &gt; ls
  Cargo.lock  Cargo.toml  src  target
  &gt; ls
  Cargo.lock  Cargo.toml  src  target
  &gt; exit
  usn@DESKTOP:~/bqy/rust/p2$ vi src/main.rs
  usn@DESKTOP:~/bqy/rust/p2$ cargo run
     Compiling p2 v0.1.0 (/mnt/d/MMM/projects/bqy/rust/p2)
      Finished dev [unoptimized + debuginfo] target(s) in 1.13s
       Running `target/debug/p2`
  &gt; ls
  Cargo.lock  Cargo.toml  src  target
  &gt; ls
  ls: cannot access 'ls': No such file or directory
  &gt; exit
  ls: cannot access 'ls': No such file or directory
  ls: cannot access 'exit': No such file or directory
  &gt; ^C
  usn@DESKTOP:~/bqy/rust/p2$ vi src/main.rs
  </code></pre>
  <p>Simple explanation of unwanted behavior is that command line is not resetted. So, why does the compiler complains ?</p>
  <p>Thank you for reading.</p>