-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Incorrect unused mut warning in 1.46.0-nightly (f455e46ea 2020-06-20) #73592
Comments
Let's find the cause of this regression. |
Hey Cleanup Crew ICE-breakers! This bug has been identified as a good cc @AminArria @camelid @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke |
Reduced somewhat:
|
Bisected with searched nightlies: from nightly-2020-05-06 to nightly-2020-06-21 bisected with cargo-bisect-rustc v0.5.2Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --start 2020-05-06 |
Just bisected, found similar results. Thanks @SNCPlay42! Culprit PR is #73504 which is a rollup, however I don't see any obvious culprit in there... |
Actually, I think #72280 is the only possible culprit here, cc @nbdd0121 @nikomatsakis |
Consider this code, derived from #73592 (comment) use std::pin::Pin;
use std::sync::Mutex;
pub struct Stderr(Mutex<()>);
pub fn poll_write(x: Pin<&mut Stderr>) { // `x` is not `mut` here
let _ = &mut *x.0.lock().unwrap();
} This does not compile with stable or beta compiler, but compiles fine with the nightly compiler. I suspect this is a soundness issue, given that I think it was expected for #72280 to only fix diagnostics, and not let code like this compile. |
#72280 does not only fix diagnostics. It fixes two cases that should compile but didn't. I am looking into this right now. |
I don't think this is a soundness issue
I might be missing something obvious, but why should this not compile? Clearly |
I digged deeper and pin-pointed the reason for the behaviour change: Previous we type-check the receiver of the method with needs = rust/src/librustc_typeck/check/expr.rs Line 867 in 7bdf7d0
This means that DerefMut of Mutex will be used even though Deref would be sufficient. For types like Mutex/RefCell which gives something with DerefMut this is overly restrictive and unnecessary, so the compilation fails in stable.
This compiles in stable: use std::pin::Pin;
use std::sync::Mutex;
use std::ops::Deref;
pub struct Stderr(Mutex<()>);
pub fn poll_write(x: Pin<&mut Stderr>) {
let _ = &mut *Deref::deref(&x).0.lock().unwrap();
} My PR fixes this and will only use |
Given that rustc is allowed to generate additional warning in new versions, My opinion is that no fixes are necessary on rustc. I would recommend |
I was worried that the OP says
But this appears to be incorrect, removing the |
I retested to make sure to cover the cases mentioned above. When removing the
both fail with the following error
However the nightly (1.46.0-nightly (f455e46 2020-06-20)) version does compile. |
I agree with @nbdd0121 that this appears to be a bug fix, and that |
I think we should then close this issue as working as intended? |
We may want to add a UI test to ensure that the code without mut compiles and the code with mut triggers a warning. |
Yes, +1 to a suitable test. |
@rustbot claim |
Add UI test for issue 73592 It happens that rust-lang#72280 accidentally fixed a bug which is later discovered in rust-lang#73592. This PR adds a UI test to prevent future regression. Closes rust-lang#73592
CI on https://github.com/async-rs/async-std suddenly started failing as we run with
deny warnings
.the error is
for the following code
which stops compiling if the referenced
mut
is removed.(Sorry in advance if this is known, but I couldn't find a matching issue)
CI run: https://github.com/async-rs/async-std/pull/822/checks?check_run_id=793134400
Source Code: https://github.com/async-rs/async-std/blob/master/src/io/stderr.rs#L90-L96
Edit: It seems that the nightly version might not be what triggered it, but rather a change in the underlying implementation of the
lock
that is being called above.No warnings under
This issue has been assigned to @nbdd0121 via this comment.
The text was updated successfully, but these errors were encountered: