Using std::borrow::Borrow has sneaky consequences #66630
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-bug
Category: This is a bug.
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
E-hard
Call for participation: Hard difficulty. Experience needed to fix: A lot.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Consider the following playground that compiles fine:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d735c0950cb1b25e8ff19e6a5c9d0445
Uncommenting the
use std::borrow::Borrow;
breaks it quite badly:This problem does not appear when there is no
RefCell
inside theMutex
.This creates confusion when the same function works in a module and not in another.
Especially when Borrow is not implemented directly by
Mutex
orMutexGuard
it is quite hard to understand what happens here, I guess it is due to a blanket implementation sinceRefCell<i32>
isSized
.My main issue in this situation is that I spent a lot of time facing this compilation issue in a module whereas the same kind of code worked in multiple other modules. I had to comment/remove every other struct/impls/use in the module until I found the culprit.
Maybe the error message could be improved to hint at traits in scope that could alter the expected behavior ?
The issue appeared on stable and nightly (rustc 1.41.0-nightly (53712f8 2019-11-21)).
The text was updated successfully, but these errors were encountered: