From 46e9212ecb0454d1d5cc9c4d641f4277512111c8 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Thu, 17 Dec 2020 16:56:59 +0100 Subject: [PATCH 1/6] Change the message for `if_let_guard` feature gate --- compiler/rustc_ast_passes/src/feature_gate.rs | 2 +- src/test/ui/rfc-2294-if-let-guard/feature-gate.rs | 4 ++-- src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 9d54d89e080f5..bb222675239aa 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -620,7 +620,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) { } }; } - gate_all!(if_let_guard, "`if let` guard is not implemented"); + gate_all!(if_let_guard, "`if let` guards are experimental"); gate_all!(let_chains, "`let` expressions in this position are experimental"); gate_all!(async_closure, "async closures are unstable"); gate_all!(generators, "yield syntax is experimental"); diff --git a/src/test/ui/rfc-2294-if-let-guard/feature-gate.rs b/src/test/ui/rfc-2294-if-let-guard/feature-gate.rs index 311d1afcfc0ee..4ba7e1eeefaa6 100644 --- a/src/test/ui/rfc-2294-if-let-guard/feature-gate.rs +++ b/src/test/ui/rfc-2294-if-let-guard/feature-gate.rs @@ -5,7 +5,7 @@ use std::ops::Range; fn _if_let_guard() { match () { () if let 0 = 1 => {} - //~^ ERROR `if let` guard is not implemented + //~^ ERROR `if let` guards are experimental () if (let 0 = 1) => {} //~^ ERROR `let` expressions in this position are experimental @@ -74,7 +74,7 @@ fn _macros() { match () { #[cfg(FALSE)] () if let 0 = 1 => {} - //~^ ERROR `if let` guard is not implemented + //~^ ERROR `if let` guards are experimental _ => {} } use_expr!(let 0 = 1); diff --git a/src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr b/src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr index 1670078e0d38b..113870c19f5d5 100644 --- a/src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr +++ b/src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr @@ -7,7 +7,7 @@ LL | macro_rules! use_expr { LL | use_expr!(let 0 = 1); | ^^^ no rules expected this token in macro call -error[E0658]: `if let` guard is not implemented +error[E0658]: `if let` guards are experimental --> $DIR/feature-gate.rs:7:12 | LL | () if let 0 = 1 => {} @@ -16,7 +16,7 @@ LL | () if let 0 = 1 => {} = note: see issue #51114 for more information = help: add `#![feature(if_let_guard)]` to the crate attributes to enable -error[E0658]: `if let` guard is not implemented +error[E0658]: `if let` guards are experimental --> $DIR/feature-gate.rs:76:12 | LL | () if let 0 = 1 => {} From 54cce72da5b0505e1c617d4359bfe45c3235908a Mon Sep 17 00:00:00 2001 From: pierwill <19642016+pierwill@users.noreply.github.com> Date: Thu, 17 Dec 2020 12:02:34 -0800 Subject: [PATCH 2/6] docs: Edit rustc_span::symbol::Symbol method Edit wording of the doc comment for rustc_span::symbol::Symbol::can_be_raw to match related methods. --- compiler/rustc_span/src/symbol.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index f61a32a0f790e..9e08e540caa61 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1632,7 +1632,7 @@ impl Symbol { self == kw::True || self == kw::False } - /// This symbol can be a raw identifier. + /// Returns `true` if this symbol can be a raw identifier. pub fn can_be_raw(self) -> bool { self != kw::Invalid && self != kw::Underscore && !self.is_path_segment_keyword() } From d6f1787447e1132d929efbb5b772be232e336c23 Mon Sep 17 00:00:00 2001 From: Camelid Date: Thu, 17 Dec 2020 13:51:20 -0800 Subject: [PATCH 3/6] Don't allow `const` to begin a nonterminal Thanks to Vadim Petrochenkov who [told me what the fix was][z]! [z]: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/finding.20which.20macro.20rule.20to.20use/near/220240422 --- .../rustc_parse/src/parser/nonterminal.rs | 2 ++ src/test/ui/inline-const/macro-with-const.rs | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/test/ui/inline-const/macro-with-const.rs diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index c007f96a79800..76ad5acd5303e 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -27,6 +27,8 @@ impl<'a> Parser<'a> { token.can_begin_expr() // This exception is here for backwards compatibility. && !token.is_keyword(kw::Let) + // This exception is here for backwards compatibility. + && !token.is_keyword(kw::Const) } NonterminalKind::Ty => token.can_begin_type(), NonterminalKind::Ident => get_macro_ident(token).is_some(), diff --git a/src/test/ui/inline-const/macro-with-const.rs b/src/test/ui/inline-const/macro-with-const.rs new file mode 100644 index 0000000000000..e7393166d8df3 --- /dev/null +++ b/src/test/ui/inline-const/macro-with-const.rs @@ -0,0 +1,20 @@ +// check-pass + +macro_rules! exp { + (const $n:expr) => { + $n + }; +} + +macro_rules! stmt { + (exp $e:expr) => { + $e + }; + (exp $($t:tt)+) => { + exp!($($t)+) + }; +} + +fn main() { + stmt!(exp const 1); +} From 605c97864183894339aae983518cf1e8a8fc0116 Mon Sep 17 00:00:00 2001 From: pierwill <19642016+pierwill@users.noreply.github.com> Date: Thu, 17 Dec 2020 20:47:05 -0800 Subject: [PATCH 4/6] Fix typo in rustc_typeck docs --- compiler/rustc_typeck/src/check/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index d27a68ccf1bda..8177b363a5a5b 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -270,7 +270,7 @@ fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option { /// If this `DefId` is a "primary tables entry", returns /// `Some((body_id, header, decl))` with information about -/// it's body-id, fn-header and fn-decl (if any). Otherwise, +/// its body-id, fn-header and fn-decl (if any). Otherwise, /// returns `None`. /// /// If this function returns `Some`, then `typeck_results(def_id)` will From ea338f544395c44dba171ae9f01fe55cb0cc8200 Mon Sep 17 00:00:00 2001 From: pierwill Date: Thu, 17 Dec 2020 21:17:43 -0800 Subject: [PATCH 5/6] Edit formatting in Rust Prelude docs Use consistent punctuation and capitalization in the list of things re-exported in the prelude. Also adds a (possibly missing) word. --- library/std/src/prelude/mod.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/library/std/src/prelude/mod.rs b/library/std/src/prelude/mod.rs index c7a7c779d3c57..a3776681d0349 100644 --- a/library/std/src/prelude/mod.rs +++ b/library/std/src/prelude/mod.rs @@ -26,38 +26,37 @@ //! # Prelude contents //! //! The current version of the prelude (version 1) lives in -//! [`std::prelude::v1`], and re-exports the following. +//! [`std::prelude::v1`], and re-exports the following: //! -//! * [`std::marker`]::{[`Copy`], [`Send`], [`Sized`], [`Sync`], [`Unpin`]}. The -//! marker traits indicate fundamental properties of types. -//! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}. Various +//! * [`std::marker`]::{[`Copy`], [`Send`], [`Sized`], [`Sync`], [`Unpin`]}, +//! marker traits that indicate fundamental properties of types. +//! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}, various //! operations for both destructors and overloading `()`. //! * [`std::mem`]::[`drop`][`mem::drop`], a convenience function for explicitly //! dropping a value. //! * [`std::boxed`]::[`Box`], a way to allocate values on the heap. -//! * [`std::borrow`]::[`ToOwned`], The conversion trait that defines +//! * [`std::borrow`]::[`ToOwned`], the conversion trait that defines //! [`to_owned`], the generic method for creating an owned type from a //! borrowed type. //! * [`std::clone`]::[`Clone`], the ubiquitous trait that defines //! [`clone`][`Clone::clone`], the method for producing a copy of a value. -//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`] }. The +//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`] }, the //! comparison traits, which implement the comparison operators and are often //! seen in trait bounds. -//! * [`std::convert`]::{[`AsRef`], [`AsMut`], [`Into`], [`From`]}. Generic +//! * [`std::convert`]::{[`AsRef`], [`AsMut`], [`Into`], [`From`]}, generic //! conversions, used by savvy API authors to create overloaded methods. //! * [`std::default`]::[`Default`], types that have default values. -//! * [`std::iter`]::{[`Iterator`], [`Extend`], [`IntoIterator`], -//! [`DoubleEndedIterator`], [`ExactSizeIterator`]}. Iterators of various +//! * [`std::iter`]::{[`Iterator`], [`Extend`], [`IntoIterator`] +//! [`DoubleEndedIterator`], [`ExactSizeIterator`]}, iterators of various //! kinds. -//! * [`std::option`]::[`Option`]::{[`self`][`Option`], [`Some`], [`None`]}. A +//! * [`std::option`]::[`Option`]::{[`self`][`Option`], [`Some`], [`None`]}, a //! type which expresses the presence or absence of a value. This type is so //! commonly used, its variants are also exported. -//! * [`std::result`]::[`Result`]::{[`self`][`Result`], [`Ok`], [`Err`]}. A type +//! * [`std::result`]::[`Result`]::{[`self`][`Result`], [`Ok`], [`Err`]}, a type //! for functions that may succeed or fail. Like [`Option`], its variants are //! exported as well. //! * [`std::string`]::{[`String`], [`ToString`]}, heap allocated strings. -//! * [`std::vec`]::[`Vec`], a growable, heap-allocated -//! vector. +//! * [`std::vec`]::[`Vec`], a growable, heap-allocated vector. //! //! [`mem::drop`]: crate::mem::drop //! [`std::borrow`]: crate::borrow From 9cb43bd9945e2c10a0641cf6c944b753fc02a38d Mon Sep 17 00:00:00 2001 From: pierwill <19642016+pierwill@users.noreply.github.com> Date: Thu, 17 Dec 2020 21:49:32 -0800 Subject: [PATCH 6/6] Add missing punctuation to std::alloc docs Add a period to first line of module docs to match other modules in std. --- library/std/src/alloc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index 819d57a934dc4..8491ff400335c 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -1,4 +1,4 @@ -//! Memory allocation APIs +//! Memory allocation APIs. //! //! In a given program, the standard library has one “global” memory allocator //! that is used for example by `Box` and `Vec`.