Skip to content

Commit e0f5df0

Browse files
committed
Auto merge of #70024 - Centril:rollup-cppmaxr, r=Centril
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
2 parents 5da2e53 + bde77af commit e0f5df0

File tree

65 files changed

+459
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+459
-377
lines changed

src/liballoc/string.rs

+11
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,17 @@ impl From<&str> for String {
22252225
}
22262226
}
22272227

2228+
#[stable(feature = "from_mut_str_for_string", since = "1.44.0")]
2229+
impl From<&mut str> for String {
2230+
/// Converts a `&mut str` into a `String`.
2231+
///
2232+
/// The result is allocated on the heap.
2233+
#[inline]
2234+
fn from(s: &mut str) -> String {
2235+
s.to_owned()
2236+
}
2237+
}
2238+
22282239
#[stable(feature = "from_ref_string", since = "1.35.0")]
22292240
impl From<&String> for String {
22302241
#[inline]

src/libcore/cell.rs

+36-5
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,33 @@ impl<T: ?Sized> RefCell<T> {
958958
unsafe { &mut *self.value.get() }
959959
}
960960

961+
/// Undo the effect of leaked guards on the borrow state of the `RefCell`.
962+
///
963+
/// This call is similar to [`get_mut`] but more specialized. It borrows `RefCell` mutably to
964+
/// ensure no borrows exist and then resets the state tracking shared borrows. This is relevant
965+
/// if some `Ref` or `RefMut` borrows have been leaked.
966+
///
967+
/// [`get_mut`]: #method.get_mut
968+
///
969+
/// # Examples
970+
///
971+
/// ```
972+
/// #![feature(cell_leak)]
973+
/// use std::cell::RefCell;
974+
///
975+
/// let mut c = RefCell::new(0);
976+
/// std::mem::forget(c.borrow_mut());
977+
///
978+
/// assert!(c.try_borrow().is_err());
979+
/// c.undo_leak();
980+
/// assert!(c.try_borrow().is_ok());
981+
/// ```
982+
#[unstable(feature = "cell_leak", issue = "69099")]
983+
pub fn undo_leak(&mut self) -> &mut T {
984+
*self.borrow.get_mut() = UNUSED;
985+
self.get_mut()
986+
}
987+
961988
/// Immutably borrows the wrapped value, returning an error if the value is
962989
/// currently mutably borrowed.
963990
///
@@ -1272,8 +1299,10 @@ impl<'b, T: ?Sized> Ref<'b, T> {
12721299
/// ```
12731300
#[unstable(feature = "cell_leak", issue = "69099")]
12741301
pub fn leak(orig: Ref<'b, T>) -> &'b T {
1275-
// By forgetting this Ref we ensure that the borrow counter in the RefCell never goes back
1276-
// to UNUSED again. No further mutable references can be created from the original cell.
1302+
// By forgetting this Ref we ensure that the borrow counter in the RefCell can't go back to
1303+
// UNUSED within the lifetime `'b`. Resetting the reference tracking state would require a
1304+
// unique reference to the borrowed RefCell. No further mutable references can be created
1305+
// from the original cell.
12771306
mem::forget(orig.borrow);
12781307
orig.value
12791308
}
@@ -1387,9 +1416,11 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
13871416
/// ```
13881417
#[unstable(feature = "cell_leak", issue = "69099")]
13891418
pub fn leak(orig: RefMut<'b, T>) -> &'b mut T {
1390-
// By forgetting this BorrowRefMut we ensure that the borrow counter in the RefCell never
1391-
// goes back to UNUSED again. No further references can be created from the original cell,
1392-
// making the current borrow the only reference for the remaining lifetime.
1419+
// By forgetting this BorrowRefMut we ensure that the borrow counter in the RefCell can't
1420+
// go back to UNUSED within the lifetime `'b`. Resetting the reference tracking state would
1421+
// require a unique reference to the borrowed RefCell. No further references can be created
1422+
// from the original cell within that lifetime, making the current borrow the only
1423+
// reference for the remaining lifetime.
13931424
mem::forget(orig.borrow);
13941425
orig.value
13951426
}

src/librustc_ast/ast.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! - [`Generics`], [`GenericParam`], [`WhereClause`]: Metadata associated with generic parameters.
1515
//! - [`EnumDef`] and [`Variant`]: Enum declaration.
1616
//! - [`Lit`] and [`LitKind`]: Literal expressions.
17-
//! - [`MacroDef`], [`MacStmtStyle`], [`Mac`], [`MacDelimeter`]: Macro definition and invocation.
17+
//! - [`MacroDef`], [`MacStmtStyle`], [`MacCall`], [`MacDelimeter`]: Macro definition and invocation.
1818
//! - [`Attribute`]: Metadata associated with item.
1919
//! - [`UnOp`], [`UnOpKind`], [`BinOp`], [`BinOpKind`]: Unary and binary operators.
2020
@@ -513,7 +513,7 @@ impl Pat {
513513
TyKind::Path(None, Path::from_ident(*ident))
514514
}
515515
PatKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()),
516-
PatKind::Mac(mac) => TyKind::Mac(mac.clone()),
516+
PatKind::MacCall(mac) => TyKind::MacCall(mac.clone()),
517517
// `&mut? P` can be reinterpreted as `&mut? T` where `T` is `P` reparsed as a type.
518518
PatKind::Ref(pat, mutbl) => {
519519
pat.to_ty().map(|ty| TyKind::Rptr(None, MutTy { ty, mutbl: *mutbl }))?
@@ -567,7 +567,7 @@ impl Pat {
567567
| PatKind::Range(..)
568568
| PatKind::Ident(..)
569569
| PatKind::Path(..)
570-
| PatKind::Mac(_) => {}
570+
| PatKind::MacCall(_) => {}
571571
}
572572
}
573573

@@ -682,7 +682,7 @@ pub enum PatKind {
682682
Paren(P<Pat>),
683683

684684
/// A macro pattern; pre-expansion.
685-
Mac(Mac),
685+
MacCall(MacCall),
686686
}
687687

688688
#[derive(
@@ -881,9 +881,9 @@ impl Stmt {
881881
pub fn add_trailing_semicolon(mut self) -> Self {
882882
self.kind = match self.kind {
883883
StmtKind::Expr(expr) => StmtKind::Semi(expr),
884-
StmtKind::Mac(mac) => {
885-
StmtKind::Mac(mac.map(|(mac, _style, attrs)| (mac, MacStmtStyle::Semicolon, attrs)))
886-
}
884+
StmtKind::MacCall(mac) => StmtKind::MacCall(
885+
mac.map(|(mac, _style, attrs)| (mac, MacStmtStyle::Semicolon, attrs)),
886+
),
887887
kind => kind,
888888
};
889889
self
@@ -917,7 +917,7 @@ pub enum StmtKind {
917917
/// Just a trailing semi-colon.
918918
Empty,
919919
/// Macro.
920-
Mac(P<(Mac, MacStmtStyle, AttrVec)>),
920+
MacCall(P<(MacCall, MacStmtStyle, AttrVec)>),
921921
}
922922

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

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

@@ -1127,7 +1127,7 @@ impl Expr {
11271127
ExprKind::Continue(..) => ExprPrecedence::Continue,
11281128
ExprKind::Ret(..) => ExprPrecedence::Ret,
11291129
ExprKind::InlineAsm(..) => ExprPrecedence::InlineAsm,
1130-
ExprKind::Mac(..) => ExprPrecedence::Mac,
1130+
ExprKind::MacCall(..) => ExprPrecedence::Mac,
11311131
ExprKind::Struct(..) => ExprPrecedence::Struct,
11321132
ExprKind::Repeat(..) => ExprPrecedence::Repeat,
11331133
ExprKind::Paren(..) => ExprPrecedence::Paren,
@@ -1259,7 +1259,7 @@ pub enum ExprKind {
12591259
InlineAsm(P<InlineAsm>),
12601260

12611261
/// A macro invocation; pre-expansion.
1262-
Mac(Mac),
1262+
MacCall(MacCall),
12631263

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

1354-
impl Mac {
1354+
impl MacCall {
13551355
pub fn span(&self) -> Span {
13561356
self.path.span.to(self.args.span().unwrap_or(self.path.span))
13571357
}
@@ -1446,7 +1446,7 @@ impl MacDelimiter {
14461446
}
14471447

14481448
/// Represents a macro definition.
1449-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
1449+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
14501450
pub struct MacroDef {
14511451
pub body: P<MacArgs>,
14521452
/// `true` if macro was defined with `macro_rules`.
@@ -1881,7 +1881,7 @@ pub enum TyKind {
18811881
/// Inferred type of a `self` or `&self` argument in a method.
18821882
ImplicitSelf,
18831883
/// A macro in the type position.
1884-
Mac(Mac),
1884+
MacCall(MacCall),
18851885
/// Placeholder for a kind that has failed to be defined.
18861886
Err,
18871887
/// Placeholder for a `va_list`.
@@ -2574,7 +2574,7 @@ pub enum ItemKind {
25742574
/// A macro invocation.
25752575
///
25762576
/// E.g., `foo!(..)`.
2577-
Mac(Mac),
2577+
MacCall(MacCall),
25782578

25792579
/// A macro definition.
25802580
MacroDef(MacroDef),
@@ -2586,7 +2586,7 @@ impl ItemKind {
25862586
match self {
25872587
Use(..) | Static(..) | Const(..) | Fn(..) | Mod(..) | GlobalAsm(..) | TyAlias(..)
25882588
| Struct(..) | Union(..) | Trait(..) | TraitAlias(..) | MacroDef(..) => "a",
2589-
ExternCrate(..) | ForeignMod(..) | Mac(..) | Enum(..) | Impl { .. } => "an",
2589+
ExternCrate(..) | ForeignMod(..) | MacCall(..) | Enum(..) | Impl { .. } => "an",
25902590
}
25912591
}
25922592

@@ -2606,7 +2606,7 @@ impl ItemKind {
26062606
ItemKind::Union(..) => "union",
26072607
ItemKind::Trait(..) => "trait",
26082608
ItemKind::TraitAlias(..) => "trait alias",
2609-
ItemKind::Mac(..) => "item macro invocation",
2609+
ItemKind::MacCall(..) => "item macro invocation",
26102610
ItemKind::MacroDef(..) => "macro definition",
26112611
ItemKind::Impl { .. } => "implementation",
26122612
}
@@ -2648,14 +2648,14 @@ pub enum AssocItemKind {
26482648
/// An associated type.
26492649
TyAlias(Defaultness, Generics, GenericBounds, Option<P<Ty>>),
26502650
/// A macro expanding to associated items.
2651-
Macro(Mac),
2651+
MacCall(MacCall),
26522652
}
26532653

26542654
impl AssocItemKind {
26552655
pub fn defaultness(&self) -> Defaultness {
26562656
match *self {
26572657
Self::Const(def, ..) | Self::Fn(def, ..) | Self::TyAlias(def, ..) => def,
2658-
Self::Macro(..) => Defaultness::Final,
2658+
Self::MacCall(..) => Defaultness::Final,
26592659
}
26602660
}
26612661
}
@@ -2666,7 +2666,7 @@ impl From<AssocItemKind> for ItemKind {
26662666
AssocItemKind::Const(a, b, c) => ItemKind::Const(a, b, c),
26672667
AssocItemKind::Fn(a, b, c, d) => ItemKind::Fn(a, b, c, d),
26682668
AssocItemKind::TyAlias(a, b, c, d) => ItemKind::TyAlias(a, b, c, d),
2669-
AssocItemKind::Macro(a) => ItemKind::Mac(a),
2669+
AssocItemKind::MacCall(a) => ItemKind::MacCall(a),
26702670
}
26712671
}
26722672
}
@@ -2679,7 +2679,7 @@ impl TryFrom<ItemKind> for AssocItemKind {
26792679
ItemKind::Const(a, b, c) => AssocItemKind::Const(a, b, c),
26802680
ItemKind::Fn(a, b, c, d) => AssocItemKind::Fn(a, b, c, d),
26812681
ItemKind::TyAlias(a, b, c, d) => AssocItemKind::TyAlias(a, b, c, d),
2682-
ItemKind::Mac(a) => AssocItemKind::Macro(a),
2682+
ItemKind::MacCall(a) => AssocItemKind::MacCall(a),
26832683
_ => return Err(item_kind),
26842684
})
26852685
}
@@ -2695,7 +2695,7 @@ pub enum ForeignItemKind {
26952695
/// A foreign type.
26962696
TyAlias(Defaultness, Generics, GenericBounds, Option<P<Ty>>),
26972697
/// A macro expanding to foreign items.
2698-
Macro(Mac),
2698+
MacCall(MacCall),
26992699
}
27002700

27012701
impl From<ForeignItemKind> for ItemKind {
@@ -2704,7 +2704,7 @@ impl From<ForeignItemKind> for ItemKind {
27042704
ForeignItemKind::Static(a, b, c) => ItemKind::Static(a, b, c),
27052705
ForeignItemKind::Fn(a, b, c, d) => ItemKind::Fn(a, b, c, d),
27062706
ForeignItemKind::TyAlias(a, b, c, d) => ItemKind::TyAlias(a, b, c, d),
2707-
ForeignItemKind::Macro(a) => ItemKind::Mac(a),
2707+
ForeignItemKind::MacCall(a) => ItemKind::MacCall(a),
27082708
}
27092709
}
27102710
}
@@ -2717,7 +2717,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
27172717
ItemKind::Static(a, b, c) => ForeignItemKind::Static(a, b, c),
27182718
ItemKind::Fn(a, b, c, d) => ForeignItemKind::Fn(a, b, c, d),
27192719
ItemKind::TyAlias(a, b, c, d) => ForeignItemKind::TyAlias(a, b, c, d),
2720-
ItemKind::Mac(a) => ForeignItemKind::Macro(a),
2720+
ItemKind::MacCall(a) => ForeignItemKind::MacCall(a),
27212721
_ => return Err(item_kind),
27222722
})
27232723
}

src/librustc_ast/attr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl HasAttrs for StmtKind {
679679
StmtKind::Local(ref local) => local.attrs(),
680680
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.attrs(),
681681
StmtKind::Empty | StmtKind::Item(..) => &[],
682-
StmtKind::Mac(ref mac) => {
682+
StmtKind::MacCall(ref mac) => {
683683
let (_, _, ref attrs) = **mac;
684684
attrs.attrs()
685685
}
@@ -691,7 +691,7 @@ impl HasAttrs for StmtKind {
691691
StmtKind::Local(local) => local.visit_attrs(f),
692692
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.visit_attrs(f),
693693
StmtKind::Empty | StmtKind::Item(..) => {}
694-
StmtKind::Mac(mac) => {
694+
StmtKind::MacCall(mac) => {
695695
let (_mac, _style, attrs) = mac.deref_mut();
696696
attrs.visit_attrs(f);
697697
}

src/librustc_ast/mut_visit.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pub trait MutVisitor: Sized {
202202
noop_visit_local(l, self);
203203
}
204204

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

587-
pub fn noop_visit_mac<T: MutVisitor>(mac: &mut Mac, vis: &mut T) {
588-
let Mac { path, args, prior_type_ascription: _ } = mac;
587+
pub fn noop_visit_mac<T: MutVisitor>(mac: &mut MacCall, vis: &mut T) {
588+
let MacCall { path, args, prior_type_ascription: _ } = mac;
589589
vis.visit_path(path);
590590
visit_mac_args(args, vis);
591591
}
@@ -926,7 +926,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
926926
vis.visit_generics(generics);
927927
visit_bounds(bounds, vis);
928928
}
929-
ItemKind::Mac(m) => vis.visit_mac(m),
929+
ItemKind::MacCall(m) => vis.visit_mac(m),
930930
ItemKind::MacroDef(def) => vis.visit_macro_def(def),
931931
}
932932
}
@@ -955,7 +955,7 @@ pub fn noop_flat_map_assoc_item<T: MutVisitor>(
955955
visit_bounds(bounds, visitor);
956956
visit_opt(ty, |ty| visitor.visit_ty(ty));
957957
}
958-
AssocItemKind::Macro(mac) => visitor.visit_mac(mac),
958+
AssocItemKind::MacCall(mac) => visitor.visit_mac(mac),
959959
}
960960
visitor.visit_span(span);
961961
smallvec![item]
@@ -1043,7 +1043,7 @@ pub fn noop_flat_map_foreign_item<T: MutVisitor>(
10431043
visit_bounds(bounds, visitor);
10441044
visit_opt(ty, |ty| visitor.visit_ty(ty));
10451045
}
1046-
ForeignItemKind::Macro(mac) => visitor.visit_mac(mac),
1046+
ForeignItemKind::MacCall(mac) => visitor.visit_mac(mac),
10471047
}
10481048
visitor.visit_span(span);
10491049
smallvec![item]
@@ -1082,7 +1082,7 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
10821082
visit_vec(elems, |elem| vis.visit_pat(elem))
10831083
}
10841084
PatKind::Paren(inner) => vis.visit_pat(inner),
1085-
PatKind::Mac(mac) => vis.visit_mac(mac),
1085+
PatKind::MacCall(mac) => vis.visit_mac(mac),
10861086
}
10871087
vis.visit_span(span);
10881088
}
@@ -1219,7 +1219,7 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { kind, id, span, attrs }: &mut Expr,
12191219
}
12201220
visit_vec(inputs, |(_c, expr)| vis.visit_expr(expr));
12211221
}
1222-
ExprKind::Mac(mac) => vis.visit_mac(mac),
1222+
ExprKind::MacCall(mac) => vis.visit_mac(mac),
12231223
ExprKind::Struct(path, fields, expr) => {
12241224
vis.visit_path(path);
12251225
fields.flat_map_in_place(|field| vis.flat_map_field(field));
@@ -1275,11 +1275,11 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(
12751275
StmtKind::Expr(expr) => vis.filter_map_expr(expr).into_iter().map(StmtKind::Expr).collect(),
12761276
StmtKind::Semi(expr) => vis.filter_map_expr(expr).into_iter().map(StmtKind::Semi).collect(),
12771277
StmtKind::Empty => smallvec![StmtKind::Empty],
1278-
StmtKind::Mac(mut mac) => {
1278+
StmtKind::MacCall(mut mac) => {
12791279
let (mac_, _semi, attrs) = mac.deref_mut();
12801280
vis.visit_mac(mac_);
12811281
visit_thin_attrs(attrs, vis);
1282-
smallvec![StmtKind::Mac(mac)]
1282+
smallvec![StmtKind::MacCall(mac)]
12831283
}
12841284
}
12851285
}

0 commit comments

Comments
 (0)