Skip to content

Do not ICE on missing access place description during mutability error reporting - #61192

Closed
estebank wants to merge 4 commits into
rust-lang:masterfrom
estebank:issue-61187
Closed

Do not ICE on missing access place description during mutability error reporting#61192
estebank wants to merge 4 commits into
rust-lang:masterfrom
estebank:issue-61187

Conversation

@estebank

Copy link
Copy Markdown
Contributor

Fix#61187.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @varkor

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 25, 2019
@estebank

Copy link
Copy Markdown
ContributorAuthor

Cc @rust-lang/wg-diagnostics @cramertj for wording

@davidtwco

Copy link
Copy Markdown
Member

I've only had a cursory glance, but would we be able to give the name of the place if we allowed CompilerDesugaringKind::Async here or would that break some cases?

Some(name)if !local.from_compiler_desugaring() => {

@estebank

Copy link
Copy Markdown
ContributorAuthor

We could probably detect the Async desugaring and say something like "cannot borrow async argument as mutable, as it is not declared as mutable"

Comment threadsrc/test/ui/issues/issue-61187.rs
@estebank

estebank commented May 26, 2019

Copy link
Copy Markdown
ContributorAuthor

@davidtwco I think it is a cool idea to use the span desugaring mark for this, but sadly at the moment we don't mark the argument's spans with it and it is taking me some time to change it to do so.

Disregard, just managed to get it working (was looking at the wrong span).

Comment threadsrc/librustc_mir/borrow_check/mutability_errors.rs Outdated
(None, Place::Base(PlaceBase::Local(local))) if self.mir.local_decls[*local]
.source_info.span.is_compiler_desugaring(CompilerDesugaringKind::Async)
=> "`async fn` parameter".to_string(),
(None, _) => "temporary place".to_string(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any output actually producing this. Should we bug! or at least delay_span_bug here?

@oli-obk

Copy link
Copy Markdown
Contributor

@bors r+ p=5 async await priorization

my nit may be fixed in a separate PR

@bors

bors commented May 29, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit d72f97d has been approved by oli-obk

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 29, 2019
@Centril

Copy link
Copy Markdown
Contributor

@bors p=0 rollup

That was slightly too over-prioritized 😂 -- including it in a rollup will do.

r? @oli-obk

@rust-highfiverust-highfive assigned oli-obk and unassigned varkorMay 29, 2019
@oli-obk

Copy link
Copy Markdown
Contributor

"just following orders" 😛

Centril added a commit to Centril/rust that referenced this pull request May 29, 2019
Do not ICE on missing access place description during mutability error reporting
Fixrust-lang#61187.
@CentrilCentril mentioned this pull request May 29, 2019
Centril added a commit to Centril/rust that referenced this pull request May 29, 2019
Do not ICE on missing access place description during mutability error reporting
Fixrust-lang#61187.
@CentrilCentril mentioned this pull request May 29, 2019
Centril added a commit to Centril/rust that referenced this pull request May 29, 2019
Do not ICE on missing access place description during mutability error reporting
Fixrust-lang#61187.
@CentrilCentril mentioned this pull request May 29, 2019
Centril added a commit to Centril/rust that referenced this pull request May 29, 2019
Do not ICE on missing access place description during mutability error reporting
Fixrust-lang#61187.
@CentrilCentril mentioned this pull request May 29, 2019
@matthewjasper

Copy link
Copy Markdown
Contributor

I don't think this is really the correct fix, the variable being mutated here shouldn't have it's Span marked. I guess this is fine for now.

Centril added a commit to Centril/rust that referenced this pull request May 29, 2019
Do not ICE on missing access place description during mutability error reporting
Fixrust-lang#61187.
@CentrilCentril mentioned this pull request May 29, 2019
@oli-obk

oli-obk commented May 29, 2019

Copy link
Copy Markdown
Contributor

The problem isn't that the argument has its Span marked, what we're seeing is a temp local that is part of the expansion of async fn causing the error. That temp local is directly connected to the argument where the Span points to.

EDIT: Nevermind, I misremembered, and didn't read the following method carefully enough during review:

fnappend_local_to_string(&self,local_index:Local,buf:&mutString) -> Result<(),()>{
let local = &self.mir.local_decls[local_index];
match local.name{
Some(name)if !local.from_compiler_desugaring() => {
buf.push_str(name.as_str().get());
Ok(())
}
_ => Err(()),
}
}

yea, we should probably not mark the local's span during HIR lowering.

@oli-obk

Copy link
Copy Markdown
Contributor

@bors r-

@borsbors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 29, 2019
@estebank

Copy link
Copy Markdown
ContributorAuthor

we should probably not mark the local's span during HIR lowering.

@oli-obk why shouldn't we? I believe there are a couple of places where we mark spans that aren't strictly part of the desugared output, but that not marking would make it impossible to provide good diagnostics in some cases. I believe this might just be one of these cases :-/

@davidtwco

Copy link
Copy Markdown
Member

In this instance, the span is marked to avoid unused_mut lint (since the desugaring will just pull the argument directly into the closure). We can’t remove the mut as that would affect the input that macros get. I’m hoping to tidy up the logic around that desugaring soon (because it’s unfortunately a mess) but I’m not sure if this span being marked will change with that.

@oli-obk

Copy link
Copy Markdown
Contributor

Hmm... in that case, would it make sense to special case append_local_to_string instead of special casing on the output of it?

@matthewjasper

Copy link
Copy Markdown
Contributor

The problems is that we are marking more than we should be. The lowered code here looks like:

asyncfnresponse(data:Vec<u8>// This is an internal variable, it should have its Span marked) -> ::std::future::from_generator(move || {let data // This variable is effectively the user's parameter, it should not have it's Span marked
= data; data.reverse();})

This is causing false negatives in cases like:

#![deny(unused_mut)]pubasyncfnresponse(mutdata:Vec<u8>){let _ = data;}

@davidtwco

Copy link
Copy Markdown
Member

@estebank, I have a drive-by fix for this in #61413 which re-implements the async fn drop order lowering (sorry!).

Centril added a commit to Centril/rust that referenced this pull request Jun 4, 2019
…-sane-way, r=eddyb
Re-implement async fn drop order lowering
This PR re-implements the async fn drop order lowering changes so
that it all takes place in HIR lowering, building atop the work done by
@eddyb to refactor `Res::Upvar`.
Previously, this types involved in the lowering were constructed in
libsyntax as they had to be used during name resolution and HIR
lowering. This was awful because none of that logic should have existed
in libsyntax.
This commit also changes `ArgSource` to keep a `HirId` to the original
argument pattern rather than a cloned copy of the pattern.
Only b7aa4ed and 71fb8fa should be reviewed, any other commits
are from rust-lang#61276 (though 447e336 might end up staying in this PR).
As a nice side effect, it also fixesrust-lang#61187 (cc rust-lang#61192).
r? @eddyb
cc @cramertj
Centril added a commit to Centril/rust that referenced this pull request Jun 4, 2019
…-sane-way, r=eddyb
Re-implement async fn drop order lowering
This PR re-implements the async fn drop order lowering changes so
that it all takes place in HIR lowering, building atop the work done by
@eddyb to refactor `Res::Upvar`.
Previously, this types involved in the lowering were constructed in
libsyntax as they had to be used during name resolution and HIR
lowering. This was awful because none of that logic should have existed
in libsyntax.
This commit also changes `ArgSource` to keep a `HirId` to the original
argument pattern rather than a cloned copy of the pattern.
Only b7aa4ed and 71fb8fa should be reviewed, any other commits
are from rust-lang#61276 (though 447e336 might end up staying in this PR).
As a nice side effect, it also fixesrust-lang#61187 (cc rust-lang#61192).
r? @eddyb
cc @cramertj
Centril added a commit to Centril/rust that referenced this pull request Jun 4, 2019
…-sane-way, r=eddyb
Re-implement async fn drop order lowering
This PR re-implements the async fn drop order lowering changes so
that it all takes place in HIR lowering, building atop the work done by
@eddyb to refactor `Res::Upvar`.
Previously, this types involved in the lowering were constructed in
libsyntax as they had to be used during name resolution and HIR
lowering. This was awful because none of that logic should have existed
in libsyntax.
This commit also changes `ArgSource` to keep a `HirId` to the original
argument pattern rather than a cloned copy of the pattern.
Only b7aa4ed and 71fb8fa should be reviewed, any other commits
are from rust-lang#61276 (though 447e336 might end up staying in this PR).
As a nice side effect, it also fixesrust-lang#61187 (cc rust-lang#61192).
r? @eddyb
cc @cramertj
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Internal compiler error in nightly when reversing a vector inside a async fn

8 participants

@estebank@rust-highfive@davidtwco@oli-obk@bors@Centril@matthewjasper@varkor