From aa3fa254768f1cfe51fc013a24383153fa2b924a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 29 Jun 2017 00:02:21 +0200 Subject: [PATCH 1/2] Add E0619 error explanation --- src/librustc_typeck/diagnostics.rs | 21 +++++++++++++++++++++ src/test/compile-fail/E0619.rs | 14 ++++++-------- src/test/compile-fail/invalid-intrinsic.rs | 16 ---------------- 3 files changed, 27 insertions(+), 24 deletions(-) delete mode 100644 src/test/compile-fail/invalid-intrinsic.rs diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 1b17faccc87f8..8181dba1e960d 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -4666,6 +4666,7 @@ i_am_a_function(); "##, E0619: r##" +<<<<<<< HEAD The type-checker needed to know the type of an expression, but that type had not yet been inferred. @@ -4726,6 +4727,26 @@ let x = &[1_usize, 2] as &[usize]; // ok! ``` "##, +E0621: r##" +An intrinsic was declared without being a function. + +Erroneous code example: + +```compile_fail,E0621 +#![feature(intrinsics)] +extern "rust-intrinsic" { + pub static breakpoint : unsafe extern "rust-intrinsic" fn(); + // error: intrinsic must be a function +} + +fn main() { unsafe { breakpoint(); } } +``` + +An intrinsic is a function available for use in a given programming language +whose implementation is handled specially by the compiler. In order to fix this +error, just declare a function. +"##, + } register_diagnostics! { diff --git a/src/test/compile-fail/E0619.rs b/src/test/compile-fail/E0619.rs index 8ef90d8993192..7c61a61f0bd8a 100644 --- a/src/test/compile-fail/E0619.rs +++ b/src/test/compile-fail/E0619.rs @@ -1,4 +1,4 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,11 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn main() { - let x; - - match x { - (..) => {} //~ ERROR E0619 - _ => {} - } +#![feature(intrinsics)] +extern "rust-intrinsic" { + pub static breakpoint : unsafe extern "rust-intrinsic" fn(); + //~^ ERROR intrinsic must be a function [E0619] } +fn main() { unsafe { breakpoint(); } } diff --git a/src/test/compile-fail/invalid-intrinsic.rs b/src/test/compile-fail/invalid-intrinsic.rs deleted file mode 100644 index c42d78c323e3c..0000000000000 --- a/src/test/compile-fail/invalid-intrinsic.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(intrinsics)] -extern "rust-intrinsic" { - pub static breakpoint : unsafe extern "rust-intrinsic" fn(); - //~^ ERROR intrinsic must be a function -} -fn main() { unsafe { breakpoint(); } } From 162b5a347590a7dbc77d3281595b1bfaba98e3b1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 29 Jun 2017 21:03:19 +0200 Subject: [PATCH 2/2] Fix error codes mixup --- src/librustc_typeck/check/intrinsic.rs | 2 +- src/librustc_typeck/diagnostics.rs | 5 ++--- src/test/compile-fail/E0619.rs | 15 +++++++++------ src/test/compile-fail/E0622.rs | 16 ++++++++++++++++ 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 src/test/compile-fail/E0622.rs diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 3acfbd1d84403..96643ae72abad 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -37,7 +37,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, match it.node { hir::ForeignItemFn(..) => {} _ => { - struct_span_err!(tcx.sess, it.span, E0619, + struct_span_err!(tcx.sess, it.span, E0622, "intrinsic must be a function") .span_label(it.span, "expected a function") .emit(); diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 8181dba1e960d..37f6f3753d7b4 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -4666,7 +4666,6 @@ i_am_a_function(); "##, E0619: r##" -<<<<<<< HEAD The type-checker needed to know the type of an expression, but that type had not yet been inferred. @@ -4727,12 +4726,12 @@ let x = &[1_usize, 2] as &[usize]; // ok! ``` "##, -E0621: r##" +E0622: r##" An intrinsic was declared without being a function. Erroneous code example: -```compile_fail,E0621 +```compile_fail,E0622 #![feature(intrinsics)] extern "rust-intrinsic" { pub static breakpoint : unsafe extern "rust-intrinsic" fn(); diff --git a/src/test/compile-fail/E0619.rs b/src/test/compile-fail/E0619.rs index 7c61a61f0bd8a..a5a5ff7218dcf 100644 --- a/src/test/compile-fail/E0619.rs +++ b/src/test/compile-fail/E0619.rs @@ -1,4 +1,4 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,9 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(intrinsics)] -extern "rust-intrinsic" { - pub static breakpoint : unsafe extern "rust-intrinsic" fn(); - //~^ ERROR intrinsic must be a function [E0619] +fn main() { + let x; + + match x { + (..) => {} //~ ERROR E0619 + _ => {} + } } -fn main() { unsafe { breakpoint(); } } + diff --git a/src/test/compile-fail/E0622.rs b/src/test/compile-fail/E0622.rs new file mode 100644 index 0000000000000..f2bde5b03648b --- /dev/null +++ b/src/test/compile-fail/E0622.rs @@ -0,0 +1,16 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(intrinsics)] +extern "rust-intrinsic" { + pub static breakpoint : unsafe extern "rust-intrinsic" fn(); + //~^ ERROR intrinsic must be a function [E0622] +} +fn main() { unsafe { breakpoint(); } }