Skip to content

Commit

Permalink
Rollup merge of rust-lang#35780 - clementmiao:E0396_new_err_format, r…
Browse files Browse the repository at this point in the history
…=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
  • Loading branch information
Jonathan Turner committed Aug 19, 2016
2 parents e38299d + dae1406 commit 8c74eb6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,13 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
if let ty::TyRawPtr(_) = base_ty.sty {
this.add(Qualif::NOT_CONST);
if this.mode != Mode::Fn {
span_err!(this.tcx.sess, this.span, E0396,
"raw pointers cannot be dereferenced in {}s",
this.mode);
struct_span_err!(this.tcx.sess,
this.span, E0396,
"raw pointers cannot be dereferenced in {}s",
this.mode)
.span_label(this.span,
&format!("dereference of raw pointer in constant"))
.emit();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/E0396.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const REG_ADDR: *const u8 = 0x5f3759df as *const u8;

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

fn main() {
}
1 change: 1 addition & 0 deletions src/test/compile-fail/const-deref-ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@

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

0 comments on commit 8c74eb6

Please sign in to comment.