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

Borrowchecker regression in 1.26 #49945

Closed
pietroalbini opened this issue Apr 13, 2018 · 12 comments
Closed

Borrowchecker regression in 1.26 #49945

pietroalbini opened this issue Apr 13, 2018 · 12 comments
Assignees
Labels
A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@pietroalbini
Copy link
Member

@pietroalbini pietroalbini added I-nominated A-borrow-checker Area: The borrow checker T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. C-bug Category: This is a bug. labels Apr 13, 2018
@pietroalbini pietroalbini added this to the 1.26 milestone Apr 13, 2018
@pietroalbini
Copy link
Member Author

cc @nikomatsakis

sorz added a commit to sorz/moproxy that referenced this issue Apr 17, 2018
@pnkfelix pnkfelix self-assigned this Apr 19, 2018
@pnkfelix
Copy link
Member

visiting for triage.

@pietroalbini are you in a position to narrow this into a stand-alone test case?

@pnkfelix
Copy link
Member

triage : P-high

@pnkfelix pnkfelix added the P-high High priority label Apr 19, 2018
@pietroalbini
Copy link
Member Author

are you in a position to narrow this into a stand-alone test case?

That was just from crater, I can try bisecting in a few hours though.

@pietroalbini
Copy link
Member Author

pietroalbini commented Apr 19, 2018

@pnkfelix the bisect run points inside of the rollup #49337, and #49299 (edit: wrong copy/paste!) is the one that makes more sense (since the issue affects closures). I'll try investigating more later today.

@pietroalbini
Copy link
Member Author

Didn't have time to investigate this in the past days, sorry! cc @nikomatsakis

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Apr 26, 2018

OK, I see what is happening. Fascinating; I did not anticipate this side-effect of making closures implement Copy. I think the problem is this:

  • Closures were never Copy before.
  • This code creates a closure skip_headers
  • This closure is then used from another closure we'll call skip; skip escapes from the fn.
    • In the olden days, because the closure was not copy, it was implicitly moved into skip
    • But now, the closure is copy, and therefore it is taken by shared reference and copied out
      • hence skip must be declared as move

I guess this is "working as expected", but it's a surprise interaction I had not considered in advance. (More generally, it seems to suggest that making any struct Copy could break closures down the line.)

cc @rust-lang/lang

@nikomatsakis
Copy link
Contributor

Still, I don't think it's worth reverting the change, and we are certainly not going to change this aspect of closure upvar inference; if we did, then a TON of things would stop working (basically any FnOnce that moves but is not declared move).

@nikomatsakis
Copy link
Contributor

Idea, discussed in gitter:

In the edition, if closures are not declared as move but reference non-zero upvars, then we could give them a phantom lifetime to prevent them from escaping the enclosing function. This would prevent the "semver-fail" that we observe here, where adding Copy to a type breaks consumers.

@pietroalbini
Copy link
Member Author

Ping @nikomatsakis! We're approaching the release of 1.26, what should we do with this regression?

@nikomatsakis
Copy link
Contributor

@pietroalbini I believe we are going to categorize this as "won't fix". The crate in question has already worked around it, in any case.

@pietroalbini
Copy link
Member Author

@nikomatsakis ok, closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. 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

4 participants