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

Confusing error message when using CellRef #41865

Closed
spirali opened this Issue May 9, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@spirali
Copy link

spirali commented May 9, 2017

Hello,

It took me some time to understand the following problem.

The following code ends with error:

error: the type of this value must be known in this context
  --> main.rs:14:34
   |
14 |     println!("Hello, world! {}", sb.flag);
   |                                  ^^^^^^^
use std::rc::Rc;
use std::cell::RefCell;
use std::borrow::Borrow;


pub struct S {
	flag : bool
}

type SCell = Rc<RefCell<S>>;

fn test(s : SCell) {
    let sb =  &s.borrow();
    println!("Hello, world! {}", sb.flag);
}

fn main() {
    let s = Rc::new(RefCell::new(S{flag: false}));
    test(s);
}

However, the similar construction works in many other situation and a natural fix (let sb : &S = &s.borrow();) does not work. I was not able to understand the problem until @gavento pointed out that the problem is with use std::borrow::Borrow;. When the line is removed, the code is compiled without any error.

I suggest to improve the error message in a way that indicates that problem is with the borrow method, since the current error message pointing to the structure usage is quite confusing (at least for me:).

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

Mark-Simulacrum commented Jun 22, 2017

I'm going to close this as the underlying problem here is #41906.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.