Skip to content

Commit ae3b961

Browse files
committed
ask people to reach out if we declare too much UB
1 parent c5c0f85 commit ae3b961

10 files changed

+31
-22
lines changed

src/borrow_tracker/stacked_borrows/diagnostics.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ use rustc_span::{Span, SpanData};
66
use rustc_target::abi::Size;
77

88
use crate::borrow_tracker::{
9-
stacked_borrows::{err_sb_ub, Permission},
10-
AccessKind, GlobalStateInner, ProtectorKind,
9+
stacked_borrows::Permission, AccessKind, GlobalStateInner, ProtectorKind,
1110
};
1211
use crate::*;
1312

13+
/// Error reporting
14+
fn err_sb_ub<'tcx>(
15+
msg: String,
16+
help: Vec<String>,
17+
history: Option<TagHistory>,
18+
) -> InterpError<'tcx> {
19+
err_machine_stop!(TerminationInfo::StackedBorrowsUb { msg, help, history })
20+
}
21+
1422
#[derive(Clone, Debug)]
1523
pub struct AllocHistory {
1624
id: AllocId,
@@ -381,9 +389,13 @@ impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
381389
self.history.id,
382390
self.offset.bytes(),
383391
);
392+
let mut helps = vec![operation_summary(&op.info.summary(), self.history.id, op.range)];
393+
if op.info.in_field {
394+
helps.push(format!("errors for retagging in fields are fairly new; please reach out to us (e.g. at <https://rust-lang.zulipchat.com/#narrow/stream/269128-miri>) if you find this error troubling"));
395+
}
384396
err_sb_ub(
385397
format!("{action}{}", error_cause(stack, op.orig_tag)),
386-
Some(operation_summary(&op.info.summary(), self.history.id, op.range)),
398+
helps,
387399
op.orig_tag.and_then(|orig_tag| self.get_logs_relevant_to(orig_tag, None)),
388400
)
389401
}
@@ -406,7 +418,7 @@ impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
406418
);
407419
err_sb_ub(
408420
format!("{action}{}", error_cause(stack, op.tag)),
409-
Some(operation_summary("an access", self.history.id, op.range)),
421+
vec![operation_summary("an access", self.history.id, op.range)],
410422
op.tag.and_then(|tag| self.get_logs_relevant_to(tag, None)),
411423
)
412424
}
@@ -432,7 +444,7 @@ impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
432444
Operation::Dealloc(_) =>
433445
err_sb_ub(
434446
format!("deallocating while item {item:?} is {protected} by call {call_id:?}",),
435-
None,
447+
vec![],
436448
None,
437449
),
438450
Operation::Retag(RetagOp { orig_tag: tag, .. })
@@ -441,7 +453,7 @@ impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
441453
format!(
442454
"not granting access to tag {tag:?} because that would remove {item:?} which is {protected} because it is an argument of call {call_id:?}",
443455
),
444-
None,
456+
vec![],
445457
tag.and_then(|tag| self.get_logs_relevant_to(tag, Some(item.tag()))),
446458
),
447459
}
@@ -459,7 +471,7 @@ impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
459471
alloc_id = self.history.id,
460472
cause = error_cause(stack, op.tag),
461473
),
462-
None,
474+
vec![],
463475
op.tag.and_then(|tag| self.get_logs_relevant_to(tag, None)),
464476
)
465477
}

src/borrow_tracker/stacked_borrows/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::ty::{
2121
use rustc_target::abi::{Abi, Size};
2222

2323
use crate::borrow_tracker::{
24-
stacked_borrows::diagnostics::{AllocHistory, DiagnosticCx, DiagnosticCxBuilder, TagHistory},
24+
stacked_borrows::diagnostics::{AllocHistory, DiagnosticCx, DiagnosticCxBuilder},
2525
AccessKind, GlobalStateInner, ProtectorKind, RetagFields,
2626
};
2727
use crate::*;
@@ -170,15 +170,6 @@ impl NewPermission {
170170
}
171171
}
172172

173-
/// Error reporting
174-
pub fn err_sb_ub<'tcx>(
175-
msg: String,
176-
help: Option<String>,
177-
history: Option<TagHistory>,
178-
) -> InterpError<'tcx> {
179-
err_machine_stop!(TerminationInfo::StackedBorrowsUb { msg, help, history })
180-
}
181-
182173
// # Stacked Borrows Core Begin
183174

184175
/// We need to make at least the following things true:

