Skip to content

Commit

Permalink
Auto merge of #60612 - Centril:rollup-61drhqt, r=Centril
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed May 7, 2019
2 parents 17dba3b + 2d6da83 commit cfdc84a
Show file tree
Hide file tree
Showing 24 changed files with 375 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
/// let mut v: Vec<i32> = vec![1, 2];
///
/// let old_v = mem::replace(&mut v, vec![3, 4, 5]);
/// assert_eq!(2, old_v.len());
/// assert_eq!(3, v.len());
/// assert_eq!(vec![1, 2], old_v);
/// assert_eq!(vec![3, 4, 5], v);
/// ```
///
/// `replace` allows consumption of a struct field by replacing it with another value.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.infcx.tcx }

fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
if let ty::Param(ty::ParamTy {name, ..}) = ty.sty {
if let ty::Param(ty::ParamTy {name, .. }) = ty.sty {
let infcx = self.infcx;
self.var_map.entry(ty).or_insert_with(||
infcx.next_ty_var(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3424,7 +3424,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
let mut found = false;
for ty in field.walk() {
if let ty::Param(p) = ty.sty {
ty_params.insert(p.idx as usize);
ty_params.insert(p.index as usize);
found = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> {
},

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(
ty::Binder::dummy(ty::OutlivesPredicate(ty, r_min))))
},
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2715,10 +2715,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}

#[inline]
pub fn mk_ty_param(self,
index: u32,
name: InternedString) -> Ty<'tcx> {
self.mk_ty(Param(ParamTy { idx: index, name: name }))
pub fn mk_ty_param(self, index: u32, name: InternedString) -> Ty<'tcx> {
self.mk_ty(Param(ParamTy { index, name: name }))
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ impl<'a, 'gcx, 'tcx> Generics {
param: &ParamTy,
tcx: TyCtxt<'a, 'gcx, 'tcx>)
-> &'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];
match param.kind {
GenericParamDefKind::Type { .. } => param,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
if a_p.idx == b_p.idx =>
if a_p.index == b_p.index =>
{
Ok(a)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl fmt::Debug for Ty<'tcx> {

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

Expand Down
12 changes: 6 additions & 6 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,13 +1111,13 @@ pub type CanonicalPolyFnSig<'tcx> = Canonical<'tcx, Binder<FnSig<'tcx>>>;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord,
Hash, RustcEncodable, RustcDecodable, HashStable)]
pub struct ParamTy {
pub idx: u32,
pub index: u32,
pub name: InternedString,
}

impl<'a, 'gcx, 'tcx> ParamTy {
pub fn new(index: u32, name: InternedString) -> ParamTy {
ParamTy { idx: index, name: name }
ParamTy { index, name: name }
}

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

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 {
// 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
// `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
}
}

Expand Down Expand Up @@ -1763,7 +1763,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {

pub fn is_param(&self, index: u32) -> bool {
match self.sty {
ty::Param(ref data) => data.idx == index,
ty::Param(ref data) => data.index == index,
_ => false,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for 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> {
// 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 {
Some(UnpackedKind::Type(ty)) => ty,
Some(kind) => {
Expand All @@ -558,7 +558,7 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
when substituting (root type={:?}) substs={:?}",
p,
source_ty,
p.idx,
p.index,
kind,
self.root_ty,
self.substs,
Expand All @@ -572,7 +572,7 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
when substituting (root type={:?}) substs={:?}",
p,
source_ty,
p.idx,
p.index,
self.root_ty,
self.substs,
);
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
});
}

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

let bounds = self.param_env
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

for leaf_ty in ty.walk() {
if let ty::Param(ty::ParamTy { idx, .. }) = leaf_ty.sty {
debug!("Found use of ty param num {}", idx);
types_used[idx as usize - own_counts.lifetimes] = true;
if let ty::Param(ty::ParamTy { index, .. }) = leaf_ty.sty {
debug!("Found use of ty param num {}", index);
types_used[index as usize - own_counts.lifetimes] = true;
} else if let ty::Error = leaf_ty.sty {
// If there is already another error, do not emit
// an error for not using a type Parameter.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(
impl<'tcx> ty::fold::TypeVisitor<'tcx> for CountParams {
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
if let ty::Param(param) = t.sty {
self.params.insert(param.idx);
self.params.insert(param.index);
}
t.super_visit_with(self)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/constrained_generic_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use syntax::source_map::Span;
pub struct Parameter(pub u32);

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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/variance/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
}

ty::Param(ref data) => {
self.add_constraint(current, data.idx, variance);
self.add_constraint(current, data.index, variance);
}

ty::FnPtr(sig) => {
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,10 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
height: 45px;
}

.rustdoc.source > .sidebar > .sidebar-menu {
display: none;
}

.sidebar-elems {
position: fixed;
z-index: 1;
Expand Down
38 changes: 24 additions & 14 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ impl<'a> Parser<'a> {
let ident = self.parse_ident()?;
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
// argument names to be left off if there is a
// definition...
Expand All @@ -1585,7 +1585,7 @@ impl<'a> Parser<'a> {
p.parse_arg_general(p.span.rust_2018(), true, false)
})?;
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 {
header: FnHeader {
Expand All @@ -1594,7 +1594,7 @@ impl<'a> Parser<'a> {
abi,
asyncness,
},
decl: d,
decl,
};

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

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,
};
let check_args_start = |this: &mut Self| {
Expand Down Expand Up @@ -6056,8 +6057,6 @@ impl<'a> Parser<'a> {
self.fatal("identifiers may currently not be used for const generics")
);
} else {
// FIXME(const_generics): this currently conflicts with emplacement syntax
// with negative integer literals.
self.parse_literal_maybe_minus()?
};
let value = AnonConst {
Expand Down Expand Up @@ -6475,10 +6474,10 @@ impl<'a> Parser<'a> {
-> PResult<'a, ItemInfo> {
let (ident, mut generics) = self.parse_fn_header()?;
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()?;
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 };
Ok((ident, ItemKind::Fn(decl, header, generics, body), Some(inner_attrs)))
}
Expand Down Expand Up @@ -6662,9 +6661,9 @@ impl<'a> Parser<'a> {
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
let ident = self.parse_ident()?;
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()?;
self.construct_async_arguments(&mut asyncness, &decl);
self.construct_async_arguments(&mut asyncness, &mut decl);
*at_end = true;
let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
let header = ast::FnHeader { abi, unsafety, constness, asyncness };
Expand Down Expand Up @@ -8710,9 +8709,9 @@ impl<'a> Parser<'a> {
///
/// 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.
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 {
for (index, input) in decl.inputs.iter().enumerate() {
for (index, input) in decl.inputs.iter_mut().enumerate() {
let id = ast::DUMMY_NODE_ID;
let span = input.pat.span;

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

// Construct an argument representing `__argN: <ty>` to replace the argument of the
Expand Down Expand Up @@ -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 };
arguments.push(AsyncArgument { ident, arg, pat_stmt, move_stmt });
}
Expand Down
30 changes: 30 additions & 0 deletions src/test/ui/async-await/argument-patterns.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Loading

0 comments on commit cfdc84a

Please sign in to comment.