-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Give all fatals, errors, and warnings unique diagnostic codes #12144
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b4f483d
rustc: Add the __tt_map_insert and __tt_map_get_expr macros
brson dda818b
rustc: Introduce a new diagnostic code registry
brson 24cc6bd
Introduce more diagnostic infrastructure
brson e529322
Convert to new diagnostics
brson d9c7a8c
rustc: Add UI for extended diagnostics
brson febb7f8
Slightly improve the format of the diagnostic database.
brson e610e6e
Address review feedback
brson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
rustc: Add the __tt_map_insert and __tt_map_get_expr macros
Behind the `__tt_map` feature gate. This feature name starts with a double underscore to emphasize it's a hack, but there's no precedent for naming features this way.
- Loading branch information
commit b4f483db9afe60a00be74200b5f42d05253432e6
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2014 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
/* | ||
* The token-tree map syntax extension maintains an arbitrary number | ||
* of named maps from ident to token-tree. Token trees can be stored | ||
* into a map with the `__tt_map_insert!` macro and retrieved as an | ||
* expression with the `__tt_map_get_expr!` macro. | ||
* | ||
* This is a hack used to maintain the tables of constants used by | ||
* the rustc error reporting system. In particular, it allows string | ||
* literals to be reused in multiple places without duplication. | ||
*/ | ||
|
||
use ast; | ||
use codemap::Span; | ||
use ext::base::{ExtCtxt, MacResult, MRExpr, MRItem}; | ||
use ext::build::AstBuilder; | ||
use parse::token; | ||
use parse::token::{gensym, get_ident}; | ||
use parse::new_parser_from_tts; | ||
use std::hashmap::HashMap; | ||
|
||
pub fn insert_expr(ecx: &mut ExtCtxt, sp: Span, | ||
tts: &[ast::TokenTree]) -> MacResult { | ||
|
||
if tts.len() != 5 { | ||
ecx.span_fatal(sp, "incorrect number of arguments"); | ||
} | ||
|
||
let idxs = [1, 3]; | ||
for i in idxs.iter() { | ||
match &tts[*i] { | ||
&ast::TTTok(_, token::COMMA) => (), | ||
_ => ecx.span_fatal(sp, "expecting comma") | ||
} | ||
} | ||
|
||
let map_name = tree_2_name(ecx, &tts[0]); | ||
let key_name = tree_2_name(ecx, &tts[2]); | ||
let expr = tts[4].clone(); | ||
|
||
if !ecx.tt_maps.contains_key(&map_name) { | ||
ecx.tt_maps.insert(map_name.clone(), HashMap::new()); | ||
} | ||
|
||
let existed = { | ||
let mut maybe_map = ecx.tt_maps.find_mut(&map_name); | ||
let map = maybe_map.get_mut_ref(); | ||
!map.insert(key_name, expr) | ||
}; | ||
|
||
if existed { | ||
let key_ident = get_ident(key_name); | ||
let key_name = key_ident.get(); | ||
ecx.span_fatal(sp, format!("key {} already exists in map", key_name)); | ||
} | ||
|
||
// This item isn't used | ||
let dummy_ident = ast::Ident::new(gensym("dummy_name")); | ||
let dummy_item = ecx.item_mod(sp, dummy_ident, ~[], ~[], ~[]); | ||
return MRItem(dummy_item); | ||
} | ||
|
||
pub fn get_expr(ecx: &mut ExtCtxt, sp: Span, | ||
tts: &[ast::TokenTree]) -> MacResult { | ||
|
||
if tts.len() != 3 { | ||
ecx.span_fatal(sp, "incorrect number of arguments"); | ||
} | ||
|
||
match &tts[1] { | ||
&ast::TTTok(_, token::COMMA) => (), | ||
_ => ecx.span_fatal(sp, "expecting comma") | ||
} | ||
|
||
let map_name = tree_2_name(ecx, &tts[0]); | ||
let key_name = tree_2_name(ecx, &tts[2]); | ||
|
||
match ecx.tt_maps.find(&map_name) { | ||
Some(map) => { | ||
match map.find(&key_name) { | ||
Some(map_tree) => { | ||
MRExpr(tree_2_expr(ecx, map_tree)) | ||
} | ||
None => { | ||
let key_ident = get_ident(key_name); | ||
let key_name = key_ident.get(); | ||
ecx.span_fatal(sp, format!("key {} does not exist in map", key_name)); | ||
} | ||
} | ||
} | ||
None => { | ||
ecx.span_fatal(sp, "map does not exist"); | ||
} | ||
} | ||
} | ||
|
||
fn tree_2_name(ecx: &ExtCtxt, tts: &ast::TokenTree) -> ast::Name { | ||
let mut p = new_parser_from_tts(ecx.parse_sess(), ecx.cfg.clone(), ~[tts.clone()]); | ||
return p.parse_ident().name; | ||
} | ||
|
||
fn tree_2_expr(ecx: &ExtCtxt, tts: &ast::TokenTree) -> @ast::Expr { | ||
let mut p = new_parser_from_tts(ecx.parse_sess(), ecx.cfg.clone(), ~[tts.clone()]); | ||
return p.parse_expr(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2013 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
fn main() { | ||
__tt_map_insert!(A, B, C); //~ ERROR __tt_map_* is a hack | ||
let _foo = __tt_map_get_expr!(A, B, C); //~ ERROR __tt_map_* is a hack | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2014 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
fn main() { | ||
|
||
let j = 2; | ||
mod m { __tt_map_insert!(my_tt_map, i, j) } | ||
|
||
let k = __tt_map_get_expr!(my_tt_map, i); | ||
assert!(j == k); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't seem to have
feature(__tt_map)
? This may also needpub fn main