Auto merge of #60612 - Centril:rollup-61drhqt, r=Centril
Rollup of 5 pull requests Successful merges: - #60489 (Remove hamburger button from source code page) - #60535 (Correct handling of arguments in async fn) - #60579 (Rename `ParamTy::idx` to `ParamTy::index`) - #60583 (Fix parsing issue with negative literals as const generic arguments) - #60609 (Be a bit more explicit asserting over the vec rather than the len) Failed merges: r? @ghost
This commit is contained in:
commit
cfdc84a009
24 changed files with 375 additions and 62 deletions
|
@ -665,8 +665,8 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
|
||||||
/// let mut v: Vec<i32> = vec![1, 2];
|
/// let mut v: Vec<i32> = vec![1, 2];
|
||||||
///
|
///
|
||||||
/// let old_v = mem::replace(&mut v, vec![3, 4, 5]);
|
/// let old_v = mem::replace(&mut v, vec![3, 4, 5]);
|
||||||
/// assert_eq!(2, old_v.len());
|
/// assert_eq!(vec![1, 2], old_v);
|
||||||
/// assert_eq!(3, v.len());
|
/// assert_eq!(vec![3, 4, 5], v);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// `replace` allows consumption of a struct field by replacing it with another value.
|
/// `replace` allows consumption of a struct field by replacing it with another value.
|
||||||
|
|
|
@ -3424,7 +3424,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
for ty in field.walk() {
|
for ty in field.walk() {
|
||||||
if let ty::Param(p) = ty.sty {
|
if let ty::Param(p) = ty.sty {
|
||||||
ty_params.insert(p.idx as usize);
|
ty_params.insert(p.index as usize);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,7 +204,7 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> {
|
||||||
},
|
},
|
||||||
|
|
||||||
Component::Param(p) => {
|
Component::Param(p) => {
|
||||||
let ty = tcx.mk_ty_param(p.idx, p.name);
|
let ty = tcx.mk_ty_param(p.index, p.name);
|
||||||
Some(ty::Predicate::TypeOutlives(
|
Some(ty::Predicate::TypeOutlives(
|
||||||
ty::Binder::dummy(ty::OutlivesPredicate(ty, r_min))))
|
ty::Binder::dummy(ty::OutlivesPredicate(ty, r_min))))
|
||||||
},
|
},
|
||||||
|
|
|
@ -2715,10 +2715,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_ty_param(self,
|
pub fn mk_ty_param(self, index: u32, name: InternedString) -> Ty<'tcx> {
|
||||||
index: u32,
|
self.mk_ty(Param(ParamTy { index, name: name }))
|
||||||
name: InternedString) -> Ty<'tcx> {
|
|
||||||
self.mk_ty(Param(ParamTy { idx: index, name: name }))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -979,7 +979,7 @@ impl<'a, 'gcx, 'tcx> Generics {
|
||||||
param: &ParamTy,
|
param: &ParamTy,
|
||||||
tcx: TyCtxt<'a, 'gcx, 'tcx>)
|
tcx: TyCtxt<'a, 'gcx, 'tcx>)
|
||||||
-> &'tcx GenericParamDef {
|
-> &'tcx GenericParamDef {
|
||||||
if let Some(index) = param.idx.checked_sub(self.parent_count as u32) {
|
if let Some(index) = param.index.checked_sub(self.parent_count as u32) {
|
||||||
let param = &self.params[index as usize];
|
let param = &self.params[index as usize];
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamDefKind::Type { .. } => param,
|
GenericParamDefKind::Type { .. } => param,
|
||||||
|
|
|
@ -390,7 +390,7 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
|
||||||
}
|
}
|
||||||
|
|
||||||
(&ty::Param(ref a_p), &ty::Param(ref b_p))
|
(&ty::Param(ref a_p), &ty::Param(ref b_p))
|
||||||
if a_p.idx == b_p.idx =>
|
if a_p.index == b_p.index =>
|
||||||
{
|
{
|
||||||
Ok(a)
|
Ok(a)
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,7 +240,7 @@ impl fmt::Debug for Ty<'tcx> {
|
||||||
|
|
||||||
impl fmt::Debug for ty::ParamTy {
|
impl fmt::Debug for ty::ParamTy {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{}/#{}", self.name, self.idx)
|
write!(f, "{}/#{}", self.name, self.index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1111,13 +1111,13 @@ pub type CanonicalPolyFnSig<'tcx> = Canonical<'tcx, Binder<FnSig<'tcx>>>;
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord,
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord,
|
||||||
Hash, RustcEncodable, RustcDecodable, HashStable)]
|
Hash, RustcEncodable, RustcDecodable, HashStable)]
|
||||||
pub struct ParamTy {
|
pub struct ParamTy {
|
||||||
pub idx: u32,
|
pub index: u32,
|
||||||
pub name: InternedString,
|
pub name: InternedString,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'gcx, 'tcx> ParamTy {
|
impl<'a, 'gcx, 'tcx> ParamTy {
|
||||||
pub fn new(index: u32, name: InternedString) -> ParamTy {
|
pub fn new(index: u32, name: InternedString) -> ParamTy {
|
||||||
ParamTy { idx: index, name: name }
|
ParamTy { index, name: name }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn for_self() -> ParamTy {
|
pub fn for_self() -> ParamTy {
|
||||||
|
@ -1129,14 +1129,14 @@ impl<'a, 'gcx, 'tcx> ParamTy {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
pub fn to_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
||||||
tcx.mk_ty_param(self.idx, self.name)
|
tcx.mk_ty_param(self.index, self.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_self(&self) -> bool {
|
pub fn is_self(&self) -> bool {
|
||||||
// FIXME(#50125): Ignoring `Self` with `idx != 0` might lead to weird behavior elsewhere,
|
// FIXME(#50125): Ignoring `Self` with `index != 0` might lead to weird behavior elsewhere,
|
||||||
// but this should only be possible when using `-Z continue-parse-after-error` like
|
// but this should only be possible when using `-Z continue-parse-after-error` like
|
||||||
// `compile-fail/issue-36638.rs`.
|
// `compile-fail/issue-36638.rs`.
|
||||||
self.name == keywords::SelfUpper.name().as_str() && self.idx == 0
|
self.name == keywords::SelfUpper.name().as_str() && self.index == 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1763,7 +1763,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
|
||||||
|
|
||||||
pub fn is_param(&self, index: u32) -> bool {
|
pub fn is_param(&self, index: u32) -> bool {
|
||||||
match self.sty {
|
match self.sty {
|
||||||
ty::Param(ref data) => data.idx == index,
|
ty::Param(ref data) => data.index == index,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -547,7 +547,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for SubstFolder<'a, 'gcx, 'tcx> {
|
||||||
impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
|
impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
|
||||||
fn ty_for_param(&self, p: ty::ParamTy, source_ty: Ty<'tcx>) -> Ty<'tcx> {
|
fn ty_for_param(&self, p: ty::ParamTy, source_ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
// Look up the type in the substitutions. It really should be in there.
|
// Look up the type in the substitutions. It really should be in there.
|
||||||
let opt_ty = self.substs.get(p.idx as usize).map(|k| k.unpack());
|
let opt_ty = self.substs.get(p.index as usize).map(|k| k.unpack());
|
||||||
let ty = match opt_ty {
|
let ty = match opt_ty {
|
||||||
Some(UnpackedKind::Type(ty)) => ty,
|
Some(UnpackedKind::Type(ty)) => ty,
|
||||||
Some(kind) => {
|
Some(kind) => {
|
||||||
|
@ -558,7 +558,7 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
|
||||||
when substituting (root type={:?}) substs={:?}",
|
when substituting (root type={:?}) substs={:?}",
|
||||||
p,
|
p,
|
||||||
source_ty,
|
source_ty,
|
||||||
p.idx,
|
p.index,
|
||||||
kind,
|
kind,
|
||||||
self.root_ty,
|
self.root_ty,
|
||||||
self.substs,
|
self.substs,
|
||||||
|
@ -572,7 +572,7 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
|
||||||
when substituting (root type={:?}) substs={:?}",
|
when substituting (root type={:?}) substs={:?}",
|
||||||
p,
|
p,
|
||||||
source_ty,
|
source_ty,
|
||||||
p.idx,
|
p.index,
|
||||||
self.root_ty,
|
self.root_ty,
|
||||||
self.substs,
|
self.substs,
|
||||||
);
|
);
|
||||||
|
|
|
@ -757,8 +757,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assemble_inherent_candidates_from_param(&mut self,
|
fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
|
||||||
param_ty: ty::ParamTy) {
|
|
||||||
// FIXME -- Do we want to commit to this behavior for param bounds?
|
// FIXME -- Do we want to commit to this behavior for param bounds?
|
||||||
|
|
||||||
let bounds = self.param_env
|
let bounds = self.param_env
|
||||||
|
|
|
@ -5793,9 +5793,9 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
let mut types_used = vec![false; own_counts.types];
|
let mut types_used = vec![false; own_counts.types];
|
||||||
|
|
||||||
for leaf_ty in ty.walk() {
|
for leaf_ty in ty.walk() {
|
||||||
if let ty::Param(ty::ParamTy { idx, .. }) = leaf_ty.sty {
|
if let ty::Param(ty::ParamTy { index, .. }) = leaf_ty.sty {
|
||||||
debug!("Found use of ty param num {}", idx);
|
debug!("Found use of ty param num {}", index);
|
||||||
types_used[idx as usize - own_counts.lifetimes] = true;
|
types_used[index as usize - own_counts.lifetimes] = true;
|
||||||
} else if let ty::Error = leaf_ty.sty {
|
} else if let ty::Error = leaf_ty.sty {
|
||||||
// If there is already another error, do not emit
|
// If there is already another error, do not emit
|
||||||
// an error for not using a type Parameter.
|
// an error for not using a type Parameter.
|
||||||
|
|
|
@ -494,7 +494,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(
|
||||||
impl<'tcx> ty::fold::TypeVisitor<'tcx> for CountParams {
|
impl<'tcx> ty::fold::TypeVisitor<'tcx> for CountParams {
|
||||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
|
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
|
||||||
if let ty::Param(param) = t.sty {
|
if let ty::Param(param) = t.sty {
|
||||||
self.params.insert(param.idx);
|
self.params.insert(param.index);
|
||||||
}
|
}
|
||||||
t.super_visit_with(self)
|
t.super_visit_with(self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use syntax::source_map::Span;
|
||||||
pub struct Parameter(pub u32);
|
pub struct Parameter(pub u32);
|
||||||
|
|
||||||
impl From<ty::ParamTy> for Parameter {
|
impl From<ty::ParamTy> for Parameter {
|
||||||
fn from(param: ty::ParamTy) -> Self { Parameter(param.idx) }
|
fn from(param: ty::ParamTy) -> Self { Parameter(param.index) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ty::EarlyBoundRegion> for Parameter {
|
impl From<ty::EarlyBoundRegion> for Parameter {
|
||||||
|
|
|
@ -324,7 +324,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Param(ref data) => {
|
ty::Param(ref data) => {
|
||||||
self.add_constraint(current, data.idx, variance);
|
self.add_constraint(current, data.index, variance);
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::FnPtr(sig) => {
|
ty::FnPtr(sig) => {
|
||||||
|
|
|
@ -1052,6 +1052,10 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
|
||||||
height: 45px;
|
height: 45px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.rustdoc.source > .sidebar > .sidebar-menu {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar-elems {
|
.sidebar-elems {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
|
|
|
@ -1576,7 +1576,7 @@ impl<'a> Parser<'a> {
|
||||||
let ident = self.parse_ident()?;
|
let ident = self.parse_ident()?;
|
||||||
let mut generics = self.parse_generics()?;
|
let mut generics = self.parse_generics()?;
|
||||||
|
|
||||||
let d = self.parse_fn_decl_with_self(|p: &mut Parser<'a>| {
|
let mut decl = self.parse_fn_decl_with_self(|p: &mut Parser<'a>| {
|
||||||
// This is somewhat dubious; We don't want to allow
|
// This is somewhat dubious; We don't want to allow
|
||||||
// argument names to be left off if there is a
|
// argument names to be left off if there is a
|
||||||
// definition...
|
// definition...
|
||||||
|
@ -1585,7 +1585,7 @@ impl<'a> Parser<'a> {
|
||||||
p.parse_arg_general(p.span.rust_2018(), true, false)
|
p.parse_arg_general(p.span.rust_2018(), true, false)
|
||||||
})?;
|
})?;
|
||||||
generics.where_clause = self.parse_where_clause()?;
|
generics.where_clause = self.parse_where_clause()?;
|
||||||
self.construct_async_arguments(&mut asyncness, &d);
|
self.construct_async_arguments(&mut asyncness, &mut decl);
|
||||||
|
|
||||||
let sig = ast::MethodSig {
|
let sig = ast::MethodSig {
|
||||||
header: FnHeader {
|
header: FnHeader {
|
||||||
|
@ -1594,7 +1594,7 @@ impl<'a> Parser<'a> {
|
||||||
abi,
|
abi,
|
||||||
asyncness,
|
asyncness,
|
||||||
},
|
},
|
||||||
decl: d,
|
decl,
|
||||||
};
|
};
|
||||||
|
|
||||||
let body = match self.token {
|
let body = match self.token {
|
||||||
|
@ -2319,7 +2319,8 @@ impl<'a> Parser<'a> {
|
||||||
let ident = self.parse_path_segment_ident()?;
|
let ident = self.parse_path_segment_ident()?;
|
||||||
|
|
||||||
let is_args_start = |token: &token::Token| match *token {
|
let is_args_start = |token: &token::Token| match *token {
|
||||||
token::Lt | token::BinOp(token::Shl) | token::OpenDelim(token::Paren) => true,
|
token::Lt | token::BinOp(token::Shl) | token::OpenDelim(token::Paren)
|
||||||
|
| token::LArrow => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
let check_args_start = |this: &mut Self| {
|
let check_args_start = |this: &mut Self| {
|
||||||
|
@ -6056,8 +6057,6 @@ impl<'a> Parser<'a> {
|
||||||
self.fatal("identifiers may currently not be used for const generics")
|
self.fatal("identifiers may currently not be used for const generics")
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// FIXME(const_generics): this currently conflicts with emplacement syntax
|
|
||||||
// with negative integer literals.
|
|
||||||
self.parse_literal_maybe_minus()?
|
self.parse_literal_maybe_minus()?
|
||||||
};
|
};
|
||||||
let value = AnonConst {
|
let value = AnonConst {
|
||||||
|
@ -6475,10 +6474,10 @@ impl<'a> Parser<'a> {
|
||||||
-> PResult<'a, ItemInfo> {
|
-> PResult<'a, ItemInfo> {
|
||||||
let (ident, mut generics) = self.parse_fn_header()?;
|
let (ident, mut generics) = self.parse_fn_header()?;
|
||||||
let allow_c_variadic = abi == Abi::C && unsafety == Unsafety::Unsafe;
|
let allow_c_variadic = abi == Abi::C && unsafety == Unsafety::Unsafe;
|
||||||
let decl = self.parse_fn_decl(allow_c_variadic)?;
|
let mut decl = self.parse_fn_decl(allow_c_variadic)?;
|
||||||
generics.where_clause = self.parse_where_clause()?;
|
generics.where_clause = self.parse_where_clause()?;
|
||||||
let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
|
let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
|
||||||
self.construct_async_arguments(&mut asyncness, &decl);
|
self.construct_async_arguments(&mut asyncness, &mut decl);
|
||||||
let header = FnHeader { unsafety, asyncness, constness, abi };
|
let header = FnHeader { unsafety, asyncness, constness, abi };
|
||||||
Ok((ident, ItemKind::Fn(decl, header, generics, body), Some(inner_attrs)))
|
Ok((ident, ItemKind::Fn(decl, header, generics, body), Some(inner_attrs)))
|
||||||
}
|
}
|
||||||
|
@ -6662,9 +6661,9 @@ impl<'a> Parser<'a> {
|
||||||
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
|
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
|
||||||
let ident = self.parse_ident()?;
|
let ident = self.parse_ident()?;
|
||||||
let mut generics = self.parse_generics()?;
|
let mut generics = self.parse_generics()?;
|
||||||
let decl = self.parse_fn_decl_with_self(|p| p.parse_arg())?;
|
let mut decl = self.parse_fn_decl_with_self(|p| p.parse_arg())?;
|
||||||
generics.where_clause = self.parse_where_clause()?;
|
generics.where_clause = self.parse_where_clause()?;
|
||||||
self.construct_async_arguments(&mut asyncness, &decl);
|
self.construct_async_arguments(&mut asyncness, &mut decl);
|
||||||
*at_end = true;
|
*at_end = true;
|
||||||
let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
|
let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
|
||||||
let header = ast::FnHeader { abi, unsafety, constness, asyncness };
|
let header = ast::FnHeader { abi, unsafety, constness, asyncness };
|
||||||
|
@ -8710,9 +8709,9 @@ impl<'a> Parser<'a> {
|
||||||
///
|
///
|
||||||
/// The arguments of the function are replaced in HIR lowering with the arguments created by
|
/// The arguments of the function are replaced in HIR lowering with the arguments created by
|
||||||
/// this function and the statements created here are inserted at the top of the closure body.
|
/// this function and the statements created here are inserted at the top of the closure body.
|
||||||
fn construct_async_arguments(&mut self, asyncness: &mut Spanned<IsAsync>, decl: &FnDecl) {
|
fn construct_async_arguments(&mut self, asyncness: &mut Spanned<IsAsync>, decl: &mut FnDecl) {
|
||||||
if let IsAsync::Async { ref mut arguments, .. } = asyncness.node {
|
if let IsAsync::Async { ref mut arguments, .. } = asyncness.node {
|
||||||
for (index, input) in decl.inputs.iter().enumerate() {
|
for (index, input) in decl.inputs.iter_mut().enumerate() {
|
||||||
let id = ast::DUMMY_NODE_ID;
|
let id = ast::DUMMY_NODE_ID;
|
||||||
let span = input.pat.span;
|
let span = input.pat.span;
|
||||||
|
|
||||||
|
@ -8724,8 +8723,10 @@ impl<'a> Parser<'a> {
|
||||||
// `let <pat> = __argN;` statement, instead just adding a `let <pat> = <pat>;`
|
// `let <pat> = __argN;` statement, instead just adding a `let <pat> = <pat>;`
|
||||||
// statement.
|
// statement.
|
||||||
let (binding_mode, ident, is_simple_pattern) = match input.pat.node {
|
let (binding_mode, ident, is_simple_pattern) = match input.pat.node {
|
||||||
PatKind::Ident(binding_mode, ident, _) => (binding_mode, ident, true),
|
PatKind::Ident(binding_mode @ BindingMode::ByValue(_), ident, _) => {
|
||||||
_ => (BindingMode::ByValue(Mutability::Immutable), ident, false),
|
(binding_mode, ident, true)
|
||||||
|
}
|
||||||
|
_ => (BindingMode::ByValue(Mutability::Mutable), ident, false),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Construct an argument representing `__argN: <ty>` to replace the argument of the
|
// Construct an argument representing `__argN: <ty>` to replace the argument of the
|
||||||
|
@ -8792,6 +8793,15 @@ impl<'a> Parser<'a> {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Remove mutability from arguments. If this is not a simple pattern,
|
||||||
|
// those arguments are replaced by `__argN`, so there is no need to do this.
|
||||||
|
if let PatKind::Ident(BindingMode::ByValue(mutability @ Mutability::Mutable), ..) =
|
||||||
|
&mut input.pat.node
|
||||||
|
{
|
||||||
|
assert!(is_simple_pattern);
|
||||||
|
*mutability = Mutability::Immutable;
|
||||||
|
}
|
||||||
|
|
||||||
let move_stmt = Stmt { id, node: StmtKind::Local(P(move_local)), span };
|
let move_stmt = Stmt { id, node: StmtKind::Local(P(move_local)), span };
|
||||||
arguments.push(AsyncArgument { ident, arg, pat_stmt, move_stmt });
|
arguments.push(AsyncArgument { ident, arg, pat_stmt, move_stmt });
|
||||||
}
|
}
|
||||||
|
|
30
src/test/ui/async-await/argument-patterns.rs
Normal file
30
src/test/ui/async-await/argument-patterns.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// edition:2018
|
||||||
|
// run-pass
|
||||||
|
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
#![deny(unused_mut)]
|
||||||
|
#![feature(async_await)]
|
||||||
|
|
||||||
|
type A = Vec<u32>;
|
||||||
|
|
||||||
|
async fn a(n: u32, mut vec: A) {
|
||||||
|
vec.push(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn b(n: u32, ref mut vec: A) {
|
||||||
|
vec.push(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn c(ref vec: A) {
|
||||||
|
vec.contains(&0);
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn d((a, mut b): (A, A)) {
|
||||||
|
b.push(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn f((ref mut a, ref b): (A, A)) {}
|
||||||
|
|
||||||
|
async fn g(((ref a, ref mut b), (ref mut c, ref d)): ((A, A), (A, A))) {}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,271 @@
|
||||||
|
// aux-build:arc_wake.rs
|
||||||
|
// edition:2018
|
||||||
|
// run-pass
|
||||||
|
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
#![feature(async_await, await_macro)]
|
||||||
|
|
||||||
|
// Test that the drop order for parameters in a fn and async fn matches up. Also test that
|
||||||
|
// parameters (used or unused) are not dropped until the async fn completes execution.
|
||||||
|
// See also #54716.
|
||||||
|
|
||||||
|
extern crate arc_wake;
|
||||||
|
|
||||||
|
use arc_wake::ArcWake;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::future::Future;
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use std::task::Context;
|
||||||
|
|
||||||
|
struct EmptyWaker;
|
||||||
|
|
||||||
|
impl ArcWake for EmptyWaker {
|
||||||
|
fn wake(self: Arc<Self>) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
|
enum DropOrder {
|
||||||
|
Function,
|
||||||
|
Val(&'static str),
|
||||||
|
}
|
||||||
|
|
||||||
|
type DropOrderListPtr = Rc<RefCell<Vec<DropOrder>>>;
|
||||||
|
|
||||||
|
struct D(&'static str, DropOrderListPtr);
|
||||||
|
|
||||||
|
impl Drop for D {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.1.borrow_mut().push(DropOrder::Val(self.0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check that unused bindings are dropped after the function is polled.
|
||||||
|
async fn foo_async(ref mut x: D, ref mut _y: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo_sync(ref mut x: D, ref mut _y: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check that underscore patterns are dropped after the function is polled.
|
||||||
|
async fn bar_async(ref mut x: D, _: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar_sync(ref mut x: D, _: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check that underscore patterns within more complex patterns are dropped after the function
|
||||||
|
/// is polled.
|
||||||
|
async fn baz_async((ref mut x, _): (D, D)) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn baz_sync((ref mut x, _): (D, D)) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check that underscore and unused bindings within and outwith more complex patterns are dropped
|
||||||
|
/// after the function is polled.
|
||||||
|
async fn foobar_async(ref mut x: D, (ref mut a, _, ref mut _c): (D, D, D), _: D, ref mut _y: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foobar_sync(ref mut x: D, (ref mut a, _, ref mut _c): (D, D, D), _: D, ref mut _y: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Foo;
|
||||||
|
|
||||||
|
impl Foo {
|
||||||
|
/// Check that unused bindings are dropped after the method is polled.
|
||||||
|
async fn foo_async(ref mut x: D, ref mut _y: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo_sync(ref mut x: D, ref mut _y: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check that underscore patterns are dropped after the method is polled.
|
||||||
|
async fn bar_async(ref mut x: D, _: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar_sync(ref mut x: D, _: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check that underscore patterns within more complex patterns are dropped after the method
|
||||||
|
/// is polled.
|
||||||
|
async fn baz_async((ref mut x, _): (D, D)) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn baz_sync((ref mut x, _): (D, D)) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check that underscore and unused bindings within and outwith more complex patterns are
|
||||||
|
/// dropped after the method is polled.
|
||||||
|
async fn foobar_async(
|
||||||
|
ref mut x: D, (ref mut a, _, ref mut _c): (D, D, D), _: D, ref mut _y: D,
|
||||||
|
) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foobar_sync(
|
||||||
|
ref mut x: D, (ref mut a, _, ref mut _c): (D, D, D), _: D, ref mut _y: D,
|
||||||
|
) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar<'a>(PhantomData<&'a ()>);
|
||||||
|
|
||||||
|
impl<'a> Bar<'a> {
|
||||||
|
/// Check that unused bindings are dropped after the method with self is polled.
|
||||||
|
async fn foo_async(&'a self, ref mut x: D, ref mut _y: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo_sync(&'a self, ref mut x: D, ref mut _y: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check that underscore patterns are dropped after the method with self is polled.
|
||||||
|
async fn bar_async(&'a self, ref mut x: D, _: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar_sync(&'a self, ref mut x: D, _: D) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check that underscore patterns within more complex patterns are dropped after the method
|
||||||
|
/// with self is polled.
|
||||||
|
async fn baz_async(&'a self, (ref mut x, _): (D, D)) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn baz_sync(&'a self, (ref mut x, _): (D, D)) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check that underscore and unused bindings within and outwith more complex patterns are
|
||||||
|
/// dropped after the method with self is polled.
|
||||||
|
async fn foobar_async(
|
||||||
|
&'a self, ref mut x: D, (ref mut a, _, ref mut _c): (D, D, D), _: D, ref mut _y: D,
|
||||||
|
) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foobar_sync(
|
||||||
|
&'a self, ref mut x: D, (ref mut a, _, ref mut _c): (D, D, D), _: D, ref mut _y: D,
|
||||||
|
) {
|
||||||
|
x.1.borrow_mut().push(DropOrder::Function);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn assert_drop_order_after_poll<Fut: Future<Output = ()>>(
|
||||||
|
f: impl FnOnce(DropOrderListPtr) -> Fut,
|
||||||
|
g: impl FnOnce(DropOrderListPtr),
|
||||||
|
) {
|
||||||
|
let empty = Arc::new(EmptyWaker);
|
||||||
|
let waker = ArcWake::into_waker(empty);
|
||||||
|
let mut cx = Context::from_waker(&waker);
|
||||||
|
|
||||||
|
let actual_order = Rc::new(RefCell::new(Vec::new()));
|
||||||
|
let mut fut = Box::pin(f(actual_order.clone()));
|
||||||
|
let _ = fut.as_mut().poll(&mut cx);
|
||||||
|
|
||||||
|
let expected_order = Rc::new(RefCell::new(Vec::new()));
|
||||||
|
g(expected_order.clone());
|
||||||
|
|
||||||
|
assert_eq!(*actual_order.borrow(), *expected_order.borrow());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// Free functions (see doc comment on function for what it tests).
|
||||||
|
assert_drop_order_after_poll(|l| foo_async(D("x", l.clone()), D("_y", l.clone())),
|
||||||
|
|l| foo_sync(D("x", l.clone()), D("_y", l.clone())));
|
||||||
|
assert_drop_order_after_poll(|l| bar_async(D("x", l.clone()), D("_", l.clone())),
|
||||||
|
|l| bar_sync(D("x", l.clone()), D("_", l.clone())));
|
||||||
|
assert_drop_order_after_poll(|l| baz_async((D("x", l.clone()), D("_", l.clone()))),
|
||||||
|
|l| baz_sync((D("x", l.clone()), D("_", l.clone()))));
|
||||||
|
assert_drop_order_after_poll(
|
||||||
|
|l| {
|
||||||
|
foobar_async(
|
||||||
|
D("x", l.clone()),
|
||||||
|
(D("a", l.clone()), D("_", l.clone()), D("_c", l.clone())),
|
||||||
|
D("_", l.clone()),
|
||||||
|
D("_y", l.clone()),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|l| {
|
||||||
|
foobar_sync(
|
||||||
|
D("x", l.clone()),
|
||||||
|
(D("a", l.clone()), D("_", l.clone()), D("_c", l.clone())),
|
||||||
|
D("_", l.clone()),
|
||||||
|
D("_y", l.clone()),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Methods w/out self (see doc comment on function for what it tests).
|
||||||
|
assert_drop_order_after_poll(|l| Foo::foo_async(D("x", l.clone()), D("_y", l.clone())),
|
||||||
|
|l| Foo::foo_sync(D("x", l.clone()), D("_y", l.clone())));
|
||||||
|
assert_drop_order_after_poll(|l| Foo::bar_async(D("x", l.clone()), D("_", l.clone())),
|
||||||
|
|l| Foo::bar_sync(D("x", l.clone()), D("_", l.clone())));
|
||||||
|
assert_drop_order_after_poll(|l| Foo::baz_async((D("x", l.clone()), D("_", l.clone()))),
|
||||||
|
|l| Foo::baz_sync((D("x", l.clone()), D("_", l.clone()))));
|
||||||
|
assert_drop_order_after_poll(
|
||||||
|
|l| {
|
||||||
|
Foo::foobar_async(
|
||||||
|
D("x", l.clone()),
|
||||||
|
(D("a", l.clone()), D("_", l.clone()), D("_c", l.clone())),
|
||||||
|
D("_", l.clone()),
|
||||||
|
D("_y", l.clone()),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|l| {
|
||||||
|
Foo::foobar_sync(
|
||||||
|
D("x", l.clone()),
|
||||||
|
(D("a", l.clone()), D("_", l.clone()), D("_c", l.clone())),
|
||||||
|
D("_", l.clone()),
|
||||||
|
D("_y", l.clone()),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Methods (see doc comment on function for what it tests).
|
||||||
|
let b = Bar(Default::default());
|
||||||
|
assert_drop_order_after_poll(|l| b.foo_async(D("x", l.clone()), D("_y", l.clone())),
|
||||||
|
|l| b.foo_sync(D("x", l.clone()), D("_y", l.clone())));
|
||||||
|
assert_drop_order_after_poll(|l| b.bar_async(D("x", l.clone()), D("_", l.clone())),
|
||||||
|
|l| b.bar_sync(D("x", l.clone()), D("_", l.clone())));
|
||||||
|
assert_drop_order_after_poll(|l| b.baz_async((D("x", l.clone()), D("_", l.clone()))),
|
||||||
|
|l| b.baz_sync((D("x", l.clone()), D("_", l.clone()))));
|
||||||
|
assert_drop_order_after_poll(
|
||||||
|
|l| {
|
||||||
|
b.foobar_async(
|
||||||
|
D("x", l.clone()),
|
||||||
|
(D("a", l.clone()), D("_", l.clone()), D("_c", l.clone())),
|
||||||
|
D("_", l.clone()),
|
||||||
|
D("_y", l.clone()),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|l| {
|
||||||
|
b.foobar_sync(
|
||||||
|
D("x", l.clone()),
|
||||||
|
(D("a", l.clone()), D("_", l.clone()), D("_c", l.clone())),
|
||||||
|
D("_", l.clone()),
|
||||||
|
D("_y", l.clone()),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
|
@ -8,4 +8,9 @@ async fn foobar_async(x: u32, (a, _, _c): (u32, u32, u32), _: u32, _y: u32) {
|
||||||
assert_eq!(__arg2, 4); //~ ERROR cannot find value `__arg2` in this scope [E0425]
|
assert_eq!(__arg2, 4); //~ ERROR cannot find value `__arg2` in this scope [E0425]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn baz_async(ref mut x: u32, ref y: u32) {
|
||||||
|
assert_eq!(__arg0, 1); //~ ERROR cannot find value `__arg0` in this scope [E0425]
|
||||||
|
assert_eq!(__arg1, 2); //~ ERROR cannot find value `__arg1` in this scope [E0425]
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -10,6 +10,18 @@ error[E0425]: cannot find value `__arg2` in this scope
|
||||||
LL | assert_eq!(__arg2, 4);
|
LL | assert_eq!(__arg2, 4);
|
||||||
| ^^^^^^ not found in this scope
|
| ^^^^^^ not found in this scope
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error[E0425]: cannot find value `__arg0` in this scope
|
||||||
|
--> $DIR/drop-order-locals-are-hidden.rs:12:16
|
||||||
|
|
|
||||||
|
LL | assert_eq!(__arg0, 1);
|
||||||
|
| ^^^^^^ not found in this scope
|
||||||
|
|
||||||
|
error[E0425]: cannot find value `__arg1` in this scope
|
||||||
|
--> $DIR/drop-order-locals-are-hidden.rs:13:16
|
||||||
|
|
|
||||||
|
LL | assert_eq!(__arg1, 2);
|
||||||
|
| ^^^^^^ not found in this scope
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0425`.
|
For more information about this error, try `rustc --explain E0425`.
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
// edition:2018
|
|
||||||
// run-pass
|
|
||||||
|
|
||||||
#![feature(async_await)]
|
|
||||||
|
|
||||||
async fn foo(n: u32, mut vec: Vec<u32>) {
|
|
||||||
vec.push(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
|
@ -6,7 +6,7 @@ fn i32_identity<const X: i32>() -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo_a() {
|
fn foo_a() {
|
||||||
i32_identity::<-1>(); //~ ERROR expected identifier, found `<-`
|
i32_identity::<-1>(); // ok
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo_b() {
|
fn foo_b() {
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
error: expected identifier, found `<-`
|
|
||||||
--> $DIR/const-expression-parameter.rs:9:19
|
|
||||||
|
|
|
||||||
LL | i32_identity::<-1>();
|
|
||||||
| ^^ expected identifier
|
|
||||||
|
|
||||||
error: expected one of `,` or `>`, found `+`
|
error: expected one of `,` or `>`, found `+`
|
||||||
--> $DIR/const-expression-parameter.rs:13:22
|
--> $DIR/const-expression-parameter.rs:13:22
|
||||||
|
|
|
|
||||||
|
@ -16,5 +10,5 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
||||||
LL | #![feature(const_generics)]
|
LL | #![feature(const_generics)]
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue