Skip to content

Commit cfdc84a

Browse files
committed
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
2 parents 17dba3b + 2d6da83 commit cfdc84a

24 files changed

+375
-62
lines changed

src/libcore/mem.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,8 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
665665
/// let mut v: Vec<i32> = vec![1, 2];
666666
///
667667
/// let old_v = mem::replace(&mut v, vec![3, 4, 5]);
668-
/// assert_eq!(2, old_v.len());
669-
/// assert_eq!(3, v.len());
668+
/// assert_eq!(vec![1, 2], old_v);
669+
/// assert_eq!(vec![3, 4, 5], v);
670670
/// ```
671671
///
672672
/// `replace` allows consumption of a struct field by replacing it with another value.

src/librustc/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14531453
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.infcx.tcx }
14541454

14551455
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
1456-
if let ty::Param(ty::ParamTy {name, ..}) = ty.sty {
1456+
if let ty::Param(ty::ParamTy {name, .. }) = ty.sty {
14571457
let infcx = self.infcx;
14581458
self.var_map.entry(ty).or_insert_with(||
14591459
infcx.next_ty_var(

src/librustc/traits/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3424,7 +3424,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
34243424
let mut found = false;
34253425
for ty in field.walk() {
34263426
if let ty::Param(p) = ty.sty {
3427-
ty_params.insert(p.idx as usize);
3427+
ty_params.insert(p.index as usize);
34283428
found = true;
34293429
}
34303430
}

src/librustc/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> {
204204
},
205205

206206
Component::Param(p) => {
207-
let ty = tcx.mk_ty_param(p.idx, p.name);
207+
let ty = tcx.mk_ty_param(p.index, p.name);
208208
Some(ty::Predicate::TypeOutlives(
209209
ty::Binder::dummy(ty::OutlivesPredicate(ty, r_min))))
210210
},

src/librustc/ty/context.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -2715,10 +2715,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
27152715
}
27162716

27172717
#[inline]
2718-
pub fn mk_ty_param(self,
2719-
index: u32,
2720-
name: InternedString) -> Ty<'tcx> {
2721-
self.mk_ty(Param(ParamTy { idx: index, name: name }))
2718+
pub fn mk_ty_param(self, index: u32, name: InternedString) -> Ty<'tcx> {
2719+
self.mk_ty(Param(ParamTy { index, name: name }))
27222720
}
27232721

27242722
#[inline]

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ impl<'a, 'gcx, 'tcx> Generics {
979979
param: &ParamTy,
980980
tcx: TyCtxt<'a, 'gcx, 'tcx>)
981981
-> &'tcx GenericParamDef {
982-
if let Some(index) = param.idx.checked_sub(self.parent_count as u32) {
982+
if let Some(index) = param.index.checked_sub(self.parent_count as u32) {
983983
let param = &self.params[index as usize];
984984
match param.kind {
985985
GenericParamDefKind::Type { .. } => param,

src/librustc/ty/relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
390390
}
391391

392392
(&ty::Param(ref a_p), &ty::Param(ref b_p))
393-
if a_p.idx == b_p.idx =>
393+
if a_p.index == b_p.index =>
394394
{
395395
Ok(a)
396396
}

src/librustc/ty/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl fmt::Debug for Ty<'tcx> {
240240

241241
impl fmt::Debug for ty::ParamTy {
242242
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
243-
write!(f, "{}/#{}", self.name, self.idx)
243+
write!(f, "{}/#{}", self.name, self.index)
244244
}
245245
}
246246

src/librustc/ty/sty.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1111,13 +1111,13 @@ pub type CanonicalPolyFnSig<'tcx> = Canonical<'tcx, Binder<FnSig<'tcx>>>;
11111111
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord,
11121112
Hash, RustcEncodable, RustcDecodable, HashStable)]
11131113
pub struct ParamTy {
1114-
pub idx: u32,
1114+
pub index: u32,
11151115
pub name: InternedString,
11161116
}
11171117

11181118
impl<'a, 'gcx, 'tcx> ParamTy {
11191119
pub fn new(index: u32, name: InternedString) -> ParamTy {
1120-
ParamTy { idx: index, name: name }
1120+
ParamTy { index, name: name }
11211121
}
11221122

11231123
pub fn for_self() -> ParamTy {
@@ -1129,14 +1129,14 @@ impl<'a, 'gcx, 'tcx> ParamTy {
11291129
}
11301130

11311131
pub fn to_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
1132-
tcx.mk_ty_param(self.idx, self.name)
1132+
tcx.mk_ty_param(self.index, self.name)
11331133
}
11341134

