From 7a74f33f9067365f9b67057ea536e5f4d84fcc45 Mon Sep 17 00:00:00 2001 From: L117 Date: Sat, 8 Jun 2019 09:02:15 +1000 Subject: [PATCH 01/16] Remove useless allocations in macro_rules follow logic. --- src/libsyntax/ext/tt/macro_rules.rs | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 7ab51c1eb20c9..5dd3138c9adf0 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -909,7 +909,7 @@ fn check_matcher_core(sess: &ParseSess, continue 'each_last; } IsInFollow::Yes => {} - IsInFollow::No(ref possible) => { + IsInFollow::No(possible) => { let may_be = if last.tokens.len() == 1 && suffix_first.tokens.len() == 1 { @@ -933,7 +933,7 @@ fn check_matcher_core(sess: &ParseSess, format!("not allowed after `{}` fragments", frag_spec), ); let msg = "allowed there are: "; - match &possible[..] { + match possible { &[] => {} &[t] => { err.note(&format!( @@ -997,7 +997,7 @@ fn frag_can_be_followed_by_any(frag: &str) -> bool { enum IsInFollow { Yes, - No(Vec<&'static str>), + No(&'static [&'static str]), Invalid(String, &'static str), } @@ -1029,28 +1029,28 @@ fn is_in_follow(tok: "ed::TokenTree, frag: &str) -> IsInFollow { IsInFollow::Yes }, "stmt" | "expr" => { - let tokens = vec!["`=>`", "`,`", "`;`"]; + const TOKENS: &[&str] = &["`=>`", "`,`", "`;`"]; match tok { TokenTree::Token(token) => match token.kind { FatArrow | Comma | Semi => IsInFollow::Yes, - _ => IsInFollow::No(tokens), + _ => IsInFollow::No(TOKENS), }, - _ => IsInFollow::No(tokens), + _ => IsInFollow::No(TOKENS), } }, "pat" => { - let tokens = vec!["`=>`", "`,`", "`=`", "`|`", "`if`", "`in`"]; + const TOKENS: &[&str] = &["`=>`", "`,`", "`=`", "`|`", "`if`", "`in`"]; match tok { TokenTree::Token(token) => match token.kind { FatArrow | Comma | Eq | BinOp(token::Or) => IsInFollow::Yes, Ident(name, false) if name == kw::If || name == kw::In => IsInFollow::Yes, - _ => IsInFollow::No(tokens), + _ => IsInFollow::No(TOKENS), }, - _ => IsInFollow::No(tokens), + _ => IsInFollow::No(TOKENS), } }, "path" | "ty" => { - let tokens = vec![ + const TOKENS: &[&str] = &[ "`{`", "`[`", "`=>`", "`,`", "`>`","`=`", "`:`", "`;`", "`|`", "`as`", "`where`", ]; @@ -1062,11 +1062,11 @@ fn is_in_follow(tok: "ed::TokenTree, frag: &str) -> IsInFollow { BinOp(token::Or) => IsInFollow::Yes, Ident(name, false) if name == kw::As || name == kw::Where => IsInFollow::Yes, - _ => IsInFollow::No(tokens), + _ => IsInFollow::No(TOKENS), }, TokenTree::MetaVarDecl(_, _, frag) if frag.name == sym::block => IsInFollow::Yes, - _ => IsInFollow::No(tokens), + _ => IsInFollow::No(TOKENS), } }, "ident" | "lifetime" => { @@ -1084,7 +1084,7 @@ fn is_in_follow(tok: "ed::TokenTree, frag: &str) -> IsInFollow { }, "vis" => { // Explicitly disallow `priv`, on the off chance it comes back. - let tokens = vec!["`,`", "an ident", "a type"]; + const TOKENS: &[&str] = &["`,`", "an ident", "a type"]; match tok { TokenTree::Token(token) => match token.kind { Comma => IsInFollow::Yes, @@ -1092,14 +1092,14 @@ fn is_in_follow(tok: "ed::TokenTree, frag: &str) -> IsInFollow { _ => if token.can_begin_type() { IsInFollow::Yes } else { - IsInFollow::No(tokens) + IsInFollow::No(TOKENS) } }, TokenTree::MetaVarDecl(_, _, frag) if frag.name == sym::ident || frag.name == sym::ty || frag.name == sym::path => IsInFollow::Yes, - _ => IsInFollow::No(tokens), + _ => IsInFollow::No(TOKENS), } }, "" => IsInFollow::Yes, // kw::Invalid From 4567f22578e02d4eaca21b7662233ef2dc43a007 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 8 Jun 2019 12:30:52 +0200 Subject: [PATCH 02/16] remove useless ident() functions in const tests and replace the useful ones by black_box (with a comment) --- src/test/run-pass/const-int-conversion.rs | 18 +++++------- src/test/run-pass/const-int-overflowing.rs | 28 ++++++++----------- src/test/run-pass/const-int-rotate.rs | 28 ++++++++----------- src/test/run-pass/const-int-wrapping.rs | 28 ++++++++----------- src/test/run-pass/consts/const-endianess.rs | 2 +- src/test/run-pass/consts/const-ptr-nonnull.rs | 13 +++++---- src/test/run-pass/consts/const-ptr-unique.rs | 12 ++++---- 7 files changed, 57 insertions(+), 72 deletions(-) diff --git a/src/test/run-pass/const-int-conversion.rs b/src/test/run-pass/const-int-conversion.rs index 3d3240d434292..1d3123d216ebf 100644 --- a/src/test/run-pass/const-int-conversion.rs +++ b/src/test/run-pass/const-int-conversion.rs @@ -8,16 +8,12 @@ const TO_BE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_be_bytes(); const TO_LE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_le_bytes(); const TO_NE_BYTES: [u8; 4] = i32::min_value().to_be().to_ne_bytes(); -fn ident(ident: T) -> T { - ident -} - fn main() { - assert_eq!(REVERSE, ident(0x1e6a2c48)); - assert_eq!(FROM_BE_BYTES, ident(0x12_34_56_78)); - assert_eq!(FROM_LE_BYTES, ident(0x78_56_34_12)); - assert_eq!(FROM_NE_BYTES, ident(i32::min_value())); - assert_eq!(TO_BE_BYTES, ident([0x12, 0x34, 0x56, 0x78])); - assert_eq!(TO_LE_BYTES, ident([0x78, 0x56, 0x34, 0x12])); - assert_eq!(TO_NE_BYTES, ident([0x80, 0, 0, 0])); + assert_eq!(REVERSE, 0x1e6a2c48); + assert_eq!(FROM_BE_BYTES, 0x12_34_56_78); + assert_eq!(FROM_LE_BYTES, 0x78_56_34_12); + assert_eq!(FROM_NE_BYTES, i32::min_value()); + assert_eq!(TO_BE_BYTES, [0x12, 0x34, 0x56, 0x78]); + assert_eq!(TO_LE_BYTES, [0x78, 0x56, 0x34, 0x12]); + assert_eq!(TO_NE_BYTES, [0x80, 0, 0, 0]); } diff --git a/src/test/run-pass/const-int-overflowing.rs b/src/test/run-pass/const-int-overflowing.rs index 82057868b73bb..9597393df72d2 100644 --- a/src/test/run-pass/const-int-overflowing.rs +++ b/src/test/run-pass/const-int-overflowing.rs @@ -16,26 +16,22 @@ const SHR_B: (u32, bool) = 0x10u32.overflowing_shr(132); const NEG_A: (u32, bool) = 0u32.overflowing_neg(); const NEG_B: (u32, bool) = core::u32::MAX.overflowing_neg(); -fn ident(ident: T) -> T { - ident -} - fn main() { - assert_eq!(ADD_A, ident((7, false))); - assert_eq!(ADD_B, ident((0, true))); + assert_eq!(ADD_A, (7, false)); + assert_eq!(ADD_B, (0, true)); - assert_eq!(SUB_A, ident((3, false))); - assert_eq!(SUB_B, ident((u32::max_value(), true))); + assert_eq!(SUB_A, (3, false)); + assert_eq!(SUB_B, (u32::max_value(), true)); - assert_eq!(MUL_A, ident((10, false))); - assert_eq!(MUL_B, ident((1410065408, true))); + assert_eq!(MUL_A, (10, false)); + assert_eq!(MUL_B, (1410065408, true)); - assert_eq!(SHL_A, ident((0x10, false))); - assert_eq!(SHL_B, ident((0x10, true))); + assert_eq!(SHL_A, (0x10, false)); + assert_eq!(SHL_B, (0x10, true)); - assert_eq!(SHR_A, ident((0x1, false))); - assert_eq!(SHR_B, ident((0x1, true))); + assert_eq!(SHR_A, (0x1, false)); + assert_eq!(SHR_B, (0x1, true)); - assert_eq!(NEG_A, ident((0, false))); - assert_eq!(NEG_B, ident((1, true))); + assert_eq!(NEG_A, (0, false)); + assert_eq!(NEG_B, (1, true)); } diff --git a/src/test/run-pass/const-int-rotate.rs b/src/test/run-pass/const-int-rotate.rs index 965f317c42466..16946eadd632a 100644 --- a/src/test/run-pass/const-int-rotate.rs +++ b/src/test/run-pass/const-int-rotate.rs @@ -21,25 +21,21 @@ const ZERO_ROTATE_RIGHT: i8 = 0b0111_1001i8.rotate_right(0); const MULTIPLE_ROTATE_LEFT: i32 = 0b0010_0001i32.rotate_left(128); const MULTIPLE_ROTATE_RIGHT: i32 = 0b0010_0001i32.rotate_right(128); -fn ident(ident: T) -> T { - ident -} - fn main() { - assert_eq!(LEFT, ident(0xb301)); - assert_eq!(RIGHT, ident(0x0100_00b3)); + assert_eq!(LEFT, 0xb301); + assert_eq!(RIGHT, 0x0100_00b3); - assert_eq!(LEFT_OVERFLOW, ident(0)); - assert_eq!(RIGHT_OVERFLOW, ident(0)); - assert_eq!(ONE_LEFT_OVERFLOW, ident(0b0001_0000_0000_0000)); - assert_eq!(ONE_RIGHT_OVERFLOW, ident(0b0001_0000)); + assert_eq!(LEFT_OVERFLOW, 0); + assert_eq!(RIGHT_OVERFLOW, 0); + assert_eq!(ONE_LEFT_OVERFLOW, 0b0001_0000_0000_0000); + assert_eq!(ONE_RIGHT_OVERFLOW, 0b0001_0000); - assert_eq!(NON_ZERO_LEFT_OVERFLOW, ident(0b0010_0000_0000_0000)); - assert_eq!(NON_ZERO_RIGHT_OVERFLOW, ident(0b0000_0000_0010_0000)); + assert_eq!(NON_ZERO_LEFT_OVERFLOW, 0b0010_0000_0000_0000); + assert_eq!(NON_ZERO_RIGHT_OVERFLOW, 0b0000_0000_0010_0000); - assert_eq!(ZERO_ROTATE_LEFT, ident(0b0010_0001)); - assert_eq!(ZERO_ROTATE_RIGHT, ident(0b0111_1001)); + assert_eq!(ZERO_ROTATE_LEFT, 0b0010_0001); + assert_eq!(ZERO_ROTATE_RIGHT, 0b0111_1001); - assert_eq!(MULTIPLE_ROTATE_LEFT, ident(0b0010_0001)); - assert_eq!(MULTIPLE_ROTATE_RIGHT, ident(0b0010_0001)); + assert_eq!(MULTIPLE_ROTATE_LEFT, 0b0010_0001); + assert_eq!(MULTIPLE_ROTATE_RIGHT, 0b0010_0001); } diff --git a/src/test/run-pass/const-int-wrapping.rs b/src/test/run-pass/const-int-wrapping.rs index 140fd57ecb802..db86c25194f08 100644 --- a/src/test/run-pass/const-int-wrapping.rs +++ b/src/test/run-pass/const-int-wrapping.rs @@ -16,26 +16,22 @@ const SHR_B: u32 = 128u32.wrapping_shr(128); const NEG_A: u32 = 5u32.wrapping_neg(); const NEG_B: u32 = 1234567890u32.wrapping_neg(); -fn ident(ident: T) -> T { - ident -} - fn main() { - assert_eq!(ADD_A, ident(255)); - assert_eq!(ADD_B, ident(199)); + assert_eq!(ADD_A, 255); + assert_eq!(ADD_B, 199); - assert_eq!(SUB_A, ident(0)); - assert_eq!(SUB_B, ident(101)); + assert_eq!(SUB_A, 0); + assert_eq!(SUB_B, 101); - assert_eq!(MUL_A, ident(120)); - assert_eq!(MUL_B, ident(44)); + assert_eq!(MUL_A, 120); + assert_eq!(MUL_B, 44); - assert_eq!(SHL_A, ident(128)); - assert_eq!(SHL_B, ident(1)); + assert_eq!(SHL_A, 128); + assert_eq!(SHL_B, 1); - assert_eq!(SHR_A, ident(1)); - assert_eq!(SHR_B, ident(128)); + assert_eq!(SHR_A, 1); + assert_eq!(SHR_B, 128); - assert_eq!(NEG_A, ident(4294967291)); - assert_eq!(NEG_B, ident(3060399406)); + assert_eq!(NEG_A, 4294967291); + assert_eq!(NEG_B, 3060399406); } diff --git a/src/test/run-pass/consts/const-endianess.rs b/src/test/run-pass/consts/const-endianess.rs index cbe6d864c9c3a..936f31954d3dd 100644 --- a/src/test/run-pass/consts/const-endianess.rs +++ b/src/test/run-pass/consts/const-endianess.rs @@ -2,7 +2,7 @@ #![feature(test)] extern crate test; -use test::black_box as b; +use test::black_box as b; // prevent promotion of the argument and const-propagation of the result const BE_U32: u32 = 55u32.to_be(); const LE_U32: u32 = 55u32.to_le(); diff --git a/src/test/run-pass/consts/const-ptr-nonnull.rs b/src/test/run-pass/consts/const-ptr-nonnull.rs index c5b9d837b47a8..4cdc8c7942359 100644 --- a/src/test/run-pass/consts/const-ptr-nonnull.rs +++ b/src/test/run-pass/consts/const-ptr-nonnull.rs @@ -1,15 +1,16 @@ // run-pass +#![feature(ptr_internals, test)] + +extern crate test; +use test::black_box as b; // prevent promotion of the argument and const-propagation of the result + use std::ptr::NonNull; const DANGLING: NonNull = NonNull::dangling(); const CASTED: NonNull = NonNull::cast(NonNull::::dangling()); -fn ident(ident: T) -> T { - ident -} - pub fn main() { - assert_eq!(DANGLING, ident(NonNull::dangling())); - assert_eq!(CASTED, ident(NonNull::dangling())); + assert_eq!(DANGLING, b(NonNull::dangling())); + assert_eq!(CASTED, b(NonNull::dangling())); } diff --git a/src/test/run-pass/consts/const-ptr-unique.rs b/src/test/run-pass/consts/const-ptr-unique.rs index eb371ab184166..b5cc78d4b7188 100644 --- a/src/test/run-pass/consts/const-ptr-unique.rs +++ b/src/test/run-pass/consts/const-ptr-unique.rs @@ -1,15 +1,15 @@ // run-pass -#![feature(ptr_internals)] +#![feature(ptr_internals, test)] + +extern crate test; +use test::black_box as b; // prevent promotion of the argument and const-propagation of the result use std::ptr::Unique; -const PTR: *mut u32 = Unique::empty().as_ptr(); -fn ident(ident: T) -> T { - ident -} +const PTR: *mut u32 = Unique::empty().as_ptr(); pub fn main() { - assert_eq!(PTR, ident(Unique::::empty().as_ptr())); + assert_eq!(PTR, b(Unique::::empty()).as_ptr()); } From a733b876f7831d2273826753841194b4ba2a5260 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 8 Jun 2019 18:13:16 +0200 Subject: [PATCH 03/16] black-box the fn ptr, not the result --- src/test/run-pass/consts/const-ptr-nonnull.rs | 4 ++-- src/test/run-pass/consts/const-ptr-unique.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/run-pass/consts/const-ptr-nonnull.rs b/src/test/run-pass/consts/const-ptr-nonnull.rs index 4cdc8c7942359..12a5ea5b480ba 100644 --- a/src/test/run-pass/consts/const-ptr-nonnull.rs +++ b/src/test/run-pass/consts/const-ptr-nonnull.rs @@ -11,6 +11,6 @@ const DANGLING: NonNull = NonNull::dangling(); const CASTED: NonNull = NonNull::cast(NonNull::::dangling()); pub fn main() { - assert_eq!(DANGLING, b(NonNull::dangling())); - assert_eq!(CASTED, b(NonNull::dangling())); + assert_eq!(DANGLING, b(NonNull::dangling)()); + assert_eq!(CASTED, b(NonNull::dangling)()); } diff --git a/src/test/run-pass/consts/const-ptr-unique.rs b/src/test/run-pass/consts/const-ptr-unique.rs index b5cc78d4b7188..be3ea193fa4eb 100644 --- a/src/test/run-pass/consts/const-ptr-unique.rs +++ b/src/test/run-pass/consts/const-ptr-unique.rs @@ -11,5 +11,5 @@ use std::ptr::Unique; const PTR: *mut u32 = Unique::empty().as_ptr(); pub fn main() { - assert_eq!(PTR, b(Unique::::empty()).as_ptr()); + assert_eq!(PTR, b(Unique::::empty)().as_ptr()); } From ffe23475cba4b933475715ff72ca0be6aea0a398 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 8 Jun 2019 20:20:00 +0300 Subject: [PATCH 04/16] syntax: Keep full `Token`s for `macro_rules` separators --- src/libsyntax/ext/tt/macro_parser.rs | 2 +- src/libsyntax/ext/tt/macro_rules.rs | 30 +++++++++---------- src/libsyntax/ext/tt/quoted.rs | 14 ++++----- src/libsyntax/ext/tt/transcribe.rs | 19 +++++------- .../macros/macro-input-future-proofing.stderr | 4 +-- 5 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index f98e1433356c2..1c7fdf995e15a 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -199,7 +199,7 @@ struct MatcherPos<'root, 'tt: 'root> { seq_op: Option, /// The separator if we are in a repetition. - sep: Option, + sep: Option, /// The "parent" matcher position if we are in a repetition. That is, the matcher position just /// before we enter the sequence. diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 4998129fdee51..b7fbfd60ed740 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -17,7 +17,7 @@ use crate::symbol::{Symbol, kw, sym}; use crate::tokenstream::{DelimSpan, TokenStream, TokenTree}; use errors::FatalError; -use syntax_pos::{Span, DUMMY_SP, symbol::Ident}; +use syntax_pos::{Span, symbol::Ident}; use log::debug; use rustc_data_structures::fx::{FxHashMap}; @@ -266,17 +266,19 @@ pub fn compile( let argument_gram = vec![ quoted::TokenTree::Sequence(DelimSpan::dummy(), Lrc::new(quoted::SequenceRepetition { tts: vec![ - quoted::TokenTree::MetaVarDecl(DUMMY_SP, lhs_nm, ast::Ident::from_str("tt")), - quoted::TokenTree::token(token::FatArrow, DUMMY_SP), - quoted::TokenTree::MetaVarDecl(DUMMY_SP, rhs_nm, ast::Ident::from_str("tt")), + quoted::TokenTree::MetaVarDecl(def.span, lhs_nm, ast::Ident::from_str("tt")), + quoted::TokenTree::token(token::FatArrow, def.span), + quoted::TokenTree::MetaVarDecl(def.span, rhs_nm, ast::Ident::from_str("tt")), ], - separator: Some(if body.legacy { token::Semi } else { token::Comma }), + separator: Some(Token::new( + if body.legacy { token::Semi } else { token::Comma }, def.span + )), op: quoted::KleeneOp::OneOrMore, num_captures: 2, })), // to phase into semicolon-termination instead of semicolon-separation quoted::TokenTree::Sequence(DelimSpan::dummy(), Lrc::new(quoted::SequenceRepetition { - tts: vec![quoted::TokenTree::token(token::Semi, DUMMY_SP)], + tts: vec![quoted::TokenTree::token(token::Semi, def.span)], separator: None, op: quoted::KleeneOp::ZeroOrMore, num_captures: 0 @@ -608,9 +610,8 @@ impl FirstSets { // If the sequence contents can be empty, then the first // token could be the separator token itself. - if let (Some(ref sep), true) = (seq_rep.separator.clone(), - subfirst.maybe_empty) { - first.add_one_maybe(TokenTree::token(sep.clone(), sp.entire())); + if let (Some(sep), true) = (&seq_rep.separator, subfirst.maybe_empty) { + first.add_one_maybe(TokenTree::Token(sep.clone())); } // Reverse scan: Sequence comes before `first`. @@ -658,9 +659,8 @@ impl FirstSets { // If the sequence contents can be empty, then the first // token could be the separator token itself. - if let (Some(ref sep), true) = (seq_rep.separator.clone(), - subfirst.maybe_empty) { - first.add_one_maybe(TokenTree::token(sep.clone(), sp.entire())); + if let (Some(sep), true) = (&seq_rep.separator, subfirst.maybe_empty) { + first.add_one_maybe(TokenTree::Token(sep.clone())); } assert!(first.maybe_empty); @@ -851,7 +851,7 @@ fn check_matcher_core(sess: &ParseSess, // against SUFFIX continue 'each_token; } - TokenTree::Sequence(sp, ref seq_rep) => { + TokenTree::Sequence(_, ref seq_rep) => { suffix_first = build_suffix_first(); // The trick here: when we check the interior, we want // to include the separator (if any) as a potential @@ -864,9 +864,9 @@ fn check_matcher_core(sess: &ParseSess, // work of cloning it? But then again, this way I may // get a "tighter" span? let mut new; - let my_suffix = if let Some(ref u) = seq_rep.separator { + let my_suffix = if let Some(sep) = &seq_rep.separator { new = suffix_first.clone(); - new.add_one_maybe(TokenTree::token(u.clone(), sp.entire())); + new.add_one_maybe(TokenTree::Token(sep.clone())); &new } else { &suffix_first diff --git a/src/libsyntax/ext/tt/quoted.rs b/src/libsyntax/ext/tt/quoted.rs index ec7d7f705d893..8f8aa586070d5 100644 --- a/src/libsyntax/ext/tt/quoted.rs +++ b/src/libsyntax/ext/tt/quoted.rs @@ -59,7 +59,7 @@ pub struct SequenceRepetition { /// The sequence of token trees pub tts: Vec, /// The optional separator - pub separator: Option, + pub separator: Option, /// Whether the sequence can be repeated zero (*), or one or more times (+) pub op: KleeneOp, /// The number of `Match`s that appear in the sequence (and subsequences) @@ -424,7 +424,7 @@ fn parse_sep_and_kleene_op( attrs: &[ast::Attribute], edition: Edition, macro_node_id: NodeId, -) -> (Option, KleeneOp) +) -> (Option, KleeneOp) where I: Iterator, { @@ -449,7 +449,7 @@ fn parse_sep_and_kleene_op_2015( _features: &Features, _attrs: &[ast::Attribute], macro_node_id: NodeId, -) -> (Option, KleeneOp) +) -> (Option, KleeneOp) where I: Iterator, { @@ -502,7 +502,7 @@ where a hard error in an upcoming edition", ); - return (Some(token::Question), op); + return (Some(Token::new(token::Question, op1_span)), op); } // #2 is a random token (this is an error) :( @@ -541,7 +541,7 @@ where } // #2 is a KleeneOp :D - Ok(Ok((op, _))) => return (Some(token.kind), op), + Ok(Ok((op, _))) => return (Some(token), op), // #2 is a random token :( Ok(Err(token)) => token.span, @@ -567,7 +567,7 @@ fn parse_sep_and_kleene_op_2018( sess: &ParseSess, _features: &Features, _attrs: &[ast::Attribute], -) -> (Option, KleeneOp) +) -> (Option, KleeneOp) where I: Iterator, { @@ -596,7 +596,7 @@ where } // #2 is a KleeneOp :D - Ok(Ok((op, _))) => return (Some(token.kind), op), + Ok(Ok((op, _))) => return (Some(token), op), // #2 is a random token :( Ok(Err(token)) => token.span, diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 90a9cc8f34d2d..3408cefdf4274 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -4,11 +4,10 @@ use crate::ext::expand::Marker; use crate::ext::tt::macro_parser::{MatchedNonterminal, MatchedSeq, NamedMatch}; use crate::ext::tt::quoted; use crate::mut_visit::noop_visit_tt; -use crate::parse::token::{self, NtTT, TokenKind}; +use crate::parse::token::{self, NtTT, Token, TokenKind}; use crate::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint}; use smallvec::{smallvec, SmallVec}; -use syntax_pos::DUMMY_SP; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; @@ -18,7 +17,7 @@ use std::rc::Rc; /// An iterator over the token trees in a delimited token tree (`{ ... }`) or a sequence (`$(...)`). enum Frame { Delimited { forest: Lrc, idx: usize, span: DelimSpan }, - Sequence { forest: Lrc, idx: usize, sep: Option }, + Sequence { forest: Lrc, idx: usize, sep: Option }, } impl Frame { @@ -109,17 +108,13 @@ pub fn transcribe( else { // Otherwise, if we have just reached the end of a sequence and we can keep repeating, // go back to the beginning of the sequence. - if let Frame::Sequence { ref mut idx, ref sep, .. } = *stack.last_mut().unwrap() { - let (ref mut repeat_idx, repeat_len) = *repeats.last_mut().unwrap(); + if let Frame::Sequence { idx, sep, .. } = stack.last_mut().unwrap() { + let (repeat_idx, repeat_len) = repeats.last_mut().unwrap(); *repeat_idx += 1; - if *repeat_idx < repeat_len { + if repeat_idx < repeat_len { *idx = 0; - if let Some(sep) = sep.clone() { - let prev_span = match result.last() { - Some((tt, _)) => tt.span(), - None => DUMMY_SP, - }; - result.push(TokenTree::token(sep, prev_span).into()); + if let Some(sep) = sep { + result.push(TokenTree::Token(sep.clone()).into()); } continue; } diff --git a/src/test/ui/macros/macro-input-future-proofing.stderr b/src/test/ui/macros/macro-input-future-proofing.stderr index a35f6283afb2e..542486927dfd1 100644 --- a/src/test/ui/macros/macro-input-future-proofing.stderr +++ b/src/test/ui/macros/macro-input-future-proofing.stderr @@ -55,10 +55,10 @@ LL | ($($a:ty, $b:ty)* -) => (); = note: allowed there are: `{`, `[`, `=>`, `,`, `>`, `=`, `:`, `;`, `|`, `as` or `where` error: `$ty:ty` is followed by `-`, which is not allowed for `ty` fragments - --> $DIR/macro-input-future-proofing.rs:18:7 + --> $DIR/macro-input-future-proofing.rs:18:15 | LL | ($($ty:ty)-+) => (); - | ^^^^^^^^ not allowed after `ty` fragments + | ^ not allowed after `ty` fragments | = note: allowed there are: `{`, `[`, `=>`, `,`, `>`, `=`, `:`, `;`, `|`, `as` or `where` From d69d0d7aa76af6496c6d623990ae6e20ecc4f947 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 9 Jun 2019 03:04:56 +0900 Subject: [PATCH 05/16] Add test for ICE --- src/test/ui/traits/trait-with-dst.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/ui/traits/trait-with-dst.rs diff --git a/src/test/ui/traits/trait-with-dst.rs b/src/test/ui/traits/trait-with-dst.rs new file mode 100644 index 0000000000000..86d6585bc6143 --- /dev/null +++ b/src/test/ui/traits/trait-with-dst.rs @@ -0,0 +1,22 @@ +// compile-pass +// #55266 + +struct VTable { + _to_dst_ptr: fn(*mut ()) -> *mut DST, +} + +trait HasVTableFor { + const VTABLE: &'static VTable; +} + +impl HasVTableFor for T { + const VTABLE: &'static VTable = &VTable { + _to_dst_ptr: |_: *mut ()| unsafe { std::mem::zeroed() }, + }; +} + +pub fn push() { + >::VTABLE; +} + +fn main() {} From 3f99ad175a745bcb49eeef64675f1fa48d84016d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 8 Jun 2019 20:35:59 +0200 Subject: [PATCH 06/16] extra paranoid mode --- src/test/run-pass/consts/const-ptr-nonnull.rs | 5 +++-- src/test/run-pass/consts/const-ptr-unique.rs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/run-pass/consts/const-ptr-nonnull.rs b/src/test/run-pass/consts/const-ptr-nonnull.rs index 12a5ea5b480ba..67d52ad08246a 100644 --- a/src/test/run-pass/consts/const-ptr-nonnull.rs +++ b/src/test/run-pass/consts/const-ptr-nonnull.rs @@ -11,6 +11,7 @@ const DANGLING: NonNull = NonNull::dangling(); const CASTED: NonNull = NonNull::cast(NonNull::::dangling()); pub fn main() { - assert_eq!(DANGLING, b(NonNull::dangling)()); - assert_eq!(CASTED, b(NonNull::dangling)()); + // Be super-extra paranoid and cast the fn items to fn pointers before blackboxing them. + assert_eq!(DANGLING, b:: _>(NonNull::dangling)()); + assert_eq!(CASTED, b:: _>(NonNull::dangling)()); } diff --git a/src/test/run-pass/consts/const-ptr-unique.rs b/src/test/run-pass/consts/const-ptr-unique.rs index be3ea193fa4eb..e8735e1a32c2c 100644 --- a/src/test/run-pass/consts/const-ptr-unique.rs +++ b/src/test/run-pass/consts/const-ptr-unique.rs @@ -11,5 +11,6 @@ use std::ptr::Unique; const PTR: *mut u32 = Unique::empty().as_ptr(); pub fn main() { - assert_eq!(PTR, b(Unique::::empty)().as_ptr()); + // Be super-extra paranoid and cast the fn items to fn pointers before blackboxing them. + assert_eq!(PTR, b:: _>(Unique::::empty)().as_ptr()); } From 0ca3c2f881fc4bc51bfa92f1adcd1b845b812534 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 8 Jun 2019 19:45:12 +0300 Subject: [PATCH 07/16] syntax: Move most of the `TokenKind` methods to `Token` --- src/librustdoc/html/highlight.rs | 2 +- src/libsyntax/attr/mod.rs | 5 +- src/libsyntax/ext/tt/macro_parser.rs | 14 ++-- src/libsyntax/ext/tt/transcribe.rs | 4 +- src/libsyntax/parse/lexer/mod.rs | 6 +- src/libsyntax/parse/parser.rs | 8 +- src/libsyntax/parse/token.rs | 116 ++++++++++----------------- src/libsyntax/tokenstream.rs | 5 +- src/libsyntax/util/parser.rs | 6 +- 9 files changed, 66 insertions(+), 100 deletions(-) diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 281bd72deeb80..99ca8c43cfbe2 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -257,7 +257,7 @@ impl<'a> Classifier<'a> { token::Question => Class::QuestionMark, token::Dollar => { - if self.lexer.peek().kind.is_ident() { + if self.lexer.peek().is_ident() { self.in_macro_nonterminal = true; Class::MacroNonTerminal } else { diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index b5d9b761773b4..d7e43f645df7b 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -20,7 +20,7 @@ use crate::source_map::{BytePos, Spanned, dummy_spanned}; use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration}; use crate::parse::parser::Parser; use crate::parse::{self, ParseSess, PResult}; -use crate::parse::token::{self, Token, TokenKind}; +use crate::parse::token::{self, Token}; use crate::ptr::P; use crate::symbol::{sym, Symbol}; use crate::ThinVec; @@ -467,8 +467,7 @@ impl MetaItem { segment.ident.span.ctxt()); idents.push(TokenTree::token(token::ModSep, mod_sep_span).into()); } - idents.push(TokenTree::token(TokenKind::from_ast_ident(segment.ident), - segment.ident.span).into()); + idents.push(TokenTree::Token(Token::from_ast_ident(segment.ident)).into()); last_pos = segment.ident.span.hi(); } self.node.tokens(self.span).append_to_tree_and_joint_vec(&mut idents); diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 1c7fdf995e15a..9520adb9029c2 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -428,13 +428,13 @@ pub fn parse_failure_msg(tok: TokenKind) -> String { } /// Performs a token equality check, ignoring syntax context (that is, an unhygienic comparison) -fn token_name_eq(t1: &TokenKind, t2: &TokenKind) -> bool { - if let (Some((name1, is_raw1)), Some((name2, is_raw2))) = (t1.ident_name(), t2.ident_name()) { - name1 == name2 && is_raw1 == is_raw2 - } else if let (Some(name1), Some(name2)) = (t1.lifetime_name(), t2.lifetime_name()) { - name1 == name2 +fn token_name_eq(t1: &Token, t2: &Token) -> bool { + if let (Some((ident1, is_raw1)), Some((ident2, is_raw2))) = (t1.ident(), t2.ident()) { + ident1.name == ident2.name && is_raw1 == is_raw2 + } else if let (Some(ident1), Some(ident2)) = (t1.lifetime(), t2.lifetime()) { + ident1.name == ident2.name } else { - *t1 == *t2 + t1.kind == t2.kind } } @@ -712,7 +712,7 @@ pub fn parse( // If we reached the EOF, check that there is EXACTLY ONE possible matcher. Otherwise, // either the parse is ambiguous (which should never happen) or there is a syntax error. - if token_name_eq(&parser.token, &token::Eof) { + if parser.token == token::Eof { if eof_items.len() == 1 { let matches = eof_items[0] .matches diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 3408cefdf4274..c51f4b20c31c0 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -4,7 +4,7 @@ use crate::ext::expand::Marker; use crate::ext::tt::macro_parser::{MatchedNonterminal, MatchedSeq, NamedMatch}; use crate::ext::tt::quoted; use crate::mut_visit::noop_visit_tt; -use crate::parse::token::{self, NtTT, Token, TokenKind}; +use crate::parse::token::{self, NtTT, Token}; use crate::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint}; use smallvec::{smallvec, SmallVec}; @@ -237,7 +237,7 @@ pub fn transcribe( Ident::new(ident.name, ident.span.apply_mark(cx.current_expansion.mark)); sp = sp.apply_mark(cx.current_expansion.mark); result.push(TokenTree::token(token::Dollar, sp).into()); - result.push(TokenTree::token(TokenKind::from_ast_ident(ident), sp).into()); + result.push(TokenTree::Token(Token::from_ast_ident(ident)).into()); } } diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index e3d959c2c54c4..2f4c48d4bf9e0 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1501,7 +1501,7 @@ fn char_at(s: &str, byte: usize) -> char { mod tests { use super::*; - use crate::ast::{Ident, CrateConfig}; + use crate::ast::CrateConfig; use crate::symbol::Symbol; use crate::source_map::{SourceMap, FilePathMapping}; use crate::feature_gate::UnstableFeatures; @@ -1562,7 +1562,7 @@ mod tests { assert_eq!(string_reader.next_token(), token::Whitespace); let tok1 = string_reader.next_token(); let tok2 = Token::new( - token::Ident(Symbol::intern("fn"), false), + mk_ident("fn"), Span::new(BytePos(21), BytePos(23), NO_EXPANSION), ); assert_eq!(tok1.kind, tok2.kind); @@ -1593,7 +1593,7 @@ mod tests { // make the identifier by looking up the string in the interner fn mk_ident(id: &str) -> TokenKind { - TokenKind::from_ast_ident(Ident::from_str(id)) + token::Ident(Symbol::intern(id), false) } fn mk_lit(kind: token::LitKind, symbol: &str, suffix: Option<&str>) -> TokenKind { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 3acd708814560..8ad43a6c809bd 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2627,9 +2627,11 @@ impl<'a> Parser<'a> { token::Ident(name, _) => name, _ => unreachable!() }; - let mut err = self.fatal(&format!("unknown macro variable `{}`", name)); - err.span_label(self.token.span, "unknown macro variable"); - err.emit(); + let span = self.prev_span.to(self.token.span); + self.diagnostic() + .struct_span_fatal(span, &format!("unknown macro variable `{}`", name)) + .span_label(span, "unknown macro variable") + .emit(); self.bump(); return } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 28a733728bf7b..0ece5b57935e5 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -241,21 +241,19 @@ pub struct Token { pub span: Span, } -impl TokenKind { - /// Recovers a `TokenKind` from an `ast::Ident`. This creates a raw identifier if necessary. - pub fn from_ast_ident(ident: ast::Ident) -> TokenKind { - Ident(ident.name, ident.is_raw_guess()) +impl Token { + /// Recovers a `Token` from an `ast::Ident`. This creates a raw identifier if necessary. + crate fn from_ast_ident(ident: ast::Ident) -> Token { + Token::new(Ident(ident.name, ident.is_raw_guess()), ident.span) } crate fn is_like_plus(&self) -> bool { - match *self { + match self.kind { BinOp(Plus) | BinOpEq(Plus) => true, _ => false, } } -} -impl Token { /// Returns `true` if the token can appear at the start of an expression. crate fn can_begin_expr(&self) -> bool { match self.kind { @@ -310,12 +308,10 @@ impl Token { _ => false, } } -} -impl TokenKind { /// Returns `true` if the token can appear at the start of a const param. - pub fn can_begin_const_arg(&self) -> bool { - match self { + crate fn can_begin_const_arg(&self) -> bool { + match self.kind { OpenDelim(Brace) => true, Interpolated(ref nt) => match **nt { NtExpr(..) => true, @@ -326,9 +322,7 @@ impl TokenKind { _ => self.can_begin_literal_or_bool(), } } -} -impl Token { /// Returns `true` if the token can appear at the start of a generic bound. crate fn can_begin_bound(&self) -> bool { self.is_path_start() || self.is_lifetime() || self.is_keyword(kw::For) || @@ -340,17 +334,19 @@ impl TokenKind { pub fn lit(kind: LitKind, symbol: Symbol, suffix: Option) -> TokenKind { Literal(Lit::new(kind, symbol, suffix)) } +} +impl Token { /// Returns `true` if the token is any literal crate fn is_lit(&self) -> bool { - match *self { + match self.kind { Literal(..) => true, _ => false, } } crate fn expect_lit(&self) -> Lit { - match *self { + match self.kind { Literal(lit) => lit, _=> panic!("`expect_lit` called on non-literal"), } @@ -359,7 +355,7 @@ impl TokenKind { /// Returns `true` if the token is any literal, a minus (which can prefix a literal, /// for example a '-42', or one of the boolean idents). crate fn can_begin_literal_or_bool(&self) -> bool { - match *self { + match self.kind { Literal(..) => true, BinOp(Minus) => true, Ident(name, false) if name == kw::True => true, @@ -371,9 +367,7 @@ impl TokenKind { _ => false, } } -} -impl Token { /// Returns an identifier if this token is an identifier. pub fn ident(&self) -> Option<(ast::Ident, /* is_raw */ bool)> { match self.kind { @@ -397,49 +391,25 @@ impl Token { _ => None, } } -} -impl TokenKind { - /// Returns an identifier name if this token is an identifier. - pub fn ident_name(&self) -> Option<(ast::Name, /* is_raw */ bool)> { - match *self { - Ident(name, is_raw) => Some((name, is_raw)), - Interpolated(ref nt) => match **nt { - NtIdent(ident, is_raw) => Some((ident.name, is_raw)), - _ => None, - }, - _ => None, - } - } - /// Returns a lifetime name if this token is a lifetime. - pub fn lifetime_name(&self) -> Option { - match *self { - Lifetime(name) => Some(name), - Interpolated(ref nt) => match **nt { - NtLifetime(ident) => Some(ident.name), - _ => None, - }, - _ => None, - } - } /// Returns `true` if the token is an identifier. pub fn is_ident(&self) -> bool { - self.ident_name().is_some() + self.ident().is_some() } /// Returns `true` if the token is a lifetime. crate fn is_lifetime(&self) -> bool { - self.lifetime_name().is_some() + self.lifetime().is_some() } /// Returns `true` if the token is a identifier whose name is the given /// string slice. crate fn is_ident_named(&self, name: Symbol) -> bool { - self.ident_name().map_or(false, |(ident_name, _)| ident_name == name) + self.ident().map_or(false, |(ident, _)| ident.name == name) } /// Returns `true` if the token is an interpolated path. fn is_path(&self) -> bool { - if let Interpolated(ref nt) = *self { + if let Interpolated(ref nt) = self.kind { if let NtPath(..) = **nt { return true; } @@ -456,33 +426,27 @@ impl TokenKind { crate fn is_qpath_start(&self) -> bool { self == &Lt || self == &BinOp(Shl) } -} -impl Token { crate fn is_path_start(&self) -> bool { self == &ModSep || self.is_qpath_start() || self.is_path() || self.is_path_segment_keyword() || self.is_ident() && !self.is_reserved_ident() } -} -impl TokenKind { /// Returns `true` if the token is a given keyword, `kw`. pub fn is_keyword(&self, kw: Symbol) -> bool { - self.ident_name().map(|(name, is_raw)| name == kw && !is_raw).unwrap_or(false) + self.ident().map(|(id, is_raw)| id.name == kw && !is_raw).unwrap_or(false) } - pub fn is_path_segment_keyword(&self) -> bool { - match self.ident_name() { - Some((name, false)) => name.is_path_segment_keyword(), + crate fn is_path_segment_keyword(&self) -> bool { + match self.ident() { + Some((id, false)) => id.is_path_segment_keyword(), _ => false, } } -} -impl Token { // Returns true for reserved identifiers used internally for elided lifetimes, // unnamed method parameters, crate root module, error recovery etc. - pub fn is_special_ident(&self) -> bool { + crate fn is_special_ident(&self) -> bool { match self.ident() { Some((id, false)) => id.is_special(), _ => false, @@ -512,55 +476,53 @@ impl Token { _ => false, } } -} -impl TokenKind { - crate fn glue(self, joint: TokenKind) -> Option { - Some(match self { - Eq => match joint { + crate fn glue(self, joint: Token) -> Option { + let kind = match self.kind { + Eq => match joint.kind { Eq => EqEq, Gt => FatArrow, _ => return None, }, - Lt => match joint { + Lt => match joint.kind { Eq => Le, Lt => BinOp(Shl), Le => BinOpEq(Shl), BinOp(Minus) => LArrow, _ => return None, }, - Gt => match joint { + Gt => match joint.kind { Eq => Ge, Gt => BinOp(Shr), Ge => BinOpEq(Shr), _ => return None, }, - Not => match joint { + Not => match joint.kind { Eq => Ne, _ => return None, }, - BinOp(op) => match joint { + BinOp(op) => match joint.kind { Eq => BinOpEq(op), BinOp(And) if op == And => AndAnd, BinOp(Or) if op == Or => OrOr, Gt if op == Minus => RArrow, _ => return None, }, - Dot => match joint { + Dot => match joint.kind { Dot => DotDot, DotDot => DotDotDot, _ => return None, }, - DotDot => match joint { + DotDot => match joint.kind { Dot => DotDotDot, Eq => DotDotEq, _ => return None, }, - Colon => match joint { + Colon => match joint.kind { Colon => ModSep, _ => return None, }, - SingleQuote => match joint { + SingleQuote => match joint.kind { Ident(name, false) => Lifetime(Symbol::intern(&format!("'{}", name))), _ => return None, }, @@ -570,9 +532,13 @@ impl TokenKind { Question | OpenDelim(..) | CloseDelim(..) | Literal(..) | Ident(..) | Lifetime(..) | Interpolated(..) | DocComment(..) | Whitespace | Comment | Shebang(..) | Eof => return None, - }) + }; + + Some(Token::new(kind, self.span.to(joint.span))) } +} +impl TokenKind { /// Returns tokens that are likely to be typed accidentally instead of the current token. /// Enables better error recovery when the wrong token is found. crate fn similar_tokens(&self) -> Option> { @@ -582,14 +548,16 @@ impl TokenKind { _ => None } } +} +impl Token { // See comments in `Nonterminal::to_tokenstream` for why we care about // *probably* equal here rather than actual equality crate fn probably_equal_for_proc_macro(&self, other: &TokenKind) -> bool { - if mem::discriminant(self) != mem::discriminant(other) { + if mem::discriminant(&self.kind) != mem::discriminant(other) { return false } - match (self, other) { + match (&self.kind, other) { (&Eq, &Eq) | (&Lt, &Lt) | (&Le, &Le) | @@ -641,9 +609,7 @@ impl TokenKind { _ => panic!("forgot to add a token?"), } } -} -impl Token { crate fn new(kind: TokenKind, span: Span) -> Self { Token { kind, span } } diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 9dea3a4dcc144..d46d2f549c09b 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -430,11 +430,10 @@ impl TokenStreamBuilder { let last_tree_if_joint = self.0.last().and_then(TokenStream::last_tree_if_joint); if let Some(TokenTree::Token(last_token)) = last_tree_if_joint { if let Some((TokenTree::Token(token), is_joint)) = stream.first_tree_and_joint() { - if let Some(glued_tok) = last_token.kind.glue(token.kind) { + if let Some(glued_tok) = last_token.glue(token) { let last_stream = self.0.pop().unwrap(); self.push_all_but_last_tree(&last_stream); - let glued_span = last_token.span.to(token.span); - let glued_tt = TokenTree::token(glued_tok, glued_span); + let glued_tt = TokenTree::Token(glued_tok); let glued_tokenstream = TokenStream::new(vec![(glued_tt, is_joint)]); self.0.push(glued_tokenstream); self.push_all_but_first_tree(&stream); diff --git a/src/libsyntax/util/parser.rs b/src/libsyntax/util/parser.rs index 9e26f1bf7d374..69dd96625cc02 100644 --- a/src/libsyntax/util/parser.rs +++ b/src/libsyntax/util/parser.rs @@ -1,4 +1,4 @@ -use crate::parse::token::{self, TokenKind, BinOpToken}; +use crate::parse::token::{self, Token, BinOpToken}; use crate::symbol::kw; use crate::ast::{self, BinOpKind}; @@ -69,9 +69,9 @@ pub enum Fixity { impl AssocOp { /// Creates a new AssocOP from a token - pub fn from_token(t: &TokenKind) -> Option { + pub fn from_token(t: &Token) -> Option { use AssocOp::*; - match *t { + match t.kind { token::BinOpEq(k) => Some(AssignOp(k)), token::Eq => Some(Assign), token::BinOp(BinOpToken::Star) => Some(Multiply), From 25b05147b3ec0a1ed9df9614910a10171b8cf211 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 8 Jun 2019 22:38:23 +0300 Subject: [PATCH 08/16] syntax: Remove `Deref` impl from `Token` --- src/libsyntax/ext/tt/macro_parser.rs | 12 +++++----- src/libsyntax/ext/tt/macro_rules.rs | 4 ++-- src/libsyntax/ext/tt/quoted.rs | 20 +++++------------ src/libsyntax/parse/diagnostics.rs | 2 +- src/libsyntax/parse/lexer/tokentrees.rs | 2 +- src/libsyntax/parse/mod.rs | 4 ++-- src/libsyntax/parse/parser.rs | 18 +++++++-------- src/libsyntax/parse/token.rs | 29 ++++++++++--------------- src/libsyntax/print/pprust.rs | 12 ++++++---- src/libsyntax/tokenstream.rs | 8 ------- 10 files changed, 45 insertions(+), 66 deletions(-) diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 9520adb9029c2..4758b6a50e520 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -78,7 +78,7 @@ use crate::ast::{Ident, Name}; use crate::ext::tt::quoted::{self, TokenTree}; use crate::parse::{Directory, ParseSess}; use crate::parse::parser::{Parser, PathStyle}; -use crate::parse::token::{self, DocComment, Nonterminal, Token, TokenKind}; +use crate::parse::token::{self, DocComment, Nonterminal, Token}; use crate::print::pprust; use crate::symbol::{kw, sym, Symbol}; use crate::tokenstream::{DelimSpan, TokenStream}; @@ -417,12 +417,12 @@ fn nameize>( /// Generates an appropriate parsing failure message. For EOF, this is "unexpected end...". For /// other tokens, this is "unexpected token...". -pub fn parse_failure_msg(tok: TokenKind) -> String { - match tok { +pub fn parse_failure_msg(tok: &Token) -> String { + match tok.kind { token::Eof => "unexpected end of macro invocation".to_string(), _ => format!( "no rules expected the token `{}`", - pprust::token_to_string(&tok) + pprust::token_to_string(tok) ), } } @@ -804,8 +804,8 @@ pub fn parse( /// The token is an identifier, but not `_`. /// We prohibit passing `_` to macros expecting `ident` for now. -fn get_macro_name(token: &TokenKind) -> Option<(Name, bool)> { - match *token { +fn get_macro_name(token: &Token) -> Option<(Name, bool)> { + match token.kind { token::Ident(name, is_raw) if name != kw::Underscore => Some((name, is_raw)), _ => None, } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index b7fbfd60ed740..e7da195c0055f 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -200,7 +200,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt<'_>, let (token, label) = best_failure.expect("ran no matchers"); let span = token.span.substitute_dummy(sp); - let mut err = cx.struct_span_err(span, &parse_failure_msg(token.kind)); + let mut err = cx.struct_span_err(span, &parse_failure_msg(&token)); err.span_label(span, label); if let Some(sp) = def_span { if cx.source_map().span_to_filename(sp).is_real() && !sp.is_dummy() { @@ -288,7 +288,7 @@ pub fn compile( let argument_map = match parse(sess, body.stream(), &argument_gram, None, true) { Success(m) => m, Failure(token, msg) => { - let s = parse_failure_msg(token.kind); + let s = parse_failure_msg(&token); let sp = token.span.substitute_dummy(def.span); let mut err = sess.span_diagnostic.struct_span_fatal(sp, &s); err.span_label(sp, msg); diff --git a/src/libsyntax/ext/tt/quoted.rs b/src/libsyntax/ext/tt/quoted.rs index 8f8aa586070d5..707fb65bcc52b 100644 --- a/src/libsyntax/ext/tt/quoted.rs +++ b/src/libsyntax/ext/tt/quoted.rs @@ -23,16 +23,6 @@ pub struct Delimited { } impl Delimited { - /// Returns the opening delimiter (possibly `NoDelim`). - pub fn open_token(&self) -> TokenKind { - token::OpenDelim(self.delim) - } - - /// Returns the closing delimiter (possibly `NoDelim`). - pub fn close_token(&self) -> TokenKind { - token::CloseDelim(self.delim) - } - /// Returns a `self::TokenTree` with a `Span` corresponding to the opening delimiter. pub fn open_tt(&self, span: Span) -> TokenTree { let open_span = if span.is_dummy() { @@ -40,7 +30,7 @@ impl Delimited { } else { span.with_lo(span.lo() + BytePos(self.delim.len() as u32)) }; - TokenTree::token(self.open_token(), open_span) + TokenTree::token(token::OpenDelim(self.delim), open_span) } /// Returns a `self::TokenTree` with a `Span` corresponding to the closing delimiter. @@ -50,7 +40,7 @@ impl Delimited { } else { span.with_lo(span.hi() - BytePos(self.delim.len() as u32)) }; - TokenTree::token(self.close_token(), close_span) + TokenTree::token(token::CloseDelim(self.delim), close_span) } } @@ -282,7 +272,7 @@ where Some(tokenstream::TokenTree::Delimited(span, delim, tts)) => { // Must have `(` not `{` or `[` if delim != token::Paren { - let tok = pprust::token_to_string(&token::OpenDelim(delim)); + let tok = pprust::token_kind_to_string(&token::OpenDelim(delim)); let msg = format!("expected `(`, found `{}`", tok); sess.span_diagnostic.span_err(span.entire(), &msg); } @@ -371,8 +361,8 @@ where /// Takes a token and returns `Some(KleeneOp)` if the token is `+` `*` or `?`. Otherwise, return /// `None`. -fn kleene_op(token: &TokenKind) -> Option { - match *token { +fn kleene_op(token: &Token) -> Option { + match token.kind { token::BinOp(token::Star) => Some(KleeneOp::ZeroOrMore), token::BinOp(token::Plus) => Some(KleeneOp::OneOrMore), token::Question => Some(KleeneOp::ZeroOrOne), diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs index c4db9a9df45a9..9d2ac5b4b5168 100644 --- a/src/libsyntax/parse/diagnostics.rs +++ b/src/libsyntax/parse/diagnostics.rs @@ -729,7 +729,7 @@ impl<'a> Parser<'a> { &mut self, t: &TokenKind, ) -> PResult<'a, bool /* recovered */> { - let token_str = pprust::token_to_string(t); + let token_str = pprust::token_kind_to_string(t); let this_token_str = self.this_token_descr(); let (prev_sp, sp) = match (&self.token.kind, self.subparser_name) { // Point at the end of the macro call when reaching end of macro arguments. diff --git a/src/libsyntax/parse/lexer/tokentrees.rs b/src/libsyntax/parse/lexer/tokentrees.rs index b809f99beba33..99d9d40a45b93 100644 --- a/src/libsyntax/parse/lexer/tokentrees.rs +++ b/src/libsyntax/parse/lexer/tokentrees.rs @@ -211,7 +211,7 @@ impl<'a> TokenTreesReader<'a> { let raw = self.string_reader.peek_span_src_raw; self.real_token(); let is_joint = raw.hi() == self.string_reader.peek_span_src_raw.lo() - && token::is_op(&self.token); + && self.token.is_op(); Ok((tt, if is_joint { Joint } else { NonJoint })) } } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 1d708d39a1379..cde35681988db 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -9,7 +9,7 @@ use crate::parse::parser::emit_unclosed_delims; use crate::parse::token::TokenKind; use crate::tokenstream::{TokenStream, TokenTree}; use crate::diagnostics::plugin::ErrorMap; -use crate::print::pprust::token_to_string; +use crate::print::pprust; use errors::{Applicability, FatalError, Level, Handler, ColorConfig, Diagnostic, DiagnosticBuilder}; use rustc_data_structures::sync::{Lrc, Lock}; @@ -312,7 +312,7 @@ pub fn maybe_file_to_stream( for unmatched in unmatched_braces { let mut db = sess.span_diagnostic.struct_span_err(unmatched.found_span, &format!( "incorrect close delimiter: `{}`", - token_to_string(&token::CloseDelim(unmatched.found_delim)), + pprust::token_kind_to_string(&token::CloseDelim(unmatched.found_delim)), )); db.span_label(unmatched.found_span, "incorrect close delimiter"); if let Some(sp) = unmatched.candidate_span { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8ad43a6c809bd..d9eba3bbadb68 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -401,7 +401,7 @@ crate enum TokenType { impl TokenType { crate fn to_string(&self) -> String { match *self { - TokenType::Token(ref t) => format!("`{}`", pprust::token_to_string(t)), + TokenType::Token(ref t) => format!("`{}`", pprust::token_kind_to_string(t)), TokenType::Keyword(kw) => format!("`{}`", kw), TokenType::Operator => "an operator".to_string(), TokenType::Lifetime => "lifetime".to_string(), @@ -418,7 +418,7 @@ impl TokenType { /// /// Types can also be of the form `IDENT(u8, u8) -> u8`, however this assumes /// that `IDENT` is not the ident of a fn trait. -fn can_continue_type_after_non_fn_ident(t: &TokenKind) -> bool { +fn can_continue_type_after_non_fn_ident(t: &Token) -> bool { t == &token::ModSep || t == &token::Lt || t == &token::BinOp(token::Shl) } @@ -586,10 +586,10 @@ impl<'a> Parser<'a> { edible: &[TokenKind], inedible: &[TokenKind], ) -> PResult<'a, bool /* recovered */> { - if edible.contains(&self.token) { + if edible.contains(&self.token.kind) { self.bump(); Ok(false) - } else if inedible.contains(&self.token) { + } else if inedible.contains(&self.token.kind) { // leave it in the input Ok(false) } else if self.last_unexpected_token_span == Some(self.token.span) { @@ -951,7 +951,7 @@ impl<'a> Parser<'a> { Err(mut e) => { // Attempt to keep parsing if it was a similar separator if let Some(ref tokens) = t.similar_tokens() { - if tokens.contains(&self.token) { + if tokens.contains(&self.token.kind) { self.bump(); } } @@ -1756,7 +1756,7 @@ impl<'a> Parser<'a> { fn parse_path_segment(&mut self, style: PathStyle) -> PResult<'a, PathSegment> { let ident = self.parse_path_segment_ident()?; - let is_args_start = |token: &TokenKind| match *token { + let is_args_start = |token: &Token| match token.kind { token::Lt | token::BinOp(token::Shl) | token::OpenDelim(token::Paren) | token::LArrow => true, _ => false, @@ -2822,7 +2822,7 @@ impl<'a> Parser<'a> { LhsExpr::AttributesParsed(attrs) => Some(attrs), _ => None, }; - if [token::DotDot, token::DotDotDot, token::DotDotEq].contains(&self.token) { + if [token::DotDot, token::DotDotDot, token::DotDotEq].contains(&self.token.kind) { return self.parse_prefix_range_expr(attrs); } else { self.parse_prefix_expr(attrs)? @@ -3099,7 +3099,7 @@ impl<'a> Parser<'a> { self.err_dotdotdot_syntax(self.token.span); } - debug_assert!([token::DotDot, token::DotDotDot, token::DotDotEq].contains(&self.token), + debug_assert!([token::DotDot, token::DotDotDot, token::DotDotEq].contains(&self.token.kind), "parse_prefix_range_expr: token {:?} is not DotDot/DotDotEq", self.token); let tok = self.token.clone(); @@ -7867,7 +7867,7 @@ pub fn emit_unclosed_delims(unclosed_delims: &mut Vec, handler: for unmatched in unclosed_delims.iter() { let mut err = handler.struct_span_err(unmatched.found_span, &format!( "incorrect close delimiter: `{}`", - pprust::token_to_string(&token::CloseDelim(unmatched.found_delim)), + pprust::token_kind_to_string(&token::CloseDelim(unmatched.found_delim)), )); err.span_label(unmatched.found_span, "incorrect close delimiter"); if let Some(sp) = unmatched.candidate_span { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 0ece5b57935e5..9b845ca524e8b 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -17,7 +17,6 @@ use log::info; use std::fmt; use std::mem; -use std::ops::Deref; #[cfg(target_arch = "x86_64")] use rustc_data_structures::static_assert_size; use rustc_data_structures::sync::Lrc; @@ -553,11 +552,11 @@ impl TokenKind { impl Token { // See comments in `Nonterminal::to_tokenstream` for why we care about // *probably* equal here rather than actual equality - crate fn probably_equal_for_proc_macro(&self, other: &TokenKind) -> bool { - if mem::discriminant(&self.kind) != mem::discriminant(other) { + crate fn probably_equal_for_proc_macro(&self, other: &Token) -> bool { + if mem::discriminant(&self.kind) != mem::discriminant(&other.kind) { return false } - match (&self.kind, other) { + match (&self.kind, &other.kind) { (&Eq, &Eq) | (&Lt, &Lt) | (&Le, &Le) | @@ -631,14 +630,6 @@ impl PartialEq for Token { } } -// FIXME: Remove this after all necessary methods are moved from `TokenKind` to `Token`. -impl Deref for Token { - type Target = TokenKind; - fn deref(&self) -> &Self::Target { - &self.kind - } -} - #[derive(Clone, RustcEncodable, RustcDecodable)] /// For interpolation during macro expansion. pub enum Nonterminal { @@ -778,12 +769,14 @@ impl Nonterminal { } } -crate fn is_op(tok: &TokenKind) -> bool { - match *tok { - OpenDelim(..) | CloseDelim(..) | Literal(..) | DocComment(..) | - Ident(..) | Lifetime(..) | Interpolated(..) | - Whitespace | Comment | Shebang(..) | Eof => false, - _ => true, +impl Token { + crate fn is_op(&self) -> bool { + match self.kind { + OpenDelim(..) | CloseDelim(..) | Literal(..) | DocComment(..) | + Ident(..) | Lifetime(..) | Interpolated(..) | + Whitespace | Comment | Shebang(..) | Eof => false, + _ => true, + } } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d922e1896cc9c..4cbe590d44bfe 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -6,7 +6,7 @@ use crate::ast::{Attribute, MacDelimiter, GenericArg}; use crate::util::parser::{self, AssocOp, Fixity}; use crate::attr; use crate::source_map::{self, SourceMap, Spanned}; -use crate::parse::token::{self, BinOpToken, Nonterminal, TokenKind}; +use crate::parse::token::{self, BinOpToken, Nonterminal, Token, TokenKind}; use crate::parse::lexer::comments; use crate::parse::{self, ParseSess}; use crate::print::pp::{self, Breaks}; @@ -189,7 +189,7 @@ pub fn literal_to_string(lit: token::Lit) -> String { out } -pub fn token_to_string(tok: &TokenKind) -> String { +pub fn token_kind_to_string(tok: &TokenKind) -> String { match *tok { token::Eq => "=".to_string(), token::Lt => "<".to_string(), @@ -250,6 +250,10 @@ pub fn token_to_string(tok: &TokenKind) -> String { } } +pub fn token_to_string(token: &Token) -> String { + token_kind_to_string(&token.kind) +} + pub fn nonterminal_to_string(nt: &Nonterminal) -> String { match *nt { token::NtExpr(ref e) => expr_to_string(e), @@ -734,11 +738,11 @@ pub trait PrintState<'a> { } } TokenTree::Delimited(_, delim, tts) => { - self.writer().word(token_to_string(&token::OpenDelim(delim)))?; + self.writer().word(token_kind_to_string(&token::OpenDelim(delim)))?; self.writer().space()?; self.print_tts(tts)?; self.writer().space()?; - self.writer().word(token_to_string(&token::CloseDelim(delim))) + self.writer().word(token_kind_to_string(&token::CloseDelim(delim))) }, } } diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index d46d2f549c09b..2daec9702798f 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -126,14 +126,6 @@ impl TokenTree { } } - /// Indicates if the stream is a token that is equal to the provided token. - pub fn eq_token(&self, t: TokenKind) -> bool { - match self { - TokenTree::Token(token) => *token == t, - _ => false, - } - } - pub fn joint(self) -> TokenStream { TokenStream::new(vec![(self, Joint)]) } From 9aaa7c770c976e35b1614f1f6bf120204c5727c8 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 8 Jun 2019 22:38:39 +0300 Subject: [PATCH 09/16] syntax: Move some `Token` methods around --- src/libsyntax/parse/token.rs | 88 ++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 48 deletions(-) diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 9b845ca524e8b..cc34883e2e815 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -240,12 +240,51 @@ pub struct Token { pub span: Span, } +impl TokenKind { + pub fn lit(kind: LitKind, symbol: Symbol, suffix: Option) -> TokenKind { + Literal(Lit::new(kind, symbol, suffix)) + } + + /// Returns tokens that are likely to be typed accidentally instead of the current token. + /// Enables better error recovery when the wrong token is found. + crate fn similar_tokens(&self) -> Option> { + match *self { + Comma => Some(vec![Dot, Lt, Semi]), + Semi => Some(vec![Colon, Comma]), + _ => None + } + } +} + impl Token { + crate fn new(kind: TokenKind, span: Span) -> Self { + Token { kind, span } + } + + /// Some token that will be thrown away later. + crate fn dummy() -> Self { + Token::new(TokenKind::Whitespace, DUMMY_SP) + } + /// Recovers a `Token` from an `ast::Ident`. This creates a raw identifier if necessary. - crate fn from_ast_ident(ident: ast::Ident) -> Token { + crate fn from_ast_ident(ident: ast::Ident) -> Self { Token::new(Ident(ident.name, ident.is_raw_guess()), ident.span) } + /// Return this token by value and leave a dummy token in its place. + crate fn take(&mut self) -> Self { + mem::replace(self, Token::dummy()) + } + + crate fn is_op(&self) -> bool { + match self.kind { + OpenDelim(..) | CloseDelim(..) | Literal(..) | DocComment(..) | + Ident(..) | Lifetime(..) | Interpolated(..) | + Whitespace | Comment | Shebang(..) | Eof => false, + _ => true, + } + } + crate fn is_like_plus(&self) -> bool { match self.kind { BinOp(Plus) | BinOpEq(Plus) => true, @@ -327,15 +366,7 @@ impl Token { self.is_path_start() || self.is_lifetime() || self.is_keyword(kw::For) || self == &Question || self == &OpenDelim(Paren) } -} - -impl TokenKind { - pub fn lit(kind: LitKind, symbol: Symbol, suffix: Option) -> TokenKind { - Literal(Lit::new(kind, symbol, suffix)) - } -} -impl Token { /// Returns `true` if the token is any literal crate fn is_lit(&self) -> bool { match self.kind { @@ -535,21 +566,7 @@ impl Token { Some(Token::new(kind, self.span.to(joint.span))) } -} - -impl TokenKind { - /// Returns tokens that are likely to be typed accidentally instead of the current token. - /// Enables better error recovery when the wrong token is found. - crate fn similar_tokens(&self) -> Option> { - match *self { - Comma => Some(vec![Dot, Lt, Semi]), - Semi => Some(vec![Colon, Comma]), - _ => None - } - } -} -impl Token { // See comments in `Nonterminal::to_tokenstream` for why we care about // *probably* equal here rather than actual equality crate fn probably_equal_for_proc_macro(&self, other: &Token) -> bool { @@ -608,20 +625,6 @@ impl Token { _ => panic!("forgot to add a token?"), } } - - crate fn new(kind: TokenKind, span: Span) -> Self { - Token { kind, span } - } - - /// Some token that will be thrown away later. - crate fn dummy() -> Self { - Token::new(TokenKind::Whitespace, DUMMY_SP) - } - - /// Return this token by value and leave a dummy token in its place. - crate fn take(&mut self) -> Self { - mem::replace(self, Token::dummy()) - } } impl PartialEq for Token { @@ -769,17 +772,6 @@ impl Nonterminal { } } -impl Token { - crate fn is_op(&self) -> bool { - match self.kind { - OpenDelim(..) | CloseDelim(..) | Literal(..) | DocComment(..) | - Ident(..) | Lifetime(..) | Interpolated(..) | - Whitespace | Comment | Shebang(..) | Eof => false, - _ => true, - } - } -} - fn prepend_attrs(sess: &ParseSess, attrs: &[ast::Attribute], tokens: Option<&tokenstream::TokenStream>, From 31dc27da91b5cbaee258ee07fff82d5292e35965 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Sat, 8 Jun 2019 22:15:22 +0200 Subject: [PATCH 10/16] Update RLS --- Cargo.lock | 22 +++++++++++----------- src/tools/rls | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 719321574435a..7f35b7344dfed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1277,7 +1277,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "jsonrpc-core" -version = "10.0.1" +version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1407,7 +1407,7 @@ dependencies = [ [[package]] name = "lsp-types" -version = "0.57.0" +version = "0.57.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2266,7 +2266,7 @@ name = "rls" version = "1.36.0" dependencies = [ "cargo 0.38.0", - "cargo_metadata 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cargo_metadata 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "clippy_lints 0.0.212", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2276,11 +2276,11 @@ dependencies = [ "heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "home 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lsp-codec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lsp-types 0.57.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lsp-types 0.57.2 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ordslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "racer 2.1.22 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2295,7 +2295,7 @@ dependencies = [ "rls-vfs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-workspace-hack 1.0.0", - "rustc_tools_util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_tools_util 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustfmt-nightly 1.2.2", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3030,12 +3030,12 @@ dependencies = [ [[package]] name = "rustc_tools_util" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.2.0" [[package]] name = "rustc_tools_util" version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rustc_traits" @@ -4229,7 +4229,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum jemalloc-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7bef0d4ce37578dfd80b466e3d8324bd9de788e249f1accebb0c472ea4b52bdc" "checksum jobserver 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b3d51e24009d966c8285d524dbaf6d60926636b2a89caee9ce0bd612494ddc16" "checksum json 0.11.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9ad0485404155f45cce53a40d4b2d6ac356418300daed05273d9e26f91c390be" -"checksum jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a5152c3fda235dfd68341b3edf4121bc4428642c93acbd6de88c26bf95fc5d7" +"checksum jsonrpc-core 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "288dca7f9713710a29e485076b9340156cb701edb46a881f5d0c31aa4f5b9143" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" @@ -4243,7 +4243,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum log_settings 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19af41f0565d7c19b2058153ad0b42d4d5ce89ec4dbf06ed6741114a8b63e7cd" "checksum lsp-codec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "169d737ad89cf8ddd82d1804d9122f54568c49377665157277cc90d747b1d31a" -"checksum lsp-types 0.57.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d220de1fbbb12b60df17898272579c22329375fc4baa960402fbd17cf0cdd165" +"checksum lsp-types 0.57.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b62b77309737b1e262b3bbf37ff8faa740562c633b14702afe9be85dbcb6f88a" "checksum lzma-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d1eaa027402541975218bb0eec67d6b0412f6233af96e0d096d31dbdfd22e614" "checksum mac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" "checksum macro-utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2c4deaccc2ead6a28c16c0ba82f07d52b6475397415ce40876e559b0b0ea510" @@ -4350,7 +4350,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc-rayon-core 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "526e7b6d2707a5b9bec3927d424ad70fa3cfc68e0ac1b75e46cdbbc95adc5108" "checksum rustc-rayon-core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "79d38ca7cbc22fa59f09d8534ea4b27f67b0facf0cbe274433aceea227a02543" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" -"checksum rustc_tools_util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c5a95edfa0c893236ae4778bb7c4752760e4c0d245e19b5eff33c5aa5eb9dc" +"checksum rustc_tools_util 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b725dadae9fabc488df69a287f5a99c5eaf5d10853842a8a3dfac52476f544ee" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustfix 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "af7c21531a91512a4a51b490be6ba1c8eff34fdda0dc5bf87dc28d86748aac56" "checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c" diff --git a/src/tools/rls b/src/tools/rls index 9692ca8fd82a8..d1e20280dc188 160000 --- a/src/tools/rls +++ b/src/tools/rls @@ -1 +1 @@ -Subproject commit 9692ca8fd82a8f96a4113dc4b88c1fb1d79c1c60 +Subproject commit d1e20280dc188f542c083a738f8da3fef25af478 From 8049e6199bad86d3148c94463216cc745db2d796 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 8 Jun 2019 11:35:30 +0300 Subject: [PATCH 11/16] Remove unused `#![feature(custom_attribute)]`s --- src/libcore/lib.rs | 1 - src/librustc_codegen_llvm/lib.rs | 1 - src/librustc_codegen_ssa/lib.rs | 1 - src/librustc_codegen_utils/lib.rs | 1 - src/librustc_errors/lib.rs | 1 - src/librustc_save_analysis/lib.rs | 1 - src/libsyntax_pos/lib.rs | 1 - src/libterm/lib.rs | 3 --- src/test/run-pass/check-static-recursion-foreign.rs | 2 +- src/test/run-pass/macros/macro-attributes.rs | 1 - src/test/ui/attr-eq-token-tree.rs | 2 -- src/test/ui/attr-eq-token-tree.stderr | 2 +- src/test/ui/custom-attribute-multisegment.rs | 2 -- src/test/ui/custom-attribute-multisegment.stderr | 2 +- src/test/ui/expanded-cfg.rs | 2 +- 15 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index af24cbe1c5c48..030f4f1d12cc8 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -75,7 +75,6 @@ #![feature(concat_idents)] #![feature(const_fn)] #![feature(const_fn_union)] -#![feature(custom_attribute)] #![feature(doc_cfg)] #![feature(doc_spotlight)] #![feature(extern_types)] diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 0fdd326a1882e..8391f02fc69ec 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -10,7 +10,6 @@ #![feature(box_syntax)] #![feature(const_cstr_unchecked)] #![feature(crate_visibility_modifier)] -#![feature(custom_attribute)] #![feature(extern_types)] #![feature(in_band_lifetimes)] #![allow(unused_attributes)] diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index 4d7af7a643b66..97de0d823b322 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -3,7 +3,6 @@ #![feature(box_patterns)] #![feature(box_syntax)] #![feature(core_intrinsics)] -#![feature(custom_attribute)] #![feature(libc)] #![feature(rustc_diagnostic_macros)] #![feature(stmt_expr_attributes)] diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs index ea1d08354528b..38d1719e7763e 100644 --- a/src/librustc_codegen_utils/lib.rs +++ b/src/librustc_codegen_utils/lib.rs @@ -8,7 +8,6 @@ #![feature(box_patterns)] #![feature(box_syntax)] #![feature(core_intrinsics)] -#![feature(custom_attribute)] #![feature(never_type)] #![feature(nll)] #![allow(unused_attributes)] diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 1831d58e73607..cc3180c783bdf 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -1,6 +1,5 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] -#![feature(custom_attribute)] #![allow(unused_attributes)] #![cfg_attr(unix, feature(libc))] #![feature(nll)] diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index cca5682d90a9b..a695a90f2ae64 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -1,5 +1,4 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] -#![feature(custom_attribute)] #![feature(nll)] #![deny(rust_2018_idioms)] #![deny(internal)] diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 24aa82184ced5..8f5595968a738 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -11,7 +11,6 @@ #![feature(const_fn)] #![feature(crate_visibility_modifier)] -#![feature(custom_attribute)] #![feature(nll)] #![feature(non_exhaustive)] #![feature(optin_builtin_traits)] diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 711716d9b926c..3b5ac7baf20bd 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -38,9 +38,6 @@ #![deny(rust_2018_idioms)] #![cfg_attr(windows, feature(libc))] -// Handle rustfmt skips -#![feature(custom_attribute)] -#![allow(unused_attributes)] use std::io::prelude::*; use std::io::{self, Stdout, Stderr}; diff --git a/src/test/run-pass/check-static-recursion-foreign.rs b/src/test/run-pass/check-static-recursion-foreign.rs index c423bf666e5fb..361f8a1d3406e 100644 --- a/src/test/run-pass/check-static-recursion-foreign.rs +++ b/src/test/run-pass/check-static-recursion-foreign.rs @@ -6,7 +6,7 @@ // pretty-expanded FIXME #23616 -#![feature(custom_attribute, rustc_private)] +#![feature(rustc_private)] extern crate check_static_recursion_foreign_helper; extern crate libc; diff --git a/src/test/run-pass/macros/macro-attributes.rs b/src/test/run-pass/macros/macro-attributes.rs index 953f6be53c5d4..d382e8b719713 100644 --- a/src/test/run-pass/macros/macro-attributes.rs +++ b/src/test/run-pass/macros/macro-attributes.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(custom_attribute)] macro_rules! compiles_fine { (#[$at:meta]) => { diff --git a/src/test/ui/attr-eq-token-tree.rs b/src/test/ui/attr-eq-token-tree.rs index 6aacb9d572aea..c301492b9e21a 100644 --- a/src/test/ui/attr-eq-token-tree.rs +++ b/src/test/ui/attr-eq-token-tree.rs @@ -1,4 +1,2 @@ -#![feature(custom_attribute)] - #[my_attr = !] //~ ERROR unexpected token: `!` fn main() {} diff --git a/src/test/ui/attr-eq-token-tree.stderr b/src/test/ui/attr-eq-token-tree.stderr index 571779dfa1ae7..bb37c2e0cc473 100644 --- a/src/test/ui/attr-eq-token-tree.stderr +++ b/src/test/ui/attr-eq-token-tree.stderr @@ -1,5 +1,5 @@ error: unexpected token: `!` - --> $DIR/attr-eq-token-tree.rs:3:13 + --> $DIR/attr-eq-token-tree.rs:1:13 | LL | #[my_attr = !] | ^ diff --git a/src/test/ui/custom-attribute-multisegment.rs b/src/test/ui/custom-attribute-multisegment.rs index 95cefe53938fb..2434921390245 100644 --- a/src/test/ui/custom-attribute-multisegment.rs +++ b/src/test/ui/custom-attribute-multisegment.rs @@ -1,7 +1,5 @@ // Unresolved multi-segment attributes are not treated as custom. -#![feature(custom_attribute)] - mod existent {} #[existent::nonexistent] //~ ERROR failed to resolve: could not find `nonexistent` in `existent` diff --git a/src/test/ui/custom-attribute-multisegment.stderr b/src/test/ui/custom-attribute-multisegment.stderr index 9ba9c00e55bc8..57eca211ed10e 100644 --- a/src/test/ui/custom-attribute-multisegment.stderr +++ b/src/test/ui/custom-attribute-multisegment.stderr @@ -1,5 +1,5 @@ error[E0433]: failed to resolve: could not find `nonexistent` in `existent` - --> $DIR/custom-attribute-multisegment.rs:7:13 + --> $DIR/custom-attribute-multisegment.rs:5:13 | LL | #[existent::nonexistent] | ^^^^^^^^^^^ could not find `nonexistent` in `existent` diff --git a/src/test/ui/expanded-cfg.rs b/src/test/ui/expanded-cfg.rs index fbae093f2ac2d..c98fd7ffea8be 100644 --- a/src/test/ui/expanded-cfg.rs +++ b/src/test/ui/expanded-cfg.rs @@ -1,6 +1,6 @@ // skip-codegen // compile-pass -#![feature(custom_attribute)] + macro_rules! mac { {} => { #[cfg(attr)] From 74a6d1c821a37a407d2b2bc701d62d0b460b9215 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 8 Jun 2019 11:36:30 +0300 Subject: [PATCH 12/16] Turn `#[allocator]` into a built-in attribute and rename it to `#[rustc_allocator]` --- src/liballoc/alloc.rs | 3 +- src/liballoc/lib.rs | 2 +- src/librustc/hir/mod.rs | 2 +- src/librustc_typeck/collect.rs | 2 +- src/libsyntax/feature_gate.rs | 5 ++ src/libsyntax_pos/symbol.rs | 1 + src/test/codegen/function-arguments.rs | 4 +- .../run-pass/auxiliary/allocator-dummy.rs | 59 ------------------- 8 files changed, 13 insertions(+), 65 deletions(-) delete mode 100644 src/test/run-pass/auxiliary/allocator-dummy.rs diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs index 41ff06d70ff09..755feb8496203 100644 --- a/src/liballoc/alloc.rs +++ b/src/liballoc/alloc.rs @@ -15,7 +15,8 @@ extern "Rust" { // them from the `#[global_allocator]` attribute if there is one, or uses the // default implementations in libstd (`__rdl_alloc` etc in `src/libstd/alloc.rs`) // otherwise. - #[allocator] + #[cfg_attr(bootstrap, allocator)] + #[cfg_attr(not(bootstrap), rustc_allocator)] #[rustc_allocator_nounwind] fn __rust_alloc(size: usize, align: usize) -> *mut u8; #[rustc_allocator_nounwind] diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index bfc008e14a486..c530ac24275c2 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -79,7 +79,7 @@ #![feature(coerce_unsized)] #![feature(dispatch_from_dyn)] #![feature(core_intrinsics)] -#![feature(custom_attribute)] +#![cfg_attr(bootstrap, feature(custom_attribute))] #![feature(dropck_eyepatch)] #![feature(exact_size_is_empty)] #![feature(fmt_internals)] diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 2aaf5ec775d49..27ee664aa5f58 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2574,7 +2574,7 @@ bitflags! { /// `#[cold]`: a hint to LLVM that this function, when called, is never on /// the hot path. const COLD = 1 << 0; - /// `#[allocator]`: a hint to LLVM that the pointer returned from this + /// `#[rustc_allocator]`: a hint to LLVM that the pointer returned from this /// function is never null. const ALLOCATOR = 1 << 1; /// `#[unwind]`: an indicator that this function may unwind despite what diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 2751cd0a37ec0..f738f90b31eb6 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -2445,7 +2445,7 @@ fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> Codegen for attr in attrs.iter() { if attr.check_name(sym::cold) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD; - } else if attr.check_name(sym::allocator) { + } else if attr.check_name(sym::rustc_allocator) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR; } else if attr.check_name(sym::unwind) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::UNWIND; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index b41b91c7631f5..ac4a7271221bb 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1331,6 +1331,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ "internal implementation detail", cfg_fn!(rustc_attrs))), + (sym::rustc_allocator, Whitelisted, template!(Word), Gated(Stability::Unstable, + sym::rustc_attrs, + "internal implementation detail", + cfg_fn!(rustc_attrs))), + // FIXME: #14408 whitelist docs since rustdoc looks at them ( sym::doc, diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 49123e4cc30c2..224b85a11f91c 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -513,6 +513,7 @@ symbols! { rust_2018_preview, rust_begin_unwind, rustc, + rustc_allocator, rustc_allocator_nounwind, rustc_allow_const_fn_ptr, rustc_args_required_const, diff --git a/src/test/codegen/function-arguments.rs b/src/test/codegen/function-arguments.rs index c2d697fd046bf..bd121ef24adae 100644 --- a/src/test/codegen/function-arguments.rs +++ b/src/test/codegen/function-arguments.rs @@ -2,7 +2,7 @@ // ignore-tidy-linelength #![crate_type = "lib"] -#![feature(custom_attribute)] +#![feature(rustc_attrs)] pub struct S { _field: [i32; 8], @@ -146,7 +146,7 @@ pub fn enum_id_2(x: Option) -> Option { // CHECK: noalias i8* @allocator() #[no_mangle] -#[allocator] +#[rustc_allocator] pub fn allocator() -> *const i8 { std::ptr::null() } diff --git a/src/test/run-pass/auxiliary/allocator-dummy.rs b/src/test/run-pass/auxiliary/allocator-dummy.rs deleted file mode 100644 index bedf3020c8be0..0000000000000 --- a/src/test/run-pass/auxiliary/allocator-dummy.rs +++ /dev/null @@ -1,59 +0,0 @@ -// no-prefer-dynamic - -#![feature(allocator, core_intrinsics, panic_unwind)] -#![allocator] -#![crate_type = "rlib"] -#![no_std] - -extern crate unwind; - -pub static mut HITS: usize = 0; - -type size_t = usize; - -extern { - fn malloc(size: usize) -> *mut u8; - fn free(ptr: *mut u8); - fn calloc(size: usize, amt: usize) -> *mut u8; - fn realloc(ptr: *mut u8, size: usize) -> *mut u8; -} - -#[no_mangle] -pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 { - unsafe { - HITS += 1; - malloc(size as size_t) as *mut u8 - } -} - -#[no_mangle] -pub extern fn __rust_allocate_zeroed(size: usize, _align: usize) -> *mut u8 { - unsafe { calloc(size as size_t, 1) as *mut u8 } -} - -#[no_mangle] -pub extern fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) { - unsafe { - HITS += 1; - free(ptr as *mut _) - } -} - -#[no_mangle] -pub extern fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize, - align: usize) -> *mut u8 { - unsafe { - realloc(ptr as *mut _, size as size_t) as *mut u8 - } -} - -#[no_mangle] -pub extern fn __rust_reallocate_inplace(ptr: *mut u8, old_size: usize, - size: usize, align: usize) -> usize { - unsafe { core::intrinsics::abort() } -} - -#[no_mangle] -pub extern fn __rust_usable_size(size: usize, align: usize) -> usize { - unsafe { core::intrinsics::abort() } -} From ea4ad555d76d2eb8e6eb749e1b4c163e16077985 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 8 Jun 2019 11:36:43 +0300 Subject: [PATCH 13/16] Introduce `#[rustc_dummy]` attribute and use it in tests Unlike other built-in attributes, this attribute accepts any input --- src/libsyntax/feature_gate.rs | 15 +- src/libsyntax_pos/symbol.rs | 1 + src/test/pretty/attr-fn-inner.rs | 11 +- src/test/pretty/attr-literals.rs | 11 +- src/test/pretty/stmt_expr_attributes.rs | 279 +++++++++--------- src/test/run-pass/attr-before-view-item.rs | 11 +- src/test/run-pass/attr-before-view-item2.rs | 11 +- src/test/run-pass/attr-mix-new.rs | 11 +- src/test/run-pass/item-attributes.rs | 116 ++++---- .../run-pass/methods/method-attributes.rs | 29 +- .../structs-enums/class-attributes-1.rs | 20 +- .../structs-enums/class-attributes-2.rs | 25 +- src/test/run-pass/variant-attributes.rs | 23 +- src/test/ui/issues/issue-24434.rs | 5 +- src/test/ui/macros/macro-inner-attributes.rs | 4 +- src/test/ui/macros/macro-outer-attributes.rs | 4 +- .../ui/malformed/malformed-interpolated.rs | 6 +- .../malformed/malformed-interpolated.stderr | 12 +- src/test/ui/stmt_expr_attrs_no_feature.rs | 61 ++-- src/test/ui/stmt_expr_attrs_no_feature.stderr | 54 ++-- src/test/ui/suffixed-literal-meta.rs | 28 +- src/test/ui/suffixed-literal-meta.stderr | 72 ++--- src/test/ui/unrestricted-attribute-tokens.rs | 8 +- src/test/ui/unused/unused-attr.rs | 33 +-- src/test/ui/unused/unused-attr.stderr | 90 +++--- 25 files changed, 458 insertions(+), 482 deletions(-) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index ac4a7271221bb..7119fd13fbbfb 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1336,6 +1336,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ "internal implementation detail", cfg_fn!(rustc_attrs))), + (sym::rustc_dummy, Normal, template!(Word /* doesn't matter*/), Gated(Stability::Unstable, + sym::rustc_attrs, + "used by the test suite", + cfg_fn!(rustc_attrs))), + // FIXME: #14408 whitelist docs since rustdoc looks at them ( sym::doc, @@ -1962,12 +1967,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } match attr_info { - Some(&(name, _, template, _)) => self.check_builtin_attribute( - attr, - name, - template - ), - None => if let Some(TokenTree::Token(token)) = attr.tokens.trees().next() { + // `rustc_dummy` doesn't have any restrictions specific to built-in attributes. + Some(&(name, _, template, _)) if name != sym::rustc_dummy => + self.check_builtin_attribute(attr, name, template), + _ => if let Some(TokenTree::Token(token)) = attr.tokens.trees().next() { if token == token::Eq { // All key-value attributes are restricted to meta-item syntax. attr.parse_meta(self.context.parse_sess).map_err(|mut err| err.emit()).ok(); diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 224b85a11f91c..302b3c75263cf 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -527,6 +527,7 @@ symbols! { rustc_diagnostic_macros, rustc_dirty, rustc_doc_only_macro, + rustc_dummy, rustc_dump_env_program_clauses, rustc_dump_program_clauses, rustc_dump_user_substs, diff --git a/src/test/pretty/attr-fn-inner.rs b/src/test/pretty/attr-fn-inner.rs index f13339e334c6e..0a745e7d34fc1 100644 --- a/src/test/pretty/attr-fn-inner.rs +++ b/src/test/pretty/attr-fn-inner.rs @@ -1,15 +1,16 @@ -// pp-exact // Testing that both the inner item and next outer item are // preserved, and that the first outer item parsed in main is not // accidentally carried over to each inner function -#![feature(custom_attribute)] +// pp-exact + +#![feature(rustc_attrs)] fn main() { - #![inner_attr] - #[outer_attr] + #![rustc_dummy] + #[rustc_dummy] fn f() { } - #[outer_attr] + #[rustc_dummy] fn g() { } } diff --git a/src/test/pretty/attr-literals.rs b/src/test/pretty/attr-literals.rs index 355f3d5a3cfb8..44d2c5db3e668 100644 --- a/src/test/pretty/attr-literals.rs +++ b/src/test/pretty/attr-literals.rs @@ -1,13 +1,14 @@ -// pp-exact // Tests literals in attributes. -#![feature(custom_attribute)] +// pp-exact + +#![feature(rustc_attrs)] fn main() { - #![hello("hi", 1, 2, 1.012, pi = 3.14, bye, name("John"))] - #[align = 8] + #![rustc_dummy("hi", 1, 2, 1.012, pi = 3.14, bye, name("John"))] + #[rustc_dummy = 8] fn f() { } - #[vector(1, 2, 3)] + #[rustc_dummy(1, 2, 3)] fn g() { } } diff --git a/src/test/pretty/stmt_expr_attributes.rs b/src/test/pretty/stmt_expr_attributes.rs index eb1768683e6e9..d81485b555fa6 100644 --- a/src/test/pretty/stmt_expr_attributes.rs +++ b/src/test/pretty/stmt_expr_attributes.rs @@ -1,20 +1,20 @@ // pp-exact -#![feature(custom_attribute)] #![feature(box_syntax)] +#![feature(rustc_attrs)] #![feature(stmt_expr_attributes)] fn main() { } fn _0() { - #[attr] + #[rustc_dummy] foo(); } fn _1() { - #[attr] + #[rustc_dummy] unsafe { // code } @@ -22,11 +22,11 @@ fn _1() { fn _2() { - #[attr] + #[rustc_dummy] { foo(); } { - #![attr] + #![rustc_dummy] foo() } @@ -34,51 +34,51 @@ fn _2() { fn _3() { - #[attr] + #[rustc_dummy] match () { _ => { } } } fn _4() { - #[attr] + #[rustc_dummy] match () { - #![attr] + #![rustc_dummy] _ => (), } let _ = - #[attr] match () { - #![attr] - () => (), - }; + #[rustc_dummy] match () { + #![rustc_dummy] + () => (), + }; } fn _5() { - #[attr] + #[rustc_dummy] let x = 1; - let x = #[attr] 1; + let x = #[rustc_dummy] 1; let y = (); let z = (); - foo3(x, #[attr] y, z); + foo3(x, #[rustc_dummy] y, z); - qux(3 + #[attr] 2); + qux(3 + #[rustc_dummy] 2); } fn _6() { - #[attr] - [#![attr] 1, 2, 3]; + #[rustc_dummy] + [#![rustc_dummy] 1, 2, 3]; - let _ = #[attr] [#![attr] 1, 2, 3]; + let _ = #[rustc_dummy] [#![rustc_dummy] 1, 2, 3]; - #[attr] - [#![attr] 1; 4]; + #[rustc_dummy] + [#![rustc_dummy] 1; 4]; - let _ = #[attr] [#![attr] 1; 4]; + let _ = #[rustc_dummy] [#![rustc_dummy] 1; 4]; } struct Foo { @@ -89,45 +89,41 @@ struct Bar(()); fn _7() { - #[attr] - Foo{#![attr] data: (),}; + #[rustc_dummy] + Foo{#![rustc_dummy] data: (),}; - let _ = #[attr] Foo{#![attr] data: (),}; + let _ = #[rustc_dummy] Foo{#![rustc_dummy] data: (),}; } fn _8() { - #[attr] - (#![attr] ); + #[rustc_dummy] + (#![rustc_dummy] ); - #[attr] - (#![attr] 0); + #[rustc_dummy] + (#![rustc_dummy] 0); - #[attr] - (#![attr] 0,); + #[rustc_dummy] + (#![rustc_dummy] 0,); - #[attr] - (#![attr] 0, 1); + #[rustc_dummy] + (#![rustc_dummy] 0, 1); } fn _9() { macro_rules! stmt_mac(( ) => { let _ = ( ) ; }); - #[attr] + #[rustc_dummy] stmt_mac!(); - /* - // pre existing pp bug: delimiter styles gets lost: - - #[attr] + #[rustc_dummy] stmt_mac!{ }; - #[attr] + #[rustc_dummy] stmt_mac![]; - #[attr] - stmt_mac!{ } // pre-existing pp bug: compiler ICEs with a None unwrap - */ + #[rustc_dummy] + stmt_mac!{ } let _ = (); } @@ -135,138 +131,131 @@ fn _9() { macro_rules! expr_mac(( ) => { ( ) }); fn _10() { - - let _ = #[attr] expr_mac!(); - - /* - // pre existing pp bug: delimiter styles gets lost: - let _ = #[attr] expr_mac![]; - let _ = #[attr] expr_mac!{}; - */ + let _ = #[rustc_dummy] expr_mac!(); + let _ = #[rustc_dummy] expr_mac![]; + let _ = #[rustc_dummy] expr_mac!{ }; } fn _11() { - let _ = #[attr] box 0; - let _: [(); 0] = #[attr] [#![attr] ]; - let _ = #[attr] [#![attr] 0, 0]; - let _ = #[attr] [#![attr] 0; 0]; - let _ = #[attr] foo(); - let _ = #[attr] 1i32.clone(); - let _ = #[attr] (#![attr] ); - let _ = #[attr] (#![attr] 0); - let _ = #[attr] (#![attr] 0,); - let _ = #[attr] (#![attr] 0, 0); - let _ = #[attr] 0 + #[attr] 0; - let _ = #[attr] !0; - let _ = #[attr] -0i32; - let _ = #[attr] false; - let _ = #[attr] 'c'; - let _ = #[attr] 0; - let _ = #[attr] 0 as usize; + let _ = #[rustc_dummy] box 0; + let _: [(); 0] = #[rustc_dummy] [#![rustc_dummy] ]; + let _ = #[rustc_dummy] [#![rustc_dummy] 0, 0]; + let _ = #[rustc_dummy] [#![rustc_dummy] 0; 0]; + let _ = #[rustc_dummy] foo(); + let _ = #[rustc_dummy] 1i32.clone(); + let _ = #[rustc_dummy] (#![rustc_dummy] ); + let _ = #[rustc_dummy] (#![rustc_dummy] 0); + let _ = #[rustc_dummy] (#![rustc_dummy] 0,); + let _ = #[rustc_dummy] (#![rustc_dummy] 0, 0); + let _ = #[rustc_dummy] 0 + #[rustc_dummy] 0; + let _ = #[rustc_dummy] !0; + let _ = #[rustc_dummy] -0i32; + let _ = #[rustc_dummy] false; + let _ = #[rustc_dummy] 'c'; + let _ = #[rustc_dummy] 0; + let _ = #[rustc_dummy] 0 as usize; let _ = - #[attr] while false { - #![attr] - }; + #[rustc_dummy] while false { + #![rustc_dummy] + }; let _ = - #[attr] while let None = Some(()) { - #![attr] - }; + #[rustc_dummy] while let None = Some(()) { + #![rustc_dummy] + }; let _ = - #[attr] for _ in 0..0 { - #![attr] - }; + #[rustc_dummy] for _ in 0..0 { + #![rustc_dummy] + }; // FIXME: pp bug, two spaces after the loop let _ = - #[attr] loop { - #![attr] - }; + #[rustc_dummy] loop { + #![rustc_dummy] + }; let _ = - #[attr] match false { - #![attr] - _ => (), - }; - let _ = #[attr] || #[attr] (); - let _ = #[attr] move || #[attr] (); + #[rustc_dummy] match false { + #![rustc_dummy] + _ => (), + }; + let _ = #[rustc_dummy] || #[rustc_dummy] (); + let _ = #[rustc_dummy] move || #[rustc_dummy] (); let _ = - #[attr] || - { - #![attr] - #[attr] - () - }; + #[rustc_dummy] || + { + #![rustc_dummy] + #[rustc_dummy] + () + }; let _ = - #[attr] move || - { - #![attr] - #[attr] - () - }; + #[rustc_dummy] move || + { + #![rustc_dummy] + #[rustc_dummy] + () + }; let _ = - #[attr] { - #![attr] - }; + #[rustc_dummy] { + #![rustc_dummy] + }; let _ = - #[attr] { - #![attr] - let _ = (); - }; + #[rustc_dummy] { + #![rustc_dummy] + let _ = (); + }; let _ = - #[attr] { - #![attr] - let _ = (); - () - }; + #[rustc_dummy] { + #![rustc_dummy] + let _ = (); + () + }; let mut x = 0; - let _ = #[attr] x = 15; - let _ = #[attr] x += 15; + let _ = #[rustc_dummy] x = 15; + let _ = #[rustc_dummy] x += 15; let s = Foo{data: (),}; - let _ = #[attr] s.data; - let _ = (#[attr] s).data; + let _ = #[rustc_dummy] s.data; + let _ = (#[rustc_dummy] s).data; let t = Bar(()); - let _ = #[attr] t.0; - let _ = (#[attr] t).0; + let _ = #[rustc_dummy] t.0; + let _ = (#[rustc_dummy] t).0; let v = vec!(0); - let _ = #[attr] v[0]; - let _ = (#[attr] v)[0]; - let _ = #[attr] 0..#[attr] 0; - let _ = #[attr] 0..; - let _ = #[attr] (0..0); - let _ = #[attr] (0..); - let _ = #[attr] (..0); - let _ = #[attr] (..); - let _: fn(&u32) -> u32 = #[attr] std::clone::Clone::clone; - let _ = #[attr] &0; - let _ = #[attr] &mut 0; - let _ = #[attr] &#[attr] 0; - let _ = #[attr] &mut #[attr] 0; + let _ = #[rustc_dummy] v[0]; + let _ = (#[rustc_dummy] v)[0]; + let _ = #[rustc_dummy] 0..#[rustc_dummy] 0; + let _ = #[rustc_dummy] 0..; + let _ = #[rustc_dummy] (0..0); + let _ = #[rustc_dummy] (0..); + let _ = #[rustc_dummy] (..0); + let _ = #[rustc_dummy] (..); + let _: fn(&u32) -> u32 = #[rustc_dummy] std::clone::Clone::clone; + let _ = #[rustc_dummy] &0; + let _ = #[rustc_dummy] &mut 0; + let _ = #[rustc_dummy] &#[rustc_dummy] 0; + let _ = #[rustc_dummy] &mut #[rustc_dummy] 0; // FIXME: pp bug, extra space after keyword? - while false { let _ = #[attr] continue ; } - while true { let _ = #[attr] break ; } - || #[attr] return; - let _ = #[attr] expr_mac!(); - /* FIXME: pp bug, losing delimiter styles - let _ = #[attr] expr_mac![]; - let _ = #[attr] expr_mac!{}; - */ - let _ = #[attr] Foo{#![attr] data: (),}; - let _ = #[attr] Foo{#![attr] ..s}; - let _ = #[attr] Foo{#![attr] data: (), ..s}; - let _ = #[attr] (#![attr] 0); + while false { let _ = #[rustc_dummy] continue ; } + while true { let _ = #[rustc_dummy] break ; } + || #[rustc_dummy] return; + let _ = #[rustc_dummy] expr_mac!(); + let _ = #[rustc_dummy] expr_mac![]; + let _ = #[rustc_dummy] expr_mac!{ }; + let _ = #[rustc_dummy] Foo{#![rustc_dummy] data: (),}; + let _ = #[rustc_dummy] Foo{#![rustc_dummy] ..s}; + let _ = #[rustc_dummy] Foo{#![rustc_dummy] data: (), ..s}; + let _ = #[rustc_dummy] (#![rustc_dummy] 0); } fn _12() { - #[attr] + #[rustc_dummy] let _ = 0; - #[attr] + #[rustc_dummy] 0; - #[attr] + #[rustc_dummy] expr_mac!(); - #[attr] + #[rustc_dummy] { - #![attr] + #![rustc_dummy] } } diff --git a/src/test/run-pass/attr-before-view-item.rs b/src/test/run-pass/attr-before-view-item.rs index 14b4189684f9c..3aa2ee77ee51c 100644 --- a/src/test/run-pass/attr-before-view-item.rs +++ b/src/test/run-pass/attr-before-view-item.rs @@ -1,11 +1,10 @@ -#![allow(unused_attributes)] - // pretty-expanded FIXME #23616 -#![feature(custom_attribute, test)] +#![allow(unused)] +#![feature(rustc_attrs)] +#![feature(test)] -#[foo = "bar"] +#[rustc_dummy = "bar"] extern crate test; -pub fn main() { -} +fn main() {} diff --git a/src/test/run-pass/attr-before-view-item2.rs b/src/test/run-pass/attr-before-view-item2.rs index 6fc1e35d47ac5..2b3a09b5e6fd5 100644 --- a/src/test/run-pass/attr-before-view-item2.rs +++ b/src/test/run-pass/attr-before-view-item2.rs @@ -1,13 +1,12 @@ -#![allow(unused_attributes)] - // pretty-expanded FIXME #23616 -#![feature(custom_attribute, test)] +#![allow(unused)] +#![feature(rustc_attrs)] +#![feature(test)] mod m { - #[foo = "bar"] + #[rustc_dummy = "bar"] extern crate test; } -pub fn main() { -} +fn main() {} diff --git a/src/test/run-pass/attr-mix-new.rs b/src/test/run-pass/attr-mix-new.rs index 223a434dbb9e7..ca53bfacf9191 100644 --- a/src/test/run-pass/attr-mix-new.rs +++ b/src/test/run-pass/attr-mix-new.rs @@ -1,14 +1,11 @@ -#![allow(unused_attributes)] -#![allow(unknown_lints)] - // pretty-expanded FIXME #23616 -#![allow(unused_attribute)] -#![feature(custom_attribute)] +#![allow(unused)] +#![feature(rustc_attrs)] -#[foo(bar)] +#[rustc_dummy(bar)] mod foo { #![feature(globs)] } -pub fn main() {} +fn main() {} diff --git a/src/test/run-pass/item-attributes.rs b/src/test/run-pass/item-attributes.rs index e3ed350f29a94..1801fa05f85c9 100644 --- a/src/test/run-pass/item-attributes.rs +++ b/src/test/run-pass/item-attributes.rs @@ -1,80 +1,76 @@ -#![allow(non_camel_case_types)] -#![allow(non_upper_case_globals)] -#![allow(unused_attributes)] -#![allow(dead_code)] -#![allow(unknown_lints)] // These are attributes of the implicit crate. Really this just needs to parse // for completeness since .rs files linked from .rc files support this // notation to specify their module's attributes -#![feature(custom_attribute)] -#![allow(unused_attribute)] -#![attr1 = "val"] -#![attr2 = "val"] -#![attr3] -#![attr4(attr5)] +#![allow(unused)] +#![feature(rustc_attrs)] + +#![rustc_dummy = "val"] +#![rustc_dummy = "val"] +#![rustc_dummy] +#![rustc_dummy(attr5)] #![crate_id="foobar#0.1"] // These are attributes of the following mod -#[attr1 = "val"] -#[attr2 = "val"] +#[rustc_dummy = "val"] +#[rustc_dummy = "val"] mod test_first_item_in_file_mod {} mod test_single_attr_outer { - #[attr = "val"] - pub static x: isize = 10; + #[rustc_dummy = "val"] + pub static X: isize = 10; - #[attr = "val"] + #[rustc_dummy = "val"] pub fn f() { } - #[attr = "val"] + #[rustc_dummy = "val"] pub mod mod1 {} pub mod rustrt { - #[attr = "val"] + #[rustc_dummy = "val"] extern {} } } mod test_multi_attr_outer { - #[attr1 = "val"] - #[attr2 = "val"] - pub static x: isize = 10; + #[rustc_dummy = "val"] + #[rustc_dummy = "val"] + pub static X: isize = 10; - #[attr1 = "val"] - #[attr2 = "val"] + #[rustc_dummy = "val"] + #[rustc_dummy = "val"] pub fn f() { } - #[attr1 = "val"] - #[attr2 = "val"] + #[rustc_dummy = "val"] + #[rustc_dummy = "val"] pub mod mod1 {} pub mod rustrt { - #[attr1 = "val"] - #[attr2 = "val"] + #[rustc_dummy = "val"] + #[rustc_dummy = "val"] extern {} } - #[attr1 = "val"] - #[attr2 = "val"] - struct t {x: isize} + #[rustc_dummy = "val"] + #[rustc_dummy = "val"] + struct T {x: isize} } mod test_stmt_single_attr_outer { pub fn f() { - #[attr = "val"] - static x: isize = 10; + #[rustc_dummy = "val"] + static X: isize = 10; - #[attr = "val"] + #[rustc_dummy = "val"] fn f() { } - #[attr = "val"] + #[rustc_dummy = "val"] mod mod1 { } mod rustrt { - #[attr = "val"] + #[rustc_dummy = "val"] extern { } } @@ -84,22 +80,22 @@ mod test_stmt_single_attr_outer { mod test_stmt_multi_attr_outer { pub fn f() { - #[attr1 = "val"] - #[attr2 = "val"] - static x: isize = 10; + #[rustc_dummy = "val"] + #[rustc_dummy = "val"] + static X: isize = 10; - #[attr1 = "val"] - #[attr2 = "val"] + #[rustc_dummy = "val"] + #[rustc_dummy = "val"] fn f() { } - #[attr1 = "val"] - #[attr2 = "val"] + #[rustc_dummy = "val"] + #[rustc_dummy = "val"] mod mod1 { } mod rustrt { - #[attr1 = "val"] - #[attr2 = "val"] + #[rustc_dummy = "val"] + #[rustc_dummy = "val"] extern { } } @@ -109,16 +105,16 @@ mod test_stmt_multi_attr_outer { mod test_attr_inner { pub mod m { // This is an attribute of mod m - #![attr = "val"] + #![rustc_dummy = "val"] } } mod test_attr_inner_then_outer { pub mod m { // This is an attribute of mod m - #![attr = "val"] + #![rustc_dummy = "val"] // This is an attribute of fn f - #[attr = "val"] + #[rustc_dummy = "val"] fn f() { } } } @@ -126,11 +122,11 @@ mod test_attr_inner_then_outer { mod test_attr_inner_then_outer_multi { pub mod m { // This is an attribute of mod m - #![attr1 = "val"] - #![attr2 = "val"] + #![rustc_dummy = "val"] + #![rustc_dummy = "val"] // This is an attribute of fn f - #[attr1 = "val"] - #[attr2 = "val"] + #[rustc_dummy = "val"] + #[rustc_dummy = "val"] fn f() { } } } @@ -138,25 +134,25 @@ mod test_attr_inner_then_outer_multi { mod test_distinguish_syntax_ext { pub fn f() { format!("test{}", "s"); - #[attr = "val"] + #[rustc_dummy = "val"] fn g() { } } } mod test_other_forms { - #[attr] - #[attr(word)] - #[attr(attr(word))] - #[attr(key1 = "val", key2 = "val", attr)] + #[rustc_dummy] + #[rustc_dummy(word)] + #[rustc_dummy(attr(word))] + #[rustc_dummy(key1 = "val", key2 = "val", attr)] pub fn f() { } } mod test_foreign_items { pub mod rustrt { extern { - #![attr] + #![rustc_dummy] - #[attr] + #[rustc_dummy] fn rust_get_test_int() -> u32; } } @@ -178,7 +174,7 @@ mod test_foreign_items { }*/ fn test_fn_inner() { - #![inner_fn_attr] + #![rustc_dummy] } -pub fn main() { } +fn main() {} diff --git a/src/test/run-pass/methods/method-attributes.rs b/src/test/run-pass/methods/method-attributes.rs index c7d8b3b1403ab..8a4ce49ffb6c4 100644 --- a/src/test/run-pass/methods/method-attributes.rs +++ b/src/test/run-pass/methods/method-attributes.rs @@ -1,31 +1,28 @@ -// run-pass -#![allow(unused_attributes)] -#![allow(non_camel_case_types)] - // pp-exact - Make sure we print all the attributes // pretty-expanded FIXME #23616 -#![feature(custom_attribute)] +#![allow(unused)] +#![feature(rustc_attrs)] -#[frobable] -trait frobable { - #[frob_attr] +#[rustc_dummy] +trait Frobable { + #[rustc_dummy] fn frob(&self); - #[defrob_attr] + #[rustc_dummy] fn defrob(&self); } -#[int_frobable] -impl frobable for isize { - #[frob_attr1] +#[rustc_dummy] +impl Frobable for isize { + #[rustc_dummy] fn frob(&self) { - #![frob_attr2] + #![rustc_dummy] } - #[defrob_attr1] + #[rustc_dummy] fn defrob(&self) { - #![defrob_attr2] + #![rustc_dummy] } } -pub fn main() { } +fn main() {} diff --git a/src/test/run-pass/structs-enums/class-attributes-1.rs b/src/test/run-pass/structs-enums/class-attributes-1.rs index 11ea29ece8a02..62cd10ef3bf5f 100644 --- a/src/test/run-pass/structs-enums/class-attributes-1.rs +++ b/src/test/run-pass/structs-enums/class-attributes-1.rs @@ -1,21 +1,19 @@ -// run-pass -#![allow(unused_attributes)] -#![allow(non_camel_case_types)] - // pp-exact - Make sure we actually print the attributes -#![feature(custom_attribute)] -struct cat { +#![allow(unused)] +#![feature(rustc_attrs)] + +struct Cat { name: String, } -impl Drop for cat { - #[cat_dropper] +impl Drop for Cat { + #[rustc_dummy] fn drop(&mut self) { println!("{} landed on hir feet" , self . name); } } -#[cat_maker] -fn cat(name: String) -> cat { cat{name: name,} } +#[rustc_dummy] +fn cat(name: String) -> Cat { Cat{name: name,} } -pub fn main() { let _kitty = cat("Spotty".to_string()); } +fn main() { let _kitty = cat("Spotty".to_string()); } diff --git a/src/test/run-pass/structs-enums/class-attributes-2.rs b/src/test/run-pass/structs-enums/class-attributes-2.rs index d6cf63e62fea2..5026ce84ad902 100644 --- a/src/test/run-pass/structs-enums/class-attributes-2.rs +++ b/src/test/run-pass/structs-enums/class-attributes-2.rs @@ -1,15 +1,12 @@ -// run-pass -#![allow(unused_attributes)] -#![allow(non_camel_case_types)] +#![allow(unused)] +#![feature(rustc_attrs)] -#![feature(custom_attribute)] - -struct cat { - name: String, +struct Cat { + name: String, } -impl Drop for cat { - #[cat_dropper] +impl Drop for Cat { + #[rustc_dummy] /** Actually, cats don't always land on their feet when you drop them. */ @@ -18,16 +15,16 @@ impl Drop for cat { } } -#[cat_maker] +#[rustc_dummy] /** Maybe it should technically be a kitten_maker. */ -fn cat(name: String) -> cat { - cat { +fn cat(name: String) -> Cat { + Cat { name: name } } -pub fn main() { - let _kitty = cat("Spotty".to_string()); +fn main() { + let _kitty = cat("Spotty".to_string()); } diff --git a/src/test/run-pass/variant-attributes.rs b/src/test/run-pass/variant-attributes.rs index 19de3ff2f63f3..25a214cea82f6 100644 --- a/src/test/run-pass/variant-attributes.rs +++ b/src/test/run-pass/variant-attributes.rs @@ -1,38 +1,37 @@ -#![allow(unused_attributes)] -#![allow(non_camel_case_types)] -#![allow(dead_code)] // pp-exact - Make sure we actually print the attributes // pretty-expanded FIXME #23616 -#![feature(custom_attribute)] +#![allow(unused)] +#![allow(non_camel_case_types)] +#![feature(rustc_attrs)] enum crew_of_enterprise_d { - #[captain] + #[rustc_dummy] jean_luc_picard, - #[oldcommander] + #[rustc_dummy] william_t_riker, - #[chief_medical_officer] + #[rustc_dummy] beverly_crusher, - #[ships_councellor] + #[rustc_dummy] deanna_troi, - #[lieutenant_oldcommander] + #[rustc_dummy] data, - #[chief_of_security] + #[rustc_dummy] worf, - #[chief_engineer] + #[rustc_dummy] geordi_la_forge, } fn boldly_go(_crew_member: crew_of_enterprise_d, _where: String) { } -pub fn main() { +fn main() { boldly_go(crew_of_enterprise_d::worf, "where no one has gone before".to_string()); } diff --git a/src/test/ui/issues/issue-24434.rs b/src/test/ui/issues/issue-24434.rs index 7b270ceb68814..2424a1c92cd64 100644 --- a/src/test/ui/issues/issue-24434.rs +++ b/src/test/ui/issues/issue-24434.rs @@ -1,8 +1,7 @@ // compile-pass -#![allow(unused_attributes)] // compile-flags:--cfg set1 -#![cfg_attr(set1, feature(custom_attribute))] +#![cfg_attr(set1, feature(rustc_attrs))] +#![rustc_dummy] -#![foobar] fn main() {} diff --git a/src/test/ui/macros/macro-inner-attributes.rs b/src/test/ui/macros/macro-inner-attributes.rs index 268ddda1b3c25..56a9023156612 100644 --- a/src/test/ui/macros/macro-inner-attributes.rs +++ b/src/test/ui/macros/macro-inner-attributes.rs @@ -1,4 +1,4 @@ -#![feature(custom_attribute)] +#![feature(rustc_attrs)] macro_rules! test { ($nm:ident, #[$a:meta], @@ -12,7 +12,7 @@ test!(b, #[cfg(not(qux))], pub fn bar() { }); -#[qux] +#[rustc_dummy] fn main() { a::bar(); //~^ ERROR failed to resolve: use of undeclared type or module `a` diff --git a/src/test/ui/macros/macro-outer-attributes.rs b/src/test/ui/macros/macro-outer-attributes.rs index aa70060425f65..0752f7e3153c1 100644 --- a/src/test/ui/macros/macro-outer-attributes.rs +++ b/src/test/ui/macros/macro-outer-attributes.rs @@ -1,4 +1,4 @@ -#![feature(custom_attribute)] +#![feature(rustc_attrs)] macro_rules! test { ($nm:ident, #[$a:meta], @@ -13,7 +13,7 @@ test!(b, pub fn bar() { }); // test1!(#[bar]) -#[qux] +#[rustc_dummy] fn main() { a::bar(); //~ ERROR cannot find function `bar` in module `a` b::bar(); diff --git a/src/test/ui/malformed/malformed-interpolated.rs b/src/test/ui/malformed/malformed-interpolated.rs index 7c4ca3c017e7b..5101b5caeea09 100644 --- a/src/test/ui/malformed/malformed-interpolated.rs +++ b/src/test/ui/malformed/malformed-interpolated.rs @@ -1,9 +1,9 @@ -#![feature(custom_attribute)] +#![feature(rustc_attrs)] macro_rules! check { ($expr: expr) => ( - #[my_attr = $expr] //~ ERROR unexpected token: `-0` - //~| ERROR unexpected token: `0 + 0` + #[rustc_dummy = $expr] //~ ERROR unexpected token: `-0` + //~| ERROR unexpected token: `0 + 0` use main as _; ); } diff --git a/src/test/ui/malformed/malformed-interpolated.stderr b/src/test/ui/malformed/malformed-interpolated.stderr index e805416172bab..bcd2ef545d815 100644 --- a/src/test/ui/malformed/malformed-interpolated.stderr +++ b/src/test/ui/malformed/malformed-interpolated.stderr @@ -7,19 +7,19 @@ LL | check!(0u8); = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). error: unexpected token: `-0` - --> $DIR/malformed-interpolated.rs:5:21 + --> $DIR/malformed-interpolated.rs:5:25 | -LL | #[my_attr = $expr] - | ^^^^^ +LL | #[rustc_dummy = $expr] + | ^^^^^ ... LL | check!(-0); // ERROR, see above | ----------- in this macro invocation error: unexpected token: `0 + 0` - --> $DIR/malformed-interpolated.rs:5:21 + --> $DIR/malformed-interpolated.rs:5:25 | -LL | #[my_attr = $expr] - | ^^^^^ +LL | #[rustc_dummy = $expr] + | ^^^^^ ... LL | check!(0 + 0); // ERROR, see above | -------------- in this macro invocation diff --git a/src/test/ui/stmt_expr_attrs_no_feature.rs b/src/test/ui/stmt_expr_attrs_no_feature.rs index 8952175e4258a..674a5ed18cee3 100644 --- a/src/test/ui/stmt_expr_attrs_no_feature.rs +++ b/src/test/ui/stmt_expr_attrs_no_feature.rs @@ -1,4 +1,4 @@ -#![feature(custom_attribute)] +#![feature(rustc_attrs)] macro_rules! stmt_mac { () => { @@ -7,18 +7,19 @@ macro_rules! stmt_mac { } fn main() { - #[attr] + #[rustc_dummy] fn a() {} - #[attr] //~ ERROR attributes on expressions are experimental + // Bug: built-in attrs like `rustc_dummy` are not gated on blocks, but other attrs are. + #[rustfmt::skip] //~ ERROR attributes on expressions are experimental { } - #[attr] + #[rustc_dummy] 5; - #[attr] + #[rustc_dummy] stmt_mac!(); } @@ -26,25 +27,25 @@ fn main() { #[cfg(unset)] fn c() { - #[attr] + #[rustc_dummy] 5; } #[cfg(not(unset))] fn j() { - #[attr] + #[rustc_dummy] 5; } #[cfg_attr(not(unset), cfg(unset))] fn d() { - #[attr] + #[rustc_dummy] 8; } #[cfg_attr(not(unset), cfg(not(unset)))] fn i() { - #[attr] + #[rustc_dummy] 8; } @@ -53,30 +54,30 @@ fn i() { macro_rules! item_mac { ($e:ident) => { fn $e() { - #[attr] + #[rustc_dummy] 42; #[cfg(unset)] fn f() { - #[attr] + #[rustc_dummy] 5; } #[cfg(not(unset))] fn k() { - #[attr] + #[rustc_dummy] 5; } #[cfg_attr(not(unset), cfg(unset))] fn g() { - #[attr] + #[rustc_dummy] 8; } #[cfg_attr(not(unset), cfg(not(unset)))] fn h() { - #[attr] + #[rustc_dummy] 8; } @@ -90,51 +91,51 @@ item_mac!(e); extern { #[cfg(unset)] - fn x(a: [u8; #[attr] 5]); - fn y(a: [u8; #[attr] 5]); //~ ERROR attributes on expressions are experimental + fn x(a: [u8; #[rustc_dummy] 5]); + fn y(a: [u8; #[rustc_dummy] 5]); //~ ERROR attributes on expressions are experimental } struct Foo; impl Foo { #[cfg(unset)] - const X: u8 = #[attr] 5; - const Y: u8 = #[attr] 5; //~ ERROR attributes on expressions are experimental + const X: u8 = #[rustc_dummy] 5; + const Y: u8 = #[rustc_dummy] 5; //~ ERROR attributes on expressions are experimental } trait Bar { #[cfg(unset)] - const X: [u8; #[attr] 5]; - const Y: [u8; #[attr] 5]; //~ ERROR attributes on expressions are experimental + const X: [u8; #[rustc_dummy] 5]; + const Y: [u8; #[rustc_dummy] 5]; //~ ERROR attributes on expressions are experimental } struct Joyce { #[cfg(unset)] - field: [u8; #[attr] 5], - field2: [u8; #[attr] 5] //~ ERROR attributes on expressions are experimental + field: [u8; #[rustc_dummy] 5], + field2: [u8; #[rustc_dummy] 5] //~ ERROR attributes on expressions are experimental } struct Walky( - #[cfg(unset)] [u8; #[attr] 5], - [u8; #[attr] 5] //~ ERROR attributes on expressions are experimental + #[cfg(unset)] [u8; #[rustc_dummy] 5], + [u8; #[rustc_dummy] 5] //~ ERROR attributes on expressions are experimental ); enum Mike { Happy( - #[cfg(unset)] [u8; #[attr] 5], - [u8; #[attr] 5] //~ ERROR attributes on expressions are experimental + #[cfg(unset)] [u8; #[rustc_dummy] 5], + [u8; #[rustc_dummy] 5] //~ ERROR attributes on expressions are experimental ), Angry { #[cfg(unset)] - field: [u8; #[attr] 5], - field2: [u8; #[attr] 5] //~ ERROR attributes on expressions are experimental + field: [u8; #[rustc_dummy] 5], + field2: [u8; #[rustc_dummy] 5] //~ ERROR attributes on expressions are experimental } } fn pat() { match 5 { #[cfg(unset)] - 5 => #[attr] (), - 6 => #[attr] (), //~ ERROR attributes on expressions are experimental + 5 => #[rustc_dummy] (), + 6 => #[rustc_dummy] (), //~ ERROR attributes on expressions are experimental _ => (), } } diff --git a/src/test/ui/stmt_expr_attrs_no_feature.stderr b/src/test/ui/stmt_expr_attrs_no_feature.stderr index 1b5e989af7b19..01372cc164b62 100644 --- a/src/test/ui/stmt_expr_attrs_no_feature.stderr +++ b/src/test/ui/stmt_expr_attrs_no_feature.stderr @@ -1,80 +1,80 @@ error[E0658]: attributes on expressions are experimental - --> $DIR/stmt_expr_attrs_no_feature.rs:13:5 + --> $DIR/stmt_expr_attrs_no_feature.rs:14:5 | -LL | #[attr] - | ^^^^^^^ +LL | #[rustfmt::skip] + | ^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/15701 = help: add #![feature(stmt_expr_attributes)] to the crate attributes to enable error[E0658]: attributes on expressions are experimental - --> $DIR/stmt_expr_attrs_no_feature.rs:94:18 + --> $DIR/stmt_expr_attrs_no_feature.rs:95:18 | -LL | fn y(a: [u8; #[attr] 5]); - | ^^^^^^^ +LL | fn y(a: [u8; #[rustc_dummy] 5]); + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/15701 = help: add #![feature(stmt_expr_attributes)] to the crate attributes to enable error[E0658]: attributes on expressions are experimental - --> $DIR/stmt_expr_attrs_no_feature.rs:101:19 + --> $DIR/stmt_expr_attrs_no_feature.rs:102:19 | -LL | const Y: u8 = #[attr] 5; - | ^^^^^^^ +LL | const Y: u8 = #[rustc_dummy] 5; + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/15701 = help: add #![feature(stmt_expr_attributes)] to the crate attributes to enable error[E0658]: attributes on expressions are experimental - --> $DIR/stmt_expr_attrs_no_feature.rs:107:19 + --> $DIR/stmt_expr_attrs_no_feature.rs:108:19 | -LL | const Y: [u8; #[attr] 5]; - | ^^^^^^^ +LL | const Y: [u8; #[rustc_dummy] 5]; + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/15701 = help: add #![feature(stmt_expr_attributes)] to the crate attributes to enable error[E0658]: attributes on expressions are experimental - --> $DIR/stmt_expr_attrs_no_feature.rs:113:18 + --> $DIR/stmt_expr_attrs_no_feature.rs:114:18 | -LL | field2: [u8; #[attr] 5] - | ^^^^^^^ +LL | field2: [u8; #[rustc_dummy] 5] + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/15701 = help: add #![feature(stmt_expr_attributes)] to the crate attributes to enable error[E0658]: attributes on expressions are experimental - --> $DIR/stmt_expr_attrs_no_feature.rs:118:10 + --> $DIR/stmt_expr_attrs_no_feature.rs:119:10 | -LL | [u8; #[attr] 5] - | ^^^^^^^ +LL | [u8; #[rustc_dummy] 5] + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/15701 = help: add #![feature(stmt_expr_attributes)] to the crate attributes to enable error[E0658]: attributes on expressions are experimental - --> $DIR/stmt_expr_attrs_no_feature.rs:124:14 + --> $DIR/stmt_expr_attrs_no_feature.rs:125:14 | -LL | [u8; #[attr] 5] - | ^^^^^^^ +LL | [u8; #[rustc_dummy] 5] + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/15701 = help: add #![feature(stmt_expr_attributes)] to the crate attributes to enable error[E0658]: attributes on expressions are experimental - --> $DIR/stmt_expr_attrs_no_feature.rs:129:22 + --> $DIR/stmt_expr_attrs_no_feature.rs:130:22 | -LL | field2: [u8; #[attr] 5] - | ^^^^^^^ +LL | field2: [u8; #[rustc_dummy] 5] + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/15701 = help: add #![feature(stmt_expr_attributes)] to the crate attributes to enable error[E0658]: attributes on expressions are experimental - --> $DIR/stmt_expr_attrs_no_feature.rs:137:14 + --> $DIR/stmt_expr_attrs_no_feature.rs:138:14 | -LL | 6 => #[attr] (), - | ^^^^^^^ +LL | 6 => #[rustc_dummy] (), + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/15701 = help: add #![feature(stmt_expr_attributes)] to the crate attributes to enable diff --git a/src/test/ui/suffixed-literal-meta.rs b/src/test/ui/suffixed-literal-meta.rs index bd2d6623d9104..a6531490c0159 100644 --- a/src/test/ui/suffixed-literal-meta.rs +++ b/src/test/ui/suffixed-literal-meta.rs @@ -1,15 +1,15 @@ -#![feature(custom_attribute)] +#![feature(rustc_attrs)] -#[my_attr = 1usize] //~ ERROR: suffixed literals are not allowed in attributes -#[my_attr = 1u8] //~ ERROR: suffixed literals are not allowed in attributes -#[my_attr = 1u16] //~ ERROR: suffixed literals are not allowed in attributes -#[my_attr = 1u32] //~ ERROR: suffixed literals are not allowed in attributes -#[my_attr = 1u64] //~ ERROR: suffixed literals are not allowed in attributes -#[my_attr = 1isize] //~ ERROR: suffixed literals are not allowed in attributes -#[my_attr = 1i8] //~ ERROR: suffixed literals are not allowed in attributes -#[my_attr = 1i16] //~ ERROR: suffixed literals are not allowed in attributes -#[my_attr = 1i32] //~ ERROR: suffixed literals are not allowed in attributes -#[my_attr = 1i64] //~ ERROR: suffixed literals are not allowed in attributes -#[my_attr = 1.0f32] //~ ERROR: suffixed literals are not allowed in attributes -#[my_attr = 1.0f64] //~ ERROR: suffixed literals are not allowed in attributes -fn main() { } +#[rustc_dummy = 1usize] //~ ERROR: suffixed literals are not allowed in attributes +#[rustc_dummy = 1u8] //~ ERROR: suffixed literals are not allowed in attributes +#[rustc_dummy = 1u16] //~ ERROR: suffixed literals are not allowed in attributes +#[rustc_dummy = 1u32] //~ ERROR: suffixed literals are not allowed in attributes +#[rustc_dummy = 1u64] //~ ERROR: suffixed literals are not allowed in attributes +#[rustc_dummy = 1isize] //~ ERROR: suffixed literals are not allowed in attributes +#[rustc_dummy = 1i8] //~ ERROR: suffixed literals are not allowed in attributes +#[rustc_dummy = 1i16] //~ ERROR: suffixed literals are not allowed in attributes +#[rustc_dummy = 1i32] //~ ERROR: suffixed literals are not allowed in attributes +#[rustc_dummy = 1i64] //~ ERROR: suffixed literals are not allowed in attributes +#[rustc_dummy = 1.0f32] //~ ERROR: suffixed literals are not allowed in attributes +#[rustc_dummy = 1.0f64] //~ ERROR: suffixed literals are not allowed in attributes +fn main() {} diff --git a/src/test/ui/suffixed-literal-meta.stderr b/src/test/ui/suffixed-literal-meta.stderr index 495404af3e8a5..83de173b1a703 100644 --- a/src/test/ui/suffixed-literal-meta.stderr +++ b/src/test/ui/suffixed-literal-meta.stderr @@ -1,96 +1,96 @@ error: suffixed literals are not allowed in attributes - --> $DIR/suffixed-literal-meta.rs:3:13 + --> $DIR/suffixed-literal-meta.rs:3:17 | -LL | #[my_attr = 1usize] - | ^^^^^^ +LL | #[rustc_dummy = 1usize] + | ^^^^^^ | = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). error: suffixed literals are not allowed in attributes - --> $DIR/suffixed-literal-meta.rs:4:13 + --> $DIR/suffixed-literal-meta.rs:4:17 | -LL | #[my_attr = 1u8] - | ^^^ +LL | #[rustc_dummy = 1u8] + | ^^^ | = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). error: suffixed literals are not allowed in attributes - --> $DIR/suffixed-literal-meta.rs:5:13 + --> $DIR/suffixed-literal-meta.rs:5:17 | -LL | #[my_attr = 1u16] - | ^^^^ +LL | #[rustc_dummy = 1u16] + | ^^^^ | = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). error: suffixed literals are not allowed in attributes - --> $DIR/suffixed-literal-meta.rs:6:13 + --> $DIR/suffixed-literal-meta.rs:6:17 | -LL | #[my_attr = 1u32] - | ^^^^ +LL | #[rustc_dummy = 1u32] + | ^^^^ | = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). error: suffixed literals are not allowed in attributes - --> $DIR/suffixed-literal-meta.rs:7:13 + --> $DIR/suffixed-literal-meta.rs:7:17 | -LL | #[my_attr = 1u64] - | ^^^^ +LL | #[rustc_dummy = 1u64] + | ^^^^ | = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). error: suffixed literals are not allowed in attributes - --> $DIR/suffixed-literal-meta.rs:8:13 + --> $DIR/suffixed-literal-meta.rs:8:17 | -LL | #[my_attr = 1isize] - | ^^^^^^ +LL | #[rustc_dummy = 1isize] + | ^^^^^^ | = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). error: suffixed literals are not allowed in attributes - --> $DIR/suffixed-literal-meta.rs:9:13 + --> $DIR/suffixed-literal-meta.rs:9:17 | -LL | #[my_attr = 1i8] - | ^^^ +LL | #[rustc_dummy = 1i8] + | ^^^ | = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). error: suffixed literals are not allowed in attributes - --> $DIR/suffixed-literal-meta.rs:10:13 + --> $DIR/suffixed-literal-meta.rs:10:17 | -LL | #[my_attr = 1i16] - | ^^^^ +LL | #[rustc_dummy = 1i16] + | ^^^^ | = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). error: suffixed literals are not allowed in attributes - --> $DIR/suffixed-literal-meta.rs:11:13 + --> $DIR/suffixed-literal-meta.rs:11:17 | -LL | #[my_attr = 1i32] - | ^^^^ +LL | #[rustc_dummy = 1i32] + | ^^^^ | = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). error: suffixed literals are not allowed in attributes - --> $DIR/suffixed-literal-meta.rs:12:13 + --> $DIR/suffixed-literal-meta.rs:12:17 | -LL | #[my_attr = 1i64] - | ^^^^ +LL | #[rustc_dummy = 1i64] + | ^^^^ | = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). error: suffixed literals are not allowed in attributes - --> $DIR/suffixed-literal-meta.rs:13:13 + --> $DIR/suffixed-literal-meta.rs:13:17 | -LL | #[my_attr = 1.0f32] - | ^^^^^^ +LL | #[rustc_dummy = 1.0f32] + | ^^^^^^ | = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). error: suffixed literals are not allowed in attributes - --> $DIR/suffixed-literal-meta.rs:14:13 + --> $DIR/suffixed-literal-meta.rs:14:17 | -LL | #[my_attr = 1.0f64] - | ^^^^^^ +LL | #[rustc_dummy = 1.0f64] + | ^^^^^^ | = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). diff --git a/src/test/ui/unrestricted-attribute-tokens.rs b/src/test/ui/unrestricted-attribute-tokens.rs index 4798f7b396cd6..b07ab96bce13f 100644 --- a/src/test/ui/unrestricted-attribute-tokens.rs +++ b/src/test/ui/unrestricted-attribute-tokens.rs @@ -1,8 +1,8 @@ // compile-pass -#![feature(custom_attribute)] +#![feature(rustc_attrs)] -#[my_attr(a b c d)] -#[my_attr[a b c d]] -#[my_attr{a b c d}] +#[rustc_dummy(a b c d)] +#[rustc_dummy[a b c d]] +#[rustc_dummy{a b c d}] fn main() {} diff --git a/src/test/ui/unused/unused-attr.rs b/src/test/ui/unused/unused-attr.rs index 810732a977578..cb8ac0e6a05c0 100644 --- a/src/test/ui/unused/unused-attr.rs +++ b/src/test/ui/unused/unused-attr.rs @@ -1,49 +1,48 @@ #![deny(unused_attributes)] -#![allow(dead_code, unused_imports, unused_extern_crates)] -#![feature(custom_attribute)] +#![feature(rustc_attrs)] -#![foo] //~ ERROR unused attribute +#![rustc_dummy] //~ ERROR unused attribute -#[foo] //~ ERROR unused attribute +#[rustc_dummy] //~ ERROR unused attribute extern crate core; -#[foo] //~ ERROR unused attribute +#[rustc_dummy] //~ ERROR unused attribute use std::collections; -#[foo] //~ ERROR unused attribute +#[rustc_dummy] //~ ERROR unused attribute extern "C" { - #[foo] //~ ERROR unused attribute + #[rustc_dummy] //~ ERROR unused attribute fn foo(); } -#[foo] //~ ERROR unused attribute +#[rustc_dummy] //~ ERROR unused attribute mod foo { - #[foo] //~ ERROR unused attribute + #[rustc_dummy] //~ ERROR unused attribute pub enum Foo { - #[foo] //~ ERROR unused attribute + #[rustc_dummy] //~ ERROR unused attribute Bar, } } -#[foo] //~ ERROR unused attribute +#[rustc_dummy] //~ ERROR unused attribute fn bar(f: foo::Foo) { match f { - #[foo] //~ ERROR unused attribute + #[rustc_dummy] //~ ERROR unused attribute foo::Foo::Bar => {} } } -#[foo] //~ ERROR unused attribute +#[rustc_dummy] //~ ERROR unused attribute struct Foo { - #[foo] //~ ERROR unused attribute + #[rustc_dummy] //~ ERROR unused attribute a: isize } -#[foo] //~ ERROR unused attribute +#[rustc_dummy] //~ ERROR unused attribute trait Baz { - #[foo] //~ ERROR unused attribute + #[rustc_dummy] //~ ERROR unused attribute fn blah(&self); - #[foo] //~ ERROR unused attribute + #[rustc_dummy] //~ ERROR unused attribute fn blah2(&self) {} } diff --git a/src/test/ui/unused/unused-attr.stderr b/src/test/ui/unused/unused-attr.stderr index 6f096d741444f..956b870715eb2 100644 --- a/src/test/ui/unused/unused-attr.stderr +++ b/src/test/ui/unused/unused-attr.stderr @@ -1,8 +1,8 @@ error: unused attribute - --> $DIR/unused-attr.rs:7:1 + --> $DIR/unused-attr.rs:6:1 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ | note: lint level defined here --> $DIR/unused-attr.rs:1:9 @@ -11,88 +11,88 @@ LL | #![deny(unused_attributes)] | ^^^^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:10:1 + --> $DIR/unused-attr.rs:9:1 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:15:5 + --> $DIR/unused-attr.rs:14:5 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:13:1 + --> $DIR/unused-attr.rs:12:1 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:23:9 + --> $DIR/unused-attr.rs:22:9 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:21:5 + --> $DIR/unused-attr.rs:20:5 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:19:1 + --> $DIR/unused-attr.rs:18:1 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:31:9 + --> $DIR/unused-attr.rs:30:9 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:28:1 + --> $DIR/unused-attr.rs:27:1 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:38:5 + --> $DIR/unused-attr.rs:37:5 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:36:1 + --> $DIR/unused-attr.rs:35:1 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:44:5 + --> $DIR/unused-attr.rs:43:5 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:46:5 + --> $DIR/unused-attr.rs:45:5 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:42:1 + --> $DIR/unused-attr.rs:41:1 | -LL | #[foo] - | ^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/unused-attr.rs:5:1 + --> $DIR/unused-attr.rs:4:1 | -LL | #![foo] - | ^^^^^^^ +LL | #![rustc_dummy] + | ^^^^^^^^^^^^^^^ error: aborting due to 15 previous errors From 6a66491883452df0ee769f052ae0bde72bafb040 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 8 Jun 2019 17:35:54 +0300 Subject: [PATCH 14/16] Remove some more `#![feature(custom_attribute)]`s --- .../src/lints/listing/warn-by-default.md | 10 +++--- src/test/ui/lint/lint-obsolete-attr.rs | 8 ++--- src/test/ui/lint/lint-obsolete-attr.stderr | 27 +++++++------- src/test/ui/lint/lint-unknown-attr.rs | 9 +++-- src/test/ui/lint/lint-unknown-attr.stderr | 36 ++++++++++--------- src/test/ui/proc-macro/resolve-error.rs | 8 ++--- src/test/ui/proc-macro/resolve-error.stderr | 23 ++++++++++-- .../tool-attributes-misplaced-1.rs | 5 ++- .../tool-attributes-misplaced-1.stderr | 26 +++++++++----- 9 files changed, 89 insertions(+), 63 deletions(-) diff --git a/src/doc/rustc/src/lints/listing/warn-by-default.md b/src/doc/rustc/src/lints/listing/warn-by-default.md index f090f142c0816..6d4aa024c75b4 100644 --- a/src/doc/rustc/src/lints/listing/warn-by-default.md +++ b/src/doc/rustc/src/lints/listing/warn-by-default.md @@ -728,19 +728,17 @@ This lint detects attributes that were not used by the compiler. Some example code that triggers this lint: ```rust -#![feature(custom_attribute)] - -#![mutable_doc] +#![macro_export] ``` This will produce: ```text warning: unused attribute - --> src/main.rs:4:1 + --> src/main.rs:1:1 | -4 | #![mutable_doc] - | ^^^^^^^^^^^^^^^ +1 | #![macro_export] + | ^^^^^^^^^^^^^^^^ | ``` diff --git a/src/test/ui/lint/lint-obsolete-attr.rs b/src/test/ui/lint/lint-obsolete-attr.rs index 149948b5a6da2..49a8dde5da84f 100644 --- a/src/test/ui/lint/lint-obsolete-attr.rs +++ b/src/test/ui/lint/lint-obsolete-attr.rs @@ -1,12 +1,8 @@ // When denying at the crate level, be sure to not get random warnings from the // injected intrinsics by the compiler. -#![deny(unused_attributes)] -#![allow(dead_code)] -#![feature(custom_attribute)] +#[ab_isize="stdcall"] extern {} //~ ERROR attribute `ab_isize` is currently unknown -#[ab_isize="stdcall"] extern {} //~ ERROR unused attribute - -#[fixed_stack_segment] fn f() {} //~ ERROR unused attribute +#[fixed_stack_segment] fn f() {} //~ ERROR attribute `fixed_stack_segment` is currently unknown fn main() {} diff --git a/src/test/ui/lint/lint-obsolete-attr.stderr b/src/test/ui/lint/lint-obsolete-attr.stderr index c06bd26df2b96..039b07e6ea544 100644 --- a/src/test/ui/lint/lint-obsolete-attr.stderr +++ b/src/test/ui/lint/lint-obsolete-attr.stderr @@ -1,20 +1,21 @@ -error: unused attribute - --> $DIR/lint-obsolete-attr.rs:8:1 +error[E0658]: The attribute `fixed_stack_segment` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/lint-obsolete-attr.rs:6:3 | -LL | #[ab_isize="stdcall"] extern {} - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: lint level defined here - --> $DIR/lint-obsolete-attr.rs:4:9 +LL | #[fixed_stack_segment] fn f() {} + | ^^^^^^^^^^^^^^^^^^^ | -LL | #![deny(unused_attributes)] - | ^^^^^^^^^^^^^^^^^ + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable -error: unused attribute - --> $DIR/lint-obsolete-attr.rs:10:1 +error[E0658]: The attribute `ab_isize` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/lint-obsolete-attr.rs:4:3 | -LL | #[fixed_stack_segment] fn f() {} - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #[ab_isize="stdcall"] extern {} + | ^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/lint/lint-unknown-attr.rs b/src/test/ui/lint/lint-unknown-attr.rs index 828b869c12e23..cddac850c59f5 100644 --- a/src/test/ui/lint/lint-unknown-attr.rs +++ b/src/test/ui/lint/lint-unknown-attr.rs @@ -1,11 +1,10 @@ // When denying at the crate level, be sure to not get random warnings from the // injected intrinsics by the compiler. -#![feature(custom_attribute)] -#![deny(unused_attributes)] +#![feature(custom_inner_attributes)] -#![mutable_doc] //~ ERROR unused attribute +#![mutable_doc] //~ ERROR attribute `mutable_doc` is currently unknown -#[dance] mod a {} //~ ERROR unused attribute +#[dance] mod a {} //~ ERROR attribute `dance` is currently unknown -#[dance] fn main() {} //~ ERROR unused attribute +#[dance] fn main() {} //~ ERROR attribute `dance` is currently unknown diff --git a/src/test/ui/lint/lint-unknown-attr.stderr b/src/test/ui/lint/lint-unknown-attr.stderr index 9817760c2247a..4f00a51a5db96 100644 --- a/src/test/ui/lint/lint-unknown-attr.stderr +++ b/src/test/ui/lint/lint-unknown-attr.stderr @@ -1,26 +1,30 @@ -error: unused attribute - --> $DIR/lint-unknown-attr.rs:9:1 +error[E0658]: The attribute `mutable_doc` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/lint-unknown-attr.rs:6:4 | -LL | #[dance] mod a {} - | ^^^^^^^^ +LL | #![mutable_doc] + | ^^^^^^^^^^^ | -note: lint level defined here - --> $DIR/lint-unknown-attr.rs:5:9 + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable + +error[E0658]: The attribute `dance` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/lint-unknown-attr.rs:8:3 | -LL | #![deny(unused_attributes)] - | ^^^^^^^^^^^^^^^^^ +LL | #[dance] mod a {} + | ^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable -error: unused attribute - --> $DIR/lint-unknown-attr.rs:11:1 +error[E0658]: The attribute `dance` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/lint-unknown-attr.rs:10:3 | LL | #[dance] fn main() {} - | ^^^^^^^^ - -error: unused attribute - --> $DIR/lint-unknown-attr.rs:7:1 + | ^^^^^ | -LL | #![mutable_doc] - | ^^^^^^^^^^^^^^^ + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/proc-macro/resolve-error.rs b/src/test/ui/proc-macro/resolve-error.rs index 82607136f0b6f..1298c08df846d 100644 --- a/src/test/ui/proc-macro/resolve-error.rs +++ b/src/test/ui/proc-macro/resolve-error.rs @@ -2,8 +2,6 @@ // aux-build:derive-clona.rs // aux-build:test-macros.rs -#![feature(custom_attribute)] - #[macro_use] extern crate derive_foo; #[macro_use] @@ -25,10 +23,12 @@ macro_rules! attr_proc_mac { //~^ ERROR cannot find struct Foo; -#[attr_proc_macra] // OK, interpreted as a custom attribute +// Interpreted as a feature gated custom attribute +#[attr_proc_macra] //~ ERROR attribute `attr_proc_macra` is currently unknown struct Bar; -#[FooWithLongNan] // OK, interpreted as a custom attribute +// Interpreted as a feature gated custom attribute +#[FooWithLongNan] //~ ERROR attribute `FooWithLongNan` is currently unknown struct Asdf; #[derive(Dlone)] diff --git a/src/test/ui/proc-macro/resolve-error.stderr b/src/test/ui/proc-macro/resolve-error.stderr index 705ef6006a049..f9f116c15dcc7 100644 --- a/src/test/ui/proc-macro/resolve-error.stderr +++ b/src/test/ui/proc-macro/resolve-error.stderr @@ -1,5 +1,23 @@ +error[E0658]: The attribute `attr_proc_macra` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/resolve-error.rs:27:3 + | +LL | #[attr_proc_macra] + | ^^^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable + +error[E0658]: The attribute `FooWithLongNan` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/resolve-error.rs:31:3 + | +LL | #[FooWithLongNan] + | ^^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable + error: cannot find derive macro `FooWithLongNan` in this scope - --> $DIR/resolve-error.rs:24:10 + --> $DIR/resolve-error.rs:22:10 | LL | #[derive(FooWithLongNan)] | ^^^^^^^^^^^^^^ help: try: `FooWithLongName` @@ -46,5 +64,6 @@ error: cannot find macro `bang_proc_macrp!` in this scope LL | bang_proc_macrp!(); | ^^^^^^^^^^^^^^^ help: you could try the macro: `bang_proc_macro` -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/tool-attributes/tool-attributes-misplaced-1.rs b/src/test/ui/tool-attributes/tool-attributes-misplaced-1.rs index 33cffcefd898a..ce902b7e7d28a 100644 --- a/src/test/ui/tool-attributes/tool-attributes-misplaced-1.rs +++ b/src/test/ui/tool-attributes/tool-attributes-misplaced-1.rs @@ -1,12 +1,11 @@ -#![feature(custom_attribute)] - type A = rustfmt; //~ ERROR expected type, found tool module `rustfmt` type B = rustfmt::skip; //~ ERROR expected type, found tool attribute `rustfmt::skip` #[derive(rustfmt)] //~ ERROR cannot find derive macro `rustfmt` in this scope struct S; -#[rustfmt] // OK, interpreted as a custom attribute +// Interpreted as a feature gated custom attribute +#[rustfmt] //~ ERROR attribute `rustfmt` is currently unknown fn check() {} #[rustfmt::skip] // OK diff --git a/src/test/ui/tool-attributes/tool-attributes-misplaced-1.stderr b/src/test/ui/tool-attributes/tool-attributes-misplaced-1.stderr index 1c799b41c5a6c..1df9821f24440 100644 --- a/src/test/ui/tool-attributes/tool-attributes-misplaced-1.stderr +++ b/src/test/ui/tool-attributes/tool-attributes-misplaced-1.stderr @@ -1,39 +1,49 @@ +error[E0658]: The attribute `rustfmt` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/tool-attributes-misplaced-1.rs:8:3 + | +LL | #[rustfmt] + | ^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable + error: cannot find derive macro `rustfmt` in this scope - --> $DIR/tool-attributes-misplaced-1.rs:6:10 + --> $DIR/tool-attributes-misplaced-1.rs:4:10 | LL | #[derive(rustfmt)] | ^^^^^^^ error: cannot find macro `rustfmt!` in this scope - --> $DIR/tool-attributes-misplaced-1.rs:15:5 + --> $DIR/tool-attributes-misplaced-1.rs:14:5 | LL | rustfmt!(); | ^^^^^^^ error[E0573]: expected type, found tool module `rustfmt` - --> $DIR/tool-attributes-misplaced-1.rs:3:10 + --> $DIR/tool-attributes-misplaced-1.rs:1:10 | LL | type A = rustfmt; | ^^^^^^^ not a type error[E0573]: expected type, found tool attribute `rustfmt::skip` - --> $DIR/tool-attributes-misplaced-1.rs:4:10 + --> $DIR/tool-attributes-misplaced-1.rs:2:10 | LL | type B = rustfmt::skip; | ^^^^^^^^^^^^^ not a type error[E0423]: expected value, found tool module `rustfmt` - --> $DIR/tool-attributes-misplaced-1.rs:14:5 + --> $DIR/tool-attributes-misplaced-1.rs:13:5 | LL | rustfmt; | ^^^^^^^ not a value error[E0423]: expected value, found tool attribute `rustfmt::skip` - --> $DIR/tool-attributes-misplaced-1.rs:17:5 + --> $DIR/tool-attributes-misplaced-1.rs:16:5 | LL | rustfmt::skip; | ^^^^^^^^^^^^^ not a value -error: aborting due to 6 previous errors +error: aborting due to 7 previous errors -For more information about this error, try `rustc --explain E0423`. +Some errors have detailed explanations: E0423, E0658. +For more information about an error, try `rustc --explain E0423`. From 8e8ab49bcacda0875afe02410e28883304e970c4 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 8 Jun 2019 17:42:58 +0300 Subject: [PATCH 15/16] Move some run-pass attribute tests to ui --- src/test/{run-pass => ui/attributes}/attr-before-view-item.rs | 2 +- src/test/{run-pass => ui/attributes}/attr-before-view-item2.rs | 2 +- src/test/{run-pass => ui/attributes}/attr-mix-new.rs | 2 +- .../attrs-with-no-formal-in-generics-1.rs | 0 .../attrs-with-no-formal-in-generics-1.stderr | 0 .../attrs-with-no-formal-in-generics-2.rs | 0 .../attrs-with-no-formal-in-generics-2.stderr | 0 .../attrs-with-no-formal-in-generics-3.rs | 0 .../attrs-with-no-formal-in-generics-3.stderr | 0 .../structs-enums => ui/attributes}/class-attributes-1.rs | 2 +- .../structs-enums => ui/attributes}/class-attributes-2.rs | 3 ++- src/test/{run-pass => ui/attributes}/item-attributes.rs | 3 ++- .../{run-pass/methods => ui/attributes}/method-attributes.rs | 2 +- src/test/{run-pass => ui/attributes}/variant-attributes.rs | 2 +- 14 files changed, 10 insertions(+), 8 deletions(-) rename src/test/{run-pass => ui/attributes}/attr-before-view-item.rs (88%) rename src/test/{run-pass => ui/attributes}/attr-before-view-item2.rs (89%) rename src/test/{run-pass => ui/attributes}/attr-mix-new.rs (87%) rename src/test/ui/{attrs-with-no-formal-in-generics => attributes}/attrs-with-no-formal-in-generics-1.rs (100%) rename src/test/ui/{attrs-with-no-formal-in-generics => attributes}/attrs-with-no-formal-in-generics-1.stderr (100%) rename src/test/ui/{attrs-with-no-formal-in-generics => attributes}/attrs-with-no-formal-in-generics-2.rs (100%) rename src/test/ui/{attrs-with-no-formal-in-generics => attributes}/attrs-with-no-formal-in-generics-2.stderr (100%) rename src/test/ui/{attrs-with-no-formal-in-generics => attributes}/attrs-with-no-formal-in-generics-3.rs (100%) rename src/test/ui/{attrs-with-no-formal-in-generics => attributes}/attrs-with-no-formal-in-generics-3.stderr (100%) rename src/test/{run-pass/structs-enums => ui/attributes}/class-attributes-1.rs (95%) rename src/test/{run-pass/structs-enums => ui/attributes}/class-attributes-2.rs (96%) rename src/test/{run-pass => ui/attributes}/item-attributes.rs (99%) rename src/test/{run-pass/methods => ui/attributes}/method-attributes.rs (95%) rename src/test/{run-pass => ui/attributes}/variant-attributes.rs (97%) diff --git a/src/test/run-pass/attr-before-view-item.rs b/src/test/ui/attributes/attr-before-view-item.rs similarity index 88% rename from src/test/run-pass/attr-before-view-item.rs rename to src/test/ui/attributes/attr-before-view-item.rs index 3aa2ee77ee51c..fc040bd1a5d10 100644 --- a/src/test/run-pass/attr-before-view-item.rs +++ b/src/test/ui/attributes/attr-before-view-item.rs @@ -1,6 +1,6 @@ +// compile-pass // pretty-expanded FIXME #23616 -#![allow(unused)] #![feature(rustc_attrs)] #![feature(test)] diff --git a/src/test/run-pass/attr-before-view-item2.rs b/src/test/ui/attributes/attr-before-view-item2.rs similarity index 89% rename from src/test/run-pass/attr-before-view-item2.rs rename to src/test/ui/attributes/attr-before-view-item2.rs index 2b3a09b5e6fd5..c7fad3802e9d6 100644 --- a/src/test/run-pass/attr-before-view-item2.rs +++ b/src/test/ui/attributes/attr-before-view-item2.rs @@ -1,6 +1,6 @@ +// compile-pass // pretty-expanded FIXME #23616 -#![allow(unused)] #![feature(rustc_attrs)] #![feature(test)] diff --git a/src/test/run-pass/attr-mix-new.rs b/src/test/ui/attributes/attr-mix-new.rs similarity index 87% rename from src/test/run-pass/attr-mix-new.rs rename to src/test/ui/attributes/attr-mix-new.rs index ca53bfacf9191..d9cb551096092 100644 --- a/src/test/run-pass/attr-mix-new.rs +++ b/src/test/ui/attributes/attr-mix-new.rs @@ -1,6 +1,6 @@ +// compile-pass // pretty-expanded FIXME #23616 -#![allow(unused)] #![feature(rustc_attrs)] #[rustc_dummy(bar)] diff --git a/src/test/ui/attrs-with-no-formal-in-generics/attrs-with-no-formal-in-generics-1.rs b/src/test/ui/attributes/attrs-with-no-formal-in-generics-1.rs similarity index 100% rename from src/test/ui/attrs-with-no-formal-in-generics/attrs-with-no-formal-in-generics-1.rs rename to src/test/ui/attributes/attrs-with-no-formal-in-generics-1.rs diff --git a/src/test/ui/attrs-with-no-formal-in-generics/attrs-with-no-formal-in-generics-1.stderr b/src/test/ui/attributes/attrs-with-no-formal-in-generics-1.stderr similarity index 100% rename from src/test/ui/attrs-with-no-formal-in-generics/attrs-with-no-formal-in-generics-1.stderr rename to src/test/ui/attributes/attrs-with-no-formal-in-generics-1.stderr diff --git a/src/test/ui/attrs-with-no-formal-in-generics/attrs-with-no-formal-in-generics-2.rs b/src/test/ui/attributes/attrs-with-no-formal-in-generics-2.rs similarity index 100% rename from src/test/ui/attrs-with-no-formal-in-generics/attrs-with-no-formal-in-generics-2.rs rename to src/test/ui/attributes/attrs-with-no-formal-in-generics-2.rs diff --git a/src/test/ui/attrs-with-no-formal-in-generics/attrs-with-no-formal-in-generics-2.stderr b/src/test/ui/attributes/attrs-with-no-formal-in-generics-2.stderr similarity index 100% rename from src/test/ui/attrs-with-no-formal-in-generics/attrs-with-no-formal-in-generics-2.stderr rename to src/test/ui/attributes/attrs-with-no-formal-in-generics-2.stderr diff --git a/src/test/ui/attrs-with-no-formal-in-generics/attrs-with-no-formal-in-generics-3.rs b/src/test/ui/attributes/attrs-with-no-formal-in-generics-3.rs similarity index 100% rename from src/test/ui/attrs-with-no-formal-in-generics/attrs-with-no-formal-in-generics-3.rs rename to src/test/ui/attributes/attrs-with-no-formal-in-generics-3.rs diff --git a/src/test/ui/attrs-with-no-formal-in-generics/attrs-with-no-formal-in-generics-3.stderr b/src/test/ui/attributes/attrs-with-no-formal-in-generics-3.stderr similarity index 100% rename from src/test/ui/attrs-with-no-formal-in-generics/attrs-with-no-formal-in-generics-3.stderr rename to src/test/ui/attributes/attrs-with-no-formal-in-generics-3.stderr diff --git a/src/test/run-pass/structs-enums/class-attributes-1.rs b/src/test/ui/attributes/class-attributes-1.rs similarity index 95% rename from src/test/run-pass/structs-enums/class-attributes-1.rs rename to src/test/ui/attributes/class-attributes-1.rs index 62cd10ef3bf5f..7808367f2c10f 100644 --- a/src/test/run-pass/structs-enums/class-attributes-1.rs +++ b/src/test/ui/attributes/class-attributes-1.rs @@ -1,6 +1,6 @@ +// compile-pass // pp-exact - Make sure we actually print the attributes -#![allow(unused)] #![feature(rustc_attrs)] struct Cat { diff --git a/src/test/run-pass/structs-enums/class-attributes-2.rs b/src/test/ui/attributes/class-attributes-2.rs similarity index 96% rename from src/test/run-pass/structs-enums/class-attributes-2.rs rename to src/test/ui/attributes/class-attributes-2.rs index 5026ce84ad902..348c70f35c328 100644 --- a/src/test/run-pass/structs-enums/class-attributes-2.rs +++ b/src/test/ui/attributes/class-attributes-2.rs @@ -1,4 +1,5 @@ -#![allow(unused)] +// compile-pass + #![feature(rustc_attrs)] struct Cat { diff --git a/src/test/run-pass/item-attributes.rs b/src/test/ui/attributes/item-attributes.rs similarity index 99% rename from src/test/run-pass/item-attributes.rs rename to src/test/ui/attributes/item-attributes.rs index 1801fa05f85c9..72c9a35dc07f0 100644 --- a/src/test/run-pass/item-attributes.rs +++ b/src/test/ui/attributes/item-attributes.rs @@ -2,7 +2,8 @@ // for completeness since .rs files linked from .rc files support this // notation to specify their module's attributes -#![allow(unused)] +// compile-pass + #![feature(rustc_attrs)] #![rustc_dummy = "val"] diff --git a/src/test/run-pass/methods/method-attributes.rs b/src/test/ui/attributes/method-attributes.rs similarity index 95% rename from src/test/run-pass/methods/method-attributes.rs rename to src/test/ui/attributes/method-attributes.rs index 8a4ce49ffb6c4..2d608acc71f71 100644 --- a/src/test/run-pass/methods/method-attributes.rs +++ b/src/test/ui/attributes/method-attributes.rs @@ -1,7 +1,7 @@ +// compile-pass // pp-exact - Make sure we print all the attributes // pretty-expanded FIXME #23616 -#![allow(unused)] #![feature(rustc_attrs)] #[rustc_dummy] diff --git a/src/test/run-pass/variant-attributes.rs b/src/test/ui/attributes/variant-attributes.rs similarity index 97% rename from src/test/run-pass/variant-attributes.rs rename to src/test/ui/attributes/variant-attributes.rs index 25a214cea82f6..a910340f4a06d 100644 --- a/src/test/run-pass/variant-attributes.rs +++ b/src/test/ui/attributes/variant-attributes.rs @@ -1,7 +1,7 @@ +// compile-pass // pp-exact - Make sure we actually print the attributes // pretty-expanded FIXME #23616 -#![allow(unused)] #![allow(non_camel_case_types)] #![feature(rustc_attrs)] From ee189ae028ce4ff620630686432f44b0ea706181 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 8 Jun 2019 23:55:09 +0300 Subject: [PATCH 16/16] Address review comments --- .../lint-obsolete-attr.rs => attributes/obsolete-attr.rs} | 3 +-- .../obsolete-attr.stderr} | 4 ++-- .../lint-unknown-attr.rs => attributes/unknown-attr.rs} | 3 +-- .../unknown-attr.stderr} | 6 +++--- 4 files changed, 7 insertions(+), 9 deletions(-) rename src/test/ui/{lint/lint-obsolete-attr.rs => attributes/obsolete-attr.rs} (62%) rename src/test/ui/{lint/lint-obsolete-attr.stderr => attributes/obsolete-attr.stderr} (91%) rename src/test/ui/{lint/lint-unknown-attr.rs => attributes/unknown-attr.rs} (67%) rename src/test/ui/{lint/lint-unknown-attr.stderr => attributes/unknown-attr.stderr} (91%) diff --git a/src/test/ui/lint/lint-obsolete-attr.rs b/src/test/ui/attributes/obsolete-attr.rs similarity index 62% rename from src/test/ui/lint/lint-obsolete-attr.rs rename to src/test/ui/attributes/obsolete-attr.rs index 49a8dde5da84f..89e2ad2669cbe 100644 --- a/src/test/ui/lint/lint-obsolete-attr.rs +++ b/src/test/ui/attributes/obsolete-attr.rs @@ -1,5 +1,4 @@ -// When denying at the crate level, be sure to not get random warnings from the -// injected intrinsics by the compiler. +// Obsolete attributes fall back to feature gated custom attributes. #[ab_isize="stdcall"] extern {} //~ ERROR attribute `ab_isize` is currently unknown diff --git a/src/test/ui/lint/lint-obsolete-attr.stderr b/src/test/ui/attributes/obsolete-attr.stderr similarity index 91% rename from src/test/ui/lint/lint-obsolete-attr.stderr rename to src/test/ui/attributes/obsolete-attr.stderr index 039b07e6ea544..2ed7f87935fca 100644 --- a/src/test/ui/lint/lint-obsolete-attr.stderr +++ b/src/test/ui/attributes/obsolete-attr.stderr @@ -1,5 +1,5 @@ error[E0658]: The attribute `fixed_stack_segment` is currently unknown to the compiler and may have meaning added to it in the future - --> $DIR/lint-obsolete-attr.rs:6:3 + --> $DIR/obsolete-attr.rs:5:3 | LL | #[fixed_stack_segment] fn f() {} | ^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | #[fixed_stack_segment] fn f() {} = help: add #![feature(custom_attribute)] to the crate attributes to enable error[E0658]: The attribute `ab_isize` is currently unknown to the compiler and may have meaning added to it in the future - --> $DIR/lint-obsolete-attr.rs:4:3 + --> $DIR/obsolete-attr.rs:3:3 | LL | #[ab_isize="stdcall"] extern {} | ^^^^^^^^ diff --git a/src/test/ui/lint/lint-unknown-attr.rs b/src/test/ui/attributes/unknown-attr.rs similarity index 67% rename from src/test/ui/lint/lint-unknown-attr.rs rename to src/test/ui/attributes/unknown-attr.rs index cddac850c59f5..e2a4f3226d562 100644 --- a/src/test/ui/lint/lint-unknown-attr.rs +++ b/src/test/ui/attributes/unknown-attr.rs @@ -1,5 +1,4 @@ -// When denying at the crate level, be sure to not get random warnings from the -// injected intrinsics by the compiler. +// Unknown attributes fall back to feature gated custom attributes. #![feature(custom_inner_attributes)] diff --git a/src/test/ui/lint/lint-unknown-attr.stderr b/src/test/ui/attributes/unknown-attr.stderr similarity index 91% rename from src/test/ui/lint/lint-unknown-attr.stderr rename to src/test/ui/attributes/unknown-attr.stderr index 4f00a51a5db96..d0ac58108fc8d 100644 --- a/src/test/ui/lint/lint-unknown-attr.stderr +++ b/src/test/ui/attributes/unknown-attr.stderr @@ -1,5 +1,5 @@ error[E0658]: The attribute `mutable_doc` is currently unknown to the compiler and may have meaning added to it in the future - --> $DIR/lint-unknown-attr.rs:6:4 + --> $DIR/unknown-attr.rs:5:4 | LL | #![mutable_doc] | ^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | #![mutable_doc] = help: add #![feature(custom_attribute)] to the crate attributes to enable error[E0658]: The attribute `dance` is currently unknown to the compiler and may have meaning added to it in the future - --> $DIR/lint-unknown-attr.rs:8:3 + --> $DIR/unknown-attr.rs:7:3 | LL | #[dance] mod a {} | ^^^^^ @@ -17,7 +17,7 @@ LL | #[dance] mod a {} = help: add #![feature(custom_attribute)] to the crate attributes to enable error[E0658]: The attribute `dance` is currently unknown to the compiler and may have meaning added to it in the future - --> $DIR/lint-unknown-attr.rs:10:3 + --> $DIR/unknown-attr.rs:9:3 | LL | #[dance] fn main() {} | ^^^^^