-
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
Erroneous multiple mutable borrows message #18803
Comments
The complier output is:
I think this is to do with how the compiler handles unused lifetimes. You probably want to be storing it with a cc @nikomatsakis for confirmation. |
Thanks! I removed |
And follow-up question: if this is the wrong way, what's the right one? I'm trying to make sure that an OpenGL context exists when I do things like create shaders, but the design above doesn't work, and neither does:
Edit: One option is to separate the creation of the structs from their initialization, so that the structs can always be created with an immutable context (e.g. having no calls to |
@nikomatsakis I do specifically want the compiler giving me sane checks for mutable usage of the OpenGL context, though (and also to not incur runtime overhead). My solution right now is to have a |
So is this a bug or not? |
Ah, I meant to reply to @bfops, sorry about that. I think this it not a bug. Basically, this is how the type system works. That said, there might be a way to express what @bfops wanted with some cleverness. Or else it is potential fodder for future type-system extensions. @bfops maybe you can ping me on IRC and we can go over the example? Right now this is all kind of "out of cache". |
SGTM thanks! |
The following fails to compile:
If I inline the definition of
Shaders::new
, it compiles. If I remove theVec
and just store a singleShaderHandle
in eachShaders
, it compiles. Is this a bug, or some subtlety in borrow semantics?The text was updated successfully, but these errors were encountered: