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

Compiler Warnings 2018-07-30 #2982

Closed
ghost opened this issue Jul 31, 2018 · 4 comments
Closed

Compiler Warnings 2018-07-30 #2982

ghost opened this issue Jul 31, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented Jul 31, 2018

When building Clippy the compiler now emits the warnings below:

warning[E0502]: cannot borrow `reg.sess.target` as immutable because it is also borrowed as mutable
   --> clippy_lints/src/lib.rs:371:13
    |
369 |       reg.register_late_lint_pass(box trivially_copy_pass_by_ref::TriviallyCopyPassByRef::new(
    |       ---
    |       |
    |  _____mutable borrow occurs here
    | |
370 | |             conf.trivial_copy_size_limit,
371 | |             &reg.sess.target,
    | |             ^^^^^^^^^^^^^^^^ immutable borrow occurs here
372 | |     ));
    | |______- borrow later used here
    |
    = warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
            It represents potential unsoundness in your code.
            This warning will become a hard error in the future.

warning: variable does not need to be mutable
   --> clippy_lints/src/consts.rs:244:21
    |
244 |                 let mut value = !value;
    |                     ----^^^^^
    |                     |
    |                     help: remove this `mut`
    |
    = note: #[warn(unused_mut)] on by default

warning[E0502]: cannot borrow `self.cx.tcx` as immutable because it is also borrowed as mutable
   --> clippy_lints/src/utils/hir_utils.rs:518:33
    |
518 |                 self.hash_expr(&self.cx.tcx.hir.body(l_id.body).value);
    |                 ----------------^^^^^^^^^^^---------------------------
    |                 |               |
    |                 |               immutable borrow occurs here
    |                 mutable borrow occurs here
    |                 borrow later used here
    |
    = warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
            It represents potential unsoundness in your code.
            This warning will become a hard error in the future.

warning[E0502]: cannot borrow `self.cx.tcx` as immutable because it is also borrowed as mutable
   --> clippy_lints/src/utils/hir_utils.rs:451:33
    |
451 |                 self.hash_expr(&self.cx.tcx.hir.body(eid).value);
    |                 ----------------^^^^^^^^^^^---------------------
    |                 |               |
    |                 |               immutable borrow occurs here
    |                 mutable borrow occurs here
    |                 borrow later used here
    |
    = warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
            It represents potential unsoundness in your code.
            This warning will become a hard error in the future.

I've already got a fix for the unused_mut error.
Is this a compiler issue or are these warnings genuine? Shouldn't the borrow on the argument end before the method is called?

@ghost ghost mentioned this issue Jul 31, 2018
@flip1995
Copy link
Member

@pnkfelix
Copy link
Member

pnkfelix commented Jul 31, 2018

Hmm, i would have expected at least some of these cases to be allowed in NLL due to two-phase borrows...

Update: Oh, no, i think I misread the code. two-phase borrows let you do an immutable borrow during an expression that evaluated for a method call's parameter, but the borrow has to end before the method itself gets around to executing. In the cases that I misidentified as being potentially allowed, I think you have immutable borrows that are lasting long enough to leak into the method call execution.

@pnkfelix
Copy link
Member

pnkfelix commented Jul 31, 2018

(Still this case is interesting because I don't think I was aware of an AST-borrowck soundness bug of this form, and yet this seems to be one...)

((Or maybe the borrows here are of derefed data, and it doesn’t actually conflict with the &mut. So that would bring me back to thinking this is a weakness in two phase borrows ))

@nikomatsakis
Copy link
Contributor

I believe @pnkfelix that this could be rust-lang/rust#38899

@ghost ghost mentioned this issue Aug 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants