Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 14 pull requests #73744

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f03cf99
Add a fast path for `std::thread::panicking`.
eduardosm May 26, 2020
e85df08
Don't move cursor in search box when using arrows to navigate search …
carols10cents Jun 2, 2020
560a996
Implement slice_strip feature
tesuji Jun 16, 2020
8a816ca
Cleanup MinGW LLVM linkage workaround
mati865 Jun 19, 2020
9766a93
Document the mod keyword
poliorcetics Jun 22, 2020
3c46e36
Document the mut keyword
poliorcetics Jun 22, 2020
ef24faf
Refactor non_ascii_idents lints, exclude ascii pair for confusable_id…
crlf0710 May 10, 2020
86f6c0e
Record span of `const` kw in GenericParamKind
ayazhafiz Jun 21, 2020
9bb414f
Fix ptr doc warnings.
ehuss Jun 23, 2020
d8ea10c
Document the return keyword
poliorcetics Jun 24, 2020
d36d351
Implement intrinsic
doctorn Jun 23, 2020
c2dfc25
Fix tests
doctorn Jun 24, 2020
4931996
Fix tests
doctorn Jun 24, 2020
771a1d8
Make `std::panicking::panic_count::is_zero` inline and move the slow …
eduardosm Jun 24, 2020
520461f
Provide suggestions for some moved value errors
estebank Jun 20, 2020
3d09017
Add a compile fail example, binding -> variable, apply suggestions
poliorcetics Jun 25, 2020
eb6d9a4
Add E0766 error for unterminated double quote byte string
GuillaumeGomez Jun 21, 2020
33302fa
Update UI test
GuillaumeGomez Jun 21, 2020
25e864e
Implement mixed script confusable lint.
crlf0710 Jun 23, 2020
77b0ed7
proc_macro: Stop flattening groups with dummy spans
petrochenkov Jun 7, 2020
1fbd160
Rollup merge of #72617 - eduardosm:panicking, r=Amanieu
Manishearth Jun 26, 2020
887ce8e
Rollup merge of #72770 - crlf0710:mixed_script_confusable, r=Manishearth
Manishearth Jun 26, 2020
c6683a5
Rollup merge of #72967 - integer32llc:prevent-default-arrows, r=kinnison
Manishearth Jun 26, 2020
8c038b7
Rollup merge of #73102 - petrochenkov:flatgroup, r=Aaron1011
Manishearth Jun 26, 2020
082cdf9
Rollup merge of #73414 - lzutao:slice_strip, r=dtolnay
Manishearth Jun 26, 2020
839bcef
Rollup merge of #73418 - doctorn:variants-intrinsic, r=kennytm
Manishearth Jun 26, 2020
0b67c1f
Rollup merge of #73507 - mati865:cleanup-mingw-llvm-linkage, r=matthe…
Manishearth Jun 26, 2020
0aef6ff
Rollup merge of #73534 - estebank:borrowck-suggestions, r=matthewjasper
Manishearth Jun 26, 2020
3fc8f8e
Rollup merge of #73581 - GuillaumeGomez:add-0766, r=varkor
Manishearth Jun 26, 2020
bab4731
Rollup merge of #73597 - ayazhafiz:i/const-span, r=ecstatic-morse
Manishearth Jun 26, 2020
19f7805
Rollup merge of #73619 - poliorcetics:mod-keyword, r=steveklabnik
Manishearth Jun 26, 2020
2334b93
Rollup merge of #73621 - poliorcetics:mut-keyword, r=steveklabnik
Manishearth Jun 26, 2020
5d4e2e1
Rollup merge of #73648 - poliorcetics:return-keyword, r=joshtriplett
Manishearth Jun 26, 2020
57167a9
Rollup merge of #73673 - ehuss:fix-ptr-docs, r=oli-obk
Manishearth Jun 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5405,15 +5405,15 @@ dependencies = [

[[package]]
name = "unicode-script"
version = "0.4.0"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b2c5c29e805da6817f5af6a627d65adb045cebf05cccd5a3493d6109454391c"
checksum = "58b33414ea8db4b7ea0343548dbdc31d27aef06beacf7044a87e564d9b0feb7d"

[[package]]
name = "unicode-security"
version = "0.0.3"
version = "0.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5f9011bbed9c13372bc8df618b55a38138445199caf3b61d432c6859c36dee0"
checksum = "5d87c28edc5b263377e448d6cdcb935c06b95413d8013ba6fae470558ccab18f"
dependencies = [
"unicode-normalization",
"unicode-script",
Expand Down
15 changes: 15 additions & 0 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,15 @@ extern "rust-intrinsic" {
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;

/// Returns the number of variants of the type `T` cast to a `usize`;
/// if `T` has no variants, returns 0. Uninhabited variants will be counted.
///
/// The to-be-stabilized version of this intrinsic is
/// [`std::mem::variant_count`](../../std/mem/fn.variant_count.html)
#[rustc_const_unstable(feature = "variant_count", issue = "73662")]
#[cfg(not(bootstrap))]
pub fn variant_count<T>() -> usize;

/// Rust's "try catch" construct which invokes the function pointer `try_fn`
/// with the data pointer `data`.
///
Expand Down Expand Up @@ -1960,6 +1969,12 @@ extern "rust-intrinsic" {
pub fn ptr_guaranteed_ne<T>(ptr: *const T, other: *const T) -> bool;
}

#[rustc_const_unstable(feature = "variant_count", issue = "73662")]
#[cfg(bootstrap)]
pub const fn variant_count<T>() -> usize {
0
}

// Some functions are defined here because they accidentally got made
// available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
// (`transmute` also falls into this category, but it cannot be wrapped due to the
Expand Down
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
#![feature(unsized_locals)]
#![feature(untagged_unions)]
#![feature(unwind_attributes)]
#![feature(variant_count)]
#![feature(doc_alias)]
#![feature(mmx_target_feature)]
#![feature(tbm_target_feature)]
Expand Down
30 changes: 30 additions & 0 deletions src/libcore/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,3 +999,33 @@ impl<T> fmt::Debug for Discriminant<T> {
pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
Discriminant(intrinsics::discriminant_value(v))
}

/// Returns the number of variants in the enum type `T`.
///
/// If `T` is not an enum, calling this function will not result in undefined behavior, but the
/// return value is unspecified. Equally, if `T` is an enum with more variants than `usize::MAX`
/// the return value is unspecified. Uninhabited variants will be counted.
///
/// # Examples
///
/// ```
/// # #![feature(never_type)]
/// # #![feature(variant_count)]
///
/// use std::mem;
///
/// enum Void {}
/// enum Foo { A(&'static str), B(i32), C(i32) }
///
/// assert_eq!(mem::variant_count::<Void>(), 0);
/// assert_eq!(mem::variant_count::<Foo>(), 3);
///
/// assert_eq!(mem::variant_count::<Option<!>>(), 2);
/// assert_eq!(mem::variant_count::<Result<!, !>>(), 2);
/// ```
#[inline(always)]
#[unstable(feature = "variant_count", issue = "73662")]
#[rustc_const_unstable(feature = "variant_count", issue = "73662")]
pub const fn variant_count<T>() -> usize {
intrinsics::variant_count::<T>()
}
2 changes: 0 additions & 2 deletions src/libcore/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ impl<T: ?Sized> *const T {
/// differently have not been explored. This method should not be used to introduce such
/// differences, and it should also not be stabilized before we have a better understanding
/// of this issue.
/// ```
#[unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
#[inline]
Expand Down Expand Up @@ -349,7 +348,6 @@ impl<T: ?Sized> *const T {
/// differently have not been explored. This method should not be used to introduce such
/// differences, and it should also not be stabilized before we have a better understanding
/// of this issue.
/// ```
#[unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
#[inline]
Expand Down
2 changes: 0 additions & 2 deletions src/libcore/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ impl<T: ?Sized> *mut T {
/// differently have not been explored. This method should not be used to introduce such
/// differences, and it should also not be stabilized before we have a better understanding
/// of this issue.
/// ```
#[unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
#[inline]
Expand Down Expand Up @@ -327,7 +326,6 @@ impl<T: ?Sized> *mut T {
/// differently have not been explored. This method should not be used to introduce such
/// differences, and it should also not be stabilized before we have a better understanding
/// of this issue.
/// ```
#[unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
#[inline]
Expand Down
80 changes: 80 additions & 0 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,86 @@ impl<T> [T] {
m >= n && needle == &self[m - n..]
}

/// Returns a subslice with the prefix removed.
///
/// Returns [`None`] if slice does not start with `prefix`.
///
/// # Examples
///
/// ```
/// #![feature(slice_strip)]
/// let v = [10, 40, 30];
/// assert_eq!(v.strip_prefix(&[10]), Some(&[40, 30]));
/// assert_eq!(v.strip_prefix(&[10, 40]), Some(&[30]));
/// assert_eq!(v.strip_prefix(&[50]), None);
/// assert_eq!(v.strip_prefix(&[10, 50]), None);
/// ```
///
/// This method returns the original slice if `prefix` is an empty slice:
///
/// ```
/// #![feature(slice_strip)]
/// let v = &[10, 40, 30];
/// assert_eq!(v.strip_prefix(&[]), Some(v));
/// let v: &[u8] = &[];
/// assert_eq!(v.strip_prefix(&[]), Some(v));
/// ```
#[must_use = "returns the subslice without modifying the original"]
#[unstable(feature = "slice_strip", issue = "73413")]
pub fn strip_prefix(&self, prefix: &[T]) -> Option<&[T]>
where
T: PartialEq,
{
let n = prefix.len();
if n <= self.len() {
let (head, tail) = self.split_at(n);
if head == prefix {
return Some(tail);
}
}
None
}

/// Returns a subslice with the suffix removed.
///
/// Returns [`None`] if slice does not end with `suffix`.
///
/// # Examples
///
/// ```
/// #![feature(slice_strip)]
/// let v = [10, 40, 30];
/// assert_eq!(v.strip_suffix(&[30]), Some(&[10, 40]));
/// assert_eq!(v.strip_suffix(&[40, 30]), Some(&[10]));
/// assert_eq!(v.strip_suffix(&[50]), None);
/// assert_eq!(v.strip_suffix(&[50, 30]), None);
/// ```
///
/// This method returns the original slice if `suffix` is an empty slice:
///
/// ```
/// #![feature(slice_strip)]
/// let v = &[10, 40, 30];
/// assert_eq!(v.strip_suffix(&[]), Some(v));
/// let v: &[u8] = &[];
/// assert_eq!(v.strip_suffix(&[]), Some(v));
/// ```
#[must_use = "returns the subslice without modifying the original"]
#[unstable(feature = "slice_strip", issue = "73413")]
pub fn strip_suffix(&self, suffix: &[T]) -> Option<&[T]>
where
T: PartialEq,
{
let (len, n) = (self.len(), suffix.len());
if n <= len {
let (head, tail) = self.split_at(len - n);
if tail == suffix {
return Some(head);
}
}
None
}

/// Binary searches this sorted slice for a given element.
///
/// If the value is found then [`Result::Ok`] is returned, containing the
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_ast/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ pub enum GenericParamKind {
},
Const {
ty: P<Ty>,
/// Span of the `const` keyword.
kw_span: Span,
},
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ impl MetaItem {
let span = span.with_hi(segments.last().unwrap().ident.span.hi());
Path { span, segments }
}
Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. })) => match *nt {
Some(TokenTree::Token(Token { kind: token::Interpolated(nt, _), .. })) => match *nt {
token::Nonterminal::NtMeta(ref item) => return item.meta(item.path.span),
token::Nonterminal::NtPath(ref path) => path.clone(),
_ => return None,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_ast/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ pub fn noop_visit_token<T: MutVisitor>(t: &mut Token, vis: &mut T) {
*span = ident.span;
return; // Avoid visiting the span for the second time.
}
token::Interpolated(nt) => {
token::Interpolated(nt, _) => {
let mut nt = Lrc::make_mut(nt);
vis.visit_interpolated(&mut nt);
}
Expand Down Expand Up @@ -762,7 +762,7 @@ pub fn noop_flat_map_generic_param<T: MutVisitor>(
GenericParamKind::Type { default } => {
visit_opt(default, |default| vis.visit_ty(default));
}
GenericParamKind::Const { ty } => {
GenericParamKind::Const { ty, kw_span: _ } => {
vis.visit_ty(ty);
}
}
Expand Down
31 changes: 20 additions & 11 deletions src/librustc_ast/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: bool) -> bool {
.contains(&name)
}

/// A hack used to pass AST fragments to attribute and derive macros
/// as a single nonterminal token instead of a token stream.
/// FIXME: It needs to be removed, but there are some compatibility issues (see #73345).
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub enum FlattenGroup {
Yes,
No,
}

#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub enum TokenKind {
/* Expression-operator symbols. */
Expand Down Expand Up @@ -236,7 +245,7 @@ pub enum TokenKind {
/// treat regular and interpolated lifetime identifiers in the same way.
Lifetime(Symbol),

Interpolated(Lrc<Nonterminal>),
Interpolated(Lrc<Nonterminal>, FlattenGroup),

// Can be expanded into several tokens.
/// A doc comment.
Expand Down Expand Up @@ -343,7 +352,7 @@ impl Token {
/// if they keep spans or perform edition checks.
pub fn uninterpolated_span(&self) -> Span {
match &self.kind {
Interpolated(nt) => nt.span(),
Interpolated(nt, _) => nt.span(),
_ => self.span,
}
}
Expand Down Expand Up @@ -382,7 +391,7 @@ impl Token {
ModSep | // global path
Lifetime(..) | // labeled loop
Pound => true, // expression attributes
Interpolated(ref nt) => match **nt {
Interpolated(ref nt, _) => match **nt {
NtLiteral(..) |
NtExpr(..) |
NtBlock(..) |
Expand All @@ -408,7 +417,7 @@ impl Token {
Lifetime(..) | // lifetime bound in trait object
Lt | BinOp(Shl) | // associated path
ModSep => true, // global path
Interpolated(ref nt) => match **nt {
Interpolated(ref nt, _) => match **nt {
NtTy(..) | NtPath(..) => true,
_ => false,
},
Expand All @@ -420,7 +429,7 @@ impl Token {
pub fn can_begin_const_arg(&self) -> bool {
match self.kind {
OpenDelim(Brace) => true,
Interpolated(ref nt) => match **nt {
Interpolated(ref nt, _) => match **nt {
NtExpr(..) | NtBlock(..) | NtLiteral(..) => true,
_ => false,
},
Expand Down Expand Up @@ -455,7 +464,7 @@ impl Token {
match self.uninterpolate().kind {
Literal(..) | BinOp(Minus) => true,
Ident(name, false) if name.is_bool_lit() => true,
Interpolated(ref nt) => match &**nt {
Interpolated(ref nt, _) => match &**nt {
NtLiteral(_) => true,
NtExpr(e) => match &e.kind {
ast::ExprKind::Lit(_) => true,
Expand All @@ -476,7 +485,7 @@ impl Token {
// otherwise returns the original token.
pub fn uninterpolate(&self) -> Cow<'_, Token> {
match &self.kind {
Interpolated(nt) => match **nt {
Interpolated(nt, _) => match **nt {
NtIdent(ident, is_raw) => {
Cow::Owned(Token::new(Ident(ident.name, is_raw), ident.span))
}
Expand Down Expand Up @@ -523,7 +532,7 @@ impl Token {

/// Returns `true` if the token is an interpolated path.
fn is_path(&self) -> bool {
if let Interpolated(ref nt) = self.kind {
if let Interpolated(ref nt, _) = self.kind {
if let NtPath(..) = **nt {
return true;
}
Expand All @@ -535,7 +544,7 @@ impl Token {
/// That is, is this a pre-parsed expression dropped into the token stream
/// (which happens while parsing the result of macro expansion)?
pub fn is_whole_expr(&self) -> bool {
if let Interpolated(ref nt) = self.kind {
if let Interpolated(ref nt, _) = self.kind {
if let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtIdent(..) | NtBlock(_) = **nt {
return true;
}
Expand All @@ -546,7 +555,7 @@ impl Token {

// Is the token an interpolated block (`$b:block`)?
pub fn is_whole_block(&self) -> bool {
if let Interpolated(ref nt) = self.kind {
if let Interpolated(ref nt, _) = self.kind {
if let NtBlock(..) = **nt {
return true;
}
Expand Down Expand Up @@ -724,7 +733,7 @@ impl Token {
b == d && (a == c || a == kw::DollarCrate || c == kw::DollarCrate)
}

(&Interpolated(_), &Interpolated(_)) => false,
(&Interpolated(..), &Interpolated(..)) => false,

_ => panic!("forgot to add a token?"),
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast/util/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl Lit {
token::Lit::new(token::Bool, name, None)
}
token::Literal(lit) => lit,
token::Interpolated(ref nt) => {
token::Interpolated(ref nt, _) => {
if let token::NtExpr(expr) | token::NtLiteral(expr) = &**nt {
if let ast::ExprKind::Lit(lit) = &expr.kind {
return Ok(lit.clone());
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

fn lower_token(&mut self, token: Token) -> TokenStream {
match token.kind {
token::Interpolated(nt) => {
token::Interpolated(nt, _) => {
let tts = (self.nt_to_tokenstream)(&nt, &self.sess.parse_sess, token.span);
self.lower_token_stream(tts)
}
Expand Down Expand Up @@ -2230,7 +2230,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

(hir::ParamName::Plain(param.ident), kind)
}
GenericParamKind::Const { ref ty } => {
GenericParamKind::Const { ref ty, kw_span: _ } => {
let ty = self
.with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| {
this.lower_ty(&ty, ImplTraitContext::disallowed())
Expand Down
Loading