From 2e20da5c2c5a09f3f9e2421b08ccdd8a054cdb91 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 3 May 2019 00:13:39 +0200 Subject: [PATCH 1/7] Remove hamburger button from source code page --- src/librustdoc/html/static/rustdoc.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 53b08cf569783..959c862743c35 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -1052,6 +1052,10 @@ span.since { height: 45px; } + .rustdoc.source > .sidebar > .sidebar-menu { + display: none; + } + .sidebar-elems { position: fixed; z-index: 1; From 121caa927bc4dace0df64f728f62fbce42a15fe9 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 5 May 2019 12:03:32 +0900 Subject: [PATCH 2/7] Correct handling of arguments in async fn --- src/libsyntax/parse/parser.rs | 33 +++++++++++++------- src/test/ui/async-await/argument-patterns.rs | 30 ++++++++++++++++++ src/test/ui/async-await/mutable-arguments.rs | 10 ------ 3 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 src/test/ui/async-await/argument-patterns.rs delete mode 100644 src/test/ui/async-await/mutable-arguments.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d46feeab33599..83f8b0e90c574 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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... @@ -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 { @@ -1594,7 +1594,7 @@ impl<'a> Parser<'a> { abi, asyncness, }, - decl: d, + decl, }; let body = match self.token { @@ -6479,10 +6479,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))) } @@ -6666,9 +6666,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 }; @@ -8714,9 +8714,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, decl: &FnDecl) { + fn construct_async_arguments(&mut self, asyncness: &mut Spanned, 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; @@ -8728,8 +8728,10 @@ impl<'a> Parser<'a> { // `let = __argN;` statement, instead just adding a `let = ;` // 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: ` to replace the argument of the @@ -8796,6 +8798,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 }); } diff --git a/src/test/ui/async-await/argument-patterns.rs b/src/test/ui/async-await/argument-patterns.rs new file mode 100644 index 0000000000000..3750c2bcb701a --- /dev/null +++ b/src/test/ui/async-await/argument-patterns.rs @@ -0,0 +1,30 @@ +// edition:2018 +// run-pass + +#![allow(unused_variables)] +#![deny(unused_mut)] +#![feature(async_await)] + +type A = Vec; + +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() {} diff --git a/src/test/ui/async-await/mutable-arguments.rs b/src/test/ui/async-await/mutable-arguments.rs deleted file mode 100644 index 4d6dba74097ca..0000000000000 --- a/src/test/ui/async-await/mutable-arguments.rs +++ /dev/null @@ -1,10 +0,0 @@ -// edition:2018 -// run-pass - -#![feature(async_await)] - -async fn foo(n: u32, mut vec: Vec) { - vec.push(n); -} - -fn main() {} From 57ec63c76c97028b6627289caec3c6a83cea92a7 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 6 May 2019 00:01:20 +0900 Subject: [PATCH 3/7] Add tests for by-ref binding --- ...-for-async-fn-parameters-by-ref-binding.rs | 271 ++++++++++++++++++ .../drop-order-locals-are-hidden.rs | 5 + .../drop-order-locals-are-hidden.stderr | 14 +- 3 files changed, 289 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/async-await/drop-order-for-async-fn-parameters-by-ref-binding.rs diff --git a/src/test/ui/async-await/drop-order-for-async-fn-parameters-by-ref-binding.rs b/src/test/ui/async-await/drop-order-for-async-fn-parameters-by-ref-binding.rs new file mode 100644 index 0000000000000..c2b59eecb9993 --- /dev/null +++ b/src/test/ui/async-await/drop-order-for-async-fn-parameters-by-ref-binding.rs @@ -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) {} +} + +#[derive(Debug, Eq, PartialEq)] +enum DropOrder { + Function, + Val(&'static str), +} + +type DropOrderListPtr = Rc>>; + +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>( + 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()), + ) + }, + ); +} diff --git a/src/test/ui/async-await/drop-order-locals-are-hidden.rs b/src/test/ui/async-await/drop-order-locals-are-hidden.rs index 10dc5e27f6f9f..bcdb8878eb5d2 100644 --- a/src/test/ui/async-await/drop-order-locals-are-hidden.rs +++ b/src/test/ui/async-await/drop-order-locals-are-hidden.rs @@ -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] } +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() {} diff --git a/src/test/ui/async-await/drop-order-locals-are-hidden.stderr b/src/test/ui/async-await/drop-order-locals-are-hidden.stderr index ca0da6b7c962a..484e1f4f4269e 100644 --- a/src/test/ui/async-await/drop-order-locals-are-hidden.stderr +++ b/src/test/ui/async-await/drop-order-locals-are-hidden.stderr @@ -10,6 +10,18 @@ error[E0425]: cannot find value `__arg2` in this scope LL | assert_eq!(__arg2, 4); | ^^^^^^ 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`. From c3694e5ee69247eb1ac10c6d3b187f567303dc8d Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 6 May 2019 13:12:04 +0100 Subject: [PATCH 4/7] Rename `ParamTy::idx` to `ParamTy::index` --- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/select.rs | 2 +- src/librustc/traits/util.rs | 2 +- src/librustc/ty/context.rs | 6 ++---- src/librustc/ty/mod.rs | 2 +- src/librustc/ty/relate.rs | 2 +- src/librustc/ty/structural_impls.rs | 2 +- src/librustc/ty/sty.rs | 12 ++++++------ src/librustc/ty/subst.rs | 6 +++--- src/librustc_typeck/check/method/probe.rs | 3 +-- src/librustc_typeck/check/mod.rs | 6 +++--- src/librustc_typeck/check/wfcheck.rs | 2 +- src/librustc_typeck/constrained_generic_params.rs | 2 +- src/librustc_typeck/variance/constraints.rs | 2 +- 14 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 007ff32f32776..d9ccbba69d5c0 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -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( diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index f0c402789c4cd..d68e2be9ea086 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -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; } } diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 90f62a4d132c7..be29ea5701b2f 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -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)))) }, diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 19440d0bc64ea..15524ca6e930c 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -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] diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index cb92e4b7470a5..7b749957c3ff5 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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, diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index d7b1907074195..2049341327495 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -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) } diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index bab9527dd07f6..6df8a21241f7b 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -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) } } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index cca40c379fc11..760f3d60d0571 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -1111,13 +1111,13 @@ pub type CanonicalPolyFnSig<'tcx> = Canonical<'tcx, Binder>>; #[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 { @@ -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 } } @@ -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, } } diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 8d51fbc174a04..33f0df836d0c1 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -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) => { @@ -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, @@ -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, ); diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 314f7e97cd28d..251400e65f383 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -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 diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e404a8e6972c8..57cd2b4dab1be 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -5795,9 +5795,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. diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 1420c66c73ea3..fd7d6fe694ccd 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -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) } diff --git a/src/librustc_typeck/constrained_generic_params.rs b/src/librustc_typeck/constrained_generic_params.rs index 18bf66ceb3501..49910e39fed20 100644 --- a/src/librustc_typeck/constrained_generic_params.rs +++ b/src/librustc_typeck/constrained_generic_params.rs @@ -8,7 +8,7 @@ use syntax::source_map::Span; pub struct Parameter(pub u32); impl From for Parameter { - fn from(param: ty::ParamTy) -> Self { Parameter(param.idx) } + fn from(param: ty::ParamTy) -> Self { Parameter(param.index) } } impl From for Parameter { diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 5079a3bb55f89..4f82978f01a5d 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -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) => { From 594685b5a2f35e2ff4fc01aca2ae91de92ed0993 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 6 May 2019 17:00:01 +0100 Subject: [PATCH 5/7] `token::LArrow` can begin arguments `<-` may indicate the start of a negative const argument. --- src/libsyntax/parse/parser.rs | 3 ++- src/test/ui/const-generics/const-expression-parameter.rs | 2 +- .../ui/const-generics/const-expression-parameter.stderr | 8 +------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d46feeab33599..2f7b6f9fa664f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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| { diff --git a/src/test/ui/const-generics/const-expression-parameter.rs b/src/test/ui/const-generics/const-expression-parameter.rs index 662c7b767bae0..22c6c35162281 100644 --- a/src/test/ui/const-generics/const-expression-parameter.rs +++ b/src/test/ui/const-generics/const-expression-parameter.rs @@ -6,7 +6,7 @@ fn i32_identity() -> i32 { } fn foo_a() { - i32_identity::<-1>(); //~ ERROR expected identifier, found `<-` + i32_identity::<-1>(); // ok } fn foo_b() { diff --git a/src/test/ui/const-generics/const-expression-parameter.stderr b/src/test/ui/const-generics/const-expression-parameter.stderr index 2f7a80f0c8fde..c255127c28079 100644 --- a/src/test/ui/const-generics/const-expression-parameter.stderr +++ b/src/test/ui/const-generics/const-expression-parameter.stderr @@ -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 `+` --> $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)] | ^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to previous error From e570fe5b220c1c9064587f94a885587b7f910ab1 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 6 May 2019 17:00:34 +0100 Subject: [PATCH 6/7] Remove resolved FIXME --- src/libsyntax/parse/parser.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2f7b6f9fa664f..67e3132b2fc18 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6061,8 +6061,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 { From b98bf88d3244cc5518b6ad9302f179c1e6d11a9e Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 7 May 2019 13:31:12 -0300 Subject: [PATCH 7/7] Be a bit more explicit asserting over the vec rather than the len --- src/libcore/mem.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 95480c6bf048d..ae43a7f5ffa1e 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -666,8 +666,8 @@ pub fn swap(x: &mut T, y: &mut T) { /// let mut v: Vec = 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.