Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E0396 new error format #35779

Closed
Closed
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
22 changes: 16 additions & 6 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,14 @@ 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 Expand Up @@ -678,9 +683,14 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {

self.add(Qualif::NOT_CONST);
if self.mode != Mode::Fn {
span_err!(self.tcx.sess, self.span, E0395,
"raw pointers cannot be compared in {}s",
self.mode);
struct_span_err!(
self.tcx.sess, self.span, E0395,
"raw pointers cannot be compared in {}s",
self.mode)
.span_label(
self.span,
&format!("comparing raw pointers in static"))
.emit();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/E0395.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ static FOO: i32 = 42;
static BAR: i32 = 42;

static BAZ: bool = { (&FOO as *const i32) == (&BAR as *const i32) }; //~ ERROR E0395

//~| NOTE comparing raw pointers in static
fn main() {
}
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);
}
1 change: 1 addition & 0 deletions src/test/compile-fail/issue-25826.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ fn id<T>(t: T) -> T { t }
fn main() {
const A: bool = id::<u8> as *const () < id::<u16> as *const ();
//~^ ERROR raw pointers cannot be compared in constants [E0395]
//~^^ NOTE comparing raw pointers in static
println!("{}", A);
}