Skip to content

Commit

Permalink
Auto merge of #70024 - Centril:rollup-cppmaxr, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - #69528 (Add undo_leak to reset RefCell borrow state)
 - #69589 (ast: `Mac`/`Macro` -> `MacCall`)
 - #69661 (Implement From<&mut str> for String)
 - #69988 (rustc_metadata: Remove `rmeta::MacroDef`)
 - #70006 (resolve: Fix two issues in fresh binding disambiguation)
 - #70011 (def_collector: Fully visit async functions)
 - #70013 (Return feature gate as a `Symbol` )
 - #70018 (Fix "since" field for `Once::is_complete`'s `#[stable]` attribute)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Mar 15, 2020
2 parents 5da2e53 + bde77af commit e0f5df0
Show file tree
Hide file tree
Showing 65 changed files with 459 additions and 377 deletions.
11 changes: 11 additions & 0 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,17 @@ impl From<&str> for String {
}
}

#[stable(feature = "from_mut_str_for_string", since = "1.44.0")]
impl From<&mut str> for String {
/// Converts a `&mut str` into a `String`.
///
/// The result is allocated on the heap.
#[inline]
fn from(s: &mut str) -> String {
s.to_owned()
}
}

#[stable(feature = "from_ref_string", since = "1.35.0")]
impl From<&String> for String {
#[inline]
Expand Down
41 changes: 36 additions & 5 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,33 @@ impl<T: ?Sized> RefCell<T> {
unsafe { &mut *self.value.get() }
}

/// Undo the effect of leaked guards on the borrow state of the `RefCell`.
///
/// This call is similar to [`get_mut`] but more specialized. It borrows `RefCell` mutably to
/// ensure no borrows exist and then resets the state tracking shared borrows. This is relevant
/// if some `Ref` or `RefMut` borrows have been leaked.
///
/// [`get_mut`]: #method.get_mut
///
/// # Examples
///
/// ```
/// #![feature(cell_leak)]
/// use std::cell::RefCell;
///
/// let mut c = RefCell::new(0);
/// std::mem::forget(c.borrow_mut());
///
/// assert!(c.try_borrow().is_err());
/// c.undo_leak();
/// assert!(c.try_borrow().is_ok());
/// ```
#[unstable(feature = "cell_leak", issue = "69099")]
pub fn undo_leak(&mut self) -> &mut T {
*self.borrow.get_mut() = UNUSED;
self.get_mut()
}

/// Immutably borrows the wrapped value, returning an error if the value is
/// currently mutably borrowed.
///
Expand Down Expand Up @@ -1272,8 +1299,10 @@ impl<'b, T: ?Sized> Ref<'b, T> {
/// ```
#[unstable(feature = "cell_leak", issue = "69099")]
pub fn leak(orig: Ref<'b, T>) -> &'b T {
// By forgetting this Ref we ensure that the borrow counter in the RefCell never goes back
// to UNUSED again. No further mutable references can be created from the original cell.
// By forgetting this Ref we ensure that the borrow counter in the RefCell can't go back to
// UNUSED within the lifetime `'b`. Resetting the reference tracking state would require a
// unique reference to the borrowed RefCell. No further mutable references can be created
// from the original cell.
mem::forget(orig.borrow);
orig.value
}
Expand Down Expand Up @@ -1387,9 +1416,11 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
/// ```
#[unstable(feature = "cell_leak", issue = "69099")]
pub fn leak(orig: RefMut<'b, T>) -> &'b mut T {
// By forgetting this BorrowRefMut we ensure that the borrow counter in the RefCell never
// goes back to UNUSED again. No further references can be created from the original cell,
// making the current borrow the only reference for the remaining lifetime.
// By forgetting this BorrowRefMut we ensure that the borrow counter in the RefCell can't
// go back to UNUSED within the lifetime `'b`. Resetting the reference tracking state would
// require a unique reference to the borrowed RefCell. No further references can be created
// from the original cell within that lifetime, making the current borrow the only
// reference for the remaining lifetime.
mem::forget(orig.borrow);
orig.value
}
Expand Down
50 changes: 25 additions & 25 deletions src/librustc_ast/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! - [`Generics`], [`GenericParam`], [`WhereClause`]: Metadata associated with generic parameters.
//! - [`EnumDef`] and [`Variant`]: Enum declaration.
//! - [`Lit`] and [`LitKind`]: Literal expressions.
//! - [`MacroDef`], [`MacStmtStyle`], [`Mac`], [`MacDelimeter`]: Macro definition and invocation.
//! - [`MacroDef`], [`MacStmtStyle`], [`MacCall`], [`MacDelimeter`]: Macro definition and invocation.
//! - [`Attribute`]: Metadata associated with item.
//! - [`UnOp`], [`UnOpKind`], [`BinOp`], [`BinOpKind`]: Unary and binary operators.

Expand Down Expand Up @@ -513,7 +513,7 @@ impl Pat {
TyKind::Path(None, Path::from_ident(*ident))
}
PatKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()),
PatKind::Mac(mac) => TyKind::Mac(mac.clone()),
PatKind::MacCall(mac) => TyKind::MacCall(mac.clone()),
// `&mut? P` can be reinterpreted as `&mut? T` where `T` is `P` reparsed as a type.
PatKind::Ref(pat, mutbl) => {
pat.to_ty().map(|ty| TyKind::Rptr(None, MutTy { ty, mutbl: *mutbl }))?
Expand Down Expand Up @@ -567,7 +567,7 @@ impl Pat {
| PatKind::Range(..)
| PatKind::Ident(..)
| PatKind::Path(..)
| PatKind::Mac(_) => {}
| PatKind::MacCall(_) => {}
}
}

Expand Down Expand Up @@ -682,7 +682,7 @@ pub enum PatKind {
Paren(P<Pat>),

/// A macro pattern; pre-expansion.
Mac(Mac),
MacCall(MacCall),
}

#[derive(
Expand Down Expand Up @@ -881,9 +881,9 @@ impl Stmt {
pub fn add_trailing_semicolon(mut self) -> Self {
self.kind = match self.kind {
StmtKind::Expr(expr) => StmtKind::Semi(expr),
StmtKind::Mac(mac) => {
StmtKind::Mac(mac.map(|(mac, _style, attrs)| (mac, MacStmtStyle::Semicolon, attrs)))
}
StmtKind::MacCall(mac) => StmtKind::MacCall(
mac.map(|(mac, _style, attrs)| (mac, MacStmtStyle::Semicolon, attrs)),
),
kind => kind,
};
self
Expand Down Expand Up @@ -917,7 +917,7 @@ pub enum StmtKind {
/// Just a trailing semi-colon.
Empty,
/// Macro.
Mac(P<(Mac, MacStmtStyle, AttrVec)>),
MacCall(P<(MacCall, MacStmtStyle, AttrVec)>),
}

#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)]
Expand Down Expand Up @@ -1057,7 +1057,7 @@ impl Expr {
let kind = match &self.kind {
// Trivial conversions.
ExprKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()),
ExprKind::Mac(mac) => TyKind::Mac(mac.clone()),
ExprKind::MacCall(mac) => TyKind::MacCall(mac.clone()),

ExprKind::Paren(expr) => expr.to_ty().map(TyKind::Paren)?,

Expand Down Expand Up @@ -1127,7 +1127,7 @@ impl Expr {
ExprKind::Continue(..) => ExprPrecedence::Continue,
ExprKind::Ret(..) => ExprPrecedence::Ret,
ExprKind::InlineAsm(..) => ExprPrecedence::InlineAsm,
ExprKind::Mac(..) => ExprPrecedence::Mac,
ExprKind::MacCall(..) => ExprPrecedence::Mac,
ExprKind::Struct(..) => ExprPrecedence::Struct,
ExprKind::Repeat(..) => ExprPrecedence::Repeat,
ExprKind::Paren(..) => ExprPrecedence::Paren,
Expand Down Expand Up @@ -1259,7 +1259,7 @@ pub enum ExprKind {
InlineAsm(P<InlineAsm>),

/// A macro invocation; pre-expansion.
Mac(Mac),
MacCall(MacCall),

/// A struct literal expression.
///
Expand Down Expand Up @@ -1345,13 +1345,13 @@ pub enum Movability {
/// Represents a macro invocation. The `path` indicates which macro
/// is being invoked, and the `args` are arguments passed to it.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Mac {
pub struct MacCall {
pub path: Path,
pub args: P<MacArgs>,
pub prior_type_ascription: Option<(Span, bool)>,
}

impl Mac {
impl MacCall {
pub fn span(&self) -> Span {
self.path.span.to(self.args.span().unwrap_or(self.path.span))
}
Expand Down Expand Up @@ -1446,7 +1446,7 @@ impl MacDelimiter {
}

/// Represents a macro definition.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub struct MacroDef {
pub body: P<MacArgs>,
/// `true` if macro was defined with `macro_rules`.
Expand Down Expand Up @@ -1881,7 +1881,7 @@ pub enum TyKind {
/// Inferred type of a `self` or `&self` argument in a method.
ImplicitSelf,
/// A macro in the type position.
Mac(Mac),
MacCall(MacCall),
/// Placeholder for a kind that has failed to be defined.
Err,
/// Placeholder for a `va_list`.
Expand Down Expand Up @@ -2574,7 +2574,7 @@ pub enum ItemKind {
/// A macro invocation.
///
/// E.g., `foo!(..)`.
Mac(Mac),
MacCall(MacCall),

/// A macro definition.
MacroDef(MacroDef),
Expand All @@ -2586,7 +2586,7 @@ impl ItemKind {
match self {
Use(..) | Static(..) | Const(..) | Fn(..) | Mod(..) | GlobalAsm(..) | TyAlias(..)
| Struct(..) | Union(..) | Trait(..) | TraitAlias(..) | MacroDef(..) => "a",
ExternCrate(..) | ForeignMod(..) | Mac(..) | Enum(..) | Impl { .. } => "an",
ExternCrate(..) | ForeignMod(..) | MacCall(..) | Enum(..) | Impl { .. } => "an",
}
}

Expand All @@ -2606,7 +2606,7 @@ impl ItemKind {
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
ItemKind::Mac(..) => "item macro invocation",
ItemKind::MacCall(..) => "item macro invocation",
ItemKind::MacroDef(..) => "macro definition",
ItemKind::Impl { .. } => "implementation",
}
Expand Down Expand Up @@ -2648,14 +2648,14 @@ pub enum AssocItemKind {
/// An associated type.
TyAlias(Defaultness, Generics, GenericBounds, Option<P<Ty>>),
/// A macro expanding to associated items.
Macro(Mac),
MacCall(MacCall),
}

impl AssocItemKind {
pub fn defaultness(&self) -> Defaultness {
match *self {
Self::Const(def, ..) | Self::Fn(def, ..) | Self::TyAlias(def, ..) => def,
Self::Macro(..) => Defaultness::Final,
Self::MacCall(..) => Defaultness::Final,
}
}
}
Expand All @@ -2666,7 +2666,7 @@ impl From<AssocItemKind> for ItemKind {
AssocItemKind::Const(a, b, c) => ItemKind::Const(a, b, c),
AssocItemKind::Fn(a, b, c, d) => ItemKind::Fn(a, b, c, d),
AssocItemKind::TyAlias(a, b, c, d) => ItemKind::TyAlias(a, b, c, d),
AssocItemKind::Macro(a) => ItemKind::Mac(a),
AssocItemKind::MacCall(a) => ItemKind::MacCall(a),
}
}
}
Expand All @@ -2679,7 +2679,7 @@ impl TryFrom<ItemKind> for AssocItemKind {
ItemKind::Const(a, b, c) => AssocItemKind::Const(a, b, c),
ItemKind::Fn(a, b, c, d) => AssocItemKind::Fn(a, b, c, d),
ItemKind::TyAlias(a, b, c, d) => AssocItemKind::TyAlias(a, b, c, d),
ItemKind::Mac(a) => AssocItemKind::Macro(a),
ItemKind::MacCall(a) => AssocItemKind::MacCall(a),
_ => return Err(item_kind),
})
}
Expand All @@ -2695,7 +2695,7 @@ pub enum ForeignItemKind {
/// A foreign type.
TyAlias(Defaultness, Generics, GenericBounds, Option<P<Ty>>),
/// A macro expanding to foreign items.
Macro(Mac),
MacCall(MacCall),
}

impl From<ForeignItemKind> for ItemKind {
Expand All @@ -2704,7 +2704,7 @@ impl From<ForeignItemKind> for ItemKind {
ForeignItemKind::Static(a, b, c) => ItemKind::Static(a, b, c),
ForeignItemKind::Fn(a, b, c, d) => ItemKind::Fn(a, b, c, d),
ForeignItemKind::TyAlias(a, b, c, d) => ItemKind::TyAlias(a, b, c, d),
ForeignItemKind::Macro(a) => ItemKind::Mac(a),
ForeignItemKind::MacCall(a) => ItemKind::MacCall(a),
}
}
}
Expand All @@ -2717,7 +2717,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
ItemKind::Static(a, b, c) => ForeignItemKind::Static(a, b, c),
ItemKind::Fn(a, b, c, d) => ForeignItemKind::Fn(a, b, c, d),
ItemKind::TyAlias(a, b, c, d) => ForeignItemKind::TyAlias(a, b, c, d),
ItemKind::Mac(a) => ForeignItemKind::Macro(a),
ItemKind::MacCall(a) => ForeignItemKind::MacCall(a),
_ => return Err(item_kind),
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_ast/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ impl HasAttrs for StmtKind {
StmtKind::Local(ref local) => local.attrs(),
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.attrs(),
StmtKind::Empty | StmtKind::Item(..) => &[],
StmtKind::Mac(ref mac) => {
StmtKind::MacCall(ref mac) => {
let (_, _, ref attrs) = **mac;
attrs.attrs()
}
Expand All @@ -691,7 +691,7 @@ impl HasAttrs for StmtKind {
StmtKind::Local(local) => local.visit_attrs(f),
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.visit_attrs(f),
StmtKind::Empty | StmtKind::Item(..) => {}
StmtKind::Mac(mac) => {
StmtKind::MacCall(mac) => {
let (_mac, _style, attrs) = mac.deref_mut();
attrs.visit_attrs(f);
}
Expand Down
22 changes: 11 additions & 11 deletions src/librustc_ast/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub trait MutVisitor: Sized {
noop_visit_local(l, self);
}

fn visit_mac(&mut self, _mac: &mut Mac) {
fn visit_mac(&mut self, _mac: &mut MacCall) {
panic!("visit_mac disabled by default");
// N.B., see note about macros above. If you really want a visitor that
// works on macros, use this definition in your trait impl:
Expand Down Expand Up @@ -482,7 +482,7 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
vis.visit_id(id);
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
}
TyKind::Mac(mac) => vis.visit_mac(mac),
TyKind::MacCall(mac) => vis.visit_mac(mac),
}
vis.visit_span(span);
}
Expand Down Expand Up @@ -584,8 +584,8 @@ pub fn noop_visit_attribute<T: MutVisitor>(attr: &mut Attribute, vis: &mut T) {
vis.visit_span(span);
}

pub fn noop_visit_mac<T: MutVisitor>(mac: &mut Mac, vis: &mut T) {
let Mac { path, args, prior_type_ascription: _ } = mac;
pub fn noop_visit_mac<T: MutVisitor>(mac: &mut MacCall, vis: &mut T) {
let MacCall { path, args, prior_type_ascription: _ } = mac;
vis.visit_path(path);
visit_mac_args(args, vis);
}
Expand Down Expand Up @@ -926,7 +926,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
vis.visit_generics(generics);
visit_bounds(bounds, vis);
}
ItemKind::Mac(m) => vis.visit_mac(m),
ItemKind::MacCall(m) => vis.visit_mac(m),
ItemKind::MacroDef(def) => vis.visit_macro_def(def),
}
}
Expand Down Expand Up @@ -955,7 +955,7 @@ pub fn noop_flat_map_assoc_item<T: MutVisitor>(
visit_bounds(bounds, visitor);
visit_opt(ty, |ty| visitor.visit_ty(ty));
}
AssocItemKind::Macro(mac) => visitor.visit_mac(mac),
AssocItemKind::MacCall(mac) => visitor.visit_mac(mac),
}
visitor.visit_span(span);
smallvec![item]
Expand Down Expand Up @@ -1043,7 +1043,7 @@ pub fn noop_flat_map_foreign_item<T: MutVisitor>(
visit_bounds(bounds, visitor);
visit_opt(ty, |ty| visitor.visit_ty(ty));
}
ForeignItemKind::Macro(mac) => visitor.visit_mac(mac),
ForeignItemKind::MacCall(mac) => visitor.visit_mac(mac),
}
visitor.visit_span(span);
smallvec![item]
Expand Down Expand Up @@ -1082,7 +1082,7 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
visit_vec(elems, |elem| vis.visit_pat(elem))
}
PatKind::Paren(inner) => vis.visit_pat(inner),
PatKind::Mac(mac) => vis.visit_mac(mac),
PatKind::MacCall(mac) => vis.visit_mac(mac),
}
vis.visit_span(span);
}
Expand Down Expand Up @@ -1219,7 +1219,7 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { kind, id, span, attrs }: &mut Expr,
}
visit_vec(inputs, |(_c, expr)| vis.visit_expr(expr));
}
ExprKind::Mac(mac) => vis.visit_mac(mac),
ExprKind::MacCall(mac) => vis.visit_mac(mac),
ExprKind::Struct(path, fields, expr) => {
vis.visit_path(path);
fields.flat_map_in_place(|field| vis.flat_map_field(field));
Expand Down Expand Up @@ -1275,11 +1275,11 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(
StmtKind::Expr(expr) => vis.filter_map_expr(expr).into_iter().map(StmtKind::Expr).collect(),
StmtKind::Semi(expr) => vis.filter_map_expr(expr).into_iter().map(StmtKind::Semi).collect(),
StmtKind::Empty => smallvec![StmtKind::Empty],
StmtKind::Mac(mut mac) => {
StmtKind::MacCall(mut mac) => {
let (mac_, _semi, attrs) = mac.deref_mut();
vis.visit_mac(mac_);
visit_thin_attrs(attrs, vis);
smallvec![StmtKind::Mac(mac)]
smallvec![StmtKind::MacCall(mac)]
}
}
}
Expand Down
Loading

0 comments on commit e0f5df0

Please sign in to comment.