From 400075d9d9b6410c9f7952ca52c35806b46b3177 Mon Sep 17 00:00:00 2001 From: Isaac van Bakel Date: Tue, 1 Aug 2017 13:03:03 +0100 Subject: Fixed all unnecessary muts in language core --- src/libsyntax/ext/tt/macro_parser.rs | 4 ++-- src/libsyntax/ext/tt/macro_rules.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 60833c75a15..146bd5d9856 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -211,7 +211,7 @@ pub enum NamedMatch { fn nameize>(sess: &ParseSess, ms: &[TokenTree], mut res: I) -> NamedParseResult { - fn n_rec>(sess: &ParseSess, m: &TokenTree, mut res: &mut I, + fn n_rec>(sess: &ParseSess, m: &TokenTree, res: &mut I, ret_val: &mut HashMap>) -> Result<(), (syntax_pos::Span, String)> { match *m { @@ -445,7 +445,7 @@ pub fn parse(sess: &ParseSess, /* error messages here could be improved with links to orig. rules */ if token_name_eq(&parser.token, &token::Eof) { if eof_items.len() == 1 { - let matches = eof_items[0].matches.iter_mut().map(|mut dv| { + let matches = eof_items[0].matches.iter_mut().map(|dv| { Rc::make_mut(dv).pop().unwrap() }); return nameize(sess, ms, matches); diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 8e746676ecd..80b6794d1e3 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -86,7 +86,7 @@ impl TTMacroExpander for MacroRulesMacroExpander { fn trace_macros_note(cx: &mut ExtCtxt, sp: Span, message: String) { let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp); - let mut values: &mut Vec = cx.expansions.entry(sp).or_insert_with(Vec::new); + let values: &mut Vec = cx.expansions.entry(sp).or_insert_with(Vec::new); values.push(message); } -- cgit 1.4.1-3-g733a5 From 4e2ddcb879d225e7d22fbf4af0536c06203b8d94 Mon Sep 17 00:00:00 2001 From: Malo Jaffré Date: Sun, 6 Aug 2017 17:36:50 +0200 Subject: Update the list of confusable characters Also reorder and space the list to make it clearer for futures updates and to come closer to the original list. Thanks @est31 for the instructions. Fixes #43629. r? @est31 --- src/libsyntax/parse/lexer/unicode_chars.rs | 144 +++++++++++++++++++++++++---- 1 file changed, 125 insertions(+), 19 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/lexer/unicode_chars.rs b/src/libsyntax/parse/lexer/unicode_chars.rs index 83a164bdb96..cc38021b7aa 100644 --- a/src/libsyntax/parse/lexer/unicode_chars.rs +++ b/src/libsyntax/parse/lexer/unicode_chars.rs @@ -1,4 +1,4 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2017 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -9,15 +9,16 @@ // except according to those terms. // Characters and their corresponding confusables were collected from -// http://www.unicode.org/Public/security/revision-06/confusables.txt +// http://www.unicode.org/Public/security/10.0.0/confusables.txt use syntax_pos::{Span, NO_EXPANSION}; use errors::DiagnosticBuilder; use super::StringReader; const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ - (' ', "No-Break Space", ' '), - (' ', "Ogham Space Mark", ' '), + ('
', "Line Separator", ' '), + ('
', "Paragraph Separator", ' '), + (' ', "Ogham Space mark", ' '), (' ', "En Quad", ' '), (' ', "Em Quad", ' '), (' ', "En Space", ' '), @@ -25,39 +26,63 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ (' ', "Three-Per-Em Space", ' '), (' ', "Four-Per-Em Space", ' '), (' ', "Six-Per-Em Space", ' '), - (' ', "Figure Space", ' '), (' ', "Punctuation Space", ' '), (' ', "Thin Space", ' '), (' ', "Hair Space", ' '), - (' ', "Narrow No-Break Space", ' '), (' ', "Medium Mathematical Space", ' '), + (' ', "No-Break Space", ' '), + (' ', "Figure Space", ' '), + (' ', "Narrow No-Break Space", ' '), (' ', "Ideographic Space", ' '), + ('ߺ', "Nko Lajanyalan", '_'), ('﹍', "Dashed Low Line", '_'), ('﹎', "Centreline Low Line", '_'), ('﹏', "Wavy Low Line", '_'), + ('_', "Fullwidth Low Line", '-'), + ('‐', "Hyphen", '-'), ('‑', "Non-Breaking Hyphen", '-'), ('‒', "Figure Dash", '-'), ('–', "En Dash", '-'), ('—', "Em Dash", '-'), ('﹘', "Small Em Dash", '-'), + ('۔', "Arabic Full Stop", '-'), ('⁃', "Hyphen Bullet", '-'), ('˗', "Modifier Letter Minus Sign", '-'), ('−', "Minus Sign", '-'), + ('➖', "Heavy Minus Sign", '-'), + ('Ⲻ', "Coptic Letter Dialect-P Ni", '-'), ('ー', "Katakana-Hiragana Prolonged Sound Mark", '-'), + ('-', "Fullwidth Hyphen-Minus", '-'), + ('―', "Horizontal Bar", '-'), + ('─', "Box Drawings Light Horizontal", '-'), + ('━', "Box Drawings Heavy Horizontal", '-'), + ('㇐', "CJK Stroke H", '-'), + ('ꟷ', "Latin Epigraphic Letter Dideways", '-'), + ('ᅳ', "Hangul Jungseong Eu", '-'), + ('ㅡ', "Hangul Letter Eu", '-'), + ('一', "CJK Unified Ideograph-4E00", '-'), + ('⼀', "Kangxi Radical One", '-'), + + ('؍', "Arabic Date Separator", ','), ('٫', "Arabic Decimal Separator", ','), ('‚', "Single Low-9 Quotation Mark", ','), + ('¸', "Cedilla", ','), ('ꓹ', "Lisu Letter Tone Na Po", ','), (',', "Fullwidth Comma", ','), + (';', "Greek Question Mark", ';'), (';', "Fullwidth Semicolon", ';'), + ('︔', "Presentation Form For Vertical Semicolon", ';'), + ('ः', "Devanagari Sign Visarga", ':'), ('ઃ', "Gujarati Sign Visarga", ':'), (':', "Fullwidth Colon", ':'), ('։', "Armenian Full Stop", ':'), ('܃', "Syriac Supralinear Colon", ':'), ('܄', "Syriac Sublinear Colon", ':'), + ('᛬', "Runic Multiple Ponctuation", ':'), ('︰', "Presentation Form For Vertical Two Dot Leader", ':'), ('᠃', "Mongolian Full Stop", ':'), ('᠉', "Mongolian Manchu Full Stop", ':'), @@ -68,25 +93,48 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ ('∶', "Ratio", ':'), ('ː', "Modifier Letter Triangular Colon", ':'), ('ꓽ', "Lisu Letter Tone Mya Jeu", ':'), + ('︓', "Presentation Form For Vertical Colon", ':'), + ('!', "Fullwidth Exclamation Mark", '!'), ('ǃ', "Latin Letter Retroflex Click", '!'), + ('ⵑ', "Tifinagh Letter Tuareg Yang", '!'), + ('︕', "Presentation Form For Vertical Exclamation Mark", '!'), + ('ʔ', "Latin Letter Glottal Stop", '?'), + ('Ɂ', "Latin Capital Letter Glottal Stop", '?'), ('ॽ', "Devanagari Letter Glottal Stop", '?'), ('Ꭾ', "Cherokee Letter He", '?'), + ('ꛫ', "Bamum Letter Ntuu", '?'), ('?', "Fullwidth Question Mark", '?'), + ('︖', "Presentation Form For Vertical Question Mark", '?'), + ('𝅭', "Musical Symbol Combining Augmentation Dot", '.'), ('․', "One Dot Leader", '.'), - ('۔', "Arabic Full Stop", '.'), ('܁', "Syriac Supralinear Full Stop", '.'), ('܂', "Syriac Sublinear Full Stop", '.'), ('꘎', "Vai Full Stop", '.'), ('𐩐', "Kharoshthi Punctuation Dot", '.'), - ('·', "Middle Dot", '.'), ('٠', "Arabic-Indic Digit Zero", '.'), ('۰', "Extended Arabic-Indic Digit Zero", '.'), ('ꓸ', "Lisu Letter Tone Mya Ti", '.'), - ('。', "Ideographic Full Stop", '.'), + ('·', "Middle Dot", '.'), ('・', "Katakana Middle Dot", '.'), + ('・', "Halfwidth Katakana Middle Dot", '.'), + ('᛫', "Runic Single Punctuation", '.'), + ('·', "Greek Ano Teleia", '.'), + ('⸱', "Word Separator Middle Dot", '.'), + ('𐄁', "Aegean Word Separator Dot", '.'), + ('•', "Bullet", '.'), + ('‧', "Hyphenation Point", '.'), + ('∙', "Bullet Operator", '.'), + ('⋅', "Dot Operator", '.'), + ('ꞏ', "Latin Letter Sinological Dot", '.'), + ('ᐧ', "Canadian Syllabics Final Middle Dot", '.'), + ('ᐧ', "Canadian Syllabics Final Middle Dot", '.'), + ('.', "Fullwidth Full Stop", '.'), + ('。', "Ideographic Full Stop", '.'), + ('︒', "Presentation Form For Vertical Ideographic Full Stop", '.'), + ('՝', "Armenian Comma", '\''), (''', "Fullwidth Apostrophe", '\''), ('‘', "Left Single Quotation Mark", '\''), @@ -96,8 +144,10 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ ('‵', "Reversed Prime", '\''), ('՚', "Armenian Apostrophe", '\''), ('׳', "Hebrew Punctuation Geresh", '\''), + ('`', "Greek Accent", '\''), ('`', "Greek Varia", '\''), ('`', "Fullwidth Grave Accent", '\''), + ('´', "Acute Accent", '\''), ('΄', "Greek Tonos", '\''), ('´', "Greek Oxia", '\''), ('᾽', "Greek Koronis", '\''), @@ -105,6 +155,7 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ ('῾', "Greek Dasia", '\''), ('ʹ', "Modifier Letter Prime", '\''), ('ʹ', "Greek Numeral Sign", '\''), + ('ˈ', "Modifier Letter Vertical Line", '\''), ('ˊ', "Modifier Letter Acute Accent", '\''), ('ˋ', "Modifier Letter Grave Accent", '\''), ('˴', "Modifier Letter Middle Grave Accent", '\''), @@ -116,6 +167,12 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ ('י', "Hebrew Letter Yod", '\''), ('ߴ', "Nko High Tone Apostrophe", '\''), ('ߵ', "Nko Low Tone Apostrophe", '\''), + ('ᑊ', "Canadian Syllabics West-Cree P", '\''), + ('ᛌ', "Runic Letter Short-Twig-Sol S", '\''), + ('𖽑', "Miao Sign Aspiration", '\''), + ('𖽒', "Miao Sign Reformed Voicing", '\''), + + ('᳓', "Vedic Sign Nihshvasa", '"'), ('"', "Fullwidth Quotation Mark", '"'), ('“', "Left Double Quotation Mark", '"'), ('”', "Right Double Quotation Mark", '"'), @@ -132,12 +189,15 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ ('ײ', "Hebrew Ligature Yiddish Double Yod", '"'), ('❞', "Heavy Double Comma Quotation Mark Ornament", '"'), ('❝', "Heavy Double Turned Comma Quotation Mark Ornament", '"'), + + ('(', "Fullwidth Left Parenthesis", '('), ('❨', "Medium Left Parenthesis Ornament", '('), ('﴾', "Ornate Left Parenthesis", '('), - ('(', "Fullwidth Left Parenthesis", '('), + + (')', "Fullwidth Right Parenthesis", ')'), ('❩', "Medium Right Parenthesis Ornament", ')'), ('﴿', "Ornate Right Parenthesis", ')'), - (')', "Fullwidth Right Parenthesis", ')'), + ('[', "Fullwidth Left Square Bracket", '['), ('❲', "Light Left Tortoise Shell Bracket Ornament", '['), ('「', "Left Corner Bracket", '['), @@ -147,6 +207,7 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ ('〖', "Left White Lenticular Bracket", '['), ('〘', "Left White Tortoise Shell Bracket", '['), ('〚', "Left White Square Bracket", '['), + (']', "Fullwidth Right Square Bracket", ']'), ('❳', "Light Right Tortoise Shell Bracket Ornament", ']'), ('」', "Right Corner Bracket", ']'), @@ -156,11 +217,20 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ ('〗', "Right White Lenticular Bracket", ']'), ('〙', "Right White Tortoise Shell Bracket", ']'), ('〛', "Right White Square Bracket", ']'), + ('❴', "Medium Left Curly Bracket Ornament", '{'), + ('𝄔', "Musical Symbol Brace", '{'), + ('{', "Fullwidth Left Curly Bracket", '{'), + ('❵', "Medium Right Curly Bracket Ornament", '}'), + ('}', "Fullwidth Right Curly Bracket", '}'), + ('⁎', "Low Asterisk", '*'), ('٭', "Arabic Five Pointed Star", '*'), ('∗', "Asterisk Operator", '*'), + ('𐌟', "Old Italic Letter Ess", '*'), + ('*', "Fullwidth Asterisk", '*'), + ('᜵', "Philippine Single Punctuation", '/'), ('⁁', "Caret Insertion Point", '/'), ('∕', "Division Slash", '/'), @@ -168,37 +238,73 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ ('╱', "Box Drawings Light Diagonal Upper Right To Lower Left", '/'), ('⟋', "Mathematical Rising Diagonal", '/'), ('⧸', "Big Solidus", '/'), - ('㇓', "Cjk Stroke Sp", '/'), + ('𝈺', "Greek Instrumental Notation Symbol-47", '/'), + ('㇓', "CJK Stroke Sp", '/'), ('〳', "Vertical Kana Repeat Mark Upper Half", '/'), - ('丿', "Cjk Unified Ideograph-4E3F", '/'), + ('Ⳇ', "Coptic Capital Letter Old Coptic Esh", '/'), + ('ノ', "Katakana Letter No", '/'), + ('丿', "CJK Unified Ideograph-4E3F", '/'), ('⼃', "Kangxi Radical Slash", '/'), + ('/', "Fullwidth Solidus", '/'), + ('\', "Fullwidth Reverse Solidus", '\\'), ('﹨', "Small Reverse Solidus", '\\'), ('∖', "Set Minus", '\\'), ('⟍', "Mathematical Falling Diagonal", '\\'), ('⧵', "Reverse Solidus Operator", '\\'), ('⧹', "Big Reverse Solidus", '\\'), + ('⧹', "Greek Vocal Notation Symbol-16", '\\'), + ('⧹', "Greek Instrumental Symbol-48", '\\'), + ('㇔', "CJK Stroke D", '\\'), + ('丶', "CJK Unified Ideograph-4E36", '\\'), + ('⼂', "Kangxi Radical Dot", '\\'), ('、', "Ideographic Comma", '\\'), ('ヽ', "Katakana Iteration Mark", '\\'), - ('㇔', "Cjk Stroke D", '\\'), - ('丶', "Cjk Unified Ideograph-4E36", '\\'), - ('⼂', "Kangxi Radical Dot", '\\'), + ('ꝸ', "Latin Small Letter Um", '&'), + ('&', "Fullwidth Ampersand", '&'), + + ('᛭', "Runic Cros Punctuation", '+'), + ('➕', "Heavy Plus Sign", '+'), + ('𐊛', "Lycian Letter H", '+'), ('﬩', "Hebrew Letter Alternative Plus Sign", '+'), + ('+', "Fullwidth Plus Sign", '+'), + ('‹', "Single Left-Pointing Angle Quotation Mark", '<'), ('❮', "Heavy Left-Pointing Angle Quotation Mark Ornament", '<'), ('˂', "Modifier Letter Left Arrowhead", '<'), + ('𝈶', "Greek Instrumental Symbol-40", '<'), + ('ᐸ', "Canadian Syllabics Pa", '<'), + ('ᚲ', "Runic Letter Kauna", '<'), + ('❬', "Medium Left-Pointing Angle Bracket Ornament", '<'), + ('⟨', "Mathematical Left Angle Bracket", '<'), + ('〈', "Left-Pointing Angle Bracket", '<'), ('〈', "Left Angle Bracket", '<'), + ('㇛', "CJK Stroke Pd", '<'), + ('く', "Hiragana Letter Ku", '<'), + ('𡿨', "CJK Unified Ideograph-21FE8", '<'), ('《', "Left Double Angle Bracket", '<'), + ('<', "Fullwidth Less-Than Sign", '<'), + + ('᐀', "Canadian Syllabics Hyphen", '='), + ('⹀', "Double Hyphen", '='), + ('゠', "Katakana-Hiragana Double Hyphen", '='), ('꓿', "Lisu Punctuation Full Stop", '='), + ('=', "Fullwidth Equals Sign", '='), + ('›', "Single Right-Pointing Angle Quotation Mark", '>'), ('❯', "Heavy Right-Pointing Angle Quotation Mark Ornament", '>'), ('˃', "Modifier Letter Right Arrowhead", '>'), + ('𝈷', "Greek Instrumental Symbol-42", '>'), + ('ᐳ', "Canadian Syllabics Po", '>'), + ('𖼿', "Miao Letter Archaic Zza", '>'), + ('❭', "Medium Right-Pointing Angle Bracket Ornament", '>'), + ('⟩', "Mathematical Right Angle Bracket", '>'), + ('〉', "Right-Pointing Angle Bracket", '>'), ('〉', "Right Angle Bracket", '>'), ('》', "Right Double Angle Bracket", '>'), - ('Ⲻ', "Coptic Capital Letter Dialect-P Ni", '-'), - ('Ɂ', "Latin Capital Letter Glottal Stop", '?'), - ('Ⳇ', "Coptic Capital Letter Old Coptic Esh", '/'), ]; + ('>', "Fullwidth Greater-Than Sign", '>'), ]; + const ASCII_ARRAY: &'static [(char, &'static str)] = &[ (' ', "Space"), -- cgit 1.4.1-3-g733a5 From 5e29bb91b0865bdc54864d0491fa6324aafb6fad Mon Sep 17 00:00:00 2001 From: Malo Jaffré Date: Sun, 6 Aug 2017 18:34:36 +0200 Subject: Fix typo in unicode_chars.rs --- src/libsyntax/parse/lexer/unicode_chars.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/lexer/unicode_chars.rs b/src/libsyntax/parse/lexer/unicode_chars.rs index cc38021b7aa..85df4eee913 100644 --- a/src/libsyntax/parse/lexer/unicode_chars.rs +++ b/src/libsyntax/parse/lexer/unicode_chars.rs @@ -39,7 +39,7 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ ('﹍', "Dashed Low Line", '_'), ('﹎', "Centreline Low Line", '_'), ('﹏', "Wavy Low Line", '_'), - ('_', "Fullwidth Low Line", '-'), + ('_', "Fullwidth Low Line", '_'), ('‐', "Hyphen", '-'), ('‑', "Non-Breaking Hyphen", '-'), -- cgit 1.4.1-3-g733a5 From ff0513c6973523b65f59b8b508ca85dc2944c988 Mon Sep 17 00:00:00 2001 From: Kornel Date: Mon, 7 Aug 2017 18:23:15 +0100 Subject: Hint correct extern constant syntax --- src/libsyntax/parse/parser.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ca362ec9368..c34317e649d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6007,7 +6007,9 @@ impl<'a> Parser<'a> { } if self.check_keyword(keywords::Const) { - return Err(self.span_fatal(self.span, "extern items cannot be `const`")); + let mut err = self.span_fatal(self.span, "extern items cannot be `const`"); + err.help("use `static` instead"); + return Err(err); } // FIXME #5668: this will occur for a macro invocation: -- cgit 1.4.1-3-g733a5 From 6fa140b86994d216b2bd425f69048a3a6c3067fc Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Mon, 7 Aug 2017 10:57:08 -0700 Subject: extended information for E0554 feature attributes only work on nightlies It's more pleasing to use the inner-attribute syntax (`#!` rather than `#`) in the error message, as that is how `feature` attributes in particular will be declared (as they apply to the entire crate). --- src/libsyntax/diagnostic_list.rs | 16 +++++++++++++++- src/libsyntax/feature_gate.rs | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/diagnostic_list.rs b/src/libsyntax/diagnostic_list.rs index 6598ecb9444..33dbc02d869 100644 --- a/src/libsyntax/diagnostic_list.rs +++ b/src/libsyntax/diagnostic_list.rs @@ -162,6 +162,21 @@ For more information about the cfg attribute, read: https://doc.rust-lang.org/reference.html#conditional-compilation "##, +E0554: r##" +Feature attributes are only allowed on the nightly release channel. Stable or +beta compilers will not comply. + +Example of erroneous code (on a stable compiler): + +```ignore (depends on release channel) +#![feature(non_ascii_idents)] // error: #![feature] may not be used on the + // stable release channel +``` + +If you need the feature, make sure to use a nightly release of the compiler +(but be warned that the feature may be removed or altered in the future). +"##, + E0558: r##" The `export_name` attribute was malformed. @@ -301,7 +316,6 @@ register_diagnostics! { E0550, // multiple deprecated attributes E0551, // incorrect meta item E0552, // unrecognized representation hint - E0554, // #[feature] may not be used on the [] release channel E0555, // malformed feature attribute, expected #![feature(...)] E0556, // malformed feature, expected just one word E0557, // feature has been removed diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index e8de8cf41c9..aeb574bc3af 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1602,7 +1602,7 @@ fn maybe_stage_features(span_handler: &Handler, krate: &ast::Crate, if attr.check_name("feature") { let release_channel = option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)"); span_err!(span_handler, attr.span, E0554, - "#[feature] may not be used on the {} release channel", + "#![feature] may not be used on the {} release channel", release_channel); } } -- cgit 1.4.1-3-g733a5 From 93bc599d65d0f946944b3c97be3556658cc01eab Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Mon, 7 Aug 2017 15:09:53 -0700 Subject: extended information for E0552 unrecognized representation hint --- src/libsyntax/diagnostic_list.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/diagnostic_list.rs b/src/libsyntax/diagnostic_list.rs index 33dbc02d869..7c6db17a352 100644 --- a/src/libsyntax/diagnostic_list.rs +++ b/src/libsyntax/diagnostic_list.rs @@ -162,6 +162,36 @@ For more information about the cfg attribute, read: https://doc.rust-lang.org/reference.html#conditional-compilation "##, +E0552: r##" +A unrecognized representation attribute was used. + +Erroneous code example: + +```compile_fail,E0552 +#[repr(D)] // error: unrecognized representation hint +struct MyStruct { + my_field: usize +} +``` + +You can use a `repr` attribute to tell the compiler how you want a struct or +enum to be laid out in memory. + +Make sure you're using one of the supported options: + +``` +#[repr(C)] // ok! +struct MyStruct { + my_field: usize +} +``` + +For more information about specifying representations, see the ["Alternative +Representations" section] of the Rustonomicon. + +["Alternative Representations" section]: https://doc.rust-lang.org/nomicon/other-reprs.html +"##, + E0554: r##" Feature attributes are only allowed on the nightly release channel. Stable or beta compilers will not comply. @@ -315,7 +345,6 @@ register_diagnostics! { E0549, // rustc_deprecated attribute must be paired with either stable or unstable attribute E0550, // multiple deprecated attributes E0551, // incorrect meta item - E0552, // unrecognized representation hint E0555, // malformed feature attribute, expected #![feature(...)] E0556, // malformed feature, expected just one word E0557, // feature has been removed -- cgit 1.4.1-3-g733a5 From 116bf07c3224301a234a3a9f4b9c137013f6164f Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Mon, 7 Aug 2017 15:37:13 -0700 Subject: extended information for E0557 feature has been removed --- src/libsyntax/diagnostic_list.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/diagnostic_list.rs b/src/libsyntax/diagnostic_list.rs index 7c6db17a352..2ea3fe51d30 100644 --- a/src/libsyntax/diagnostic_list.rs +++ b/src/libsyntax/diagnostic_list.rs @@ -207,6 +207,18 @@ If you need the feature, make sure to use a nightly release of the compiler (but be warned that the feature may be removed or altered in the future). "##, +E0557: r##" +A feature attribute named a feature that has been removed. + +Erroneous code example: + +```compile_fail,E0557 +#![feature(managed_boxes)] // error: feature has been removed +``` + +Delete the offending feature attribute. +"##, + E0558: r##" The `export_name` attribute was malformed. @@ -347,7 +359,6 @@ register_diagnostics! { E0551, // incorrect meta item E0555, // malformed feature attribute, expected #![feature(...)] E0556, // malformed feature, expected just one word - E0557, // feature has been removed E0584, // file for module `..` found at both .. and .. E0589, // invalid `repr(align)` attribute } -- cgit 1.4.1-3-g733a5 From a965beef8f362e1db47eadd0ff701ec57cc23cfe Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 10 Aug 2017 01:43:06 +0300 Subject: Better diagnostics and recovery for `const` in extern blocks --- src/libsyntax/parse/parser.rs | 24 ++++++++++++------------ src/test/ui/extern-const.rs | 19 +++++++++++++++++++ src/test/ui/extern-const.stderr | 8 ++++++++ 3 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 src/test/ui/extern-const.rs create mode 100644 src/test/ui/extern-const.stderr (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c34317e649d..cb28f356fe6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5518,12 +5518,11 @@ impl<'a> Parser<'a> { }) } - /// Parse a static item from a foreign module + /// Parse a static item from a foreign module. + /// Assumes that the `static` keyword is already parsed. fn parse_item_foreign_static(&mut self, vis: ast::Visibility, lo: Span, attrs: Vec) -> PResult<'a, ForeignItem> { - self.expect_keyword(keywords::Static)?; let mutbl = self.eat_keyword(keywords::Mut); - let ident = self.parse_ident()?; self.expect(&token::Colon)?; let ty = self.parse_ty()?; @@ -5997,21 +5996,22 @@ impl<'a> Parser<'a> { let lo = self.span; let visibility = self.parse_visibility(false)?; - if self.check_keyword(keywords::Static) { - // FOREIGN STATIC ITEM + // FOREIGN STATIC ITEM + // Treat `const` as `static` for error recovery, but don't add it to expected tokens. + if self.check_keyword(keywords::Static) || self.token.is_keyword(keywords::Const) { + if self.token.is_keyword(keywords::Const) { + self.diagnostic() + .struct_span_err(self.span, "extern items cannot be `const`") + .span_label(self.span, "use `static` instead").emit(); + } + self.bump(); // `static` or `const` return Ok(Some(self.parse_item_foreign_static(visibility, lo, attrs)?)); } + // FOREIGN FUNCTION ITEM if self.check_keyword(keywords::Fn) { - // FOREIGN FUNCTION ITEM return Ok(Some(self.parse_item_foreign_fn(visibility, lo, attrs)?)); } - if self.check_keyword(keywords::Const) { - let mut err = self.span_fatal(self.span, "extern items cannot be `const`"); - err.help("use `static` instead"); - return Err(err); - } - // FIXME #5668: this will occur for a macro invocation: match self.parse_macro_use_or_failure(attrs, true, false, lo, visibility)? { Some(item) => { diff --git a/src/test/ui/extern-const.rs b/src/test/ui/extern-const.rs new file mode 100644 index 00000000000..a77d7b11895 --- /dev/null +++ b/src/test/ui/extern-const.rs @@ -0,0 +1,19 @@ +// 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. +// +// 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. + +// compile-flags: -Z continue-parse-after-error + +extern "C" { + const C: u8; //~ ERROR extern items cannot be `const` +} + +fn main() { + let x = C; +} diff --git a/src/test/ui/extern-const.stderr b/src/test/ui/extern-const.stderr new file mode 100644 index 00000000000..e6c41a05594 --- /dev/null +++ b/src/test/ui/extern-const.stderr @@ -0,0 +1,8 @@ +error: extern items cannot be `const` + --> $DIR/extern-const.rs:14:5 + | +14 | const C: u8; //~ ERROR extern items cannot be `const` + | ^^^^^ use `static` instead + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5 From 5cf9f6330a02a0e86f08223289c74b36fba784db Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 10 Aug 2017 01:42:36 +0200 Subject: Add a feature gate @alexcrichton figured out a way how to do it :) --- src/libsyntax/ext/source_util.rs | 10 ++++++++++ src/libsyntax_ext/lib.rs | 2 +- src/test/compile-fail/rust-unstable-column-gated.rs | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/rust-unstable-column-gated.rs (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 3cdd3a4b2c3..b293aa8de38 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -52,6 +52,16 @@ pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32)) } +/* __rust_unstable_column!(): expands to the current column number */ +pub fn expand_column_gated(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) + -> Box { + if sp.allows_unstable() { + expand_column(cx, sp, tts) + } else { + cx.span_fatal(sp, "the __rust_unstable_column macro is unstable"); + } +} + /// file!(): expands to the current filename */ /// The filemap (`loc.file`) contains a bunch more information we could spit /// out if we wanted. diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index 558d2e90310..5eab81dd28f 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -89,7 +89,7 @@ pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver, use syntax::ext::source_util::*; register! { line: expand_line, - __rust_unstable_column: expand_column, + __rust_unstable_column: expand_column_gated, column: expand_column, file: expand_file, stringify: expand_stringify, diff --git a/src/test/compile-fail/rust-unstable-column-gated.rs b/src/test/compile-fail/rust-unstable-column-gated.rs new file mode 100644 index 00000000000..abc92c86eec --- /dev/null +++ b/src/test/compile-fail/rust-unstable-column-gated.rs @@ -0,0 +1,14 @@ +// 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. +// +// 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. + +fn main() { + println!("{}", __rust_unstable_column!()); + //~^ERROR the __rust_unstable_column macro is unstable +} -- cgit 1.4.1-3-g733a5 From cabc9be9e2057c5197db273ba0c750aad5ff3366 Mon Sep 17 00:00:00 2001 From: Kornel Date: Thu, 10 Aug 2017 12:16:01 +0100 Subject: Reword error hint --- src/libsyntax/parse/parser.rs | 3 ++- src/test/ui/extern-const.stderr | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index cb28f356fe6..7bf4c6799b3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6002,7 +6002,8 @@ impl<'a> Parser<'a> { if self.token.is_keyword(keywords::Const) { self.diagnostic() .struct_span_err(self.span, "extern items cannot be `const`") - .span_label(self.span, "use `static` instead").emit(); + .span_suggestion(self.span, "instead try using", "static".to_owned()) + .emit(); } self.bump(); // `static` or `const` return Ok(Some(self.parse_item_foreign_static(visibility, lo, attrs)?)); diff --git a/src/test/ui/extern-const.stderr b/src/test/ui/extern-const.stderr index e6c41a05594..c5a3149e85a 100644 --- a/src/test/ui/extern-const.stderr +++ b/src/test/ui/extern-const.stderr @@ -2,7 +2,7 @@ error: extern items cannot be `const` --> $DIR/extern-const.rs:14:5 | 14 | const C: u8; //~ ERROR extern items cannot be `const` - | ^^^^^ use `static` instead + | ^^^^^ help: instead try using: `static` error: aborting due to previous error -- cgit 1.4.1-3-g733a5