From 6e85f467c59e7ae943404a2aee9cc83ee475cf23 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 21 Nov 2019 18:45:28 +0000 Subject: Initial implementation of or-pattern usefulness checking --- src/librustc_mir/hair/pattern/_match.rs | 60 +++++++++++++++++++++++++-------- src/test/compile-fail/or-patterns.rs | 45 +++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 src/test/compile-fail/or-patterns.rs (limited to 'src') diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 5e7a7f01e7a..7d3bbbc1ee4 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -399,6 +399,25 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> { self.0.iter().map(|p| *p) } + // If the first pattern is an or-pattern, expand this pattern. Otherwise, return `None`. + fn expand_or_pat(&self) -> Option>> { + if self.is_empty() { + None + } else if let PatKind::Or { pats } = &*self.head().kind { + Some( + pats.iter() + .map(|pat| { + let mut new_patstack = PatStack::from_pattern(pat); + new_patstack.0.extend_from_slice(&self.0[1..]); + new_patstack + }) + .collect(), + ) + } else { + None + } + } + /// This computes `D(self)`. See top of the file for explanations. fn specialize_wildcard(&self) -> Option { if self.head().is_wildcard() { Some(self.to_tail()) } else { None } @@ -446,8 +465,13 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> { Matrix(vec![]) } + /// Pushes a new row to the matrix. If the row starts with an or-pattern, this expands it. pub fn push(&mut self, row: PatStack<'p, 'tcx>) { - self.0.push(row) + if let Some(rows) = row.expand_or_pat() { + self.0.extend(rows); + } else { + self.0.push(row); + } } /// Iterate over the first component of each row @@ -471,12 +495,10 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> { 'a: 'q, 'p: 'q, { - Matrix( - self.0 - .iter() - .filter_map(|r| r.specialize_constructor(cx, constructor, ctor_wild_subpatterns)) - .collect(), - ) + self.0 + .iter() + .filter_map(|r| r.specialize_constructor(cx, constructor, ctor_wild_subpatterns)) + .collect() } } @@ -528,7 +550,12 @@ impl<'p, 'tcx> FromIterator> for Matrix<'p, 'tcx> { where T: IntoIterator>, { - Matrix(iter.into_iter().collect()) + let mut matrix = Matrix::empty(); + for x in iter { + // Using `push` ensures we correctly expand or-patterns. + matrix.push(x); + } + matrix } } @@ -1601,6 +1628,15 @@ pub fn is_useful<'p, 'a, 'tcx>( assert!(rows.iter().all(|r| r.len() == v.len())); + // If the first pattern is an or-pattern, expand it. + if let Some(vs) = v.expand_or_pat() { + return vs + .into_iter() + .map(|v| is_useful(cx, matrix, &v, witness_preference, hir_id)) + .find(|result| result.is_useful()) + .unwrap_or(NotUseful); + } + let (ty, span) = matrix .heads() .map(|r| (r.ty, r.span)) @@ -1802,9 +1838,7 @@ fn pat_constructor<'tcx>( if slice.is_some() { VarLen(prefix, suffix) } else { FixedLen(prefix + suffix) }; Some(Slice(Slice { array_len, kind })) } - PatKind::Or { .. } => { - bug!("support for or-patterns has not been fully implemented yet."); - } + PatKind::Or { .. } => bug!(), // Should have been expanded earlier on. } } @@ -2410,9 +2444,7 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>( _ => span_bug!(pat.span, "unexpected ctor {:?} for slice pat", constructor), }, - PatKind::Or { .. } => { - bug!("support for or-patterns has not been fully implemented yet."); - } + PatKind::Or { .. } => bug!(), // Should have been expanded earlier on. }; debug!("specialize({:#?}, {:#?}) = {:#?}", pat, ctor_wild_subpatterns, result); diff --git a/src/test/compile-fail/or-patterns.rs b/src/test/compile-fail/or-patterns.rs new file mode 100644 index 00000000000..e1b5dce852d --- /dev/null +++ b/src/test/compile-fail/or-patterns.rs @@ -0,0 +1,45 @@ +// should-ice +#![allow(incomplete_features)] +#![feature(or_patterns)] +#![deny(unreachable_patterns)] + +// The ice will get removed once or-patterns are correctly implemented +fn main() { + // We wrap patterns in a tuple because top-level or-patterns are special-cased for now. + match (0u8,) { + (1 | 2,) => {} + //~^ ERROR simplifyable pattern found + // This above is the ICE error message + _ => {} + } + + match (0u8,) { + (1 | 2,) => {} + (1,) => {} //~ ERROR unreachable pattern + _ => {} + } + match (0u8,) { + (1 | 2,) => {} + (2,) => {} //~ ERROR unreachable pattern + _ => {} + } + match (0u8,) { + (1,) => {} + (2,) => {} + (1 | 2,) => {} //~ ERROR unreachable pattern + _ => {} + } + match (0u8,) { + (1 | 1,) => {} // redundancy not detected for now + _ => {} + } + match (0u8, 0u8) { + (1 | 2, 3 | 4) => {} + (1, 2) => {} + (1, 3) => {} //~ ERROR unreachable pattern + (1, 4) => {} //~ ERROR unreachable pattern + (2, 4) => {} //~ ERROR unreachable pattern + (2 | 1, 4) => {} //~ ERROR unreachable pattern + _ => {} + } +} -- cgit 1.4.1-3-g733a5 From 0030a777f286bbbd938b9cc4f0b559843fffd37a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 21 Nov 2019 19:06:49 +0000 Subject: Add some more tests --- src/test/compile-fail/or-patterns.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/test/compile-fail/or-patterns.rs b/src/test/compile-fail/or-patterns.rs index e1b5dce852d..fb243f24328 100644 --- a/src/test/compile-fail/or-patterns.rs +++ b/src/test/compile-fail/or-patterns.rs @@ -42,4 +42,15 @@ fn main() { (2 | 1, 4) => {} //~ ERROR unreachable pattern _ => {} } + match (Some(0u8),) { + (None | Some(1 | 2),) => {} + (Some(1),) => {} //~ ERROR unreachable pattern + (None,) => {} //~ ERROR unreachable pattern + (Some(_),) => {} + } + match ((0u8,),) { + ((1 | 2,) | (3 | 4,),) => {}, + ((1..=4,),) => {}, //~ ERROR unreachable pattern + ((_,),) => {}, + } } -- cgit 1.4.1-3-g733a5 From 3b1c742e23648260e60f87d67aa47e1f43d0cc0d Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Sat, 23 Nov 2019 17:07:31 +0100 Subject: Add as_mut_ptr method to atomic types. --- src/libcore/sync/atomic.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'src') diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index d311cb16b64..5d6972bf75c 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -802,6 +802,37 @@ impl AtomicBool { pub fn fetch_xor(&self, val: bool, order: Ordering) -> bool { unsafe { atomic_xor(self.v.get(), val as u8, order) != 0 } } + + /// Returns a mutable pointer to the underlying [`bool`]. + /// + /// Doing non-atomic reads and writes on the resulting integer can be a data race. + /// This method is mostly useful for FFI, where the function signature may use + /// `*mut bool` instead of `&AtomicBool`. + /// + /// [`bool`]: ../../../std/primitive.bool.html + /// + /// # Examples + /// + /// ```ignore (extern-declaration) + /// # fn main() { + /// use std::sync::atomic::AtomicBool; + /// extern { + /// fn my_atomic_op(arg: *mut bool); + /// } + /// + /// let mut atomic = AtomicBool::new(true); + /// unsafe { + /// my_atomic_op(atomic.as_mut_ptr()); + /// } + /// # } + /// ``` + #[inline] + #[unstable(feature = "atomic_mut_ptr", + reason = "recently added", + issue = "0")] + pub fn as_mut_ptr(&self) -> *mut bool { + self.v.get() as *mut bool + } } #[cfg(any(bootstrap, target_has_atomic_load_store = "ptr"))] @@ -1891,6 +1922,37 @@ assert_eq!(min_foo, 12); } } + doc_comment! { + concat!("Returns a mutable pointer to the underlying integer. + +Doing non-atomic reads and writes on the resulting integer can be a data race. +This method is mostly useful for FFI, where the function signature may use +`*mut ", stringify!($int_type), "` instead of `&", stringify!($atomic_type), "`. + +# Examples + +```ignore (extern-declaration) +# fn main() { +", $extra_feature, "use std::sync::atomic::", stringify!($atomic_type), "; + +extern { + fn my_atomic_op(arg: *mut ", stringify!($int_type), "); +} + +let mut atomic = ", stringify!($atomic_type), "::new(1); +unsafe { + my_atomic_op(atomic.as_mut_ptr()); +} +# } +```"), + #[inline] + #[unstable(feature = "atomic_mut_ptr", + reason = "recently added", + issue = "0")] + pub fn as_mut_ptr(&self) -> *mut $int_type { + self.v.get() + } + } } } } -- cgit 1.4.1-3-g733a5 From 23c5e584e0ea40a6f630be0d4c5151b67ba96dd1 Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Sun, 24 Nov 2019 16:28:01 +0100 Subject: Use as_mut_ptr instead of casts --- src/libstd/lib.rs | 1 + src/libstd/sys/wasm/alloc.rs | 4 ++-- src/libstd/sys/wasm/condvar_atomics.rs | 2 +- src/libstd/sys/wasm/mutex_atomics.rs | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 927fd2a6b0b..98464763882 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -234,6 +234,7 @@ #![feature(allocator_internals)] #![feature(allow_internal_unsafe)] #![feature(allow_internal_unstable)] +#![feature(atomic_mut_ptr)] #![feature(arbitrary_self_types)] #![feature(array_error_internals)] #![feature(asm)] diff --git a/src/libstd/sys/wasm/alloc.rs b/src/libstd/sys/wasm/alloc.rs index c1af6ec1262..05e55334ac0 100644 --- a/src/libstd/sys/wasm/alloc.rs +++ b/src/libstd/sys/wasm/alloc.rs @@ -67,7 +67,7 @@ mod lock { // // unsafe { // let r = core::arch::wasm32::i32_atomic_wait( - // &LOCKED as *const AtomicI32 as *mut i32, + // LOCKED.as_mut_ptr(), // 1, // expected value // -1, // timeout // ); @@ -143,7 +143,7 @@ mod lock { // // unsafe { // core::arch::wasm32::atomic_notify( - // &LOCKED as *const AtomicI32 as *mut i32, + // LOCKED.as_mut_ptr(), // 1, // only one thread // ); // } diff --git a/src/libstd/sys/wasm/condvar_atomics.rs b/src/libstd/sys/wasm/condvar_atomics.rs index 580d2121844..f452bbd3487 100644 --- a/src/libstd/sys/wasm/condvar_atomics.rs +++ b/src/libstd/sys/wasm/condvar_atomics.rs @@ -89,6 +89,6 @@ impl Condvar { #[inline] fn ptr(&self) -> *mut i32 { assert_eq!(mem::size_of::(), mem::size_of::()); - &self.cnt as *const AtomicUsize as *mut i32 + self.cnt.as_mut_ptr() as *mut i32 } } diff --git a/src/libstd/sys/wasm/mutex_atomics.rs b/src/libstd/sys/wasm/mutex_atomics.rs index 0e4f3d80aa9..cddd584dd22 100644 --- a/src/libstd/sys/wasm/mutex_atomics.rs +++ b/src/libstd/sys/wasm/mutex_atomics.rs @@ -56,7 +56,7 @@ impl Mutex { #[inline] fn ptr(&self) -> *mut i32 { assert_eq!(mem::size_of::(), mem::size_of::()); - &self.locked as *const AtomicUsize as *mut isize as *mut i32 + self.locked.as_mut_ptr() as *mut i32 } } @@ -145,6 +145,6 @@ impl ReentrantMutex { #[inline] fn ptr(&self) -> *mut i32 { - &self.owner as *const AtomicU32 as *mut i32 + self.owner.as_mut_ptr() as *mut i32 } } -- cgit 1.4.1-3-g733a5 From b5ec4d11835d16167ee48bb6e3cf7e8347f367e1 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 25 Nov 2019 18:23:09 +0000 Subject: Address reviews --- src/librustc_mir/hair/pattern/_match.rs | 6 +++--- src/test/compile-fail/or-patterns.rs | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 7d3bbbc1ee4..2e339b1eb88 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -400,7 +400,7 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> { } // If the first pattern is an or-pattern, expand this pattern. Otherwise, return `None`. - fn expand_or_pat(&self) -> Option>> { + fn expand_or_pat(&self) -> Option> { if self.is_empty() { None } else if let PatKind::Or { pats } = &*self.head().kind { @@ -1838,7 +1838,7 @@ fn pat_constructor<'tcx>( if slice.is_some() { VarLen(prefix, suffix) } else { FixedLen(prefix + suffix) }; Some(Slice(Slice { array_len, kind })) } - PatKind::Or { .. } => bug!(), // Should have been expanded earlier on. + PatKind::Or { .. } => bug!("Or-pattern hould have been expanded earlier on."), } } @@ -2444,7 +2444,7 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>( _ => span_bug!(pat.span, "unexpected ctor {:?} for slice pat", constructor), }, - PatKind::Or { .. } => bug!(), // Should have been expanded earlier on. + PatKind::Or { .. } => bug!("Or-pattern hould have been expanded earlier on."), }; debug!("specialize({:#?}, {:#?}) = {:#?}", pat, ctor_wild_subpatterns, result); diff --git a/src/test/compile-fail/or-patterns.rs b/src/test/compile-fail/or-patterns.rs index fb243f24328..ba8427045e3 100644 --- a/src/test/compile-fail/or-patterns.rs +++ b/src/test/compile-fail/or-patterns.rs @@ -1,6 +1,7 @@ // should-ice -#![allow(incomplete_features)] #![feature(or_patterns)] +#![feature(slice_patterns)] +#![allow(incomplete_features)] #![deny(unreachable_patterns)] // The ice will get removed once or-patterns are correctly implemented @@ -53,4 +54,8 @@ fn main() { ((1..=4,),) => {}, //~ ERROR unreachable pattern ((_,),) => {}, } + match (&[0u8][..],) { + ([] | [0 | 1..=255] | [_, ..],) => {}, + (_,) => {}, //~ ERROR unreachable pattern + } } -- cgit 1.4.1-3-g733a5 From f8a4b6d2ba2ad2a0897cd26cf6196cca23045f96 Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Mon, 25 Nov 2019 17:55:26 -0500 Subject: impl TrustedLen for vec::Drain --- src/liballoc/vec.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 07e4358d644..ab9e2a23cb0 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2701,6 +2701,9 @@ impl ExactSizeIterator for Drain<'_, T> { } } +#[unstable(feature = "trusted_len", issue = "37572")] +unsafe impl TrustedLen for Drain<'_, T> {} + #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Drain<'_, T> {} -- cgit 1.4.1-3-g733a5 From cdc844e81f186c62e9368a24e3b8edba1ef6143b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 26 Nov 2019 14:32:47 +0000 Subject: Make the ice a fatal error --- src/librustc_mir/build/matches/test.rs | 8 +++++++- src/test/compile-fail/or-patterns.rs | 11 +++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs index 5c2f72c0a06..f534c2a347c 100644 --- a/src/librustc_mir/build/matches/test.rs +++ b/src/librustc_mir/build/matches/test.rs @@ -84,10 +84,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } + PatKind::Or { .. } => { + self.hir.tcx().sess.span_fatal( + match_pair.pattern.span, + "or-patterns are not fully implemented yet" + ) + } + PatKind::AscribeUserType { .. } | PatKind::Array { .. } | PatKind::Wild | - PatKind::Or { .. } | PatKind::Binding { .. } | PatKind::Leaf { .. } | PatKind::Deref { .. } => { diff --git a/src/test/compile-fail/or-patterns.rs b/src/test/compile-fail/or-patterns.rs index ba8427045e3..118090c9eb2 100644 --- a/src/test/compile-fail/or-patterns.rs +++ b/src/test/compile-fail/or-patterns.rs @@ -1,16 +1,19 @@ -// should-ice #![feature(or_patterns)] #![feature(slice_patterns)] #![allow(incomplete_features)] #![deny(unreachable_patterns)] -// The ice will get removed once or-patterns are correctly implemented fn main() { // We wrap patterns in a tuple because top-level or-patterns are special-cased for now. + + // Get the fatal error out of the way + match (0u8,) { + (0 | _,) => {} + //~^ ERROR or-patterns are not fully implemented yet + } + match (0u8,) { (1 | 2,) => {} - //~^ ERROR simplifyable pattern found - // This above is the ICE error message _ => {} } -- cgit 1.4.1-3-g733a5 From 0881750173d714770713f989332464eb5498574e Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 26 Nov 2019 14:53:54 +0000 Subject: Move tests to ui, split them and add some --- src/test/compile-fail/or-patterns.rs | 64 ----------------- .../or-patterns/exhaustiveness-non-exhaustive.rs | 26 +++++++ .../exhaustiveness-non-exhaustive.stderr | 33 +++++++++ src/test/ui/or-patterns/exhaustiveness-pass.rs | 40 +++++++++++ src/test/ui/or-patterns/exhaustiveness-pass.stderr | 8 +++ .../exhaustiveness-unreachable-pattern.rs | 51 ++++++++++++++ .../exhaustiveness-unreachable-pattern.stderr | 80 ++++++++++++++++++++++ 7 files changed, 238 insertions(+), 64 deletions(-) delete mode 100644 src/test/compile-fail/or-patterns.rs create mode 100644 src/test/ui/or-patterns/exhaustiveness-non-exhaustive.rs create mode 100644 src/test/ui/or-patterns/exhaustiveness-non-exhaustive.stderr create mode 100644 src/test/ui/or-patterns/exhaustiveness-pass.rs create mode 100644 src/test/ui/or-patterns/exhaustiveness-pass.stderr create mode 100644 src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs create mode 100644 src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr (limited to 'src') diff --git a/src/test/compile-fail/or-patterns.rs b/src/test/compile-fail/or-patterns.rs deleted file mode 100644 index 118090c9eb2..00000000000 --- a/src/test/compile-fail/or-patterns.rs +++ /dev/null @@ -1,64 +0,0 @@ -#![feature(or_patterns)] -#![feature(slice_patterns)] -#![allow(incomplete_features)] -#![deny(unreachable_patterns)] - -fn main() { - // We wrap patterns in a tuple because top-level or-patterns are special-cased for now. - - // Get the fatal error out of the way - match (0u8,) { - (0 | _,) => {} - //~^ ERROR or-patterns are not fully implemented yet - } - - match (0u8,) { - (1 | 2,) => {} - _ => {} - } - - match (0u8,) { - (1 | 2,) => {} - (1,) => {} //~ ERROR unreachable pattern - _ => {} - } - match (0u8,) { - (1 | 2,) => {} - (2,) => {} //~ ERROR unreachable pattern - _ => {} - } - match (0u8,) { - (1,) => {} - (2,) => {} - (1 | 2,) => {} //~ ERROR unreachable pattern - _ => {} - } - match (0u8,) { - (1 | 1,) => {} // redundancy not detected for now - _ => {} - } - match (0u8, 0u8) { - (1 | 2, 3 | 4) => {} - (1, 2) => {} - (1, 3) => {} //~ ERROR unreachable pattern - (1, 4) => {} //~ ERROR unreachable pattern - (2, 4) => {} //~ ERROR unreachable pattern - (2 | 1, 4) => {} //~ ERROR unreachable pattern - _ => {} - } - match (Some(0u8),) { - (None | Some(1 | 2),) => {} - (Some(1),) => {} //~ ERROR unreachable pattern - (None,) => {} //~ ERROR unreachable pattern - (Some(_),) => {} - } - match ((0u8,),) { - ((1 | 2,) | (3 | 4,),) => {}, - ((1..=4,),) => {}, //~ ERROR unreachable pattern - ((_,),) => {}, - } - match (&[0u8][..],) { - ([] | [0 | 1..=255] | [_, ..],) => {}, - (_,) => {}, //~ ERROR unreachable pattern - } -} diff --git a/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.rs b/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.rs new file mode 100644 index 00000000000..d7c191bb5a2 --- /dev/null +++ b/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.rs @@ -0,0 +1,26 @@ +#![feature(or_patterns)] +#![feature(slice_patterns)] +#![allow(incomplete_features)] +#![deny(unreachable_patterns)] + +// We wrap patterns in a tuple because top-level or-patterns are special-cased for now. +fn main() { + // Get the fatal error out of the way + match (0u8,) { + (0 | _,) => {} + //~^ ERROR or-patterns are not fully implemented yet + } + + match (0u8, 0u8) { + //~^ ERROR non-exhaustive patterns: `(2u8..=std::u8::MAX, _)` + (0 | 1, 2 | 3) => {} + } + match ((0u8,),) { + //~^ ERROR non-exhaustive patterns: `((4u8..=std::u8::MAX))` + ((0 | 1,) | (2 | 3,),) => {}, + } + match (Some(0u8),) { + //~^ ERROR non-exhaustive patterns: `(Some(2u8..=std::u8::MAX))` + (None | Some(0 | 1),) => {} + } +} diff --git a/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.stderr b/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.stderr new file mode 100644 index 00000000000..e6aa157d278 --- /dev/null +++ b/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.stderr @@ -0,0 +1,33 @@ +error[E0004]: non-exhaustive patterns: `(2u8..=std::u8::MAX, _)` not covered + --> $DIR/exhaustiveness-non-exhaustive.rs:14:11 + | +LL | match (0u8, 0u8) { + | ^^^^^^^^^^ pattern `(2u8..=std::u8::MAX, _)` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `((4u8..=std::u8::MAX))` not covered + --> $DIR/exhaustiveness-non-exhaustive.rs:18:11 + | +LL | match ((0u8,),) { + | ^^^^^^^^^ pattern `((4u8..=std::u8::MAX))` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `(Some(2u8..=std::u8::MAX))` not covered + --> $DIR/exhaustiveness-non-exhaustive.rs:22:11 + | +LL | match (Some(0u8),) { + | ^^^^^^^^^^^^ pattern `(Some(2u8..=std::u8::MAX))` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error: or-patterns are not fully implemented yet + --> $DIR/exhaustiveness-non-exhaustive.rs:10:10 + | +LL | (0 | _,) => {} + | ^^^^^ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0004`. diff --git a/src/test/ui/or-patterns/exhaustiveness-pass.rs b/src/test/ui/or-patterns/exhaustiveness-pass.rs new file mode 100644 index 00000000000..a29cc7253ad --- /dev/null +++ b/src/test/ui/or-patterns/exhaustiveness-pass.rs @@ -0,0 +1,40 @@ +#![feature(or_patterns)] +#![feature(slice_patterns)] +#![allow(incomplete_features)] +#![deny(unreachable_patterns)] + +// We wrap patterns in a tuple because top-level or-patterns are special-cased for now. +fn main() { + // Get the fatal error out of the way + match (0u8,) { + (0 | _,) => {} + //~^ ERROR or-patterns are not fully implemented yet + } + + match (0u8,) { + (1 | 2,) => {} + _ => {} + } + + match (0u8,) { + (1 | 1,) => {} // redundancy not detected for now + _ => {} + } + match (0u8, 0u8) { + (1 | 2, 3 | 4) => {} + (1, 2) => {} + (2, 1) => {} + _ => {} + } + match (Some(0u8),) { + (None | Some(0 | 1),) => {} + (Some(2..=255),) => {} + } + match ((0u8,),) { + ((0 | 1,) | (2 | 3,),) => {}, + ((_,),) => {}, + } + match (&[0u8][..],) { + ([] | [0 | 1..=255] | [_, ..],) => {}, + } +} diff --git a/src/test/ui/or-patterns/exhaustiveness-pass.stderr b/src/test/ui/or-patterns/exhaustiveness-pass.stderr new file mode 100644 index 00000000000..1f4278c4b80 --- /dev/null +++ b/src/test/ui/or-patterns/exhaustiveness-pass.stderr @@ -0,0 +1,8 @@ +error: or-patterns are not fully implemented yet + --> $DIR/exhaustiveness-pass.rs:10:10 + | +LL | (0 | _,) => {} + | ^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs new file mode 100644 index 00000000000..2cd8ca2dbac --- /dev/null +++ b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs @@ -0,0 +1,51 @@ +#![feature(or_patterns)] +#![feature(slice_patterns)] +#![allow(incomplete_features)] +#![deny(unreachable_patterns)] + +// We wrap patterns in a tuple because top-level or-patterns are special-cased for now. +fn main() { + // Get the fatal error out of the way + match (0u8,) { + (0 | _,) => {} + //~^ ERROR or-patterns are not fully implemented yet + } + + match (0u8,) { + (1 | 2,) => {} + (1,) => {} //~ ERROR unreachable pattern + _ => {} + } + match (0u8,) { + (1 | 2,) => {} + (2,) => {} //~ ERROR unreachable pattern + _ => {} + } + match (0u8,) { + (1,) => {} + (2,) => {} + (1 | 2,) => {} //~ ERROR unreachable pattern + _ => {} + } + match (0u8, 0u8) { + (1 | 2, 3 | 4) => {} + (1, 3) => {} //~ ERROR unreachable pattern + (1, 4) => {} //~ ERROR unreachable pattern + (2, 4) => {} //~ ERROR unreachable pattern + (2 | 1, 4) => {} //~ ERROR unreachable pattern + (1, 5 | 6) => {} + (1, 4 | 5) => {} //~ ERROR unreachable pattern + _ => {} + } + match (Some(0u8),) { + (None | Some(1 | 2),) => {} + (Some(1),) => {} //~ ERROR unreachable pattern + (None,) => {} //~ ERROR unreachable pattern + _ => {} + } + match ((0u8,),) { + ((1 | 2,) | (3 | 4,),) => {}, + ((1..=4,),) => {}, //~ ERROR unreachable pattern + _ => {}, + } +} diff --git a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr new file mode 100644 index 00000000000..a4d55d805c3 --- /dev/null +++ b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr @@ -0,0 +1,80 @@ +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:16:9 + | +LL | (1,) => {} + | ^^^^ + | +note: lint level defined here + --> $DIR/exhaustiveness-unreachable-pattern.rs:4:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:21:9 + | +LL | (2,) => {} + | ^^^^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:27:9 + | +LL | (1 | 2,) => {} + | ^^^^^^^^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:32:9 + | +LL | (1, 3) => {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:33:9 + | +LL | (1, 4) => {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:34:9 + | +LL | (2, 4) => {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:35:9 + | +LL | (2 | 1, 4) => {} + | ^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:37:9 + | +LL | (1, 4 | 5) => {} + | ^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:42:9 + | +LL | (Some(1),) => {} + | ^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:43:9 + | +LL | (None,) => {} + | ^^^^^^^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:48:9 + | +LL | ((1..=4,),) => {}, + | ^^^^^^^^^^^ + +error: or-patterns are not fully implemented yet + --> $DIR/exhaustiveness-unreachable-pattern.rs:10:10 + | +LL | (0 | _,) => {} + | ^^^^^ + +error: aborting due to 12 previous errors + -- cgit 1.4.1-3-g733a5 From b41b1d3407068fad2fc0f4e0cc7db92cb3589bc6 Mon Sep 17 00:00:00 2001 From: Victor Ding Date: Fri, 29 Nov 2019 14:31:09 +1100 Subject: Use LLVMAddAnalysisPasses instead of Rust's wrapper LLVM exposes a C API `LLVMAddAnalysisPasses` and hence Rust's own wrapper `LLVMRustAddAnalysisPasses` is not needed anymore. --- src/librustc_codegen_llvm/back/lto.rs | 2 +- src/librustc_codegen_llvm/back/write.rs | 6 +++--- src/librustc_codegen_llvm/llvm/ffi.rs | 3 ++- src/rustllvm/PassWrapper.cpp | 11 ----------- 4 files changed, 6 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs index b3be3d09f17..d0b065ccc84 100644 --- a/src/librustc_codegen_llvm/back/lto.rs +++ b/src/librustc_codegen_llvm/back/lto.rs @@ -541,7 +541,7 @@ pub(crate) fn run_pass_manager(cgcx: &CodegenContext, debug!("running the pass manager"); unsafe { let pm = llvm::LLVMCreatePassManager(); - llvm::LLVMRustAddAnalysisPasses(module.module_llvm.tm, pm, module.module_llvm.llmod()); + llvm::LLVMAddAnalysisPasses(module.module_llvm.tm, pm); if config.verify_llvm_ir { let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr().cast()); diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs index 6cc7b0b4b1e..5dfb04a4436 100644 --- a/src/librustc_codegen_llvm/back/write.rs +++ b/src/librustc_codegen_llvm/back/write.rs @@ -384,8 +384,8 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext, // we'll get errors in LLVM. let using_thin_buffers = config.bitcode_needed(); if !config.no_prepopulate_passes { - llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod); - llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod); + llvm::LLVMAddAnalysisPasses(tm, fpm); + llvm::LLVMAddAnalysisPasses(tm, mpm); let opt_level = to_llvm_opt_settings(opt_level).0; let prepare_for_thin_lto = cgcx.lto == Lto::Thin || cgcx.lto == Lto::ThinLocal || (cgcx.lto != Lto::Fat && cgcx.opts.cg.linker_plugin_lto.enabled()); @@ -509,7 +509,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext, where F: FnOnce(&'ll mut PassManager<'ll>) -> R, { let cpm = llvm::LLVMCreatePassManager(); - llvm::LLVMRustAddAnalysisPasses(tm, cpm, llmod); + llvm::LLVMAddAnalysisPasses(tm, cpm); llvm::LLVMRustAddLibraryInfo(cpm, llmod, no_builtins); f(cpm) } diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs index 241ca695e5f..a49e863fa21 100644 --- a/src/librustc_codegen_llvm/llvm/ffi.rs +++ b/src/librustc_codegen_llvm/llvm/ffi.rs @@ -1341,6 +1341,8 @@ extern "C" { pub fn LLVMInitializePasses(); + pub fn LLVMAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>); + pub fn LLVMPassManagerBuilderCreate() -> &'static mut PassManagerBuilder; pub fn LLVMPassManagerBuilderDispose(PMB: &'static mut PassManagerBuilder); pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: &PassManagerBuilder, Value: Bool); @@ -1703,7 +1705,6 @@ extern "C" { EmitStackSizeSection: bool) -> Option<&'static mut TargetMachine>; pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine); - pub fn LLVMRustAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>, M: &'a Module); pub fn LLVMRustAddBuilderLibraryInfo(PMB: &'a PassManagerBuilder, M: &'a Module, DisableSimplifyLibCalls: bool); diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index e2bb49699e9..a116ed282ac 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -445,17 +445,6 @@ extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) { delete unwrap(TM); } -// Unfortunately, LLVM doesn't expose a C API to add the corresponding analysis -// passes for a target to a pass manager. We export that functionality through -// this function. -extern "C" void LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM, - LLVMPassManagerRef PMR, - LLVMModuleRef M) { - PassManagerBase *PM = unwrap(PMR); - PM->add( - createTargetTransformInfoWrapperPass(unwrap(TM)->getTargetIRAnalysis())); -} - extern "C" void LLVMRustConfigurePassManagerBuilder( LLVMPassManagerBuilderRef PMBR, LLVMRustCodeGenOptLevel OptLevel, bool MergeFunctions, bool SLPVectorize, bool LoopVectorize, bool PrepareForThinLTO, -- cgit 1.4.1-3-g733a5 From 45c4e11e43e177056d87b15ea4bddbf03a469036 Mon Sep 17 00:00:00 2001 From: Tomasz Miąsko Date: Fri, 29 Nov 2019 00:00:00 +0000 Subject: SimplifyArmIdentity only for locals with the same type Co-Authored-By: Mazdak Farrokhzad --- src/librustc_mir/transform/simplify_try.rs | 8 +++- src/test/mir-opt/simplify-arm-identity.rs | 75 ++++++++++++++++++++++++++++++ src/test/ui/issues/issue-66851.rs | 20 ++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/test/mir-opt/simplify-arm-identity.rs create mode 100644 src/test/ui/issues/issue-66851.rs (limited to 'src') diff --git a/src/librustc_mir/transform/simplify_try.rs b/src/librustc_mir/transform/simplify_try.rs index de5c2ebb571..9dc5daa9b07 100644 --- a/src/librustc_mir/transform/simplify_try.rs +++ b/src/librustc_mir/transform/simplify_try.rs @@ -34,7 +34,8 @@ pub struct SimplifyArmIdentity; impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) { - for bb in body.basic_blocks_mut() { + let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); + for bb in basic_blocks { // Need 3 statements: let (s0, s1, s2) = match &mut *bb.statements { [s0, s1, s2] => (s0, s1, s2), @@ -51,7 +52,12 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { Some(x) => x, }; if local_tmp_s0 != local_tmp_s1 + // The field-and-variant information match up. || vf_s0 != vf_s1 + // Source and target locals have the same type. + // FIXME(Centril | oli-obk): possibly relax to same layout? + || local_decls[local_0].ty != local_decls[local_1].ty + // We're setting the discriminant of `local_0` to this variant. || Some((local_0, vf_s0.var_idx)) != match_set_discr(s2) { continue; diff --git a/src/test/mir-opt/simplify-arm-identity.rs b/src/test/mir-opt/simplify-arm-identity.rs new file mode 100644 index 00000000000..a8fa64255fb --- /dev/null +++ b/src/test/mir-opt/simplify-arm-identity.rs @@ -0,0 +1,75 @@ +// Checks that `SimplifyArmIdentity` is not applied if enums have incompatible layouts. +// Regression test for issue #66856. +// +// compile-flags: -Zmir-opt-level=2 + +enum Src { + Foo(u8), + Bar, +} + +enum Dst { + Foo(u8), +} + +fn main() { + let e: Src = Src::Foo(0); + let _: Dst = match e { + Src::Foo(x) => Dst::Foo(x), + Src::Bar => Dst::Foo(0), + }; +} + +// END RUST SOURCE +// START rustc.main.SimplifyArmIdentity.before.mir +// fn main() -> () { +// ... +// bb0: { +// StorageLive(_1); +// ((_1 as Foo).0: u8) = const 0u8; +// discriminant(_1) = 0; +// StorageLive(_2); +// _3 = discriminant(_1); +// switchInt(move _3) -> [0isize: bb3, 1isize: bb1, otherwise: bb2]; +// } +// bb1: { +// ((_2 as Foo).0: u8) = const 0u8; +// discriminant(_2) = 0; +// goto -> bb4; +// } +// ... +// bb3: { +// _4 = ((_1 as Foo).0: u8); +// ((_2 as Foo).0: u8) = move _4; +// discriminant(_2) = 0; +// goto -> bb4; +// } +// ... +// } +// END rustc.main.SimplifyArmIdentity.before.mir +// START rustc.main.SimplifyArmIdentity.after.mir +// fn main() -> () { +// ... +// bb0: { +// StorageLive(_1); +// ((_1 as Foo).0: u8) = const 0u8; +// discriminant(_1) = 0; +// StorageLive(_2); +// _3 = discriminant(_1); +// switchInt(move _3) -> [0isize: bb3, 1isize: bb1, otherwise: bb2]; +// } +// bb1: { +// ((_2 as Foo).0: u8) = const 0u8; +// discriminant(_2) = 0; +// goto -> bb4; +// } +// ... +// bb3: { +// _4 = ((_1 as Foo).0: u8); +// ((_2 as Foo).0: u8) = move _4; +// discriminant(_2) = 0; +// goto -> bb4; +// } +// ... +// } +// END rustc.main.SimplifyArmIdentity.after.mir diff --git a/src/test/ui/issues/issue-66851.rs b/src/test/ui/issues/issue-66851.rs new file mode 100644 index 00000000000..72d62a30a33 --- /dev/null +++ b/src/test/ui/issues/issue-66851.rs @@ -0,0 +1,20 @@ +// This used to mis-compile because the mir-opt `SimplifyArmIdentity` +// did not check that the types matched up in the `Ok(r)` branch. +// +// run-pass +// compile-flags: -Zmir-opt-level=2 + +#[derive(Debug, PartialEq, Eq)] +enum SpecialsRes { Res(u64) } + +fn e103() -> SpecialsRes { + if let Ok(r) = "1".parse() { + SpecialsRes::Res(r) + } else { + SpecialsRes::Res(42) + } +} + +fn main() { + assert_eq!(e103(), SpecialsRes::Res(1)); +} -- cgit 1.4.1-3-g733a5 From de30d319761c6fed04c87a41e62828d0b275e01e Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sat, 30 Nov 2019 01:13:47 +0200 Subject: rustc: fix ty::Const::eval's handling of inference variables. --- src/librustc/ty/sty.rs | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index b72468a6ff9..aa5b1c7315a 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -2330,22 +2330,43 @@ impl<'tcx> Const<'tcx> { tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ) -> &Const<'tcx> { - // FIXME(const_generics): this doesn't work right now, - // because it tries to relate an `Infer` to a `Param`. + let try_const_eval = |did, param_env: ParamEnv<'tcx>, substs| { + let param_env_and_substs = param_env.with_reveal_all().and(substs); + + // Avoid querying `tcx.const_eval(...)` with any e.g. inference vars. + if param_env_and_substs.has_local_value() { + return None; + } + + let (param_env, substs) = param_env_and_substs.into_parts(); + + // try to resolve e.g. associated constants to their definition on an impl + let instance = ty::Instance::resolve(tcx, param_env, did, substs)?; + let gid = GlobalId { + instance, + promoted: None, + }; + tcx.const_eval(param_env.and(gid)).ok() + }; + match self.val { ConstKind::Unevaluated(did, substs) => { - // if `substs` has no unresolved components, use and empty param_env - let (param_env, substs) = param_env.with_reveal_all().and(substs).into_parts(); - // try to resolve e.g. associated constants to their definition on an impl - let instance = match ty::Instance::resolve(tcx, param_env, did, substs) { - Some(instance) => instance, - None => return self, - }; - let gid = GlobalId { - instance, - promoted: None, - }; - tcx.const_eval(param_env.and(gid)).unwrap_or(self) + // HACK(eddyb) when substs contain e.g. inference variables, + // attempt using identity substs instead, that will succeed + // when the expression doesn't depend on any parameters. + // FIXME(eddyb) make `const_eval` a canonical query instead, + // that would properly handle inference variables in `substs`. + if substs.has_local_value() { + let identity_substs = InternalSubsts::identity_for_item(tcx, did); + // The `ParamEnv` needs to match the `identity_substs`. + let identity_param_env = tcx.param_env(did); + match try_const_eval(did, identity_param_env, identity_substs) { + Some(ct) => ct.subst(tcx, substs), + None => self, + } + } else { + try_const_eval(did, param_env, substs).unwrap_or(self) + } }, _ => self, } -- cgit 1.4.1-3-g733a5 From 584ede5f3034af8b1b64518385e201de4942637c Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sat, 30 Nov 2019 01:15:15 +0200 Subject: rustc_typeck: gate AnonConst's generics on feature(const_generics). --- src/librustc_typeck/collect.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 652f081e176..301b0ff3503 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -909,14 +909,12 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics { let parent_id = tcx.hir().get_parent_item(hir_id); Some(tcx.hir().local_def_id(parent_id)) } - // FIXME(#43408) enable this in all cases when we get lazy normalization. - Node::AnonConst(&anon_const) => { - // HACK(eddyb) this provides the correct generics when the workaround - // for a const parameter `AnonConst` is being used elsewhere, as then - // there won't be the kind of cyclic dependency blocking #43408. - let expr = &tcx.hir().body(anon_const.body).value; - let icx = ItemCtxt::new(tcx, def_id); - if AstConv::const_param_def_id(&icx, expr).is_some() { + // FIXME(#43408) enable this always when we get lazy normalization. + Node::AnonConst(_) => { + // HACK(eddyb) this provides the correct generics when + // `feature(const_generics)` is enabled, so that const expressions + // used with const generics, e.g. `Foo<{N+1}>`, can work at all. + if tcx.features().const_generics { let parent_id = tcx.hir().get_parent_item(hir_id); Some(tcx.hir().local_def_id(parent_id)) } else { -- cgit 1.4.1-3-g733a5 From 3d080a4a77274abd747f780b446e6fedce14fac7 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 00:23:38 +0100 Subject: introduce crate rustc_feature and move active, accepted, and removed to it --- Cargo.lock | 14 + src/librustc/Cargo.toml | 1 + src/librustc/arena.rs | 2 +- src/librustc/ich/impls_syntax.rs | 3 +- src/librustc/query/mod.rs | 2 +- src/librustc/session/mod.rs | 7 +- src/librustc/ty/context.rs | 3 +- src/librustc/ty/query/mod.rs | 1 - src/librustc_feature/Cargo.toml | 13 + src/librustc_feature/accepted.rs | 265 +++++++++++++ src/librustc_feature/active.rs | 553 +++++++++++++++++++++++++++ src/librustc_feature/lib.rs | 61 +++ src/librustc_feature/removed.rs | 116 ++++++ src/librustc_lint/Cargo.toml | 1 + src/librustc_lint/builtin.rs | 4 +- src/librustc_parse/Cargo.toml | 1 + src/librustc_parse/config.rs | 2 +- src/librustc_passes/Cargo.toml | 1 + src/librustc_passes/check_const.rs | 3 +- src/librustdoc/clean/cfg.rs | 2 +- src/librustdoc/lib.rs | 1 + src/libsyntax/Cargo.toml | 1 + src/libsyntax/attr/builtin.rs | 3 +- src/libsyntax/feature_gate/accepted.rs | 265 ------------- src/libsyntax/feature_gate/active.rs | 554 ---------------------------- src/libsyntax/feature_gate/builtin_attrs.rs | 4 +- src/libsyntax/feature_gate/check.rs | 5 +- src/libsyntax/feature_gate/mod.rs | 71 ---- src/libsyntax/feature_gate/removed.rs | 116 ------ src/libsyntax/lib.rs | 15 +- src/libsyntax_expand/Cargo.toml | 1 + src/libsyntax_expand/expand.rs | 5 +- src/libsyntax_expand/mbe/macro_rules.rs | 2 +- src/libsyntax_ext/Cargo.toml | 1 + src/libsyntax_ext/test_harness.rs | 2 +- 35 files changed, 1068 insertions(+), 1033 deletions(-) create mode 100644 src/librustc_feature/Cargo.toml create mode 100644 src/librustc_feature/accepted.rs create mode 100644 src/librustc_feature/active.rs create mode 100644 src/librustc_feature/lib.rs create mode 100644 src/librustc_feature/removed.rs delete mode 100644 src/libsyntax/feature_gate/accepted.rs delete mode 100644 src/libsyntax/feature_gate/active.rs delete mode 100644 src/libsyntax/feature_gate/mod.rs delete mode 100644 src/libsyntax/feature_gate/removed.rs (limited to 'src') diff --git a/Cargo.lock b/Cargo.lock index d27eec893b0..9ed2f021344 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3199,6 +3199,7 @@ dependencies = [ "rustc_data_structures", "rustc_error_codes", "rustc_errors", + "rustc_feature", "rustc_fs_util", "rustc_index", "rustc_macros", @@ -3607,6 +3608,13 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "rustc_feature" +version = "0.0.0" +dependencies = [ + "syntax_pos", +] + [[package]] name = "rustc_fs_util" version = "0.0.0" @@ -3682,6 +3690,7 @@ dependencies = [ "rustc", "rustc_data_structures", "rustc_error_codes", + "rustc_feature", "rustc_index", "rustc_target", "syntax", @@ -3786,6 +3795,7 @@ dependencies = [ "rustc_data_structures", "rustc_error_codes", "rustc_errors", + "rustc_feature", "rustc_lexer", "rustc_target", "smallvec 1.0.0", @@ -3802,6 +3812,7 @@ dependencies = [ "rustc_data_structures", "rustc_error_codes", "rustc_errors", + "rustc_feature", "rustc_index", "rustc_parse", "rustc_target", @@ -4442,6 +4453,7 @@ dependencies = [ "rustc_data_structures", "rustc_error_codes", "rustc_errors", + "rustc_feature", "rustc_index", "rustc_lexer", "rustc_macros", @@ -4458,6 +4470,7 @@ dependencies = [ "log", "rustc_data_structures", "rustc_errors", + "rustc_feature", "rustc_lexer", "rustc_parse", "serialize", @@ -4475,6 +4488,7 @@ dependencies = [ "rustc_data_structures", "rustc_error_codes", "rustc_errors", + "rustc_feature", "rustc_parse", "rustc_target", "smallvec 1.0.0", diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml index 6c1695a4eac..fb30d6c519c 100644 --- a/src/librustc/Cargo.toml +++ b/src/librustc/Cargo.toml @@ -22,6 +22,7 @@ rustc-rayon = "0.3.0" rustc-rayon-core = "0.3.0" polonius-engine = "0.10.0" rustc_apfloat = { path = "../librustc_apfloat" } +rustc_feature = { path = "../librustc_feature" } rustc_target = { path = "../librustc_target" } rustc_macros = { path = "../librustc_macros" } rustc_data_structures = { path = "../librustc_data_structures" } diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index 9b13a910c61..c3b810d04eb 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -100,7 +100,7 @@ macro_rules! arena_types { [few] resolve_lifetimes: rustc::middle::resolve_lifetime::ResolveLifetimes, [few] lint_levels: rustc::lint::LintLevelMap, [few] stability_index: rustc::middle::stability::Index<'tcx>, - [few] features: syntax::feature_gate::Features, + [few] features: rustc_feature::Features, [few] all_traits: Vec, [few] privacy_access_levels: rustc::middle::privacy::AccessLevels, [few] target_features_whitelist: rustc_data_structures::fx::FxHashMap< diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index 144980c53eb..6499e56325a 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -4,7 +4,6 @@ use crate::ich::StableHashingContext; use syntax::ast; -use syntax::feature_gate; use syntax_pos::SourceFile; use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX}; @@ -156,7 +155,7 @@ fn stable_normalized_pos(np: ::syntax_pos::NormalizedPos, } -impl<'tcx> HashStable> for feature_gate::Features { +impl<'tcx> HashStable> for rustc_feature::Features { fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { // Unfortunately we cannot exhaustively list fields here, since the // struct is macro generated. diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index cd93fed8e1e..d715ddb1b81 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -1130,7 +1130,7 @@ rustc_queries! { desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) } } - query features_query(_: CrateNum) -> &'tcx feature_gate::Features { + query features_query(_: CrateNum) -> &'tcx rustc_feature::Features { eval_always desc { "looking up enabled feature gates" } } diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index af6522df61e..0ee8107cb14 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -21,7 +21,6 @@ use errors::emitter::{Emitter, EmitterWriter}; use errors::emitter::HumanReadableErrorType; use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter}; use syntax::edition::Edition; -use syntax::feature_gate; use errors::json::JsonEmitter; use syntax::source_map; use syntax::sess::ParseSess; @@ -86,7 +85,7 @@ pub struct Session { /// `rustc_codegen_llvm::back::symbol_names` module for more information. pub crate_disambiguator: Once, - features: Once, + features: Once, /// The maximum recursion limit for potentially infinitely recursive /// operations such as auto-dereference and monomorphization. @@ -473,11 +472,11 @@ impl Session { /// DO NOT USE THIS METHOD if there is a TyCtxt available, as it circumvents /// dependency tracking. Use tcx.features() instead. #[inline] - pub fn features_untracked(&self) -> &feature_gate::Features { + pub fn features_untracked(&self) -> &rustc_feature::Features { self.features.get() } - pub fn init_features(&self, features: feature_gate::Features) { + pub fn init_features(&self, features: rustc_feature::Features) { self.features.set(features); } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 95456581169..d2f9312a482 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -72,7 +72,6 @@ use rustc_macros::HashStable; use syntax::ast; use syntax::attr; use syntax::source_map::MultiSpan; -use syntax::feature_gate; use syntax::symbol::{Symbol, kw, sym}; use syntax_pos::Span; use syntax::expand::allocator::AllocatorKind; @@ -1315,7 +1314,7 @@ impl<'tcx> TyCtxt<'tcx> { self.cstore.allocator_kind() } - pub fn features(self) -> &'tcx feature_gate::Features { + pub fn features(self) -> &'tcx rustc_feature::Features { self.features_query(LOCAL_CRATE) } diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index a1eb1c43335..5b4a6ac8a2d 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -56,7 +56,6 @@ use std::any::type_name; use syntax_pos::{Span, DUMMY_SP}; use syntax::attr; use syntax::ast; -use syntax::feature_gate; use syntax::symbol::Symbol; #[macro_use] diff --git a/src/librustc_feature/Cargo.toml b/src/librustc_feature/Cargo.toml new file mode 100644 index 00000000000..22e8366804b --- /dev/null +++ b/src/librustc_feature/Cargo.toml @@ -0,0 +1,13 @@ +[package] +authors = ["The Rust Project Developers"] +name = "rustc_feature" +version = "0.0.0" +edition = "2018" + +[lib] +name = "rustc_feature" +path = "lib.rs" +doctest = false + +[dependencies] +syntax_pos = { path = "../libsyntax_pos" } diff --git a/src/librustc_feature/accepted.rs b/src/librustc_feature/accepted.rs new file mode 100644 index 00000000000..fec5a7f1a45 --- /dev/null +++ b/src/librustc_feature/accepted.rs @@ -0,0 +1,265 @@ +//! List of the accepted feature gates. + +use super::{State, Feature}; +use syntax_pos::symbol::sym; + +macro_rules! declare_features { + ($( + $(#[doc = $doc:tt])* (accepted, $feature:ident, $ver:expr, $issue:expr, None), + )+) => { + /// Those language feature has since been Accepted (it was once Active) + pub const ACCEPTED_FEATURES: &[Feature] = &[ + $( + Feature { + state: State::Accepted, + name: sym::$feature, + since: $ver, + issue: $issue, + edition: None, + description: concat!($($doc,)*), + } + ),+ + ]; + } +} + +declare_features! ( + // ------------------------------------------------------------------------- + // feature-group-start: for testing purposes + // ------------------------------------------------------------------------- + + /// A temporary feature gate used to enable parser extensions needed + /// to bootstrap fix for #5723. + (accepted, issue_5723_bootstrap, "1.0.0", None, None), + /// These are used to test this portion of the compiler, + /// they don't actually mean anything. + (accepted, test_accepted_feature, "1.0.0", None, None), + + // ------------------------------------------------------------------------- + // feature-group-end: for testing purposes + // ------------------------------------------------------------------------- + + // ------------------------------------------------------------------------- + // feature-group-start: accepted features + // ------------------------------------------------------------------------- + + /// Allows using associated `type`s in `trait`s. + (accepted, associated_types, "1.0.0", None, None), + /// Allows using assigning a default type to type parameters in algebraic data type definitions. + (accepted, default_type_params, "1.0.0", None, None), + // FIXME: explain `globs`. + (accepted, globs, "1.0.0", None, None), + /// Allows `macro_rules!` items. + (accepted, macro_rules, "1.0.0", None, None), + /// Allows use of `&foo[a..b]` as a slicing syntax. + (accepted, slicing_syntax, "1.0.0", None, None), + /// Allows struct variants `Foo { baz: u8, .. }` in enums (RFC 418). + (accepted, struct_variant, "1.0.0", None, None), + /// Allows indexing tuples. + (accepted, tuple_indexing, "1.0.0", None, None), + /// Allows the use of `if let` expressions. + (accepted, if_let, "1.0.0", None, None), + /// Allows the use of `while let` expressions. + (accepted, while_let, "1.0.0", None, None), + /// Allows using `#![no_std]`. + (accepted, no_std, "1.6.0", None, None), + /// Allows overloading augmented assignment operations like `a += b`. + (accepted, augmented_assignments, "1.8.0", Some(28235), None), + /// Allows empty structs and enum variants with braces. + (accepted, braced_empty_structs, "1.8.0", Some(29720), None), + /// Allows `#[deprecated]` attribute. + (accepted, deprecated, "1.9.0", Some(29935), None), + /// Allows macros to appear in the type position. + (accepted, type_macros, "1.13.0", Some(27245), None), + /// Allows use of the postfix `?` operator in expressions. + (accepted, question_mark, "1.13.0", Some(31436), None), + /// Allows `..` in tuple (struct) patterns. + (accepted, dotdot_in_tuple_patterns, "1.14.0", Some(33627), None), + /// Allows some increased flexibility in the name resolution rules, + /// especially around globs and shadowing (RFC 1560). + (accepted, item_like_imports, "1.15.0", Some(35120), None), + /// Allows using `Self` and associated types in struct expressions and patterns. + (accepted, more_struct_aliases, "1.16.0", Some(37544), None), + /// Allows elision of `'static` lifetimes in `static`s and `const`s. + (accepted, static_in_const, "1.17.0", Some(35897), None), + /// Allows field shorthands (`x` meaning `x: x`) in struct literal expressions. + (accepted, field_init_shorthand, "1.17.0", Some(37340), None), + /// Allows the definition recursive static items. + (accepted, static_recursion, "1.17.0", Some(29719), None), + /// Allows `pub(restricted)` visibilities (RFC 1422). + (accepted, pub_restricted, "1.18.0", Some(32409), None), + /// Allows `#![windows_subsystem]`. + (accepted, windows_subsystem, "1.18.0", Some(37499), None), + /// Allows `break {expr}` with a value inside `loop`s. + (accepted, loop_break_value, "1.19.0", Some(37339), None), + /// Allows numeric fields in struct expressions and patterns. + (accepted, relaxed_adts, "1.19.0", Some(35626), None), + /// Allows coercing non capturing closures to function pointers. + (accepted, closure_to_fn_coercion, "1.19.0", Some(39817), None), + /// Allows attributes on struct literal fields. + (accepted, struct_field_attributes, "1.20.0", Some(38814), None), + /// Allows the definition of associated constants in `trait` or `impl` blocks. + (accepted, associated_consts, "1.20.0", Some(29646), None), + /// Allows usage of the `compile_error!` macro. + (accepted, compile_error, "1.20.0", Some(40872), None), + /// Allows code like `let x: &'static u32 = &42` to work (RFC 1414). + (accepted, rvalue_static_promotion, "1.21.0", Some(38865), None), + /// Allows `Drop` types in constants (RFC 1440). + (accepted, drop_types_in_const, "1.22.0", Some(33156), None), + /// Allows the sysV64 ABI to be specified on all platforms + /// instead of just the platforms on which it is the C ABI. + (accepted, abi_sysv64, "1.24.0", Some(36167), None), + /// Allows `repr(align(16))` struct attribute (RFC 1358). + (accepted, repr_align, "1.25.0", Some(33626), None), + /// Allows '|' at beginning of match arms (RFC 1925). + (accepted, match_beginning_vert, "1.25.0", Some(44101), None), + /// Allows nested groups in `use` items (RFC 2128). + (accepted, use_nested_groups, "1.25.0", Some(44494), None), + /// Allows indexing into constant arrays. + (accepted, const_indexing, "1.26.0", Some(29947), None), + /// Allows using `a..=b` and `..=b` as inclusive range syntaxes. + (accepted, inclusive_range_syntax, "1.26.0", Some(28237), None), + /// Allows `..=` in patterns (RFC 1192). + (accepted, dotdoteq_in_patterns, "1.26.0", Some(28237), None), + /// Allows `fn main()` with return types which implements `Termination` (RFC 1937). + (accepted, termination_trait, "1.26.0", Some(43301), None), + /// Allows implementing `Clone` for closures where possible (RFC 2132). + (accepted, clone_closures, "1.26.0", Some(44490), None), + /// Allows implementing `Copy` for closures where possible (RFC 2132). + (accepted, copy_closures, "1.26.0", Some(44490), None), + /// Allows `impl Trait` in function arguments. + (accepted, universal_impl_trait, "1.26.0", Some(34511), None), + /// Allows `impl Trait` in function return types. + (accepted, conservative_impl_trait, "1.26.0", Some(34511), None), + /// Allows using the `u128` and `i128` types. + (accepted, i128_type, "1.26.0", Some(35118), None), + /// Allows default match binding modes (RFC 2005). + (accepted, match_default_bindings, "1.26.0", Some(42640), None), + /// Allows `'_` placeholder lifetimes. + (accepted, underscore_lifetimes, "1.26.0", Some(44524), None), + /// Allows attributes on lifetime/type formal parameters in generics (RFC 1327). + (accepted, generic_param_attrs, "1.27.0", Some(48848), None), + /// Allows `cfg(target_feature = "...")`. + (accepted, cfg_target_feature, "1.27.0", Some(29717), None), + /// Allows `#[target_feature(...)]`. + (accepted, target_feature, "1.27.0", None, None), + /// Allows using `dyn Trait` as a syntax for trait objects. + (accepted, dyn_trait, "1.27.0", Some(44662), None), + /// Allows `#[must_use]` on functions, and introduces must-use operators (RFC 1940). + (accepted, fn_must_use, "1.27.0", Some(43302), None), + /// Allows use of the `:lifetime` macro fragment specifier. + (accepted, macro_lifetime_matcher, "1.27.0", Some(34303), None), + /// Allows `#[test]` functions where the return type implements `Termination` (RFC 1937). + (accepted, termination_trait_test, "1.27.0", Some(48854), None), + /// Allows the `#[global_allocator]` attribute. + (accepted, global_allocator, "1.28.0", Some(27389), None), + /// Allows `#[repr(transparent)]` attribute on newtype structs. + (accepted, repr_transparent, "1.28.0", Some(43036), None), + /// Allows procedural macros in `proc-macro` crates. + (accepted, proc_macro, "1.29.0", Some(38356), None), + /// Allows `foo.rs` as an alternative to `foo/mod.rs`. + (accepted, non_modrs_mods, "1.30.0", Some(44660), None), + /// Allows use of the `:vis` macro fragment specifier + (accepted, macro_vis_matcher, "1.30.0", Some(41022), None), + /// Allows importing and reexporting macros with `use`, + /// enables macro modularization in general. + (accepted, use_extern_macros, "1.30.0", Some(35896), None), + /// Allows keywords to be escaped for use as identifiers. + (accepted, raw_identifiers, "1.30.0", Some(48589), None), + /// Allows attributes scoped to tools. + (accepted, tool_attributes, "1.30.0", Some(44690), None), + /// Allows multi-segment paths in attributes and derives. + (accepted, proc_macro_path_invoc, "1.30.0", Some(38356), None), + /// Allows all literals in attribute lists and values of key-value pairs. + (accepted, attr_literals, "1.30.0", Some(34981), None), + /// Allows inferring outlives requirements (RFC 2093). + (accepted, infer_outlives_requirements, "1.30.0", Some(44493), None), + /// Allows annotating functions conforming to `fn(&PanicInfo) -> !` with `#[panic_handler]`. + /// This defines the behavior of panics. + (accepted, panic_handler, "1.30.0", Some(44489), None), + /// Allows `#[used]` to preserve symbols (see llvm.used). + (accepted, used, "1.30.0", Some(40289), None), + /// Allows `crate` in paths. + (accepted, crate_in_paths, "1.30.0", Some(45477), None), + /// Allows resolving absolute paths as paths from other crates. + (accepted, extern_absolute_paths, "1.30.0", Some(44660), None), + /// Allows access to crate names passed via `--extern` through prelude. + (accepted, extern_prelude, "1.30.0", Some(44660), None), + /// Allows parentheses in patterns. + (accepted, pattern_parentheses, "1.31.0", Some(51087), None), + /// Allows the definition of `const fn` functions. + (accepted, min_const_fn, "1.31.0", Some(53555), None), + /// Allows scoped lints. + (accepted, tool_lints, "1.31.0", Some(44690), None), + /// Allows lifetime elision in `impl` headers. For example: + /// + `impl Iterator for &mut Iterator` + /// + `impl Debug for Foo<'_>` + (accepted, impl_header_lifetime_elision, "1.31.0", Some(15872), None), + /// Allows `extern crate foo as bar;`. This puts `bar` into extern prelude. + (accepted, extern_crate_item_prelude, "1.31.0", Some(55599), None), + /// Allows use of the `:literal` macro fragment specifier (RFC 1576). + (accepted, macro_literal_matcher, "1.32.0", Some(35625), None), + /// Allows use of `?` as the Kleene "at most one" operator in macros. + (accepted, macro_at_most_once_rep, "1.32.0", Some(48075), None), + /// Allows `Self` struct constructor (RFC 2302). + (accepted, self_struct_ctor, "1.32.0", Some(51994), None), + /// Allows `Self` in type definitions (RFC 2300). + (accepted, self_in_typedefs, "1.32.0", Some(49303), None), + /// Allows `use x::y;` to search `x` in the current scope. + (accepted, uniform_paths, "1.32.0", Some(53130), None), + /// Allows integer match exhaustiveness checking (RFC 2591). + (accepted, exhaustive_integer_patterns, "1.33.0", Some(50907), None), + /// Allows `use path as _;` and `extern crate c as _;`. + (accepted, underscore_imports, "1.33.0", Some(48216), None), + /// Allows `#[repr(packed(N))]` attribute on structs. + (accepted, repr_packed, "1.33.0", Some(33158), None), + /// Allows irrefutable patterns in `if let` and `while let` statements (RFC 2086). + (accepted, irrefutable_let_patterns, "1.33.0", Some(44495), None), + /// Allows calling `const unsafe fn` inside `unsafe` blocks in `const fn` functions. + (accepted, min_const_unsafe_fn, "1.33.0", Some(55607), None), + /// Allows let bindings, assignments and destructuring in `const` functions and constants. + /// As long as control flow is not implemented in const eval, `&&` and `||` may not be used + /// at the same time as let bindings. + (accepted, const_let, "1.33.0", Some(48821), None), + /// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`. + (accepted, cfg_attr_multi, "1.33.0", Some(54881), None), + /// Allows top level or-patterns (`p | q`) in `if let` and `while let`. + (accepted, if_while_or_patterns, "1.33.0", Some(48215), None), + /// Allows `cfg(target_vendor = "...")`. + (accepted, cfg_target_vendor, "1.33.0", Some(29718), None), + /// Allows `extern crate self as foo;`. + /// This puts local crate root into extern prelude under name `foo`. + (accepted, extern_crate_self, "1.34.0", Some(56409), None), + /// Allows arbitrary delimited token streams in non-macro attributes. + (accepted, unrestricted_attribute_tokens, "1.34.0", Some(55208), None), + /// Allows paths to enum variants on type aliases including `Self`. + (accepted, type_alias_enum_variants, "1.37.0", Some(49683), None), + /// Allows using `#[repr(align(X))]` on enums with equivalent semantics + /// to wrapping an enum in a wrapper struct with `#[repr(align(X))]`. + (accepted, repr_align_enum, "1.37.0", Some(57996), None), + /// Allows `const _: TYPE = VALUE`. + (accepted, underscore_const_names, "1.37.0", Some(54912), None), + /// Allows free and inherent `async fn`s, `async` blocks, and `.await` expressions. + (accepted, async_await, "1.39.0", Some(50547), None), + /// Allows mixing bind-by-move in patterns and references to those identifiers in guards. + (accepted, bind_by_move_pattern_guards, "1.39.0", Some(15287), None), + /// Allows attributes in formal function parameters. + (accepted, param_attrs, "1.39.0", Some(60406), None), + /// Allows macro invocations in `extern {}` blocks. + (accepted, macros_in_extern, "1.40.0", Some(49476), None), + /// Allows future-proofing enums/structs with the `#[non_exhaustive]` attribute (RFC 2008). + (accepted, non_exhaustive, "1.40.0", Some(44109), None), + /// Allows calling constructor functions in `const fn`. + (accepted, const_constructor, "1.40.0", Some(61456), None), + /// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests. + (accepted, cfg_doctest, "1.40.0", Some(62210), None), + /// Allows the `!` type. Does not imply 'exhaustive_patterns' any more. + (accepted, never_type, "1.41.0", Some(35121), None), + /// Allows relaxing the coherence rules such that + /// `impl ForeignTrait for ForeignType` is permitted. + (accepted, re_rebalance_coherence, "1.41.0", Some(55437), None), + + // ------------------------------------------------------------------------- + // feature-group-end: accepted features + // ------------------------------------------------------------------------- +); diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs new file mode 100644 index 00000000000..fc1f770e226 --- /dev/null +++ b/src/librustc_feature/active.rs @@ -0,0 +1,553 @@ +//! List of the active feature gates. + +use super::{State, Feature}; + +use syntax_pos::edition::Edition; +use syntax_pos::Span; +use syntax_pos::symbol::{Symbol, sym}; + +macro_rules! set { + ($field: ident) => {{ + fn f(features: &mut Features, _: Span) { + features.$field = true; + } + f as fn(&mut Features, Span) + }} +} + +macro_rules! declare_features { + ($( + $(#[doc = $doc:tt])* (active, $feature:ident, $ver:expr, $issue:expr, $edition:expr), + )+) => { + /// Represents active features that are currently being implemented or + /// currently being considered for addition/removal. + pub const ACTIVE_FEATURES: + &[Feature] = + &[$( + // (sym::$feature, $ver, $issue, $edition, set!($feature)) + Feature { + state: State::Active { set: set!($feature) }, + name: sym::$feature, + since: $ver, + issue: $issue, + edition: $edition, + description: concat!($($doc,)*), + } + ),+]; + + /// A set of features to be used by later passes. + #[derive(Clone)] + pub struct Features { + /// `#![feature]` attrs for language features, for error reporting. + pub declared_lang_features: Vec<(Symbol, Span, Option)>, + /// `#![feature]` attrs for non-language (library) features. + pub declared_lib_features: Vec<(Symbol, Span)>, + $( + $(#[doc = $doc])* + pub $feature: bool + ),+ + } + + impl Features { + pub fn new() -> Features { + Features { + declared_lang_features: Vec::new(), + declared_lib_features: Vec::new(), + $($feature: false),+ + } + } + + pub fn walk_feature_fields(&self, mut f: F) + where F: FnMut(&str, bool) + { + $(f(stringify!($feature), self.$feature);)+ + } + } + }; +} + +impl Feature { + /// Sets this feature in `Features`. Panics if called on a non-active feature. + pub fn set(&self, features: &mut Features, span: Span) { + match self.state { + State::Active { set } => set(features, span), + _ => panic!("called `set` on feature `{}` which is not `active`", self.name) + } + } +} + +// If you change this, please modify `src/doc/unstable-book` as well. +// +// Don't ever remove anything from this list; move them to `removed.rs`. +// +// The version numbers here correspond to the version in which the current status +// was set. This is most important for knowing when a particular feature became +// stable (active). +// +// Note that the features are grouped into internal/user-facing and then +// sorted by version inside those groups. This is enforced with tidy. +// +// N.B., `tools/tidy/src/features.rs` parses this information directly out of the +// source, so take care when modifying it. + +declare_features! ( + // ------------------------------------------------------------------------- + // feature-group-start: internal feature gates + // ------------------------------------------------------------------------- + + // no-tracking-issue-start + + /// Allows using compiler's own crates. + (active, rustc_private, "1.0.0", Some(27812), None), + + /// Allows using the `rust-intrinsic`'s "ABI". + (active, intrinsics, "1.0.0", None, None), + + /// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic. + (active, lang_items, "1.0.0", None, None), + + /// Allows using the `#[stable]` and `#[unstable]` attributes. + (active, staged_api, "1.0.0", None, None), + + /// Allows using `#[allow_internal_unstable]`. This is an + /// attribute on `macro_rules!` and can't use the attribute handling + /// below (it has to be checked before expansion possibly makes + /// macros disappear). + (active, allow_internal_unstable, "1.0.0", None, None), + + /// Allows using `#[allow_internal_unsafe]`. This is an + /// attribute on `macro_rules!` and can't use the attribute handling + /// below (it has to be checked before expansion possibly makes + /// macros disappear). + (active, allow_internal_unsafe, "1.0.0", None, None), + + /// Allows using `#[rustc_const_unstable(feature = "foo", ..)]` which + /// lets a function to be `const` when opted into with `#![feature(foo)]`. + (active, rustc_const_unstable, "1.0.0", None, None), + + /// no-tracking-issue-end + + /// Allows using `#[link_name="llvm.*"]`. + (active, link_llvm_intrinsics, "1.0.0", Some(29602), None), + + /// Allows using `rustc_*` attributes (RFC 572). + (active, rustc_attrs, "1.0.0", Some(29642), None), + + /// Allows using the `box $expr` syntax. + (active, box_syntax, "1.0.0", Some(49733), None), + + /// Allows using `#[main]` to replace the entrypoint `#[lang = "start"]` calls. + (active, main, "1.0.0", Some(29634), None), + + /// Allows using `#[start]` on a function indicating that it is the program entrypoint. + (active, start, "1.0.0", Some(29633), None), + + /// Allows using the `#[fundamental]` attribute. + (active, fundamental, "1.0.0", Some(29635), None), + + /// Allows using the `rust-call` ABI. + (active, unboxed_closures, "1.0.0", Some(29625), None), + + /// Allows using the `#[linkage = ".."]` attribute. + (active, linkage, "1.0.0", Some(29603), None), + + /// Allows features specific to OIBIT (auto traits). + (active, optin_builtin_traits, "1.0.0", Some(13231), None), + + /// Allows using `box` in patterns (RFC 469). + (active, box_patterns, "1.0.0", Some(29641), None), + + // no-tracking-issue-start + + /// Allows using `#[prelude_import]` on glob `use` items. + (active, prelude_import, "1.2.0", None, None), + + // no-tracking-issue-end + + // no-tracking-issue-start + + /// Allows using `#[omit_gdb_pretty_printer_section]`. + (active, omit_gdb_pretty_printer_section, "1.5.0", None, None), + + /// Allows using the `vectorcall` ABI. + (active, abi_vectorcall, "1.7.0", None, None), + + // no-tracking-issue-end + + /// Allows using `#[structural_match]` which indicates that a type is structurally matchable. + (active, structural_match, "1.8.0", Some(31434), None), + + /// Allows using the `may_dangle` attribute (RFC 1327). + (active, dropck_eyepatch, "1.10.0", Some(34761), None), + + /// Allows using the `#![panic_runtime]` attribute. + (active, panic_runtime, "1.10.0", Some(32837), None), + + /// Allows declaring with `#![needs_panic_runtime]` that a panic runtime is needed. + (active, needs_panic_runtime, "1.10.0", Some(32837), None), + + // no-tracking-issue-start + + /// Allows identifying the `compiler_builtins` crate. + (active, compiler_builtins, "1.13.0", None, None), + + /// Allows using the `unadjusted` ABI; perma-unstable. + (active, abi_unadjusted, "1.16.0", None, None), + + /// Allows identifying crates that contain sanitizer runtimes. + (active, sanitizer_runtime, "1.17.0", None, None), + + /// Used to identify crates that contain the profiler runtime. + (active, profiler_runtime, "1.18.0", None, None), + + /// Allows using the `thiscall` ABI. + (active, abi_thiscall, "1.19.0", None, None), + + /// Allows using `#![needs_allocator]`, an implementation detail of `#[global_allocator]`. + (active, allocator_internals, "1.20.0", None, None), + + /// Added for testing E0705; perma-unstable. + (active, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)), + + // no-tracking-issue-end + + // ------------------------------------------------------------------------- + // feature-group-end: internal feature gates + // ------------------------------------------------------------------------- + + // ------------------------------------------------------------------------- + // feature-group-start: actual feature gates (target features) + // ------------------------------------------------------------------------- + + // FIXME: Document these and merge with the list below. + + // Unstable `#[target_feature]` directives. + (active, arm_target_feature, "1.27.0", Some(44839), None), + (active, aarch64_target_feature, "1.27.0", Some(44839), None), + (active, hexagon_target_feature, "1.27.0", Some(44839), None), + (active, powerpc_target_feature, "1.27.0", Some(44839), None), + (active, mips_target_feature, "1.27.0", Some(44839), None), + (active, avx512_target_feature, "1.27.0", Some(44839), None), + (active, mmx_target_feature, "1.27.0", Some(44839), None), + (active, sse4a_target_feature, "1.27.0", Some(44839), None), + (active, tbm_target_feature, "1.27.0", Some(44839), None), + (active, wasm_target_feature, "1.30.0", Some(44839), None), + (active, adx_target_feature, "1.32.0", Some(44839), None), + (active, cmpxchg16b_target_feature, "1.32.0", Some(44839), None), + (active, movbe_target_feature, "1.34.0", Some(44839), None), + (active, rtm_target_feature, "1.35.0", Some(44839), None), + (active, f16c_target_feature, "1.36.0", Some(44839), None), + + // ------------------------------------------------------------------------- + // feature-group-end: actual feature gates (target features) + // ------------------------------------------------------------------------- + + // ------------------------------------------------------------------------- + // feature-group-start: actual feature gates + // ------------------------------------------------------------------------- + + /// Allows using the `#[link_args]` attribute. + (active, link_args, "1.0.0", Some(29596), None), + + /// Allows defining identifiers beyond ASCII. + (active, non_ascii_idents, "1.0.0", Some(55467), None), + + /// Allows using `#[plugin_registrar]` on functions. + (active, plugin_registrar, "1.0.0", Some(29597), None), + + /// Allows using `#![plugin(myplugin)]`. + (active, plugin, "1.0.0", Some(29597), None), + + /// Allows using `#[thread_local]` on `static` items. + (active, thread_local, "1.0.0", Some(29594), None), + + /// Allows the use of SIMD types in functions declared in `extern` blocks. + (active, simd_ffi, "1.0.0", Some(27731), None), + + /// Allows using non lexical lifetimes (RFC 2094). + (active, nll, "1.0.0", Some(43234), None), + + /// Allows using slice patterns. + (active, slice_patterns, "1.0.0", Some(62254), None), + + /// Allows the definition of `const` functions with some advanced features. + (active, const_fn, "1.2.0", Some(57563), None), + + /// Allows associated type defaults. + (active, associated_type_defaults, "1.2.0", Some(29661), None), + + /// Allows `#![no_core]`. + (active, no_core, "1.3.0", Some(29639), None), + + /// Allows default type parameters to influence type inference. + (active, default_type_parameter_fallback, "1.3.0", Some(27336), None), + + /// Allows `repr(simd)` and importing the various simd intrinsics. + (active, repr_simd, "1.4.0", Some(27731), None), + + /// Allows `extern "platform-intrinsic" { ... }`. + (active, platform_intrinsics, "1.4.0", Some(27731), None), + + /// Allows `#[unwind(..)]`. + /// + /// Permits specifying whether a function should permit unwinding or abort on unwind. + (active, unwind_attributes, "1.4.0", Some(58760), None), + + /// Allows `#[no_debug]`. + (active, no_debug, "1.5.0", Some(29721), None), + + /// Allows attributes on expressions and non-item statements. + (active, stmt_expr_attributes, "1.6.0", Some(15701), None), + + /// Allows the use of type ascription in expressions. + (active, type_ascription, "1.6.0", Some(23416), None), + + /// Allows `cfg(target_thread_local)`. + (active, cfg_target_thread_local, "1.7.0", Some(29594), None), + + /// Allows specialization of implementations (RFC 1210). + (active, specialization, "1.7.0", Some(31844), None), + + /// Allows using `#[naked]` on functions. + (active, naked_functions, "1.9.0", Some(32408), None), + + /// Allows `cfg(target_has_atomic = "...")`. + (active, cfg_target_has_atomic, "1.9.0", Some(32976), None), + + /// Allows `X..Y` patterns. + (active, exclusive_range_pattern, "1.11.0", Some(37854), None), + + /// Allows exhaustive pattern matching on types that contain uninhabited types. + (active, exhaustive_patterns, "1.13.0", Some(51085), None), + + /// Allows `union`s to implement `Drop`. Moreover, `union`s may now include fields + /// that don't implement `Copy` as long as they don't have any drop glue. + /// This is checked recursively. On encountering type variable where no progress can be made, + /// `T: Copy` is used as a substitute for "no drop glue". + /// + /// NOTE: A limited form of `union U { ... }` was accepted in 1.19.0. + (active, untagged_unions, "1.13.0", Some(55149), None), + + /// Allows `#[link(..., cfg(..))]`. + (active, link_cfg, "1.14.0", Some(37406), None), + + /// Allows `extern "ptx-*" fn()`. + (active, abi_ptx, "1.15.0", Some(38788), None), + + /// Allows the `#[repr(i128)]` attribute for enums. + (active, repr128, "1.16.0", Some(35118), None), + + /// Allows `#[link(kind="static-nobundle"...)]`. + (active, static_nobundle, "1.16.0", Some(37403), None), + + /// Allows `extern "msp430-interrupt" fn()`. + (active, abi_msp430_interrupt, "1.16.0", Some(38487), None), + + /// Allows declarative macros 2.0 (`macro`). + (active, decl_macro, "1.17.0", Some(39412), None), + + /// Allows `extern "x86-interrupt" fn()`. + (active, abi_x86_interrupt, "1.17.0", Some(40180), None), + + /// Allows overlapping impls of marker traits. + (active, overlapping_marker_traits, "1.18.0", Some(29864), None), + + /// Allows a test to fail without failing the whole suite. + (active, allow_fail, "1.19.0", Some(46488), None), + + /// Allows unsized tuple coercion. + (active, unsized_tuple_coercion, "1.20.0", Some(42877), None), + + /// Allows defining generators. + (active, generators, "1.21.0", Some(43122), None), + + /// Allows `#[doc(cfg(...))]`. + (active, doc_cfg, "1.21.0", Some(43781), None), + + /// Allows `#[doc(masked)]`. + (active, doc_masked, "1.21.0", Some(44027), None), + + /// Allows `#[doc(spotlight)]`. + (active, doc_spotlight, "1.22.0", Some(45040), None), + + /// Allows `#[doc(include = "some-file")]`. + (active, external_doc, "1.22.0", Some(44732), None), + + /// Allows using `crate` as visibility modifier, synonymous with `pub(crate)`. + (active, crate_visibility_modifier, "1.23.0", Some(53120), None), + + /// Allows defining `extern type`s. + (active, extern_types, "1.23.0", Some(43467), None), + + /// Allows trait methods with arbitrary self types. + (active, arbitrary_self_types, "1.23.0", Some(44874), None), + + /// Allows in-band quantification of lifetime bindings (e.g., `fn foo(x: &'a u8) -> &'a u8`). + (active, in_band_lifetimes, "1.23.0", Some(44524), None), + + /// Allows associated types to be generic, e.g., `type Foo;` (RFC 1598). + (active, generic_associated_types, "1.23.0", Some(44265), None), + + /// Allows defining `trait X = A + B;` alias items. + (active, trait_alias, "1.24.0", Some(41517), None), + + /// Allows infering `'static` outlives requirements (RFC 2093). + (active, infer_static_outlives_requirements, "1.26.0", Some(54185), None), + + /// Allows accessing fields of unions inside `const` functions. + (active, const_fn_union, "1.27.0", Some(51909), None), + + /// Allows casting raw pointers to `usize` during const eval. + (active, const_raw_ptr_to_usize_cast, "1.27.0", Some(51910), None), + + /// Allows dereferencing raw pointers during const eval. + (active, const_raw_ptr_deref, "1.27.0", Some(51911), None), + + /// Allows comparing raw pointers during const eval. + (active, const_compare_raw_pointers, "1.27.0", Some(53020), None), + + /// Allows `#[doc(alias = "...")]`. + (active, doc_alias, "1.27.0", Some(50146), None), + + /// Allows inconsistent bounds in where clauses. + (active, trivial_bounds, "1.28.0", Some(48214), None), + + /// Allows `'a: { break 'a; }`. + (active, label_break_value, "1.28.0", Some(48594), None), + + /// Allows using `#[doc(keyword = "...")]`. + (active, doc_keyword, "1.28.0", Some(51315), None), + + /// Allows reinterpretation of the bits of a value of one type as another + /// type during const eval. + (active, const_transmute, "1.29.0", Some(53605), None), + + /// Allows using `try {...}` expressions. + (active, try_blocks, "1.29.0", Some(31436), None), + + /// Allows defining an `#[alloc_error_handler]`. + (active, alloc_error_handler, "1.29.0", Some(51540), None), + + /// Allows using the `amdgpu-kernel` ABI. + (active, abi_amdgpu_kernel, "1.29.0", Some(51575), None), + + /// Allows panicking during const eval (producing compile-time errors). + (active, const_panic, "1.30.0", Some(51999), None), + + /// Allows `#[marker]` on certain traits allowing overlapping implementations. + (active, marker_trait_attr, "1.30.0", Some(29864), None), + + /// Allows macro invocations on modules expressions and statements and + /// procedural macros to expand to non-items. + (active, proc_macro_hygiene, "1.30.0", Some(54727), None), + + /// Allows unsized rvalues at arguments and parameters. + (active, unsized_locals, "1.30.0", Some(48055), None), + + /// Allows custom test frameworks with `#![test_runner]` and `#[test_case]`. + (active, custom_test_frameworks, "1.30.0", Some(50297), None), + + /// Allows non-builtin attributes in inner attribute position. + (active, custom_inner_attributes, "1.30.0", Some(54726), None), + + /// Allows `impl Trait` in bindings (`let`, `const`, `static`). + (active, impl_trait_in_bindings, "1.30.0", Some(63065), None), + + /// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check. + (active, lint_reasons, "1.31.0", Some(54503), None), + + /// Allows exhaustive integer pattern matching on `usize` and `isize`. + (active, precise_pointer_size_matching, "1.32.0", Some(56354), None), + + /// Allows using `#[ffi_returns_twice]` on foreign functions. + (active, ffi_returns_twice, "1.34.0", Some(58314), None), + + /// Allows const generic types (e.g. `struct Foo(...);`). + (active, const_generics, "1.34.0", Some(44580), None), + + /// Allows using `#[optimize(X)]`. + (active, optimize_attribute, "1.34.0", Some(54882), None), + + /// Allows using C-variadics. + (active, c_variadic, "1.34.0", Some(44930), None), + + /// Allows the user of associated type bounds. + (active, associated_type_bounds, "1.34.0", Some(52662), None), + + /// Allows `if/while p && let q = r && ...` chains. + (active, let_chains, "1.37.0", Some(53667), None), + + /// Allows #[repr(transparent)] on enums (RFC 2645). + (active, transparent_enums, "1.37.0", Some(60405), None), + + /// Allows #[repr(transparent)] on unions (RFC 2645). + (active, transparent_unions, "1.37.0", Some(60405), None), + + /// Allows explicit discriminants on non-unit enum variants. + (active, arbitrary_enum_discriminant, "1.37.0", Some(60553), None), + + /// Allows `impl Trait` with multiple unrelated lifetimes. + (active, member_constraints, "1.37.0", Some(61977), None), + + /// Allows `async || body` closures. + (active, async_closure, "1.37.0", Some(62290), None), + + /// Allows `[x; N]` where `x` is a constant (RFC 2203). + (active, const_in_array_repeat_expressions, "1.37.0", Some(49147), None), + + /// Allows `impl Trait` to be used inside type aliases (RFC 2515). + (active, type_alias_impl_trait, "1.38.0", Some(63063), None), + + /// Allows the use of or-patterns (e.g., `0 | 1`). + (active, or_patterns, "1.38.0", Some(54883), None), + + /// Allows the definition of `const extern fn` and `const unsafe extern fn`. + (active, const_extern_fn, "1.40.0", Some(64926), None), + + /// Allows the use of raw-dylibs (RFC 2627). + (active, raw_dylib, "1.40.0", Some(58713), None), + + /// Allows `#[track_caller]` to be used which provides + /// accurate caller location reporting during panic (RFC 2091). + (active, track_caller, "1.40.0", Some(47809), None), + + /// Allows making `dyn Trait` well-formed even if `Trait` is not object safe. + /// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and + /// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden. + (active, object_safe_for_dispatch, "1.40.0", Some(43561), None), + + /// Allows using the `efiapi` ABI. + (active, abi_efiapi, "1.40.0", Some(65815), None), + + /// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions. + (active, raw_ref_op, "1.41.0", Some(64490), None), + + /// Allows diverging expressions to fall back to `!` rather than `()`. + (active, never_type_fallback, "1.41.0", Some(65992), None), + + /// Allows using the `#[register_attr]` attribute. + (active, register_attr, "1.41.0", Some(66080), None), + + /// Allows using the `#[register_tool]` attribute. + (active, register_tool, "1.41.0", Some(66079), None), + + /// Allows the use of `if` and `match` in constants. + (active, const_if_match, "1.41.0", Some(49146), None), + + // ------------------------------------------------------------------------- + // feature-group-end: actual feature gates + // ------------------------------------------------------------------------- +); + +/// Some features are known to be incomplete and using them is likely to have +/// unanticipated results, such as compiler crashes. We warn the user about these +/// to alert them. +pub const INCOMPLETE_FEATURES: &[Symbol] = &[ + sym::impl_trait_in_bindings, + sym::generic_associated_types, + sym::const_generics, + sym::or_patterns, + sym::let_chains, + sym::raw_dylib, + sym::track_caller, +]; diff --git a/src/librustc_feature/lib.rs b/src/librustc_feature/lib.rs new file mode 100644 index 00000000000..c6388f47cfe --- /dev/null +++ b/src/librustc_feature/lib.rs @@ -0,0 +1,61 @@ +//! # Feature gating +//! +//! This module implements the gating necessary for preventing certain compiler +//! features from being used by default. This module will crawl a pre-expanded +//! AST to ensure that there are no features which are used that are not +//! enabled. +//! +//! Features are enabled in programs via the crate-level attributes of +//! `#![feature(...)]` with a comma-separated list of features. +//! +//! For the purpose of future feature-tracking, once code for detection of feature +//! gate usage is added, *do not remove it again* even once the feature +//! becomes stable. + +mod accepted; +mod removed; +mod active; + +use std::fmt; +use std::num::NonZeroU32; +use syntax_pos::{Span, edition::Edition, symbol::Symbol}; + +#[derive(Clone, Copy)] +pub enum State { + Accepted, + Active { set: fn(&mut Features, Span) }, + Removed { reason: Option<&'static str> }, + Stabilized { reason: Option<&'static str> }, +} + +impl fmt::Debug for State { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + State::Accepted { .. } => write!(f, "accepted"), + State::Active { .. } => write!(f, "active"), + State::Removed { .. } => write!(f, "removed"), + State::Stabilized { .. } => write!(f, "stabilized"), + } + } +} + +#[derive(Debug, Clone)] +pub struct Feature { + pub state: State, + pub name: Symbol, + pub since: &'static str, + issue: Option, // FIXME: once #58732 is done make this an Option + pub edition: Option, + description: &'static str, +} + +impl Feature { + // FIXME(Centril): privatize again. + pub fn issue(&self) -> Option { + self.issue.and_then(|i| NonZeroU32::new(i)) + } +} + +pub use accepted::ACCEPTED_FEATURES; +pub use active::{ACTIVE_FEATURES, Features, INCOMPLETE_FEATURES}; +pub use removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; diff --git a/src/librustc_feature/removed.rs b/src/librustc_feature/removed.rs new file mode 100644 index 00000000000..340bd32fb8a --- /dev/null +++ b/src/librustc_feature/removed.rs @@ -0,0 +1,116 @@ +//! List of the removed feature gates. + +use super::{State, Feature}; +use syntax_pos::symbol::sym; + +macro_rules! declare_features { + ($( + $(#[doc = $doc:tt])* (removed, $feature:ident, $ver:expr, $issue:expr, None, $reason:expr), + )+) => { + /// Represents unstable features which have since been removed (it was once Active) + pub const REMOVED_FEATURES: &[Feature] = &[ + $( + Feature { + state: State::Removed { reason: $reason }, + name: sym::$feature, + since: $ver, + issue: $issue, + edition: None, + description: concat!($($doc,)*), + } + ),+ + ]; + }; + + ($( + $(#[doc = $doc:tt])* (stable_removed, $feature:ident, $ver:expr, $issue:expr, None), + )+) => { + /// Represents stable features which have since been removed (it was once Accepted) + pub const STABLE_REMOVED_FEATURES: &[Feature] = &[ + $( + Feature { + state: State::Stabilized { reason: None }, + name: sym::$feature, + since: $ver, + issue: $issue, + edition: None, + description: concat!($($doc,)*), + } + ),+ + ]; + }; +} + +declare_features! ( + // ------------------------------------------------------------------------- + // feature-group-start: removed features + // ------------------------------------------------------------------------- + + (removed, import_shadowing, "1.0.0", None, None, None), + (removed, managed_boxes, "1.0.0", None, None, None), + /// Allows use of unary negate on unsigned integers, e.g., -e for e: u8 + (removed, negate_unsigned, "1.0.0", Some(29645), None, None), + (removed, reflect, "1.0.0", Some(27749), None, None), + /// A way to temporarily opt out of opt in copy. This will *never* be accepted. + (removed, opt_out_copy, "1.0.0", None, None, None), + (removed, quad_precision_float, "1.0.0", None, None, None), + (removed, struct_inherit, "1.0.0", None, None, None), + (removed, test_removed_feature, "1.0.0", None, None, None), + (removed, visible_private_types, "1.0.0", None, None, None), + (removed, unsafe_no_drop_flag, "1.0.0", None, None, None), + /// Allows using items which are missing stability attributes + (removed, unmarked_api, "1.0.0", None, None, None), + (removed, allocator, "1.0.0", None, None, None), + (removed, simd, "1.0.0", Some(27731), None, + Some("removed in favor of `#[repr(simd)]`")), + (removed, advanced_slice_patterns, "1.0.0", Some(62254), None, + Some("merged into `#![feature(slice_patterns)]`")), + (removed, macro_reexport, "1.0.0", Some(29638), None, + Some("subsumed by `pub use`")), + /// Allows using custom attributes (RFC 572). + (removed, custom_attribute, "1.0.0", Some(29642), None, + Some("removed in favor of `#![register_tool]` and `#![register_attr]`")), + (removed, pushpop_unsafe, "1.2.0", None, None, None), + (removed, needs_allocator, "1.4.0", Some(27389), None, + Some("subsumed by `#![feature(allocator_internals)]`")), + (removed, proc_macro_mod, "1.27.0", Some(54727), None, + Some("subsumed by `#![feature(proc_macro_hygiene)]`")), + (removed, proc_macro_expr, "1.27.0", Some(54727), None, + Some("subsumed by `#![feature(proc_macro_hygiene)]`")), + (removed, proc_macro_non_items, "1.27.0", Some(54727), None, + Some("subsumed by `#![feature(proc_macro_hygiene)]`")), + (removed, proc_macro_gen, "1.27.0", Some(54727), None, + Some("subsumed by `#![feature(proc_macro_hygiene)]`")), + (removed, panic_implementation, "1.28.0", Some(44489), None, + Some("subsumed by `#[panic_handler]`")), + /// Allows the use of `#[derive(Anything)]` as sugar for `#[derive_Anything]`. + (removed, custom_derive, "1.32.0", Some(29644), None, + Some("subsumed by `#[proc_macro_derive]`")), + /// Paths of the form: `extern::foo::bar` + (removed, extern_in_paths, "1.33.0", Some(55600), None, + Some("subsumed by `::foo::bar` paths")), + (removed, quote, "1.33.0", Some(29601), None, None), + /// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238). + (removed, dropck_parametricity, "1.38.0", Some(28498), None, None), + (removed, await_macro, "1.38.0", Some(50547), None, + Some("subsumed by `.await` syntax")), + /// Allows defining `existential type`s. + (removed, existential_type, "1.38.0", Some(63063), None, + Some("removed in favor of `#![feature(type_alias_impl_trait)]`")), + /// Allows using the macros: + /// + `__diagnostic_used` + /// + `__register_diagnostic` + /// +`__build_diagnostic_array` + (removed, rustc_diagnostic_macros, "1.38.0", None, None, None), + /// Allows using `#[on_unimplemented(..)]` on traits. + /// (Moved to `rustc_attrs`.) + (removed, on_unimplemented, "1.40.0", None, None, None), + + // ------------------------------------------------------------------------- + // feature-group-end: removed features + // ------------------------------------------------------------------------- +); + +declare_features! ( + (stable_removed, no_stack_check, "1.0.0", None, None), +); diff --git a/src/librustc_lint/Cargo.toml b/src/librustc_lint/Cargo.toml index d26d8791f66..ed38243581b 100644 --- a/src/librustc_lint/Cargo.toml +++ b/src/librustc_lint/Cargo.toml @@ -15,5 +15,6 @@ rustc_target = { path = "../librustc_target" } syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } rustc_data_structures = { path = "../librustc_data_structures" } +rustc_feature = { path = "../librustc_feature" } rustc_index = { path = "../librustc_index" } rustc_error_codes = { path = "../librustc_error_codes" } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 38624034022..3515ef13e79 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -41,7 +41,7 @@ use syntax::ptr::P; use syntax::attr::{self, HasAttrs, AttributeTemplate}; use syntax::source_map::Spanned; use syntax::edition::Edition; -use syntax::feature_gate::{self, AttributeGate, AttributeType}; +use syntax::feature_gate::{AttributeGate, AttributeType}; use syntax::feature_gate::{Stability, deprecated_attributes}; use syntax_pos::{BytePos, Span}; use syntax::symbol::{Symbol, kw, sym}; @@ -1850,7 +1850,7 @@ impl EarlyLintPass for IncompleteFeatures { features.declared_lang_features .iter().map(|(name, span, _)| (name, span)) .chain(features.declared_lib_features.iter().map(|(name, span)| (name, span))) - .filter(|(name, _)| feature_gate::INCOMPLETE_FEATURES.iter().any(|f| name == &f)) + .filter(|(name, _)| rustc_feature::INCOMPLETE_FEATURES.iter().any(|f| name == &f)) .for_each(|(name, &span)| { cx.struct_span_lint( INCOMPLETE_FEATURES, diff --git a/src/librustc_parse/Cargo.toml b/src/librustc_parse/Cargo.toml index a9175487a75..95b3256f53a 100644 --- a/src/librustc_parse/Cargo.toml +++ b/src/librustc_parse/Cargo.toml @@ -16,6 +16,7 @@ syntax_pos = { path = "../libsyntax_pos" } syntax = { path = "../libsyntax" } errors = { path = "../librustc_errors", package = "rustc_errors" } rustc_data_structures = { path = "../librustc_data_structures" } +rustc_feature = { path = "../librustc_feature" } rustc_lexer = { path = "../librustc_lexer" } rustc_target = { path = "../librustc_target" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } diff --git a/src/librustc_parse/config.rs b/src/librustc_parse/config.rs index 7ce555ed57a..9c309f60515 100644 --- a/src/librustc_parse/config.rs +++ b/src/librustc_parse/config.rs @@ -9,11 +9,11 @@ //! [#64197]: https://github.com/rust-lang/rust/issues/64197 use crate::validate_attr; +use rustc_feature::Features; use syntax::attr::HasAttrs; use syntax::feature_gate::{ feature_err, EXPLAIN_STMT_ATTR_SYNTAX, - Features, get_features, GateIssue, }; diff --git a/src/librustc_passes/Cargo.toml b/src/librustc_passes/Cargo.toml index 7a98734bdbe..bb2f7c67418 100644 --- a/src/librustc_passes/Cargo.toml +++ b/src/librustc_passes/Cargo.toml @@ -12,6 +12,7 @@ path = "lib.rs" log = "0.4" rustc = { path = "../librustc" } rustc_data_structures = { path = "../librustc_data_structures" } +rustc_feature = { path = "../librustc_feature" } rustc_index = { path = "../librustc_index" } rustc_parse = { path = "../librustc_parse" } rustc_target = { path = "../librustc_target" } diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index 24bc088e24a..697a3ae873c 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -13,8 +13,9 @@ use rustc::hir::map::Map; use rustc::hir; use rustc::ty::TyCtxt; use rustc::ty::query::Providers; +use rustc_feature::Features; use syntax::ast::Mutability; -use syntax::feature_gate::{emit_feature_err, Features, GateIssue}; +use syntax::feature_gate::{emit_feature_err, GateIssue}; use syntax::span_err; use syntax_pos::{sym, Span}; use rustc_error_codes::*; diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index 09f4873967e..078948cc63b 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -7,10 +7,10 @@ use std::mem; use std::fmt::{self, Write}; use std::ops; +use rustc_feature::Features; use syntax::symbol::{Symbol, sym}; use syntax::ast::{MetaItem, MetaItemKind, NestedMetaItem, LitKind}; use syntax::sess::ParseSess; -use syntax::feature_gate::Features; use syntax_pos::Span; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 69d9748bb88..be3644ecf96 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -24,6 +24,7 @@ extern crate env_logger; extern crate rustc; extern crate rustc_data_structures; extern crate rustc_driver; +extern crate rustc_feature; extern crate rustc_error_codes; extern crate rustc_index; extern crate rustc_resolve; diff --git a/src/libsyntax/Cargo.toml b/src/libsyntax/Cargo.toml index dff23076c82..085c1760c80 100644 --- a/src/libsyntax/Cargo.toml +++ b/src/libsyntax/Cargo.toml @@ -18,6 +18,7 @@ lazy_static = "1.0.0" syntax_pos = { path = "../libsyntax_pos" } errors = { path = "../librustc_errors", package = "rustc_errors" } rustc_data_structures = { path = "../librustc_data_structures" } +rustc_feature = { path = "../librustc_feature" } rustc_index = { path = "../librustc_index" } rustc_lexer = { path = "../librustc_lexer" } rustc_macros = { path = "../librustc_macros" } diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index c10541c8c7e..eaa4a64025a 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -1,14 +1,15 @@ //! Parsing and validation of builtin attributes use crate::ast::{self, Attribute, MetaItem, NestedMetaItem}; -use crate::feature_gate::{Features, GatedCfg}; use crate::print::pprust; +use crate::feature_gate::GatedCfg; use crate::sess::ParseSess; use errors::{Applicability, Handler}; use std::num::NonZeroU32; use syntax_pos::hygiene::Transparency; use syntax_pos::{symbol::Symbol, symbol::sym, Span}; +use rustc_feature::Features; use rustc_macros::HashStable_Generic; use super::{mark_used, MetaItemKind}; diff --git a/src/libsyntax/feature_gate/accepted.rs b/src/libsyntax/feature_gate/accepted.rs deleted file mode 100644 index dab83f48a03..00000000000 --- a/src/libsyntax/feature_gate/accepted.rs +++ /dev/null @@ -1,265 +0,0 @@ -//! List of the accepted feature gates. - -use crate::symbol::sym; -use super::{State, Feature}; - -macro_rules! declare_features { - ($( - $(#[doc = $doc:tt])* (accepted, $feature:ident, $ver:expr, $issue:expr, None), - )+) => { - /// Those language feature has since been Accepted (it was once Active) - pub const ACCEPTED_FEATURES: &[Feature] = &[ - $( - Feature { - state: State::Accepted, - name: sym::$feature, - since: $ver, - issue: $issue, - edition: None, - description: concat!($($doc,)*), - } - ),+ - ]; - } -} - -declare_features! ( - // ------------------------------------------------------------------------- - // feature-group-start: for testing purposes - // ------------------------------------------------------------------------- - - /// A temporary feature gate used to enable parser extensions needed - /// to bootstrap fix for #5723. - (accepted, issue_5723_bootstrap, "1.0.0", None, None), - /// These are used to test this portion of the compiler, - /// they don't actually mean anything. - (accepted, test_accepted_feature, "1.0.0", None, None), - - // ------------------------------------------------------------------------- - // feature-group-end: for testing purposes - // ------------------------------------------------------------------------- - - // ------------------------------------------------------------------------- - // feature-group-start: accepted features - // ------------------------------------------------------------------------- - - /// Allows using associated `type`s in `trait`s. - (accepted, associated_types, "1.0.0", None, None), - /// Allows using assigning a default type to type parameters in algebraic data type definitions. - (accepted, default_type_params, "1.0.0", None, None), - // FIXME: explain `globs`. - (accepted, globs, "1.0.0", None, None), - /// Allows `macro_rules!` items. - (accepted, macro_rules, "1.0.0", None, None), - /// Allows use of `&foo[a..b]` as a slicing syntax. - (accepted, slicing_syntax, "1.0.0", None, None), - /// Allows struct variants `Foo { baz: u8, .. }` in enums (RFC 418). - (accepted, struct_variant, "1.0.0", None, None), - /// Allows indexing tuples. - (accepted, tuple_indexing, "1.0.0", None, None), - /// Allows the use of `if let` expressions. - (accepted, if_let, "1.0.0", None, None), - /// Allows the use of `while let` expressions. - (accepted, while_let, "1.0.0", None, None), - /// Allows using `#![no_std]`. - (accepted, no_std, "1.6.0", None, None), - /// Allows overloading augmented assignment operations like `a += b`. - (accepted, augmented_assignments, "1.8.0", Some(28235), None), - /// Allows empty structs and enum variants with braces. - (accepted, braced_empty_structs, "1.8.0", Some(29720), None), - /// Allows `#[deprecated]` attribute. - (accepted, deprecated, "1.9.0", Some(29935), None), - /// Allows macros to appear in the type position. - (accepted, type_macros, "1.13.0", Some(27245), None), - /// Allows use of the postfix `?` operator in expressions. - (accepted, question_mark, "1.13.0", Some(31436), None), - /// Allows `..` in tuple (struct) patterns. - (accepted, dotdot_in_tuple_patterns, "1.14.0", Some(33627), None), - /// Allows some increased flexibility in the name resolution rules, - /// especially around globs and shadowing (RFC 1560). - (accepted, item_like_imports, "1.15.0", Some(35120), None), - /// Allows using `Self` and associated types in struct expressions and patterns. - (accepted, more_struct_aliases, "1.16.0", Some(37544), None), - /// Allows elision of `'static` lifetimes in `static`s and `const`s. - (accepted, static_in_const, "1.17.0", Some(35897), None), - /// Allows field shorthands (`x` meaning `x: x`) in struct literal expressions. - (accepted, field_init_shorthand, "1.17.0", Some(37340), None), - /// Allows the definition recursive static items. - (accepted, static_recursion, "1.17.0", Some(29719), None), - /// Allows `pub(restricted)` visibilities (RFC 1422). - (accepted, pub_restricted, "1.18.0", Some(32409), None), - /// Allows `#![windows_subsystem]`. - (accepted, windows_subsystem, "1.18.0", Some(37499), None), - /// Allows `break {expr}` with a value inside `loop`s. - (accepted, loop_break_value, "1.19.0", Some(37339), None), - /// Allows numeric fields in struct expressions and patterns. - (accepted, relaxed_adts, "1.19.0", Some(35626), None), - /// Allows coercing non capturing closures to function pointers. - (accepted, closure_to_fn_coercion, "1.19.0", Some(39817), None), - /// Allows attributes on struct literal fields. - (accepted, struct_field_attributes, "1.20.0", Some(38814), None), - /// Allows the definition of associated constants in `trait` or `impl` blocks. - (accepted, associated_consts, "1.20.0", Some(29646), None), - /// Allows usage of the `compile_error!` macro. - (accepted, compile_error, "1.20.0", Some(40872), None), - /// Allows code like `let x: &'static u32 = &42` to work (RFC 1414). - (accepted, rvalue_static_promotion, "1.21.0", Some(38865), None), - /// Allows `Drop` types in constants (RFC 1440). - (accepted, drop_types_in_const, "1.22.0", Some(33156), None), - /// Allows the sysV64 ABI to be specified on all platforms - /// instead of just the platforms on which it is the C ABI. - (accepted, abi_sysv64, "1.24.0", Some(36167), None), - /// Allows `repr(align(16))` struct attribute (RFC 1358). - (accepted, repr_align, "1.25.0", Some(33626), None), - /// Allows '|' at beginning of match arms (RFC 1925). - (accepted, match_beginning_vert, "1.25.0", Some(44101), None), - /// Allows nested groups in `use` items (RFC 2128). - (accepted, use_nested_groups, "1.25.0", Some(44494), None), - /// Allows indexing into constant arrays. - (accepted, const_indexing, "1.26.0", Some(29947), None), - /// Allows using `a..=b` and `..=b` as inclusive range syntaxes. - (accepted, inclusive_range_syntax, "1.26.0", Some(28237), None), - /// Allows `..=` in patterns (RFC 1192). - (accepted, dotdoteq_in_patterns, "1.26.0", Some(28237), None), - /// Allows `fn main()` with return types which implements `Termination` (RFC 1937). - (accepted, termination_trait, "1.26.0", Some(43301), None), - /// Allows implementing `Clone` for closures where possible (RFC 2132). - (accepted, clone_closures, "1.26.0", Some(44490), None), - /// Allows implementing `Copy` for closures where possible (RFC 2132). - (accepted, copy_closures, "1.26.0", Some(44490), None), - /// Allows `impl Trait` in function arguments. - (accepted, universal_impl_trait, "1.26.0", Some(34511), None), - /// Allows `impl Trait` in function return types. - (accepted, conservative_impl_trait, "1.26.0", Some(34511), None), - /// Allows using the `u128` and `i128` types. - (accepted, i128_type, "1.26.0", Some(35118), None), - /// Allows default match binding modes (RFC 2005). - (accepted, match_default_bindings, "1.26.0", Some(42640), None), - /// Allows `'_` placeholder lifetimes. - (accepted, underscore_lifetimes, "1.26.0", Some(44524), None), - /// Allows attributes on lifetime/type formal parameters in generics (RFC 1327). - (accepted, generic_param_attrs, "1.27.0", Some(48848), None), - /// Allows `cfg(target_feature = "...")`. - (accepted, cfg_target_feature, "1.27.0", Some(29717), None), - /// Allows `#[target_feature(...)]`. - (accepted, target_feature, "1.27.0", None, None), - /// Allows using `dyn Trait` as a syntax for trait objects. - (accepted, dyn_trait, "1.27.0", Some(44662), None), - /// Allows `#[must_use]` on functions, and introduces must-use operators (RFC 1940). - (accepted, fn_must_use, "1.27.0", Some(43302), None), - /// Allows use of the `:lifetime` macro fragment specifier. - (accepted, macro_lifetime_matcher, "1.27.0", Some(34303), None), - /// Allows `#[test]` functions where the return type implements `Termination` (RFC 1937). - (accepted, termination_trait_test, "1.27.0", Some(48854), None), - /// Allows the `#[global_allocator]` attribute. - (accepted, global_allocator, "1.28.0", Some(27389), None), - /// Allows `#[repr(transparent)]` attribute on newtype structs. - (accepted, repr_transparent, "1.28.0", Some(43036), None), - /// Allows procedural macros in `proc-macro` crates. - (accepted, proc_macro, "1.29.0", Some(38356), None), - /// Allows `foo.rs` as an alternative to `foo/mod.rs`. - (accepted, non_modrs_mods, "1.30.0", Some(44660), None), - /// Allows use of the `:vis` macro fragment specifier - (accepted, macro_vis_matcher, "1.30.0", Some(41022), None), - /// Allows importing and reexporting macros with `use`, - /// enables macro modularization in general. - (accepted, use_extern_macros, "1.30.0", Some(35896), None), - /// Allows keywords to be escaped for use as identifiers. - (accepted, raw_identifiers, "1.30.0", Some(48589), None), - /// Allows attributes scoped to tools. - (accepted, tool_attributes, "1.30.0", Some(44690), None), - /// Allows multi-segment paths in attributes and derives. - (accepted, proc_macro_path_invoc, "1.30.0", Some(38356), None), - /// Allows all literals in attribute lists and values of key-value pairs. - (accepted, attr_literals, "1.30.0", Some(34981), None), - /// Allows inferring outlives requirements (RFC 2093). - (accepted, infer_outlives_requirements, "1.30.0", Some(44493), None), - /// Allows annotating functions conforming to `fn(&PanicInfo) -> !` with `#[panic_handler]`. - /// This defines the behavior of panics. - (accepted, panic_handler, "1.30.0", Some(44489), None), - /// Allows `#[used]` to preserve symbols (see llvm.used). - (accepted, used, "1.30.0", Some(40289), None), - /// Allows `crate` in paths. - (accepted, crate_in_paths, "1.30.0", Some(45477), None), - /// Allows resolving absolute paths as paths from other crates. - (accepted, extern_absolute_paths, "1.30.0", Some(44660), None), - /// Allows access to crate names passed via `--extern` through prelude. - (accepted, extern_prelude, "1.30.0", Some(44660), None), - /// Allows parentheses in patterns. - (accepted, pattern_parentheses, "1.31.0", Some(51087), None), - /// Allows the definition of `const fn` functions. - (accepted, min_const_fn, "1.31.0", Some(53555), None), - /// Allows scoped lints. - (accepted, tool_lints, "1.31.0", Some(44690), None), - /// Allows lifetime elision in `impl` headers. For example: - /// + `impl Iterator for &mut Iterator` - /// + `impl Debug for Foo<'_>` - (accepted, impl_header_lifetime_elision, "1.31.0", Some(15872), None), - /// Allows `extern crate foo as bar;`. This puts `bar` into extern prelude. - (accepted, extern_crate_item_prelude, "1.31.0", Some(55599), None), - /// Allows use of the `:literal` macro fragment specifier (RFC 1576). - (accepted, macro_literal_matcher, "1.32.0", Some(35625), None), - /// Allows use of `?` as the Kleene "at most one" operator in macros. - (accepted, macro_at_most_once_rep, "1.32.0", Some(48075), None), - /// Allows `Self` struct constructor (RFC 2302). - (accepted, self_struct_ctor, "1.32.0", Some(51994), None), - /// Allows `Self` in type definitions (RFC 2300). - (accepted, self_in_typedefs, "1.32.0", Some(49303), None), - /// Allows `use x::y;` to search `x` in the current scope. - (accepted, uniform_paths, "1.32.0", Some(53130), None), - /// Allows integer match exhaustiveness checking (RFC 2591). - (accepted, exhaustive_integer_patterns, "1.33.0", Some(50907), None), - /// Allows `use path as _;` and `extern crate c as _;`. - (accepted, underscore_imports, "1.33.0", Some(48216), None), - /// Allows `#[repr(packed(N))]` attribute on structs. - (accepted, repr_packed, "1.33.0", Some(33158), None), - /// Allows irrefutable patterns in `if let` and `while let` statements (RFC 2086). - (accepted, irrefutable_let_patterns, "1.33.0", Some(44495), None), - /// Allows calling `const unsafe fn` inside `unsafe` blocks in `const fn` functions. - (accepted, min_const_unsafe_fn, "1.33.0", Some(55607), None), - /// Allows let bindings, assignments and destructuring in `const` functions and constants. - /// As long as control flow is not implemented in const eval, `&&` and `||` may not be used - /// at the same time as let bindings. - (accepted, const_let, "1.33.0", Some(48821), None), - /// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`. - (accepted, cfg_attr_multi, "1.33.0", Some(54881), None), - /// Allows top level or-patterns (`p | q`) in `if let` and `while let`. - (accepted, if_while_or_patterns, "1.33.0", Some(48215), None), - /// Allows `cfg(target_vendor = "...")`. - (accepted, cfg_target_vendor, "1.33.0", Some(29718), None), - /// Allows `extern crate self as foo;`. - /// This puts local crate root into extern prelude under name `foo`. - (accepted, extern_crate_self, "1.34.0", Some(56409), None), - /// Allows arbitrary delimited token streams in non-macro attributes. - (accepted, unrestricted_attribute_tokens, "1.34.0", Some(55208), None), - /// Allows paths to enum variants on type aliases including `Self`. - (accepted, type_alias_enum_variants, "1.37.0", Some(49683), None), - /// Allows using `#[repr(align(X))]` on enums with equivalent semantics - /// to wrapping an enum in a wrapper struct with `#[repr(align(X))]`. - (accepted, repr_align_enum, "1.37.0", Some(57996), None), - /// Allows `const _: TYPE = VALUE`. - (accepted, underscore_const_names, "1.37.0", Some(54912), None), - /// Allows free and inherent `async fn`s, `async` blocks, and `.await` expressions. - (accepted, async_await, "1.39.0", Some(50547), None), - /// Allows mixing bind-by-move in patterns and references to those identifiers in guards. - (accepted, bind_by_move_pattern_guards, "1.39.0", Some(15287), None), - /// Allows attributes in formal function parameters. - (accepted, param_attrs, "1.39.0", Some(60406), None), - /// Allows macro invocations in `extern {}` blocks. - (accepted, macros_in_extern, "1.40.0", Some(49476), None), - /// Allows future-proofing enums/structs with the `#[non_exhaustive]` attribute (RFC 2008). - (accepted, non_exhaustive, "1.40.0", Some(44109), None), - /// Allows calling constructor functions in `const fn`. - (accepted, const_constructor, "1.40.0", Some(61456), None), - /// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests. - (accepted, cfg_doctest, "1.40.0", Some(62210), None), - /// Allows the `!` type. Does not imply 'exhaustive_patterns' any more. - (accepted, never_type, "1.41.0", Some(35121), None), - /// Allows relaxing the coherence rules such that - /// `impl ForeignTrait for ForeignType` is permitted. - (accepted, re_rebalance_coherence, "1.41.0", Some(55437), None), - - // ------------------------------------------------------------------------- - // feature-group-end: accepted features - // ------------------------------------------------------------------------- -); diff --git a/src/libsyntax/feature_gate/active.rs b/src/libsyntax/feature_gate/active.rs deleted file mode 100644 index b04b30aa6bc..00000000000 --- a/src/libsyntax/feature_gate/active.rs +++ /dev/null @@ -1,554 +0,0 @@ -//! List of the active feature gates. - -use super::{State, Feature}; - -use crate::edition::Edition; -use crate::symbol::{Symbol, sym}; - -use syntax_pos::Span; - -macro_rules! set { - ($field: ident) => {{ - fn f(features: &mut Features, _: Span) { - features.$field = true; - } - f as fn(&mut Features, Span) - }} -} - -macro_rules! declare_features { - ($( - $(#[doc = $doc:tt])* (active, $feature:ident, $ver:expr, $issue:expr, $edition:expr), - )+) => { - /// Represents active features that are currently being implemented or - /// currently being considered for addition/removal. - pub const ACTIVE_FEATURES: - &[Feature] = - &[$( - // (sym::$feature, $ver, $issue, $edition, set!($feature)) - Feature { - state: State::Active { set: set!($feature) }, - name: sym::$feature, - since: $ver, - issue: $issue, - edition: $edition, - description: concat!($($doc,)*), - } - ),+]; - - /// A set of features to be used by later passes. - #[derive(Clone)] - pub struct Features { - /// `#![feature]` attrs for language features, for error reporting. - pub declared_lang_features: Vec<(Symbol, Span, Option)>, - /// `#![feature]` attrs for non-language (library) features. - pub declared_lib_features: Vec<(Symbol, Span)>, - $( - $(#[doc = $doc])* - pub $feature: bool - ),+ - } - - impl Features { - pub fn new() -> Features { - Features { - declared_lang_features: Vec::new(), - declared_lib_features: Vec::new(), - $($feature: false),+ - } - } - - pub fn walk_feature_fields(&self, mut f: F) - where F: FnMut(&str, bool) - { - $(f(stringify!($feature), self.$feature);)+ - } - } - }; -} - -impl Feature { - /// Sets this feature in `Features`. Panics if called on a non-active feature. - pub fn set(&self, features: &mut Features, span: Span) { - match self.state { - State::Active { set } => set(features, span), - _ => panic!("called `set` on feature `{}` which is not `active`", self.name) - } - } -} - -// If you change this, please modify `src/doc/unstable-book` as well. -// -// Don't ever remove anything from this list; move them to `removed.rs`. -// -// The version numbers here correspond to the version in which the current status -// was set. This is most important for knowing when a particular feature became -// stable (active). -// -// Note that the features are grouped into internal/user-facing and then -// sorted by version inside those groups. This is enforced with tidy. -// -// N.B., `tools/tidy/src/features.rs` parses this information directly out of the -// source, so take care when modifying it. - -declare_features! ( - // ------------------------------------------------------------------------- - // feature-group-start: internal feature gates - // ------------------------------------------------------------------------- - - // no-tracking-issue-start - - /// Allows using compiler's own crates. - (active, rustc_private, "1.0.0", Some(27812), None), - - /// Allows using the `rust-intrinsic`'s "ABI". - (active, intrinsics, "1.0.0", None, None), - - /// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic. - (active, lang_items, "1.0.0", None, None), - - /// Allows using the `#[stable]` and `#[unstable]` attributes. - (active, staged_api, "1.0.0", None, None), - - /// Allows using `#[allow_internal_unstable]`. This is an - /// attribute on `macro_rules!` and can't use the attribute handling - /// below (it has to be checked before expansion possibly makes - /// macros disappear). - (active, allow_internal_unstable, "1.0.0", None, None), - - /// Allows using `#[allow_internal_unsafe]`. This is an - /// attribute on `macro_rules!` and can't use the attribute handling - /// below (it has to be checked before expansion possibly makes - /// macros disappear). - (active, allow_internal_unsafe, "1.0.0", None, None), - - /// Allows using `#[rustc_const_unstable(feature = "foo", ..)]` which - /// lets a function to be `const` when opted into with `#![feature(foo)]`. - (active, rustc_const_unstable, "1.0.0", None, None), - - /// no-tracking-issue-end - - /// Allows using `#[link_name="llvm.*"]`. - (active, link_llvm_intrinsics, "1.0.0", Some(29602), None), - - /// Allows using `rustc_*` attributes (RFC 572). - (active, rustc_attrs, "1.0.0", Some(29642), None), - - /// Allows using the `box $expr` syntax. - (active, box_syntax, "1.0.0", Some(49733), None), - - /// Allows using `#[main]` to replace the entrypoint `#[lang = "start"]` calls. - (active, main, "1.0.0", Some(29634), None), - - /// Allows using `#[start]` on a function indicating that it is the program entrypoint. - (active, start, "1.0.0", Some(29633), None), - - /// Allows using the `#[fundamental]` attribute. - (active, fundamental, "1.0.0", Some(29635), None), - - /// Allows using the `rust-call` ABI. - (active, unboxed_closures, "1.0.0", Some(29625), None), - - /// Allows using the `#[linkage = ".."]` attribute. - (active, linkage, "1.0.0", Some(29603), None), - - /// Allows features specific to OIBIT (auto traits). - (active, optin_builtin_traits, "1.0.0", Some(13231), None), - - /// Allows using `box` in patterns (RFC 469). - (active, box_patterns, "1.0.0", Some(29641), None), - - // no-tracking-issue-start - - /// Allows using `#[prelude_import]` on glob `use` items. - (active, prelude_import, "1.2.0", None, None), - - // no-tracking-issue-end - - // no-tracking-issue-start - - /// Allows using `#[omit_gdb_pretty_printer_section]`. - (active, omit_gdb_pretty_printer_section, "1.5.0", None, None), - - /// Allows using the `vectorcall` ABI. - (active, abi_vectorcall, "1.7.0", None, None), - - // no-tracking-issue-end - - /// Allows using `#[structural_match]` which indicates that a type is structurally matchable. - (active, structural_match, "1.8.0", Some(31434), None), - - /// Allows using the `may_dangle` attribute (RFC 1327). - (active, dropck_eyepatch, "1.10.0", Some(34761), None), - - /// Allows using the `#![panic_runtime]` attribute. - (active, panic_runtime, "1.10.0", Some(32837), None), - - /// Allows declaring with `#![needs_panic_runtime]` that a panic runtime is needed. - (active, needs_panic_runtime, "1.10.0", Some(32837), None), - - // no-tracking-issue-start - - /// Allows identifying the `compiler_builtins` crate. - (active, compiler_builtins, "1.13.0", None, None), - - /// Allows using the `unadjusted` ABI; perma-unstable. - (active, abi_unadjusted, "1.16.0", None, None), - - /// Allows identifying crates that contain sanitizer runtimes. - (active, sanitizer_runtime, "1.17.0", None, None), - - /// Used to identify crates that contain the profiler runtime. - (active, profiler_runtime, "1.18.0", None, None), - - /// Allows using the `thiscall` ABI. - (active, abi_thiscall, "1.19.0", None, None), - - /// Allows using `#![needs_allocator]`, an implementation detail of `#[global_allocator]`. - (active, allocator_internals, "1.20.0", None, None), - - /// Added for testing E0705; perma-unstable. - (active, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)), - - // no-tracking-issue-end - - // ------------------------------------------------------------------------- - // feature-group-end: internal feature gates - // ------------------------------------------------------------------------- - - // ------------------------------------------------------------------------- - // feature-group-start: actual feature gates (target features) - // ------------------------------------------------------------------------- - - // FIXME: Document these and merge with the list below. - - // Unstable `#[target_feature]` directives. - (active, arm_target_feature, "1.27.0", Some(44839), None), - (active, aarch64_target_feature, "1.27.0", Some(44839), None), - (active, hexagon_target_feature, "1.27.0", Some(44839), None), - (active, powerpc_target_feature, "1.27.0", Some(44839), None), - (active, mips_target_feature, "1.27.0", Some(44839), None), - (active, avx512_target_feature, "1.27.0", Some(44839), None), - (active, mmx_target_feature, "1.27.0", Some(44839), None), - (active, sse4a_target_feature, "1.27.0", Some(44839), None), - (active, tbm_target_feature, "1.27.0", Some(44839), None), - (active, wasm_target_feature, "1.30.0", Some(44839), None), - (active, adx_target_feature, "1.32.0", Some(44839), None), - (active, cmpxchg16b_target_feature, "1.32.0", Some(44839), None), - (active, movbe_target_feature, "1.34.0", Some(44839), None), - (active, rtm_target_feature, "1.35.0", Some(44839), None), - (active, f16c_target_feature, "1.36.0", Some(44839), None), - - // ------------------------------------------------------------------------- - // feature-group-end: actual feature gates (target features) - // ------------------------------------------------------------------------- - - // ------------------------------------------------------------------------- - // feature-group-start: actual feature gates - // ------------------------------------------------------------------------- - - /// Allows using the `#[link_args]` attribute. - (active, link_args, "1.0.0", Some(29596), None), - - /// Allows defining identifiers beyond ASCII. - (active, non_ascii_idents, "1.0.0", Some(55467), None), - - /// Allows using `#[plugin_registrar]` on functions. - (active, plugin_registrar, "1.0.0", Some(29597), None), - - /// Allows using `#![plugin(myplugin)]`. - (active, plugin, "1.0.0", Some(29597), None), - - /// Allows using `#[thread_local]` on `static` items. - (active, thread_local, "1.0.0", Some(29594), None), - - /// Allows the use of SIMD types in functions declared in `extern` blocks. - (active, simd_ffi, "1.0.0", Some(27731), None), - - /// Allows using non lexical lifetimes (RFC 2094). - (active, nll, "1.0.0", Some(43234), None), - - /// Allows using slice patterns. - (active, slice_patterns, "1.0.0", Some(62254), None), - - /// Allows the definition of `const` functions with some advanced features. - (active, const_fn, "1.2.0", Some(57563), None), - - /// Allows associated type defaults. - (active, associated_type_defaults, "1.2.0", Some(29661), None), - - /// Allows `#![no_core]`. - (active, no_core, "1.3.0", Some(29639), None), - - /// Allows default type parameters to influence type inference. - (active, default_type_parameter_fallback, "1.3.0", Some(27336), None), - - /// Allows `repr(simd)` and importing the various simd intrinsics. - (active, repr_simd, "1.4.0", Some(27731), None), - - /// Allows `extern "platform-intrinsic" { ... }`. - (active, platform_intrinsics, "1.4.0", Some(27731), None), - - /// Allows `#[unwind(..)]`. - /// - /// Permits specifying whether a function should permit unwinding or abort on unwind. - (active, unwind_attributes, "1.4.0", Some(58760), None), - - /// Allows `#[no_debug]`. - (active, no_debug, "1.5.0", Some(29721), None), - - /// Allows attributes on expressions and non-item statements. - (active, stmt_expr_attributes, "1.6.0", Some(15701), None), - - /// Allows the use of type ascription in expressions. - (active, type_ascription, "1.6.0", Some(23416), None), - - /// Allows `cfg(target_thread_local)`. - (active, cfg_target_thread_local, "1.7.0", Some(29594), None), - - /// Allows specialization of implementations (RFC 1210). - (active, specialization, "1.7.0", Some(31844), None), - - /// Allows using `#[naked]` on functions. - (active, naked_functions, "1.9.0", Some(32408), None), - - /// Allows `cfg(target_has_atomic = "...")`. - (active, cfg_target_has_atomic, "1.9.0", Some(32976), None), - - /// Allows `X..Y` patterns. - (active, exclusive_range_pattern, "1.11.0", Some(37854), None), - - /// Allows exhaustive pattern matching on types that contain uninhabited types. - (active, exhaustive_patterns, "1.13.0", Some(51085), None), - - /// Allows `union`s to implement `Drop`. Moreover, `union`s may now include fields - /// that don't implement `Copy` as long as they don't have any drop glue. - /// This is checked recursively. On encountering type variable where no progress can be made, - /// `T: Copy` is used as a substitute for "no drop glue". - /// - /// NOTE: A limited form of `union U { ... }` was accepted in 1.19.0. - (active, untagged_unions, "1.13.0", Some(55149), None), - - /// Allows `#[link(..., cfg(..))]`. - (active, link_cfg, "1.14.0", Some(37406), None), - - /// Allows `extern "ptx-*" fn()`. - (active, abi_ptx, "1.15.0", Some(38788), None), - - /// Allows the `#[repr(i128)]` attribute for enums. - (active, repr128, "1.16.0", Some(35118), None), - - /// Allows `#[link(kind="static-nobundle"...)]`. - (active, static_nobundle, "1.16.0", Some(37403), None), - - /// Allows `extern "msp430-interrupt" fn()`. - (active, abi_msp430_interrupt, "1.16.0", Some(38487), None), - - /// Allows declarative macros 2.0 (`macro`). - (active, decl_macro, "1.17.0", Some(39412), None), - - /// Allows `extern "x86-interrupt" fn()`. - (active, abi_x86_interrupt, "1.17.0", Some(40180), None), - - /// Allows overlapping impls of marker traits. - (active, overlapping_marker_traits, "1.18.0", Some(29864), None), - - /// Allows a test to fail without failing the whole suite. - (active, allow_fail, "1.19.0", Some(46488), None), - - /// Allows unsized tuple coercion. - (active, unsized_tuple_coercion, "1.20.0", Some(42877), None), - - /// Allows defining generators. - (active, generators, "1.21.0", Some(43122), None), - - /// Allows `#[doc(cfg(...))]`. - (active, doc_cfg, "1.21.0", Some(43781), None), - - /// Allows `#[doc(masked)]`. - (active, doc_masked, "1.21.0", Some(44027), None), - - /// Allows `#[doc(spotlight)]`. - (active, doc_spotlight, "1.22.0", Some(45040), None), - - /// Allows `#[doc(include = "some-file")]`. - (active, external_doc, "1.22.0", Some(44732), None), - - /// Allows using `crate` as visibility modifier, synonymous with `pub(crate)`. - (active, crate_visibility_modifier, "1.23.0", Some(53120), None), - - /// Allows defining `extern type`s. - (active, extern_types, "1.23.0", Some(43467), None), - - /// Allows trait methods with arbitrary self types. - (active, arbitrary_self_types, "1.23.0", Some(44874), None), - - /// Allows in-band quantification of lifetime bindings (e.g., `fn foo(x: &'a u8) -> &'a u8`). - (active, in_band_lifetimes, "1.23.0", Some(44524), None), - - /// Allows associated types to be generic, e.g., `type Foo;` (RFC 1598). - (active, generic_associated_types, "1.23.0", Some(44265), None), - - /// Allows defining `trait X = A + B;` alias items. - (active, trait_alias, "1.24.0", Some(41517), None), - - /// Allows infering `'static` outlives requirements (RFC 2093). - (active, infer_static_outlives_requirements, "1.26.0", Some(54185), None), - - /// Allows accessing fields of unions inside `const` functions. - (active, const_fn_union, "1.27.0", Some(51909), None), - - /// Allows casting raw pointers to `usize` during const eval. - (active, const_raw_ptr_to_usize_cast, "1.27.0", Some(51910), None), - - /// Allows dereferencing raw pointers during const eval. - (active, const_raw_ptr_deref, "1.27.0", Some(51911), None), - - /// Allows comparing raw pointers during const eval. - (active, const_compare_raw_pointers, "1.27.0", Some(53020), None), - - /// Allows `#[doc(alias = "...")]`. - (active, doc_alias, "1.27.0", Some(50146), None), - - /// Allows inconsistent bounds in where clauses. - (active, trivial_bounds, "1.28.0", Some(48214), None), - - /// Allows `'a: { break 'a; }`. - (active, label_break_value, "1.28.0", Some(48594), None), - - /// Allows using `#[doc(keyword = "...")]`. - (active, doc_keyword, "1.28.0", Some(51315), None), - - /// Allows reinterpretation of the bits of a value of one type as another - /// type during const eval. - (active, const_transmute, "1.29.0", Some(53605), None), - - /// Allows using `try {...}` expressions. - (active, try_blocks, "1.29.0", Some(31436), None), - - /// Allows defining an `#[alloc_error_handler]`. - (active, alloc_error_handler, "1.29.0", Some(51540), None), - - /// Allows using the `amdgpu-kernel` ABI. - (active, abi_amdgpu_kernel, "1.29.0", Some(51575), None), - - /// Allows panicking during const eval (producing compile-time errors). - (active, const_panic, "1.30.0", Some(51999), None), - - /// Allows `#[marker]` on certain traits allowing overlapping implementations. - (active, marker_trait_attr, "1.30.0", Some(29864), None), - - /// Allows macro invocations on modules expressions and statements and - /// procedural macros to expand to non-items. - (active, proc_macro_hygiene, "1.30.0", Some(54727), None), - - /// Allows unsized rvalues at arguments and parameters. - (active, unsized_locals, "1.30.0", Some(48055), None), - - /// Allows custom test frameworks with `#![test_runner]` and `#[test_case]`. - (active, custom_test_frameworks, "1.30.0", Some(50297), None), - - /// Allows non-builtin attributes in inner attribute position. - (active, custom_inner_attributes, "1.30.0", Some(54726), None), - - /// Allows `impl Trait` in bindings (`let`, `const`, `static`). - (active, impl_trait_in_bindings, "1.30.0", Some(63065), None), - - /// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check. - (active, lint_reasons, "1.31.0", Some(54503), None), - - /// Allows exhaustive integer pattern matching on `usize` and `isize`. - (active, precise_pointer_size_matching, "1.32.0", Some(56354), None), - - /// Allows using `#[ffi_returns_twice]` on foreign functions. - (active, ffi_returns_twice, "1.34.0", Some(58314), None), - - /// Allows const generic types (e.g. `struct Foo(...);`). - (active, const_generics, "1.34.0", Some(44580), None), - - /// Allows using `#[optimize(X)]`. - (active, optimize_attribute, "1.34.0", Some(54882), None), - - /// Allows using C-variadics. - (active, c_variadic, "1.34.0", Some(44930), None), - - /// Allows the user of associated type bounds. - (active, associated_type_bounds, "1.34.0", Some(52662), None), - - /// Allows `if/while p && let q = r && ...` chains. - (active, let_chains, "1.37.0", Some(53667), None), - - /// Allows #[repr(transparent)] on enums (RFC 2645). - (active, transparent_enums, "1.37.0", Some(60405), None), - - /// Allows #[repr(transparent)] on unions (RFC 2645). - (active, transparent_unions, "1.37.0", Some(60405), None), - - /// Allows explicit discriminants on non-unit enum variants. - (active, arbitrary_enum_discriminant, "1.37.0", Some(60553), None), - - /// Allows `impl Trait` with multiple unrelated lifetimes. - (active, member_constraints, "1.37.0", Some(61977), None), - - /// Allows `async || body` closures. - (active, async_closure, "1.37.0", Some(62290), None), - - /// Allows `[x; N]` where `x` is a constant (RFC 2203). - (active, const_in_array_repeat_expressions, "1.37.0", Some(49147), None), - - /// Allows `impl Trait` to be used inside type aliases (RFC 2515). - (active, type_alias_impl_trait, "1.38.0", Some(63063), None), - - /// Allows the use of or-patterns (e.g., `0 | 1`). - (active, or_patterns, "1.38.0", Some(54883), None), - - /// Allows the definition of `const extern fn` and `const unsafe extern fn`. - (active, const_extern_fn, "1.40.0", Some(64926), None), - - /// Allows the use of raw-dylibs (RFC 2627). - (active, raw_dylib, "1.40.0", Some(58713), None), - - /// Allows `#[track_caller]` to be used which provides - /// accurate caller location reporting during panic (RFC 2091). - (active, track_caller, "1.40.0", Some(47809), None), - - /// Allows making `dyn Trait` well-formed even if `Trait` is not object safe. - /// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and - /// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden. - (active, object_safe_for_dispatch, "1.40.0", Some(43561), None), - - /// Allows using the `efiapi` ABI. - (active, abi_efiapi, "1.40.0", Some(65815), None), - - /// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions. - (active, raw_ref_op, "1.41.0", Some(64490), None), - - /// Allows diverging expressions to fall back to `!` rather than `()`. - (active, never_type_fallback, "1.41.0", Some(65992), None), - - /// Allows using the `#[register_attr]` attribute. - (active, register_attr, "1.41.0", Some(66080), None), - - /// Allows using the `#[register_tool]` attribute. - (active, register_tool, "1.41.0", Some(66079), None), - - /// Allows the use of `if` and `match` in constants. - (active, const_if_match, "1.41.0", Some(49146), None), - - // ------------------------------------------------------------------------- - // feature-group-end: actual feature gates - // ------------------------------------------------------------------------- -); - -/// Some features are known to be incomplete and using them is likely to have -/// unanticipated results, such as compiler crashes. We warn the user about these -/// to alert them. -pub const INCOMPLETE_FEATURES: &[Symbol] = &[ - sym::impl_trait_in_bindings, - sym::generic_associated_types, - sym::const_generics, - sym::or_patterns, - sym::let_chains, - sym::raw_dylib, - sym::track_caller, -]; diff --git a/src/libsyntax/feature_gate/builtin_attrs.rs b/src/libsyntax/feature_gate/builtin_attrs.rs index a9f41633f30..e6f61e8fcbe 100644 --- a/src/libsyntax/feature_gate/builtin_attrs.rs +++ b/src/libsyntax/feature_gate/builtin_attrs.rs @@ -5,13 +5,13 @@ use AttributeGate::*; use super::check::{emit_feature_err, GateIssue}; use super::check::{Stability, EXPLAIN_ALLOW_INTERNAL_UNSAFE, EXPLAIN_ALLOW_INTERNAL_UNSTABLE}; -use super::active::Features; +use rustc_feature::Features; use crate::ast; use crate::attr::AttributeTemplate; use crate::sess::ParseSess; -use crate::symbol::{Symbol, sym}; +use syntax_pos::symbol::{Symbol, sym}; use syntax_pos::Span; use rustc_data_structures::fx::FxHashMap; use lazy_static::lazy_static; diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index ec0eaa56812..7d959756f23 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -1,6 +1,5 @@ -use super::{active::{ACTIVE_FEATURES, Features}, Feature, State as FeatureState}; -use super::accepted::ACCEPTED_FEATURES; -use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; +use rustc_feature::{ACCEPTED_FEATURES, ACTIVE_FEATURES, Features, Feature, State as FeatureState}; +use rustc_feature::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP}; use crate::ast::{self, AssocTyConstraint, AssocTyConstraintKind, NodeId}; diff --git a/src/libsyntax/feature_gate/mod.rs b/src/libsyntax/feature_gate/mod.rs deleted file mode 100644 index c4418c0f0f6..00000000000 --- a/src/libsyntax/feature_gate/mod.rs +++ /dev/null @@ -1,71 +0,0 @@ -//! # Feature gating -//! -//! This module implements the gating necessary for preventing certain compiler -//! features from being used by default. This module will crawl a pre-expanded -//! AST to ensure that there are no features which are used that are not -//! enabled. -//! -//! Features are enabled in programs via the crate-level attributes of -//! `#![feature(...)]` with a comma-separated list of features. -//! -//! For the purpose of future feature-tracking, once code for detection of feature -//! gate usage is added, *do not remove it again* even once the feature -//! becomes stable. - -mod accepted; -mod removed; -mod active; -mod builtin_attrs; -mod check; - -use crate::{edition::Edition, symbol::Symbol}; -use std::fmt; -use std::num::NonZeroU32; -use syntax_pos::Span; - -#[derive(Clone, Copy)] -pub enum State { - Accepted, - Active { set: fn(&mut Features, Span) }, - Removed { reason: Option<&'static str> }, - Stabilized { reason: Option<&'static str> }, -} - -impl fmt::Debug for State { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - State::Accepted { .. } => write!(f, "accepted"), - State::Active { .. } => write!(f, "active"), - State::Removed { .. } => write!(f, "removed"), - State::Stabilized { .. } => write!(f, "stabilized"), - } - } -} - -#[derive(Debug, Clone)] -pub struct Feature { - state: State, - name: Symbol, - since: &'static str, - issue: Option, // FIXME: once #58732 is done make this an Option - edition: Option, - description: &'static str, -} - -impl Feature { - fn issue(&self) -> Option { - self.issue.and_then(|i| NonZeroU32::new(i)) - } -} - -pub use active::{Features, INCOMPLETE_FEATURES}; -pub use builtin_attrs::{ - AttributeGate, AttributeType, GatedCfg, - BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP, - deprecated_attributes, is_builtin_attr, is_builtin_attr_name, -}; -pub use check::{ - check_crate, check_attribute, get_features, feature_err, emit_feature_err, - Stability, GateIssue, UnstableFeatures, - EXPLAIN_STMT_ATTR_SYNTAX, EXPLAIN_UNSIZED_TUPLE_COERCION, -}; diff --git a/src/libsyntax/feature_gate/removed.rs b/src/libsyntax/feature_gate/removed.rs deleted file mode 100644 index f0aa74c65df..00000000000 --- a/src/libsyntax/feature_gate/removed.rs +++ /dev/null @@ -1,116 +0,0 @@ -//! List of the removed feature gates. - -use crate::symbol::sym; -use super::{State, Feature}; - -macro_rules! declare_features { - ($( - $(#[doc = $doc:tt])* (removed, $feature:ident, $ver:expr, $issue:expr, None, $reason:expr), - )+) => { - /// Represents unstable features which have since been removed (it was once Active) - pub const REMOVED_FEATURES: &[Feature] = &[ - $( - Feature { - state: State::Removed { reason: $reason }, - name: sym::$feature, - since: $ver, - issue: $issue, - edition: None, - description: concat!($($doc,)*), - } - ),+ - ]; - }; - - ($( - $(#[doc = $doc:tt])* (stable_removed, $feature:ident, $ver:expr, $issue:expr, None), - )+) => { - /// Represents stable features which have since been removed (it was once Accepted) - pub const STABLE_REMOVED_FEATURES: &[Feature] = &[ - $( - Feature { - state: State::Stabilized { reason: None }, - name: sym::$feature, - since: $ver, - issue: $issue, - edition: None, - description: concat!($($doc,)*), - } - ),+ - ]; - }; -} - -declare_features! ( - // ------------------------------------------------------------------------- - // feature-group-start: removed features - // ------------------------------------------------------------------------- - - (removed, import_shadowing, "1.0.0", None, None, None), - (removed, managed_boxes, "1.0.0", None, None, None), - /// Allows use of unary negate on unsigned integers, e.g., -e for e: u8 - (removed, negate_unsigned, "1.0.0", Some(29645), None, None), - (removed, reflect, "1.0.0", Some(27749), None, None), - /// A way to temporarily opt out of opt in copy. This will *never* be accepted. - (removed, opt_out_copy, "1.0.0", None, None, None), - (removed, quad_precision_float, "1.0.0", None, None, None), - (removed, struct_inherit, "1.0.0", None, None, None), - (removed, test_removed_feature, "1.0.0", None, None, None), - (removed, visible_private_types, "1.0.0", None, None, None), - (removed, unsafe_no_drop_flag, "1.0.0", None, None, None), - /// Allows using items which are missing stability attributes - (removed, unmarked_api, "1.0.0", None, None, None), - (removed, allocator, "1.0.0", None, None, None), - (removed, simd, "1.0.0", Some(27731), None, - Some("removed in favor of `#[repr(simd)]`")), - (removed, advanced_slice_patterns, "1.0.0", Some(62254), None, - Some("merged into `#![feature(slice_patterns)]`")), - (removed, macro_reexport, "1.0.0", Some(29638), None, - Some("subsumed by `pub use`")), - /// Allows using custom attributes (RFC 572). - (removed, custom_attribute, "1.0.0", Some(29642), None, - Some("removed in favor of `#![register_tool]` and `#![register_attr]`")), - (removed, pushpop_unsafe, "1.2.0", None, None, None), - (removed, needs_allocator, "1.4.0", Some(27389), None, - Some("subsumed by `#![feature(allocator_internals)]`")), - (removed, proc_macro_mod, "1.27.0", Some(54727), None, - Some("subsumed by `#![feature(proc_macro_hygiene)]`")), - (removed, proc_macro_expr, "1.27.0", Some(54727), None, - Some("subsumed by `#![feature(proc_macro_hygiene)]`")), - (removed, proc_macro_non_items, "1.27.0", Some(54727), None, - Some("subsumed by `#![feature(proc_macro_hygiene)]`")), - (removed, proc_macro_gen, "1.27.0", Some(54727), None, - Some("subsumed by `#![feature(proc_macro_hygiene)]`")), - (removed, panic_implementation, "1.28.0", Some(44489), None, - Some("subsumed by `#[panic_handler]`")), - /// Allows the use of `#[derive(Anything)]` as sugar for `#[derive_Anything]`. - (removed, custom_derive, "1.32.0", Some(29644), None, - Some("subsumed by `#[proc_macro_derive]`")), - /// Paths of the form: `extern::foo::bar` - (removed, extern_in_paths, "1.33.0", Some(55600), None, - Some("subsumed by `::foo::bar` paths")), - (removed, quote, "1.33.0", Some(29601), None, None), - /// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238). - (removed, dropck_parametricity, "1.38.0", Some(28498), None, None), - (removed, await_macro, "1.38.0", Some(50547), None, - Some("subsumed by `.await` syntax")), - /// Allows defining `existential type`s. - (removed, existential_type, "1.38.0", Some(63063), None, - Some("removed in favor of `#![feature(type_alias_impl_trait)]`")), - /// Allows using the macros: - /// + `__diagnostic_used` - /// + `__register_diagnostic` - /// +`__build_diagnostic_array` - (removed, rustc_diagnostic_macros, "1.38.0", None, None, None), - /// Allows using `#[on_unimplemented(..)]` on traits. - /// (Moved to `rustc_attrs`.) - (removed, on_unimplemented, "1.40.0", None, None, None), - - // ------------------------------------------------------------------------- - // feature-group-end: removed features - // ------------------------------------------------------------------------- -); - -declare_features! ( - (stable_removed, no_stack_check, "1.0.0", None, None), -); diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 22b49862f49..f0d857673e7 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -92,7 +92,20 @@ pub mod attr; pub mod expand; pub use syntax_pos::source_map; pub mod entry; -pub mod feature_gate; +pub mod feature_gate { + mod check; + pub use check::{ + check_crate, check_attribute, get_features, feature_err, emit_feature_err, + Stability, GateIssue, UnstableFeatures, + EXPLAIN_STMT_ATTR_SYNTAX, EXPLAIN_UNSIZED_TUPLE_COERCION, + }; + mod builtin_attrs; + pub use builtin_attrs::{ + AttributeGate, AttributeType, GatedCfg, + BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP, + deprecated_attributes, is_builtin_attr, is_builtin_attr_name, + }; +} pub mod mut_visit; pub mod ptr; pub mod show_span; diff --git a/src/libsyntax_expand/Cargo.toml b/src/libsyntax_expand/Cargo.toml index 653b87f0d82..897d5a65ba3 100644 --- a/src/libsyntax_expand/Cargo.toml +++ b/src/libsyntax_expand/Cargo.toml @@ -16,6 +16,7 @@ log = "0.4" syntax_pos = { path = "../libsyntax_pos" } errors = { path = "../librustc_errors", package = "rustc_errors" } rustc_data_structures = { path = "../librustc_data_structures" } +rustc_feature = { path = "../librustc_feature" } rustc_lexer = { path = "../librustc_lexer" } rustc_parse = { path = "../librustc_parse" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } diff --git a/src/libsyntax_expand/expand.rs b/src/libsyntax_expand/expand.rs index 4f05b0147bf..d8033759033 100644 --- a/src/libsyntax_expand/expand.rs +++ b/src/libsyntax_expand/expand.rs @@ -4,8 +4,9 @@ use crate::hygiene::{ExpnId, SyntaxContext, ExpnData, ExpnKind}; use crate::mbe::macro_rules::annotate_err_with_kind; use crate::placeholders::{placeholder, PlaceholderExpander}; use crate::config::StripUnconfigured; -use rustc_parse::configure; +use rustc_feature::Features; +use rustc_parse::configure; use rustc_parse::DirectoryOwnership; use rustc_parse::parser::Parser; use rustc_parse::validate_attr; @@ -13,7 +14,7 @@ use syntax::ast::{self, AttrItem, Block, Ident, LitKind, NodeId, PatKind, Path}; use syntax::ast::{MacStmtStyle, StmtKind, ItemKind}; use syntax::attr::{self, HasAttrs}; use syntax::source_map::respan; -use syntax::feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err}; +use syntax::feature_gate::{self, GateIssue, is_builtin_attr, emit_feature_err}; use syntax::mut_visit::*; use syntax::print::pprust; use syntax::ptr::P; diff --git a/src/libsyntax_expand/mbe/macro_rules.rs b/src/libsyntax_expand/mbe/macro_rules.rs index a1d8b5a5338..b191527df19 100644 --- a/src/libsyntax_expand/mbe/macro_rules.rs +++ b/src/libsyntax_expand/mbe/macro_rules.rs @@ -8,12 +8,12 @@ use crate::mbe::macro_parser::{Error, Failure, Success}; use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, NamedParseResult}; use crate::mbe::transcribe::transcribe; +use rustc_feature::Features; use rustc_parse::parser::Parser; use rustc_parse::Directory; use syntax::ast; use syntax::attr::{self, TransparencyError}; use syntax::edition::Edition; -use syntax::feature_gate::Features; use syntax::print::pprust; use syntax::sess::ParseSess; use syntax::symbol::{kw, sym, Symbol}; diff --git a/src/libsyntax_ext/Cargo.toml b/src/libsyntax_ext/Cargo.toml index 2ebdac8ef7c..d73a9ea6cdb 100644 --- a/src/libsyntax_ext/Cargo.toml +++ b/src/libsyntax_ext/Cargo.toml @@ -14,6 +14,7 @@ errors = { path = "../librustc_errors", package = "rustc_errors" } fmt_macros = { path = "../libfmt_macros" } log = "0.4" rustc_data_structures = { path = "../librustc_data_structures" } +rustc_feature = { path = "../librustc_feature" } rustc_parse = { path = "../librustc_parse" } rustc_target = { path = "../librustc_target" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } diff --git a/src/libsyntax_ext/test_harness.rs b/src/libsyntax_ext/test_harness.rs index 659780d7a43..4c1eec38c6e 100644 --- a/src/libsyntax_ext/test_harness.rs +++ b/src/libsyntax_ext/test_harness.rs @@ -2,13 +2,13 @@ use log::debug; use smallvec::{smallvec, SmallVec}; +use rustc_feature::Features; use rustc_target::spec::PanicStrategy; use syntax::ast::{self, Ident}; use syntax::attr; use syntax::entry::{self, EntryPointType}; use syntax_expand::base::{ExtCtxt, Resolver}; use syntax_expand::expand::{AstFragment, ExpansionConfig}; -use syntax::feature_gate::Features; use syntax::mut_visit::{*, ExpectOne}; use syntax::ptr::P; use syntax::sess::ParseSess; -- cgit 1.4.1-3-g733a5 From 048201fa7a69b3c3795e76186bc954d06d2ca368 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 00:39:51 +0100 Subject: move Stability to rustc_feature --- src/librustc_feature/lib.rs | 8 ++++++++ src/librustc_lint/builtin.rs | 3 ++- src/libsyntax/feature_gate/builtin_attrs.rs | 4 ++-- src/libsyntax/feature_gate/check.rs | 8 -------- src/libsyntax/lib.rs | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/librustc_feature/lib.rs b/src/librustc_feature/lib.rs index c6388f47cfe..5d248f75216 100644 --- a/src/librustc_feature/lib.rs +++ b/src/librustc_feature/lib.rs @@ -56,6 +56,14 @@ impl Feature { } } +#[derive(Copy, Clone, Debug)] +pub enum Stability { + Unstable, + // First argument is tracking issue link; second argument is an optional + // help message, which defaults to "remove this attribute". + Deprecated(&'static str, Option<&'static str>), +} + pub use accepted::ACCEPTED_FEATURES; pub use active::{ACTIVE_FEATURES, Features, INCOMPLETE_FEATURES}; pub use removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 3515ef13e79..06616d537de 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -34,6 +34,7 @@ use lint::{LateContext, LintContext, LintArray}; use lint::{LintPass, LateLintPass, EarlyLintPass, EarlyContext}; use rustc::util::nodemap::FxHashSet; +use rustc_feature::Stability; use syntax::tokenstream::{TokenTree, TokenStream}; use syntax::ast::{self, Expr}; @@ -42,7 +43,7 @@ use syntax::attr::{self, HasAttrs, AttributeTemplate}; use syntax::source_map::Spanned; use syntax::edition::Edition; use syntax::feature_gate::{AttributeGate, AttributeType}; -use syntax::feature_gate::{Stability, deprecated_attributes}; +use syntax::feature_gate::deprecated_attributes; use syntax_pos::{BytePos, Span}; use syntax::symbol::{Symbol, kw, sym}; use syntax::errors::{Applicability, DiagnosticBuilder}; diff --git a/src/libsyntax/feature_gate/builtin_attrs.rs b/src/libsyntax/feature_gate/builtin_attrs.rs index e6f61e8fcbe..70f923c2783 100644 --- a/src/libsyntax/feature_gate/builtin_attrs.rs +++ b/src/libsyntax/feature_gate/builtin_attrs.rs @@ -4,8 +4,8 @@ use AttributeType::*; use AttributeGate::*; use super::check::{emit_feature_err, GateIssue}; -use super::check::{Stability, EXPLAIN_ALLOW_INTERNAL_UNSAFE, EXPLAIN_ALLOW_INTERNAL_UNSTABLE}; -use rustc_feature::Features; +use super::check::{EXPLAIN_ALLOW_INTERNAL_UNSAFE, EXPLAIN_ALLOW_INTERNAL_UNSTABLE}; +use rustc_feature::{Features, Stability}; use crate::ast; use crate::attr::AttributeTemplate; diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 7d959756f23..19e615f40fa 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -22,14 +22,6 @@ use rustc_error_codes::*; use std::env; use std::num::NonZeroU32; -#[derive(Copy, Clone, Debug)] -pub enum Stability { - Unstable, - // First argument is tracking issue link; second argument is an optional - // help message, which defaults to "remove this attribute" - Deprecated(&'static str, Option<&'static str>), -} - macro_rules! gate_feature_fn { ($cx: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr, $level: expr) => {{ let (cx, has_feature, span, diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index f0d857673e7..e33aa8f1f2b 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -96,7 +96,7 @@ pub mod feature_gate { mod check; pub use check::{ check_crate, check_attribute, get_features, feature_err, emit_feature_err, - Stability, GateIssue, UnstableFeatures, + GateIssue, UnstableFeatures, EXPLAIN_STMT_ATTR_SYNTAX, EXPLAIN_UNSIZED_TUPLE_COERCION, }; mod builtin_attrs; -- cgit 1.4.1-3-g733a5 From 8ad4d15f3888f1339d52632d40e0a47697dd2a24 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 00:56:46 +0100 Subject: move AttributeTemplate to builtin_attrs --- src/librustc_lint/builtin.rs | 4 ++-- src/librustc_parse/validate_attr.rs | 17 ++++++++++++++--- src/libsyntax/attr/builtin.rs | 25 ------------------------- src/libsyntax/feature_gate/builtin_attrs.rs | 17 ++++++++++++++++- src/libsyntax/lib.rs | 2 +- src/libsyntax_ext/util.rs | 2 +- 6 files changed, 34 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 06616d537de..284b23a14e7 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -39,10 +39,10 @@ use rustc_feature::Stability; use syntax::tokenstream::{TokenTree, TokenStream}; use syntax::ast::{self, Expr}; use syntax::ptr::P; -use syntax::attr::{self, HasAttrs, AttributeTemplate}; +use syntax::attr::{self, HasAttrs}; use syntax::source_map::Spanned; use syntax::edition::Edition; -use syntax::feature_gate::{AttributeGate, AttributeType}; +use syntax::feature_gate::{AttributeGate, AttributeTemplate, AttributeType}; use syntax::feature_gate::deprecated_attributes; use syntax_pos::{BytePos, Span}; use syntax::symbol::{Symbol, kw, sym}; diff --git a/src/librustc_parse/validate_attr.rs b/src/librustc_parse/validate_attr.rs index bbe0dc1c35f..e6284858a21 100644 --- a/src/librustc_parse/validate_attr.rs +++ b/src/librustc_parse/validate_attr.rs @@ -1,8 +1,9 @@ //! Meta-syntax validation logic of attributes for post-expansion. use errors::{PResult, Applicability}; -use syntax::ast::{self, Attribute, AttrKind, Ident, MetaItem}; -use syntax::attr::{AttributeTemplate, mk_name_value_item_str}; +use syntax::feature_gate::AttributeTemplate; +use syntax::ast::{self, Attribute, AttrKind, Ident, MetaItem, MetaItemKind}; +use syntax::attr::mk_name_value_item_str; use syntax::early_buffered_lints::BufferedEarlyLintId; use syntax::feature_gate::BUILTIN_ATTRIBUTE_MAP; use syntax::token; @@ -41,6 +42,16 @@ pub fn parse_meta<'a>(sess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Meta }) } +/// Checks that the given meta-item is compatible with this `AttributeTemplate`. +fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaItemKind) -> bool { + match meta { + MetaItemKind::Word => template.word, + MetaItemKind::List(..) => template.list.is_some(), + MetaItemKind::NameValue(lit) if lit.kind.is_str() => template.name_value_str.is_some(), + MetaItemKind::NameValue(..) => false, + } +} + pub fn check_builtin_attribute( sess: &ParseSess, attr: &Attribute, @@ -57,7 +68,7 @@ pub fn check_builtin_attribute( name == sym::test || name == sym::bench; match parse_meta(sess, attr) { - Ok(meta) => if !should_skip(name) && !template.compatible(&meta.kind) { + Ok(meta) => if !should_skip(name) && !is_attr_template_compatible(&template, &meta.kind) { let error_msg = format!("malformed `{}` attribute input", name); let mut msg = "attribute must be of the form ".to_owned(); let mut suggestions = vec![]; diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index eaa4a64025a..be53d802eec 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -25,31 +25,6 @@ enum AttrError { UnsupportedLiteral(&'static str, /* is_bytestr */ bool), } -/// A template that the attribute input must match. -/// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now. -#[derive(Clone, Copy)] -pub struct AttributeTemplate { - pub word: bool, - pub list: Option<&'static str>, - pub name_value_str: Option<&'static str>, -} - -impl AttributeTemplate { - pub fn only_word() -> Self { - Self { word: true, list: None, name_value_str: None } - } - - /// Checks that the given meta-item is compatible with this template. - pub fn compatible(&self, meta_item_kind: &ast::MetaItemKind) -> bool { - match meta_item_kind { - ast::MetaItemKind::Word => self.word, - ast::MetaItemKind::List(..) => self.list.is_some(), - ast::MetaItemKind::NameValue(lit) if lit.kind.is_str() => self.name_value_str.is_some(), - ast::MetaItemKind::NameValue(..) => false, - } - } -} - fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) { let diag = &sess.span_diagnostic; match error { diff --git a/src/libsyntax/feature_gate/builtin_attrs.rs b/src/libsyntax/feature_gate/builtin_attrs.rs index 70f923c2783..7435b2e056a 100644 --- a/src/libsyntax/feature_gate/builtin_attrs.rs +++ b/src/libsyntax/feature_gate/builtin_attrs.rs @@ -8,7 +8,6 @@ use super::check::{EXPLAIN_ALLOW_INTERNAL_UNSAFE, EXPLAIN_ALLOW_INTERNAL_UNSTABL use rustc_feature::{Features, Stability}; use crate::ast; -use crate::attr::AttributeTemplate; use crate::sess::ParseSess; use syntax_pos::symbol::{Symbol, sym}; @@ -16,6 +15,7 @@ use syntax_pos::Span; use rustc_data_structures::fx::FxHashMap; use lazy_static::lazy_static; + type GateFn = fn(&Features) -> bool; macro_rules! cfg_fn { @@ -108,6 +108,21 @@ impl AttributeGate { } } +/// A template that the attribute input must match. +/// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now. +#[derive(Clone, Copy)] +pub struct AttributeTemplate { + pub word: bool, + pub list: Option<&'static str>, + pub name_value_str: Option<&'static str>, +} + +impl AttributeTemplate { + pub fn only_word() -> Self { + Self { word: true, list: None, name_value_str: None } + } +} + /// A convenience macro for constructing attribute templates. /// E.g., `template!(Word, List: "description")` means that the attribute /// supports forms `#[attr]` and `#[attr(description)]`. diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index e33aa8f1f2b..8e95fe3c34b 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -101,7 +101,7 @@ pub mod feature_gate { }; mod builtin_attrs; pub use builtin_attrs::{ - AttributeGate, AttributeType, GatedCfg, + AttributeGate, AttributeTemplate, AttributeType, GatedCfg, BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP, deprecated_attributes, is_builtin_attr, is_builtin_attr_name, }; diff --git a/src/libsyntax_ext/util.rs b/src/libsyntax_ext/util.rs index e59daab1770..893fd402e83 100644 --- a/src/libsyntax_ext/util.rs +++ b/src/libsyntax_ext/util.rs @@ -1,7 +1,7 @@ use rustc_parse::validate_attr; use syntax_pos::Symbol; use syntax::ast::MetaItem; -use syntax::attr::AttributeTemplate; +use syntax::feature_gate::AttributeTemplate; use syntax_expand::base::ExtCtxt; pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, name: Symbol) { -- cgit 1.4.1-3-g733a5 From 6cab02cf149787db6c9e30ee0ceed97768bbe9aa Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 01:57:53 +0100 Subject: simplify gated cfgs logic --- src/librustc_driver/lib.rs | 21 +++++++---------- src/libsyntax/attr/builtin.rs | 24 +++++++++++++------ src/libsyntax/feature_gate/builtin_attrs.rs | 36 +++++------------------------ src/libsyntax/lib.rs | 2 +- 4 files changed, 32 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 13829b842fd..22f130ed3c9 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -62,9 +62,9 @@ use std::time::Instant; use syntax::ast; use syntax::source_map::FileLoader; -use syntax::feature_gate::{GatedCfg, UnstableFeatures}; -use syntax::symbol::sym; -use syntax_pos::{DUMMY_SP, FileName}; +use syntax::feature_gate::{find_gated_cfg, UnstableFeatures}; +use syntax_pos::symbol::sym; +use syntax_pos::FileName; pub mod pretty; mod args; @@ -677,12 +677,6 @@ impl RustcDefaultCalls { .is_nightly_build(); let mut cfgs = sess.parse_sess.config.iter().filter_map(|&(name, ref value)| { - let gated_cfg = GatedCfg::gate(&ast::MetaItem { - path: ast::Path::from_ident(ast::Ident::with_dummy_span(name)), - kind: ast::MetaItemKind::Word, - span: DUMMY_SP, - }); - // Note that crt-static is a specially recognized cfg // directive that's printed out here as part of // rust-lang/rust#37406, but in general the @@ -693,10 +687,11 @@ impl RustcDefaultCalls { // through to build scripts. let value = value.as_ref().map(|s| s.as_str()); let value = value.as_ref().map(|s| s.as_ref()); - if name != sym::target_feature || value != Some("crt-static") { - if !allow_unstable_cfg && gated_cfg.is_some() { - return None - } + if (name != sym::target_feature || value != Some("crt-static")) + && !allow_unstable_cfg + && find_gated_cfg(|cfg_sym| cfg_sym == name).is_some() + { + return None; } if let Some(value) = value { diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index be53d802eec..4e7738439b2 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -1,8 +1,8 @@ //! Parsing and validation of builtin attributes use crate::ast::{self, Attribute, MetaItem, NestedMetaItem}; +use crate::feature_gate::{find_gated_cfg, emit_feature_err, GatedCfg, GateIssue}; use crate::print::pprust; -use crate::feature_gate::GatedCfg; use crate::sess::ParseSess; use errors::{Applicability, Handler}; @@ -531,8 +531,9 @@ pub fn find_crate_name(attrs: &[Attribute]) -> Option { /// Tests if a cfg-pattern matches the cfg set pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Features>) -> bool { eval_condition(cfg, sess, &mut |cfg| { - if let (Some(feats), Some(gated_cfg)) = (features, GatedCfg::gate(cfg)) { - gated_cfg.check_and_emit(sess, feats); + let gate = find_gated_cfg(|sym| cfg.check_name(sym)); + if let (Some(feats), Some(gated_cfg)) = (features, gate) { + gate_cfg(&gated_cfg, cfg.span, sess, feats); } let error = |span, msg| { sess.span_diagnostic.span_err(span, msg); true }; if cfg.path.segments.len() != 1 { @@ -561,12 +562,21 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat }) } +fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &ParseSess, features: &Features) { + let (cfg, feature, has_feature) = gated_cfg; + if !has_feature(features) && !cfg_span.allows_unstable(*feature) { + let explain = format!("`cfg({})` is experimental and subject to change", cfg); + emit_feature_err(sess, *feature, cfg_span, GateIssue::Language, &explain); + } +} + /// Evaluate a cfg-like condition (with `any` and `all`), using `eval` to /// evaluate individual items. -pub fn eval_condition(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F) - -> bool - where F: FnMut(&ast::MetaItem) -> bool -{ +pub fn eval_condition( + cfg: &ast::MetaItem, + sess: &ParseSess, + eval: &mut impl FnMut(&ast::MetaItem) -> bool, +) -> bool { match cfg.kind { ast::MetaItemKind::List(ref mis) => { for mi in mis.iter() { diff --git a/src/libsyntax/feature_gate/builtin_attrs.rs b/src/libsyntax/feature_gate/builtin_attrs.rs index 7435b2e056a..36916de57fc 100644 --- a/src/libsyntax/feature_gate/builtin_attrs.rs +++ b/src/libsyntax/feature_gate/builtin_attrs.rs @@ -3,19 +3,15 @@ use AttributeType::*; use AttributeGate::*; -use super::check::{emit_feature_err, GateIssue}; use super::check::{EXPLAIN_ALLOW_INTERNAL_UNSAFE, EXPLAIN_ALLOW_INTERNAL_UNSTABLE}; use rustc_feature::{Features, Stability}; use crate::ast; -use crate::sess::ParseSess; use syntax_pos::symbol::{Symbol, sym}; -use syntax_pos::Span; use rustc_data_structures::fx::FxHashMap; use lazy_static::lazy_static; - type GateFn = fn(&Features) -> bool; macro_rules! cfg_fn { @@ -24,39 +20,19 @@ macro_rules! cfg_fn { } } +pub type GatedCfg = (Symbol, Symbol, GateFn); + /// `cfg(...)`'s that are feature gated. -const GATED_CFGS: &[(Symbol, Symbol, GateFn)] = &[ +const GATED_CFGS: &[GatedCfg] = &[ // (name in cfg, feature, function to check if the feature is enabled) (sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)), (sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)), (sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)), ]; -#[derive(Debug)] -pub struct GatedCfg { - span: Span, - index: usize, -} - -impl GatedCfg { - pub fn gate(cfg: &ast::MetaItem) -> Option { - GATED_CFGS.iter() - .position(|info| cfg.check_name(info.0)) - .map(|idx| { - GatedCfg { - span: cfg.span, - index: idx - } - }) - } - - pub fn check_and_emit(&self, sess: &ParseSess, features: &Features) { - let (cfg, feature, has_feature) = GATED_CFGS[self.index]; - if !has_feature(features) && !self.span.allows_unstable(feature) { - let explain = format!("`cfg({})` is experimental and subject to change", cfg); - emit_feature_err(sess, feature, self.span, GateIssue::Language, &explain); - } - } +/// Find a gated cfg determined by the `pred`icate which is given the cfg's name. +pub fn find_gated_cfg(pred: impl Fn(Symbol) -> bool) -> Option<&'static GatedCfg> { + GATED_CFGS.iter().find(|(cfg_sym, ..)| pred(*cfg_sym)) } // If you change this, please modify `src/doc/unstable-book` as well. You must diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 8e95fe3c34b..7f28ebb2b2d 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -101,7 +101,7 @@ pub mod feature_gate { }; mod builtin_attrs; pub use builtin_attrs::{ - AttributeGate, AttributeTemplate, AttributeType, GatedCfg, + AttributeGate, AttributeTemplate, AttributeType, find_gated_cfg, GatedCfg, BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP, deprecated_attributes, is_builtin_attr, is_builtin_attr_name, }; -- cgit 1.4.1-3-g733a5 From 4d9fde59aec621a2ea5c5ce3c1d7de3d2599d9ae Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 02:03:32 +0100 Subject: builtin_attrs: inline some strings --- src/libsyntax/feature_gate/builtin_attrs.rs | 8 +++++--- src/libsyntax/feature_gate/check.rs | 5 ----- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/libsyntax/feature_gate/builtin_attrs.rs b/src/libsyntax/feature_gate/builtin_attrs.rs index 36916de57fc..3e08e2af494 100644 --- a/src/libsyntax/feature_gate/builtin_attrs.rs +++ b/src/libsyntax/feature_gate/builtin_attrs.rs @@ -3,7 +3,6 @@ use AttributeType::*; use AttributeGate::*; -use super::check::{EXPLAIN_ALLOW_INTERNAL_UNSAFE, EXPLAIN_ALLOW_INTERNAL_UNSTABLE}; use rustc_feature::{Features, Stability}; use crate::ast; @@ -352,9 +351,12 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ), gated!( allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), - EXPLAIN_ALLOW_INTERNAL_UNSTABLE, + "allow_internal_unstable side-steps feature gating and stability checks", + ), + gated!( + allow_internal_unsafe, Normal, template!(Word), + "allow_internal_unsafe side-steps the unsafe_code lint", ), - gated!(allow_internal_unsafe, Normal, template!(Word), EXPLAIN_ALLOW_INTERNAL_UNSAFE), // ========================================================================== // Internal attributes: Type system related: diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 19e615f40fa..e89c1f910d3 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -153,11 +153,6 @@ const EXPLAIN_BOX_SYNTAX: &str = pub const EXPLAIN_STMT_ATTR_SYNTAX: &str = "attributes on expressions are experimental"; -pub const EXPLAIN_ALLOW_INTERNAL_UNSTABLE: &str = - "allow_internal_unstable side-steps feature gating and stability checks"; -pub const EXPLAIN_ALLOW_INTERNAL_UNSAFE: &str = - "allow_internal_unsafe side-steps the unsafe_code lint"; - pub const EXPLAIN_UNSIZED_TUPLE_COERCION: &str = "unsized tuple coercion is not stable enough for use and is subject to change"; -- cgit 1.4.1-3-g733a5 From d04b838a44b914411d967e32704d66d7f9e0b16f Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 02:20:07 +0100 Subject: move is_builtin_attr to syntax::attr --- src/librustc_passes/ast_validation.rs | 3 +-- src/librustc_resolve/build_reduced_graph.rs | 4 +--- src/libsyntax/attr/builtin.rs | 6 ++++++ src/libsyntax/feature_gate/builtin_attrs.rs | 11 ++--------- src/libsyntax/lib.rs | 2 +- src/libsyntax_expand/expand.rs | 4 ++-- 6 files changed, 13 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index e189b7175f9..5a29a56ad54 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -14,7 +14,6 @@ use rustc_parse::validate_attr; use syntax::ast::*; use syntax::attr; use syntax::expand::is_proc_macro_attr; -use syntax::feature_gate::is_builtin_attr; use syntax::print::pprust; use syntax::source_map::Spanned; use syntax::symbol::{kw, sym}; @@ -257,7 +256,7 @@ impl<'a> AstValidator<'a> { .flat_map(|i| i.attrs.as_ref()) .filter(|attr| { let arr = [sym::allow, sym::cfg, sym::cfg_attr, sym::deny, sym::forbid, sym::warn]; - !arr.contains(&attr.name_or_empty()) && is_builtin_attr(attr) + !arr.contains(&attr.name_or_empty()) && attr::is_builtin_attr(attr) }) .for_each(|attr| if attr.is_doc_comment() { let mut err = self.err_handler().struct_span_err( diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 6694ddc53d4..a621d54cf92 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -29,10 +29,8 @@ use errors::Applicability; use syntax::ast::{Name, Ident}; use syntax::attr; - use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId}; use syntax::ast::{MetaItemKind, StmtKind, TraitItem, TraitItemKind}; -use syntax::feature_gate::is_builtin_attr; use syntax::token::{self, Token}; use syntax::print::pprust; use syntax::{span_err, struct_span_err}; @@ -1231,7 +1229,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> { } fn visit_attribute(&mut self, attr: &'b ast::Attribute) { - if !attr.is_doc_comment() && is_builtin_attr(attr) { + if !attr.is_doc_comment() && attr::is_builtin_attr(attr) { self.r.builtin_attrs.push( (attr.get_normal_item().path.segments[0].ident, self.parent_scope) ); diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 4e7738439b2..2623386f584 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -2,6 +2,7 @@ use crate::ast::{self, Attribute, MetaItem, NestedMetaItem}; use crate::feature_gate::{find_gated_cfg, emit_feature_err, GatedCfg, GateIssue}; +use crate::feature_gate::is_builtin_attr_name; use crate::print::pprust; use crate::sess::ParseSess; @@ -10,12 +11,17 @@ use std::num::NonZeroU32; use syntax_pos::hygiene::Transparency; use syntax_pos::{symbol::Symbol, symbol::sym, Span}; use rustc_feature::Features; + use rustc_macros::HashStable_Generic; use super::{mark_used, MetaItemKind}; use rustc_error_codes::*; +pub fn is_builtin_attr(attr: &Attribute) -> bool { + attr.ident().filter(|ident| is_builtin_attr_name(ident.name)).is_some() +} + enum AttrError { MultipleItem(String), UnknownMetaItem(String, &'static [&'static str]), diff --git a/src/libsyntax/feature_gate/builtin_attrs.rs b/src/libsyntax/feature_gate/builtin_attrs.rs index 3e08e2af494..9b764d64c49 100644 --- a/src/libsyntax/feature_gate/builtin_attrs.rs +++ b/src/libsyntax/feature_gate/builtin_attrs.rs @@ -3,12 +3,9 @@ use AttributeType::*; use AttributeGate::*; +use rustc_data_structures::fx::FxHashMap; use rustc_feature::{Features, Stability}; - -use crate::ast; - use syntax_pos::symbol::{Symbol, sym}; -use rustc_data_structures::fx::FxHashMap; use lazy_static::lazy_static; type GateFn = fn(&Features) -> bool; @@ -580,14 +577,10 @@ pub fn deprecated_attributes() -> Vec<&'static BuiltinAttribute> { BUILTIN_ATTRIBUTES.iter().filter(|(.., gate)| gate.is_deprecated()).collect() } -pub fn is_builtin_attr_name(name: ast::Name) -> bool { +pub fn is_builtin_attr_name(name: Symbol) -> bool { BUILTIN_ATTRIBUTE_MAP.get(&name).is_some() } -pub fn is_builtin_attr(attr: &ast::Attribute) -> bool { - attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)).is_some() -} - lazy_static! { pub static ref BUILTIN_ATTRIBUTE_MAP: FxHashMap = { let mut map = FxHashMap::default(); diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 7f28ebb2b2d..74036bdcfb7 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -103,7 +103,7 @@ pub mod feature_gate { pub use builtin_attrs::{ AttributeGate, AttributeTemplate, AttributeType, find_gated_cfg, GatedCfg, BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP, - deprecated_attributes, is_builtin_attr, is_builtin_attr_name, + deprecated_attributes, is_builtin_attr_name, }; } pub mod mut_visit; diff --git a/src/libsyntax_expand/expand.rs b/src/libsyntax_expand/expand.rs index d8033759033..e4c4f4c43e6 100644 --- a/src/libsyntax_expand/expand.rs +++ b/src/libsyntax_expand/expand.rs @@ -12,9 +12,9 @@ use rustc_parse::parser::Parser; use rustc_parse::validate_attr; use syntax::ast::{self, AttrItem, Block, Ident, LitKind, NodeId, PatKind, Path}; use syntax::ast::{MacStmtStyle, StmtKind, ItemKind}; -use syntax::attr::{self, HasAttrs}; +use syntax::attr::{self, HasAttrs, is_builtin_attr}; use syntax::source_map::respan; -use syntax::feature_gate::{self, GateIssue, is_builtin_attr, emit_feature_err}; +use syntax::feature_gate::{self, GateIssue, emit_feature_err}; use syntax::mut_visit::*; use syntax::print::pprust; use syntax::ptr::P; -- cgit 1.4.1-3-g733a5 From 70234f16dfbd22a7315401d46f5f7da2729463b5 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 02:34:18 +0100 Subject: builtin_attrs.rs -> rustc_feature --- Cargo.lock | 4 + src/librustc_driver/Cargo.toml | 1 + src/librustc_driver/lib.rs | 3 +- src/librustc_feature/Cargo.toml | 2 + src/librustc_feature/builtin_attrs.rs | 595 ++++++++++++++++++++++++++++ src/librustc_feature/lib.rs | 6 + src/librustc_lint/builtin.rs | 3 +- src/librustc_lint/unused.rs | 5 +- src/librustc_parse/validate_attr.rs | 3 +- src/librustc_resolve/Cargo.toml | 1 + src/librustc_resolve/diagnostics.rs | 2 +- src/librustc_resolve/macros.rs | 6 +- src/libsyntax/attr/builtin.rs | 9 +- src/libsyntax/feature_gate/builtin_attrs.rs | 594 --------------------------- src/libsyntax/feature_gate/check.rs | 2 +- src/libsyntax/lib.rs | 6 - src/libsyntax_ext/util.rs | 2 +- 17 files changed, 624 insertions(+), 620 deletions(-) create mode 100644 src/librustc_feature/builtin_attrs.rs delete mode 100644 src/libsyntax/feature_gate/builtin_attrs.rs (limited to 'src') diff --git a/Cargo.lock b/Cargo.lock index 9ed2f021344..67259aed8eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3575,6 +3575,7 @@ dependencies = [ "rustc_data_structures", "rustc_error_codes", "rustc_errors", + "rustc_feature", "rustc_interface", "rustc_lint", "rustc_metadata", @@ -3612,6 +3613,8 @@ dependencies = [ name = "rustc_feature" version = "0.0.0" dependencies = [ + "lazy_static 1.3.0", + "rustc_data_structures", "syntax_pos", ] @@ -3855,6 +3858,7 @@ dependencies = [ "rustc_data_structures", "rustc_error_codes", "rustc_errors", + "rustc_feature", "rustc_metadata", "smallvec 1.0.0", "syntax", diff --git a/src/librustc_driver/Cargo.toml b/src/librustc_driver/Cargo.toml index 2b7e4d35248..d1cb4cbeb9b 100644 --- a/src/librustc_driver/Cargo.toml +++ b/src/librustc_driver/Cargo.toml @@ -19,6 +19,7 @@ rustc_target = { path = "../librustc_target" } rustc_lint = { path = "../librustc_lint" } rustc_data_structures = { path = "../librustc_data_structures" } errors = { path = "../librustc_errors", package = "rustc_errors" } +rustc_feature = { path = "../librustc_feature" } rustc_metadata = { path = "../librustc_metadata" } rustc_mir = { path = "../librustc_mir" } rustc_parse = { path = "../librustc_parse" } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 22f130ed3c9..89ef402bdb5 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -44,6 +44,7 @@ use errors::{PResult, registry::Registry}; use rustc_interface::interface; use rustc_interface::util::get_codegen_sysroot; use rustc_data_structures::sync::SeqCst; +use rustc_feature::find_gated_cfg; use rustc_serialize::json::ToJson; @@ -62,7 +63,7 @@ use std::time::Instant; use syntax::ast; use syntax::source_map::FileLoader; -use syntax::feature_gate::{find_gated_cfg, UnstableFeatures}; +use syntax::feature_gate::UnstableFeatures; use syntax_pos::symbol::sym; use syntax_pos::FileName; diff --git a/src/librustc_feature/Cargo.toml b/src/librustc_feature/Cargo.toml index 22e8366804b..40ce922947b 100644 --- a/src/librustc_feature/Cargo.toml +++ b/src/librustc_feature/Cargo.toml @@ -10,4 +10,6 @@ path = "lib.rs" doctest = false [dependencies] +rustc_data_structures = { path = "../librustc_data_structures" } +lazy_static = "1.0.0" syntax_pos = { path = "../libsyntax_pos" } diff --git a/src/librustc_feature/builtin_attrs.rs b/src/librustc_feature/builtin_attrs.rs new file mode 100644 index 00000000000..f72df00a8e8 --- /dev/null +++ b/src/librustc_feature/builtin_attrs.rs @@ -0,0 +1,595 @@ +//! Built-in attributes and `cfg` flag gating. + +use AttributeType::*; +use AttributeGate::*; + +use crate::{Features, Stability}; + +use rustc_data_structures::fx::FxHashMap; +use syntax_pos::symbol::{Symbol, sym}; +use lazy_static::lazy_static; + +type GateFn = fn(&Features) -> bool; + +macro_rules! cfg_fn { + ($field: ident) => { + (|features| { features.$field }) as GateFn + } +} + +pub type GatedCfg = (Symbol, Symbol, GateFn); + +/// `cfg(...)`'s that are feature gated. +const GATED_CFGS: &[GatedCfg] = &[ + // (name in cfg, feature, function to check if the feature is enabled) + (sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)), + (sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)), + (sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)), +]; + +/// Find a gated cfg determined by the `pred`icate which is given the cfg's name. +pub fn find_gated_cfg(pred: impl Fn(Symbol) -> bool) -> Option<&'static GatedCfg> { + GATED_CFGS.iter().find(|(cfg_sym, ..)| pred(*cfg_sym)) +} + +// If you change this, please modify `src/doc/unstable-book` as well. You must +// move that documentation into the relevant place in the other docs, and +// remove the chapter on the flag. + +#[derive(Copy, Clone, PartialEq, Debug)] +pub enum AttributeType { + /// Normal, builtin attribute that is consumed + /// by the compiler before the unused_attribute check + Normal, + + /// Builtin attribute that may not be consumed by the compiler + /// before the unused_attribute check. These attributes + /// will be ignored by the unused_attribute lint + Whitelisted, + + /// Builtin attribute that is only allowed at the crate level + CrateLevel, +} + +#[derive(Clone, Copy)] +pub enum AttributeGate { + /// Is gated by a given feature gate, reason + /// and function to check if enabled + Gated(Stability, Symbol, &'static str, fn(&Features) -> bool), + + /// Ungated attribute, can be used on all release channels + Ungated, +} + +// fn() is not Debug +impl std::fmt::Debug for AttributeGate { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match *self { + Self::Gated(ref stab, name, expl, _) => + write!(fmt, "Gated({:?}, {}, {})", stab, name, expl), + Self::Ungated => write!(fmt, "Ungated") + } + } +} + +impl AttributeGate { + fn is_deprecated(&self) -> bool { + match *self { + Self::Gated(Stability::Deprecated(_, _), ..) => true, + _ => false, + } + } +} + +/// A template that the attribute input must match. +/// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now. +#[derive(Clone, Copy)] +pub struct AttributeTemplate { + pub word: bool, + pub list: Option<&'static str>, + pub name_value_str: Option<&'static str>, +} + +impl AttributeTemplate { + pub fn only_word() -> Self { + Self { word: true, list: None, name_value_str: None } + } +} + +/// A convenience macro for constructing attribute templates. +/// E.g., `template!(Word, List: "description")` means that the attribute +/// supports forms `#[attr]` and `#[attr(description)]`. +macro_rules! template { + (Word) => { template!(@ true, None, None) }; + (List: $descr: expr) => { template!(@ false, Some($descr), None) }; + (NameValueStr: $descr: expr) => { template!(@ false, None, Some($descr)) }; + (Word, List: $descr: expr) => { template!(@ true, Some($descr), None) }; + (Word, NameValueStr: $descr: expr) => { template!(@ true, None, Some($descr)) }; + (List: $descr1: expr, NameValueStr: $descr2: expr) => { + template!(@ false, Some($descr1), Some($descr2)) + }; + (Word, List: $descr1: expr, NameValueStr: $descr2: expr) => { + template!(@ true, Some($descr1), Some($descr2)) + }; + (@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate { + word: $word, list: $list, name_value_str: $name_value_str + } }; +} + +macro_rules! ungated { + ($attr:ident, $typ:expr, $tpl:expr $(,)?) => { + (sym::$attr, $typ, $tpl, Ungated) + }; +} + +macro_rules! gated { + ($attr:ident, $typ:expr, $tpl:expr, $gate:ident, $msg:expr $(,)?) => { + (sym::$attr, $typ, $tpl, Gated(Stability::Unstable, sym::$gate, $msg, cfg_fn!($gate))) + }; + ($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => { + (sym::$attr, $typ, $tpl, Gated(Stability::Unstable, sym::$attr, $msg, cfg_fn!($attr))) + }; +} + +macro_rules! rustc_attr { + (TEST, $attr:ident, $typ:expr, $tpl:expr $(,)?) => { + rustc_attr!( + $attr, $typ, $tpl, + concat!("the `#[", stringify!($attr), "]` attribute is just used for rustc unit tests \ + and will never be stable", + ), + ) + }; + ($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => { + (sym::$attr, $typ, $tpl, + Gated(Stability::Unstable, sym::rustc_attrs, $msg, cfg_fn!(rustc_attrs))) + }; +} + +macro_rules! experimental { + ($attr:ident) => { + concat!("the `#[", stringify!($attr), "]` attribute is an experimental feature") + } +} + +const IMPL_DETAIL: &str = "internal implementation detail"; +const INTERNAL_UNSTABLE: &str = "this is an internal attribute that will never be stable"; + +pub type BuiltinAttribute = (Symbol, AttributeType, AttributeTemplate, AttributeGate); + +/// Attributes that have a special meaning to rustc or rustdoc. +pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ + // ========================================================================== + // Stable attributes: + // ========================================================================== + + // Condtional compilation: + ungated!(cfg, Normal, template!(List: "predicate")), + ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ...")), + + // Testing: + ungated!(ignore, Normal, template!(Word, NameValueStr: "reason")), + ungated!( + should_panic, Normal, + template!(Word, List: r#"expected = "reason"#, NameValueStr: "reason"), + ), + // FIXME(Centril): This can be used on stable but shouldn't. + ungated!(reexport_test_harness_main, Normal, template!(NameValueStr: "name")), + + // Macros: + ungated!(derive, Normal, template!(List: "Trait1, Trait2, ...")), + ungated!(automatically_derived, Normal, template!(Word)), + // FIXME(#14407) + ungated!(macro_use, Normal, template!(Word, List: "name1, name2, ...")), + ungated!(macro_escape, Normal, template!(Word)), // Deprecated synonym for `macro_use`. + ungated!(macro_export, Normal, template!(Word, List: "local_inner_macros")), + ungated!(proc_macro, Normal, template!(Word)), + ungated!( + proc_macro_derive, Normal, + template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"), + ), + ungated!(proc_macro_attribute, Normal, template!(Word)), + + // Lints: + ungated!(warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)), + ungated!(allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)), + ungated!(forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)), + ungated!(deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)), + ungated!(must_use, Whitelisted, template!(Word, NameValueStr: "reason")), + // FIXME(#14407) + ungated!( + deprecated, Normal, + template!( + Word, + List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#, + NameValueStr: "reason" + ), + ), + + // Crate properties: + ungated!(crate_name, CrateLevel, template!(NameValueStr: "name")), + ungated!(crate_type, CrateLevel, template!(NameValueStr: "bin|lib|...")), + ungated!(crate_id, CrateLevel, template!(NameValueStr: "ignored")), + + // ABI, linking, symbols, and FFI + ungated!( + link, Whitelisted, + template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ cfg = "...""#), + ), + ungated!(link_name, Whitelisted, template!(NameValueStr: "name")), + ungated!(no_link, Normal, template!(Word)), + ungated!(repr, Normal, template!(List: "C")), + ungated!(export_name, Whitelisted, template!(NameValueStr: "name")), + ungated!(link_section, Whitelisted, template!(NameValueStr: "name")), + ungated!(no_mangle, Whitelisted, template!(Word)), + ungated!(used, Whitelisted, template!(Word)), + + // Limits: + ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N")), + ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N")), + + // Entry point: + ungated!(main, Normal, template!(Word)), + ungated!(start, Normal, template!(Word)), + ungated!(no_start, CrateLevel, template!(Word)), + ungated!(no_main, CrateLevel, template!(Word)), + + // Modules, prelude, and resolution: + ungated!(path, Normal, template!(NameValueStr: "file")), + ungated!(no_std, CrateLevel, template!(Word)), + ungated!(no_implicit_prelude, Normal, template!(Word)), + ungated!(non_exhaustive, Whitelisted, template!(Word)), + + // Runtime + ungated!(windows_subsystem, Whitelisted, template!(NameValueStr: "windows|console")), + ungated!(panic_handler, Normal, template!(Word)), // RFC 2070 + + // Code generation: + ungated!(inline, Whitelisted, template!(Word, List: "always|never")), + ungated!(cold, Whitelisted, template!(Word)), + ungated!(no_builtins, Whitelisted, template!(Word)), + ungated!(target_feature, Whitelisted, template!(List: r#"enable = "name""#)), + + // FIXME: #14408 whitelist docs since rustdoc looks at them + ungated!(doc, Whitelisted, template!(List: "hidden|inline|...", NameValueStr: "string")), + + // ========================================================================== + // Unstable attributes: + // ========================================================================== + + // Linking: + gated!(naked, Whitelisted, template!(Word), naked_functions, experimental!(naked)), + gated!( + link_args, Normal, template!(NameValueStr: "args"), + "the `link_args` attribute is experimental and not portable across platforms, \ + it is recommended to use `#[link(name = \"foo\")] instead", + ), + gated!( + link_ordinal, Whitelisted, template!(List: "ordinal"), raw_dylib, + experimental!(link_ordinal) + ), + + // Plugins: + ( + sym::plugin_registrar, Normal, template!(Word), + Gated( + Stability::Deprecated( + "https://github.com/rust-lang/rust/pull/64675", + Some("may be removed in a future compiler version"), + ), + sym::plugin_registrar, + "compiler plugins are deprecated", + cfg_fn!(plugin_registrar) + ) + ), + ( + sym::plugin, CrateLevel, template!(List: "name|name(args)"), + Gated( + Stability::Deprecated( + "https://github.com/rust-lang/rust/pull/64675", + Some("may be removed in a future compiler version"), + ), + sym::plugin, + "compiler plugins are deprecated", + cfg_fn!(plugin) + ) + ), + + // Testing: + gated!(allow_fail, Normal, template!(Word), experimental!(allow_fail)), + gated!( + test_runner, CrateLevel, template!(List: "path"), custom_test_frameworks, + "custom test frameworks are an unstable feature", + ), + // RFC #1268 + gated!(marker, Normal, template!(Word), marker_trait_attr, experimental!(marker)), + gated!( + thread_local, Whitelisted, template!(Word), + "`#[thread_local]` is an experimental feature, and does not currently handle destructors", + ), + gated!(no_core, CrateLevel, template!(Word), experimental!(no_core)), + // RFC 2412 + gated!( + optimize, Whitelisted, template!(List: "size|speed"), optimize_attribute, + experimental!(optimize), + ), + + gated!(ffi_returns_twice, Whitelisted, template!(Word), experimental!(ffi_returns_twice)), + gated!(track_caller, Whitelisted, template!(Word), experimental!(track_caller)), + gated!( + register_attr, CrateLevel, template!(List: "attr1, attr2, ..."), + experimental!(register_attr), + ), + gated!( + register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), + experimental!(register_tool), + ), + + // ========================================================================== + // Internal attributes: Stability, deprecation, and unsafe: + // ========================================================================== + + ungated!(feature, CrateLevel, template!(List: "name1, name1, ...")), + // FIXME(#14407) -- only looked at on-demand so we can't + // guarantee they'll have already been checked. + ungated!( + rustc_deprecated, Whitelisted, + template!(List: r#"since = "version", reason = "...""#) + ), + // FIXME(#14407) + ungated!(stable, Whitelisted, template!(List: r#"feature = "name", since = "version""#)), + // FIXME(#14407) + ungated!( + unstable, Whitelisted, + template!(List: r#"feature = "name", reason = "...", issue = "N""#), + ), + gated!( + rustc_const_unstable, Normal, template!(List: r#"feature = "name""#), + "the `#[rustc_const_unstable]` attribute is an internal feature", + ), + gated!( + allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), + "allow_internal_unstable side-steps feature gating and stability checks", + ), + gated!( + allow_internal_unsafe, Normal, template!(Word), + "allow_internal_unsafe side-steps the unsafe_code lint", + ), + + // ========================================================================== + // Internal attributes: Type system related: + // ========================================================================== + + gated!(fundamental, Whitelisted, template!(Word), experimental!(fundamental)), + gated!( + // RFC #1445. + structural_match, Whitelisted, template!(Word), + "the semantics of constant patterns is not yet settled", + ), + gated!( + may_dangle, Normal, template!(Word), dropck_eyepatch, + "`may_dangle` has unstable semantics and may be removed in the future", + ), + + // ========================================================================== + // Internal attributes: Runtime related: + // ========================================================================== + + rustc_attr!(rustc_allocator, Whitelisted, template!(Word), IMPL_DETAIL), + rustc_attr!(rustc_allocator_nounwind, Whitelisted, template!(Word), IMPL_DETAIL), + gated!(alloc_error_handler, Normal, template!(Word), experimental!(alloc_error_handler)), + gated!( + default_lib_allocator, Whitelisted, template!(Word), allocator_internals, + experimental!(default_lib_allocator), + ), + gated!( + needs_allocator, Normal, template!(Word), allocator_internals, + experimental!(needs_allocator), + ), + gated!(panic_runtime, Whitelisted, template!(Word), experimental!(panic_runtime)), + gated!(needs_panic_runtime, Whitelisted, template!(Word), experimental!(needs_panic_runtime)), + gated!( + unwind, Whitelisted, template!(List: "allowed|aborts"), unwind_attributes, + experimental!(unwind), + ), + gated!( + compiler_builtins, Whitelisted, template!(Word), + "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \ + which contains compiler-rt intrinsics and will never be stable", + ), + gated!( + sanitizer_runtime, Whitelisted, template!(Word), + "the `#[sanitizer_runtime]` attribute is used to identify crates that contain the runtime \ + of a sanitizer and will never be stable", + ), + gated!( + profiler_runtime, Whitelisted, template!(Word), + "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \ + which contains the profiler runtime and will never be stable", + ), + + // ========================================================================== + // Internal attributes, Linkage: + // ========================================================================== + + gated!( + linkage, Whitelisted, template!(NameValueStr: "external|internal|..."), + "the `linkage` attribute is experimental and not portable across platforms", + ), + rustc_attr!(rustc_std_internal_symbol, Whitelisted, template!(Word), INTERNAL_UNSTABLE), + + // ========================================================================== + // Internal attributes, Macro related: + // ========================================================================== + + rustc_attr!(rustc_builtin_macro, Whitelisted, template!(Word), IMPL_DETAIL), + rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), INTERNAL_UNSTABLE), + rustc_attr!( + rustc_macro_transparency, Whitelisted, + template!(NameValueStr: "transparent|semitransparent|opaque"), + "used internally for testing macro hygiene", + ), + + // ========================================================================== + // Internal attributes, Diagnostics related: + // ========================================================================== + + rustc_attr!( + rustc_on_unimplemented, Whitelisted, + template!( + List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#, + NameValueStr: "message" + ), + INTERNAL_UNSTABLE + ), + // Whitelists "identity-like" conversion methods to suggest on type mismatch. + rustc_attr!(rustc_conversion_suggestion, Whitelisted, template!(Word), INTERNAL_UNSTABLE), + + // ========================================================================== + // Internal attributes, Const related: + // ========================================================================== + + rustc_attr!(rustc_promotable, Whitelisted, template!(Word), IMPL_DETAIL), + rustc_attr!(rustc_allow_const_fn_ptr, Whitelisted, template!(Word), IMPL_DETAIL), + rustc_attr!(rustc_args_required_const, Whitelisted, template!(List: "N"), INTERNAL_UNSTABLE), + + // ========================================================================== + // Internal attributes, Layout related: + // ========================================================================== + + rustc_attr!( + rustc_layout_scalar_valid_range_start, Whitelisted, template!(List: "value"), + "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \ + niche optimizations in libcore and will never be stable", + ), + rustc_attr!( + rustc_layout_scalar_valid_range_end, Whitelisted, template!(List: "value"), + "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \ + niche optimizations in libcore and will never be stable", + ), + rustc_attr!( + rustc_nonnull_optimization_guaranteed, Whitelisted, template!(Word), + "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to enable \ + niche optimizations in libcore and will never be stable", + ), + + // ========================================================================== + // Internal attributes, Misc: + // ========================================================================== + gated!( + lang, Normal, template!(NameValueStr: "name"), lang_items, + "language items are subject to change", + ), + ( + sym::rustc_diagnostic_item, + Normal, + template!(NameValueStr: "name"), + Gated( + Stability::Unstable, + sym::rustc_attrs, + "diagnostic items compiler internal support for linting", + cfg_fn!(rustc_attrs), + ), + ), + ( + sym::no_debug, Whitelisted, template!(Word), + Gated( + Stability::Deprecated("https://github.com/rust-lang/rust/issues/29721", None), + sym::no_debug, + "the `#[no_debug]` attribute was an experimental feature that has been \ + deprecated due to lack of demand", + cfg_fn!(no_debug) + ) + ), + gated!( + // Used in resolve: + prelude_import, Whitelisted, template!(Word), + "`#[prelude_import]` is for use by rustc only", + ), + gated!( + rustc_paren_sugar, Normal, template!(Word), unboxed_closures, + "unboxed_closures are still evolving", + ), + rustc_attr!( + rustc_inherit_overflow_checks, Whitelisted, template!(Word), + "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \ + overflow checking behavior of several libcore functions that are inlined \ + across crates and will never be stable", + ), + rustc_attr!(rustc_reservation_impl, Normal, template!(NameValueStr: "reservation message"), + "the `#[rustc_reservation_impl]` attribute is internally used \ + for reserving for `for From for T` impl" + ), + rustc_attr!( + rustc_test_marker, Normal, template!(Word), + "the `#[rustc_test_marker]` attribute is used internally to track tests", + ), + + // ========================================================================== + // Internal attributes, Testing: + // ========================================================================== + + rustc_attr!(TEST, rustc_outlives, Normal, template!(Word)), + rustc_attr!(TEST, rustc_variance, Normal, template!(Word)), + rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ...")), + rustc_attr!(TEST, rustc_regions, Normal, template!(Word)), + rustc_attr!( + TEST, rustc_error, Whitelisted, + template!(Word, List: "delay_span_bug_from_inside_query") + ), + rustc_attr!(TEST, rustc_dump_user_substs, Whitelisted, template!(Word)), + rustc_attr!(TEST, rustc_if_this_changed, Whitelisted, template!(Word, List: "DepNode")), + rustc_attr!(TEST, rustc_then_this_would_need, Whitelisted, template!(List: "DepNode")), + rustc_attr!( + TEST, rustc_dirty, Whitelisted, + template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#), + ), + rustc_attr!( + TEST, rustc_clean, Whitelisted, + template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#), + ), + rustc_attr!( + TEST, rustc_partition_reused, Whitelisted, + template!(List: r#"cfg = "...", module = "...""#), + ), + rustc_attr!( + TEST, rustc_partition_codegened, Whitelisted, + template!(List: r#"cfg = "...", module = "...""#), + ), + rustc_attr!( + TEST, rustc_expected_cgu_reuse, Whitelisted, + template!(List: r#"cfg = "...", module = "...", kind = "...""#), + ), + rustc_attr!(TEST, rustc_synthetic, Whitelisted, template!(Word)), + rustc_attr!(TEST, rustc_symbol_name, Whitelisted, template!(Word)), + rustc_attr!(TEST, rustc_def_path, Whitelisted, template!(Word)), + rustc_attr!(TEST, rustc_mir, Whitelisted, template!(List: "arg1, arg2, ...")), + rustc_attr!(TEST, rustc_dump_program_clauses, Whitelisted, template!(Word)), + rustc_attr!(TEST, rustc_dump_env_program_clauses, Whitelisted, template!(Word)), + rustc_attr!(TEST, rustc_object_lifetime_default, Whitelisted, template!(Word)), + rustc_attr!(TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/)), + gated!( + omit_gdb_pretty_printer_section, Whitelisted, template!(Word), + "the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite", + ), +]; + +pub fn deprecated_attributes() -> Vec<&'static BuiltinAttribute> { + BUILTIN_ATTRIBUTES.iter().filter(|(.., gate)| gate.is_deprecated()).collect() +} + +pub fn is_builtin_attr_name(name: Symbol) -> bool { + BUILTIN_ATTRIBUTE_MAP.get(&name).is_some() +} + +lazy_static! { + pub static ref BUILTIN_ATTRIBUTE_MAP: FxHashMap = { + let mut map = FxHashMap::default(); + for attr in BUILTIN_ATTRIBUTES.iter() { + if map.insert(attr.0, attr).is_some() { + panic!("duplicate builtin attribute `{}`", attr.0); + } + } + map + }; +} diff --git a/src/librustc_feature/lib.rs b/src/librustc_feature/lib.rs index 5d248f75216..bda1449d85c 100644 --- a/src/librustc_feature/lib.rs +++ b/src/librustc_feature/lib.rs @@ -15,6 +15,7 @@ mod accepted; mod removed; mod active; +mod builtin_attrs; use std::fmt; use std::num::NonZeroU32; @@ -67,3 +68,8 @@ pub enum Stability { pub use accepted::ACCEPTED_FEATURES; pub use active::{ACTIVE_FEATURES, Features, INCOMPLETE_FEATURES}; pub use removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; +pub use builtin_attrs::{ + AttributeGate, AttributeTemplate, AttributeType, find_gated_cfg, GatedCfg, + BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP, + deprecated_attributes, is_builtin_attr_name, +}; diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 284b23a14e7..5d3a6cccc4e 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -34,6 +34,7 @@ use lint::{LateContext, LintContext, LintArray}; use lint::{LintPass, LateLintPass, EarlyLintPass, EarlyContext}; use rustc::util::nodemap::FxHashSet; +use rustc_feature::{AttributeGate, AttributeTemplate, AttributeType, deprecated_attributes}; use rustc_feature::Stability; use syntax::tokenstream::{TokenTree, TokenStream}; @@ -42,8 +43,6 @@ use syntax::ptr::P; use syntax::attr::{self, HasAttrs}; use syntax::source_map::Spanned; use syntax::edition::Edition; -use syntax::feature_gate::{AttributeGate, AttributeTemplate, AttributeType}; -use syntax::feature_gate::deprecated_attributes; use syntax_pos::{BytePos, Span}; use syntax::symbol::{Symbol, kw, sym}; use syntax::errors::{Applicability, DiagnosticBuilder}; diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 9f293bdaa10..f7de7ec7e18 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -1,3 +1,4 @@ +use rustc::hir; use rustc::hir::def::{Res, DefKind}; use rustc::hir::def_id::DefId; use rustc::lint; @@ -7,19 +8,17 @@ use rustc::ty::adjustment; use rustc_data_structures::fx::FxHashMap; use lint::{LateContext, EarlyContext, LintContext, LintArray}; use lint::{LintPass, EarlyLintPass, LateLintPass}; +use rustc_feature::{AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP}; use syntax::ast; use syntax::attr; use syntax::errors::{Applicability, pluralize}; -use syntax::feature_gate::{AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP}; use syntax::print::pprust; use syntax::symbol::{kw, sym}; use syntax::symbol::Symbol; use syntax::util::parser; use syntax_pos::{Span, BytePos}; -use rustc::hir; - use log::debug; declare_lint! { diff --git a/src/librustc_parse/validate_attr.rs b/src/librustc_parse/validate_attr.rs index e6284858a21..a3c9e266593 100644 --- a/src/librustc_parse/validate_attr.rs +++ b/src/librustc_parse/validate_attr.rs @@ -1,11 +1,10 @@ //! Meta-syntax validation logic of attributes for post-expansion. use errors::{PResult, Applicability}; -use syntax::feature_gate::AttributeTemplate; +use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP}; use syntax::ast::{self, Attribute, AttrKind, Ident, MetaItem, MetaItemKind}; use syntax::attr::mk_name_value_item_str; use syntax::early_buffered_lints::BufferedEarlyLintId; -use syntax::feature_gate::BUILTIN_ATTRIBUTE_MAP; use syntax::token; use syntax::tokenstream::TokenTree; use syntax::sess::ParseSess; diff --git a/src/librustc_resolve/Cargo.toml b/src/librustc_resolve/Cargo.toml index 6cce893f8ec..caca20e4221 100644 --- a/src/librustc_resolve/Cargo.toml +++ b/src/librustc_resolve/Cargo.toml @@ -20,6 +20,7 @@ arena = { path = "../libarena" } errors = { path = "../librustc_errors", package = "rustc_errors" } syntax_pos = { path = "../libsyntax_pos" } rustc_data_structures = { path = "../librustc_data_structures" } +rustc_feature = { path = "../librustc_feature" } rustc_metadata = { path = "../librustc_metadata" } rustc_error_codes = { path = "../librustc_error_codes" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index e134b8b92ac..4dcafb6d279 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -9,8 +9,8 @@ use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId}; use rustc::session::Session; use rustc::ty::{self, DefIdTree}; use rustc::util::nodemap::FxHashSet; +use rustc_feature::BUILTIN_ATTRIBUTES; use syntax::ast::{self, Ident, Path}; -use syntax::feature_gate::BUILTIN_ATTRIBUTES; use syntax::source_map::SourceMap; use syntax::struct_span_err; use syntax::symbol::{Symbol, kw}; diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 21c24f9da1c..cc5bc2b41dc 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -12,18 +12,18 @@ use rustc::middle::stability; use rustc::session::Session; use rustc::util::nodemap::FxHashSet; use rustc::{ty, lint, span_bug}; +use rustc_feature::is_builtin_attr_name; use syntax::ast::{self, NodeId, Ident}; use syntax::attr::{self, StabilityLevel}; use syntax::edition::Edition; -use syntax::feature_gate::{emit_feature_err, is_builtin_attr_name}; -use syntax::feature_gate::GateIssue; +use syntax::feature_gate::{emit_feature_err, GateIssue}; use syntax::print::pprust; -use syntax::symbol::{Symbol, kw, sym}; use syntax_expand::base::{self, InvocationRes, Indeterminate}; use syntax_expand::base::SyntaxExtension; use syntax_expand::expand::{AstFragment, AstFragmentKind, Invocation, InvocationKind}; use syntax_expand::compile_declarative_macro; use syntax_pos::hygiene::{self, ExpnId, ExpnData, ExpnKind}; +use syntax_pos::symbol::{Symbol, kw, sym}; use syntax_pos::{Span, DUMMY_SP}; use std::{mem, ptr}; diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 2623386f584..bbcb8cc3c62 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -1,8 +1,8 @@ //! Parsing and validation of builtin attributes +use super::{mark_used, MetaItemKind}; use crate::ast::{self, Attribute, MetaItem, NestedMetaItem}; -use crate::feature_gate::{find_gated_cfg, emit_feature_err, GatedCfg, GateIssue}; -use crate::feature_gate::is_builtin_attr_name; +use crate::feature_gate::{emit_feature_err, GateIssue}; use crate::print::pprust; use crate::sess::ParseSess; @@ -10,12 +10,9 @@ use errors::{Applicability, Handler}; use std::num::NonZeroU32; use syntax_pos::hygiene::Transparency; use syntax_pos::{symbol::Symbol, symbol::sym, Span}; -use rustc_feature::Features; - +use rustc_feature::{Features, find_gated_cfg, GatedCfg, is_builtin_attr_name}; use rustc_macros::HashStable_Generic; -use super::{mark_used, MetaItemKind}; - use rustc_error_codes::*; pub fn is_builtin_attr(attr: &Attribute) -> bool { diff --git a/src/libsyntax/feature_gate/builtin_attrs.rs b/src/libsyntax/feature_gate/builtin_attrs.rs deleted file mode 100644 index 9b764d64c49..00000000000 --- a/src/libsyntax/feature_gate/builtin_attrs.rs +++ /dev/null @@ -1,594 +0,0 @@ -//! Built-in attributes and `cfg` flag gating. - -use AttributeType::*; -use AttributeGate::*; - -use rustc_data_structures::fx::FxHashMap; -use rustc_feature::{Features, Stability}; -use syntax_pos::symbol::{Symbol, sym}; -use lazy_static::lazy_static; - -type GateFn = fn(&Features) -> bool; - -macro_rules! cfg_fn { - ($field: ident) => { - (|features| { features.$field }) as GateFn - } -} - -pub type GatedCfg = (Symbol, Symbol, GateFn); - -/// `cfg(...)`'s that are feature gated. -const GATED_CFGS: &[GatedCfg] = &[ - // (name in cfg, feature, function to check if the feature is enabled) - (sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)), - (sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)), - (sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)), -]; - -/// Find a gated cfg determined by the `pred`icate which is given the cfg's name. -pub fn find_gated_cfg(pred: impl Fn(Symbol) -> bool) -> Option<&'static GatedCfg> { - GATED_CFGS.iter().find(|(cfg_sym, ..)| pred(*cfg_sym)) -} - -// If you change this, please modify `src/doc/unstable-book` as well. You must -// move that documentation into the relevant place in the other docs, and -// remove the chapter on the flag. - -#[derive(Copy, Clone, PartialEq, Debug)] -pub enum AttributeType { - /// Normal, builtin attribute that is consumed - /// by the compiler before the unused_attribute check - Normal, - - /// Builtin attribute that may not be consumed by the compiler - /// before the unused_attribute check. These attributes - /// will be ignored by the unused_attribute lint - Whitelisted, - - /// Builtin attribute that is only allowed at the crate level - CrateLevel, -} - -#[derive(Clone, Copy)] -pub enum AttributeGate { - /// Is gated by a given feature gate, reason - /// and function to check if enabled - Gated(Stability, Symbol, &'static str, fn(&Features) -> bool), - - /// Ungated attribute, can be used on all release channels - Ungated, -} - -// fn() is not Debug -impl std::fmt::Debug for AttributeGate { - fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match *self { - Self::Gated(ref stab, name, expl, _) => - write!(fmt, "Gated({:?}, {}, {})", stab, name, expl), - Self::Ungated => write!(fmt, "Ungated") - } - } -} - -impl AttributeGate { - fn is_deprecated(&self) -> bool { - match *self { - Self::Gated(Stability::Deprecated(_, _), ..) => true, - _ => false, - } - } -} - -/// A template that the attribute input must match. -/// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now. -#[derive(Clone, Copy)] -pub struct AttributeTemplate { - pub word: bool, - pub list: Option<&'static str>, - pub name_value_str: Option<&'static str>, -} - -impl AttributeTemplate { - pub fn only_word() -> Self { - Self { word: true, list: None, name_value_str: None } - } -} - -/// A convenience macro for constructing attribute templates. -/// E.g., `template!(Word, List: "description")` means that the attribute -/// supports forms `#[attr]` and `#[attr(description)]`. -macro_rules! template { - (Word) => { template!(@ true, None, None) }; - (List: $descr: expr) => { template!(@ false, Some($descr), None) }; - (NameValueStr: $descr: expr) => { template!(@ false, None, Some($descr)) }; - (Word, List: $descr: expr) => { template!(@ true, Some($descr), None) }; - (Word, NameValueStr: $descr: expr) => { template!(@ true, None, Some($descr)) }; - (List: $descr1: expr, NameValueStr: $descr2: expr) => { - template!(@ false, Some($descr1), Some($descr2)) - }; - (Word, List: $descr1: expr, NameValueStr: $descr2: expr) => { - template!(@ true, Some($descr1), Some($descr2)) - }; - (@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate { - word: $word, list: $list, name_value_str: $name_value_str - } }; -} - -macro_rules! ungated { - ($attr:ident, $typ:expr, $tpl:expr $(,)?) => { - (sym::$attr, $typ, $tpl, Ungated) - }; -} - -macro_rules! gated { - ($attr:ident, $typ:expr, $tpl:expr, $gate:ident, $msg:expr $(,)?) => { - (sym::$attr, $typ, $tpl, Gated(Stability::Unstable, sym::$gate, $msg, cfg_fn!($gate))) - }; - ($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => { - (sym::$attr, $typ, $tpl, Gated(Stability::Unstable, sym::$attr, $msg, cfg_fn!($attr))) - }; -} - -macro_rules! rustc_attr { - (TEST, $attr:ident, $typ:expr, $tpl:expr $(,)?) => { - rustc_attr!( - $attr, $typ, $tpl, - concat!("the `#[", stringify!($attr), "]` attribute is just used for rustc unit tests \ - and will never be stable", - ), - ) - }; - ($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => { - (sym::$attr, $typ, $tpl, - Gated(Stability::Unstable, sym::rustc_attrs, $msg, cfg_fn!(rustc_attrs))) - }; -} - -macro_rules! experimental { - ($attr:ident) => { - concat!("the `#[", stringify!($attr), "]` attribute is an experimental feature") - } -} - -const IMPL_DETAIL: &str = "internal implementation detail"; -const INTERNAL_UNSTABLE: &str = "this is an internal attribute that will never be stable"; - -pub type BuiltinAttribute = (Symbol, AttributeType, AttributeTemplate, AttributeGate); - -/// Attributes that have a special meaning to rustc or rustdoc. -pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ - // ========================================================================== - // Stable attributes: - // ========================================================================== - - // Condtional compilation: - ungated!(cfg, Normal, template!(List: "predicate")), - ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ...")), - - // Testing: - ungated!(ignore, Normal, template!(Word, NameValueStr: "reason")), - ungated!( - should_panic, Normal, - template!(Word, List: r#"expected = "reason"#, NameValueStr: "reason"), - ), - // FIXME(Centril): This can be used on stable but shouldn't. - ungated!(reexport_test_harness_main, Normal, template!(NameValueStr: "name")), - - // Macros: - ungated!(derive, Normal, template!(List: "Trait1, Trait2, ...")), - ungated!(automatically_derived, Normal, template!(Word)), - // FIXME(#14407) - ungated!(macro_use, Normal, template!(Word, List: "name1, name2, ...")), - ungated!(macro_escape, Normal, template!(Word)), // Deprecated synonym for `macro_use`. - ungated!(macro_export, Normal, template!(Word, List: "local_inner_macros")), - ungated!(proc_macro, Normal, template!(Word)), - ungated!( - proc_macro_derive, Normal, - template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"), - ), - ungated!(proc_macro_attribute, Normal, template!(Word)), - - // Lints: - ungated!(warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)), - ungated!(allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)), - ungated!(forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)), - ungated!(deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)), - ungated!(must_use, Whitelisted, template!(Word, NameValueStr: "reason")), - // FIXME(#14407) - ungated!( - deprecated, Normal, - template!( - Word, - List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#, - NameValueStr: "reason" - ), - ), - - // Crate properties: - ungated!(crate_name, CrateLevel, template!(NameValueStr: "name")), - ungated!(crate_type, CrateLevel, template!(NameValueStr: "bin|lib|...")), - ungated!(crate_id, CrateLevel, template!(NameValueStr: "ignored")), - - // ABI, linking, symbols, and FFI - ungated!( - link, Whitelisted, - template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ cfg = "...""#), - ), - ungated!(link_name, Whitelisted, template!(NameValueStr: "name")), - ungated!(no_link, Normal, template!(Word)), - ungated!(repr, Normal, template!(List: "C")), - ungated!(export_name, Whitelisted, template!(NameValueStr: "name")), - ungated!(link_section, Whitelisted, template!(NameValueStr: "name")), - ungated!(no_mangle, Whitelisted, template!(Word)), - ungated!(used, Whitelisted, template!(Word)), - - // Limits: - ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N")), - ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N")), - - // Entry point: - ungated!(main, Normal, template!(Word)), - ungated!(start, Normal, template!(Word)), - ungated!(no_start, CrateLevel, template!(Word)), - ungated!(no_main, CrateLevel, template!(Word)), - - // Modules, prelude, and resolution: - ungated!(path, Normal, template!(NameValueStr: "file")), - ungated!(no_std, CrateLevel, template!(Word)), - ungated!(no_implicit_prelude, Normal, template!(Word)), - ungated!(non_exhaustive, Whitelisted, template!(Word)), - - // Runtime - ungated!(windows_subsystem, Whitelisted, template!(NameValueStr: "windows|console")), - ungated!(panic_handler, Normal, template!(Word)), // RFC 2070 - - // Code generation: - ungated!(inline, Whitelisted, template!(Word, List: "always|never")), - ungated!(cold, Whitelisted, template!(Word)), - ungated!(no_builtins, Whitelisted, template!(Word)), - ungated!(target_feature, Whitelisted, template!(List: r#"enable = "name""#)), - - // FIXME: #14408 whitelist docs since rustdoc looks at them - ungated!(doc, Whitelisted, template!(List: "hidden|inline|...", NameValueStr: "string")), - - // ========================================================================== - // Unstable attributes: - // ========================================================================== - - // Linking: - gated!(naked, Whitelisted, template!(Word), naked_functions, experimental!(naked)), - gated!( - link_args, Normal, template!(NameValueStr: "args"), - "the `link_args` attribute is experimental and not portable across platforms, \ - it is recommended to use `#[link(name = \"foo\")] instead", - ), - gated!( - link_ordinal, Whitelisted, template!(List: "ordinal"), raw_dylib, - experimental!(link_ordinal) - ), - - // Plugins: - ( - sym::plugin_registrar, Normal, template!(Word), - Gated( - Stability::Deprecated( - "https://github.com/rust-lang/rust/pull/64675", - Some("may be removed in a future compiler version"), - ), - sym::plugin_registrar, - "compiler plugins are deprecated", - cfg_fn!(plugin_registrar) - ) - ), - ( - sym::plugin, CrateLevel, template!(List: "name|name(args)"), - Gated( - Stability::Deprecated( - "https://github.com/rust-lang/rust/pull/64675", - Some("may be removed in a future compiler version"), - ), - sym::plugin, - "compiler plugins are deprecated", - cfg_fn!(plugin) - ) - ), - - // Testing: - gated!(allow_fail, Normal, template!(Word), experimental!(allow_fail)), - gated!( - test_runner, CrateLevel, template!(List: "path"), custom_test_frameworks, - "custom test frameworks are an unstable feature", - ), - // RFC #1268 - gated!(marker, Normal, template!(Word), marker_trait_attr, experimental!(marker)), - gated!( - thread_local, Whitelisted, template!(Word), - "`#[thread_local]` is an experimental feature, and does not currently handle destructors", - ), - gated!(no_core, CrateLevel, template!(Word), experimental!(no_core)), - // RFC 2412 - gated!( - optimize, Whitelisted, template!(List: "size|speed"), optimize_attribute, - experimental!(optimize), - ), - - gated!(ffi_returns_twice, Whitelisted, template!(Word), experimental!(ffi_returns_twice)), - gated!(track_caller, Whitelisted, template!(Word), experimental!(track_caller)), - gated!( - register_attr, CrateLevel, template!(List: "attr1, attr2, ..."), - experimental!(register_attr), - ), - gated!( - register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), - experimental!(register_tool), - ), - - // ========================================================================== - // Internal attributes: Stability, deprecation, and unsafe: - // ========================================================================== - - ungated!(feature, CrateLevel, template!(List: "name1, name1, ...")), - // FIXME(#14407) -- only looked at on-demand so we can't - // guarantee they'll have already been checked. - ungated!( - rustc_deprecated, Whitelisted, - template!(List: r#"since = "version", reason = "...""#) - ), - // FIXME(#14407) - ungated!(stable, Whitelisted, template!(List: r#"feature = "name", since = "version""#)), - // FIXME(#14407) - ungated!( - unstable, Whitelisted, - template!(List: r#"feature = "name", reason = "...", issue = "N""#), - ), - gated!( - rustc_const_unstable, Normal, template!(List: r#"feature = "name""#), - "the `#[rustc_const_unstable]` attribute is an internal feature", - ), - gated!( - allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), - "allow_internal_unstable side-steps feature gating and stability checks", - ), - gated!( - allow_internal_unsafe, Normal, template!(Word), - "allow_internal_unsafe side-steps the unsafe_code lint", - ), - - // ========================================================================== - // Internal attributes: Type system related: - // ========================================================================== - - gated!(fundamental, Whitelisted, template!(Word), experimental!(fundamental)), - gated!( - // RFC #1445. - structural_match, Whitelisted, template!(Word), - "the semantics of constant patterns is not yet settled", - ), - gated!( - may_dangle, Normal, template!(Word), dropck_eyepatch, - "`may_dangle` has unstable semantics and may be removed in the future", - ), - - // ========================================================================== - // Internal attributes: Runtime related: - // ========================================================================== - - rustc_attr!(rustc_allocator, Whitelisted, template!(Word), IMPL_DETAIL), - rustc_attr!(rustc_allocator_nounwind, Whitelisted, template!(Word), IMPL_DETAIL), - gated!(alloc_error_handler, Normal, template!(Word), experimental!(alloc_error_handler)), - gated!( - default_lib_allocator, Whitelisted, template!(Word), allocator_internals, - experimental!(default_lib_allocator), - ), - gated!( - needs_allocator, Normal, template!(Word), allocator_internals, - experimental!(needs_allocator), - ), - gated!(panic_runtime, Whitelisted, template!(Word), experimental!(panic_runtime)), - gated!(needs_panic_runtime, Whitelisted, template!(Word), experimental!(needs_panic_runtime)), - gated!( - unwind, Whitelisted, template!(List: "allowed|aborts"), unwind_attributes, - experimental!(unwind), - ), - gated!( - compiler_builtins, Whitelisted, template!(Word), - "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \ - which contains compiler-rt intrinsics and will never be stable", - ), - gated!( - sanitizer_runtime, Whitelisted, template!(Word), - "the `#[sanitizer_runtime]` attribute is used to identify crates that contain the runtime \ - of a sanitizer and will never be stable", - ), - gated!( - profiler_runtime, Whitelisted, template!(Word), - "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \ - which contains the profiler runtime and will never be stable", - ), - - // ========================================================================== - // Internal attributes, Linkage: - // ========================================================================== - - gated!( - linkage, Whitelisted, template!(NameValueStr: "external|internal|..."), - "the `linkage` attribute is experimental and not portable across platforms", - ), - rustc_attr!(rustc_std_internal_symbol, Whitelisted, template!(Word), INTERNAL_UNSTABLE), - - // ========================================================================== - // Internal attributes, Macro related: - // ========================================================================== - - rustc_attr!(rustc_builtin_macro, Whitelisted, template!(Word), IMPL_DETAIL), - rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), INTERNAL_UNSTABLE), - rustc_attr!( - rustc_macro_transparency, Whitelisted, - template!(NameValueStr: "transparent|semitransparent|opaque"), - "used internally for testing macro hygiene", - ), - - // ========================================================================== - // Internal attributes, Diagnostics related: - // ========================================================================== - - rustc_attr!( - rustc_on_unimplemented, Whitelisted, - template!( - List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#, - NameValueStr: "message" - ), - INTERNAL_UNSTABLE - ), - // Whitelists "identity-like" conversion methods to suggest on type mismatch. - rustc_attr!(rustc_conversion_suggestion, Whitelisted, template!(Word), INTERNAL_UNSTABLE), - - // ========================================================================== - // Internal attributes, Const related: - // ========================================================================== - - rustc_attr!(rustc_promotable, Whitelisted, template!(Word), IMPL_DETAIL), - rustc_attr!(rustc_allow_const_fn_ptr, Whitelisted, template!(Word), IMPL_DETAIL), - rustc_attr!(rustc_args_required_const, Whitelisted, template!(List: "N"), INTERNAL_UNSTABLE), - - // ========================================================================== - // Internal attributes, Layout related: - // ========================================================================== - - rustc_attr!( - rustc_layout_scalar_valid_range_start, Whitelisted, template!(List: "value"), - "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \ - niche optimizations in libcore and will never be stable", - ), - rustc_attr!( - rustc_layout_scalar_valid_range_end, Whitelisted, template!(List: "value"), - "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \ - niche optimizations in libcore and will never be stable", - ), - rustc_attr!( - rustc_nonnull_optimization_guaranteed, Whitelisted, template!(Word), - "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to enable \ - niche optimizations in libcore and will never be stable", - ), - - // ========================================================================== - // Internal attributes, Misc: - // ========================================================================== - gated!( - lang, Normal, template!(NameValueStr: "name"), lang_items, - "language items are subject to change", - ), - ( - sym::rustc_diagnostic_item, - Normal, - template!(NameValueStr: "name"), - Gated( - Stability::Unstable, - sym::rustc_attrs, - "diagnostic items compiler internal support for linting", - cfg_fn!(rustc_attrs), - ), - ), - ( - sym::no_debug, Whitelisted, template!(Word), - Gated( - Stability::Deprecated("https://github.com/rust-lang/rust/issues/29721", None), - sym::no_debug, - "the `#[no_debug]` attribute was an experimental feature that has been \ - deprecated due to lack of demand", - cfg_fn!(no_debug) - ) - ), - gated!( - // Used in resolve: - prelude_import, Whitelisted, template!(Word), - "`#[prelude_import]` is for use by rustc only", - ), - gated!( - rustc_paren_sugar, Normal, template!(Word), unboxed_closures, - "unboxed_closures are still evolving", - ), - rustc_attr!( - rustc_inherit_overflow_checks, Whitelisted, template!(Word), - "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \ - overflow checking behavior of several libcore functions that are inlined \ - across crates and will never be stable", - ), - rustc_attr!(rustc_reservation_impl, Normal, template!(NameValueStr: "reservation message"), - "the `#[rustc_reservation_impl]` attribute is internally used \ - for reserving for `for From for T` impl" - ), - rustc_attr!( - rustc_test_marker, Normal, template!(Word), - "the `#[rustc_test_marker]` attribute is used internally to track tests", - ), - - // ========================================================================== - // Internal attributes, Testing: - // ========================================================================== - - rustc_attr!(TEST, rustc_outlives, Normal, template!(Word)), - rustc_attr!(TEST, rustc_variance, Normal, template!(Word)), - rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ...")), - rustc_attr!(TEST, rustc_regions, Normal, template!(Word)), - rustc_attr!( - TEST, rustc_error, Whitelisted, - template!(Word, List: "delay_span_bug_from_inside_query") - ), - rustc_attr!(TEST, rustc_dump_user_substs, Whitelisted, template!(Word)), - rustc_attr!(TEST, rustc_if_this_changed, Whitelisted, template!(Word, List: "DepNode")), - rustc_attr!(TEST, rustc_then_this_would_need, Whitelisted, template!(List: "DepNode")), - rustc_attr!( - TEST, rustc_dirty, Whitelisted, - template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#), - ), - rustc_attr!( - TEST, rustc_clean, Whitelisted, - template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#), - ), - rustc_attr!( - TEST, rustc_partition_reused, Whitelisted, - template!(List: r#"cfg = "...", module = "...""#), - ), - rustc_attr!( - TEST, rustc_partition_codegened, Whitelisted, - template!(List: r#"cfg = "...", module = "...""#), - ), - rustc_attr!( - TEST, rustc_expected_cgu_reuse, Whitelisted, - template!(List: r#"cfg = "...", module = "...", kind = "...""#), - ), - rustc_attr!(TEST, rustc_synthetic, Whitelisted, template!(Word)), - rustc_attr!(TEST, rustc_symbol_name, Whitelisted, template!(Word)), - rustc_attr!(TEST, rustc_def_path, Whitelisted, template!(Word)), - rustc_attr!(TEST, rustc_mir, Whitelisted, template!(List: "arg1, arg2, ...")), - rustc_attr!(TEST, rustc_dump_program_clauses, Whitelisted, template!(Word)), - rustc_attr!(TEST, rustc_dump_env_program_clauses, Whitelisted, template!(Word)), - rustc_attr!(TEST, rustc_object_lifetime_default, Whitelisted, template!(Word)), - rustc_attr!(TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/)), - gated!( - omit_gdb_pretty_printer_section, Whitelisted, template!(Word), - "the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite", - ), -]; - -pub fn deprecated_attributes() -> Vec<&'static BuiltinAttribute> { - BUILTIN_ATTRIBUTES.iter().filter(|(.., gate)| gate.is_deprecated()).collect() -} - -pub fn is_builtin_attr_name(name: Symbol) -> bool { - BUILTIN_ATTRIBUTE_MAP.get(&name).is_some() -} - -lazy_static! { - pub static ref BUILTIN_ATTRIBUTE_MAP: FxHashMap = { - let mut map = FxHashMap::default(); - for attr in BUILTIN_ATTRIBUTES.iter() { - if map.insert(attr.0, attr).is_some() { - panic!("duplicate builtin attribute `{}`", attr.0); - } - } - map - }; -} diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index e89c1f910d3..b5dc7d4db2b 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -1,6 +1,6 @@ use rustc_feature::{ACCEPTED_FEATURES, ACTIVE_FEATURES, Features, Feature, State as FeatureState}; use rustc_feature::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; -use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP}; +use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP}; use crate::ast::{self, AssocTyConstraint, AssocTyConstraintKind, NodeId}; use crate::ast::{GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData}; diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 74036bdcfb7..9db2007ea9c 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -99,12 +99,6 @@ pub mod feature_gate { GateIssue, UnstableFeatures, EXPLAIN_STMT_ATTR_SYNTAX, EXPLAIN_UNSIZED_TUPLE_COERCION, }; - mod builtin_attrs; - pub use builtin_attrs::{ - AttributeGate, AttributeTemplate, AttributeType, find_gated_cfg, GatedCfg, - BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP, - deprecated_attributes, is_builtin_attr_name, - }; } pub mod mut_visit; pub mod ptr; diff --git a/src/libsyntax_ext/util.rs b/src/libsyntax_ext/util.rs index 893fd402e83..f7bd9a05604 100644 --- a/src/libsyntax_ext/util.rs +++ b/src/libsyntax_ext/util.rs @@ -1,7 +1,7 @@ use rustc_parse::validate_attr; +use rustc_feature::AttributeTemplate; use syntax_pos::Symbol; use syntax::ast::MetaItem; -use syntax::feature_gate::AttributeTemplate; use syntax_expand::base::ExtCtxt; pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, name: Symbol) { -- cgit 1.4.1-3-g733a5 From db89679ebce6ed3b9bcb3f5cea430084b40a3a1f Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 02:40:28 +0100 Subject: inline two explanation constants --- src/librustc_parse/config.rs | 9 ++------- src/librustc_typeck/check/coercion.rs | 12 +++++++----- src/libsyntax/feature_gate/check.rs | 6 ------ src/libsyntax/lib.rs | 1 - 4 files changed, 9 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/librustc_parse/config.rs b/src/librustc_parse/config.rs index 9c309f60515..dde320aed21 100644 --- a/src/librustc_parse/config.rs +++ b/src/librustc_parse/config.rs @@ -11,12 +11,7 @@ use crate::validate_attr; use rustc_feature::Features; use syntax::attr::HasAttrs; -use syntax::feature_gate::{ - feature_err, - EXPLAIN_STMT_ATTR_SYNTAX, - get_features, - GateIssue, -}; +use syntax::feature_gate::{feature_err, get_features, GateIssue}; use syntax::attr; use syntax::ast; use syntax::edition::Edition; @@ -218,7 +213,7 @@ impl<'a> StripUnconfigured<'a> { sym::stmt_expr_attributes, attr.span, GateIssue::Language, - EXPLAIN_STMT_ATTR_SYNTAX); + "attributes on expressions are experimental"); if attr.is_doc_comment() { err.help("`///` is for documentation comments. For a plain comment, use `//`."); diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 871acb2726a..593f8e74ba9 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -644,11 +644,13 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } if has_unsized_tuple_coercion && !self.tcx.features().unsized_tuple_coercion { - feature_gate::emit_feature_err(&self.tcx.sess.parse_sess, - sym::unsized_tuple_coercion, - self.cause.span, - feature_gate::GateIssue::Language, - feature_gate::EXPLAIN_UNSIZED_TUPLE_COERCION); + feature_gate::emit_feature_err( + &self.tcx.sess.parse_sess, + sym::unsized_tuple_coercion, + self.cause.span, + feature_gate::GateIssue::Language, + "unsized tuple coercion is not stable enough for use and is subject to change", + ); } Ok(coercion) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index b5dc7d4db2b..c53f5f41e32 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -150,12 +150,6 @@ fn leveled_feature_err<'a, S: Into>( const EXPLAIN_BOX_SYNTAX: &str = "box expression syntax is experimental; you can call `Box::new` instead"; -pub const EXPLAIN_STMT_ATTR_SYNTAX: &str = - "attributes on expressions are experimental"; - -pub const EXPLAIN_UNSIZED_TUPLE_COERCION: &str = - "unsized tuple coercion is not stable enough for use and is subject to change"; - struct PostExpansionVisitor<'a> { parse_sess: &'a ParseSess, features: &'a Features, diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 9db2007ea9c..fda95374f64 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -97,7 +97,6 @@ pub mod feature_gate { pub use check::{ check_crate, check_attribute, get_features, feature_err, emit_feature_err, GateIssue, UnstableFeatures, - EXPLAIN_STMT_ATTR_SYNTAX, EXPLAIN_UNSIZED_TUPLE_COERCION, }; } pub mod mut_visit; -- cgit 1.4.1-3-g733a5 From b45f21d38e7e127d257c6299b9da00fdc57476b9 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 02:50:47 +0100 Subject: move UnstableFeatures -> rustc_feature --- src/librustc/session/config.rs | 6 ++-- src/librustc_codegen_llvm/lib.rs | 1 + src/librustc_codegen_llvm/llvm_util.rs | 2 +- src/librustc_driver/lib.rs | 6 ++-- src/librustc_feature/lib.rs | 34 ++++++++++++++++++++ src/librustdoc/core.rs | 2 +- src/librustdoc/externalfiles.rs | 2 +- src/librustdoc/html/render.rs | 2 +- src/librustdoc/markdown.rs | 2 +- src/librustdoc/passes/collect_intra_doc_links.rs | 2 +- src/librustdoc/test.rs | 2 +- src/libsyntax/feature_gate/check.rs | 40 ++---------------------- src/libsyntax/lib.rs | 2 +- src/libsyntax/sess.rs | 4 +-- 14 files changed, 52 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 6733250e1e8..fbfae721bbe 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -7,6 +7,7 @@ use crate::session::{early_error, early_warn, Session}; use crate::session::search_paths::SearchPath; use rustc_data_structures::fx::FxHashSet; +use rustc_feature::UnstableFeatures; use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel}; use rustc_target::spec::{Target, TargetTriple}; @@ -16,7 +17,6 @@ use syntax::ast; use syntax::source_map::{FileName, FilePathMapping}; use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION}; use syntax::symbol::{sym, Symbol}; -use syntax::feature_gate::UnstableFeatures; use errors::emitter::HumanReadableErrorType; use errors::{ColorConfig, FatalError, Handler}; @@ -2701,7 +2701,7 @@ pub fn parse_crate_types_from_list(list_list: Vec) -> Result), } +#[derive(Clone, Copy, Hash)] +pub enum UnstableFeatures { + /// Hard errors for unstable features are active, as on beta/stable channels. + Disallow, + /// Allow features to be activated, as on nightly. + Allow, + /// Errors are bypassed for bootstrapping. This is required any time + /// during the build that feature-related lints are set to warn or above + /// because the build turns on warnings-as-errors and uses lots of unstable + /// features. As a result, this is always required for building Rust itself. + Cheat +} + +impl UnstableFeatures { + pub fn from_environment() -> UnstableFeatures { + // `true` if this is a feature-staged build, i.e., on the beta or stable channel. + let disable_unstable_features = option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some(); + // `true` if we should enable unstable features for bootstrapping. + let bootstrap = std::env::var("RUSTC_BOOTSTRAP").is_ok(); + match (disable_unstable_features, bootstrap) { + (_, true) => UnstableFeatures::Cheat, + (true, _) => UnstableFeatures::Disallow, + (false, _) => UnstableFeatures::Allow + } + } + + pub fn is_nightly_build(&self) -> bool { + match *self { + UnstableFeatures::Allow | UnstableFeatures::Cheat => true, + UnstableFeatures::Disallow => false, + } + } +} + pub use accepted::ACCEPTED_FEATURES; pub use active::{ACTIVE_FEATURES, Features, INCOMPLETE_FEATURES}; pub use removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 612f3c69871..9e03896d980 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -12,12 +12,12 @@ use rustc::session::DiagnosticOutput; use rustc::util::nodemap::{FxHashMap, FxHashSet}; use rustc_interface::interface; use rustc_driver::abort_on_err; +use rustc_feature::UnstableFeatures; use rustc_resolve as resolve; use syntax::ast::CRATE_NODE_ID; use syntax::source_map; use syntax::attr; -use syntax::feature_gate::UnstableFeatures; use errors::json::JsonEmitter; use syntax::symbol::sym; use syntax_pos::DUMMY_SP; diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index 56f1191feed..7945850ef08 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -2,7 +2,7 @@ use std::fs; use std::path::Path; use std::str; use errors; -use crate::syntax::feature_gate::UnstableFeatures; +use rustc_feature::UnstableFeatures; use crate::syntax::edition::Edition; use crate::html::markdown::{IdMap, ErrorCodes, Markdown, Playground}; diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ba94cb82c00..b5c1a77a387 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -45,7 +45,6 @@ use errors; use serialize::json::{ToJson, Json, as_json}; use syntax::ast; use syntax::edition::Edition; -use syntax::feature_gate::UnstableFeatures; use syntax::print::pprust; use syntax::source_map::FileName; use syntax::symbol::{Symbol, sym}; @@ -56,6 +55,7 @@ use rustc::middle::stability; use rustc::hir; use rustc::util::nodemap::{FxHashMap, FxHashSet}; use rustc_data_structures::flock; +use rustc_feature::UnstableFeatures; use crate::clean::{self, AttributesExt, Deprecation, GetDefId, SelfTy, Mutability}; use crate::config::RenderOptions; diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 8431271e62d..7dc3df23a6d 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -6,7 +6,7 @@ use errors; use testing; use syntax::edition::Edition; use syntax::source_map::DUMMY_SP; -use syntax::feature_gate::UnstableFeatures; +use rustc_feature::UnstableFeatures; use crate::externalfiles::{LoadStringError, load_string}; use crate::config::{Options, RenderOptions}; diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index d8f2dbca835..3c021ae7465 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -5,10 +5,10 @@ use rustc::hir; use rustc::lint as lint; use rustc::ty; use rustc_resolve::ParentScope; +use rustc_feature::UnstableFeatures; use syntax; use syntax::ast::{self, Ident}; use syntax_expand::base::SyntaxExtensionKind; -use syntax::feature_gate::UnstableFeatures; use syntax::symbol::Symbol; use syntax_pos::DUMMY_SP; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 22f209b8bad..cf5fb06fa56 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -1,4 +1,5 @@ use rustc_data_structures::sync::Lrc; +use rustc_feature::UnstableFeatures; use rustc_interface::interface; use rustc_target::spec::TargetTriple; use rustc::hir; @@ -9,7 +10,6 @@ use syntax::ast; use syntax::with_globals; use syntax::source_map::SourceMap; use syntax::edition::Edition; -use syntax::feature_gate::UnstableFeatures; use std::env; use std::io::{self, Write}; use std::panic; diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index c53f5f41e32..141b324baa8 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -1,6 +1,6 @@ -use rustc_feature::{ACCEPTED_FEATURES, ACTIVE_FEATURES, Features, Feature, State as FeatureState}; -use rustc_feature::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; +use rustc_feature::{ACCEPTED_FEATURES, ACTIVE_FEATURES, REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP}; +use rustc_feature::{Features, Feature, State as FeatureState, UnstableFeatures}; use crate::ast::{self, AssocTyConstraint, AssocTyConstraintKind, NodeId}; use crate::ast::{GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData}; @@ -18,8 +18,6 @@ use log::debug; use rustc_error_codes::*; - -use std::env; use std::num::NonZeroU32; macro_rules! gate_feature_fn { @@ -880,40 +878,6 @@ pub fn check_crate(krate: &ast::Crate, visit::walk_crate(&mut visitor, krate); } -#[derive(Clone, Copy, Hash)] -pub enum UnstableFeatures { - /// Hard errors for unstable features are active, as on beta/stable channels. - Disallow, - /// Allow features to be activated, as on nightly. - Allow, - /// Errors are bypassed for bootstrapping. This is required any time - /// during the build that feature-related lints are set to warn or above - /// because the build turns on warnings-as-errors and uses lots of unstable - /// features. As a result, this is always required for building Rust itself. - Cheat -} - -impl UnstableFeatures { - pub fn from_environment() -> UnstableFeatures { - // `true` if this is a feature-staged build, i.e., on the beta or stable channel. - let disable_unstable_features = option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some(); - // `true` if we should enable unstable features for bootstrapping. - let bootstrap = env::var("RUSTC_BOOTSTRAP").is_ok(); - match (disable_unstable_features, bootstrap) { - (_, true) => UnstableFeatures::Cheat, - (true, _) => UnstableFeatures::Disallow, - (false, _) => UnstableFeatures::Allow - } - } - - pub fn is_nightly_build(&self) -> bool { - match *self { - UnstableFeatures::Allow | UnstableFeatures::Cheat => true, - UnstableFeatures::Disallow => false, - } - } -} - fn maybe_stage_features(span_handler: &Handler, krate: &ast::Crate, unstable: UnstableFeatures) { if !unstable.is_nightly_build() { for attr in krate.attrs.iter().filter(|attr| attr.check_name(sym::feature)) { diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index fda95374f64..c2d887c9267 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -96,7 +96,7 @@ pub mod feature_gate { mod check; pub use check::{ check_crate, check_attribute, get_features, feature_err, emit_feature_err, - GateIssue, UnstableFeatures, + GateIssue, }; } pub mod mut_visit; diff --git a/src/libsyntax/sess.rs b/src/libsyntax/sess.rs index 740e9dfe459..aa9217c1b69 100644 --- a/src/libsyntax/sess.rs +++ b/src/libsyntax/sess.rs @@ -3,15 +3,15 @@ use crate::ast::{CrateConfig, NodeId}; use crate::early_buffered_lints::{BufferedEarlyLint, BufferedEarlyLintId}; -use crate::source_map::{SourceMap, FilePathMapping}; -use crate::feature_gate::UnstableFeatures; use errors::{Applicability, emitter::SilentEmitter, Handler, ColorConfig, DiagnosticBuilder}; use rustc_data_structures::fx::{FxHashSet, FxHashMap}; use rustc_data_structures::sync::{Lrc, Lock, Once}; +use rustc_feature::UnstableFeatures; use syntax_pos::{Symbol, Span, MultiSpan}; use syntax_pos::edition::Edition; use syntax_pos::hygiene::ExpnId; +use syntax_pos::source_map::{SourceMap, FilePathMapping}; use std::path::PathBuf; use std::str; -- cgit 1.4.1-3-g733a5 From 96261814948099370141413446c3b34a1354548a Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 03:30:49 +0100 Subject: check.rs: inline a constant --- src/libsyntax/feature_gate/check.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 141b324baa8..ea0eff1eed9 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -145,9 +145,6 @@ fn leveled_feature_err<'a, S: Into>( } -const EXPLAIN_BOX_SYNTAX: &str = - "box expression syntax is experimental; you can call `Box::new` instead"; - struct PostExpansionVisitor<'a> { parse_sess: &'a ParseSess, features: &'a Features, @@ -507,7 +504,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { fn visit_expr(&mut self, e: &'a ast::Expr) { match e.kind { ast::ExprKind::Box(_) => { - gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX); + gate_feature_post!( + &self, box_syntax, e.span, + "box expression syntax is experimental; you can call `Box::new` instead" + ); } ast::ExprKind::Type(..) => { // To avoid noise about type ascription in common syntax errors, only emit if it -- cgit 1.4.1-3-g733a5 From d353a4c2672b6688899a833b022d9f75a7090b60 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 Nov 2019 19:38:59 -0800 Subject: Make dec2flt_table compatible with rustfmt --- src/etc/dec2flt_table.py | 15 +- src/libcore/num/dec2flt/table.rs | 2456 +++++++++++++++++++------------------- 2 files changed, 1241 insertions(+), 1230 deletions(-) mode change 100644 => 100755 src/etc/dec2flt_table.py (limited to 'src') diff --git a/src/etc/dec2flt_table.py b/src/etc/dec2flt_table.py old mode 100644 new mode 100755 index 2ffaf13dc8f..85395d2ecdf --- a/src/etc/dec2flt_table.py +++ b/src/etc/dec2flt_table.py @@ -111,14 +111,18 @@ def print_proper_powers(): print("pub const MIN_E: i16 = {};".format(MIN_E)) print("pub const MAX_E: i16 = {};".format(MAX_E)) print() + print("#[rustfmt::skip]") typ = "([u64; {0}], [i16; {0}])".format(len(powers)) - print("pub const POWERS: ", typ, " = ([", sep='') + print("pub const POWERS: ", typ, " = (", sep='') + print(" [") for z in powers: - print(" 0x{:x},".format(z.sig)) - print("], [") + print(" 0x{:x},".format(z.sig)) + print(" ],") + print(" [") for z in powers: - print(" {},".format(z.exp)) - print("]);") + print(" {},".format(z.exp)) + print(" ],") + print(");") def print_short_powers(num_bits, significand_size): @@ -127,6 +131,7 @@ def print_short_powers(num_bits, significand_size): max_e = int(ceil(log(max_sig, 5))) e_range = range(max_e) typ = "[f{}; {}]".format(num_bits, len(e_range)) + print("#[rustfmt::skip]") print("pub const F", num_bits, "_SHORT_POWERS: ", typ, " = [", sep='') for e in e_range: print(" 1e{},".format(e)) diff --git a/src/libcore/num/dec2flt/table.rs b/src/libcore/num/dec2flt/table.rs index 345ac830aaa..1bd94ffa04e 100644 --- a/src/libcore/num/dec2flt/table.rs +++ b/src/libcore/num/dec2flt/table.rs @@ -4,1232 +4,1237 @@ pub const MIN_E: i16 = -305; pub const MAX_E: i16 = 305; -pub const POWERS: ([u64; 611], [i16; 611]) = ([ - 0xe0b62e2929aba83c, - 0x8c71dcd9ba0b4926, - 0xaf8e5410288e1b6f, - 0xdb71e91432b1a24b, - 0x892731ac9faf056f, - 0xab70fe17c79ac6ca, - 0xd64d3d9db981787d, - 0x85f0468293f0eb4e, - 0xa76c582338ed2622, - 0xd1476e2c07286faa, - 0x82cca4db847945ca, - 0xa37fce126597973d, - 0xcc5fc196fefd7d0c, - 0xff77b1fcbebcdc4f, - 0x9faacf3df73609b1, - 0xc795830d75038c1e, - 0xf97ae3d0d2446f25, - 0x9becce62836ac577, - 0xc2e801fb244576d5, - 0xf3a20279ed56d48a, - 0x9845418c345644d7, - 0xbe5691ef416bd60c, - 0xedec366b11c6cb8f, - 0x94b3a202eb1c3f39, - 0xb9e08a83a5e34f08, - 0xe858ad248f5c22ca, - 0x91376c36d99995be, - 0xb58547448ffffb2e, - 0xe2e69915b3fff9f9, - 0x8dd01fad907ffc3c, - 0xb1442798f49ffb4b, - 0xdd95317f31c7fa1d, - 0x8a7d3eef7f1cfc52, - 0xad1c8eab5ee43b67, - 0xd863b256369d4a41, - 0x873e4f75e2224e68, - 0xa90de3535aaae202, - 0xd3515c2831559a83, - 0x8412d9991ed58092, - 0xa5178fff668ae0b6, - 0xce5d73ff402d98e4, - 0x80fa687f881c7f8e, - 0xa139029f6a239f72, - 0xc987434744ac874f, - 0xfbe9141915d7a922, - 0x9d71ac8fada6c9b5, - 0xc4ce17b399107c23, - 0xf6019da07f549b2b, - 0x99c102844f94e0fb, - 0xc0314325637a193a, - 0xf03d93eebc589f88, - 0x96267c7535b763b5, - 0xbbb01b9283253ca3, - 0xea9c227723ee8bcb, - 0x92a1958a7675175f, - 0xb749faed14125d37, - 0xe51c79a85916f485, - 0x8f31cc0937ae58d3, - 0xb2fe3f0b8599ef08, - 0xdfbdcece67006ac9, - 0x8bd6a141006042be, - 0xaecc49914078536d, - 0xda7f5bf590966849, - 0x888f99797a5e012d, - 0xaab37fd7d8f58179, - 0xd5605fcdcf32e1d7, - 0x855c3be0a17fcd26, - 0xa6b34ad8c9dfc070, - 0xd0601d8efc57b08c, - 0x823c12795db6ce57, - 0xa2cb1717b52481ed, - 0xcb7ddcdda26da269, - 0xfe5d54150b090b03, - 0x9efa548d26e5a6e2, - 0xc6b8e9b0709f109a, - 0xf867241c8cc6d4c1, - 0x9b407691d7fc44f8, - 0xc21094364dfb5637, - 0xf294b943e17a2bc4, - 0x979cf3ca6cec5b5b, - 0xbd8430bd08277231, - 0xece53cec4a314ebe, - 0x940f4613ae5ed137, - 0xb913179899f68584, - 0xe757dd7ec07426e5, - 0x9096ea6f3848984f, - 0xb4bca50b065abe63, - 0xe1ebce4dc7f16dfc, - 0x8d3360f09cf6e4bd, - 0xb080392cc4349ded, - 0xdca04777f541c568, - 0x89e42caaf9491b61, - 0xac5d37d5b79b6239, - 0xd77485cb25823ac7, - 0x86a8d39ef77164bd, - 0xa8530886b54dbdec, - 0xd267caa862a12d67, - 0x8380dea93da4bc60, - 0xa46116538d0deb78, - 0xcd795be870516656, - 0x806bd9714632dff6, - 0xa086cfcd97bf97f4, - 0xc8a883c0fdaf7df0, - 0xfad2a4b13d1b5d6c, - 0x9cc3a6eec6311a64, - 0xc3f490aa77bd60fd, - 0xf4f1b4d515acb93c, - 0x991711052d8bf3c5, - 0xbf5cd54678eef0b7, - 0xef340a98172aace5, - 0x9580869f0e7aac0f, - 0xbae0a846d2195713, - 0xe998d258869facd7, - 0x91ff83775423cc06, - 0xb67f6455292cbf08, - 0xe41f3d6a7377eeca, - 0x8e938662882af53e, - 0xb23867fb2a35b28e, - 0xdec681f9f4c31f31, - 0x8b3c113c38f9f37f, - 0xae0b158b4738705f, - 0xd98ddaee19068c76, - 0x87f8a8d4cfa417ca, - 0xa9f6d30a038d1dbc, - 0xd47487cc8470652b, - 0x84c8d4dfd2c63f3b, - 0xa5fb0a17c777cf0a, - 0xcf79cc9db955c2cc, - 0x81ac1fe293d599c0, - 0xa21727db38cb0030, - 0xca9cf1d206fdc03c, - 0xfd442e4688bd304b, - 0x9e4a9cec15763e2f, - 0xc5dd44271ad3cdba, - 0xf7549530e188c129, - 0x9a94dd3e8cf578ba, - 0xc13a148e3032d6e8, - 0xf18899b1bc3f8ca2, - 0x96f5600f15a7b7e5, - 0xbcb2b812db11a5de, - 0xebdf661791d60f56, - 0x936b9fcebb25c996, - 0xb84687c269ef3bfb, - 0xe65829b3046b0afa, - 0x8ff71a0fe2c2e6dc, - 0xb3f4e093db73a093, - 0xe0f218b8d25088b8, - 0x8c974f7383725573, - 0xafbd2350644eead0, - 0xdbac6c247d62a584, - 0x894bc396ce5da772, - 0xab9eb47c81f5114f, - 0xd686619ba27255a3, - 0x8613fd0145877586, - 0xa798fc4196e952e7, - 0xd17f3b51fca3a7a1, - 0x82ef85133de648c5, - 0xa3ab66580d5fdaf6, - 0xcc963fee10b7d1b3, - 0xffbbcfe994e5c620, - 0x9fd561f1fd0f9bd4, - 0xc7caba6e7c5382c9, - 0xf9bd690a1b68637b, - 0x9c1661a651213e2d, - 0xc31bfa0fe5698db8, - 0xf3e2f893dec3f126, - 0x986ddb5c6b3a76b8, - 0xbe89523386091466, - 0xee2ba6c0678b597f, - 0x94db483840b717f0, - 0xba121a4650e4ddec, - 0xe896a0d7e51e1566, - 0x915e2486ef32cd60, - 0xb5b5ada8aaff80b8, - 0xe3231912d5bf60e6, - 0x8df5efabc5979c90, - 0xb1736b96b6fd83b4, - 0xddd0467c64bce4a1, - 0x8aa22c0dbef60ee4, - 0xad4ab7112eb3929e, - 0xd89d64d57a607745, - 0x87625f056c7c4a8b, - 0xa93af6c6c79b5d2e, - 0xd389b47879823479, - 0x843610cb4bf160cc, - 0xa54394fe1eedb8ff, - 0xce947a3da6a9273e, - 0x811ccc668829b887, - 0xa163ff802a3426a9, - 0xc9bcff6034c13053, - 0xfc2c3f3841f17c68, - 0x9d9ba7832936edc1, - 0xc5029163f384a931, - 0xf64335bcf065d37d, - 0x99ea0196163fa42e, - 0xc06481fb9bcf8d3a, - 0xf07da27a82c37088, - 0x964e858c91ba2655, - 0xbbe226efb628afeb, - 0xeadab0aba3b2dbe5, - 0x92c8ae6b464fc96f, - 0xb77ada0617e3bbcb, - 0xe55990879ddcaabe, - 0x8f57fa54c2a9eab7, - 0xb32df8e9f3546564, - 0xdff9772470297ebd, - 0x8bfbea76c619ef36, - 0xaefae51477a06b04, - 0xdab99e59958885c5, - 0x88b402f7fd75539b, - 0xaae103b5fcd2a882, - 0xd59944a37c0752a2, - 0x857fcae62d8493a5, - 0xa6dfbd9fb8e5b88f, - 0xd097ad07a71f26b2, - 0x825ecc24c8737830, - 0xa2f67f2dfa90563b, - 0xcbb41ef979346bca, - 0xfea126b7d78186bd, - 0x9f24b832e6b0f436, - 0xc6ede63fa05d3144, - 0xf8a95fcf88747d94, - 0x9b69dbe1b548ce7d, - 0xc24452da229b021c, - 0xf2d56790ab41c2a3, - 0x97c560ba6b0919a6, - 0xbdb6b8e905cb600f, - 0xed246723473e3813, - 0x9436c0760c86e30c, - 0xb94470938fa89bcf, - 0xe7958cb87392c2c3, - 0x90bd77f3483bb9ba, - 0xb4ecd5f01a4aa828, - 0xe2280b6c20dd5232, - 0x8d590723948a535f, - 0xb0af48ec79ace837, - 0xdcdb1b2798182245, - 0x8a08f0f8bf0f156b, - 0xac8b2d36eed2dac6, - 0xd7adf884aa879177, - 0x86ccbb52ea94baeb, - 0xa87fea27a539e9a5, - 0xd29fe4b18e88640f, - 0x83a3eeeef9153e89, - 0xa48ceaaab75a8e2b, - 0xcdb02555653131b6, - 0x808e17555f3ebf12, - 0xa0b19d2ab70e6ed6, - 0xc8de047564d20a8c, - 0xfb158592be068d2f, - 0x9ced737bb6c4183d, - 0xc428d05aa4751e4d, - 0xf53304714d9265e0, - 0x993fe2c6d07b7fac, - 0xbf8fdb78849a5f97, - 0xef73d256a5c0f77d, - 0x95a8637627989aae, - 0xbb127c53b17ec159, - 0xe9d71b689dde71b0, - 0x9226712162ab070e, - 0xb6b00d69bb55c8d1, - 0xe45c10c42a2b3b06, - 0x8eb98a7a9a5b04e3, - 0xb267ed1940f1c61c, - 0xdf01e85f912e37a3, - 0x8b61313bbabce2c6, - 0xae397d8aa96c1b78, - 0xd9c7dced53c72256, - 0x881cea14545c7575, - 0xaa242499697392d3, - 0xd4ad2dbfc3d07788, - 0x84ec3c97da624ab5, - 0xa6274bbdd0fadd62, - 0xcfb11ead453994ba, - 0x81ceb32c4b43fcf5, - 0xa2425ff75e14fc32, - 0xcad2f7f5359a3b3e, - 0xfd87b5f28300ca0e, - 0x9e74d1b791e07e48, - 0xc612062576589ddb, - 0xf79687aed3eec551, - 0x9abe14cd44753b53, - 0xc16d9a0095928a27, - 0xf1c90080baf72cb1, - 0x971da05074da7bef, - 0xbce5086492111aeb, - 0xec1e4a7db69561a5, - 0x9392ee8e921d5d07, - 0xb877aa3236a4b449, - 0xe69594bec44de15b, - 0x901d7cf73ab0acd9, - 0xb424dc35095cd80f, - 0xe12e13424bb40e13, - 0x8cbccc096f5088cc, - 0xafebff0bcb24aaff, - 0xdbe6fecebdedd5bf, - 0x89705f4136b4a597, - 0xabcc77118461cefd, - 0xd6bf94d5e57a42bc, - 0x8637bd05af6c69b6, - 0xa7c5ac471b478423, - 0xd1b71758e219652c, - 0x83126e978d4fdf3b, - 0xa3d70a3d70a3d70a, - 0xcccccccccccccccd, - 0x8000000000000000, - 0xa000000000000000, - 0xc800000000000000, - 0xfa00000000000000, - 0x9c40000000000000, - 0xc350000000000000, - 0xf424000000000000, - 0x9896800000000000, - 0xbebc200000000000, - 0xee6b280000000000, - 0x9502f90000000000, - 0xba43b74000000000, - 0xe8d4a51000000000, - 0x9184e72a00000000, - 0xb5e620f480000000, - 0xe35fa931a0000000, - 0x8e1bc9bf04000000, - 0xb1a2bc2ec5000000, - 0xde0b6b3a76400000, - 0x8ac7230489e80000, - 0xad78ebc5ac620000, - 0xd8d726b7177a8000, - 0x878678326eac9000, - 0xa968163f0a57b400, - 0xd3c21bcecceda100, - 0x84595161401484a0, - 0xa56fa5b99019a5c8, - 0xcecb8f27f4200f3a, - 0x813f3978f8940984, - 0xa18f07d736b90be5, - 0xc9f2c9cd04674edf, - 0xfc6f7c4045812296, - 0x9dc5ada82b70b59e, - 0xc5371912364ce305, - 0xf684df56c3e01bc7, - 0x9a130b963a6c115c, - 0xc097ce7bc90715b3, - 0xf0bdc21abb48db20, - 0x96769950b50d88f4, - 0xbc143fa4e250eb31, - 0xeb194f8e1ae525fd, - 0x92efd1b8d0cf37be, - 0xb7abc627050305ae, - 0xe596b7b0c643c719, - 0x8f7e32ce7bea5c70, - 0xb35dbf821ae4f38c, - 0xe0352f62a19e306f, - 0x8c213d9da502de45, - 0xaf298d050e4395d7, - 0xdaf3f04651d47b4c, - 0x88d8762bf324cd10, - 0xab0e93b6efee0054, - 0xd5d238a4abe98068, - 0x85a36366eb71f041, - 0xa70c3c40a64e6c52, - 0xd0cf4b50cfe20766, - 0x82818f1281ed44a0, - 0xa321f2d7226895c8, - 0xcbea6f8ceb02bb3a, - 0xfee50b7025c36a08, - 0x9f4f2726179a2245, - 0xc722f0ef9d80aad6, - 0xf8ebad2b84e0d58c, - 0x9b934c3b330c8577, - 0xc2781f49ffcfa6d5, - 0xf316271c7fc3908b, - 0x97edd871cfda3a57, - 0xbde94e8e43d0c8ec, - 0xed63a231d4c4fb27, - 0x945e455f24fb1cf9, - 0xb975d6b6ee39e437, - 0xe7d34c64a9c85d44, - 0x90e40fbeea1d3a4b, - 0xb51d13aea4a488dd, - 0xe264589a4dcdab15, - 0x8d7eb76070a08aed, - 0xb0de65388cc8ada8, - 0xdd15fe86affad912, - 0x8a2dbf142dfcc7ab, - 0xacb92ed9397bf996, - 0xd7e77a8f87daf7fc, - 0x86f0ac99b4e8dafd, - 0xa8acd7c0222311bd, - 0xd2d80db02aabd62c, - 0x83c7088e1aab65db, - 0xa4b8cab1a1563f52, - 0xcde6fd5e09abcf27, - 0x80b05e5ac60b6178, - 0xa0dc75f1778e39d6, - 0xc913936dd571c84c, - 0xfb5878494ace3a5f, - 0x9d174b2dcec0e47b, - 0xc45d1df942711d9a, - 0xf5746577930d6501, - 0x9968bf6abbe85f20, - 0xbfc2ef456ae276e9, - 0xefb3ab16c59b14a3, - 0x95d04aee3b80ece6, - 0xbb445da9ca61281f, - 0xea1575143cf97227, - 0x924d692ca61be758, - 0xb6e0c377cfa2e12e, - 0xe498f455c38b997a, - 0x8edf98b59a373fec, - 0xb2977ee300c50fe7, - 0xdf3d5e9bc0f653e1, - 0x8b865b215899f46d, - 0xae67f1e9aec07188, - 0xda01ee641a708dea, - 0x884134fe908658b2, - 0xaa51823e34a7eedf, - 0xd4e5e2cdc1d1ea96, - 0x850fadc09923329e, - 0xa6539930bf6bff46, - 0xcfe87f7cef46ff17, - 0x81f14fae158c5f6e, - 0xa26da3999aef774a, - 0xcb090c8001ab551c, - 0xfdcb4fa002162a63, - 0x9e9f11c4014dda7e, - 0xc646d63501a1511e, - 0xf7d88bc24209a565, - 0x9ae757596946075f, - 0xc1a12d2fc3978937, - 0xf209787bb47d6b85, - 0x9745eb4d50ce6333, - 0xbd176620a501fc00, - 0xec5d3fa8ce427b00, - 0x93ba47c980e98ce0, - 0xb8a8d9bbe123f018, - 0xe6d3102ad96cec1e, - 0x9043ea1ac7e41393, - 0xb454e4a179dd1877, - 0xe16a1dc9d8545e95, - 0x8ce2529e2734bb1d, - 0xb01ae745b101e9e4, - 0xdc21a1171d42645d, - 0x899504ae72497eba, - 0xabfa45da0edbde69, - 0xd6f8d7509292d603, - 0x865b86925b9bc5c2, - 0xa7f26836f282b733, - 0xd1ef0244af2364ff, - 0x8335616aed761f1f, - 0xa402b9c5a8d3a6e7, - 0xcd036837130890a1, - 0x802221226be55a65, - 0xa02aa96b06deb0fe, - 0xc83553c5c8965d3d, - 0xfa42a8b73abbf48d, - 0x9c69a97284b578d8, - 0xc38413cf25e2d70e, - 0xf46518c2ef5b8cd1, - 0x98bf2f79d5993803, - 0xbeeefb584aff8604, - 0xeeaaba2e5dbf6785, - 0x952ab45cfa97a0b3, - 0xba756174393d88e0, - 0xe912b9d1478ceb17, - 0x91abb422ccb812ef, - 0xb616a12b7fe617aa, - 0xe39c49765fdf9d95, - 0x8e41ade9fbebc27d, - 0xb1d219647ae6b31c, - 0xde469fbd99a05fe3, - 0x8aec23d680043bee, - 0xada72ccc20054aea, - 0xd910f7ff28069da4, - 0x87aa9aff79042287, - 0xa99541bf57452b28, - 0xd3fa922f2d1675f2, - 0x847c9b5d7c2e09b7, - 0xa59bc234db398c25, - 0xcf02b2c21207ef2f, - 0x8161afb94b44f57d, - 0xa1ba1ba79e1632dc, - 0xca28a291859bbf93, - 0xfcb2cb35e702af78, - 0x9defbf01b061adab, - 0xc56baec21c7a1916, - 0xf6c69a72a3989f5c, - 0x9a3c2087a63f6399, - 0xc0cb28a98fcf3c80, - 0xf0fdf2d3f3c30b9f, - 0x969eb7c47859e744, - 0xbc4665b596706115, - 0xeb57ff22fc0c795a, - 0x9316ff75dd87cbd8, - 0xb7dcbf5354e9bece, - 0xe5d3ef282a242e82, - 0x8fa475791a569d11, - 0xb38d92d760ec4455, - 0xe070f78d3927556b, - 0x8c469ab843b89563, - 0xaf58416654a6babb, - 0xdb2e51bfe9d0696a, - 0x88fcf317f22241e2, - 0xab3c2fddeeaad25b, - 0xd60b3bd56a5586f2, - 0x85c7056562757457, - 0xa738c6bebb12d16d, - 0xd106f86e69d785c8, - 0x82a45b450226b39d, - 0xa34d721642b06084, - 0xcc20ce9bd35c78a5, - 0xff290242c83396ce, - 0x9f79a169bd203e41, - 0xc75809c42c684dd1, - 0xf92e0c3537826146, - 0x9bbcc7a142b17ccc, - 0xc2abf989935ddbfe, - 0xf356f7ebf83552fe, - 0x98165af37b2153df, - 0xbe1bf1b059e9a8d6, - 0xeda2ee1c7064130c, - 0x9485d4d1c63e8be8, - 0xb9a74a0637ce2ee1, - 0xe8111c87c5c1ba9a, - 0x910ab1d4db9914a0, - 0xb54d5e4a127f59c8, - 0xe2a0b5dc971f303a, - 0x8da471a9de737e24, - 0xb10d8e1456105dad, - 0xdd50f1996b947519, - 0x8a5296ffe33cc930, - 0xace73cbfdc0bfb7b, - 0xd8210befd30efa5a, - 0x8714a775e3e95c78, - 0xa8d9d1535ce3b396, - 0xd31045a8341ca07c, - 0x83ea2b892091e44e, - 0xa4e4b66b68b65d61, - 0xce1de40642e3f4b9, - 0x80d2ae83e9ce78f4, - 0xa1075a24e4421731, - 0xc94930ae1d529cfd, - 0xfb9b7cd9a4a7443c, - 0x9d412e0806e88aa6, - 0xc491798a08a2ad4f, - 0xf5b5d7ec8acb58a3, - 0x9991a6f3d6bf1766, - 0xbff610b0cc6edd3f, - 0xeff394dcff8a948f, - 0x95f83d0a1fb69cd9, - 0xbb764c4ca7a44410, - 0xea53df5fd18d5514, - 0x92746b9be2f8552c, - 0xb7118682dbb66a77, - 0xe4d5e82392a40515, - 0x8f05b1163ba6832d, - 0xb2c71d5bca9023f8, - 0xdf78e4b2bd342cf7, - 0x8bab8eefb6409c1a, - 0xae9672aba3d0c321, - 0xda3c0f568cc4f3e9, - 0x8865899617fb1871, - 0xaa7eebfb9df9de8e, - 0xd51ea6fa85785631, - 0x8533285c936b35df, - 0xa67ff273b8460357, - 0xd01fef10a657842c, - 0x8213f56a67f6b29c, - 0xa298f2c501f45f43, - 0xcb3f2f7642717713, - 0xfe0efb53d30dd4d8, - 0x9ec95d1463e8a507, - 0xc67bb4597ce2ce49, - 0xf81aa16fdc1b81db, - 0x9b10a4e5e9913129, - 0xc1d4ce1f63f57d73, - 0xf24a01a73cf2dcd0, - 0x976e41088617ca02, - 0xbd49d14aa79dbc82, - 0xec9c459d51852ba3, - 0x93e1ab8252f33b46, - 0xb8da1662e7b00a17, - 0xe7109bfba19c0c9d, - 0x906a617d450187e2, - 0xb484f9dc9641e9db, - 0xe1a63853bbd26451, - 0x8d07e33455637eb3, - 0xb049dc016abc5e60, - 0xdc5c5301c56b75f7, - 0x89b9b3e11b6329bb, - 0xac2820d9623bf429, - 0xd732290fbacaf134, - 0x867f59a9d4bed6c0, - 0xa81f301449ee8c70, - 0xd226fc195c6a2f8c, - 0x83585d8fd9c25db8, - 0xa42e74f3d032f526, - 0xcd3a1230c43fb26f, - 0x80444b5e7aa7cf85, - 0xa0555e361951c367, - 0xc86ab5c39fa63441, - 0xfa856334878fc151, - 0x9c935e00d4b9d8d2, - 0xc3b8358109e84f07, - 0xf4a642e14c6262c9, - 0x98e7e9cccfbd7dbe, - 0xbf21e44003acdd2d, - 0xeeea5d5004981478, - 0x95527a5202df0ccb, - 0xbaa718e68396cffe, - 0xe950df20247c83fd, - 0x91d28b7416cdd27e, -], [ - -1077, - -1073, - -1070, - -1067, - -1063, - -1060, - -1057, - -1053, - -1050, - -1047, - -1043, - -1040, - -1037, - -1034, - -1030, - -1027, - -1024, - -1020, - -1017, - -1014, - -1010, - -1007, - -1004, - -1000, - -997, - -994, - -990, - -987, - -984, - -980, - -977, - -974, - -970, - -967, - -964, - -960, - -957, - -954, - -950, - -947, - -944, - -940, - -937, - -934, - -931, - -927, - -924, - -921, - -917, - -914, - -911, - -907, - -904, - -901, - -897, - -894, - -891, - -887, - -884, - -881, - -877, - -874, - -871, - -867, - -864, - -861, - -857, - -854, - -851, - -847, - -844, - -841, - -838, - -834, - -831, - -828, - -824, - -821, - -818, - -814, - -811, - -808, - -804, - -801, - -798, - -794, - -791, - -788, - -784, - -781, - -778, - -774, - -771, - -768, - -764, - -761, - -758, - -754, - -751, - -748, - -744, - -741, - -738, - -735, - -731, - -728, - -725, - -721, - -718, - -715, - -711, - -708, - -705, - -701, - -698, - -695, - -691, - -688, - -685, - -681, - -678, - -675, - -671, - -668, - -665, - -661, - -658, - -655, - -651, - -648, - -645, - -642, - -638, - -635, - -632, - -628, - -625, - -622, - -618, - -615, - -612, - -608, - -605, - -602, - -598, - -595, - -592, - -588, - -585, - -582, - -578, - -575, - -572, - -568, - -565, - -562, - -558, - -555, - -552, - -549, - -545, - -542, - -539, - -535, - -532, - -529, - -525, - -522, - -519, - -515, - -512, - -509, - -505, - -502, - -499, - -495, - -492, - -489, - -485, - -482, - -479, - -475, - -472, - -469, - -465, - -462, - -459, - -455, - -452, - -449, - -446, - -442, - -439, - -436, - -432, - -429, - -426, - -422, - -419, - -416, - -412, - -409, - -406, - -402, - -399, - -396, - -392, - -389, - -386, - -382, - -379, - -376, - -372, - -369, - -366, - -362, - -359, - -356, - -353, - -349, - -346, - -343, - -339, - -336, - -333, - -329, - -326, - -323, - -319, - -316, - -313, - -309, - -306, - -303, - -299, - -296, - -293, - -289, - -286, - -283, - -279, - -276, - -273, - -269, - -266, - -263, - -259, - -256, - -253, - -250, - -246, - -243, - -240, - -236, - -233, - -230, - -226, - -223, - -220, - -216, - -213, - -210, - -206, - -203, - -200, - -196, - -193, - -190, - -186, - -183, - -180, - -176, - -173, - -170, - -166, - -163, - -160, - -157, - -153, - -150, - -147, - -143, - -140, - -137, - -133, - -130, - -127, - -123, - -120, - -117, - -113, - -110, - -107, - -103, - -100, - -97, - -93, - -90, - -87, - -83, - -80, - -77, - -73, - -70, - -67, - -63, - -60, - -57, - -54, - -50, - -47, - -44, - -40, - -37, - -34, - -30, - -27, - -24, - -20, - -17, - -14, - -10, - -7, - -4, - 0, - 3, - 6, - 10, - 13, - 16, - 20, - 23, - 26, - 30, - 33, - 36, - 39, - 43, - 46, - 49, - 53, - 56, - 59, - 63, - 66, - 69, - 73, - 76, - 79, - 83, - 86, - 89, - 93, - 96, - 99, - 103, - 106, - 109, - 113, - 116, - 119, - 123, - 126, - 129, - 132, - 136, - 139, - 142, - 146, - 149, - 152, - 156, - 159, - 162, - 166, - 169, - 172, - 176, - 179, - 182, - 186, - 189, - 192, - 196, - 199, - 202, - 206, - 209, - 212, - 216, - 219, - 222, - 226, - 229, - 232, - 235, - 239, - 242, - 245, - 249, - 252, - 255, - 259, - 262, - 265, - 269, - 272, - 275, - 279, - 282, - 285, - 289, - 292, - 295, - 299, - 302, - 305, - 309, - 312, - 315, - 319, - 322, - 325, - 328, - 332, - 335, - 338, - 342, - 345, - 348, - 352, - 355, - 358, - 362, - 365, - 368, - 372, - 375, - 378, - 382, - 385, - 388, - 392, - 395, - 398, - 402, - 405, - 408, - 412, - 415, - 418, - 422, - 425, - 428, - 431, - 435, - 438, - 441, - 445, - 448, - 451, - 455, - 458, - 461, - 465, - 468, - 471, - 475, - 478, - 481, - 485, - 488, - 491, - 495, - 498, - 501, - 505, - 508, - 511, - 515, - 518, - 521, - 524, - 528, - 531, - 534, - 538, - 541, - 544, - 548, - 551, - 554, - 558, - 561, - 564, - 568, - 571, - 574, - 578, - 581, - 584, - 588, - 591, - 594, - 598, - 601, - 604, - 608, - 611, - 614, - 617, - 621, - 624, - 627, - 631, - 634, - 637, - 641, - 644, - 647, - 651, - 654, - 657, - 661, - 664, - 667, - 671, - 674, - 677, - 681, - 684, - 687, - 691, - 694, - 697, - 701, - 704, - 707, - 711, - 714, - 717, - 720, - 724, - 727, - 730, - 734, - 737, - 740, - 744, - 747, - 750, - 754, - 757, - 760, - 764, - 767, - 770, - 774, - 777, - 780, - 784, - 787, - 790, - 794, - 797, - 800, - 804, - 807, - 810, - 813, - 817, - 820, - 823, - 827, - 830, - 833, - 837, - 840, - 843, - 847, - 850, - 853, - 857, - 860, - 863, - 867, - 870, - 873, - 877, - 880, - 883, - 887, - 890, - 893, - 897, - 900, - 903, - 907, - 910, - 913, - 916, - 920, - 923, - 926, - 930, - 933, - 936, - 940, - 943, - 946, - 950, -]); +#[rustfmt::skip] +pub const POWERS: ([u64; 611], [i16; 611]) = ( + [ + 0xe0b62e2929aba83c, + 0x8c71dcd9ba0b4926, + 0xaf8e5410288e1b6f, + 0xdb71e91432b1a24b, + 0x892731ac9faf056f, + 0xab70fe17c79ac6ca, + 0xd64d3d9db981787d, + 0x85f0468293f0eb4e, + 0xa76c582338ed2622, + 0xd1476e2c07286faa, + 0x82cca4db847945ca, + 0xa37fce126597973d, + 0xcc5fc196fefd7d0c, + 0xff77b1fcbebcdc4f, + 0x9faacf3df73609b1, + 0xc795830d75038c1e, + 0xf97ae3d0d2446f25, + 0x9becce62836ac577, + 0xc2e801fb244576d5, + 0xf3a20279ed56d48a, + 0x9845418c345644d7, + 0xbe5691ef416bd60c, + 0xedec366b11c6cb8f, + 0x94b3a202eb1c3f39, + 0xb9e08a83a5e34f08, + 0xe858ad248f5c22ca, + 0x91376c36d99995be, + 0xb58547448ffffb2e, + 0xe2e69915b3fff9f9, + 0x8dd01fad907ffc3c, + 0xb1442798f49ffb4b, + 0xdd95317f31c7fa1d, + 0x8a7d3eef7f1cfc52, + 0xad1c8eab5ee43b67, + 0xd863b256369d4a41, + 0x873e4f75e2224e68, + 0xa90de3535aaae202, + 0xd3515c2831559a83, + 0x8412d9991ed58092, + 0xa5178fff668ae0b6, + 0xce5d73ff402d98e4, + 0x80fa687f881c7f8e, + 0xa139029f6a239f72, + 0xc987434744ac874f, + 0xfbe9141915d7a922, + 0x9d71ac8fada6c9b5, + 0xc4ce17b399107c23, + 0xf6019da07f549b2b, + 0x99c102844f94e0fb, + 0xc0314325637a193a, + 0xf03d93eebc589f88, + 0x96267c7535b763b5, + 0xbbb01b9283253ca3, + 0xea9c227723ee8bcb, + 0x92a1958a7675175f, + 0xb749faed14125d37, + 0xe51c79a85916f485, + 0x8f31cc0937ae58d3, + 0xb2fe3f0b8599ef08, + 0xdfbdcece67006ac9, + 0x8bd6a141006042be, + 0xaecc49914078536d, + 0xda7f5bf590966849, + 0x888f99797a5e012d, + 0xaab37fd7d8f58179, + 0xd5605fcdcf32e1d7, + 0x855c3be0a17fcd26, + 0xa6b34ad8c9dfc070, + 0xd0601d8efc57b08c, + 0x823c12795db6ce57, + 0xa2cb1717b52481ed, + 0xcb7ddcdda26da269, + 0xfe5d54150b090b03, + 0x9efa548d26e5a6e2, + 0xc6b8e9b0709f109a, + 0xf867241c8cc6d4c1, + 0x9b407691d7fc44f8, + 0xc21094364dfb5637, + 0xf294b943e17a2bc4, + 0x979cf3ca6cec5b5b, + 0xbd8430bd08277231, + 0xece53cec4a314ebe, + 0x940f4613ae5ed137, + 0xb913179899f68584, + 0xe757dd7ec07426e5, + 0x9096ea6f3848984f, + 0xb4bca50b065abe63, + 0xe1ebce4dc7f16dfc, + 0x8d3360f09cf6e4bd, + 0xb080392cc4349ded, + 0xdca04777f541c568, + 0x89e42caaf9491b61, + 0xac5d37d5b79b6239, + 0xd77485cb25823ac7, + 0x86a8d39ef77164bd, + 0xa8530886b54dbdec, + 0xd267caa862a12d67, + 0x8380dea93da4bc60, + 0xa46116538d0deb78, + 0xcd795be870516656, + 0x806bd9714632dff6, + 0xa086cfcd97bf97f4, + 0xc8a883c0fdaf7df0, + 0xfad2a4b13d1b5d6c, + 0x9cc3a6eec6311a64, + 0xc3f490aa77bd60fd, + 0xf4f1b4d515acb93c, + 0x991711052d8bf3c5, + 0xbf5cd54678eef0b7, + 0xef340a98172aace5, + 0x9580869f0e7aac0f, + 0xbae0a846d2195713, + 0xe998d258869facd7, + 0x91ff83775423cc06, + 0xb67f6455292cbf08, + 0xe41f3d6a7377eeca, + 0x8e938662882af53e, + 0xb23867fb2a35b28e, + 0xdec681f9f4c31f31, + 0x8b3c113c38f9f37f, + 0xae0b158b4738705f, + 0xd98ddaee19068c76, + 0x87f8a8d4cfa417ca, + 0xa9f6d30a038d1dbc, + 0xd47487cc8470652b, + 0x84c8d4dfd2c63f3b, + 0xa5fb0a17c777cf0a, + 0xcf79cc9db955c2cc, + 0x81ac1fe293d599c0, + 0xa21727db38cb0030, + 0xca9cf1d206fdc03c, + 0xfd442e4688bd304b, + 0x9e4a9cec15763e2f, + 0xc5dd44271ad3cdba, + 0xf7549530e188c129, + 0x9a94dd3e8cf578ba, + 0xc13a148e3032d6e8, + 0xf18899b1bc3f8ca2, + 0x96f5600f15a7b7e5, + 0xbcb2b812db11a5de, + 0xebdf661791d60f56, + 0x936b9fcebb25c996, + 0xb84687c269ef3bfb, + 0xe65829b3046b0afa, + 0x8ff71a0fe2c2e6dc, + 0xb3f4e093db73a093, + 0xe0f218b8d25088b8, + 0x8c974f7383725573, + 0xafbd2350644eead0, + 0xdbac6c247d62a584, + 0x894bc396ce5da772, + 0xab9eb47c81f5114f, + 0xd686619ba27255a3, + 0x8613fd0145877586, + 0xa798fc4196e952e7, + 0xd17f3b51fca3a7a1, + 0x82ef85133de648c5, + 0xa3ab66580d5fdaf6, + 0xcc963fee10b7d1b3, + 0xffbbcfe994e5c620, + 0x9fd561f1fd0f9bd4, + 0xc7caba6e7c5382c9, + 0xf9bd690a1b68637b, + 0x9c1661a651213e2d, + 0xc31bfa0fe5698db8, + 0xf3e2f893dec3f126, + 0x986ddb5c6b3a76b8, + 0xbe89523386091466, + 0xee2ba6c0678b597f, + 0x94db483840b717f0, + 0xba121a4650e4ddec, + 0xe896a0d7e51e1566, + 0x915e2486ef32cd60, + 0xb5b5ada8aaff80b8, + 0xe3231912d5bf60e6, + 0x8df5efabc5979c90, + 0xb1736b96b6fd83b4, + 0xddd0467c64bce4a1, + 0x8aa22c0dbef60ee4, + 0xad4ab7112eb3929e, + 0xd89d64d57a607745, + 0x87625f056c7c4a8b, + 0xa93af6c6c79b5d2e, + 0xd389b47879823479, + 0x843610cb4bf160cc, + 0xa54394fe1eedb8ff, + 0xce947a3da6a9273e, + 0x811ccc668829b887, + 0xa163ff802a3426a9, + 0xc9bcff6034c13053, + 0xfc2c3f3841f17c68, + 0x9d9ba7832936edc1, + 0xc5029163f384a931, + 0xf64335bcf065d37d, + 0x99ea0196163fa42e, + 0xc06481fb9bcf8d3a, + 0xf07da27a82c37088, + 0x964e858c91ba2655, + 0xbbe226efb628afeb, + 0xeadab0aba3b2dbe5, + 0x92c8ae6b464fc96f, + 0xb77ada0617e3bbcb, + 0xe55990879ddcaabe, + 0x8f57fa54c2a9eab7, + 0xb32df8e9f3546564, + 0xdff9772470297ebd, + 0x8bfbea76c619ef36, + 0xaefae51477a06b04, + 0xdab99e59958885c5, + 0x88b402f7fd75539b, + 0xaae103b5fcd2a882, + 0xd59944a37c0752a2, + 0x857fcae62d8493a5, + 0xa6dfbd9fb8e5b88f, + 0xd097ad07a71f26b2, + 0x825ecc24c8737830, + 0xa2f67f2dfa90563b, + 0xcbb41ef979346bca, + 0xfea126b7d78186bd, + 0x9f24b832e6b0f436, + 0xc6ede63fa05d3144, + 0xf8a95fcf88747d94, + 0x9b69dbe1b548ce7d, + 0xc24452da229b021c, + 0xf2d56790ab41c2a3, + 0x97c560ba6b0919a6, + 0xbdb6b8e905cb600f, + 0xed246723473e3813, + 0x9436c0760c86e30c, + 0xb94470938fa89bcf, + 0xe7958cb87392c2c3, + 0x90bd77f3483bb9ba, + 0xb4ecd5f01a4aa828, + 0xe2280b6c20dd5232, + 0x8d590723948a535f, + 0xb0af48ec79ace837, + 0xdcdb1b2798182245, + 0x8a08f0f8bf0f156b, + 0xac8b2d36eed2dac6, + 0xd7adf884aa879177, + 0x86ccbb52ea94baeb, + 0xa87fea27a539e9a5, + 0xd29fe4b18e88640f, + 0x83a3eeeef9153e89, + 0xa48ceaaab75a8e2b, + 0xcdb02555653131b6, + 0x808e17555f3ebf12, + 0xa0b19d2ab70e6ed6, + 0xc8de047564d20a8c, + 0xfb158592be068d2f, + 0x9ced737bb6c4183d, + 0xc428d05aa4751e4d, + 0xf53304714d9265e0, + 0x993fe2c6d07b7fac, + 0xbf8fdb78849a5f97, + 0xef73d256a5c0f77d, + 0x95a8637627989aae, + 0xbb127c53b17ec159, + 0xe9d71b689dde71b0, + 0x9226712162ab070e, + 0xb6b00d69bb55c8d1, + 0xe45c10c42a2b3b06, + 0x8eb98a7a9a5b04e3, + 0xb267ed1940f1c61c, + 0xdf01e85f912e37a3, + 0x8b61313bbabce2c6, + 0xae397d8aa96c1b78, + 0xd9c7dced53c72256, + 0x881cea14545c7575, + 0xaa242499697392d3, + 0xd4ad2dbfc3d07788, + 0x84ec3c97da624ab5, + 0xa6274bbdd0fadd62, + 0xcfb11ead453994ba, + 0x81ceb32c4b43fcf5, + 0xa2425ff75e14fc32, + 0xcad2f7f5359a3b3e, + 0xfd87b5f28300ca0e, + 0x9e74d1b791e07e48, + 0xc612062576589ddb, + 0xf79687aed3eec551, + 0x9abe14cd44753b53, + 0xc16d9a0095928a27, + 0xf1c90080baf72cb1, + 0x971da05074da7bef, + 0xbce5086492111aeb, + 0xec1e4a7db69561a5, + 0x9392ee8e921d5d07, + 0xb877aa3236a4b449, + 0xe69594bec44de15b, + 0x901d7cf73ab0acd9, + 0xb424dc35095cd80f, + 0xe12e13424bb40e13, + 0x8cbccc096f5088cc, + 0xafebff0bcb24aaff, + 0xdbe6fecebdedd5bf, + 0x89705f4136b4a597, + 0xabcc77118461cefd, + 0xd6bf94d5e57a42bc, + 0x8637bd05af6c69b6, + 0xa7c5ac471b478423, + 0xd1b71758e219652c, + 0x83126e978d4fdf3b, + 0xa3d70a3d70a3d70a, + 0xcccccccccccccccd, + 0x8000000000000000, + 0xa000000000000000, + 0xc800000000000000, + 0xfa00000000000000, + 0x9c40000000000000, + 0xc350000000000000, + 0xf424000000000000, + 0x9896800000000000, + 0xbebc200000000000, + 0xee6b280000000000, + 0x9502f90000000000, + 0xba43b74000000000, + 0xe8d4a51000000000, + 0x9184e72a00000000, + 0xb5e620f480000000, + 0xe35fa931a0000000, + 0x8e1bc9bf04000000, + 0xb1a2bc2ec5000000, + 0xde0b6b3a76400000, + 0x8ac7230489e80000, + 0xad78ebc5ac620000, + 0xd8d726b7177a8000, + 0x878678326eac9000, + 0xa968163f0a57b400, + 0xd3c21bcecceda100, + 0x84595161401484a0, + 0xa56fa5b99019a5c8, + 0xcecb8f27f4200f3a, + 0x813f3978f8940984, + 0xa18f07d736b90be5, + 0xc9f2c9cd04674edf, + 0xfc6f7c4045812296, + 0x9dc5ada82b70b59e, + 0xc5371912364ce305, + 0xf684df56c3e01bc7, + 0x9a130b963a6c115c, + 0xc097ce7bc90715b3, + 0xf0bdc21abb48db20, + 0x96769950b50d88f4, + 0xbc143fa4e250eb31, + 0xeb194f8e1ae525fd, + 0x92efd1b8d0cf37be, + 0xb7abc627050305ae, + 0xe596b7b0c643c719, + 0x8f7e32ce7bea5c70, + 0xb35dbf821ae4f38c, + 0xe0352f62a19e306f, + 0x8c213d9da502de45, + 0xaf298d050e4395d7, + 0xdaf3f04651d47b4c, + 0x88d8762bf324cd10, + 0xab0e93b6efee0054, + 0xd5d238a4abe98068, + 0x85a36366eb71f041, + 0xa70c3c40a64e6c52, + 0xd0cf4b50cfe20766, + 0x82818f1281ed44a0, + 0xa321f2d7226895c8, + 0xcbea6f8ceb02bb3a, + 0xfee50b7025c36a08, + 0x9f4f2726179a2245, + 0xc722f0ef9d80aad6, + 0xf8ebad2b84e0d58c, + 0x9b934c3b330c8577, + 0xc2781f49ffcfa6d5, + 0xf316271c7fc3908b, + 0x97edd871cfda3a57, + 0xbde94e8e43d0c8ec, + 0xed63a231d4c4fb27, + 0x945e455f24fb1cf9, + 0xb975d6b6ee39e437, + 0xe7d34c64a9c85d44, + 0x90e40fbeea1d3a4b, + 0xb51d13aea4a488dd, + 0xe264589a4dcdab15, + 0x8d7eb76070a08aed, + 0xb0de65388cc8ada8, + 0xdd15fe86affad912, + 0x8a2dbf142dfcc7ab, + 0xacb92ed9397bf996, + 0xd7e77a8f87daf7fc, + 0x86f0ac99b4e8dafd, + 0xa8acd7c0222311bd, + 0xd2d80db02aabd62c, + 0x83c7088e1aab65db, + 0xa4b8cab1a1563f52, + 0xcde6fd5e09abcf27, + 0x80b05e5ac60b6178, + 0xa0dc75f1778e39d6, + 0xc913936dd571c84c, + 0xfb5878494ace3a5f, + 0x9d174b2dcec0e47b, + 0xc45d1df942711d9a, + 0xf5746577930d6501, + 0x9968bf6abbe85f20, + 0xbfc2ef456ae276e9, + 0xefb3ab16c59b14a3, + 0x95d04aee3b80ece6, + 0xbb445da9ca61281f, + 0xea1575143cf97227, + 0x924d692ca61be758, + 0xb6e0c377cfa2e12e, + 0xe498f455c38b997a, + 0x8edf98b59a373fec, + 0xb2977ee300c50fe7, + 0xdf3d5e9bc0f653e1, + 0x8b865b215899f46d, + 0xae67f1e9aec07188, + 0xda01ee641a708dea, + 0x884134fe908658b2, + 0xaa51823e34a7eedf, + 0xd4e5e2cdc1d1ea96, + 0x850fadc09923329e, + 0xa6539930bf6bff46, + 0xcfe87f7cef46ff17, + 0x81f14fae158c5f6e, + 0xa26da3999aef774a, + 0xcb090c8001ab551c, + 0xfdcb4fa002162a63, + 0x9e9f11c4014dda7e, + 0xc646d63501a1511e, + 0xf7d88bc24209a565, + 0x9ae757596946075f, + 0xc1a12d2fc3978937, + 0xf209787bb47d6b85, + 0x9745eb4d50ce6333, + 0xbd176620a501fc00, + 0xec5d3fa8ce427b00, + 0x93ba47c980e98ce0, + 0xb8a8d9bbe123f018, + 0xe6d3102ad96cec1e, + 0x9043ea1ac7e41393, + 0xb454e4a179dd1877, + 0xe16a1dc9d8545e95, + 0x8ce2529e2734bb1d, + 0xb01ae745b101e9e4, + 0xdc21a1171d42645d, + 0x899504ae72497eba, + 0xabfa45da0edbde69, + 0xd6f8d7509292d603, + 0x865b86925b9bc5c2, + 0xa7f26836f282b733, + 0xd1ef0244af2364ff, + 0x8335616aed761f1f, + 0xa402b9c5a8d3a6e7, + 0xcd036837130890a1, + 0x802221226be55a65, + 0xa02aa96b06deb0fe, + 0xc83553c5c8965d3d, + 0xfa42a8b73abbf48d, + 0x9c69a97284b578d8, + 0xc38413cf25e2d70e, + 0xf46518c2ef5b8cd1, + 0x98bf2f79d5993803, + 0xbeeefb584aff8604, + 0xeeaaba2e5dbf6785, + 0x952ab45cfa97a0b3, + 0xba756174393d88e0, + 0xe912b9d1478ceb17, + 0x91abb422ccb812ef, + 0xb616a12b7fe617aa, + 0xe39c49765fdf9d95, + 0x8e41ade9fbebc27d, + 0xb1d219647ae6b31c, + 0xde469fbd99a05fe3, + 0x8aec23d680043bee, + 0xada72ccc20054aea, + 0xd910f7ff28069da4, + 0x87aa9aff79042287, + 0xa99541bf57452b28, + 0xd3fa922f2d1675f2, + 0x847c9b5d7c2e09b7, + 0xa59bc234db398c25, + 0xcf02b2c21207ef2f, + 0x8161afb94b44f57d, + 0xa1ba1ba79e1632dc, + 0xca28a291859bbf93, + 0xfcb2cb35e702af78, + 0x9defbf01b061adab, + 0xc56baec21c7a1916, + 0xf6c69a72a3989f5c, + 0x9a3c2087a63f6399, + 0xc0cb28a98fcf3c80, + 0xf0fdf2d3f3c30b9f, + 0x969eb7c47859e744, + 0xbc4665b596706115, + 0xeb57ff22fc0c795a, + 0x9316ff75dd87cbd8, + 0xb7dcbf5354e9bece, + 0xe5d3ef282a242e82, + 0x8fa475791a569d11, + 0xb38d92d760ec4455, + 0xe070f78d3927556b, + 0x8c469ab843b89563, + 0xaf58416654a6babb, + 0xdb2e51bfe9d0696a, + 0x88fcf317f22241e2, + 0xab3c2fddeeaad25b, + 0xd60b3bd56a5586f2, + 0x85c7056562757457, + 0xa738c6bebb12d16d, + 0xd106f86e69d785c8, + 0x82a45b450226b39d, + 0xa34d721642b06084, + 0xcc20ce9bd35c78a5, + 0xff290242c83396ce, + 0x9f79a169bd203e41, + 0xc75809c42c684dd1, + 0xf92e0c3537826146, + 0x9bbcc7a142b17ccc, + 0xc2abf989935ddbfe, + 0xf356f7ebf83552fe, + 0x98165af37b2153df, + 0xbe1bf1b059e9a8d6, + 0xeda2ee1c7064130c, + 0x9485d4d1c63e8be8, + 0xb9a74a0637ce2ee1, + 0xe8111c87c5c1ba9a, + 0x910ab1d4db9914a0, + 0xb54d5e4a127f59c8, + 0xe2a0b5dc971f303a, + 0x8da471a9de737e24, + 0xb10d8e1456105dad, + 0xdd50f1996b947519, + 0x8a5296ffe33cc930, + 0xace73cbfdc0bfb7b, + 0xd8210befd30efa5a, + 0x8714a775e3e95c78, + 0xa8d9d1535ce3b396, + 0xd31045a8341ca07c, + 0x83ea2b892091e44e, + 0xa4e4b66b68b65d61, + 0xce1de40642e3f4b9, + 0x80d2ae83e9ce78f4, + 0xa1075a24e4421731, + 0xc94930ae1d529cfd, + 0xfb9b7cd9a4a7443c, + 0x9d412e0806e88aa6, + 0xc491798a08a2ad4f, + 0xf5b5d7ec8acb58a3, + 0x9991a6f3d6bf1766, + 0xbff610b0cc6edd3f, + 0xeff394dcff8a948f, + 0x95f83d0a1fb69cd9, + 0xbb764c4ca7a44410, + 0xea53df5fd18d5514, + 0x92746b9be2f8552c, + 0xb7118682dbb66a77, + 0xe4d5e82392a40515, + 0x8f05b1163ba6832d, + 0xb2c71d5bca9023f8, + 0xdf78e4b2bd342cf7, + 0x8bab8eefb6409c1a, + 0xae9672aba3d0c321, + 0xda3c0f568cc4f3e9, + 0x8865899617fb1871, + 0xaa7eebfb9df9de8e, + 0xd51ea6fa85785631, + 0x8533285c936b35df, + 0xa67ff273b8460357, + 0xd01fef10a657842c, + 0x8213f56a67f6b29c, + 0xa298f2c501f45f43, + 0xcb3f2f7642717713, + 0xfe0efb53d30dd4d8, + 0x9ec95d1463e8a507, + 0xc67bb4597ce2ce49, + 0xf81aa16fdc1b81db, + 0x9b10a4e5e9913129, + 0xc1d4ce1f63f57d73, + 0xf24a01a73cf2dcd0, + 0x976e41088617ca02, + 0xbd49d14aa79dbc82, + 0xec9c459d51852ba3, + 0x93e1ab8252f33b46, + 0xb8da1662e7b00a17, + 0xe7109bfba19c0c9d, + 0x906a617d450187e2, + 0xb484f9dc9641e9db, + 0xe1a63853bbd26451, + 0x8d07e33455637eb3, + 0xb049dc016abc5e60, + 0xdc5c5301c56b75f7, + 0x89b9b3e11b6329bb, + 0xac2820d9623bf429, + 0xd732290fbacaf134, + 0x867f59a9d4bed6c0, + 0xa81f301449ee8c70, + 0xd226fc195c6a2f8c, + 0x83585d8fd9c25db8, + 0xa42e74f3d032f526, + 0xcd3a1230c43fb26f, + 0x80444b5e7aa7cf85, + 0xa0555e361951c367, + 0xc86ab5c39fa63441, + 0xfa856334878fc151, + 0x9c935e00d4b9d8d2, + 0xc3b8358109e84f07, + 0xf4a642e14c6262c9, + 0x98e7e9cccfbd7dbe, + 0xbf21e44003acdd2d, + 0xeeea5d5004981478, + 0x95527a5202df0ccb, + 0xbaa718e68396cffe, + 0xe950df20247c83fd, + 0x91d28b7416cdd27e, + ], + [ + -1077, + -1073, + -1070, + -1067, + -1063, + -1060, + -1057, + -1053, + -1050, + -1047, + -1043, + -1040, + -1037, + -1034, + -1030, + -1027, + -1024, + -1020, + -1017, + -1014, + -1010, + -1007, + -1004, + -1000, + -997, + -994, + -990, + -987, + -984, + -980, + -977, + -974, + -970, + -967, + -964, + -960, + -957, + -954, + -950, + -947, + -944, + -940, + -937, + -934, + -931, + -927, + -924, + -921, + -917, + -914, + -911, + -907, + -904, + -901, + -897, + -894, + -891, + -887, + -884, + -881, + -877, + -874, + -871, + -867, + -864, + -861, + -857, + -854, + -851, + -847, + -844, + -841, + -838, + -834, + -831, + -828, + -824, + -821, + -818, + -814, + -811, + -808, + -804, + -801, + -798, + -794, + -791, + -788, + -784, + -781, + -778, + -774, + -771, + -768, + -764, + -761, + -758, + -754, + -751, + -748, + -744, + -741, + -738, + -735, + -731, + -728, + -725, + -721, + -718, + -715, + -711, + -708, + -705, + -701, + -698, + -695, + -691, + -688, + -685, + -681, + -678, + -675, + -671, + -668, + -665, + -661, + -658, + -655, + -651, + -648, + -645, + -642, + -638, + -635, + -632, + -628, + -625, + -622, + -618, + -615, + -612, + -608, + -605, + -602, + -598, + -595, + -592, + -588, + -585, + -582, + -578, + -575, + -572, + -568, + -565, + -562, + -558, + -555, + -552, + -549, + -545, + -542, + -539, + -535, + -532, + -529, + -525, + -522, + -519, + -515, + -512, + -509, + -505, + -502, + -499, + -495, + -492, + -489, + -485, + -482, + -479, + -475, + -472, + -469, + -465, + -462, + -459, + -455, + -452, + -449, + -446, + -442, + -439, + -436, + -432, + -429, + -426, + -422, + -419, + -416, + -412, + -409, + -406, + -402, + -399, + -396, + -392, + -389, + -386, + -382, + -379, + -376, + -372, + -369, + -366, + -362, + -359, + -356, + -353, + -349, + -346, + -343, + -339, + -336, + -333, + -329, + -326, + -323, + -319, + -316, + -313, + -309, + -306, + -303, + -299, + -296, + -293, + -289, + -286, + -283, + -279, + -276, + -273, + -269, + -266, + -263, + -259, + -256, + -253, + -250, + -246, + -243, + -240, + -236, + -233, + -230, + -226, + -223, + -220, + -216, + -213, + -210, + -206, + -203, + -200, + -196, + -193, + -190, + -186, + -183, + -180, + -176, + -173, + -170, + -166, + -163, + -160, + -157, + -153, + -150, + -147, + -143, + -140, + -137, + -133, + -130, + -127, + -123, + -120, + -117, + -113, + -110, + -107, + -103, + -100, + -97, + -93, + -90, + -87, + -83, + -80, + -77, + -73, + -70, + -67, + -63, + -60, + -57, + -54, + -50, + -47, + -44, + -40, + -37, + -34, + -30, + -27, + -24, + -20, + -17, + -14, + -10, + -7, + -4, + 0, + 3, + 6, + 10, + 13, + 16, + 20, + 23, + 26, + 30, + 33, + 36, + 39, + 43, + 46, + 49, + 53, + 56, + 59, + 63, + 66, + 69, + 73, + 76, + 79, + 83, + 86, + 89, + 93, + 96, + 99, + 103, + 106, + 109, + 113, + 116, + 119, + 123, + 126, + 129, + 132, + 136, + 139, + 142, + 146, + 149, + 152, + 156, + 159, + 162, + 166, + 169, + 172, + 176, + 179, + 182, + 186, + 189, + 192, + 196, + 199, + 202, + 206, + 209, + 212, + 216, + 219, + 222, + 226, + 229, + 232, + 235, + 239, + 242, + 245, + 249, + 252, + 255, + 259, + 262, + 265, + 269, + 272, + 275, + 279, + 282, + 285, + 289, + 292, + 295, + 299, + 302, + 305, + 309, + 312, + 315, + 319, + 322, + 325, + 328, + 332, + 335, + 338, + 342, + 345, + 348, + 352, + 355, + 358, + 362, + 365, + 368, + 372, + 375, + 378, + 382, + 385, + 388, + 392, + 395, + 398, + 402, + 405, + 408, + 412, + 415, + 418, + 422, + 425, + 428, + 431, + 435, + 438, + 441, + 445, + 448, + 451, + 455, + 458, + 461, + 465, + 468, + 471, + 475, + 478, + 481, + 485, + 488, + 491, + 495, + 498, + 501, + 505, + 508, + 511, + 515, + 518, + 521, + 524, + 528, + 531, + 534, + 538, + 541, + 544, + 548, + 551, + 554, + 558, + 561, + 564, + 568, + 571, + 574, + 578, + 581, + 584, + 588, + 591, + 594, + 598, + 601, + 604, + 608, + 611, + 614, + 617, + 621, + 624, + 627, + 631, + 634, + 637, + 641, + 644, + 647, + 651, + 654, + 657, + 661, + 664, + 667, + 671, + 674, + 677, + 681, + 684, + 687, + 691, + 694, + 697, + 701, + 704, + 707, + 711, + 714, + 717, + 720, + 724, + 727, + 730, + 734, + 737, + 740, + 744, + 747, + 750, + 754, + 757, + 760, + 764, + 767, + 770, + 774, + 777, + 780, + 784, + 787, + 790, + 794, + 797, + 800, + 804, + 807, + 810, + 813, + 817, + 820, + 823, + 827, + 830, + 833, + 837, + 840, + 843, + 847, + 850, + 853, + 857, + 860, + 863, + 867, + 870, + 873, + 877, + 880, + 883, + 887, + 890, + 893, + 897, + 900, + 903, + 907, + 910, + 913, + 916, + 920, + 923, + 926, + 930, + 933, + 936, + 940, + 943, + 946, + 950, + ], +); +#[rustfmt::skip] pub const F32_SHORT_POWERS: [f32; 11] = [ 1e0, 1e1, @@ -1244,6 +1249,7 @@ pub const F32_SHORT_POWERS: [f32; 11] = [ 1e10, ]; +#[rustfmt::skip] pub const F64_SHORT_POWERS: [f64; 23] = [ 1e0, 1e1, -- cgit 1.4.1-3-g733a5 From f4cff277925d61c15e64cc2a05b37a3446a3a411 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 Nov 2019 19:44:55 -0800 Subject: Make libcore/unicode/printable.rs compatible with rustfmt --- src/libcore/unicode/printable.py | 6 ++++-- src/libcore/unicode/printable.rs | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) mode change 100644 => 100755 src/libcore/unicode/printable.py (limited to 'src') diff --git a/src/libcore/unicode/printable.py b/src/libcore/unicode/printable.py old mode 100644 new mode 100755 index 4e8b4ecad02..91db6381c9b --- a/src/libcore/unicode/printable.py +++ b/src/libcore/unicode/printable.py @@ -111,16 +111,19 @@ def compress_normal(normal): return compressed def print_singletons(uppers, lowers, uppersname, lowersname): + print("#[rustfmt::skip]") print("const {}: &[(u8, u8)] = &[".format(uppersname)) for u, c in uppers: print(" ({:#04x}, {}),".format(u, c)) print("];") + print("#[rustfmt::skip]") print("const {}: &[u8] = &[".format(lowersname)) for i in range(0, len(lowers), 8): print(" {}".format(" ".join("{:#04x},".format(l) for l in lowers[i:i+8]))) print("];") def print_normal(normal, normalname): + print("#[rustfmt::skip]") print("const {}: &[u8] = &[".format(normalname)) for v in normal: print(" {}".format(" ".join("{:#04x},".format(i) for i in v))) @@ -170,8 +173,7 @@ def main(): // NOTE: The following code was generated by "src/libcore/unicode/printable.py", // do not edit directly! -fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8], - normal: &[u8]) -> bool { +fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8], normal: &[u8]) -> bool { let xupper = (x >> 8) as u8; let mut lowerstart = 0; for &(upper, lowercount) in singletonuppers { diff --git a/src/libcore/unicode/printable.rs b/src/libcore/unicode/printable.rs index d411dda7dc1..eee9ea52ef0 100644 --- a/src/libcore/unicode/printable.rs +++ b/src/libcore/unicode/printable.rs @@ -1,8 +1,7 @@ // NOTE: The following code was generated by "src/libcore/unicode/printable.py", // do not edit directly! -fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8], - normal: &[u8]) -> bool { +fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8], normal: &[u8]) -> bool { let xupper = (x >> 8) as u8; let mut lowerstart = 0; for &(upper, lowercount) in singletonuppers { @@ -70,6 +69,7 @@ pub(crate) fn is_printable(x: char) -> bool { } } +#[rustfmt::skip] const SINGLETONS0U: &[(u8, u8)] = &[ (0x00, 1), (0x03, 5), @@ -113,6 +113,7 @@ const SINGLETONS0U: &[(u8, u8)] = &[ (0xfe, 3), (0xff, 9), ]; +#[rustfmt::skip] const SINGLETONS0L: &[u8] = &[ 0xad, 0x78, 0x79, 0x8b, 0x8d, 0xa2, 0x30, 0x57, 0x58, 0x8b, 0x8c, 0x90, 0x1c, 0x1d, 0xdd, 0x0e, @@ -152,6 +153,7 @@ const SINGLETONS0L: &[u8] = &[ 0xff, 0x53, 0x67, 0x75, 0xc8, 0xc9, 0xd0, 0xd1, 0xd8, 0xd9, 0xe7, 0xfe, 0xff, ]; +#[rustfmt::skip] const SINGLETONS1U: &[(u8, u8)] = &[ (0x00, 6), (0x01, 1), @@ -189,6 +191,7 @@ const SINGLETONS1U: &[(u8, u8)] = &[ (0xf9, 6), (0xfa, 2), ]; +#[rustfmt::skip] const SINGLETONS1L: &[u8] = &[ 0x0c, 0x27, 0x3b, 0x3e, 0x4e, 0x4f, 0x8f, 0x9e, 0x9e, 0x9f, 0x06, 0x07, 0x09, 0x36, 0x3d, 0x3e, @@ -212,6 +215,7 @@ const SINGLETONS1L: &[u8] = &[ 0xa4, 0xaa, 0xaf, 0xb0, 0xc0, 0xd0, 0x0c, 0x72, 0xa3, 0xa4, 0xcb, 0xcc, 0x6e, 0x6f, ]; +#[rustfmt::skip] const NORMAL0: &[u8] = &[ 0x00, 0x20, 0x5f, 0x22, @@ -355,6 +359,7 @@ const NORMAL0: &[u8] = &[ 0x1b, 0x03, 0x0f, 0x0d, ]; +#[rustfmt::skip] const NORMAL1: &[u8] = &[ 0x5e, 0x22, 0x7b, 0x05, -- cgit 1.4.1-3-g733a5 From 28eb31f8dcfa495e2d0090a7e649d90a2cbef237 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 Nov 2019 19:50:24 -0800 Subject: Make libcore/unicode/tables.rs compatible with rustfmt --- src/libcore/unicode/tables.rs | 29 ++++++++++++++++------------- src/libcore/unicode/unicode.py | 36 ++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/libcore/unicode/tables.rs b/src/libcore/unicode/tables.rs index 5b5be485431..3fa125e8fea 100644 --- a/src/libcore/unicode/tables.rs +++ b/src/libcore/unicode/tables.rs @@ -2,19 +2,16 @@ #![allow(missing_docs, non_upper_case_globals, non_snake_case, clippy::unreadable_literal)] -use crate::unicode::version::UnicodeVersion; use crate::unicode::bool_trie::{BoolTrie, SmallBoolTrie}; +use crate::unicode::version::UnicodeVersion; /// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of /// `char` and `str` methods are based on. #[unstable(feature = "unicode_version", issue = "49726")] -pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion { - major: 12, - minor: 1, - micro: 0, - _priv: (), -}; +pub const UNICODE_VERSION: UnicodeVersion = + UnicodeVersion { major: 12, minor: 1, micro: 0, _priv: () }; pub(crate) mod general_category { + #[rustfmt::skip] const Cc_table: &super::SmallBoolTrie = &super::SmallBoolTrie { r1: &[ 0, 1, 0 @@ -28,6 +25,7 @@ pub(crate) mod general_category { Cc_table.lookup(c) } + #[rustfmt::skip] const N_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x03ff000000000000, 0x0000000000000000, 0x720c000000000000, 0x0000000000000000, @@ -138,10 +136,10 @@ pub(crate) mod general_category { pub fn N(c: char) -> bool { N_table.lookup(c) } - } pub(crate) mod derived_property { + #[rustfmt::skip] const Alphabetic_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x0000000000000000, 0x07fffffe07fffffe, 0x0420040000000000, 0xff7fffffff7fffff, @@ -327,6 +325,7 @@ pub(crate) mod derived_property { Alphabetic_table.lookup(c) } + #[rustfmt::skip] const Case_Ignorable_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x0400408000000000, 0x0000000140000000, 0x0190a10000000000, 0x0000000000000000, @@ -464,6 +463,7 @@ pub(crate) mod derived_property { Case_Ignorable_table.lookup(c) } + #[rustfmt::skip] const Cased_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x0000000000000000, 0x07fffffe07fffffe, 0x0420040000000000, 0xff7fffffff7fffff, @@ -565,6 +565,7 @@ pub(crate) mod derived_property { Cased_table.lookup(c) } + #[rustfmt::skip] const Grapheme_Extend_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, @@ -689,6 +690,7 @@ pub(crate) mod derived_property { Grapheme_Extend_table.lookup(c) } + #[rustfmt::skip] const Lowercase_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x0000000000000000, 0x07fffffe00000000, 0x0420040000000000, 0xff7fffff80000000, @@ -789,6 +791,7 @@ pub(crate) mod derived_property { Lowercase_table.lookup(c) } + #[rustfmt::skip] const Uppercase_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x0000000000000000, 0x0000000007fffffe, 0x0000000000000000, 0x000000007f7fffff, @@ -889,10 +892,10 @@ pub(crate) mod derived_property { pub fn Uppercase(c: char) -> bool { Uppercase_table.lookup(c) } - } pub(crate) mod property { + #[rustfmt::skip] const White_Space_table: &super::SmallBoolTrie = &super::SmallBoolTrie { r1: &[ 0, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -912,20 +915,19 @@ pub(crate) mod property { pub fn White_Space(c: char) -> bool { White_Space_table.lookup(c) } - } pub(crate) mod conversions { pub fn to_lower(c: char) -> [char; 3] { match bsearch_case_table(c, to_lowercase_table) { - None => [c, '\0', '\0'], + None => [c, '\0', '\0'], Some(index) => to_lowercase_table[index].1, } } pub fn to_upper(c: char) -> [char; 3] { match bsearch_case_table(c, to_uppercase_table) { - None => [c, '\0', '\0'], + None => [c, '\0', '\0'], Some(index) => to_uppercase_table[index].1, } } @@ -934,6 +936,7 @@ pub(crate) mod conversions { table.binary_search_by(|&(key, _)| key.cmp(&c)).ok() } + #[rustfmt::skip] const to_lowercase_table: &[(char, [char; 3])] = &[ ('\u{41}', ['\u{61}', '\0', '\0']), ('\u{42}', ['\u{62}', '\0', '\0']), ('\u{43}', ['\u{63}', '\0', '\0']), ('\u{44}', ['\u{64}', '\0', '\0']), ('\u{45}', ['\u{65}', '\0', @@ -1558,6 +1561,7 @@ pub(crate) mod conversions { ('\u{1e920}', ['\u{1e942}', '\0', '\0']), ('\u{1e921}', ['\u{1e943}', '\0', '\0']) ]; + #[rustfmt::skip] const to_uppercase_table: &[(char, [char; 3])] = &[ ('\u{61}', ['\u{41}', '\0', '\0']), ('\u{62}', ['\u{42}', '\0', '\0']), ('\u{63}', ['\u{43}', '\0', '\0']), ('\u{64}', ['\u{44}', '\0', '\0']), ('\u{65}', ['\u{45}', '\0', @@ -2228,5 +2232,4 @@ pub(crate) mod conversions { ('\u{1e940}', ['\u{1e91e}', '\0', '\0']), ('\u{1e941}', ['\u{1e91f}', '\0', '\0']), ('\u{1e942}', ['\u{1e920}', '\0', '\0']), ('\u{1e943}', ['\u{1e921}', '\0', '\0']) ]; - } diff --git a/src/libcore/unicode/unicode.py b/src/libcore/unicode/unicode.py index 89894f7932d..97df92a56da 100755 --- a/src/libcore/unicode/unicode.py +++ b/src/libcore/unicode/unicode.py @@ -81,8 +81,8 @@ PREAMBLE = """\ #![allow(missing_docs, non_upper_case_globals, non_snake_case, clippy::unreadable_literal)] -use crate::unicode::version::UnicodeVersion; use crate::unicode::bool_trie::{{BoolTrie, SmallBoolTrie}}; +use crate::unicode::version::UnicodeVersion; """.format(year=datetime.datetime.now().year) # Mapping taken from Table 12 from: @@ -555,6 +555,8 @@ def generate_table( if is_pub: pub_string = "pub " + yield "\n" + yield " #[rustfmt::skip]\n" yield " %sconst %s: %s = &[\n" % (pub_string, name, decl_type) data = [] @@ -568,7 +570,7 @@ def generate_table( for table_line in generate_table_lines("".join(data).split(","), 8): yield table_line - yield "\n ];\n\n" + yield "\n ];\n" def compute_trie(raw_data, chunk_size): @@ -634,6 +636,9 @@ def generate_bool_trie(name, codepoint_ranges, is_pub=False): pub_string = "" if is_pub: pub_string = "pub " + + yield "\n" + yield " #[rustfmt::skip]\n" yield " %sconst %s: &super::BoolTrie = &super::BoolTrie {\n" % (pub_string, name) yield " r1: [\n" data = ("0x%016x" % chunk for chunk in chunks[:0x800 // chunk_size]) @@ -678,7 +683,7 @@ def generate_bool_trie(name, codepoint_ranges, is_pub=False): yield fragment yield "\n ],\n" - yield " };\n\n" + yield " };\n" def generate_small_bool_trie(name, codepoint_ranges, is_pub=False): @@ -700,6 +705,8 @@ def generate_small_bool_trie(name, codepoint_ranges, is_pub=False): if is_pub: pub_string = "pub " + yield "\n" + yield " #[rustfmt::skip]\n" yield (" %sconst %s: &super::SmallBoolTrie = &super::SmallBoolTrie {\n" % (pub_string, name)) @@ -717,7 +724,7 @@ def generate_small_bool_trie(name, codepoint_ranges, is_pub=False): yield fragment yield "\n ],\n" - yield " };\n\n" + yield " };\n" def generate_property_module(mod, grouped_categories, category_subset): @@ -726,7 +733,7 @@ def generate_property_module(mod, grouped_categories, category_subset): Generate Rust code for module defining properties. """ - yield "pub(crate) mod %s {\n" % mod + yield "pub(crate) mod %s {" % mod for cat in sorted(category_subset): if cat in ("Cc", "White_Space"): generator = generate_small_bool_trie("%s_table" % cat, grouped_categories[cat]) @@ -736,9 +743,10 @@ def generate_property_module(mod, grouped_categories, category_subset): for fragment in generator: yield fragment + yield "\n" yield " pub fn %s(c: char) -> bool {\n" % cat yield " %s_table.lookup(c)\n" % cat - yield " }\n\n" + yield " }\n" yield "}\n\n" @@ -753,21 +761,21 @@ def generate_conversions_module(unicode_data): yield """ pub fn to_lower(c: char) -> [char; 3] { match bsearch_case_table(c, to_lowercase_table) { - None => [c, '\\0', '\\0'], + None => [c, '\\0', '\\0'], Some(index) => to_lowercase_table[index].1, } } pub fn to_upper(c: char) -> [char; 3] { match bsearch_case_table(c, to_uppercase_table) { - None => [c, '\\0', '\\0'], + None => [c, '\\0', '\\0'], Some(index) => to_uppercase_table[index].1, } } fn bsearch_case_table(c: char, table: &[(char, [char; 3])]) -> Option { table.binary_search_by(|&(key, _)| key.cmp(&c)).ok() - }\n\n""" + }\n""" decl_type = "&[(char, [char; 3])]" format_conversion = lambda x: "({},[{},{},{}])".format(*( @@ -827,13 +835,9 @@ def main(): /// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of /// `char` and `str` methods are based on. #[unstable(feature = "unicode_version", issue = "49726")] - pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {{ - major: {version.major}, - minor: {version.minor}, - micro: {version.micro}, - _priv: (), - }}; - """).format(version=unicode_version) + pub const UNICODE_VERSION: UnicodeVersion = + UnicodeVersion {{ major: {v.major}, minor: {v.minor}, micro: {v.micro}, _priv: () }}; + """).format(v=unicode_version) buf.write(unicode_version_notice) get_path = lambda f: get_unicode_file_path(unicode_version, f) -- cgit 1.4.1-3-g733a5 From b756b7d074976c3644031009e89925963ce6f798 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 06:32:49 +0100 Subject: tidy: adjust feature gating path --- src/tools/tidy/src/features.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index defe85ef46a..4ea101296b7 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -231,7 +231,7 @@ pub fn collect_lang_features(base_src_path: &Path, bad: &mut bool) -> Features { } fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features { - let path = base.join("libsyntax/feature_gate").join(file); + let path = base.join("librustc_feature").join(file); let contents = t!(fs::read_to_string(&path)); // We allow rustc-internal features to omit a tracking issue. -- cgit 1.4.1-3-g733a5 From 91fcd40ca2637796b5b4eb75db7cfb57efcde11e Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 06:43:32 +0100 Subject: update rustc_feature crate docs --- src/librustc_feature/lib.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/librustc_feature/lib.rs b/src/librustc_feature/lib.rs index e8ed1f377e5..82e60889316 100644 --- a/src/librustc_feature/lib.rs +++ b/src/librustc_feature/lib.rs @@ -1,16 +1,14 @@ -//! # Feature gating +//! # Feature gates //! -//! This module implements the gating necessary for preventing certain compiler -//! features from being used by default. This module will crawl a pre-expanded -//! AST to ensure that there are no features which are used that are not -//! enabled. +//! This crate declares the set of past and present unstable features in the compiler. +//! Feature gate checking itself is done in `libsyntax/feature_gate/check.rs` at the moment. //! //! Features are enabled in programs via the crate-level attributes of //! `#![feature(...)]` with a comma-separated list of features. //! -//! For the purpose of future feature-tracking, once code for detection of feature -//! gate usage is added, *do not remove it again* even once the feature -//! becomes stable. +//! For the purpose of future feature-tracking, once a feature gate is added, +//! even if it is stabilized or removed, *do not remove it*. Instead, move the +//! symbol to the `accepted` or `removed` modules respectively. mod accepted; mod removed; -- cgit 1.4.1-3-g733a5 From 79077f13ffa9194161a0ed574b036794ab1a8c36 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 07:40:28 +0100 Subject: move GateIssue to rustc_feature & simplify emit_feature_err --- src/librustc/lint/levels.rs | 6 +-- src/librustc/middle/stability.rs | 24 +++++++----- src/librustc_feature/lib.rs | 34 +++++++++++++++- src/librustc_metadata/native_libs.rs | 36 +++++++++-------- src/librustc_mir/transform/check_consts/ops.rs | 48 +++++++++++------------ src/librustc_parse/config.rs | 3 +- src/librustc_passes/check_const.rs | 10 +---- src/librustc_resolve/macros.rs | 11 ++---- src/librustc_typeck/astconv.rs | 5 +-- src/librustc_typeck/check/coercion.rs | 6 +-- src/librustc_typeck/check/mod.rs | 32 ++++++++------- src/librustc_typeck/check/wfcheck.rs | 6 +-- src/librustc_typeck/collect.rs | 12 +++--- src/libsyntax/attr/builtin.rs | 4 +- src/libsyntax/feature_gate/check.rs | 54 ++++++-------------------- src/libsyntax/lib.rs | 5 +-- src/libsyntax_expand/expand.rs | 28 ++++++------- 17 files changed, 159 insertions(+), 165 deletions(-) (limited to 'src') diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index 27bf9649324..619ca724214 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -232,13 +232,13 @@ impl<'a> LintLevelsBuilder<'a> { // don't have any lint names (`#[level(reason = "foo")]`) if let ast::LitKind::Str(rationale, _) = name_value.kind { if !self.sess.features_untracked().lint_reasons { - feature_gate::emit_feature_err( + feature_gate::feature_err( &self.sess.parse_sess, sym::lint_reasons, item.span, - feature_gate::GateIssue::Language, "lint reasons are experimental" - ); + ) + .emit(); } reason = Some(rationale); } else { diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 411a47423c5..54aafe2114d 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -13,11 +13,12 @@ use crate::ty::query::Providers; use crate::middle::privacy::AccessLevels; use crate::session::{DiagnosticMessageId, Session}; use errors::DiagnosticBuilder; +use rustc_feature::GateIssue; use syntax::symbol::{Symbol, sym}; use syntax_pos::{Span, MultiSpan}; use syntax::ast::{Attribute, CRATE_NODE_ID}; use syntax::errors::Applicability; -use syntax::feature_gate::{GateIssue, emit_feature_err}; +use syntax::feature_gate::{feature_err, feature_err_issue}; use syntax::attr::{self, Stability, Deprecation, RustcDeprecation}; use crate::ty::{self, TyCtxt}; use crate::util::nodemap::{FxHashSet, FxHashMap}; @@ -512,9 +513,8 @@ pub fn report_unstable( if is_soft { soft_handler(lint::builtin::SOFT_UNSTABLE, span, &msg) } else { - emit_feature_err( - &sess.parse_sess, feature, span, GateIssue::Library(issue), &msg - ); + feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg) + .emit(); } } } @@ -842,15 +842,19 @@ impl Visitor<'tcx> for Checker<'tcx> { let ty = self.tcx.type_of(def_id); if adt_def.has_dtor(self.tcx) { - emit_feature_err(&self.tcx.sess.parse_sess, - sym::untagged_unions, item.span, GateIssue::Language, - "unions with `Drop` implementations are unstable"); + feature_err( + &self.tcx.sess.parse_sess, sym::untagged_unions, item.span, + "unions with `Drop` implementations are unstable" + ) + .emit(); } else { let param_env = self.tcx.param_env(def_id); if !param_env.can_type_implement_copy(self.tcx, ty).is_ok() { - emit_feature_err(&self.tcx.sess.parse_sess, - sym::untagged_unions, item.span, GateIssue::Language, - "unions with non-`Copy` fields are unstable"); + feature_err( + &self.tcx.sess.parse_sess, sym::untagged_unions, item.span, + "unions with non-`Copy` fields are unstable" + ) + .emit(); } } } diff --git a/src/librustc_feature/lib.rs b/src/librustc_feature/lib.rs index 82e60889316..c38bb3740af 100644 --- a/src/librustc_feature/lib.rs +++ b/src/librustc_feature/lib.rs @@ -49,8 +49,7 @@ pub struct Feature { } impl Feature { - // FIXME(Centril): privatize again. - pub fn issue(&self) -> Option { + fn issue(&self) -> Option { self.issue.and_then(|i| NonZeroU32::new(i)) } } @@ -97,6 +96,37 @@ impl UnstableFeatures { } } +fn find_lang_feature_issue(feature: Symbol) -> Option { + if let Some(info) = ACTIVE_FEATURES.iter().find(|t| t.name == feature) { + // FIXME (#28244): enforce that active features have issue numbers + // assert!(info.issue().is_some()) + info.issue() + } else { + // search in Accepted, Removed, or Stable Removed features + let found = ACCEPTED_FEATURES + .iter() + .chain(REMOVED_FEATURES) + .chain(STABLE_REMOVED_FEATURES) + .find(|t| t.name == feature); + match found { + Some(found) => found.issue(), + None => panic!("feature `{}` is not declared anywhere", feature), + } + } +} + +pub enum GateIssue { + Language, + Library(Option) +} + +pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option { + match issue { + GateIssue::Language => find_lang_feature_issue(feature), + GateIssue::Library(lib) => lib, + } +} + pub use accepted::ACCEPTED_FEATURES; pub use active::{ACTIVE_FEATURES, Features, INCOMPLETE_FEATURES}; pub use removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index e577b238c86..425e5d1d821 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -7,7 +7,7 @@ use rustc::util::nodemap::FxHashSet; use rustc_target::spec::abi::Abi; use syntax::attr; use syntax::source_map::Span; -use syntax::feature_gate::{self, GateIssue}; +use syntax::feature_gate::feature_err; use syntax::symbol::{kw, sym, Symbol}; use syntax::{span_err, struct_span_err}; @@ -158,27 +158,29 @@ impl Collector<'tcx> { } } if lib.cfg.is_some() && !self.tcx.features().link_cfg { - feature_gate::emit_feature_err(&self.tcx.sess.parse_sess, - sym::link_cfg, - span.unwrap(), - GateIssue::Language, - "is unstable"); + feature_err(&self.tcx.sess.parse_sess, sym::link_cfg, span.unwrap(), "is unstable") + .emit(); } if lib.kind == cstore::NativeStaticNobundle && - !self.tcx.features().static_nobundle { - feature_gate::emit_feature_err(&self.tcx.sess.parse_sess, - sym::static_nobundle, - span.unwrap_or_else(|| syntax_pos::DUMMY_SP), - GateIssue::Language, - "kind=\"static-nobundle\" is unstable"); + !self.tcx.features().static_nobundle + { + feature_err( + &self.tcx.sess.parse_sess, + sym::static_nobundle, + span.unwrap_or_else(|| syntax_pos::DUMMY_SP), + "kind=\"static-nobundle\" is unstable" + ) + .emit(); } if lib.kind == cstore::NativeRawDylib && !self.tcx.features().raw_dylib { - feature_gate::emit_feature_err(&self.tcx.sess.parse_sess, - sym::raw_dylib, - span.unwrap_or_else(|| syntax_pos::DUMMY_SP), - GateIssue::Language, - "kind=\"raw-dylib\" is unstable"); + feature_err( + &self.tcx.sess.parse_sess, + sym::raw_dylib, + span.unwrap_or_else(|| syntax_pos::DUMMY_SP), + "kind=\"raw-dylib\" is unstable" + ) + .emit(); } self.libs.push(lib); } diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs index acad56be604..a4f12a4e54f 100644 --- a/src/librustc_mir/transform/check_consts/ops.rs +++ b/src/librustc_mir/transform/check_consts/ops.rs @@ -4,7 +4,7 @@ use rustc::hir::def_id::DefId; use rustc::mir::BorrowKind; use rustc::session::config::nightly_options; use rustc::ty::TyCtxt; -use syntax::feature_gate::{emit_feature_err, GateIssue}; +use syntax::feature_gate::feature_err; use syntax::symbol::sym; use syntax_pos::{Span, Symbol}; @@ -222,13 +222,13 @@ impl NonConstOp for Panic { } fn emit_error(&self, item: &Item<'_, '_>, span: Span) { - emit_feature_err( + feature_err( &item.tcx.sess.parse_sess, sym::const_panic, span, - GateIssue::Language, &format!("panicking in {}s is unstable", item.const_kind()), - ); + ) + .emit(); } } @@ -240,13 +240,13 @@ impl NonConstOp for RawPtrComparison { } fn emit_error(&self, item: &Item<'_, '_>, span: Span) { - emit_feature_err( + feature_err( &item.tcx.sess.parse_sess, sym::const_compare_raw_pointers, span, - GateIssue::Language, &format!("comparing raw pointers inside {}", item.const_kind()), - ); + ) + .emit(); } } @@ -258,14 +258,14 @@ impl NonConstOp for RawPtrDeref { } fn emit_error(&self, item: &Item<'_, '_>, span: Span) { - emit_feature_err( - &item.tcx.sess.parse_sess, sym::const_raw_ptr_deref, - span, GateIssue::Language, + feature_err( + &item.tcx.sess.parse_sess, sym::const_raw_ptr_deref, span, &format!( "dereferencing raw pointers in {}s is unstable", item.const_kind(), ), - ); + ) + .emit(); } } @@ -277,14 +277,14 @@ impl NonConstOp for RawPtrToIntCast { } fn emit_error(&self, item: &Item<'_, '_>, span: Span) { - emit_feature_err( - &item.tcx.sess.parse_sess, sym::const_raw_ptr_to_usize_cast, - span, GateIssue::Language, + feature_err( + &item.tcx.sess.parse_sess, sym::const_raw_ptr_to_usize_cast, span, &format!( "casting pointers to integers in {}s is unstable", item.const_kind(), ), - ); + ) + .emit(); } } @@ -334,11 +334,11 @@ impl NonConstOp for Transmute { } fn emit_error(&self, item: &Item<'_, '_>, span: Span) { - emit_feature_err( - &item.tcx.sess.parse_sess, sym::const_transmute, - span, GateIssue::Language, - &format!("The use of std::mem::transmute() \ - is gated in {}s", item.const_kind())); + feature_err( + &item.tcx.sess.parse_sess, sym::const_transmute, span, + &format!("The use of std::mem::transmute() is gated in {}s", item.const_kind()) + ) + .emit(); } } @@ -355,10 +355,10 @@ impl NonConstOp for UnionAccess { } fn emit_error(&self, item: &Item<'_, '_>, span: Span) { - emit_feature_err( - &item.tcx.sess.parse_sess, sym::const_fn_union, - span, GateIssue::Language, + feature_err( + &item.tcx.sess.parse_sess, sym::const_fn_union, span, "unions in const fn are unstable", - ); + ) + .emit(); } } diff --git a/src/librustc_parse/config.rs b/src/librustc_parse/config.rs index dde320aed21..6293858ed4e 100644 --- a/src/librustc_parse/config.rs +++ b/src/librustc_parse/config.rs @@ -11,7 +11,7 @@ use crate::validate_attr; use rustc_feature::Features; use syntax::attr::HasAttrs; -use syntax::feature_gate::{feature_err, get_features, GateIssue}; +use syntax::feature_gate::{feature_err, get_features}; use syntax::attr; use syntax::ast; use syntax::edition::Edition; @@ -212,7 +212,6 @@ impl<'a> StripUnconfigured<'a> { let mut err = feature_err(self.sess, sym::stmt_expr_attributes, attr.span, - GateIssue::Language, "attributes on expressions are experimental"); if attr.is_doc_comment() { diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index 697a3ae873c..63c6e60de79 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -15,7 +15,7 @@ use rustc::ty::TyCtxt; use rustc::ty::query::Providers; use rustc_feature::Features; use syntax::ast::Mutability; -use syntax::feature_gate::{emit_feature_err, GateIssue}; +use syntax::feature_gate::feature_err; use syntax::span_err; use syntax_pos::{sym, Span}; use rustc_error_codes::*; @@ -141,13 +141,7 @@ impl<'tcx> CheckConstVisitor<'tcx> { | NonConstExpr::Match(hir::MatchSource::Normal) | NonConstExpr::Match(hir::MatchSource::IfDesugar { .. }) | NonConstExpr::Match(hir::MatchSource::IfLetDesugar { .. }) - => emit_feature_err( - &self.tcx.sess.parse_sess, - sym::const_if_match, - span, - GateIssue::Language, - &msg - ), + => feature_err(&self.tcx.sess.parse_sess, sym::const_if_match, span, &msg).emit(), _ => span_err!(self.tcx.sess, span, E0744, "{}", msg), } diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index cc5bc2b41dc..9e7098da49f 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -16,7 +16,7 @@ use rustc_feature::is_builtin_attr_name; use syntax::ast::{self, NodeId, Ident}; use syntax::attr::{self, StabilityLevel}; use syntax::edition::Edition; -use syntax::feature_gate::{emit_feature_err, GateIssue}; +use syntax::feature_gate::feature_err; use syntax::print::pprust; use syntax_expand::base::{self, InvocationRes, Indeterminate}; use syntax_expand::base::SyntaxExtension; @@ -346,13 +346,8 @@ impl<'a> Resolver<'a> { segment.ident.as_str().starts_with("rustc") { let msg = "attributes starting with `rustc` are reserved for use by the `rustc` compiler"; - emit_feature_err( - &self.session.parse_sess, - sym::rustc_attrs, - segment.ident.span, - GateIssue::Language, - msg, - ); + feature_err(&self.session.parse_sess, sym::rustc_attrs, segment.ident.span, msg) + .emit(); } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index a33b2e32c86..dafb89badd7 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -23,7 +23,7 @@ use crate::require_c_abi_if_c_variadic; use smallvec::SmallVec; use syntax::ast; use syntax::errors::pluralize; -use syntax::feature_gate::{GateIssue, emit_feature_err}; +use syntax::feature_gate::feature_err; use syntax::util::lev_distance::find_best_match_for_name; use syntax::symbol::sym; use syntax_pos::{DUMMY_SP, Span, MultiSpan}; @@ -914,8 +914,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } else { "parenthetical notation is only stable when used with `Fn`-family traits" }; - emit_feature_err(&self.tcx().sess.parse_sess, sym::unboxed_closures, - span, GateIssue::Language, msg); + feature_err(&self.tcx().sess.parse_sess, sym::unboxed_closures, span, msg).emit(); } self.create_substs_for_ast_path(span, diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 593f8e74ba9..901a2192e20 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -644,13 +644,13 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } if has_unsized_tuple_coercion && !self.tcx.features().unsized_tuple_coercion { - feature_gate::emit_feature_err( + feature_gate::feature_err( &self.tcx.sess.parse_sess, sym::unsized_tuple_coercion, self.cause.span, - feature_gate::GateIssue::Language, "unsized tuple coercion is not stable enough for use and is subject to change", - ); + ) + .emit(); } Ok(coercion) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 930241262b0..84607fb6c81 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -125,7 +125,7 @@ use syntax_pos::{self, BytePos, Span, MultiSpan}; use syntax_pos::hygiene::DesugaringKind; use syntax::ast; use syntax::attr; -use syntax::feature_gate::{GateIssue, emit_feature_err}; +use syntax::feature_gate::feature_err; use syntax::source_map::{DUMMY_SP, original_sp}; use syntax::symbol::{kw, sym, Ident}; use syntax::util::parser::ExprPrecedence; @@ -2373,13 +2373,13 @@ fn check_transparent(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) { if adt.is_enum() { if !tcx.features().transparent_enums { - emit_feature_err( + feature_err( &tcx.sess.parse_sess, sym::transparent_enums, sp, - GateIssue::Language, "transparent enums are unstable", - ); + ) + .emit(); } if adt.variants.len() != 1 { bad_variant_count(tcx, adt, sp, def_id); @@ -2391,11 +2391,13 @@ fn check_transparent(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) { } if adt.is_union() && !tcx.features().transparent_unions { - emit_feature_err(&tcx.sess.parse_sess, - sym::transparent_unions, - sp, - GateIssue::Language, - "transparent unions are unstable"); + feature_err( + &tcx.sess.parse_sess, + sym::transparent_unions, + sp, + "transparent unions are unstable", + ) + .emit(); } // For each field, figure out if it's known to be a ZST and align(1) @@ -2452,11 +2454,13 @@ pub fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, vs: &'tcx [hir::Variant], i let repr_type_ty = def.repr.discr_type().to_ty(tcx); if repr_type_ty == tcx.types.i128 || repr_type_ty == tcx.types.u128 { if !tcx.features().repr128 { - emit_feature_err(&tcx.sess.parse_sess, - sym::repr128, - sp, - GateIssue::Language, - "repr with 128-bit type is unstable"); + feature_err( + &tcx.sess.parse_sess, + sym::repr128, + sp, + "repr with 128-bit type is unstable", + ) + .emit(); } } diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index b491b103313..20b6b01de57 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -10,7 +10,7 @@ use rustc::middle::lang_items; use rustc::infer::opaque_types::may_define_opaque_type; use syntax::ast; -use syntax::feature_gate::{self, GateIssue}; +use syntax::feature_gate; use syntax_pos::Span; use syntax::symbol::sym; use errors::DiagnosticBuilder; @@ -830,13 +830,13 @@ fn check_method_receiver<'fcx, 'tcx>( &fcx.tcx.sess.parse_sess, sym::arbitrary_self_types, span, - GateIssue::Language, &format!( "`{}` cannot be used as the type of `self` without \ the `arbitrary_self_types` feature", receiver_ty, ), - ).help(HELP_FOR_SELF_TYPE) + ) + .help(HELP_FOR_SELF_TYPE) .emit(); } else { // Report error; would not have worked with `arbitrary_self_types`. diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 652f081e176..ab9845c89f5 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1494,16 +1494,16 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { _ => None, }; if let Some(unsupported_type) = err { - feature_gate::emit_feature_err( + feature_gate::feature_err( &tcx.sess.parse_sess, sym::const_compare_raw_pointers, hir_ty.span, - feature_gate::GateIssue::Language, &format!( "using {} as const generic parameters is unstable", unsupported_type ), - ); + ) + .emit(); }; } if ty::search_for_structural_match_violation( @@ -2522,13 +2522,13 @@ fn from_target_feature( None => true, }; if !allowed && id.is_local() { - feature_gate::emit_feature_err( + feature_gate::feature_err( &tcx.sess.parse_sess, feature_gate.unwrap(), item.span(), - feature_gate::GateIssue::Language, &format!("the target feature `{}` is currently unstable", feature), - ); + ) + .emit(); } Some(Symbol::intern(feature)) })); diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index bbcb8cc3c62..3c10f27b60a 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -2,7 +2,7 @@ use super::{mark_used, MetaItemKind}; use crate::ast::{self, Attribute, MetaItem, NestedMetaItem}; -use crate::feature_gate::{emit_feature_err, GateIssue}; +use crate::feature_gate::feature_err; use crate::print::pprust; use crate::sess::ParseSess; @@ -569,7 +569,7 @@ fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &ParseSess, features: &F let (cfg, feature, has_feature) = gated_cfg; if !has_feature(features) && !cfg_span.allows_unstable(*feature) { let explain = format!("`cfg({})` is experimental and subject to change", cfg); - emit_feature_err(sess, *feature, cfg_span, GateIssue::Language, &explain); + feature_err(sess, *feature, cfg_span, &explain).emit() } } diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index ea0eff1eed9..c90f4c6f19f 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -1,6 +1,7 @@ use rustc_feature::{ACCEPTED_FEATURES, ACTIVE_FEATURES, REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP}; use rustc_feature::{Features, Feature, State as FeatureState, UnstableFeatures}; +use rustc_feature::{find_feature_issue, GateIssue}; use crate::ast::{self, AssocTyConstraint, AssocTyConstraintKind, NodeId}; use crate::ast::{GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData}; @@ -18,8 +19,6 @@ use log::debug; use rustc_error_codes::*; -use std::num::NonZeroU32; - macro_rules! gate_feature_fn { ($cx: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr, $level: expr) => {{ let (cx, has_feature, span, @@ -48,30 +47,6 @@ pub fn check_attribute(attr: &ast::Attribute, parse_sess: &ParseSess, features: PostExpansionVisitor { parse_sess, features }.visit_attribute(attr) } -fn find_lang_feature_issue(feature: Symbol) -> Option { - if let Some(info) = ACTIVE_FEATURES.iter().find(|t| t.name == feature) { - // FIXME (#28244): enforce that active features have issue numbers - // assert!(info.issue().is_some()) - info.issue() - } else { - // search in Accepted, Removed, or Stable Removed features - let found = ACCEPTED_FEATURES - .iter() - .chain(REMOVED_FEATURES) - .chain(STABLE_REMOVED_FEATURES) - .find(|t| t.name == feature); - match found { - Some(found) => found.issue(), - None => panic!("feature `{}` is not declared anywhere", feature), - } - } -} - -pub enum GateIssue { - Language, - Library(Option) -} - #[derive(Debug, Copy, Clone, PartialEq)] pub enum GateStrength { /// A hard error. (Most feature gates should use this.) @@ -80,41 +55,35 @@ pub enum GateStrength { Soft, } -pub fn emit_feature_err( - sess: &ParseSess, +pub fn feature_err<'a>( + sess: &'a ParseSess, feature: Symbol, - span: Span, - issue: GateIssue, + span: impl Into, explain: &str, -) { - feature_err(sess, feature, span, issue, explain).emit(); +) -> DiagnosticBuilder<'a> { + feature_err_issue(sess, feature, span, GateIssue::Language, explain) } -pub fn feature_err<'a, S: Into>( +pub fn feature_err_issue<'a>( sess: &'a ParseSess, feature: Symbol, - span: S, + span: impl Into, issue: GateIssue, explain: &str, ) -> DiagnosticBuilder<'a> { leveled_feature_err(sess, feature, span, issue, explain, GateStrength::Hard) } -fn leveled_feature_err<'a, S: Into>( +fn leveled_feature_err<'a>( sess: &'a ParseSess, feature: Symbol, - span: S, + span: impl Into, issue: GateIssue, explain: &str, level: GateStrength, ) -> DiagnosticBuilder<'a> { let diag = &sess.span_diagnostic; - let issue = match issue { - GateIssue::Language => find_lang_feature_issue(feature), - GateIssue::Library(lib) => lib, - }; - let mut err = match level { GateStrength::Hard => { diag.struct_span_err_with_code(span, explain, stringify_error_code!(E0658)) @@ -122,7 +91,7 @@ fn leveled_feature_err<'a, S: Into>( GateStrength::Soft => diag.struct_span_warn(span, explain), }; - if let Some(n) = issue { + if let Some(n) = find_feature_issue(feature, issue) { err.note(&format!( "for more information, see https://github.com/rust-lang/rust/issues/{}", n, @@ -257,7 +226,6 @@ impl<'a> PostExpansionVisitor<'a> { self.parse_sess, sym::arbitrary_enum_discriminant, discriminant_spans.clone(), - crate::feature_gate::GateIssue::Language, "custom discriminant values are not allowed in enums with tuple or struct variants", ); for sp in discriminant_spans { diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index c2d887c9267..3d4a5d624c1 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -94,10 +94,7 @@ pub use syntax_pos::source_map; pub mod entry; pub mod feature_gate { mod check; - pub use check::{ - check_crate, check_attribute, get_features, feature_err, emit_feature_err, - GateIssue, - }; + pub use check::{check_crate, check_attribute, get_features, feature_err, feature_err_issue}; } pub mod mut_visit; pub mod ptr; diff --git a/src/libsyntax_expand/expand.rs b/src/libsyntax_expand/expand.rs index e4c4f4c43e6..a6ced1439c5 100644 --- a/src/libsyntax_expand/expand.rs +++ b/src/libsyntax_expand/expand.rs @@ -14,7 +14,7 @@ use syntax::ast::{self, AttrItem, Block, Ident, LitKind, NodeId, PatKind, Path}; use syntax::ast::{MacStmtStyle, StmtKind, ItemKind}; use syntax::attr::{self, HasAttrs, is_builtin_attr}; use syntax::source_map::respan; -use syntax::feature_gate::{self, GateIssue, emit_feature_err}; +use syntax::feature_gate::{self, feature_err}; use syntax::mut_visit::*; use syntax::print::pprust; use syntax::ptr::P; @@ -727,13 +727,13 @@ impl<'a, 'b> MacroExpander<'a, 'b> { if self.cx.ecfg.proc_macro_hygiene() { return } - emit_feature_err( + feature_err( self.cx.parse_sess, sym::proc_macro_hygiene, span, - GateIssue::Language, &format!("custom attributes cannot be applied to {}", kind), - ); + ) + .emit(); } fn gate_proc_macro_input(&self, annotatable: &Annotatable) { @@ -745,13 +745,13 @@ impl<'a, 'b> MacroExpander<'a, 'b> { fn visit_item(&mut self, item: &'ast ast::Item) { match &item.kind { ast::ItemKind::Mod(module) if !module.inline => { - emit_feature_err( + feature_err( self.parse_sess, sym::proc_macro_hygiene, item.span, - GateIssue::Language, "non-inline modules in proc macro input are unstable", - ); + ) + .emit(); } _ => {} } @@ -790,13 +790,13 @@ impl<'a, 'b> MacroExpander<'a, 'b> { if self.cx.ecfg.proc_macro_hygiene() { return } - emit_feature_err( + feature_err( self.cx.parse_sess, sym::proc_macro_hygiene, span, - GateIssue::Language, &format!("procedural macros cannot be expanded to {}", kind), - ); + ) + .emit(); } fn parse_ast_fragment( @@ -992,9 +992,11 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { if let Some(attr) = &attr { if !self.cx.ecfg.custom_inner_attributes() && attr.style == ast::AttrStyle::Inner && !attr.has_name(sym::test) { - emit_feature_err(&self.cx.parse_sess, sym::custom_inner_attributes, - attr.span, GateIssue::Language, - "non-builtin inner attributes are unstable"); + feature_err( + &self.cx.parse_sess, sym::custom_inner_attributes, attr.span, + "non-builtin inner attributes are unstable" + ) + .emit(); } } attr -- cgit 1.4.1-3-g733a5 From ded177a06a1cde44ab64dcd09c63f6c2b815a9fe Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 07:44:01 +0100 Subject: derive(Default) for Features --- src/librustc_feature/active.rs | 14 ++------------ src/librustc_parse/config.rs | 2 +- src/libsyntax/feature_gate/check.rs | 2 +- 3 files changed, 4 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs index fc1f770e226..7c0d39965fc 100644 --- a/src/librustc_feature/active.rs +++ b/src/librustc_feature/active.rs @@ -36,7 +36,7 @@ macro_rules! declare_features { ),+]; /// A set of features to be used by later passes. - #[derive(Clone)] + #[derive(Clone, Default)] pub struct Features { /// `#![feature]` attrs for language features, for error reporting. pub declared_lang_features: Vec<(Symbol, Span, Option)>, @@ -49,17 +49,7 @@ macro_rules! declare_features { } impl Features { - pub fn new() -> Features { - Features { - declared_lang_features: Vec::new(), - declared_lib_features: Vec::new(), - $($feature: false),+ - } - } - - pub fn walk_feature_fields(&self, mut f: F) - where F: FnMut(&str, bool) - { + pub fn walk_feature_fields(&self, mut f: impl FnMut(&str, bool)) { $(f(stringify!($feature), self.$feature);)+ } } diff --git a/src/librustc_parse/config.rs b/src/librustc_parse/config.rs index 6293858ed4e..26e51e83d62 100644 --- a/src/librustc_parse/config.rs +++ b/src/librustc_parse/config.rs @@ -47,7 +47,7 @@ pub fn features(mut krate: ast::Crate, sess: &ParseSess, edition: Edition, } else { // the entire crate is unconfigured krate.attrs = Vec::new(); krate.module.items = Vec::new(); - return (krate, Features::new()); + return (krate, Features::default()); } features = get_features(&sess.span_diagnostic, &krate.attrs, edition, allow_features); diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index c90f4c6f19f..3d2c3b1d4f9 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -641,7 +641,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], err.emit(); } - let mut features = Features::new(); + let mut features = Features::default(); let mut edition_enabled_features = FxHashMap::default(); for &edition in ALL_EDITIONS { -- cgit 1.4.1-3-g733a5 From f34990e9b504ab5062d0dbd953d45bc382de0bc6 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 Nov 2019 23:15:45 -0800 Subject: Remove unneeded prelude imports in libcore tests These three lines are from c82da7a54b9efb1a0ccbe11de66c71f547bf7db9 in 2015. They cause problems when applying rustfmt to the codebase, because reordering wildcard imports can trigger new unused import warnings. As a minimized example, the following program compiles successfully: #![deny(unused_imports)] use std::fmt::Debug; use std::marker::Send; pub mod repro { use std::prelude::v1::*; use super::*; pub type D = dyn Debug; pub type S = dyn Send; } pub type S = dyn Send; but putting it through rustfmt produces a program that fails to compile: #![deny(unused_imports)] use std::fmt::Debug; use std::marker::Send; pub mod repro { use super::*; use std::prelude::v1::*; pub type D = dyn Debug; pub type S = dyn Send; } pub type S = dyn Send; The error is: error: unused import: `std::prelude::v1::*` --> src/main.rs:8:9 | 8 | use std::prelude::v1::*; | ^^^^^^^^^^^^^^^^^^^ --- src/libcore/tests/num/bignum.rs | 1 - src/libcore/tests/num/flt2dec/mod.rs | 1 - src/libcore/tests/num/flt2dec/strategy/dragon.rs | 1 - 3 files changed, 3 deletions(-) (limited to 'src') diff --git a/src/libcore/tests/num/bignum.rs b/src/libcore/tests/num/bignum.rs index b9e15ec5c07..50a3ec046ad 100644 --- a/src/libcore/tests/num/bignum.rs +++ b/src/libcore/tests/num/bignum.rs @@ -1,4 +1,3 @@ -use std::prelude::v1::*; use core::num::bignum::tests::Big8x3 as Big; #[test] diff --git a/src/libcore/tests/num/flt2dec/mod.rs b/src/libcore/tests/num/flt2dec/mod.rs index a35897e9bc1..f85369ce40b 100644 --- a/src/libcore/tests/num/flt2dec/mod.rs +++ b/src/libcore/tests/num/flt2dec/mod.rs @@ -1,4 +1,3 @@ -use std::prelude::v1::*; use std::{str, i16, f32, f64, fmt}; use core::num::flt2dec::{decode, DecodableFloat, FullDecoded, Decoded}; diff --git a/src/libcore/tests/num/flt2dec/strategy/dragon.rs b/src/libcore/tests/num/flt2dec/strategy/dragon.rs index dc4d78bfae1..0c545b4d887 100644 --- a/src/libcore/tests/num/flt2dec/strategy/dragon.rs +++ b/src/libcore/tests/num/flt2dec/strategy/dragon.rs @@ -1,4 +1,3 @@ -use std::prelude::v1::*; use super::super::*; use core::num::bignum::Big32x40 as Big; use core::num::flt2dec::strategy::dragon::*; -- cgit 1.4.1-3-g733a5 From 4843173a0015df5139866bffc3957c7782d8ccfe Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Sat, 30 Nov 2019 12:57:50 +0100 Subject: Document why as_mut_ptr is safe --- src/libcore/sync/atomic.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 5d6972bf75c..3a5b4135a91 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -809,6 +809,12 @@ impl AtomicBool { /// This method is mostly useful for FFI, where the function signature may use /// `*mut bool` instead of `&AtomicBool`. /// + /// Returning an `*mut` pointer from a shared reference to this atomic is safe because the + /// atomic types work with interior mutability. All modifications of an atomic change the value + /// through a shared reference, and can do so safely as long as they use atomic operations. Any + /// use of the returned raw pointer requires an `unsafe` block and still has to uphold the same + /// restriction: operations on it must be atomic. + /// /// [`bool`]: ../../../std/primitive.bool.html /// /// # Examples @@ -1929,6 +1935,12 @@ Doing non-atomic reads and writes on the resulting integer can be a data race. This method is mostly useful for FFI, where the function signature may use `*mut ", stringify!($int_type), "` instead of `&", stringify!($atomic_type), "`. +Returning an `*mut` pointer from a shared reference to this atomic is safe because the +atomic types work with interior mutability. All modifications of an atomic change the value +through a shared reference, and can do so safely as long as they use atomic operations. Any +use of the returned raw pointer requires an `unsafe` block and still has to uphold the same +restriction: operations on it must be atomic. + # Examples ```ignore (extern-declaration) -- cgit 1.4.1-3-g733a5 From d34090a10a6517f3e3ea8528936175953ce8bc3d Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Sat, 30 Nov 2019 12:58:15 +0100 Subject: Fill tracking issue --- src/libcore/sync/atomic.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 3a5b4135a91..9a910f35485 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -835,7 +835,7 @@ impl AtomicBool { #[inline] #[unstable(feature = "atomic_mut_ptr", reason = "recently added", - issue = "0")] + issue = "66893")] pub fn as_mut_ptr(&self) -> *mut bool { self.v.get() as *mut bool } @@ -1960,7 +1960,7 @@ unsafe { #[inline] #[unstable(feature = "atomic_mut_ptr", reason = "recently added", - issue = "0")] + issue = "66893")] pub fn as_mut_ptr(&self) -> *mut $int_type { self.v.get() } -- cgit 1.4.1-3-g733a5 From 0f4c5fb20cf5d499bc3d6426b1909863f1c86a5b Mon Sep 17 00:00:00 2001 From: Nadrieril Feneanar Date: Sat, 30 Nov 2019 13:35:46 +0000 Subject: Apply suggestions from code review Co-Authored-By: varkor --- src/librustc_mir/hair/pattern/_match.rs | 4 ++-- src/test/ui/or-patterns/exhaustiveness-pass.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 2e339b1eb88..d54f6b03cdd 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -1838,7 +1838,7 @@ fn pat_constructor<'tcx>( if slice.is_some() { VarLen(prefix, suffix) } else { FixedLen(prefix + suffix) }; Some(Slice(Slice { array_len, kind })) } - PatKind::Or { .. } => bug!("Or-pattern hould have been expanded earlier on."), + PatKind::Or { .. } => bug!("Or-pattern should have been expanded earlier on."), } } @@ -2444,7 +2444,7 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>( _ => span_bug!(pat.span, "unexpected ctor {:?} for slice pat", constructor), }, - PatKind::Or { .. } => bug!("Or-pattern hould have been expanded earlier on."), + PatKind::Or { .. } => bug!("Or-pattern should have been expanded earlier on."), }; debug!("specialize({:#?}, {:#?}) = {:#?}", pat, ctor_wild_subpatterns, result); diff --git a/src/test/ui/or-patterns/exhaustiveness-pass.rs b/src/test/ui/or-patterns/exhaustiveness-pass.rs index a29cc7253ad..62a851719f9 100644 --- a/src/test/ui/or-patterns/exhaustiveness-pass.rs +++ b/src/test/ui/or-patterns/exhaustiveness-pass.rs @@ -17,7 +17,7 @@ fn main() { } match (0u8,) { - (1 | 1,) => {} // redundancy not detected for now + (1 | 1,) => {} // FIXME(or_patterns): redundancy not detected for now. _ => {} } match (0u8, 0u8) { -- cgit 1.4.1-3-g733a5