[ Prev ]
2021-10-06

-- Oct 6 In-Class Exercise Thread
fn main() {
  let s1 = String::from("hi there");
  let s2 = s1.clone(); // if had let s2 = s1; instead, next line would not work
  println!("s1 = {}, s2 = {}", s1, s2);
 }
 
 output:
 s1 = hi there, s2 = hi there
 
 fn main() {
  let s1 = String::from("hi there");
  let s2 = s1; // if had let s2 = s1; instead, next line would not work
  println!("s1 = {}, s2 = {}", s1, s2);
 }
 
 output: 
 error[E0382]: borrow of moved value: `s1`
  --> src/main.rs:4:30
   |
 2 | let s1 = String::from("hi there");
   |     -- move occurs because `s1` has type `String`, which does not implement the 
 `Copy` trait
 3 | let s2 = s1; // if had let s2 = s1; instead, next line would not work
   |          -- value moved here
 4 | println!("s1 = {}, s2 = {}", s1, s2);
   |                              ^^ value borrowed here after move 
For more information about this error, try rustc−−expla∈E0382. error: could not compile playground due to previous error
fn main() { let s1 = String::from("hi there"); let s2 = s1.clone(); // if had let s2 = s1; instead, next line would not work println!("s1 = {}, s2 = {}", s1, s2); } output: s1 = hi there, s2 = hi there fn main() { let s1 = String::from("hi there"); let s2 = s1; // if had let s2 = s1; instead, next line would not work println!("s1 = {}, s2 = {}", s1, s2); } output: error[E0382]: borrow of moved value: @BT@s1@BT@ --> src/main.rs:4:30 | 2 | let s1 = String::from("hi there"); | -- move occurs because @BT@s1@BT@ has type @BT@String@BT@, which does not implement the @BT@Copy@BT@ trait 3 | let s2 = s1; // if had let s2 = s1; instead, next line would not work | -- value moved here 4 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after move For more information about this error, try rustc−−expla∈E0382. error: could not compile playground due to previous error

User Icon
-- Oct 6 In-Class Exercise Thread
Original
 fn main(){
     let s1 = String::from("hi there");
     let s2 = s1.clone(); // if had let s2 = s1; instead, next line would not work
     println!("s1 = {}, s2 = {}", s1, s2); 
 }
Output
 s1 = hi there, s2 = hi there
Modified
 fn main(){
     let s1 = String::from("hi there");
     //let s2 = s1.clone(); // if had let s2 = s1; instead, next line would not work
     let s2 = s1;
     println!("s1 = {}, s2 = {}", s1, s2);
 }
Output
 error[E0382]: borrow of moved value: `s1`
  --> inClass.rs:5:34
   | 
 2 |     let s1 = String::from("hi there");
   |         -- move occurs because `s1` has type `String`, which does not implement the `Copy` trait
 3 |     //let s2 = s1.clone(); // if had let s2 = s1; instead, next line would not work 
 4 |     let s2 = s1;
   |              -- value moved here
 5 |     println!("s1 = {}, s2 = {}", s1, s2);
   |                                  ^^ value borrowed here after move
 error: aborting due to previous error
 For more information about this error, try `rustc --explain E0382`.
(Edited: 2021-10-06)
Original fn main(){ let s1 = String::from("hi there"); let s2 = s1.clone(); // if had let s2 = s1; instead, next line would not work println!("s1 = {}, s2 = {}", s1, s2); } Output s1 = hi there, s2 = hi there Modified fn main(){ let s1 = String::from("hi there"); //let s2 = s1.clone(); // if had let s2 = s1; instead, next line would not work let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2); } Output error[E0382]: borrow of moved value: @BT@s1@BT@ --> inClass.rs:5:34 | 2 | let s1 = String::from("hi there"); | -- move occurs because @BT@s1@BT@ has type @BT@String@BT@, which does not implement the @BT@Copy@BT@ trait 3 | //let s2 = s1.clone(); // if had let s2 = s1; instead, next line would not work 4 | let s2 = s1; | -- value moved here 5 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after move error: aborting due to previous error For more information about this error, try @BT@rustc --explain E0382@BT@.

-- Oct 6 In-Class Exercise Thread
 Original Program:
 fn main() {
 	let s1 = String::from("hi there");
 	let s2 = s1.clone(); 
 	println!("s1 = {}, s2 = {}", s1, s2);
 }
 Output:
 s1 = hi there, s2 = hi there
 
 Modified Program:
 fn main() {
 	let s1 = String::from("hi there");
 	let s2 = s1; 
 	println!("s1 = {}, s2 = {}", s1, s2);
 } 
 Output:
 error[E0382]: borrow of moved value: `s1`
  --> src/main.rs:4:31
   |
 2 |     let s1 = String::from("hi there");
   |         -- move occurs because `s1` has type `String`, which does not implement the 
 `Copy` trait
 3 |     let s2 = s1; 
   |              -- value moved here
 4 |     println!("s1 = {}, s2 = {}", s1, s2);
   |                                  ^^ value borrowed here after move
 
 error: aborting due to previous error
 
 For more information about this error, try `rustc --explain E0382`.
(Edited: 2021-10-06)
Original Program: fn main() { let s1 = String::from("hi there"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}", s1, s2); } Output: s1 = hi there, s2 = hi there Modified Program: fn main() { let s1 = String::from("hi there"); let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2); } Output: error[E0382]: borrow of moved value: @BT@s1@BT@ --> src/main.rs:4:31 | 2 | let s1 = String::from("hi there"); | -- move occurs because @BT@s1@BT@ has type @BT@String@BT@, which does not implement the @BT@Copy@BT@ trait 3 | let s2 = s1; | -- value moved here 4 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after move error: aborting due to previous error For more information about this error, try @BT@rustc --explain E0382@BT@.

-- Oct 6 In-Class Exercise Thread
Resource Description for Screen Shot 2021-10-06 at 6.35.59 PM.png
((resource:Screen Shot 2021-10-06 at 6.35.59 PM.png|Resource Description for Screen Shot 2021-10-06 at 6.35.59 PM.png))

-- Oct 6 In-Class Exercise Thread
Program 1:
fn main() {
	let s1 = String::from("hi there");
	let s2 = s1.clone();
	println!("s1 = {}, s2 = {}", s1, s2);
}
Program 2:
fn main() {
	let s1 = String::from("hi there");
	let s2 = s1;
	println!("s1 = {}, s2 = {}", s1, s2);
} Resource Description for output.png (Edited: 2021-10-06)
<pre> Program 1: fn main() { let s1 = String::from("hi there"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}", s1, s2); } </pre> <pre> Program 2: fn main() { let s1 = String::from("hi there"); let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2); } </pre> ((resource:output.png|Resource Description for output.png))

-- Oct 6 In-Class Exercise Thread
fn main(){ let s1 = String::from("hi there"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}", s1, s2); } output: C:\Users\Harrison Hwang\Desktop\College\Fall2021\CS152\10-6ex>rustc driver.rs C:\Users\Harrison Hwang\Desktop\College\Fall2021\CS152\10-6ex>.\driver.exe s1 = hi there, s2 = hi there modified: fn main(){ let s1 = String::from("hi there"); //let s2 = s1.clone(); let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2); } error: C:\Users\Harrison Hwang\Desktop\College\Fall2021\CS152\10-6ex>rustc driver.rs error[E0382]: borrow of moved value: `s1` --> driver.rs:9:31 | 6 | let s1 = String::from("hi there"); | -- move occurs because `s1` has type `String`, which does not implement the `Copy` trait 7 | //let s2 = s1.clone(); 8 | let s2 = s1; | -- value moved here 9 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after move error: aborting due to previous error For more information about this error, try `rustc --explain E0382`.
(Edited: 2021-10-06)
<nowiki>fn main(){ let s1 = String::from("hi there"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}", s1, s2); } output: C:\Users\Harrison Hwang\Desktop\College\Fall2021\CS152\10-6ex>rustc driver.rs C:\Users\Harrison Hwang\Desktop\College\Fall2021\CS152\10-6ex>.\driver.exe s1 = hi there, s2 = hi there modified: fn main(){ let s1 = String::from("hi there"); //let s2 = s1.clone(); let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2); } error: C:\Users\Harrison Hwang\Desktop\College\Fall2021\CS152\10-6ex>rustc driver.rs error[E0382]: borrow of moved value: @BT@s1@BT@ --> driver.rs:9:31 | 6 | let s1 = String::from("hi there"); | -- move occurs because @BT@s1@BT@ has type @BT@String@BT@, which does not implement the @BT@Copy@BT@ trait 7 | //let s2 = s1.clone(); 8 | let s2 = s1; | -- value moved here 9 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after move error: aborting due to previous error For more information about this error, try @BT@rustc --explain E0382@BT@. </nowiki>

-- Oct 6 In-Class Exercise Thread
Compiles and runs the correct version: bill@Bills-MacBook-Pro hw1 % rustc example1.rs bill@Bills-MacBook-Pro hw1 % ./example1 s1 = hi there, s2 = hi there Second example does not compile: bill@Bills-MacBook-Pro hw1 % rustc example2.rs error: expected `;`, found `println` --> example2.rs:3:16 | 3 | let s2 = s1 // if had let s2 = s1; instead, next line would not work | ^ help: add `;` here 4 | println!("s1 = {}, s2 = {}", s1, s2); | ------- unexpected token error: aborting due to previous error
<nowiki> Compiles and runs the correct version: bill@Bills-MacBook-Pro hw1 % rustc example1.rs bill@Bills-MacBook-Pro hw1 % ./example1 s1 = hi there, s2 = hi there Second example does not compile: bill@Bills-MacBook-Pro hw1 % rustc example2.rs error: expected @BT@;@BT@, found @BT@println@BT@ --> example2.rs:3:16 | 3 | let s2 = s1 // if had let s2 = s1; instead, next line would not work | ^ help: add @BT@;@BT@ here 4 | println!("s1 = {}, s2 = {}", s1, s2); | ------- unexpected token error: aborting due to previous error</nowiki>

-- Oct 6 In-Class Exercise Thread
 fn main() {
    let s1 = String::from("hi there");
    let s2 = s1.clone();
    println!("s1 = {}, s2 = {}", s1, s2);
  }
 output : 
	 s1 = hi there, s2 = hi there
 fn main() {
    let s1 = String::from("hi there");
    let s2 = s1;
    println!("s1 = {}, s2 = {}", s1, s2);
 }
 output : 
 error[E0382]: borrow of moved value: `s1`
  --> example.rs:4:31
   |
 2 |     let s1 = String::from("hi there");
   |         -- move occurs because `s1` has type `String`, which does not 
 implement the `Copy` trait
 3 |     let s2 = s1;
   |              -- value moved here
 4 |     println!("s1 = {}, s2 = {}", s1, s2);
   |                                  ^^ value borrowed here after move
 error: aborting due to previous error
(Edited: 2021-10-06)
fn main() { let s1 = String::from("hi there"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}", s1, s2); } output : s1 = hi there, s2 = hi there fn main() { let s1 = String::from("hi there"); let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2); } output : error[E0382]: borrow of moved value: @BT@s1@BT@ --> example.rs:4:31 | 2 | let s1 = String::from("hi there"); | -- move occurs because @BT@s1@BT@ has type @BT@String@BT@, which does not implement the @BT@Copy@BT@ trait 3 | let s2 = s1; | -- value moved here 4 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after move error: aborting due to previous error

-- Oct 6 In-Class Exercise Thread
fn main() {
	let s1 = String::from("hi there");
	let s2 = s1.clone();
	println!("s1 = {}, s2 = {}", s1, s2);
}
 
Output:
s1 = hi there, s2 = hi there
 
Modified Program: fn main() {
	let s1 = String::from("hi there");
	let s2 = s1;
	println!("s1 = {}, s2 = {}", s1, s2);
}
 
Output:
error[E0382]: borrow of moved value: `s1`
 --> main.rs:4:31
  |
2 | let s1 = String::from("hi there");
  |         -- move occurs because `s1` has type `std::string::String`, which does not implement the `Copy` trait
3 | let s2 = s1; // if had let s2 = s1; instead, next line w...
  |              -- value moved here
4 | println!("s1 = {}, s2 = {}", s1, s2);
  |                                  ^^ value borrowed here after move
error: aborting due to previous error
For more information about this error, try rustc --explain E0382.
exit status 1
(Edited: 2021-10-06)
fn main() { let s1 = String::from("hi there"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}", s1, s2); } Output: s1 = hi there, s2 = hi there Modified Program: fn main() { let s1 = String::from("hi there"); let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2); } Output: error[E0382]: borrow of moved value: @BT@s1@BT@ --> main.rs:4:31 | 2 | let s1 = String::from("hi there"); | -- move occurs because @BT@s1@BT@ has type @BT@std::string::String@BT@, which does not implement the @BT@Copy@BT@ trait 3 | let s2 = s1; // if had let s2 = s1; instead, next line w... | -- value moved here 4 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after move error: aborting due to previous error For more information about this error, try rustc --explain E0382. exit status 1

-- Oct 6 In-Class Exercise Thread
fn main() { let s1 = String::from("hi there"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}", s1, s2); } Output: s1 = hi there, s2 = hi there fn main() { let s1 = String::from("hi there"); let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2); } error[E0382]: borrow of moved value: `s1` --> src/main.rs:4:34 | 2 | let s1 = String::from("hi there"); | -- move occurs because `s1` has type `String`, which does not implement the `Copy` trait 3 | let s2 = s1; | -- value moved here 4 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after move For more information about this error, try `rustc --explain E0382`.
<nowiki>fn main() { let s1 = String::from("hi there"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}", s1, s2); } Output: s1 = hi there, s2 = hi there fn main() { let s1 = String::from("hi there"); let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2); } error[E0382]: borrow of moved value: @BT@s1@BT@ --> src/main.rs:4:34 | 2 | let s1 = String::from("hi there"); | -- move occurs because @BT@s1@BT@ has type @BT@String@BT@, which does not implement the @BT@Copy@BT@ trait 3 | let s2 = s1; | -- value moved here 4 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after move For more information about this error, try @BT@rustc --explain E0382@BT@.</nowiki>
[ Next ]
X