miri icon indicating copy to clipboard operation
miri copied to clipboard

Stacked Borrows "is this argument" diagnostics go wrong for protected in-place function arguments

Open RalfJung opened this issue 1 year ago • 4 comments

For example, in this test case, or in this one, it doesn't even point at something that is an argument.

Cc @saethlin

RalfJung avatar Sep 05 '23 06:09 RalfJung

🤨 Is the problem here just that custom MIR doesn't have coherent spans? Is it supposed to? My instinct is that anyone using custom MIR has already opted out of usable diagnostics.

saethlin avatar Sep 05 '23 13:09 saethlin

No, the spans are fine. The problem is that we're using protectors for things that are not function arguments. When a function argument is passed by-move, then we put a protector on the memory it comes from. We also put a protector on the return place. The diagnostics assume that only function arguments are protected and then things go downhill from there.

Reliably triggering these errors requires custom MIR, but with MIR optimizations it might be possible to also trigger those errors without nightly features. The initially created MIR has enough temporaries to make it impossible to trigger the error (as far as I know).

RalfJung avatar Sep 05 '23 13:09 RalfJung

Ah I see! My brain grouped the diagnostic with the wrong span in the error. At first glance this seems pretty thorny to do a good diagnostic for. Hm.

saethlin avatar Sep 05 '23 14:09 saethlin

Yeah it's definitely tricky, and also fairly low-priority since it cannot usually be encountered by users.

RalfJung avatar Sep 05 '23 14:09 RalfJung