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

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

Closed
wants to merge 4 commits into from

Conversation

estebank
Copy link
Contributor

Fix #61187.

@rust-highfive
Copy link
Collaborator

r? @varkor

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

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

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

@davidtwco
Copy link
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
Contributor Author

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

@estebank
Copy link
Contributor Author

estebank commented May 26, 2019

@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).

(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
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
Contributor

oli-obk commented May 29, 2019

@bors r+ p=5 async await priorization

my nit may be fixed in a separate PR

@bors
Copy link
Contributor

bors commented May 29, 2019

📌 Commit d72f97d has been approved by oli-obk

@bors bors 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
Contributor

Centril commented May 29, 2019

@bors p=0 rollup

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

r? @oli-obk

@rust-highfive rust-highfive assigned oli-obk and unassigned varkor May 29, 2019
@oli-obk
Copy link
Contributor

oli-obk commented May 29, 2019

"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

Fix rust-lang#61187.
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

Fix rust-lang#61187.
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

Fix rust-lang#61187.
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

Fix rust-lang#61187.
@matthewjasper
Copy link
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

Fix rust-lang#61187.
@oli-obk
Copy link
Contributor

oli-obk commented May 29, 2019

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:

fn append_local_to_string(&self, local_index: Local, buf: &mut String) -> 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
Contributor

oli-obk commented May 29, 2019

@bors r-

@bors bors 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
Contributor Author

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
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
Contributor

oli-obk commented May 31, 2019

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
Contributor

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

async fn response(
    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)]
pub async fn response(mut data: Vec<u8>) {
    let _ = data;
}

@davidtwco
Copy link
Member

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

@estebank estebank closed this May 31, 2019
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 fixes rust-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 fixes rust-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 fixes rust-lang#61187 (cc rust-lang#61192).

r? @eddyb
cc @cramertj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: 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