-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[NLL] E0389 error message uses the term immutable item
inappropriately
#47388
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
Comments
Mentoring instructionsThe error messages in question seem to originate here: rust/src/librustc_mir/borrow_check/mod.rs Lines 1404 to 1407 in da569fa
I think that to fix this, we will want to examine the Lines 1231 to 1243 in da569fa
I think we could either print "immutable path" instead of "immutable item", or else (maybe better) If it's a local, print "immutable local variable". For a static, "immutable static" or "immutable static variable". For anything else, maybe just "path"? In general, I think I would also prefer the message to be like
It might take a bit of tweaking to get this right, but by walking up the |
Investigating this |
Looking at possible error messages for the similar cases
Message2
|
I think I would prefer:
The "immutable/mutable reference" is jargony, but consistent with other errors. We need to make it clear that |
Overall, I am feeling torn here. I like @estebank's phrasing, but I have two concerns: First, I personally don't like term 'immutable reference'. I know it is widely used in our error messages -- and even in the Rust book -- but I think it is misleading. In particular, an Ignoring that, I think that @estebank's message is nice, though I wonder: I feel like there should be a principle of only mentioning the things that actually matter in the error, and in fact the precise field ( Putting it all together, maybe something like this?
But I'm not sure if it's really an improvement on what @estebank wrote. In some ways, e.g. the use of the word "through" instead of a field name, it may be less clear. Curious what others think. (I'm also not sure about |
@nikomatsakis I feel the term |
@gaurikholkar ok, if @estebank is happy with that, let's try for that for now. This is going to require a bit of analysis of the |
I disagree slightly that |
Yeah, irrelevant is too strong. But it's not that there is anything special about the
but that seems a bit verbose (and likely to run off the side of the screen). |
|
@estebank that seems really good. We should consider all the other cases that will arise I suppose. We can probably fallback to my simpler variant when it is not a field being assigned? |
That would be my preference, yes. |
@gaurikholkar ok so let me leave you a few more tips. I mentioned already that we will want to examine the Lines 1241 to 1242 in da569fa
A projection consists of an "element" and a base Lines 1258 to 1266 in da569fa
Elements consist of things like fields or dereferences: Lines 1268 to 1269 in da569fa
In this case, where
|
I think, for error messages purposes, we want to consider things like this:
rust/src/librustc_mir/borrow_check/mod.rs Lines 1471 to 1476 in da569fa
and it seems like |
Thanks @nikomatsakis |
@gaurikholkar how goes ? Just checking in here =) |
This is the output for now.
|
@gaurikholkar making progress! One nit: should be "cannot assign through
|
Current status. The error message labels are inverted, will fix that and open a PR.
|
@gaurikholkar this is awesome =) A few notes:
|
@nikomatsakis the suggestion is inline now |
I'm guessing that it wasn't a
There's already a method to get a span pointing at the end of a given span ( @gaurikholkar be careful with suggestions, everything underlined will be replaced with the content of the suggestion string, in this case the resulting code would be |
Yeah I was using
@estebank are you saying we should alter the suggestion/error message or get back the old method? |
@gaurikholkar I'm saying that the only change needed to fix the incorrect suggestion result is changing the span to only point to the |
Clearing assignment since #48914 was closed for inactivity. It'd be good to dust off the PR and get those changes landed though! We were getting close. |
Reopening the PR @nikomatsakis @estebank |
Modify compile-fail/E0389 error message WIP This fixes #47388 cc @nikomatsakis @estebank r? @nikomatsakis Certain ui tests were failing locally. I'll check if the same happens here too.
The test compile-fail/E0389.rs gives the error message "cannot assign to immutable item
fancy_ref.num
". This is not particularly good because:(a) "item" is probably not a very clear term for end-users but also
(b) even if it were, I would expect it to refer to "global things" like functions or statics, not fields of a local variable.
The text was updated successfully, but these errors were encountered: