Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when expression contains = but not ; #8

Closed
pzmarzly opened this issue May 12, 2019 · 4 comments
Closed

Warn when expression contains = but not ; #8

pzmarzly opened this issue May 12, 2019 · 4 comments

Comments

@pzmarzly
Copy link
Contributor

In: let mut x  = 5;

In: x = 3
Out: ()


In: x
Out: 5


In: x = 3;

In: x
Out: 3

This behavior may be surprising sometimes. I'm not sure what the right way to improve it is, but my suggestion is printing a warning between In: and Out: about it whenever someone writes a line with = but not ;

@sigmaSd
Copy link
Owner

sigmaSd commented May 12, 2019

I like the idea!, I implemented it but there are cases when you get an ugly messages like

Are you missing an `;` ?
   Compiling irust v0.1.0 (/tmp/irust)
warning: variable `x` is assigned to, but never used
 --> src/main.rs:2:6
  |
2 |     let x = 5;
  |         ^
  |
  = note: #[warn(unused_variables)] on by default
  = note: consider using `_x` instead

warning: value assigned to `x` is never read
 --> src/main.rs:4:1
  |
4 | x = 6
  | ^
  |
  = note: #[warn(unused_assignments)] on by default
  = help: maybe it is overwritten before being read?

error[E0384]: cannot assign twice to immutable variable `x`
 --> src/main.rs:4:1
  |
2 |     let x = 5;
  |         -
  |         |
  |         first assignment to `x`
  |         help: make this binding mutable: `mut x`
3 |     println!("{:?}", {
4 | x = 6
  | ^^^^^ cannot assign twice to immutable variable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0384`.
error: Could not compile `irust`.

To learn more, run the command again with --verbose.

I think there are steps we need to do before doing this,

1- format output, At first I liked the separation of concerns by making parse() returns a string that is printed by handle_enter(), but now I feel its really limiting, since I'm printing all kind of output the same way, instead of being able to customize per function, for example print "Are you missing an ; ?" with different color, plus I already break that encapsulation with art.rs wait_for_cmd

2- format rustc errors, I want this:

   Compiling irust v0.1.0 (/tmp/irust)
warning: variable `x` is assigned to, but never used
 --> src/main.rs:2:6
  |
2 |     let x = 5;
  |         ^
  |
  = note: #[warn(unused_variables)] on by default
  = note: consider using `_x` instead

to become

 --> src/main.rs:2:6
  |
2 |     let x = 5;
  |         ^
  |

@sigmaSd
Copy link
Owner

sigmaSd commented May 12, 2019

@sigmaSd
Copy link
Owner

sigmaSd commented May 12, 2019

@pzmarzly here is a PR for this issue, #9, would be great if you check it out

@sigmaSd
Copy link
Owner

sigmaSd commented May 13, 2019

should be good now c288e4f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants