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

Why does stacked borrows treat reference parameters specially? #295

Open
Storyyeller opened this issue Jul 3, 2021 · 2 comments
Open

Why does stacked borrows treat reference parameters specially? #295

Storyyeller opened this issue Jul 3, 2021 · 2 comments
Labels
A-aliasing-model Topic: Related to the aliasing model (e.g. Stacked/Tree Borrows) C-support Category: Supporting a user to solve a concrete problem

Comments

@Storyyeller
Copy link
Contributor

Why does stacked borrows treat reference parameters specially?

Naively, I would expect fn foo(x: &u8, y: &u8) and fn foo(xy: (&u8, &u8)) to be equivalent, but it appears that only in the former case are the references protected by a CallId. Is there an explanation for why it was decided to do things this way?

@bjorn3
Copy link
Member

bjorn3 commented Jul 3, 2021

See #125 for why this is.

@RalfJung
Copy link
Member

RalfJung commented Jul 4, 2021

Naively, I would expect fn foo(x: &u8, y: &u8) and fn foo(xy: (&u8, &u8)) to be equivalent

Yeah, that would be nice to have, and maybe the final version of Stacked Borrows will work like this.

But this also opens a few new questions, (some of) which are discussed in more depth in #125 as @bjorn3 mentioned:

  • Should we also recurse into private fields? If no, which module do we use to determine visibility? Wouldn't it be somewhat odd to be in a situation where adding pub to a field introduces UB? (It can introduce unsoundness, sure, but for UB I'd find this quite surprising.)
  • What about enums? Traversing structs is fairly straight-forward, but should Stacked Borrows really be in the business of extracting references out of Option<&T> and protect/retag them when the current variant is Some?

@RalfJung RalfJung added C-support Category: Supporting a user to solve a concrete problem A-aliasing-model Topic: Related to the aliasing model (e.g. Stacked/Tree Borrows) labels Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-aliasing-model Topic: Related to the aliasing model (e.g. Stacked/Tree Borrows) C-support Category: Supporting a user to solve a concrete problem
Projects
None yet
Development

No branches or pull requests

3 participants