From 953d6dfd7e1b1d5c5b17314b6e3bdec15d8e7a01 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 16 Jan 2015 15:54:58 -0800 Subject: Make error code registration work again. #19624 --- src/libsyntax/diagnostics/plugin.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/libsyntax/diagnostics') diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 1469c50061c..0e99829fa1c 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -65,6 +65,13 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt, } () }); + with_registered_diagnostics(|diagnostics| { + if !diagnostics.contains_key(&code.name) { + ecx.span_err(span, &format!( + "used diagnostic code {} not registered", token::get_ident(code).get() + )[]); + } + }); MacExpr::new(quote_expr!(ecx, ())) } -- cgit 1.4.1-3-g733a5 From f68029ec94415298e56ab20f73bcf2a1224ace4d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 18 Jan 2015 13:39:18 -0800 Subject: Make fatal errors work with codes, add to typeck --- src/librustc/session/mod.rs | 3 +++ src/librustc_typeck/astconv.rs | 44 ++++++++++++++++++------------------- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/diagnostics.rs | 13 ++++++++++- src/librustc_typeck/lib.rs | 2 +- src/libsyntax/diagnostic.rs | 4 ++++ src/libsyntax/diagnostics/macros.rs | 8 +++++++ 7 files changed, 50 insertions(+), 26 deletions(-) (limited to 'src/libsyntax/diagnostics') diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 5424b1c8cae..0392fbfdeae 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -69,6 +69,9 @@ impl Session { pub fn span_fatal(&self, sp: Span, msg: &str) -> ! { self.diagnostic().span_fatal(sp, msg) } + pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str) -> ! { + self.diagnostic().span_fatal_with_code(sp, msg, code) + } pub fn fatal(&self, msg: &str) -> ! { self.diagnostic().handler().fatal(msg) } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 080959cae0c..cfcc65bd15a 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -339,22 +339,22 @@ fn create_substs_for_ast_path<'tcx>( } else { "expected" }; - this.tcx().sess.span_fatal(span, - &format!("wrong number of type arguments: {} {}, found {}", + span_fatal!(this.tcx().sess, span, E0243, + "wrong number of type arguments: {} {}, found {}", expected, required_ty_param_count, - supplied_ty_param_count)[]); + supplied_ty_param_count); } else if supplied_ty_param_count > formal_ty_param_count { let expected = if required_ty_param_count < formal_ty_param_count { "expected at most" } else { "expected" }; - this.tcx().sess.span_fatal(span, - &format!("wrong number of type arguments: {} {}, found {}", + span_fatal!(this.tcx().sess, span, E0244, + "wrong number of type arguments: {} {}, found {}", expected, formal_ty_param_count, - supplied_ty_param_count)[]); + supplied_ty_param_count); } let mut substs = Substs::new_type(types, regions); @@ -557,10 +557,9 @@ pub fn instantiate_trait_ref<'tcx>( trait_ref } _ => { - this.tcx().sess.span_fatal( - ast_trait_ref.path.span, - &format!("`{}` is not a trait", - ast_trait_ref.path.user_string(this.tcx()))[]); + span_fatal!(this.tcx().sess, ast_trait_ref.path.span, E0245, + "`{}` is not a trait", + ast_trait_ref.path.user_string(this.tcx())); } } } @@ -1036,7 +1035,7 @@ pub fn ast_ty_to_ty<'tcx>( match ast_ty_to_ty_cache.get(&ast_ty.id) { Some(&ty::atttce_resolved(ty)) => return ty, Some(&ty::atttce_unresolved) => { - tcx.sess.span_fatal(ast_ty.span, + span_fatal!(tcx.sess, ast_ty.span, E0246, "illegal recursive type; insert an enum \ or struct in the cycle, if this is \ desired"); @@ -1136,9 +1135,9 @@ pub fn ast_ty_to_ty<'tcx>( ty::mk_self_type(tcx) } def::DefMod(id) => { - tcx.sess.span_fatal(ast_ty.span, - &format!("found module name used as a type: {}", - tcx.map.node_to_string(id.node))[]); + span_fatal!(tcx.sess, ast_ty.span, E0247, + "found module name used as a type: {}", + tcx.map.node_to_string(id.node)); } def::DefPrimTy(_) => { panic!("DefPrimTy arm missed in previous ast_ty_to_prim_ty call"); @@ -1164,10 +1163,10 @@ pub fn ast_ty_to_ty<'tcx>( associated_path_def_to_ty(this, ast_ty, provenance, assoc_ident.name) } _ => { - tcx.sess.span_fatal(ast_ty.span, - &format!("found value name used \ + span_fatal!(tcx.sess, ast_ty.span, E0248, + "found value name used \ as a type: {:?}", - a_def)[]); + a_def); } } } @@ -1185,17 +1184,16 @@ pub fn ast_ty_to_ty<'tcx>( ty::mk_vec(tcx, ast_ty_to_ty(this, rscope, &**ty), Some(i as uint)), _ => { - tcx.sess.span_fatal( - ast_ty.span, "expected constant expr for array length"); + span_fatal!(tcx.sess, ast_ty.span, E0249, + "expected constant expr for array length"); } } } Err(ref r) => { - tcx.sess.span_fatal( - ast_ty.span, - &format!("expected constant expr for array \ + span_fatal!(tcx.sess, ast_ty.span, E0250, + "expected constant expr for array \ length: {}", - *r)[]); + *r); } } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 58b655d7585..db4962b0d22 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -5224,7 +5224,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) { "get_tydesc" => { let tydesc_ty = match ty::get_tydesc_ty(ccx.tcx) { Ok(t) => t, - Err(s) => { tcx.sess.span_fatal(it.span, &s[]); } + Err(s) => { span_fatal!(tcx.sess, it.span, E0240, "{}", &s[]); } }; let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt { ty: tydesc_ty, diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index ce30cb91c91..3627fa41160 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -160,7 +160,18 @@ register_diagnostics! { E0236, // no lang item for range syntax E0237, // no lang item for range syntax E0238, // parenthesized parameters may only be used with a trait - E0239 // `next` method of `Iterator` trait has unexpected type + E0239, // `next` method of `Iterator` trait has unexpected type + E0240, + E0241, + E0242, // internal error looking up a definition + E0243, // wrong number of type arguments + E0244, // wrong number of type arguments + E0245, // not a trait + E0246, // illegal recursive type + E0247, // found module name used as a type + E0248, // found value name used as a type + E0249, // expected constant expr for array length + E0250 // expected constant expr for array length } __build_diagnostic_array! { DIAGNOSTICS } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index aa99549bcd6..78007f3552e 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -162,7 +162,7 @@ fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def { match tcx.def_map.borrow().get(&id) { Some(x) => x.clone(), _ => { - tcx.sess.span_fatal(sp, "internal error looking up a definition") + span_fatal!(tcx.sess, sp, E0242, "internal error looking up a definition") } } } diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 7213b0fa955..b26ec64c24b 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -92,6 +92,10 @@ impl SpanHandler { self.handler.emit(Some((&self.cm, sp)), msg, Fatal); panic!(FatalError); } + pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str) -> ! { + self.handler.emit_with_code(Some((&self.cm, sp)), msg, code, Fatal); + panic!(FatalError); + } pub fn span_err(&self, sp: Span, msg: &str) { self.handler.emit(Some((&self.cm, sp)), msg, Error); self.handler.bump_err_count(); diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs index 34a193dffd3..5bd683c86ae 100644 --- a/src/libsyntax/diagnostics/macros.rs +++ b/src/libsyntax/diagnostics/macros.rs @@ -14,6 +14,14 @@ macro_rules! register_diagnostic { ($code:tt) => (__register_diagnostic! { $code }) } +#[macro_export] +macro_rules! span_fatal { + ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ + __diagnostic_used!($code); + $session.span_fatal_with_code($span, format!($($message)*).as_slice(), stringify!($code)) + }) +} + #[macro_export] macro_rules! span_err { ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ -- cgit 1.4.1-3-g733a5 From 9a4401fe828f2f29c359bc3c83f6f3b7eed27d83 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Sat, 17 Jan 2015 17:20:24 -0800 Subject: Add some extended errors. --- src/librustc/diagnostics.rs | 40 +++++++++++++++++++++++++++++++------ src/libsyntax/diagnostics/macros.rs | 6 ++++++ 2 files changed, 40 insertions(+), 6 deletions(-) (limited to 'src/libsyntax/diagnostics') diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 1dbd6eb4e8d..b48df36a679 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -10,21 +10,49 @@ #![allow(non_snake_case)] -register_diagnostic! { E0001, r##" +register_long_diagnostics! { + E0001: r##" This error suggests that the expression arm corresponding to the noted pattern will never be reached as for all possible values of the expression being matched, one of the preceeding patterns will match. This means that perhaps some of the preceeding patterns are too general, this one is too specific or the ordering is incorrect. -"## } +"##, + + E0003: r##" + Not-a-Number (NaN) values can not be compared for equality and hence can never match + the input to a match expression. To match against NaN values, you should instead use + the `is_nan` method in a guard, as in: x if x.is_nan() => ... +"##, + + E0004: r##" + This error indicates that the compiler can not guarantee a matching pattern for one + or more possible inputs to a match expression. Guaranteed matches are required in order + to assign values to match expressions, or alternatively, determine the flow of execution. + + If you encounter this error you must alter your patterns so that every possible value of + the input type is matched. For types with a small number of variants (like enums) you + should probably cover all cases explicitly. Alternatively, the underscore `_` wildcard + pattern can be added after all other patterns to match "anything else". +"##, + + // FIXME: Remove duplication here? + E0005: r##" + Patterns used to bind names must be irrefutable, that is, they must guarantee that a + name will be extracted in all cases. If you encounter this error you probably need + to use a `match` or `if let` to deal with the possibility of failure. +"##, + + E0006: r##" + Patterns used to bind names must be irrefutable, that is, they must guarantee that a + name will be extracted in all cases. If you encounter this error you probably need + to use a `match` or `if let` to deal with the possibility of failure. +"## +} register_diagnostics! { E0002, - E0003, - E0004, - E0005, - E0006, E0007, E0008, E0009, diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs index 5bd683c86ae..9321d3ca3df 100644 --- a/src/libsyntax/diagnostics/macros.rs +++ b/src/libsyntax/diagnostics/macros.rs @@ -59,3 +59,9 @@ macro_rules! register_diagnostics { ) } +#[macro_export] +macro_rules! register_long_diagnostics { + ($($code:tt: $description:tt),*) => ( + $(register_diagnostic! { $code, $description })* + ) +} -- cgit 1.4.1-3-g733a5 From 90af72378d9f848de78adc5003dff6b90f327b3c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 21 Jan 2015 14:32:54 -0800 Subject: Make diagnostic ordering deterministic --- src/librustc/diagnostics.rs | 2 -- src/libsyntax/diagnostics/plugin.rs | 14 +++++++------- src/test/debuginfo/vec-slices.rs | 1 + src/test/run-pass/issue-20797.rs | 3 +++ 4 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src/libsyntax/diagnostics') diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 653ade67b72..b48df36a679 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -77,8 +77,6 @@ register_diagnostics! { E0138, E0139, E0152, - E0153, - E0157, E0158, E0161, E0162, diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 0e99829fa1c..bd5247bbad6 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -9,7 +9,7 @@ // except according to those terms. use std::cell::RefCell; -use std::collections::HashMap; +use std::collections::BTreeMap; use ast; use ast::{Ident, Name, TokenTree}; use codemap::Span; @@ -19,18 +19,18 @@ use parse::token; use ptr::P; thread_local! { - static REGISTERED_DIAGNOSTICS: RefCell>> = { - RefCell::new(HashMap::new()) + static REGISTERED_DIAGNOSTICS: RefCell>> = { + RefCell::new(BTreeMap::new()) } } thread_local! { - static USED_DIAGNOSTICS: RefCell> = { - RefCell::new(HashMap::new()) + static USED_DIAGNOSTICS: RefCell> = { + RefCell::new(BTreeMap::new()) } } fn with_registered_diagnostics(f: F) -> T where - F: FnOnce(&mut HashMap>) -> T, + F: FnOnce(&mut BTreeMap>) -> T, { REGISTERED_DIAGNOSTICS.with(move |slot| { f(&mut *slot.borrow_mut()) @@ -38,7 +38,7 @@ fn with_registered_diagnostics(f: F) -> T where } fn with_used_diagnostics(f: F) -> T where - F: FnOnce(&mut HashMap) -> T, + F: FnOnce(&mut BTreeMap) -> T, { USED_DIAGNOSTICS.with(move |slot| { f(&mut *slot.borrow_mut()) diff --git a/src/test/debuginfo/vec-slices.rs b/src/test/debuginfo/vec-slices.rs index 949dffaac06..3ceb3946f3c 100644 --- a/src/test/debuginfo/vec-slices.rs +++ b/src/test/debuginfo/vec-slices.rs @@ -9,6 +9,7 @@ // except according to those terms. // ignore-android: FIXME(#10381) +// ignore-windows // min-lldb-version: 310 // compile-flags:-g diff --git a/src/test/run-pass/issue-20797.rs b/src/test/run-pass/issue-20797.rs index c4f3c33f269..089b6f31975 100644 --- a/src/test/run-pass/issue-20797.rs +++ b/src/test/run-pass/issue-20797.rs @@ -8,6 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-android +// ignore-windows + // Regression test for #20797. use std::default::Default; -- cgit 1.4.1-3-g733a5