Skip to content

Parameter cardinality error has a terrible span. #13684

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

Closed
SiegeLord opened this issue Apr 22, 2014 · 0 comments · Fixed by #13713
Closed

Parameter cardinality error has a terrible span. #13684

SiegeLord opened this issue Apr 22, 2014 · 0 comments · Fixed by #13713
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@SiegeLord
Copy link
Contributor

E.g.:

fn main()
{
    range(0, 5).take();
    range(0, 5)
    .take();
}

Gives this error:

test.rs:3:2: 3:20 error: this function takes 1 parameter but 0 parameters were supplied
test.rs:3       range(0, 5).take();
                ^~~~~~~~~~~~~~~~~~
test.rs:4:2: 5:9 error: this function takes 1 parameter but 0 parameters were supplied
test.rs:4       range(0, 5)
test.rs:5       .take();
error: aborting due to 2 previous errors

Both are quite terrible and require going through each function to figure out which one has the wrong number of arguments.

edwardw added a commit to edwardw/rust that referenced this issue Apr 23, 2014
Specifically, the method parameter cardinality mismatch or missing
method error message span now gets method itself exactly. It was the
whole expression.

Closes rust-lang#9390
Closes rust-lang#13684
Closes rust-lang#13709
bors added a commit that referenced this issue Apr 24, 2014
Specifically, the method parameter cardinality mismatch or missing
method error message span now gets method itself exactly. It was the
whole expression.

Closes #9390
Closes #13684
Closes #13709
arcnmx pushed a commit to arcnmx/rust that referenced this issue Jan 9, 2023
…mat-string, r=Veykril

feat: extract_expressions_from_format_string

closes rust-lang#13640
- rename to `extract_expressions_from_format_string`
- leave identifier from format string
	- but this is from rustc version 1.65.0
	- Should I add flag or something?

Note: the assist behaves below cases for now. I'll create an issue for these.
```rs
let var = 1 + 1;
// ok
format!("{var} {1+1}");   // → format!("{var} {}", 1+1);
format!("{var:?} {1+1}"); // → format!("{var:?} {}", 1 + 1);
format!("{var} {var} {1+1}"); // → format!("{var} {var} {}", 1 + 1);

// breaks (need to handle minimum width by postfix`$`)
format!("{var:width$} {1+1}"); // → format!("{var:width\$} {}", 1+1);
format!("{var:.prec$} {1+1}"); // → format!("{var:.prec\$} {}", 1+1);
format!("Hello {:1$}! {1+1}", "x" 5); // → format("Hello {:1\$}! {}", "x", 1+1);
format!("Hello {:width$}! {1+1}", "x", width = 5); // → println!("Hello {:width\$}! {}", "x", 1+1);
```

https://user-images.githubusercontent.com/38400669/204344911-f1f8fbd2-706d-414e-b1ab-d309376efb9b.mov
flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 15, 2024
changelog:
```
changelog: [`needless_option_take`]: now lints for all temporary expressions of type  Option<T>.
```

fixes rust-lang#13671

In general, needless_option_take should report whenever take() is called
on a temporary value, not just when the temporary value is created by
as_ref().

Also, we stop emitting machine applicable fixes in these cases, since
sometimes the intention of the user is to actually clear the original
option, in cases such as `option.as_mut().take()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants