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

suggestion prints expanded macros #41858

Closed
oli-obk opened this issue May 9, 2017 · 0 comments
Closed

suggestion prints expanded macros #41858

oli-obk opened this issue May 9, 2017 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented May 9, 2017

= help: try with &mut $ crate :: fmt :: format ( format_args ! ( $ ( $ arg ) * ) )

should be

= help: try with &mut format!("foo")

at the minimum. Even better would be to suggest *s for the s on the lhs of the assignment.

fn main() {
    let s = &mut String::new();
    s = format!("foo");
}

produces

error[E0308]: mismatched types
 --> <anon>:3:9
  |
3 |     s = format!("foo");
  |         ^^^^^^^^^^^^^^ expected mutable reference, found struct `std::string::String`
  |
  = note: expected type `&mut std::string::String`
             found type `std::string::String`
  = help: try with `&mut $ crate :: fmt :: format ( format_args ! ( $ ( $ arg ) * ) )`
  = note: this error originates in a macro outside of the current crate
@nikomatsakis nikomatsakis added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 9, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue Jun 3, 2017
Use callsite's span for macro calls on suggestion

When suggesting an appropriate mutability for a macro call, use the call
span instead of the expanded macro's span.

```
error[E0308]: mismatched types
  --> $DIR/coerce-suggestions.rs:48:9
   |
48 |     s = format!("foo");
   |         ^^^^^^^^^^^^^^ expected mutable reference, found struct `std::string::String`
   |
   = note: expected type `&mut std::string::String`
              found type `std::string::String`
   = help: try with `&mut format!("foo")`
   = note: this error originates in a macro outside of the current crate
```
Fix rust-lang#41858.
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants