Skip to content

Commit fe5f685

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35780 - clementmiao:E0396_new_err_format, r=jonathandturner
updated E0396 to new error format Updated E0396 to new error format. Part of rust-lang#35233 Fixes rust-lang#35779 Thanks again for letting me help! r? @jonathandturner
2 parents bf934f9 + dae1406 commit fe5f685

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,13 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
493493
if let ty::TyRawPtr(_) = base_ty.sty {
494494
this.add(Qualif::NOT_CONST);
495495
if this.mode != Mode::Fn {
496-
span_err!(this.tcx.sess, this.span, E0396,
497-
"raw pointers cannot be dereferenced in {}s",
498-
this.mode);
496+
struct_span_err!(this.tcx.sess,
497+
this.span, E0396,
498+
"raw pointers cannot be dereferenced in {}s",
499+
this.mode)
500+
.span_label(this.span,
501+
&format!("dereference of raw pointer in constant"))
502+
.emit();
499503
}
500504
}
501505
}

src/test/compile-fail/E0396.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
const REG_ADDR: *const u8 = 0x5f3759df as *const u8;
1212

1313
const VALUE: u8 = unsafe { *REG_ADDR }; //~ ERROR E0396
14+
//~| NOTE dereference of raw pointer in constant
1415

1516
fn main() {
1617
}

src/test/compile-fail/const-deref-ptr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212

1313
fn main() {
1414
static C: u64 = unsafe {*(0xdeadbeef as *const u64)}; //~ ERROR E0396
15+
//~| NOTE dereference of raw pointer in constant
1516
println!("{}", C);
1617
}

0 commit comments

Comments
 (0)