src/diagnostics.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub enum TerminationInfo {
2222
UnsupportedInIsolation(String),
2323
StackedBorrowsUb {
2424
msg: String,
25-
help: Option<String>,
25+
help: Vec<String>,
2626
history: Option<TagHistory>,
2727
},
2828
TreeBorrowsUb {
@@ -224,11 +224,10 @@ pub fn report_error<'tcx, 'mir>(
224224
(None, format!("or pass `-Zmiri-isolation-error=warn` to configure Miri to return an error code from isolated operations (if supported for that operation) and continue with a warning")),
225225
],
226226
StackedBorrowsUb { help, history, .. } => {
227-
let url = "https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md";
228227
msg.extend(help.clone());
229228
let mut helps = vec![
230229
(None, format!("this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental")),
231-
(None, format!("see {url} for further information")),
230+
(None, format!("see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information")),
232231
];
233232
if let Some(TagHistory {created, invalidated, protected}) = history.clone() {
234233
helps.push((Some(created.1), created.0));

tests/fail/both_borrows/buggy_split_at_mut.stack.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ LL | | from_raw_parts_mut(ptr.offset(mid as isize), len - mid),
77
LL | | )
88
| | ^
99
| | |
10-
| |_____________trying to retag from <TAG> for Unique permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
11-
| this error occurs as part of retag (of a reference/box inside this compound value) at ALLOC[0x0..0x10]
10+
| | trying to retag from <TAG> for Unique permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
11+
| |_____________this error occurs as part of retag (of a reference/box inside this compound value) at ALLOC[0x0..0x10]
12+
| errors for retagging in fields are fairly new; please reach out to us (e.g. at <https://rust-lang.zulipchat.com/#narrow/stream/269128-miri>) if you find this error troubling
1213
|
1314
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1415
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

tests/fail/both_borrows/pass_invalid_shr_option.stack.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | foo(some_xref);
66
| |
77
| trying to retag from <TAG> for SharedReadOnly permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of retag (of a reference/box inside this compound value) at ALLOC[0x0..0x4]
9+
| errors for retagging in fields are fairly new; please reach out to us (e.g. at <https://rust-lang.zulipchat.com/#narrow/stream/269128-miri>) if you find this error troubling
910
|
1011
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1112
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

tests/fail/both_borrows/pass_invalid_shr_tuple.stack.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | foo(pair_xref);
66
| |
77
| trying to retag from <TAG> for SharedReadOnly permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of retag (of a reference/box inside this compound value) at ALLOC[0x0..0x4]
9+
| errors for retagging in fields are fairly new; please reach out to us (e.g. at <https://rust-lang.zulipchat.com/#narrow/stream/269128-miri>) if you find this error troubling
910
|
1011
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1112
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

tests/fail/both_borrows/return_invalid_shr_option.stack.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | ret
66
| |
77
| trying to retag from <TAG> for SharedReadOnly permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of retag (of a reference/box inside this compound value) at ALLOC[0x4..0x8]
9+
| errors for retagging in fields are fairly new; please reach out to us (e.g. at <https://rust-lang.zulipchat.com/#narrow/stream/269128-miri>) if you find this error troubling
910
|
1011
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1112
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

tests/fail/both_borrows/return_invalid_shr_tuple.stack.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | ret
66
| |
77
| trying to retag from <TAG> for SharedReadOnly permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of retag (of a reference/box inside this compound value) at ALLOC[0x4..0x8]
9+
| errors for retagging in fields are fairly new; please reach out to us (e.g. at <https://rust-lang.zulipchat.com/#narrow/stream/269128-miri>) if you find this error troubling
910
|
1011
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1112
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

tests/fail/stacked_borrows/return_invalid_mut_option.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | ret
66
| |
77
| trying to retag from <TAG> for Unique permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of retag (of a reference/box inside this compound value) at ALLOC[0x4..0x8]
9+
| errors for retagging in fields are fairly new; please reach out to us (e.g. at <https://rust-lang.zulipchat.com/#narrow/stream/269128-miri>) if you find this error troubling
910
|
1011
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1112
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

tests/fail/stacked_borrows/return_invalid_mut_tuple.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | ret
66
| |
77
| trying to retag from <TAG> for Unique permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of retag (of a reference/box inside this compound value) at ALLOC[0x4..0x8]
9+
| errors for retagging in fields are fairly new; please reach out to us (e.g. at <https://rust-lang.zulipchat.com/#narrow/stream/269128-miri>) if you find this error troubling
910
|
1011
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1112
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

0 commit comments

Comments
 (0)