Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/thir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
}
ThreadLocalRef(_) => {}
Yield { value } => visitor.visit_expr(&visitor.thir()[value]),
Reborrow { .. } => {}
Reborrow { source, mutability: _, target: _ } => {
visitor.visit_expr(&visitor.thir()[source])
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions tests/ui/reborrow/reborrow-source-unsafety.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Regression test for rust-lang/rust#158033.

#![feature(reborrow)]
#![allow(dead_code)]
#![deny(unsafe_code)]

use std::marker::Reborrow;

struct Thing<'a> {
field: &'a mut usize,
}

impl<'a> Reborrow for Thing<'a> {}

fn takes(_: Thing<'_>) {}

fn main() {
let mut x = 0;
let thing = Thing { field: &mut x };
let y = 123usize;

takes({
let p: *const usize = &y;
std::hint::black_box(std::ptr::read(p));
//~^ ERROR call to unsafe function `std::ptr::read` is unsafe
thing
});
}
11 changes: 11 additions & 0 deletions tests/ui/reborrow/reborrow-source-unsafety.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0133]: call to unsafe function `std::ptr::read` is unsafe and requires unsafe function or block
--> $DIR/reborrow-source-unsafety.rs:24:30
|
LL | std::hint::black_box(std::ptr::read(p));
| ^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0133`.
Loading