11351135
pub fn is_self(&self) -> bool {
1136-
// FIXME(#50125): Ignoring `Self` with `idx != 0` might lead to weird behavior elsewhere,
1136+
// FIXME(#50125): Ignoring `Self` with `index != 0` might lead to weird behavior elsewhere,
11371137
// but this should only be possible when using `-Z continue-parse-after-error` like
11381138
// `compile-fail/issue-36638.rs`.
1139-
self.name == keywords::SelfUpper.name().as_str() && self.idx == 0
1139+
self.name == keywords::SelfUpper.name().as_str() && self.index == 0
11401140
}
11411141
}
11421142

@@ -1763,7 +1763,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
17631763

17641764
pub fn is_param(&self, index: u32) -> bool {
17651765
match self.sty {
1766-
ty::Param(ref data) => data.idx == index,
1766+
ty::Param(ref data) => data.index == index,
17671767
_ => false,
17681768
}
17691769
}

src/librustc/ty/subst.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for SubstFolder<'a, 'gcx, 'tcx> {
547547
impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
548548
fn ty_for_param(&self, p: ty::ParamTy, source_ty: Ty<'tcx>) -> Ty<'tcx> {
549549
// Look up the type in the substitutions. It really should be in there.
550-
let opt_ty = self.substs.get(p.idx as usize).map(|k| k.unpack());
550+
let opt_ty = self.substs.get(p.index as usize).map(|k| k.unpack());
551551
let ty = match opt_ty {
552552
Some(UnpackedKind::Type(ty)) => ty,
553553
Some(kind) => {
@@ -558,7 +558,7 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
558558
when substituting (root type={:?}) substs={:?}",
559559
p,
560560
source_ty,
561-
p.idx,
561+
p.index,
562562
kind,
563563
self.root_ty,
564564
self.substs,
@@ -572,7 +572,7 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
572572
when substituting (root type={:?}) substs={:?}",
573573
p,
574574
source_ty,
575-
p.idx,
575+
p.index,
576576
self.root_ty,
577577
self.substs,
578578
);

src/librustc_typeck/check/method/probe.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
757757
});
758758
}
759759

760-
fn assemble_inherent_candidates_from_param(&mut self,
761-
param_ty: ty::ParamTy) {
760+
fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
762761
// FIXME -- Do we want to commit to this behavior for param bounds?
763762

764763
let bounds = self.param_env

src/librustc_typeck/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5793,9 +5793,9 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
57935793
let mut types_used = vec![false; own_counts.types];
57945794

57955795
for leaf_ty in ty.walk() {
5796-
if let ty::Param(ty::ParamTy { idx, .. }) = leaf_ty.sty {
5797-
debug!("Found use of ty param num {}", idx);
5798-
types_used[idx as usize - own_counts.lifetimes] = true;
5796+
if let ty::Param(ty::ParamTy { index, .. }) = leaf_ty.sty {
5797+
debug!("Found use of ty param num {}", index);
5798+
types_used[index as usize - own_counts.lifetimes] = true;
57995799
} else if let ty::Error = leaf_ty.sty {
58005800
// If there is already another error, do not emit
58015801
// an error for not using a type Parameter.

src/librustc_typeck/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(
494494
impl<'tcx> ty::fold::TypeVisitor<'tcx> for CountParams {
495495
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
496496
if let ty::Param(param) = t.sty {
497-
self.params.insert(param.idx);
497+
self.params.insert(param.index);
498498
}
499499
t.super_visit_with(self)
500500
}

src/librustc_typeck/constrained_generic_params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use syntax::source_map::Span;
88
pub struct Parameter(pub u32);
99

1010
impl From<ty::ParamTy> for Parameter {
11-
fn from(param: ty::ParamTy) -> Self { Parameter(param.idx) }
11+
fn from(param: ty::ParamTy) -> Self { Parameter(param.index) }
1212
}
1313

1414
impl From<ty::EarlyBoundRegion> for Parameter {

src/librustc_typeck/variance/constraints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
324324
}
325325

326326
ty::Param(ref data) => {
327-
self.add_constraint(current, data.idx, variance);
327+
self.add_constraint(current, data.index, variance);
328328
}
329329

330330
ty::FnPtr(sig) => {

src/librustdoc/html/static/rustdoc.css

+4
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,10 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
10521052
height: 45px;
10531053
}
10541054

1055+
.rustdoc.source > .sidebar > .sidebar-menu {
1056+
display: none;
1057+
}
1058+
10551059
.sidebar-elems {
10561060
position: fixed;
10571061
z-index: 1;

src/libsyntax/parse/parser.rs

+24-14
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ impl<'a> Parser<'a> {
15761576
let ident = self.parse_ident()?;
15771577
let mut generics = self.parse_generics()?;
15781578

1579-
let d = self.parse_fn_decl_with_self(|p: &mut Parser<'a>| {
1579+
let mut decl = self.parse_fn_decl_with_self(|p: &mut Parser<'a>| {
15801580
// This is somewhat dubious; We don't want to allow
15811581
// argument names to be left off if there is a
15821582
// definition...
@@ -1585,7 +1585,7 @@ impl<'a> Parser<'a> {
15851585
p.parse_arg_general(p.span.rust_2018(), true, false)
15861586
})?;
15871587
generics.where_clause = self.parse_where_clause()?;
1588-
self.construct_async_arguments(&mut asyncness, &d);
1588+
self.construct_async_arguments(&mut asyncness, &mut decl);
15891589

15901590
let sig = ast::MethodSig {
15911591
header: FnHeader {
@@ -1594,7 +1594,7 @@ impl<'a> Parser<'a> {
15941594
abi,
15951595
asyncness,
15961596
},
1597-
decl: d,
1597+
decl,
15981598
};
15991599

16001600
let body = match self.token {
@@ -2319,7 +2319,8 @@ impl<'a> Parser<'a> {
23192319
let ident = self.parse_path_segment_ident()?;
23202320

23212321
let is_args_start = |token: &token::Token| match *token {
2322-
token::Lt | token::BinOp(token::Shl) | token::OpenDelim(token::Paren) => true,
2322+
token::Lt | token::BinOp(token::Shl) | token::OpenDelim(token::Paren)
2323+
| token::LArrow => true,
23232324
_ => false,
23242325
};
23252326
let check_args_start = |this: &mut Self| {
@@ -6056,8 +6057,6 @@ impl<'a> Parser<'a> {
60566057
self.fatal("identifiers may currently not be used for const generics")
60576058
);
60586059
} else {
6059-
// FIXME(const_generics): this currently conflicts with emplacement syntax
6060-
// with negative integer literals.
60616060
self.parse_literal_maybe_minus()?
60626061
};
60636062
let value = AnonConst {
@@ -6475,10 +6474,10 @@ impl<'a> Parser<'a> {
64756474
-> PResult<'a, ItemInfo> {
64766475
let (ident, mut generics) = self.parse_fn_header()?;
64776476
let allow_c_variadic = abi == Abi::C && unsafety == Unsafety::Unsafe;
6478-
let decl = self.parse_fn_decl(allow_c_variadic)?;
6477+
let mut decl = self.parse_fn_decl(allow_c_variadic)?;
64796478
generics.where_clause = self.parse_where_clause()?;
64806479
let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
6481-
self.construct_async_arguments(&mut asyncness, &decl);
6480+
self.construct_async_arguments(&mut asyncness, &mut decl);
64826481
let header = FnHeader { unsafety, asyncness, constness, abi };
64836482
Ok((ident, ItemKind::Fn(decl, header, generics, body), Some(inner_attrs)))
64846483
}
@@ -6662,9 +6661,9 @@ impl<'a> Parser<'a> {
66626661
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
66636662
let ident = self.parse_ident()?;
66646663
let mut generics = self.parse_generics()?;
6665-
let decl = self.parse_fn_decl_with_self(|p| p.parse_arg())?;
6664+
let mut decl = self.parse_fn_decl_with_self(|p| p.parse_arg())?;
66666665
generics.where_clause = self.parse_where_clause()?;
6667-
self.construct_async_arguments(&mut asyncness, &decl);
6666+
self.construct_async_arguments(&mut asyncness, &mut decl);
66686667
*at_end = true;
66696668
let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
66706669
let header = ast::FnHeader { abi, unsafety, constness, asyncness };
@@ -8710,9 +8709,9 @@ impl<'a> Parser<'a> {
87108709
///
87118710
/// The arguments of the function are replaced in HIR lowering with the arguments created by
87128711
/// this function and the statements created here are inserted at the top of the closure body.
8713-
fn construct_async_arguments(&mut self, asyncness: &mut Spanned<IsAsync>, decl: &FnDecl) {
8712+
fn construct_async_arguments(&mut self, asyncness: &mut Spanned<IsAsync>, decl: &mut FnDecl) {
87148713
if let IsAsync::Async { ref mut arguments, .. } = asyncness.node {
8715-
for (index, input) in decl.inputs.iter().enumerate() {
8714+
for (index, input) in decl.inputs.iter_mut().enumerate() {
87168715
let id = ast::DUMMY_NODE_ID;
87178716
let span = input.pat.span;
87188717

@@ -8724,8 +8723,10 @@ impl<'a> Parser<'a> {
87248723
// `let <pat> = __argN;` statement, instead just adding a `let <pat> = <pat>;`
87258724
// statement.
87268725
let (binding_mode, ident, is_simple_pattern) = match input.pat.node {
8727-
PatKind::Ident(binding_mode, ident, _) => (binding_mode, ident, true),
8728-
_ => (BindingMode::ByValue(Mutability::Immutable), ident, false),
8726+
PatKind::Ident(binding_mode @ BindingMode::ByValue(_), ident, _) => {
8727+
(binding_mode, ident, true)
8728+
}
8729+
_ => (BindingMode::ByValue(Mutability::Mutable), ident, false),
87298730
};
87308731

87318732
// Construct an argument representing `__argN: <ty>` to replace the argument of the
@@ -8792,6 +8793,15 @@ impl<'a> Parser<'a> {
87928793
})
87938794
};
87948795

8796+
// Remove mutability from arguments. If this is not a simple pattern,
8797+
// those arguments are replaced by `__argN`, so there is no need to do this.
8798+
if let PatKind::Ident(BindingMode::ByValue(mutability @ Mutability::Mutable), ..) =
8799+
&mut input.pat.node
8800+
{
8801+
assert!(is_simple_pattern);
8802+
*mutability = Mutability::Immutable;
8803+
}
8804+
87958805
let move_stmt = Stmt { id, node: StmtKind::Local(P(move_local)), span };
87968806
arguments.push(AsyncArgument { ident, arg, pat_stmt, move_stmt });
87978807
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// edition:2018
2+
// run-pass
3+
4+
#![allow(unused_variables)]
5+
#![deny(unused_mut)]
6+
#![feature(async_await)]
7+
8+
type A = Vec<u32>;
9+
10+
async fn a(n: u32, mut vec: A) {
11+
vec.push(n);
12+
}
13+
14+
async fn b(n: u32, ref mut vec: A) {
15+
vec.push(n);
16+
}
17+
18+
async fn c(ref vec: A) {
19+
vec.contains(&0);
20+
}
21+
22+
async fn d((a, mut b): (A, A)) {
23+
b.push(1);
24+
}
25+
26+
async fn f((ref mut a, ref b): (A, A)) {}
27+
28+
async fn g(((ref a, ref mut b), (ref mut c, ref d)): ((A, A), (A, A))) {}
29+
30+
fn main() {}

0 commit comments

Comments
 (0)