From 83d5a60cf64bbda77debdc8e91ba5486b2522880 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 9 Aug 2018 20:58:43 +0100 Subject: [PATCH 01/21] Feature gate where clauses on associated type impls --- src/libsyntax/feature_gate.rs | 13 +++++++++---- .../feature-gate-generic_associated_types.rs | 5 +++++ .../feature-gate-generic_associated_types.stderr | 16 ++++++++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 56e69b9df9e04..3cbb391420156 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1869,10 +1869,15 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "existential types are unstable" ); } - - ast::ImplItemKind::Type(_) if !ii.generics.params.is_empty() => { - gate_feature_post!(&self, generic_associated_types, ii.span, - "generic associated types are unstable"); + ast::ImplItemKind::Type(_) => { + if !ii.generics.params.is_empty() { + gate_feature_post!(&self, generic_associated_types, ii.span, + "generic associated types are unstable"); + } + if !ii.generics.where_clause.predicates.is_empty() { + gate_feature_post!(&self, generic_associated_types, ii.span, + "where clauses on associated types are unstable"); + } } _ => {} } diff --git a/src/test/ui/feature-gates/feature-gate-generic_associated_types.rs b/src/test/ui/feature-gates/feature-gate-generic_associated_types.rs index 3470662686643..bbaae1ef449fc 100644 --- a/src/test/ui/feature-gates/feature-gate-generic_associated_types.rs +++ b/src/test/ui/feature-gates/feature-gate-generic_associated_types.rs @@ -19,6 +19,7 @@ trait PointerFamily { } struct Foo; + impl PointerFamily for Foo { type Pointer = Box; //~^ ERROR generic associated types are unstable @@ -31,5 +32,9 @@ trait Bar { //~^ ERROR where clauses on associated types are unstable } +impl Bar for Foo { + type Assoc where Self: Sized = Foo; + //~^ ERROR where clauses on associated types are unstable +} fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr b/src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr index d7891f13c6b4d..f12cbe727fbed 100644 --- a/src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr +++ b/src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr @@ -23,7 +23,7 @@ LL | type Pointer2: Deref where T: Clone, U: Clone; = help: add #![feature(generic_associated_types)] to the crate attributes to enable error[E0658]: generic associated types are unstable (see issue #44265) - --> $DIR/feature-gate-generic_associated_types.rs:23:5 + --> $DIR/feature-gate-generic_associated_types.rs:24:5 | LL | type Pointer = Box; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | type Pointer = Box; = help: add #![feature(generic_associated_types)] to the crate attributes to enable error[E0658]: generic associated types are unstable (see issue #44265) - --> $DIR/feature-gate-generic_associated_types.rs:25:5 + --> $DIR/feature-gate-generic_associated_types.rs:26:5 | LL | type Pointer2 = Box; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -39,13 +39,21 @@ LL | type Pointer2 = Box; = help: add #![feature(generic_associated_types)] to the crate attributes to enable error[E0658]: where clauses on associated types are unstable (see issue #44265) - --> $DIR/feature-gate-generic_associated_types.rs:30:5 + --> $DIR/feature-gate-generic_associated_types.rs:31:5 | LL | type Assoc where Self: Sized; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add #![feature(generic_associated_types)] to the crate attributes to enable -error: aborting due to 6 previous errors +error[E0658]: where clauses on associated types are unstable (see issue #44265) + --> $DIR/feature-gate-generic_associated_types.rs:36:5 + | +LL | type Assoc where Self: Sized = Foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(generic_associated_types)] to the crate attributes to enable + +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0658`. From f2445fb5075fa35d9b387d40bf6053007e63361e Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 21 Jul 2018 18:47:02 -0700 Subject: [PATCH 02/21] Rename `Catch` variants to `TryBlock` (Not `Try` since `QuestionMark` is using that.) --- src/librustc/hir/lowering.rs | 4 ++-- src/librustc/ich/impls_syntax.rs | 2 +- src/libsyntax/ast.rs | 6 +++--- src/libsyntax/feature_gate.rs | 2 +- src/libsyntax/fold.rs | 2 +- src/libsyntax/parse/classify.rs | 2 +- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax/print/pprust.rs | 2 +- src/libsyntax/util/parser.rs | 4 ++-- src/libsyntax/visit.rs | 2 +- src/libsyntax_pos/hygiene.rs | 4 ++-- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 09f76552279f7..6ca18ae1847d9 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -3613,10 +3613,10 @@ impl<'a> LoweringContext<'a> { hir::LoopSource::Loop, ) }), - ExprKind::Catch(ref body) => { + ExprKind::TryBlock(ref body) => { self.with_catch_scope(body.id, |this| { let unstable_span = - this.allow_internal_unstable(CompilerDesugaringKind::Catch, body.span); + this.allow_internal_unstable(CompilerDesugaringKind::TryBlock, body.span); let mut block = this.lower_block(body, true).into_inner(); let tail = block.expr.take().map_or_else( || { diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index d086d3bd28df0..cb90d2d127704 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -412,7 +412,7 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::CompilerDesugaringKind { QuestionMark, ExistentialReturnType, ForLoop, - Catch + TryBlock }); impl_stable_hash_for!(enum ::syntax_pos::FileName { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e53f3ea903603..0f2afde8f9e03 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -987,7 +987,7 @@ impl Expr { ExprKind::Match(..) => ExprPrecedence::Match, ExprKind::Closure(..) => ExprPrecedence::Closure, ExprKind::Block(..) => ExprPrecedence::Block, - ExprKind::Catch(..) => ExprPrecedence::Catch, + ExprKind::TryBlock(..) => ExprPrecedence::TryBlock, ExprKind::Async(..) => ExprPrecedence::Async, ExprKind::Assign(..) => ExprPrecedence::Assign, ExprKind::AssignOp(..) => ExprPrecedence::AssignOp, @@ -1108,8 +1108,8 @@ pub enum ExprKind { /// created during lowering cannot be made the parent of any other /// preexisting defs. Async(CaptureBy, NodeId, P), - /// A catch block (`catch { ... }`) - Catch(P), + /// A try block (`try { ... }`) + TryBlock(P), /// An assignment (`a = foo()`) Assign(P, P), diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index e8245a553eb48..3276913094049 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1734,7 +1734,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { e.span, "yield syntax is experimental"); } - ast::ExprKind::Catch(_) => { + ast::ExprKind::TryBlock(_) => { gate_feature_post!(&self, catch_expr, e.span, "`catch` expression is experimental"); } ast::ExprKind::IfLet(ref pats, ..) | ast::ExprKind::WhileLet(ref pats, ..) => { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 3209939d9b14d..632dd5c330977 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1351,7 +1351,7 @@ pub fn noop_fold_expr(Expr {id, node, span, attrs}: Expr, folder: &mu } ExprKind::Yield(ex) => ExprKind::Yield(ex.map(|x| folder.fold_expr(x))), ExprKind::Try(ex) => ExprKind::Try(folder.fold_expr(ex)), - ExprKind::Catch(body) => ExprKind::Catch(folder.fold_block(body)), + ExprKind::TryBlock(body) => ExprKind::TryBlock(folder.fold_block(body)), }, id: folder.new_id(id), span: folder.new_span(span), diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 531483e7de120..99f9d0511fe5e 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -31,7 +31,7 @@ pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool { ast::ExprKind::WhileLet(..) | ast::ExprKind::Loop(..) | ast::ExprKind::ForLoop(..) | - ast::ExprKind::Catch(..) => false, + ast::ExprKind::TryBlock(..) => false, _ => true, } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 345464c666425..fdb9f80b7c692 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3458,7 +3458,7 @@ impl<'a> Parser<'a> { { let (iattrs, body) = self.parse_inner_attrs_and_block()?; attrs.extend(iattrs); - Ok(self.mk_expr(span_lo.to(body.span), ExprKind::Catch(body), attrs)) + Ok(self.mk_expr(span_lo.to(body.span), ExprKind::TryBlock(body), attrs)) } // `match` token already eaten diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 54ce06f61ef6b..f8d01fee950c5 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2379,7 +2379,7 @@ impl<'a> State<'a> { self.print_expr_maybe_paren(e, parser::PREC_POSTFIX)?; self.s.word("?")? } - ast::ExprKind::Catch(ref blk) => { + ast::ExprKind::TryBlock(ref blk) => { self.head("do catch")?; self.s.space()?; self.print_block_with_attrs(blk, attrs)? diff --git a/src/libsyntax/util/parser.rs b/src/libsyntax/util/parser.rs index 67bc6f947b59a..6866806cd7c66 100644 --- a/src/libsyntax/util/parser.rs +++ b/src/libsyntax/util/parser.rs @@ -273,7 +273,7 @@ pub enum ExprPrecedence { Loop, Match, Block, - Catch, + TryBlock, Struct, Async, } @@ -332,7 +332,7 @@ impl ExprPrecedence { ExprPrecedence::Loop | ExprPrecedence::Match | ExprPrecedence::Block | - ExprPrecedence::Catch | + ExprPrecedence::TryBlock | ExprPrecedence::Async | ExprPrecedence::Struct => PREC_PAREN, } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 51be129737e56..e57d692faae53 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -809,7 +809,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { ExprKind::Try(ref subexpression) => { visitor.visit_expr(subexpression) } - ExprKind::Catch(ref body) => { + ExprKind::TryBlock(ref body) => { visitor.visit_block(body) } } diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index 670fd5b872d92..569019174507b 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -595,7 +595,7 @@ impl ExpnFormat { #[derive(Clone, Copy, Hash, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)] pub enum CompilerDesugaringKind { QuestionMark, - Catch, + TryBlock, /// Desugaring of an `impl Trait` in return type position /// to an `existential type Foo: Trait;` + replacing the /// `impl Trait` with `Foo`. @@ -609,7 +609,7 @@ impl CompilerDesugaringKind { Symbol::intern(match self { CompilerDesugaringKind::Async => "async", CompilerDesugaringKind::QuestionMark => "?", - CompilerDesugaringKind::Catch => "do catch", + CompilerDesugaringKind::TryBlock => "do catch", CompilerDesugaringKind::ExistentialReturnType => "existential type", CompilerDesugaringKind::ForLoop => "for loop", }) From 1c906093f93ca55994bded24fa0f9c99b8d1a681 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 21 Jul 2018 19:34:45 -0700 Subject: [PATCH 03/21] Add `try` to syntax_pos as an edition-2018-only keyword --- src/libsyntax_pos/symbol.rs | 29 ++++++++++++------- .../keyword-try-as-identifier-edition2018.rs | 15 ++++++++++ .../run-pass/try-is-identifier-edition2015.rs | 18 ++++++++++++ 3 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 src/test/parse-fail/keyword-try-as-identifier-edition2018.rs create mode 100644 src/test/run-pass/try-is-identifier-edition2015.rs diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 62f22475e7de7..dc92ce56c791e 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -413,23 +413,30 @@ declare_keywords! { (49, Virtual, "virtual") (50, Yield, "yield") + // Edition-specific keywords currently in use. + (51, Try, "try") // >= 2018 Edition Only + // Edition-specific keywords reserved for future use. - (51, Async, "async") // >= 2018 Edition Only + (52, Async, "async") // >= 2018 Edition Only // Special lifetime names - (52, UnderscoreLifetime, "'_") - (53, StaticLifetime, "'static") + (53, UnderscoreLifetime, "'_") + (54, StaticLifetime, "'static") // Weak keywords, have special meaning only in specific contexts. - (54, Auto, "auto") - (55, Catch, "catch") - (56, Default, "default") - (57, Dyn, "dyn") - (58, Union, "union") - (59, Existential, "existential") + (55, Auto, "auto") + (56, Catch, "catch") + (57, Default, "default") + (58, Dyn, "dyn") + (59, Union, "union") + (60, Existential, "existential") } impl Symbol { + fn is_used_keyword_2018(self) -> bool { + self == keywords::Try.name() + } + fn is_unused_keyword_2018(self) -> bool { self == keywords::Async.name() } @@ -444,7 +451,9 @@ impl Ident { /// Returns `true` if the token is a keyword used in the language. pub fn is_used_keyword(self) -> bool { - self.name >= keywords::As.name() && self.name <= keywords::While.name() + // Note: `span.edition()` is relatively expensive, don't call it unless necessary. + self.name >= keywords::As.name() && self.name <= keywords::While.name() || + self.name.is_used_keyword_2018() && self.span.edition() == Edition::Edition2018 } /// Returns `true` if the token is a keyword reserved for possible future use. diff --git a/src/test/parse-fail/keyword-try-as-identifier-edition2018.rs b/src/test/parse-fail/keyword-try-as-identifier-edition2018.rs new file mode 100644 index 0000000000000..1fe67313a3555 --- /dev/null +++ b/src/test/parse-fail/keyword-try-as-identifier-edition2018.rs @@ -0,0 +1,15 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z parse-only --edition 2018 + +fn main() { + let try = "foo"; //~ error: expected pattern, found keyword `try` +} diff --git a/src/test/run-pass/try-is-identifier-edition2015.rs b/src/test/run-pass/try-is-identifier-edition2015.rs new file mode 100644 index 0000000000000..aafb52e4c491f --- /dev/null +++ b/src/test/run-pass/try-is-identifier-edition2015.rs @@ -0,0 +1,18 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: --edition 2015 + +fn main() { + let try = 2; + struct try { try: u32 }; + let try: try = try { try }; + assert_eq!(try.try, 2); +} From 9e64ce179903e610197e1d201a53471e9feb69f2 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 21 Jul 2018 20:59:44 -0700 Subject: [PATCH 04/21] Parse try blocks with the try keyword instead of do catch placeholder --- src/librustc_mir/borrow_check/nll/mod.rs | 4 +- src/librustc_mir/lib.rs | 9 +++- src/librustc_mir/util/pretty.rs | 4 +- src/librustc_typeck/check/mod.rs | 2 +- src/libsyntax/feature_gate.rs | 4 +- src/libsyntax/parse/parser.rs | 22 ++++---- src/libsyntax/print/pprust.rs | 2 +- src/libsyntax_pos/hygiene.rs | 2 +- .../try-block-bad-lifetime.rs} | 12 +++-- .../try-block-bad-type.rs} | 12 +++-- .../try-block-in-match.rs} | 4 +- .../try-block-in-while.rs} | 4 +- .../try-block-maybe-bad-lifetime.rs} | 10 ++-- .../try-block-opt-init.rs} | 4 +- src/test/run-pass/issue-45124.rs | 4 +- .../run-pass/{catch-expr.rs => try-block.rs} | 20 +++---- .../ui/catch/catch-bad-lifetime.nll.stderr | 39 -------------- src/test/ui/catch/catch-bad-lifetime.stderr | 44 ---------------- src/test/ui/catch/catch-bad-type.stderr | 52 ------------------- src/test/ui/catch/catch-in-match.stderr | 8 --- src/test/ui/catch/catch-in-while.stderr | 8 --- .../catch/catch-maybe-bad-lifetime.nll.stderr | 14 ----- .../ui/catch/catch-maybe-bad-lifetime.stderr | 33 ------------ src/test/ui/catch/catch-opt-init.nll.stderr | 11 ---- src/test/ui/catch/catch-opt-init.stderr | 9 ---- .../feature-gates/feature-gate-catch_expr.rs | 6 ++- .../feature-gate-catch_expr.stderr | 8 +-- src/test/ui/try-block-in-edition2015.rs | 20 +++++++ src/test/ui/try-block-in-edition2015.stderr | 18 +++++++ ...-type-error.rs => try-block-type-error.rs} | 6 ++- ...ror.stderr => try-block-type-error.stderr} | 4 +- 31 files changed, 123 insertions(+), 276 deletions(-) rename src/test/{ui/catch/catch-bad-lifetime.rs => compile-fail/try-block-bad-lifetime.rs} (74%) rename src/test/{ui/catch/catch-bad-type.rs => compile-fail/try-block-bad-type.rs} (65%) rename src/test/{ui/catch/catch-in-match.rs => compile-fail/try-block-in-match.rs} (80%) rename src/test/{ui/catch/catch-in-while.rs => compile-fail/try-block-in-while.rs} (81%) rename src/test/{ui/catch/catch-maybe-bad-lifetime.rs => compile-fail/try-block-maybe-bad-lifetime.rs} (83%) rename src/test/{ui/catch/catch-opt-init.rs => compile-fail/try-block-opt-init.rs} (91%) rename src/test/run-pass/{catch-expr.rs => try-block.rs} (79%) delete mode 100644 src/test/ui/catch/catch-bad-lifetime.nll.stderr delete mode 100644 src/test/ui/catch/catch-bad-lifetime.stderr delete mode 100644 src/test/ui/catch/catch-bad-type.stderr delete mode 100644 src/test/ui/catch/catch-in-match.stderr delete mode 100644 src/test/ui/catch/catch-in-while.stderr delete mode 100644 src/test/ui/catch/catch-maybe-bad-lifetime.nll.stderr delete mode 100644 src/test/ui/catch/catch-maybe-bad-lifetime.stderr delete mode 100644 src/test/ui/catch/catch-opt-init.nll.stderr delete mode 100644 src/test/ui/catch/catch-opt-init.stderr create mode 100644 src/test/ui/try-block-in-edition2015.rs create mode 100644 src/test/ui/try-block-in-edition2015.stderr rename src/test/ui/{catch/catch-block-type-error.rs => try-block-type-error.rs} (87%) rename src/test/ui/{catch/catch-block-type-error.stderr => try-block-type-error.stderr} (88%) diff --git a/src/librustc_mir/borrow_check/nll/mod.rs b/src/librustc_mir/borrow_check/nll/mod.rs index f54d80d5f4f7e..40df78d6bfd37 100644 --- a/src/librustc_mir/borrow_check/nll/mod.rs +++ b/src/librustc_mir/borrow_check/nll/mod.rs @@ -312,14 +312,14 @@ fn dump_mir_results<'a, 'gcx, 'tcx>( ); // Also dump the inference graph constraints as a graphviz file. - let _: io::Result<()> = do catch { + let _: io::Result<()> = try_block! { let mut file = pretty::create_dump_file(infcx.tcx, "regioncx.all.dot", None, "nll", &0, source)?; regioncx.dump_graphviz_raw_constraints(&mut file)?; }; // Also dump the inference graph constraints as a graphviz file. - let _: io::Result<()> = do catch { + let _: io::Result<()> = try_block! { let mut file = pretty::create_dump_file(infcx.tcx, "regioncx.scc.dot", None, "nll", &0, source)?; regioncx.dump_graphviz_scc_constraints(&mut file)?; diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index bda80ff562c75..3858aae3d5c3c 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -21,7 +21,6 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![feature(slice_sort_by_cached_key)] #![feature(box_patterns)] #![feature(box_syntax)] -#![feature(catch_expr)] #![feature(crate_visibility_modifier)] #![feature(const_fn)] #![feature(core_intrinsics)] @@ -61,6 +60,14 @@ extern crate rustc_apfloat; extern crate byteorder; extern crate core; +// Once we can use edition 2018 in the compiler, +// replace this with real try blocks. +macro_rules! try_block { + ($($inside:tt)*) => ( + (||{ ::std::ops::Try::from_ok({ $($inside)* }) })() + ) +} + mod diagnostics; mod borrow_check; diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 01ad85cf66830..465dad35ae312 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -140,7 +140,7 @@ fn dump_matched_mir_node<'a, 'gcx, 'tcx, F>( ) where F: FnMut(PassWhere, &mut dyn Write) -> io::Result<()>, { - let _: io::Result<()> = do catch { + let _: io::Result<()> = try_block! { let mut file = create_dump_file(tcx, "mir", pass_num, pass_name, disambiguator, source)?; writeln!(file, "// MIR for `{}`", node_path)?; writeln!(file, "// source = {:?}", source)?; @@ -156,7 +156,7 @@ fn dump_matched_mir_node<'a, 'gcx, 'tcx, F>( }; if tcx.sess.opts.debugging_opts.dump_mir_graphviz { - let _: io::Result<()> = do catch { + let _: io::Result<()> = try_block! { let mut file = create_dump_file(tcx, "dot", pass_num, pass_name, disambiguator, source)?; write_mir_fn_graphviz(tcx, source.def_id, mir, &mut file)?; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 27b427f7f89fb..89537634ad9cc 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4461,7 +4461,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // In some cases, blocks have just one exit, but other blocks // can be targeted by multiple breaks. This can happen both // with labeled blocks as well as when we desugar - // a `do catch { ... }` expression. + // a `try { ... }` expression. // // Example 1: // diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 3276913094049..f796c0e2e535b 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -330,7 +330,7 @@ declare_features! ( // `extern "x86-interrupt" fn()` (active, abi_x86_interrupt, "1.17.0", Some(40180), None), - // Allows the `catch {...}` expression + // Allows the `try {...}` expression (active, catch_expr, "1.17.0", Some(31436), None), // Used to preserve symbols (see llvm.used) @@ -1735,7 +1735,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "yield syntax is experimental"); } ast::ExprKind::TryBlock(_) => { - gate_feature_post!(&self, catch_expr, e.span, "`catch` expression is experimental"); + gate_feature_post!(&self, catch_expr, e.span, "`try` expression is experimental"); } ast::ExprKind::IfLet(ref pats, ..) | ast::ExprKind::WhileLet(ref pats, ..) => { if pats.len() > 1 { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index fdb9f80b7c692..2b0cfd14a3d5a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2386,11 +2386,10 @@ impl<'a> Parser<'a> { BlockCheckMode::Unsafe(ast::UserProvided), attrs); } - if self.is_catch_expr() { + if self.is_try_block() { let lo = self.span; - assert!(self.eat_keyword(keywords::Do)); - assert!(self.eat_keyword(keywords::Catch)); - return self.parse_catch_expr(lo, attrs); + assert!(self.eat_keyword(keywords::Try)); + return self.parse_try_block(lo, attrs); } if self.eat_keyword(keywords::Return) { if self.token.can_begin_expr() { @@ -3452,8 +3451,8 @@ impl<'a> Parser<'a> { ExprKind::Async(capture_clause, ast::DUMMY_NODE_ID, body), attrs)) } - /// Parse a `do catch {...}` expression (`do catch` token already eaten) - fn parse_catch_expr(&mut self, span_lo: Span, mut attrs: ThinVec) + /// Parse a `try {...}` expression (`try` token already eaten) + fn parse_try_block(&mut self, span_lo: Span, mut attrs: ThinVec) -> PResult<'a, P> { let (iattrs, body) = self.parse_inner_attrs_and_block()?; @@ -4407,12 +4406,13 @@ impl<'a> Parser<'a> { ) } - fn is_catch_expr(&mut self) -> bool { - self.token.is_keyword(keywords::Do) && - self.look_ahead(1, |t| t.is_keyword(keywords::Catch)) && - self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace)) && + fn is_try_block(&mut self) -> bool { + self.token.is_keyword(keywords::Try) && + self.look_ahead(1, |t| *t == token::OpenDelim(token::Brace)) && - // prevent `while catch {} {}`, `if catch {} {} else {}`, etc. + self.span.edition() >= Edition::Edition2018 && + + // prevent `while try {} {}`, `if try {} {} else {}`, etc. !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index f8d01fee950c5..14e7b08172b51 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2380,7 +2380,7 @@ impl<'a> State<'a> { self.s.word("?")? } ast::ExprKind::TryBlock(ref blk) => { - self.head("do catch")?; + self.head("try")?; self.s.space()?; self.print_block_with_attrs(blk, attrs)? } diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index 569019174507b..364c640debb16 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -609,7 +609,7 @@ impl CompilerDesugaringKind { Symbol::intern(match self { CompilerDesugaringKind::Async => "async", CompilerDesugaringKind::QuestionMark => "?", - CompilerDesugaringKind::TryBlock => "do catch", + CompilerDesugaringKind::TryBlock => "try block", CompilerDesugaringKind::ExistentialReturnType => "existential type", CompilerDesugaringKind::ForLoop => "for loop", }) diff --git a/src/test/ui/catch/catch-bad-lifetime.rs b/src/test/compile-fail/try-block-bad-lifetime.rs similarity index 74% rename from src/test/ui/catch/catch-bad-lifetime.rs rename to src/test/compile-fail/try-block-bad-lifetime.rs index f332ffd449423..8dfd8545af7a5 100644 --- a/src/test/ui/catch/catch-bad-lifetime.rs +++ b/src/test/compile-fail/try-block-bad-lifetime.rs @@ -8,14 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: --edition 2018 + #![feature(catch_expr)] -// This test checks that borrows made and returned inside catch blocks are properly constrained +// This test checks that borrows made and returned inside try blocks are properly constrained pub fn main() { { - // Test that borrows returned from a catch block must be valid for the lifetime of the + // Test that borrows returned from a try block must be valid for the lifetime of the // result variable - let _result: Result<(), &str> = do catch { + let _result: Result<(), &str> = try { let my_string = String::from(""); let my_str: & str = & my_string; //~^ ERROR `my_string` does not live long enough @@ -25,10 +27,10 @@ pub fn main() { } { - // Test that borrows returned from catch blocks freeze their referent + // Test that borrows returned from try blocks freeze their referent let mut i = 5; let k = &mut i; - let mut j: Result<(), &mut i32> = do catch { + let mut j: Result<(), &mut i32> = try { Err(k) ?; i = 10; //~ ERROR cannot assign to `i` because it is borrowed }; diff --git a/src/test/ui/catch/catch-bad-type.rs b/src/test/compile-fail/try-block-bad-type.rs similarity index 65% rename from src/test/ui/catch/catch-bad-type.rs rename to src/test/compile-fail/try-block-bad-type.rs index b369847699bdb..9e555df8535e5 100644 --- a/src/test/ui/catch/catch-bad-type.rs +++ b/src/test/compile-fail/try-block-bad-type.rs @@ -8,21 +8,23 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: --edition 2018 + #![feature(catch_expr)] pub fn main() { - let res: Result = do catch { + let res: Result = try { Err("")?; //~ ERROR the trait bound `i32: std::convert::From<&str>` is not satisfied 5 }; - let res: Result = do catch { + let res: Result = try { "" //~ ERROR type mismatch }; - let res: Result = do catch { }; //~ ERROR type mismatch + let res: Result = try { }; //~ ERROR type mismatch - let res: () = do catch { }; //~ the trait bound `(): std::ops::Try` is not satisfied + let res: () = try { }; //~ the trait bound `(): std::ops::Try` is not satisfied - let res: i32 = do catch { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied + let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied } diff --git a/src/test/ui/catch/catch-in-match.rs b/src/test/compile-fail/try-block-in-match.rs similarity index 80% rename from src/test/ui/catch/catch-in-match.rs rename to src/test/compile-fail/try-block-in-match.rs index 9f9968e81242a..490b00a6f434b 100644 --- a/src/test/ui/catch/catch-in-match.rs +++ b/src/test/compile-fail/try-block-in-match.rs @@ -8,8 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: --edition 2018 + #![feature(catch_expr)] fn main() { - match do catch { false } { _ => {} } //~ ERROR expected expression, found reserved keyword `do` + match try { false } { _ => {} } //~ ERROR expected expression, found keyword `try` } diff --git a/src/test/ui/catch/catch-in-while.rs b/src/test/compile-fail/try-block-in-while.rs similarity index 81% rename from src/test/ui/catch/catch-in-while.rs rename to src/test/compile-fail/try-block-in-while.rs index cb8613ee60b42..a949e778f389c 100644 --- a/src/test/ui/catch/catch-in-while.rs +++ b/src/test/compile-fail/try-block-in-while.rs @@ -8,8 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: --edition 2018 + #![feature(catch_expr)] fn main() { - while do catch { false } {} //~ ERROR expected expression, found reserved keyword `do` + while try { false } {} //~ ERROR expected expression, found keyword `try` } diff --git a/src/test/ui/catch/catch-maybe-bad-lifetime.rs b/src/test/compile-fail/try-block-maybe-bad-lifetime.rs similarity index 83% rename from src/test/ui/catch/catch-maybe-bad-lifetime.rs rename to src/test/compile-fail/try-block-maybe-bad-lifetime.rs index faefb5ef18a35..db37a397c16ad 100644 --- a/src/test/ui/catch/catch-maybe-bad-lifetime.rs +++ b/src/test/compile-fail/try-block-maybe-bad-lifetime.rs @@ -8,14 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: --edition 2018 + #![feature(catch_expr)] -// This test checks that borrows made and returned inside catch blocks are properly constrained +// This test checks that borrows made and returned inside try blocks are properly constrained pub fn main() { { // Test that a borrow which *might* be returned still freezes its referent let mut i = 222; - let x: Result<&i32, ()> = do catch { + let x: Result<&i32, ()> = try { Err(())?; &i }; @@ -26,7 +28,7 @@ pub fn main() { { let x = String::new(); - let _y: Result<(), ()> = do catch { + let _y: Result<(), ()> = try { Err(())?; ::std::mem::drop(x); }; @@ -38,7 +40,7 @@ pub fn main() { // its referent let mut i = 222; let j; - let x: Result<(), ()> = do catch { + let x: Result<(), ()> = try { Err(())?; j = &i; }; diff --git a/src/test/ui/catch/catch-opt-init.rs b/src/test/compile-fail/try-block-opt-init.rs similarity index 91% rename from src/test/ui/catch/catch-opt-init.rs rename to src/test/compile-fail/try-block-opt-init.rs index 0c41102e3bea4..14544c6ea0ccc 100644 --- a/src/test/ui/catch/catch-opt-init.rs +++ b/src/test/compile-fail/try-block-opt-init.rs @@ -8,13 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: --edition 2018 + #![feature(catch_expr)] fn use_val(_x: T) {} pub fn main() { let cfg_res; - let _: Result<(), ()> = do catch { + let _: Result<(), ()> = try { Err(())?; cfg_res = 5; Ok::<(), ()>(())?; diff --git a/src/test/run-pass/issue-45124.rs b/src/test/run-pass/issue-45124.rs index c65823e460be3..5f47cc8d7d554 100644 --- a/src/test/run-pass/issue-45124.rs +++ b/src/test/run-pass/issue-45124.rs @@ -8,12 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: --edition 2018 + #![feature(catch_expr)] fn main() { let mut a = 0; let () = { - let _: Result<(), ()> = do catch { + let _: Result<(), ()> = try { let _ = Err(())?; return }; diff --git a/src/test/run-pass/catch-expr.rs b/src/test/run-pass/try-block.rs similarity index 79% rename from src/test/run-pass/catch-expr.rs rename to src/test/run-pass/try-block.rs index c23bca7f49e54..f2b017e94f08f 100644 --- a/src/test/run-pass/catch-expr.rs +++ b/src/test/run-pass/try-block.rs @@ -8,12 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: --edition 2018 + #![feature(catch_expr)] struct catch {} pub fn main() { - let catch_result: Option<_> = do catch { + let catch_result: Option<_> = try { let x = 5; x }; @@ -30,20 +32,20 @@ pub fn main() { _ => {} }; - let catch_err: Result<_, i32> = do catch { + let catch_err: Result<_, i32> = try { Err(22)?; 1 }; assert_eq!(catch_err, Err(22)); - let catch_okay: Result = do catch { + let catch_okay: Result = try { if false { Err(25)?; } Ok::<(), i32>(())?; 28 }; assert_eq!(catch_okay, Ok(28)); - let catch_from_loop: Result = do catch { + let catch_from_loop: Result = try { for i in 0..10 { if i < 5 { Ok::(i)?; } else { Err(i)?; } } @@ -52,28 +54,28 @@ pub fn main() { assert_eq!(catch_from_loop, Err(5)); let cfg_init; - let _res: Result<(), ()> = do catch { + let _res: Result<(), ()> = try { cfg_init = 5; }; assert_eq!(cfg_init, 5); let cfg_init_2; - let _res: Result<(), ()> = do catch { + let _res: Result<(), ()> = try { cfg_init_2 = 6; Err(())?; }; assert_eq!(cfg_init_2, 6); let my_string = "test".to_string(); - let res: Result<&str, ()> = do catch { + let res: Result<&str, ()> = try { // Unfortunately, deref doesn't fire here (#49356) &my_string[..] }; assert_eq!(res, Ok("test")); - let my_opt: Option<_> = do catch { () }; + let my_opt: Option<_> = try { () }; assert_eq!(my_opt, Some(())); - let my_opt: Option<_> = do catch { }; + let my_opt: Option<_> = try { }; assert_eq!(my_opt, Some(())); } diff --git a/src/test/ui/catch/catch-bad-lifetime.nll.stderr b/src/test/ui/catch/catch-bad-lifetime.nll.stderr deleted file mode 100644 index dd1595f931511..0000000000000 --- a/src/test/ui/catch/catch-bad-lifetime.nll.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error[E0506]: cannot assign to `i` because it is borrowed - --> $DIR/catch-bad-lifetime.rs:33:13 - | -LL | let k = &mut i; - | ------ borrow of `i` occurs here -... -LL | i = 10; //~ ERROR cannot assign to `i` because it is borrowed - | ^^^^^^ assignment to borrowed `i` occurs here -LL | }; -LL | ::std::mem::drop(k); //~ ERROR use of moved value: `k` - | - borrow later used here - -error[E0382]: use of moved value: `k` - --> $DIR/catch-bad-lifetime.rs:35:26 - | -LL | Err(k) ?; - | - value moved here -... -LL | ::std::mem::drop(k); //~ ERROR use of moved value: `k` - | ^ value used here after move - | - = note: move occurs because `k` has type `&mut i32`, which does not implement the `Copy` trait - -error[E0506]: cannot assign to `i` because it is borrowed - --> $DIR/catch-bad-lifetime.rs:36:9 - | -LL | let k = &mut i; - | ------ borrow of `i` occurs here -... -LL | i = 40; //~ ERROR cannot assign to `i` because it is borrowed - | ^^^^^^ assignment to borrowed `i` occurs here -LL | -LL | let i_ptr = if let Err(i_ptr) = j { i_ptr } else { panic ! ("") }; - | - borrow later used here - -error: aborting due to 3 previous errors - -Some errors occurred: E0382, E0506. -For more information about an error, try `rustc --explain E0382`. diff --git a/src/test/ui/catch/catch-bad-lifetime.stderr b/src/test/ui/catch/catch-bad-lifetime.stderr deleted file mode 100644 index 2ea54d1fb24db..0000000000000 --- a/src/test/ui/catch/catch-bad-lifetime.stderr +++ /dev/null @@ -1,44 +0,0 @@ -error[E0597]: `my_string` does not live long enough - --> $DIR/catch-bad-lifetime.rs:20:35 - | -LL | let my_str: & str = & my_string; - | ^^^^^^^^^ borrowed value does not live long enough -... -LL | }; - | - `my_string` dropped here while still borrowed -LL | } - | - borrowed value needs to live until here - -error[E0506]: cannot assign to `i` because it is borrowed - --> $DIR/catch-bad-lifetime.rs:33:13 - | -LL | let k = &mut i; - | - borrow of `i` occurs here -... -LL | i = 10; //~ ERROR cannot assign to `i` because it is borrowed - | ^^^^^^ assignment to borrowed `i` occurs here - -error[E0382]: use of moved value: `k` - --> $DIR/catch-bad-lifetime.rs:35:26 - | -LL | Err(k) ?; - | - value moved here -... -LL | ::std::mem::drop(k); //~ ERROR use of moved value: `k` - | ^ value used here after move - | - = note: move occurs because `k` has type `&mut i32`, which does not implement the `Copy` trait - -error[E0506]: cannot assign to `i` because it is borrowed - --> $DIR/catch-bad-lifetime.rs:36:9 - | -LL | let k = &mut i; - | - borrow of `i` occurs here -... -LL | i = 40; //~ ERROR cannot assign to `i` because it is borrowed - | ^^^^^^ assignment to borrowed `i` occurs here - -error: aborting due to 4 previous errors - -Some errors occurred: E0382, E0506, E0597. -For more information about an error, try `rustc --explain E0382`. diff --git a/src/test/ui/catch/catch-bad-type.stderr b/src/test/ui/catch/catch-bad-type.stderr deleted file mode 100644 index 2ab5b3e31768c..0000000000000 --- a/src/test/ui/catch/catch-bad-type.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error[E0277]: the trait bound `i32: std::convert::From<&str>` is not satisfied - --> $DIR/catch-bad-type.rs:15:9 - | -LL | Err("")?; //~ ERROR the trait bound `i32: std::convert::From<&str>` is not satisfied - | ^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `i32` - | - = help: the following implementations were found: - > - > - > - > - > - = note: required by `std::convert::From::from` - -error[E0271]: type mismatch resolving ` as std::ops::Try>::Ok == &str` - --> $DIR/catch-bad-type.rs:20:9 - | -LL | "" //~ ERROR type mismatch - | ^^ expected i32, found &str - | - = note: expected type `i32` - found type `&str` - -error[E0271]: type mismatch resolving ` as std::ops::Try>::Ok == ()` - --> $DIR/catch-bad-type.rs:23:44 - | -LL | let res: Result = do catch { }; //~ ERROR type mismatch - | ^ expected i32, found () - | - = note: expected type `i32` - found type `()` - -error[E0277]: the trait bound `(): std::ops::Try` is not satisfied - --> $DIR/catch-bad-type.rs:25:28 - | -LL | let res: () = do catch { }; //~ the trait bound `(): std::ops::Try` is not satisfied - | ^^^ the trait `std::ops::Try` is not implemented for `()` - | - = note: required by `std::ops::Try::from_ok` - -error[E0277]: the trait bound `i32: std::ops::Try` is not satisfied - --> $DIR/catch-bad-type.rs:27:29 - | -LL | let res: i32 = do catch { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied - | ^^^^^ the trait `std::ops::Try` is not implemented for `i32` - | - = note: required by `std::ops::Try::from_ok` - -error: aborting due to 5 previous errors - -Some errors occurred: E0271, E0277. -For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/catch/catch-in-match.stderr b/src/test/ui/catch/catch-in-match.stderr deleted file mode 100644 index 1542989cc359a..0000000000000 --- a/src/test/ui/catch/catch-in-match.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: expected expression, found reserved keyword `do` - --> $DIR/catch-in-match.rs:14:11 - | -LL | match do catch { false } { _ => {} } //~ ERROR expected expression, found reserved keyword `do` - | ^^ expected expression - -error: aborting due to previous error - diff --git a/src/test/ui/catch/catch-in-while.stderr b/src/test/ui/catch/catch-in-while.stderr deleted file mode 100644 index 9316bbcd4bcfb..0000000000000 --- a/src/test/ui/catch/catch-in-while.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: expected expression, found reserved keyword `do` - --> $DIR/catch-in-while.rs:14:11 - | -LL | while do catch { false } {} //~ ERROR expected expression, found reserved keyword `do` - | ^^ expected expression - -error: aborting due to previous error - diff --git a/src/test/ui/catch/catch-maybe-bad-lifetime.nll.stderr b/src/test/ui/catch/catch-maybe-bad-lifetime.nll.stderr deleted file mode 100644 index 157793160ce4e..0000000000000 --- a/src/test/ui/catch/catch-maybe-bad-lifetime.nll.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0382]: borrow of moved value: `x` - --> $DIR/catch-maybe-bad-lifetime.rs:33:24 - | -LL | ::std::mem::drop(x); - | - value moved here -LL | }; -LL | println!("{}", x); //~ ERROR use of moved value: `x` - | ^ value borrowed here after move - | - = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/catch/catch-maybe-bad-lifetime.stderr b/src/test/ui/catch/catch-maybe-bad-lifetime.stderr deleted file mode 100644 index 21fe1049f436e..0000000000000 --- a/src/test/ui/catch/catch-maybe-bad-lifetime.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error[E0506]: cannot assign to `i` because it is borrowed - --> $DIR/catch-maybe-bad-lifetime.rs:23:9 - | -LL | &i - | - borrow of `i` occurs here -... -LL | i = 0; //~ ERROR cannot assign to `i` because it is borrowed - | ^^^^^ assignment to borrowed `i` occurs here - -error[E0382]: use of moved value: `x` - --> $DIR/catch-maybe-bad-lifetime.rs:33:24 - | -LL | ::std::mem::drop(x); - | - value moved here -LL | }; -LL | println!("{}", x); //~ ERROR use of moved value: `x` - | ^ value used here after move - | - = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait - -error[E0506]: cannot assign to `i` because it is borrowed - --> $DIR/catch-maybe-bad-lifetime.rs:45:9 - | -LL | j = &i; - | - borrow of `i` occurs here -LL | }; -LL | i = 0; //~ ERROR cannot assign to `i` because it is borrowed - | ^^^^^ assignment to borrowed `i` occurs here - -error: aborting due to 3 previous errors - -Some errors occurred: E0382, E0506. -For more information about an error, try `rustc --explain E0382`. diff --git a/src/test/ui/catch/catch-opt-init.nll.stderr b/src/test/ui/catch/catch-opt-init.nll.stderr deleted file mode 100644 index ea8c8ebdcb7af..0000000000000 --- a/src/test/ui/catch/catch-opt-init.nll.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0381]: borrow of possibly uninitialized variable: `cfg_res` - --> $DIR/catch-opt-init.rs:23:5 - | -LL | assert_eq!(cfg_res, 5); //~ ERROR use of possibly uninitialized variable - | ^^^^^^^^^^^^^^^^^^^^^^^ use of possibly uninitialized `cfg_res` - | - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0381`. diff --git a/src/test/ui/catch/catch-opt-init.stderr b/src/test/ui/catch/catch-opt-init.stderr deleted file mode 100644 index 6a14ba17f9e80..0000000000000 --- a/src/test/ui/catch/catch-opt-init.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0381]: use of possibly uninitialized variable: `cfg_res` - --> $DIR/catch-opt-init.rs:23:16 - | -LL | assert_eq!(cfg_res, 5); //~ ERROR use of possibly uninitialized variable - | ^^^^^^^ use of possibly uninitialized `cfg_res` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0381`. diff --git a/src/test/ui/feature-gates/feature-gate-catch_expr.rs b/src/test/ui/feature-gates/feature-gate-catch_expr.rs index 5568a5cf0aac2..6536280c71f09 100644 --- a/src/test/ui/feature-gates/feature-gate-catch_expr.rs +++ b/src/test/ui/feature-gates/feature-gate-catch_expr.rs @@ -8,10 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: --edition 2018 + pub fn main() { - let catch_result = do catch { //~ ERROR `catch` expression is experimental + let try_result: Option<_> = try { //~ ERROR `try` expression is experimental let x = 5; x }; - assert_eq!(catch_result, 5); + assert_eq!(try_result, Some(5)); } diff --git a/src/test/ui/feature-gates/feature-gate-catch_expr.stderr b/src/test/ui/feature-gates/feature-gate-catch_expr.stderr index 4ab71460c0dac..4842215d51a57 100644 --- a/src/test/ui/feature-gates/feature-gate-catch_expr.stderr +++ b/src/test/ui/feature-gates/feature-gate-catch_expr.stderr @@ -1,8 +1,8 @@ -error[E0658]: `catch` expression is experimental (see issue #31436) - --> $DIR/feature-gate-catch_expr.rs:12:24 +error[E0658]: `try` expression is experimental (see issue #31436) + --> $DIR/feature-gate-catch_expr.rs:14:33 | -LL | let catch_result = do catch { //~ ERROR `catch` expression is experimental - | ________________________^ +LL | let try_result: Option<_> = try { //~ ERROR `try` expression is experimental + | _________________________________^ LL | | let x = 5; LL | | x LL | | }; diff --git a/src/test/ui/try-block-in-edition2015.rs b/src/test/ui/try-block-in-edition2015.rs new file mode 100644 index 0000000000000..64485bb8318f1 --- /dev/null +++ b/src/test/ui/try-block-in-edition2015.rs @@ -0,0 +1,20 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: --edition 2015 + +pub fn main() { + let try_result: Option<_> = try { + //~^ ERROR expected struct, variant or union type, found macro `try` + let x = 5; //~ ERROR expected identifier, found keyword + x + }; + assert_eq!(try_result, Some(5)); +} diff --git a/src/test/ui/try-block-in-edition2015.stderr b/src/test/ui/try-block-in-edition2015.stderr new file mode 100644 index 0000000000000..7e6d515e111d0 --- /dev/null +++ b/src/test/ui/try-block-in-edition2015.stderr @@ -0,0 +1,18 @@ +error: expected identifier, found keyword `let` + --> $DIR/try-block-in-edition2015.rs:16:9 + | +LL | let try_result: Option<_> = try { + | --- while parsing this struct +LL | //~^ ERROR expected struct, variant or union type, found macro `try` +LL | let x = 5; //~ ERROR expected identifier, found keyword + | ^^^ expected identifier, found keyword + +error[E0574]: expected struct, variant or union type, found macro `try` + --> $DIR/try-block-in-edition2015.rs:14:33 + | +LL | let try_result: Option<_> = try { + | ^^^ did you mean `try!(...)`? + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0574`. diff --git a/src/test/ui/catch/catch-block-type-error.rs b/src/test/ui/try-block-type-error.rs similarity index 87% rename from src/test/ui/catch/catch-block-type-error.rs rename to src/test/ui/try-block-type-error.rs index 10130ef1e5d1a..58b35e4630210 100644 --- a/src/test/ui/catch/catch-block-type-error.rs +++ b/src/test/ui/try-block-type-error.rs @@ -8,18 +8,20 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: --edition 2018 + #![feature(catch_expr)] fn foo() -> Option<()> { Some(()) } fn main() { - let _: Option = do catch { + let _: Option = try { foo()?; 42 //~^ ERROR type mismatch }; - let _: Option = do catch { + let _: Option = try { foo()?; }; //~^ ERROR type mismatch diff --git a/src/test/ui/catch/catch-block-type-error.stderr b/src/test/ui/try-block-type-error.stderr similarity index 88% rename from src/test/ui/catch/catch-block-type-error.stderr rename to src/test/ui/try-block-type-error.stderr index 288168c699263..3b67e92ec61bf 100644 --- a/src/test/ui/catch/catch-block-type-error.stderr +++ b/src/test/ui/try-block-type-error.stderr @@ -1,5 +1,5 @@ error[E0271]: type mismatch resolving ` as std::ops::Try>::Ok == {integer}` - --> $DIR/catch-block-type-error.rs:18:9 + --> $DIR/try-block-type-error.rs:20:9 | LL | 42 | ^^ @@ -11,7 +11,7 @@ LL | 42 found type `{integer}` error[E0271]: type mismatch resolving ` as std::ops::Try>::Ok == ()` - --> $DIR/catch-block-type-error.rs:24:5 + --> $DIR/try-block-type-error.rs:26:5 | LL | }; | ^ expected i32, found () From ef198867a73f24d4c3c50d246c1024a3bff3cee2 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 21 Jul 2018 23:23:15 -0700 Subject: [PATCH 05/21] Fix the unstable book I ignored the code block as I didn't see a way to run the doctest in 2018 -- I noticed the edition guide is also not testing its 2018 code snippits. --- .../src/language-features/catch-expr.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/doc/unstable-book/src/language-features/catch-expr.md b/src/doc/unstable-book/src/language-features/catch-expr.md index 247333d841ad0..5295d642aa6e9 100644 --- a/src/doc/unstable-book/src/language-features/catch-expr.md +++ b/src/doc/unstable-book/src/language-features/catch-expr.md @@ -6,22 +6,24 @@ The tracking issue for this feature is: [#31436] ------------------------ -The `catch_expr` feature adds support for a `catch` expression. The `catch` -expression creates a new scope one can use the `?` operator in. +The `catch_expr` feature adds support for `try` blocks. A `try` +block creates a new scope one can use the `?` operator in. + +```rust,ignore +// This code needs the 2018 edition -```rust #![feature(catch_expr)] use std::num::ParseIntError; -let result: Result = do catch { +let result: Result = try { "1".parse::()? + "2".parse::()? + "3".parse::()? }; assert_eq!(result, Ok(6)); -let result: Result = do catch { +let result: Result = try { "1".parse::()? + "foo".parse::()? + "3".parse::()? From 91967a8f163b44eb46bdac130ffded7752ae298c Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 22 Jul 2018 20:52:43 -0700 Subject: [PATCH 06/21] Put `try` in the reserved list, not the in-use list --- src/libsyntax_pos/symbol.rs | 17 +++++------------ src/test/compile-fail/try-block-in-match.rs | 2 +- src/test/compile-fail/try-block-in-while.rs | 2 +- .../keyword-try-as-identifier-edition2018.rs | 2 +- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index dc92ce56c791e..1eb76e7fe52fd 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -413,11 +413,9 @@ declare_keywords! { (49, Virtual, "virtual") (50, Yield, "yield") - // Edition-specific keywords currently in use. - (51, Try, "try") // >= 2018 Edition Only - // Edition-specific keywords reserved for future use. - (52, Async, "async") // >= 2018 Edition Only + (51, Async, "async") // >= 2018 Edition Only + (52, Try, "try") // >= 2018 Edition Only // Special lifetime names (53, UnderscoreLifetime, "'_") @@ -433,12 +431,9 @@ declare_keywords! { } impl Symbol { - fn is_used_keyword_2018(self) -> bool { - self == keywords::Try.name() - } - fn is_unused_keyword_2018(self) -> bool { - self == keywords::Async.name() + self >= keywords::Async.name() && + self <= keywords::Try.name() } } @@ -451,9 +446,7 @@ impl Ident { /// Returns `true` if the token is a keyword used in the language. pub fn is_used_keyword(self) -> bool { - // Note: `span.edition()` is relatively expensive, don't call it unless necessary. - self.name >= keywords::As.name() && self.name <= keywords::While.name() || - self.name.is_used_keyword_2018() && self.span.edition() == Edition::Edition2018 + self.name >= keywords::As.name() && self.name <= keywords::While.name() } /// Returns `true` if the token is a keyword reserved for possible future use. diff --git a/src/test/compile-fail/try-block-in-match.rs b/src/test/compile-fail/try-block-in-match.rs index 490b00a6f434b..1920caa548f09 100644 --- a/src/test/compile-fail/try-block-in-match.rs +++ b/src/test/compile-fail/try-block-in-match.rs @@ -13,5 +13,5 @@ #![feature(catch_expr)] fn main() { - match try { false } { _ => {} } //~ ERROR expected expression, found keyword `try` + match try { false } { _ => {} } //~ ERROR expected expression, found reserved keyword `try` } diff --git a/src/test/compile-fail/try-block-in-while.rs b/src/test/compile-fail/try-block-in-while.rs index a949e778f389c..fc1c08976141c 100644 --- a/src/test/compile-fail/try-block-in-while.rs +++ b/src/test/compile-fail/try-block-in-while.rs @@ -13,5 +13,5 @@ #![feature(catch_expr)] fn main() { - while try { false } {} //~ ERROR expected expression, found keyword `try` + while try { false } {} //~ ERROR expected expression, found reserved keyword `try` } diff --git a/src/test/parse-fail/keyword-try-as-identifier-edition2018.rs b/src/test/parse-fail/keyword-try-as-identifier-edition2018.rs index 1fe67313a3555..1e4f85c122d6c 100644 --- a/src/test/parse-fail/keyword-try-as-identifier-edition2018.rs +++ b/src/test/parse-fail/keyword-try-as-identifier-edition2018.rs @@ -11,5 +11,5 @@ // compile-flags: -Z parse-only --edition 2018 fn main() { - let try = "foo"; //~ error: expected pattern, found keyword `try` + let try = "foo"; //~ error: expected pattern, found reserved keyword `try` } From 817efc2489806b8188c2f5693fb3b0dcf9c76eb1 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Tue, 24 Jul 2018 17:55:36 -0700 Subject: [PATCH 07/21] Suggest `try` if someone uses `do catch` --- src/libsyntax/parse/parser.rs | 12 ++++++++++++ src/test/parse-fail/do-catch-suggests-try.rs | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/test/parse-fail/do-catch-suggests-try.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2b0cfd14a3d5a..ad57530474ce7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2386,6 +2386,11 @@ impl<'a> Parser<'a> { BlockCheckMode::Unsafe(ast::UserProvided), attrs); } + if self.is_do_catch_block() { + let mut db = self.fatal("found removed `do catch` syntax"); + db.help("Following RFC #2388, the new non-placeholder syntax is `try`"); + return Err(db); + } if self.is_try_block() { let lo = self.span; assert!(self.eat_keyword(keywords::Try)); @@ -4406,6 +4411,13 @@ impl<'a> Parser<'a> { ) } + fn is_do_catch_block(&mut self) -> bool { + self.token.is_keyword(keywords::Do) && + self.look_ahead(1, |t| t.is_keyword(keywords::Catch)) && + self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace)) && + !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL) + } + fn is_try_block(&mut self) -> bool { self.token.is_keyword(keywords::Try) && self.look_ahead(1, |t| *t == token::OpenDelim(token::Brace)) && diff --git a/src/test/parse-fail/do-catch-suggests-try.rs b/src/test/parse-fail/do-catch-suggests-try.rs new file mode 100644 index 0000000000000..449135e69c319 --- /dev/null +++ b/src/test/parse-fail/do-catch-suggests-try.rs @@ -0,0 +1,17 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z parse-only + +fn main() { + let _: Option<()> = do catch {}; + //~^ ERROR found removed `do catch` syntax + //~^^ HELP Following RFC #2388, the new non-placeholder syntax is `try` +} From 9f683bed3dfa6516bbe81b6e58a9a8f2f00b1250 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Tue, 24 Jul 2018 18:03:25 -0700 Subject: [PATCH 08/21] Rename `catch_expr` feature to `try_blocks` --- .../src/language-features/{catch-expr.md => try-blocks.md} | 6 +++--- src/librustc/lib.rs | 1 - src/libsyntax/feature_gate.rs | 4 ++-- src/test/compile-fail/try-block-bad-lifetime.rs | 2 +- src/test/compile-fail/try-block-bad-type.rs | 2 +- src/test/compile-fail/try-block-in-match.rs | 2 +- src/test/compile-fail/try-block-in-while.rs | 2 +- src/test/compile-fail/try-block-maybe-bad-lifetime.rs | 2 +- src/test/compile-fail/try-block-opt-init.rs | 2 +- src/test/run-pass/issue-45124.rs | 2 +- src/test/run-pass/try-block.rs | 2 +- ...eature-gate-catch_expr.rs => feature-gate-try_blocks.rs} | 0 ...ate-catch_expr.stderr => feature-gate-try_blocks.stderr} | 4 ++-- src/test/ui/try-block-type-error.rs | 2 +- 14 files changed, 16 insertions(+), 17 deletions(-) rename src/doc/unstable-book/src/language-features/{catch-expr.md => try-blocks.md} (85%) rename src/test/ui/feature-gates/{feature-gate-catch_expr.rs => feature-gate-try_blocks.rs} (100%) rename src/test/ui/feature-gates/{feature-gate-catch_expr.stderr => feature-gate-try_blocks.stderr} (78%) diff --git a/src/doc/unstable-book/src/language-features/catch-expr.md b/src/doc/unstable-book/src/language-features/try-blocks.md similarity index 85% rename from src/doc/unstable-book/src/language-features/catch-expr.md rename to src/doc/unstable-book/src/language-features/try-blocks.md index 5295d642aa6e9..866b37a39a781 100644 --- a/src/doc/unstable-book/src/language-features/catch-expr.md +++ b/src/doc/unstable-book/src/language-features/try-blocks.md @@ -1,4 +1,4 @@ -# `catch_expr` +# `try_blocks` The tracking issue for this feature is: [#31436] @@ -6,13 +6,13 @@ The tracking issue for this feature is: [#31436] ------------------------ -The `catch_expr` feature adds support for `try` blocks. A `try` +The `try_blocks` feature adds support for `try` blocks. A `try` block creates a new scope one can use the `?` operator in. ```rust,ignore // This code needs the 2018 edition -#![feature(catch_expr)] +#![feature(try_blocks)] use std::num::ParseIntError; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index b6f4bd6dc408c..7e937c5fc0525 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -65,7 +65,6 @@ #![feature(trace_macros)] #![feature(trusted_len)] #![feature(vec_remove_item)] -#![feature(catch_expr)] #![feature(step_trait)] #![feature(integer_atomics)] #![feature(test)] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index f796c0e2e535b..c89efcf4ba0e8 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -331,7 +331,7 @@ declare_features! ( (active, abi_x86_interrupt, "1.17.0", Some(40180), None), // Allows the `try {...}` expression - (active, catch_expr, "1.17.0", Some(31436), None), + (active, try_blocks, "1.29.0", Some(31436), None), // Used to preserve symbols (see llvm.used) (active, used, "1.18.0", Some(40289), None), @@ -1735,7 +1735,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "yield syntax is experimental"); } ast::ExprKind::TryBlock(_) => { - gate_feature_post!(&self, catch_expr, e.span, "`try` expression is experimental"); + gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental"); } ast::ExprKind::IfLet(ref pats, ..) | ast::ExprKind::WhileLet(ref pats, ..) => { if pats.len() > 1 { diff --git a/src/test/compile-fail/try-block-bad-lifetime.rs b/src/test/compile-fail/try-block-bad-lifetime.rs index 8dfd8545af7a5..61de6baecd7e4 100644 --- a/src/test/compile-fail/try-block-bad-lifetime.rs +++ b/src/test/compile-fail/try-block-bad-lifetime.rs @@ -10,7 +10,7 @@ // compile-flags: --edition 2018 -#![feature(catch_expr)] +#![feature(try_blocks)] // This test checks that borrows made and returned inside try blocks are properly constrained pub fn main() { diff --git a/src/test/compile-fail/try-block-bad-type.rs b/src/test/compile-fail/try-block-bad-type.rs index 9e555df8535e5..a984b63af4575 100644 --- a/src/test/compile-fail/try-block-bad-type.rs +++ b/src/test/compile-fail/try-block-bad-type.rs @@ -10,7 +10,7 @@ // compile-flags: --edition 2018 -#![feature(catch_expr)] +#![feature(try_blocks)] pub fn main() { let res: Result = try { diff --git a/src/test/compile-fail/try-block-in-match.rs b/src/test/compile-fail/try-block-in-match.rs index 1920caa548f09..d10149126ee89 100644 --- a/src/test/compile-fail/try-block-in-match.rs +++ b/src/test/compile-fail/try-block-in-match.rs @@ -10,7 +10,7 @@ // compile-flags: --edition 2018 -#![feature(catch_expr)] +#![feature(try_blocks)] fn main() { match try { false } { _ => {} } //~ ERROR expected expression, found reserved keyword `try` diff --git a/src/test/compile-fail/try-block-in-while.rs b/src/test/compile-fail/try-block-in-while.rs index fc1c08976141c..b531267a55bba 100644 --- a/src/test/compile-fail/try-block-in-while.rs +++ b/src/test/compile-fail/try-block-in-while.rs @@ -10,7 +10,7 @@ // compile-flags: --edition 2018 -#![feature(catch_expr)] +#![feature(try_blocks)] fn main() { while try { false } {} //~ ERROR expected expression, found reserved keyword `try` diff --git a/src/test/compile-fail/try-block-maybe-bad-lifetime.rs b/src/test/compile-fail/try-block-maybe-bad-lifetime.rs index db37a397c16ad..297540bb1e7d2 100644 --- a/src/test/compile-fail/try-block-maybe-bad-lifetime.rs +++ b/src/test/compile-fail/try-block-maybe-bad-lifetime.rs @@ -10,7 +10,7 @@ // compile-flags: --edition 2018 -#![feature(catch_expr)] +#![feature(try_blocks)] // This test checks that borrows made and returned inside try blocks are properly constrained pub fn main() { diff --git a/src/test/compile-fail/try-block-opt-init.rs b/src/test/compile-fail/try-block-opt-init.rs index 14544c6ea0ccc..476fec2022093 100644 --- a/src/test/compile-fail/try-block-opt-init.rs +++ b/src/test/compile-fail/try-block-opt-init.rs @@ -10,7 +10,7 @@ // compile-flags: --edition 2018 -#![feature(catch_expr)] +#![feature(try_blocks)] fn use_val(_x: T) {} diff --git a/src/test/run-pass/issue-45124.rs b/src/test/run-pass/issue-45124.rs index 5f47cc8d7d554..cb79eda8b0739 100644 --- a/src/test/run-pass/issue-45124.rs +++ b/src/test/run-pass/issue-45124.rs @@ -10,7 +10,7 @@ // compile-flags: --edition 2018 -#![feature(catch_expr)] +#![feature(try_blocks)] fn main() { let mut a = 0; diff --git a/src/test/run-pass/try-block.rs b/src/test/run-pass/try-block.rs index f2b017e94f08f..a7e7cc2062095 100644 --- a/src/test/run-pass/try-block.rs +++ b/src/test/run-pass/try-block.rs @@ -10,7 +10,7 @@ // compile-flags: --edition 2018 -#![feature(catch_expr)] +#![feature(try_blocks)] struct catch {} diff --git a/src/test/ui/feature-gates/feature-gate-catch_expr.rs b/src/test/ui/feature-gates/feature-gate-try_blocks.rs similarity index 100% rename from src/test/ui/feature-gates/feature-gate-catch_expr.rs rename to src/test/ui/feature-gates/feature-gate-try_blocks.rs diff --git a/src/test/ui/feature-gates/feature-gate-catch_expr.stderr b/src/test/ui/feature-gates/feature-gate-try_blocks.stderr similarity index 78% rename from src/test/ui/feature-gates/feature-gate-catch_expr.stderr rename to src/test/ui/feature-gates/feature-gate-try_blocks.stderr index 4842215d51a57..29ef2f87b9d0d 100644 --- a/src/test/ui/feature-gates/feature-gate-catch_expr.stderr +++ b/src/test/ui/feature-gates/feature-gate-try_blocks.stderr @@ -1,5 +1,5 @@ error[E0658]: `try` expression is experimental (see issue #31436) - --> $DIR/feature-gate-catch_expr.rs:14:33 + --> $DIR/feature-gate-try_blocks.rs:14:33 | LL | let try_result: Option<_> = try { //~ ERROR `try` expression is experimental | _________________________________^ @@ -8,7 +8,7 @@ LL | | x LL | | }; | |_____^ | - = help: add #![feature(catch_expr)] to the crate attributes to enable + = help: add #![feature(try_blocks)] to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/try-block-type-error.rs b/src/test/ui/try-block-type-error.rs index 58b35e4630210..6a69cff48836f 100644 --- a/src/test/ui/try-block-type-error.rs +++ b/src/test/ui/try-block-type-error.rs @@ -10,7 +10,7 @@ // compile-flags: --edition 2018 -#![feature(catch_expr)] +#![feature(try_blocks)] fn foo() -> Option<()> { Some(()) } From 5cf387c4f41fd0afc01650e896e865c90d387d31 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 28 Jul 2018 01:06:11 -0700 Subject: [PATCH 09/21] Update try-block tests to work under NLL --- src/test/compile-fail/try-block-bad-lifetime.rs | 6 +++++- .../compile-fail/try-block-maybe-bad-lifetime.rs | 12 ++++++++---- src/test/compile-fail/try-block-opt-init.rs | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/test/compile-fail/try-block-bad-lifetime.rs b/src/test/compile-fail/try-block-bad-lifetime.rs index 61de6baecd7e4..576a0202018b6 100644 --- a/src/test/compile-fail/try-block-bad-lifetime.rs +++ b/src/test/compile-fail/try-block-bad-lifetime.rs @@ -12,18 +12,22 @@ #![feature(try_blocks)] +#![inline(never)] +fn do_something_with(_x: T) {} + // This test checks that borrows made and returned inside try blocks are properly constrained pub fn main() { { // Test that borrows returned from a try block must be valid for the lifetime of the // result variable - let _result: Result<(), &str> = try { + let result: Result<(), &str> = try { let my_string = String::from(""); let my_str: & str = & my_string; //~^ ERROR `my_string` does not live long enough Err(my_str) ?; Err("") ?; }; + do_something_with(result); } { diff --git a/src/test/compile-fail/try-block-maybe-bad-lifetime.rs b/src/test/compile-fail/try-block-maybe-bad-lifetime.rs index 297540bb1e7d2..b5e0ebdbc222e 100644 --- a/src/test/compile-fail/try-block-maybe-bad-lifetime.rs +++ b/src/test/compile-fail/try-block-maybe-bad-lifetime.rs @@ -12,6 +12,9 @@ #![feature(try_blocks)] +#![inline(never)] +fn do_something_with(_x: T) {} + // This test checks that borrows made and returned inside try blocks are properly constrained pub fn main() { { @@ -21,9 +24,9 @@ pub fn main() { Err(())?; &i }; - x.ok().cloned(); i = 0; //~ ERROR cannot assign to `i` because it is borrowed let _ = i; + do_something_with(x); } { @@ -32,20 +35,21 @@ pub fn main() { Err(())?; ::std::mem::drop(x); }; - println!("{}", x); //~ ERROR use of moved value: `x` + println!("{}", x); //~ ERROR borrow of moved value: `x` } { // Test that a borrow which *might* be assigned to an outer variable still freezes // its referent let mut i = 222; - let j; - let x: Result<(), ()> = try { + let mut j = &-1; + let _x: Result<(), ()> = try { Err(())?; j = &i; }; i = 0; //~ ERROR cannot assign to `i` because it is borrowed let _ = i; + do_something_with(j); } } diff --git a/src/test/compile-fail/try-block-opt-init.rs b/src/test/compile-fail/try-block-opt-init.rs index 476fec2022093..ca81a9c311037 100644 --- a/src/test/compile-fail/try-block-opt-init.rs +++ b/src/test/compile-fail/try-block-opt-init.rs @@ -22,6 +22,6 @@ pub fn main() { Ok::<(), ()>(())?; use_val(cfg_res); }; - assert_eq!(cfg_res, 5); //~ ERROR use of possibly uninitialized variable + assert_eq!(cfg_res, 5); //~ ERROR borrow of possibly uninitialized variable: `cfg_res` } From e4280852ae8ff32494c1ca6e4fe76e9e4a15dd31 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 12 Aug 2018 20:05:29 -0700 Subject: [PATCH 10/21] Make a try-blocks folder for all the try{} UI tests --- .../try-block}/try-block-bad-lifetime.rs | 0 .../try-block/try-block-bad-lifetime.stderr | 50 ++++++++++++++++++ .../try-block}/try-block-bad-type.rs | 0 .../ui/try-block/try-block-bad-type.stderr | 52 +++++++++++++++++++ .../try-block-in-edition2015.rs | 0 .../try-block-in-edition2015.stderr | 0 .../try-block}/try-block-in-match.rs | 0 .../ui/try-block/try-block-in-match.stderr | 8 +++ .../try-block}/try-block-in-while.rs | 0 .../ui/try-block/try-block-in-while.stderr | 8 +++ .../try-block-maybe-bad-lifetime.rs | 0 .../try-block-maybe-bad-lifetime.stderr | 39 ++++++++++++++ .../try-block}/try-block-opt-init.rs | 0 .../ui/try-block/try-block-opt-init.stderr | 11 ++++ .../{ => try-block}/try-block-type-error.rs | 0 .../try-block-type-error.stderr | 0 16 files changed, 168 insertions(+) rename src/test/{compile-fail => ui/try-block}/try-block-bad-lifetime.rs (100%) create mode 100644 src/test/ui/try-block/try-block-bad-lifetime.stderr rename src/test/{compile-fail => ui/try-block}/try-block-bad-type.rs (100%) create mode 100644 src/test/ui/try-block/try-block-bad-type.stderr rename src/test/ui/{ => try-block}/try-block-in-edition2015.rs (100%) rename src/test/ui/{ => try-block}/try-block-in-edition2015.stderr (100%) rename src/test/{compile-fail => ui/try-block}/try-block-in-match.rs (100%) create mode 100644 src/test/ui/try-block/try-block-in-match.stderr rename src/test/{compile-fail => ui/try-block}/try-block-in-while.rs (100%) create mode 100644 src/test/ui/try-block/try-block-in-while.stderr rename src/test/{compile-fail => ui/try-block}/try-block-maybe-bad-lifetime.rs (100%) create mode 100644 src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr rename src/test/{compile-fail => ui/try-block}/try-block-opt-init.rs (100%) create mode 100644 src/test/ui/try-block/try-block-opt-init.stderr rename src/test/ui/{ => try-block}/try-block-type-error.rs (100%) rename src/test/ui/{ => try-block}/try-block-type-error.stderr (100%) diff --git a/src/test/compile-fail/try-block-bad-lifetime.rs b/src/test/ui/try-block/try-block-bad-lifetime.rs similarity index 100% rename from src/test/compile-fail/try-block-bad-lifetime.rs rename to src/test/ui/try-block/try-block-bad-lifetime.rs diff --git a/src/test/ui/try-block/try-block-bad-lifetime.stderr b/src/test/ui/try-block/try-block-bad-lifetime.stderr new file mode 100644 index 0000000000000..36c89faf5a2ca --- /dev/null +++ b/src/test/ui/try-block/try-block-bad-lifetime.stderr @@ -0,0 +1,50 @@ +error[E0597]: `my_string` does not live long enough + --> $DIR/try-block-bad-lifetime.rs:25:33 + | +LL | let my_str: & str = & my_string; + | ^^^^^^^^^^^ borrowed value does not live long enough +... +LL | }; + | - `my_string` dropped here while still borrowed +LL | do_something_with(result); + | ------ borrow later used here + +error[E0506]: cannot assign to `i` because it is borrowed + --> $DIR/try-block-bad-lifetime.rs:39:13 + | +LL | let k = &mut i; + | ------ borrow of `i` occurs here +... +LL | i = 10; //~ ERROR cannot assign to `i` because it is borrowed + | ^^^^^^ assignment to borrowed `i` occurs here +LL | }; +LL | ::std::mem::drop(k); //~ ERROR use of moved value: `k` + | - borrow later used here + +error[E0382]: use of moved value: `k` + --> $DIR/try-block-bad-lifetime.rs:41:26 + | +LL | Err(k) ?; + | - value moved here +... +LL | ::std::mem::drop(k); //~ ERROR use of moved value: `k` + | ^ value used here after move + | + = note: move occurs because `k` has type `&mut i32`, which does not implement the `Copy` trait + +error[E0506]: cannot assign to `i` because it is borrowed + --> $DIR/try-block-bad-lifetime.rs:42:9 + | +LL | let k = &mut i; + | ------ borrow of `i` occurs here +... +LL | i = 40; //~ ERROR cannot assign to `i` because it is borrowed + | ^^^^^^ assignment to borrowed `i` occurs here +LL | +LL | let i_ptr = if let Err(i_ptr) = j { i_ptr } else { panic ! ("") }; + | - borrow later used here + +error: aborting due to 4 previous errors + +Some errors occurred: E0382, E0506, E0597. +For more information about an error, try `rustc --explain E0382`. diff --git a/src/test/compile-fail/try-block-bad-type.rs b/src/test/ui/try-block/try-block-bad-type.rs similarity index 100% rename from src/test/compile-fail/try-block-bad-type.rs rename to src/test/ui/try-block/try-block-bad-type.rs diff --git a/src/test/ui/try-block/try-block-bad-type.stderr b/src/test/ui/try-block/try-block-bad-type.stderr new file mode 100644 index 0000000000000..159e43e13e405 --- /dev/null +++ b/src/test/ui/try-block/try-block-bad-type.stderr @@ -0,0 +1,52 @@ +error[E0277]: the trait bound `i32: std::convert::From<&str>` is not satisfied + --> $DIR/try-block-bad-type.rs:17:9 + | +LL | Err("")?; //~ ERROR the trait bound `i32: std::convert::From<&str>` is not satisfied + | ^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `i32` + | + = help: the following implementations were found: + > + > + > + > + > + = note: required by `std::convert::From::from` + +error[E0271]: type mismatch resolving ` as std::ops::Try>::Ok == &str` + --> $DIR/try-block-bad-type.rs:22:9 + | +LL | "" //~ ERROR type mismatch + | ^^ expected i32, found &str + | + = note: expected type `i32` + found type `&str` + +error[E0271]: type mismatch resolving ` as std::ops::Try>::Ok == ()` + --> $DIR/try-block-bad-type.rs:25:39 + | +LL | let res: Result = try { }; //~ ERROR type mismatch + | ^ expected i32, found () + | + = note: expected type `i32` + found type `()` + +error[E0277]: the trait bound `(): std::ops::Try` is not satisfied + --> $DIR/try-block-bad-type.rs:27:23 + | +LL | let res: () = try { }; //~ the trait bound `(): std::ops::Try` is not satisfied + | ^^^ the trait `std::ops::Try` is not implemented for `()` + | + = note: required by `std::ops::Try::from_ok` + +error[E0277]: the trait bound `i32: std::ops::Try` is not satisfied + --> $DIR/try-block-bad-type.rs:29:24 + | +LL | let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied + | ^^^^^ the trait `std::ops::Try` is not implemented for `i32` + | + = note: required by `std::ops::Try::from_ok` + +error: aborting due to 5 previous errors + +Some errors occurred: E0271, E0277. +For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/try-block-in-edition2015.rs b/src/test/ui/try-block/try-block-in-edition2015.rs similarity index 100% rename from src/test/ui/try-block-in-edition2015.rs rename to src/test/ui/try-block/try-block-in-edition2015.rs diff --git a/src/test/ui/try-block-in-edition2015.stderr b/src/test/ui/try-block/try-block-in-edition2015.stderr similarity index 100% rename from src/test/ui/try-block-in-edition2015.stderr rename to src/test/ui/try-block/try-block-in-edition2015.stderr diff --git a/src/test/compile-fail/try-block-in-match.rs b/src/test/ui/try-block/try-block-in-match.rs similarity index 100% rename from src/test/compile-fail/try-block-in-match.rs rename to src/test/ui/try-block/try-block-in-match.rs diff --git a/src/test/ui/try-block/try-block-in-match.stderr b/src/test/ui/try-block/try-block-in-match.stderr new file mode 100644 index 0000000000000..f07d23885aca1 --- /dev/null +++ b/src/test/ui/try-block/try-block-in-match.stderr @@ -0,0 +1,8 @@ +error: expected expression, found reserved keyword `try` + --> $DIR/try-block-in-match.rs:16:11 + | +LL | match try { false } { _ => {} } //~ ERROR expected expression, found reserved keyword `try` + | ^^^ expected expression + +error: aborting due to previous error + diff --git a/src/test/compile-fail/try-block-in-while.rs b/src/test/ui/try-block/try-block-in-while.rs similarity index 100% rename from src/test/compile-fail/try-block-in-while.rs rename to src/test/ui/try-block/try-block-in-while.rs diff --git a/src/test/ui/try-block/try-block-in-while.stderr b/src/test/ui/try-block/try-block-in-while.stderr new file mode 100644 index 0000000000000..36577d784b83f --- /dev/null +++ b/src/test/ui/try-block/try-block-in-while.stderr @@ -0,0 +1,8 @@ +error: expected expression, found reserved keyword `try` + --> $DIR/try-block-in-while.rs:16:11 + | +LL | while try { false } {} //~ ERROR expected expression, found reserved keyword `try` + | ^^^ expected expression + +error: aborting due to previous error + diff --git a/src/test/compile-fail/try-block-maybe-bad-lifetime.rs b/src/test/ui/try-block/try-block-maybe-bad-lifetime.rs similarity index 100% rename from src/test/compile-fail/try-block-maybe-bad-lifetime.rs rename to src/test/ui/try-block/try-block-maybe-bad-lifetime.rs diff --git a/src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr b/src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr new file mode 100644 index 0000000000000..366a8da4b6e83 --- /dev/null +++ b/src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr @@ -0,0 +1,39 @@ +error[E0506]: cannot assign to `i` because it is borrowed + --> $DIR/try-block-maybe-bad-lifetime.rs:27:9 + | +LL | &i + | -- borrow of `i` occurs here +LL | }; +LL | i = 0; //~ ERROR cannot assign to `i` because it is borrowed + | ^^^^^ assignment to borrowed `i` occurs here +LL | let _ = i; +LL | do_something_with(x); + | - borrow later used here + +error[E0382]: borrow of moved value: `x` + --> $DIR/try-block-maybe-bad-lifetime.rs:38:24 + | +LL | ::std::mem::drop(x); + | - value moved here +LL | }; +LL | println!("{}", x); //~ ERROR borrow of moved value: `x` + | ^ value borrowed here after move + | + = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait + +error[E0506]: cannot assign to `i` because it is borrowed + --> $DIR/try-block-maybe-bad-lifetime.rs:50:9 + | +LL | j = &i; + | -- borrow of `i` occurs here +LL | }; +LL | i = 0; //~ ERROR cannot assign to `i` because it is borrowed + | ^^^^^ assignment to borrowed `i` occurs here +LL | let _ = i; +LL | do_something_with(j); + | - borrow later used here + +error: aborting due to 3 previous errors + +Some errors occurred: E0382, E0506. +For more information about an error, try `rustc --explain E0382`. diff --git a/src/test/compile-fail/try-block-opt-init.rs b/src/test/ui/try-block/try-block-opt-init.rs similarity index 100% rename from src/test/compile-fail/try-block-opt-init.rs rename to src/test/ui/try-block/try-block-opt-init.rs diff --git a/src/test/ui/try-block/try-block-opt-init.stderr b/src/test/ui/try-block/try-block-opt-init.stderr new file mode 100644 index 0000000000000..3ebcb7dc37af1 --- /dev/null +++ b/src/test/ui/try-block/try-block-opt-init.stderr @@ -0,0 +1,11 @@ +error[E0381]: borrow of possibly uninitialized variable: `cfg_res` + --> $DIR/try-block-opt-init.rs:25:5 + | +LL | assert_eq!(cfg_res, 5); //~ ERROR borrow of possibly uninitialized variable: `cfg_res` + | ^^^^^^^^^^^^^^^^^^^^^^^ use of possibly uninitialized `cfg_res` + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0381`. diff --git a/src/test/ui/try-block-type-error.rs b/src/test/ui/try-block/try-block-type-error.rs similarity index 100% rename from src/test/ui/try-block-type-error.rs rename to src/test/ui/try-block/try-block-type-error.rs diff --git a/src/test/ui/try-block-type-error.stderr b/src/test/ui/try-block/try-block-type-error.stderr similarity index 100% rename from src/test/ui/try-block-type-error.stderr rename to src/test/ui/try-block/try-block-type-error.stderr From 009547141729b6d66f721065820edf9ddbde4831 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 19 Aug 2018 17:51:02 -0700 Subject: [PATCH 11/21] Switch out another use of `do catch` --- src/libsyntax/lib.rs | 2 +- src/libsyntax/parse/parser.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 0a42325d2b6ff..0b9d53b5af45e 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -26,8 +26,8 @@ #![feature(rustc_diagnostic_macros)] #![feature(slice_sort_by_cached_key)] #![feature(str_escape)] +#![feature(try_trait)] #![feature(unicode_internals)] -#![feature(catch_expr)] #![recursion_limit="256"] diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ad57530474ce7..b766fbd0d71b7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1756,9 +1756,17 @@ impl<'a> Parser<'a> { let parser_snapshot_before_pat = self.clone(); + // Once we can use edition 2018 in the compiler, + // replace this with real try blocks. + macro_rules! try_block { + ($($inside:tt)*) => ( + (||{ ::std::ops::Try::from_ok({ $($inside)* }) })() + ) + } + // We're going to try parsing the argument as a pattern (even though it's not // allowed). This way we can provide better errors to the user. - let pat_arg: PResult<'a, _> = do catch { + let pat_arg: PResult<'a, _> = try_block! { let pat = self.parse_pat()?; self.expect(&token::Colon)?; (pat, self.parse_ty()?) From 04b50e22bb978f10d90df78a377f23fd122a8d83 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 17 Aug 2018 10:41:14 +1000 Subject: [PATCH 12/21] Convert `AllSets::on_entry_sets` to a `Vec>`. This makes it more like `AllSets::{gen,kill}_set`, removes the need for a bunch of bitset range computations, and removes the need for `Bits`. It's marginally less efficient, because we have to allocate one bitset per basic block instead of one large shared bitset, but the difference is negligible in practice. --- src/librustc_mir/dataflow/mod.rs | 54 +++++++++----------------------- 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index 56c4dac19e504..0881b66e5508b 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -10,7 +10,7 @@ use syntax::ast::{self, MetaItem}; -use rustc_data_structures::bitslice::{bitwise, BitwiseOperator, Word}; +use rustc_data_structures::bitslice::{bitwise, BitwiseOperator}; use rustc_data_structures::indexed_set::{HybridIdxSetBuf, IdxSet, IdxSetBuf}; use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::work_queue::WorkQueue; @@ -23,7 +23,6 @@ use rustc::session::Session; use std::borrow::Borrow; use std::fmt; use std::io; -use std::mem; use std::path::PathBuf; use std::usize; @@ -287,18 +286,6 @@ impl<'a, 'tcx: 'a, BD> DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation } } -/// Maps each block to a set of bits -#[derive(Clone, Debug)] -pub(crate) struct Bits { - bits: IdxSetBuf, -} - -impl Bits { - fn new(bits: IdxSetBuf) -> Self { - Bits { bits: bits } - } -} - /// DataflowResultsConsumer abstracts over walking the MIR with some /// already constructed dataflow results. /// @@ -464,12 +451,8 @@ pub struct AllSets { /// Analysis bitwidth for each block. bits_per_block: usize, - /// Number of words associated with each block entry - /// equal to bits_per_block / (mem::size_of:: * 8), rounded up. - words_per_block: usize, - /// For each block, bits valid on entry to the block. - on_entry_sets: Bits, + on_entry_sets: Vec>, /// For each block, bits generated by executing the statements in /// the block. (For comparison, the Terminator for each block is @@ -559,19 +542,15 @@ impl<'a, E:Idx> BlockSets<'a, E> { impl AllSets { pub fn bits_per_block(&self) -> usize { self.bits_per_block } pub fn for_block(&mut self, block_idx: usize) -> BlockSets { - let offset = self.words_per_block * block_idx; - let range = E::new(offset)..E::new(offset + self.words_per_block); BlockSets { - on_entry: self.on_entry_sets.bits.range_mut(&range), + on_entry: &mut self.on_entry_sets[block_idx], gen_set: &mut self.gen_sets[block_idx], kill_set: &mut self.kill_sets[block_idx], } } - pub fn on_entry_set_for(&self, block_idx: usize) -> &IdxSet { - let offset = self.words_per_block * block_idx; - let range = E::new(offset)..E::new(offset + self.words_per_block); - self.on_entry_sets.bits.range(&range) + pub fn on_entry_set_for(&self, block_idx: usize) -> &IdxSetBuf { + &self.on_entry_sets[block_idx] } pub fn gen_set_for(&self, block_idx: usize) -> &HybridIdxSetBuf { &self.gen_sets[block_idx] @@ -731,18 +710,15 @@ impl<'a, 'tcx, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation dead_unwinds: &'a IdxSet, denotation: D) -> Self where D: InitialFlow { let bits_per_block = denotation.bits_per_block(); - let bits_per_word = mem::size_of::() * 8; - let words_per_block = (bits_per_block + bits_per_word - 1) / bits_per_word; - let bits_per_block_rounded_up = words_per_block * bits_per_word; // a multiple of word size let num_blocks = mir.basic_blocks().len(); - let num_overall = num_blocks * bits_per_block_rounded_up; - let on_entry = Bits::new(if D::bottom_value() { - IdxSetBuf::new_filled(num_overall) + let on_entry_sets = if D::bottom_value() { + vec![IdxSetBuf::new_filled(bits_per_block); num_blocks] } else { - IdxSetBuf::new_empty(num_overall) - }); - let empties = vec![HybridIdxSetBuf::new_empty(bits_per_block); num_blocks]; + vec![IdxSetBuf::new_empty(bits_per_block); num_blocks] + }; + let gen_sets = vec![HybridIdxSetBuf::new_empty(bits_per_block); num_blocks]; + let kill_sets = gen_sets.clone(); DataflowAnalysis { mir, @@ -750,10 +726,9 @@ impl<'a, 'tcx, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation flow_state: DataflowState { sets: AllSets { bits_per_block, - words_per_block, - on_entry_sets: on_entry, - gen_sets: empties.clone(), - kill_sets: empties, + on_entry_sets, + gen_sets, + kill_sets, }, operator: denotation, } @@ -873,5 +848,4 @@ impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation dirty_queue.insert(bb); } } - } From ab8dfbc7bb969378c2d7e8f7b0c29e26100707e0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 17 Aug 2018 13:32:11 +1000 Subject: [PATCH 13/21] Merge `IdxSet` and `IdxSetBuf`. The `Buf` vs. non-`Buf` distinction is no longer necessary, and the nastiest code in this file can be removed. To minimize this patch, `IdxSet` is made a typedef of `IdxSetBuf`. The next patch will remove this typedef. --- src/librustc_data_structures/indexed_set.rs | 93 ++------------------- 1 file changed, 5 insertions(+), 88 deletions(-) diff --git a/src/librustc_data_structures/indexed_set.rs b/src/librustc_data_structures/indexed_set.rs index a7672d1ffe891..6c64e5de37807 100644 --- a/src/librustc_data_structures/indexed_set.rs +++ b/src/librustc_data_structures/indexed_set.rs @@ -9,20 +9,18 @@ // except according to those terms. use array_vec::ArrayVec; -use std::borrow::{Borrow, BorrowMut, ToOwned}; use std::fmt; use std::iter; use std::marker::PhantomData; use std::mem; -use std::ops::{Deref, DerefMut, Range}; use std::slice; use bitslice::{BitSlice, Word}; use bitslice::{bitwise, Union, Subtract, Intersect}; use indexed_vec::Idx; use rustc_serialize; -/// Represents a set (or packed family of sets), of some element type -/// E, where each E is identified by some unique index type `T`. +/// Represents a set of some element type E, where each E is identified by some +/// unique index type `T`. /// /// In other words, `T` is the type used to index into the bitvector /// this type uses to represent the set of object it holds. @@ -34,6 +32,9 @@ pub struct IdxSetBuf { bits: Vec, } +// FIXME: temporary +pub type IdxSet = IdxSetBuf; + impl Clone for IdxSetBuf { fn clone(&self) -> Self { IdxSetBuf { _pd: PhantomData, bits: self.bits.clone() } @@ -59,40 +60,6 @@ impl rustc_serialize::Decodable for IdxSetBuf { } } - -// pnkfelix wants to have this be `IdxSet([Word]) and then pass -// around `&mut IdxSet` or `&IdxSet`. - -/// Represents a set (or packed family of sets), of some element type -/// E, where each E is identified by some unique index type `T`. -/// -/// In other words, `T` is the type used to index into the bitslice -/// this type uses to represent the set of object it holds. -#[repr(transparent)] -pub struct IdxSet { - _pd: PhantomData, - bits: [Word], -} - -impl Borrow> for IdxSetBuf { - fn borrow(&self) -> &IdxSet { - &*self - } -} - -impl BorrowMut> for IdxSetBuf { - fn borrow_mut(&mut self) -> &mut IdxSet { - &mut *self - } -} - -impl ToOwned for IdxSet { - type Owned = IdxSetBuf; - fn to_owned(&self) -> Self::Owned { - IdxSet::to_owned(self) - } -} - const BITS_PER_WORD: usize = mem::size_of::() * 8; impl fmt::Debug for IdxSetBuf { @@ -103,14 +70,6 @@ impl fmt::Debug for IdxSetBuf { } } -impl fmt::Debug for IdxSet { - fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { - w.debug_list() - .entries(self.iter()) - .finish() - } -} - impl IdxSetBuf { fn new(init: Word, universe_size: usize) -> Self { let num_words = (universe_size + (BITS_PER_WORD - 1)) / BITS_PER_WORD; @@ -131,38 +90,6 @@ impl IdxSetBuf { pub fn new_empty(universe_size: usize) -> Self { Self::new(0, universe_size) } -} - -impl IdxSet { - unsafe fn from_slice(s: &[Word]) -> &Self { - &*(s as *const [Word] as *const Self) - } - - unsafe fn from_slice_mut(s: &mut [Word]) -> &mut Self { - &mut *(s as *mut [Word] as *mut Self) - } -} - -impl Deref for IdxSetBuf { - type Target = IdxSet; - fn deref(&self) -> &IdxSet { - unsafe { IdxSet::from_slice(&self.bits) } - } -} - -impl DerefMut for IdxSetBuf { - fn deref_mut(&mut self) -> &mut IdxSet { - unsafe { IdxSet::from_slice_mut(&mut self.bits) } - } -} - -impl IdxSet { - pub fn to_owned(&self) -> IdxSetBuf { - IdxSetBuf { - _pd: Default::default(), - bits: self.bits.to_owned(), - } - } /// Duplicates as a hybrid set. pub fn to_hybrid(&self) -> HybridIdxSetBuf { @@ -219,16 +146,6 @@ impl IdxSet { self.bits.set_bit(elem.index()) } - pub fn range(&self, elems: &Range) -> &Self { - let elems = elems.start.index()..elems.end.index(); - unsafe { Self::from_slice(&self.bits[elems]) } - } - - pub fn range_mut(&mut self, elems: &Range) -> &mut Self { - let elems = elems.start.index()..elems.end.index(); - unsafe { Self::from_slice_mut(&mut self.bits[elems]) } - } - /// Returns true iff set `self` contains `elem`. pub fn contains(&self, elem: &T) -> bool { self.bits.get_bit(elem.index()) From e7e9f2e6997ae12573cf4726935f232bf13fb40b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 17 Aug 2018 14:51:39 +1000 Subject: [PATCH 14/21] Remove IdxSet typedef and Rename {,Hybrid}IdxSetBuf as {,Hybrid}IdxSet. Now that the `Buf` vs. non-`Buf` distinction has been removed, it makes sense to drop the `Buf` suffix and use the shorter names everywhere. --- src/librustc/ty/query/mod.rs | 4 +- src/librustc_data_structures/indexed_set.rs | 119 +++++++++--------- src/librustc_data_structures/stable_hasher.rs | 2 +- src/librustc_data_structures/work_queue.rs | 8 +- src/librustc_metadata/cstore_impl.rs | 4 +- src/librustc_mir/borrow_check/mod.rs | 4 +- .../borrow_check/nll/region_infer/mod.rs | 4 +- src/librustc_mir/dataflow/at_location.rs | 14 +-- src/librustc_mir/dataflow/mod.rs | 30 ++--- src/librustc_mir/transform/elaborate_drops.rs | 12 +- src/librustc_mir/transform/generator.rs | 6 +- src/librustc_mir/transform/qualify_consts.rs | 10 +- src/librustc_mir/transform/rustc_peek.rs | 4 +- src/librustc_mir/util/liveness.rs | 4 +- 14 files changed, 111 insertions(+), 114 deletions(-) diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index ef22ebef9d7d4..5f7c5190159c4 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -49,7 +49,7 @@ use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet}; use util::common::{ErrorReported}; use util::profiling::ProfileCategory::*; -use rustc_data_structures::indexed_set::IdxSetBuf; +use rustc_data_structures::indexed_set::IdxSet; use rustc_target::spec::PanicStrategy; use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; @@ -208,7 +208,7 @@ define_queries! { <'tcx> /// Maps DefId's that have an associated Mir to the result /// of the MIR qualify_consts pass. The actual meaning of /// the value isn't known except to the pass itself. - [] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc>), + [] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc>), /// Fetch the MIR for a given def-id right after it's built - this includes /// unreachable code. diff --git a/src/librustc_data_structures/indexed_set.rs b/src/librustc_data_structures/indexed_set.rs index 6c64e5de37807..f21c898a28a34 100644 --- a/src/librustc_data_structures/indexed_set.rs +++ b/src/librustc_data_structures/indexed_set.rs @@ -27,21 +27,18 @@ use rustc_serialize; /// /// The representation is dense, using one bit per possible element. #[derive(Eq, PartialEq)] -pub struct IdxSetBuf { +pub struct IdxSet { _pd: PhantomData, bits: Vec, } -// FIXME: temporary -pub type IdxSet = IdxSetBuf; - -impl Clone for IdxSetBuf { +impl Clone for IdxSet { fn clone(&self) -> Self { - IdxSetBuf { _pd: PhantomData, bits: self.bits.clone() } + IdxSet { _pd: PhantomData, bits: self.bits.clone() } } } -impl rustc_serialize::Encodable for IdxSetBuf { +impl rustc_serialize::Encodable for IdxSet { fn encode(&self, encoder: &mut E) -> Result<(), E::Error> { @@ -49,11 +46,11 @@ impl rustc_serialize::Encodable for IdxSetBuf { } } -impl rustc_serialize::Decodable for IdxSetBuf { - fn decode(d: &mut D) -> Result, D::Error> { +impl rustc_serialize::Decodable for IdxSet { + fn decode(d: &mut D) -> Result, D::Error> { let words: Vec = rustc_serialize::Decodable::decode(d)?; - Ok(IdxSetBuf { + Ok(IdxSet { _pd: PhantomData, bits: words, }) @@ -62,7 +59,7 @@ impl rustc_serialize::Decodable for IdxSetBuf { const BITS_PER_WORD: usize = mem::size_of::() * 8; -impl fmt::Debug for IdxSetBuf { +impl fmt::Debug for IdxSet { fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { w.debug_list() .entries(self.iter()) @@ -70,10 +67,10 @@ impl fmt::Debug for IdxSetBuf { } } -impl IdxSetBuf { +impl IdxSet { fn new(init: Word, universe_size: usize) -> Self { let num_words = (universe_size + (BITS_PER_WORD - 1)) / BITS_PER_WORD; - IdxSetBuf { + IdxSet { _pd: Default::default(), bits: vec![init; num_words], } @@ -92,13 +89,13 @@ impl IdxSetBuf { } /// Duplicates as a hybrid set. - pub fn to_hybrid(&self) -> HybridIdxSetBuf { + pub fn to_hybrid(&self) -> HybridIdxSet { // This universe_size may be slightly larger than the one specified // upon creation, due to rounding up to a whole word. That's ok. let universe_size = self.bits.len() * BITS_PER_WORD; // Note: we currently don't bother trying to make a Sparse set. - HybridIdxSetBuf::Dense(self.to_owned(), universe_size) + HybridIdxSet::Dense(self.to_owned(), universe_size) } /// Removes all elements @@ -171,8 +168,8 @@ impl IdxSetBuf { bitwise(self.words_mut(), other.words(), &Union) } - /// Like `union()`, but takes a `SparseIdxSetBuf` argument. - fn union_sparse(&mut self, other: &SparseIdxSetBuf) -> bool { + /// Like `union()`, but takes a `SparseIdxSet` argument. + fn union_sparse(&mut self, other: &SparseIdxSet) -> bool { let mut changed = false; for elem in other.iter() { changed |= self.add(&elem); @@ -180,11 +177,11 @@ impl IdxSetBuf { changed } - /// Like `union()`, but takes a `HybridIdxSetBuf` argument. - pub fn union_hybrid(&mut self, other: &HybridIdxSetBuf) -> bool { + /// Like `union()`, but takes a `HybridIdxSet` argument. + pub fn union_hybrid(&mut self, other: &HybridIdxSet) -> bool { match other { - HybridIdxSetBuf::Sparse(sparse, _) => self.union_sparse(sparse), - HybridIdxSetBuf::Dense(dense, _) => self.union(dense), + HybridIdxSet::Sparse(sparse, _) => self.union_sparse(sparse), + HybridIdxSet::Dense(dense, _) => self.union(dense), } } @@ -194,8 +191,8 @@ impl IdxSetBuf { bitwise(self.words_mut(), other.words(), &Subtract) } - /// Like `subtract()`, but takes a `SparseIdxSetBuf` argument. - fn subtract_sparse(&mut self, other: &SparseIdxSetBuf) -> bool { + /// Like `subtract()`, but takes a `SparseIdxSet` argument. + fn subtract_sparse(&mut self, other: &SparseIdxSet) -> bool { let mut changed = false; for elem in other.iter() { changed |= self.remove(&elem); @@ -203,11 +200,11 @@ impl IdxSetBuf { changed } - /// Like `subtract()`, but takes a `HybridIdxSetBuf` argument. - pub fn subtract_hybrid(&mut self, other: &HybridIdxSetBuf) -> bool { + /// Like `subtract()`, but takes a `HybridIdxSet` argument. + pub fn subtract_hybrid(&mut self, other: &HybridIdxSet) -> bool { match other { - HybridIdxSetBuf::Sparse(sparse, _) => self.subtract_sparse(sparse), - HybridIdxSetBuf::Dense(dense, _) => self.subtract(dense), + HybridIdxSet::Sparse(sparse, _) => self.subtract_sparse(sparse), + HybridIdxSet::Dense(dense, _) => self.subtract(dense), } } @@ -255,15 +252,15 @@ impl<'a, T: Idx> Iterator for Iter<'a, T> { const SPARSE_MAX: usize = 8; /// A sparse index set with a maximum of SPARSE_MAX elements. Used by -/// HybridIdxSetBuf; do not use directly. +/// HybridIdxSet; do not use directly. /// /// The elements are stored as an unsorted vector with no duplicates. #[derive(Clone, Debug)] -pub struct SparseIdxSetBuf(ArrayVec<[T; SPARSE_MAX]>); +pub struct SparseIdxSet(ArrayVec<[T; SPARSE_MAX]>); -impl SparseIdxSetBuf { +impl SparseIdxSet { fn new() -> Self { - SparseIdxSetBuf(ArrayVec::new()) + SparseIdxSet(ArrayVec::new()) } fn len(&self) -> usize { @@ -296,8 +293,8 @@ impl SparseIdxSetBuf { } } - fn to_dense(&self, universe_size: usize) -> IdxSetBuf { - let mut dense = IdxSetBuf::new_empty(universe_size); + fn to_dense(&self, universe_size: usize) -> IdxSet { + let mut dense = IdxSet::new_empty(universe_size); for elem in self.0.iter() { dense.add(elem); } @@ -323,72 +320,72 @@ impl<'a, T: Idx> Iterator for SparseIter<'a, T> { } } -/// Like IdxSetBuf, but with a hybrid representation: sparse when there are few +/// Like IdxSet, but with a hybrid representation: sparse when there are few /// elements in the set, but dense when there are many. It's especially /// efficient for sets that typically have a small number of elements, but a /// large `universe_size`, and are cleared frequently. #[derive(Clone, Debug)] -pub enum HybridIdxSetBuf { - Sparse(SparseIdxSetBuf, usize), - Dense(IdxSetBuf, usize), +pub enum HybridIdxSet { + Sparse(SparseIdxSet, usize), + Dense(IdxSet, usize), } -impl HybridIdxSetBuf { +impl HybridIdxSet { pub fn new_empty(universe_size: usize) -> Self { - HybridIdxSetBuf::Sparse(SparseIdxSetBuf::new(), universe_size) + HybridIdxSet::Sparse(SparseIdxSet::new(), universe_size) } fn universe_size(&mut self) -> usize { match *self { - HybridIdxSetBuf::Sparse(_, size) => size, - HybridIdxSetBuf::Dense(_, size) => size, + HybridIdxSet::Sparse(_, size) => size, + HybridIdxSet::Dense(_, size) => size, } } pub fn clear(&mut self) { let universe_size = self.universe_size(); - *self = HybridIdxSetBuf::new_empty(universe_size); + *self = HybridIdxSet::new_empty(universe_size); } /// Returns true iff set `self` contains `elem`. pub fn contains(&self, elem: &T) -> bool { match self { - HybridIdxSetBuf::Sparse(sparse, _) => sparse.contains(elem), - HybridIdxSetBuf::Dense(dense, _) => dense.contains(elem), + HybridIdxSet::Sparse(sparse, _) => sparse.contains(elem), + HybridIdxSet::Dense(dense, _) => dense.contains(elem), } } /// Adds `elem` to the set `self`. pub fn add(&mut self, elem: &T) -> bool { match self { - HybridIdxSetBuf::Sparse(sparse, _) if sparse.len() < SPARSE_MAX => { + HybridIdxSet::Sparse(sparse, _) if sparse.len() < SPARSE_MAX => { // The set is sparse and has space for `elem`. sparse.add(elem) } - HybridIdxSetBuf::Sparse(sparse, _) if sparse.contains(elem) => { + HybridIdxSet::Sparse(sparse, _) if sparse.contains(elem) => { // The set is sparse and does not have space for `elem`, but // that doesn't matter because `elem` is already present. false } - HybridIdxSetBuf::Sparse(_, _) => { + HybridIdxSet::Sparse(_, _) => { // The set is sparse and full. Convert to a dense set. // // FIXME: This code is awful, but I can't work out how else to // appease the borrow checker. - let dummy = HybridIdxSetBuf::Sparse(SparseIdxSetBuf::new(), 0); + let dummy = HybridIdxSet::Sparse(SparseIdxSet::new(), 0); match mem::replace(self, dummy) { - HybridIdxSetBuf::Sparse(sparse, universe_size) => { + HybridIdxSet::Sparse(sparse, universe_size) => { let mut dense = sparse.to_dense(universe_size); let changed = dense.add(elem); assert!(changed); - mem::replace(self, HybridIdxSetBuf::Dense(dense, universe_size)); + mem::replace(self, HybridIdxSet::Dense(dense, universe_size)); changed } _ => panic!("impossible"), } } - HybridIdxSetBuf::Dense(dense, _) => dense.add(elem), + HybridIdxSet::Dense(dense, _) => dense.add(elem), } } @@ -396,24 +393,24 @@ impl HybridIdxSetBuf { pub fn remove(&mut self, elem: &T) -> bool { // Note: we currently don't bother going from Dense back to Sparse. match self { - HybridIdxSetBuf::Sparse(sparse, _) => sparse.remove(elem), - HybridIdxSetBuf::Dense(dense, _) => dense.remove(elem), + HybridIdxSet::Sparse(sparse, _) => sparse.remove(elem), + HybridIdxSet::Dense(dense, _) => dense.remove(elem), } } /// Converts to a dense set, consuming itself in the process. - pub fn to_dense(self) -> IdxSetBuf { + pub fn to_dense(self) -> IdxSet { match self { - HybridIdxSetBuf::Sparse(sparse, universe_size) => sparse.to_dense(universe_size), - HybridIdxSetBuf::Dense(dense, _) => dense, + HybridIdxSet::Sparse(sparse, universe_size) => sparse.to_dense(universe_size), + HybridIdxSet::Dense(dense, _) => dense, } } /// Iteration order is unspecified. pub fn iter(&self) -> HybridIter { match self { - HybridIdxSetBuf::Sparse(sparse, _) => HybridIter::Sparse(sparse.iter()), - HybridIdxSetBuf::Dense(dense, _) => HybridIter::Dense(dense.iter()), + HybridIdxSet::Sparse(sparse, _) => HybridIter::Sparse(sparse.iter()), + HybridIdxSet::Dense(dense, _) => HybridIter::Dense(dense.iter()), } } } @@ -439,7 +436,7 @@ fn test_trim_to() { use std::cmp; for i in 0..256 { - let mut idx_buf: IdxSetBuf = IdxSetBuf::new_filled(128); + let mut idx_buf: IdxSet = IdxSet::new_filled(128); idx_buf.trim_to(i); let elems: Vec = idx_buf.iter().collect(); @@ -452,7 +449,7 @@ fn test_trim_to() { fn test_set_up_to() { for i in 0..128 { for mut idx_buf in - vec![IdxSetBuf::new_empty(128), IdxSetBuf::new_filled(128)] + vec![IdxSet::new_empty(128), IdxSet::new_filled(128)] .into_iter() { idx_buf.set_up_to(i); @@ -467,7 +464,7 @@ fn test_set_up_to() { #[test] fn test_new_filled() { for i in 0..128 { - let idx_buf = IdxSetBuf::new_filled(i); + let idx_buf = IdxSet::new_filled(i); let elems: Vec = idx_buf.iter().collect(); let expected: Vec = (0..i).collect(); assert_eq!(elems, expected); diff --git a/src/librustc_data_structures/stable_hasher.rs b/src/librustc_data_structures/stable_hasher.rs index 9f1c7dac1194e..1024e69cc2b0e 100644 --- a/src/librustc_data_structures/stable_hasher.rs +++ b/src/librustc_data_structures/stable_hasher.rs @@ -432,7 +432,7 @@ impl HashStable for ::indexed_vec::IndexVec< } -impl HashStable for ::indexed_set::IdxSetBuf +impl HashStable for ::indexed_set::IdxSet { fn hash_stable(&self, ctx: &mut CTX, diff --git a/src/librustc_data_structures/work_queue.rs b/src/librustc_data_structures/work_queue.rs index b8e8b249bb504..0c8ec753a18f6 100644 --- a/src/librustc_data_structures/work_queue.rs +++ b/src/librustc_data_structures/work_queue.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use indexed_set::IdxSetBuf; +use indexed_set::IdxSet; use indexed_vec::Idx; use std::collections::VecDeque; @@ -20,7 +20,7 @@ use std::collections::VecDeque; /// and also use a bit set to track occupancy. pub struct WorkQueue { deque: VecDeque, - set: IdxSetBuf, + set: IdxSet, } impl WorkQueue { @@ -29,7 +29,7 @@ impl WorkQueue { pub fn with_all(len: usize) -> Self { WorkQueue { deque: (0..len).map(T::new).collect(), - set: IdxSetBuf::new_filled(len), + set: IdxSet::new_filled(len), } } @@ -38,7 +38,7 @@ impl WorkQueue { pub fn with_none(len: usize) -> Self { WorkQueue { deque: VecDeque::with_capacity(len), - set: IdxSetBuf::new_empty(len), + set: IdxSet::new_empty(len), } } diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 4926da3b880e7..bbc4dbe09e147 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -43,7 +43,7 @@ use syntax::edition::Edition; use syntax::parse::filemap_to_stream; use syntax::symbol::Symbol; use syntax_pos::{Span, NO_EXPANSION, FileName}; -use rustc_data_structures::indexed_set::IdxSetBuf; +use rustc_data_structures::indexed_set::IdxSet; use rustc::hir; macro_rules! provide { @@ -142,7 +142,7 @@ provide! { <'tcx> tcx, def_id, other, cdata, mir } mir_const_qualif => { - (cdata.mir_const_qualif(def_id.index), Lrc::new(IdxSetBuf::new_empty(0))) + (cdata.mir_const_qualif(def_id.index), Lrc::new(IdxSet::new_empty(0))) } fn_sig => { cdata.fn_sig(def_id.index, tcx) } inherent_impls => { Lrc::new(cdata.get_inherent_implementations_for_type(def_id.index)) } diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index ce0e76a636db2..fdec7e70622e4 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -27,7 +27,7 @@ use rustc::ty::{self, ParamEnv, TyCtxt, Ty}; use rustc_errors::{Diagnostic, DiagnosticBuilder, Level}; use rustc_data_structures::graph::dominators::Dominators; use rustc_data_structures::fx::FxHashSet; -use rustc_data_structures::indexed_set::IdxSetBuf; +use rustc_data_structures::indexed_set::IdxSet; use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::small_vec::SmallVec; @@ -166,7 +166,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( _ => Some(tcx.hir.body_owned_by(id)), }; - let dead_unwinds = IdxSetBuf::new_empty(mir.basic_blocks().len()); + let dead_unwinds = IdxSet::new_empty(mir.basic_blocks().len()); let mut flow_inits = FlowAtLocation::new(do_dataflow( tcx, mir, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index ebcc044093a65..ff68b5987e85a 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -27,7 +27,7 @@ use rustc::mir::{ use rustc::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable}; use rustc::util::common; use rustc_data_structures::graph::scc::Sccs; -use rustc_data_structures::indexed_set::{IdxSet, IdxSetBuf}; +use rustc_data_structures::indexed_set::IdxSet; use rustc_data_structures::indexed_vec::IndexVec; use rustc_errors::Diagnostic; @@ -468,7 +468,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // SCC. For each SCC, we visit its successors and compute // their values, then we union all those values to get our // own. - let visited = &mut IdxSetBuf::new_empty(self.constraint_sccs.num_sccs()); + let visited = &mut IdxSet::new_empty(self.constraint_sccs.num_sccs()); for scc_index in self.constraint_sccs.all_sccs() { self.propagate_constraint_sccs_if_new(scc_index, visited); } diff --git a/src/librustc_mir/dataflow/at_location.rs b/src/librustc_mir/dataflow/at_location.rs index d2a8a9dcf4ba2..0dfc5b5b4b7e0 100644 --- a/src/librustc_mir/dataflow/at_location.rs +++ b/src/librustc_mir/dataflow/at_location.rs @@ -12,7 +12,7 @@ //! locations. use rustc::mir::{BasicBlock, Location}; -use rustc_data_structures::indexed_set::{HybridIdxSetBuf, IdxSetBuf, Iter}; +use rustc_data_structures::indexed_set::{HybridIdxSet, IdxSet, Iter}; use rustc_data_structures::indexed_vec::Idx; use dataflow::{BitDenotation, BlockSets, DataflowResults}; @@ -67,9 +67,9 @@ where BD: BitDenotation, { base_results: DataflowResults, - curr_state: IdxSetBuf, - stmt_gen: HybridIdxSetBuf, - stmt_kill: HybridIdxSetBuf, + curr_state: IdxSet, + stmt_gen: HybridIdxSet, + stmt_kill: HybridIdxSet, } impl FlowAtLocation @@ -96,9 +96,9 @@ where pub fn new(results: DataflowResults) -> Self { let bits_per_block = results.sets().bits_per_block(); - let curr_state = IdxSetBuf::new_empty(bits_per_block); - let stmt_gen = HybridIdxSetBuf::new_empty(bits_per_block); - let stmt_kill = HybridIdxSetBuf::new_empty(bits_per_block); + let curr_state = IdxSet::new_empty(bits_per_block); + let stmt_gen = HybridIdxSet::new_empty(bits_per_block); + let stmt_kill = HybridIdxSet::new_empty(bits_per_block); FlowAtLocation { base_results: results, curr_state: curr_state, diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index 0881b66e5508b..54f19428df765 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -11,7 +11,7 @@ use syntax::ast::{self, MetaItem}; use rustc_data_structures::bitslice::{bitwise, BitwiseOperator}; -use rustc_data_structures::indexed_set::{HybridIdxSetBuf, IdxSet, IdxSetBuf}; +use rustc_data_structures::indexed_set::{HybridIdxSet, IdxSet}; use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::work_queue::WorkQueue; @@ -182,7 +182,7 @@ struct PropagationContext<'b, 'a: 'b, 'tcx: 'a, O> where O: 'b + BitDenotation impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation { fn propagate(&mut self) { - let mut temp = IdxSetBuf::new_empty(self.flow_state.sets.bits_per_block); + let mut temp = IdxSet::new_empty(self.flow_state.sets.bits_per_block); let mut propcx = PropagationContext { builder: self, }; @@ -353,7 +353,7 @@ pub fn state_for_location<'tcx, T: BitDenotation>(loc: Location, analysis: &T, result: &DataflowResults, mir: &Mir<'tcx>) - -> IdxSetBuf { + -> IdxSet { let mut on_entry = result.sets().on_entry_set_for(loc.block.index()).to_owned(); let mut kill_set = on_entry.to_hybrid(); let mut gen_set = kill_set.clone(); @@ -437,7 +437,7 @@ impl DataflowState { pub(crate) fn interpret_hybrid_set<'c, P>(&self, o: &'c O, - set: &HybridIdxSetBuf, + set: &HybridIdxSet, render_idx: &P) -> Vec where P: Fn(&O, O::Idx) -> DebugFormatted @@ -452,17 +452,17 @@ pub struct AllSets { bits_per_block: usize, /// For each block, bits valid on entry to the block. - on_entry_sets: Vec>, + on_entry_sets: Vec>, /// For each block, bits generated by executing the statements in /// the block. (For comparison, the Terminator for each block is /// handled in a flow-specific manner during propagation.) - gen_sets: Vec>, + gen_sets: Vec>, /// For each block, bits killed by executing the statements in the /// block. (For comparison, the Terminator for each block is /// handled in a flow-specific manner during propagation.) - kill_sets: Vec>, + kill_sets: Vec>, } /// Triple of sets associated with a given block. @@ -486,11 +486,11 @@ pub struct BlockSets<'a, E: Idx> { /// Bits that are set to 1 by the time we exit the given block. Hybrid /// because it usually contains only 0 or 1 elements. - pub(crate) gen_set: &'a mut HybridIdxSetBuf, + pub(crate) gen_set: &'a mut HybridIdxSet, /// Bits that are set to 0 by the time we exit the given block. Hybrid /// because it usually contains only 0 or 1 elements. - pub(crate) kill_set: &'a mut HybridIdxSetBuf, + pub(crate) kill_set: &'a mut HybridIdxSet, } impl<'a, E:Idx> BlockSets<'a, E> { @@ -549,13 +549,13 @@ impl AllSets { } } - pub fn on_entry_set_for(&self, block_idx: usize) -> &IdxSetBuf { + pub fn on_entry_set_for(&self, block_idx: usize) -> &IdxSet { &self.on_entry_sets[block_idx] } - pub fn gen_set_for(&self, block_idx: usize) -> &HybridIdxSetBuf { + pub fn gen_set_for(&self, block_idx: usize) -> &HybridIdxSet { &self.gen_sets[block_idx] } - pub fn kill_set_for(&self, block_idx: usize) -> &HybridIdxSetBuf { + pub fn kill_set_for(&self, block_idx: usize) -> &HybridIdxSet { &self.kill_sets[block_idx] } } @@ -713,11 +713,11 @@ impl<'a, 'tcx, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation let num_blocks = mir.basic_blocks().len(); let on_entry_sets = if D::bottom_value() { - vec![IdxSetBuf::new_filled(bits_per_block); num_blocks] + vec![IdxSet::new_filled(bits_per_block); num_blocks] } else { - vec![IdxSetBuf::new_empty(bits_per_block); num_blocks] + vec![IdxSet::new_empty(bits_per_block); num_blocks] }; - let gen_sets = vec![HybridIdxSetBuf::new_empty(bits_per_block); num_blocks]; + let gen_sets = vec![HybridIdxSet::new_empty(bits_per_block); num_blocks]; let kill_sets = gen_sets.clone(); DataflowAnalysis { diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index 937d01a0c5e88..bbf896e624f20 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -18,7 +18,7 @@ use dataflow::{self, do_dataflow, DebugFormatted}; use rustc::ty::{self, TyCtxt}; use rustc::mir::*; use rustc::util::nodemap::FxHashMap; -use rustc_data_structures::indexed_set::IdxSetBuf; +use rustc_data_structures::indexed_set::IdxSet; use rustc_data_structures::indexed_vec::Idx; use transform::{MirPass, MirSource}; use util::patch::MirPatch; @@ -93,12 +93,12 @@ fn find_dead_unwinds<'a, 'tcx>( mir: &Mir<'tcx>, id: ast::NodeId, env: &MoveDataParamEnv<'tcx, 'tcx>) - -> IdxSetBuf + -> IdxSet { debug!("find_dead_unwinds({:?})", mir.span); // We only need to do this pass once, because unwind edges can only // reach cleanup blocks, which can't have unwind edges themselves. - let mut dead_unwinds = IdxSetBuf::new_empty(mir.basic_blocks().len()); + let mut dead_unwinds = IdxSet::new_empty(mir.basic_blocks().len()); let flow_inits = do_dataflow(tcx, mir, id, &[], &dead_unwinds, MaybeInitializedPlaces::new(tcx, mir, &env), @@ -112,7 +112,7 @@ fn find_dead_unwinds<'a, 'tcx>( let mut init_data = InitializationData { live: flow_inits.sets().on_entry_set_for(bb.index()).to_owned(), - dead: IdxSetBuf::new_empty(env.move_data.move_paths.len()), + dead: IdxSet::new_empty(env.move_data.move_paths.len()), }; debug!("find_dead_unwinds @ {:?}: {:?}; init_data={:?}", bb, bb_data, init_data.live); @@ -147,8 +147,8 @@ fn find_dead_unwinds<'a, 'tcx>( } struct InitializationData { - live: IdxSetBuf, - dead: IdxSetBuf + live: IdxSet, + dead: IdxSet } impl InitializationData { diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index a3647edd155d3..744efb3783226 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -68,7 +68,7 @@ use rustc::ty::subst::Substs; use util::dump_mir; use util::liveness::{self, IdentityMap, LivenessMode}; use rustc_data_structures::indexed_vec::Idx; -use rustc_data_structures::indexed_set::IdxSetBuf; +use rustc_data_structures::indexed_set::IdxSet; use std::collections::HashMap; use std::borrow::Cow; use std::iter::once; @@ -369,7 +369,7 @@ fn locals_live_across_suspend_points<'a, 'tcx,>(tcx: TyCtxt<'a, 'tcx, 'tcx>, movable: bool) -> (liveness::LiveVarSet, HashMap>) { - let dead_unwinds = IdxSetBuf::new_empty(mir.basic_blocks().len()); + let dead_unwinds = IdxSet::new_empty(mir.basic_blocks().len()); let node_id = tcx.hir.as_local_node_id(source.def_id).unwrap(); // Calculate when MIR locals have live storage. This gives us an upper bound of their @@ -381,7 +381,7 @@ fn locals_live_across_suspend_points<'a, 'tcx,>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Find the MIR locals which do not use StorageLive/StorageDead statements. // The storage of these locals are always live. - let mut ignored = StorageIgnored(IdxSetBuf::new_filled(mir.local_decls.len())); + let mut ignored = StorageIgnored(IdxSet::new_filled(mir.local_decls.len())); ignored.visit_mir(mir); // Calculate the MIR locals which have been previously diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index d876ee77e76cf..22bf764506039 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -15,7 +15,7 @@ //! diagnostics as to why a constant rvalue wasn't promoted. use rustc_data_structures::bitvec::BitArray; -use rustc_data_structures::indexed_set::IdxSetBuf; +use rustc_data_structures::indexed_set::IdxSet; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; use rustc_data_structures::fx::FxHashSet; use rustc::hir; @@ -279,7 +279,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> { } /// Qualify a whole const, static initializer or const fn. - fn qualify_const(&mut self) -> (Qualif, Lrc>) { + fn qualify_const(&mut self) -> (Qualif, Lrc>) { debug!("qualifying {} {:?}", self.mode, self.def_id); let mir = self.mir; @@ -382,7 +382,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> { // Collect all the temps we need to promote. - let mut promoted_temps = IdxSetBuf::new_empty(self.temp_promotion_state.len()); + let mut promoted_temps = IdxSet::new_empty(self.temp_promotion_state.len()); for candidate in &self.promotion_candidates { match *candidate { @@ -1082,7 +1082,7 @@ pub fn provide(providers: &mut Providers) { fn mir_const_qualif<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) - -> (u8, Lrc>) { + -> (u8, Lrc>) { // NB: This `borrow()` is guaranteed to be valid (i.e., the value // cannot yet be stolen), because `mir_validated()`, which steals // from `mir_const(), forces this query to execute before @@ -1091,7 +1091,7 @@ fn mir_const_qualif<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if mir.return_ty().references_error() { tcx.sess.delay_span_bug(mir.span, "mir_const_qualif: Mir had errors"); - return (Qualif::NOT_CONST.bits(), Lrc::new(IdxSetBuf::new_empty(0))); + return (Qualif::NOT_CONST.bits(), Lrc::new(IdxSet::new_empty(0))); } let mut qualifier = Qualifier::new(tcx, def_id, mir, Mode::Const); diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs index 776d7888459f7..c471853175422 100644 --- a/src/librustc_mir/transform/rustc_peek.rs +++ b/src/librustc_mir/transform/rustc_peek.rs @@ -14,7 +14,7 @@ use syntax_pos::Span; use rustc::ty::{self, TyCtxt}; use rustc::mir::{self, Mir, Location}; -use rustc_data_structures::indexed_set::IdxSetBuf; +use rustc_data_structures::indexed_set::IdxSet; use rustc_data_structures::indexed_vec::Idx; use transform::{MirPass, MirSource}; @@ -47,7 +47,7 @@ impl MirPass for SanityCheck { let param_env = tcx.param_env(def_id); let move_data = MoveData::gather_moves(mir, tcx).unwrap(); let mdpe = MoveDataParamEnv { move_data: move_data, param_env: param_env }; - let dead_unwinds = IdxSetBuf::new_empty(mir.basic_blocks().len()); + let dead_unwinds = IdxSet::new_empty(mir.basic_blocks().len()); let flow_inits = do_dataflow(tcx, mir, id, &attributes, &dead_unwinds, MaybeInitializedPlaces::new(tcx, mir, &mdpe), diff --git a/src/librustc_mir/util/liveness.rs b/src/librustc_mir/util/liveness.rs index 6c5b38a806e57..04fa516a655a6 100644 --- a/src/librustc_mir/util/liveness.rs +++ b/src/librustc_mir/util/liveness.rs @@ -38,7 +38,7 @@ use rustc::mir::visit::{PlaceContext, Visitor}; use rustc::mir::Local; use rustc::mir::*; use rustc::ty::{item_path, TyCtxt}; -use rustc_data_structures::indexed_set::IdxSetBuf; +use rustc_data_structures::indexed_set::IdxSet; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; use rustc_data_structures::work_queue::WorkQueue; use std::fs; @@ -47,7 +47,7 @@ use std::path::{Path, PathBuf}; use transform::MirSource; use util::pretty::{dump_enabled, write_basic_block, write_mir_intro}; -pub type LiveVarSet = IdxSetBuf; +pub type LiveVarSet = IdxSet; /// This gives the result of the liveness analysis at the boundary of /// basic blocks. You can use `simulate_block` to obtain the From 11f3918ca2c7913f7976a42539646dc28e86ffcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 22 Aug 2018 08:06:39 +0200 Subject: [PATCH 15/21] docs: std::string::String.repeat(): slightly rephrase to be more in-line with other descriptions. add ticks around a few keywords in other descriptions. --- src/liballoc/str.rs | 2 +- src/liballoc/string.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 870bf971cd3f6..c451a051c74dc 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -513,7 +513,7 @@ impl str { unsafe { String::from_utf8_unchecked(slice.into_vec()) } } - /// Create a [`String`] by repeating a string `n` times. + /// Creates a new [`String`] by repeating a string `n` times. /// /// [`String`]: string/struct.String.html /// diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index eabda7123dec0..aa821abb34cdf 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -752,7 +752,7 @@ impl String { self.vec } - /// Extracts a string slice containing the entire string. + /// Extracts a string slice containing the entire `String`. /// /// # Examples /// @@ -1454,8 +1454,8 @@ impl String { self.vec.clear() } - /// Creates a draining iterator that removes the specified range in the string - /// and yields the removed chars. + /// Creates a draining iterator that removes the specified range in the `String` + /// and yields the removed `chars`. /// /// Note: The element range is removed even if the iterator is not /// consumed until the end. From f07245c041384649e0caeca4555540be94620d80 Mon Sep 17 00:00:00 2001 From: Aaron Power Date: Wed, 22 Aug 2018 09:18:34 +0100 Subject: [PATCH 16/21] Update RELEASES.md --- RELEASES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 088d361b7ea6a..ac7fd5c873756 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -39,6 +39,8 @@ Misc will demote `deny` and `forbid` lints to `warn`. - [`rustc` and `rustdoc` will now have the exit code of `1` if compilation fails, and `101` if there is a panic.][52197] +- [Added a preview of clippy has been made available through rustup][51122] + Install with `rustup component add clippy-preview` Compatibility Notes ------------------- @@ -64,6 +66,7 @@ Compatibility Notes [51619]: https://github.com/rust-lang/rust/pull/51619/ [51656]: https://github.com/rust-lang/rust/pull/51656/ [51178]: https://github.com/rust-lang/rust/pull/51178/ +[51122]: https://github.com/rust-lang/rust/pull/51122 [50494]: https://github.com/rust-lang/rust/pull/50494/ [cargo/5614]: https://github.com/rust-lang/cargo/pull/5614/ [cargo/5723]: https://github.com/rust-lang/cargo/pull/5723/ From c9c4f5ef784069319a36cf75d15dfaa604196071 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 22 Aug 2018 12:15:29 +0100 Subject: [PATCH 17/21] Fix a grammatical mistake in "expected generic arguments" errors --- src/librustc_typeck/astconv.rs | 2 +- .../ui/generic/generic-impl-more-params-with-defaults.stderr | 2 +- .../ui/generic/generic-type-more-params-with-defaults.stderr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index ccdb751bc4eed..3f88bf829a82e 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -371,7 +371,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { quantifier, bound, kind, - if required != 1 { "s" } else { "" }, + if bound != 1 { "s" } else { "" }, ) }; diff --git a/src/test/ui/generic/generic-impl-more-params-with-defaults.stderr b/src/test/ui/generic/generic-impl-more-params-with-defaults.stderr index b614da88ba164..6b54baefb1dd3 100644 --- a/src/test/ui/generic/generic-impl-more-params-with-defaults.stderr +++ b/src/test/ui/generic/generic-impl-more-params-with-defaults.stderr @@ -2,7 +2,7 @@ error[E0244]: wrong number of type arguments: expected at most 2, found 3 --> $DIR/generic-impl-more-params-with-defaults.rs:23:5 | LL | Vec::::new(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected at most 2 type argument + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected at most 2 type arguments error: aborting due to previous error diff --git a/src/test/ui/generic/generic-type-more-params-with-defaults.stderr b/src/test/ui/generic/generic-type-more-params-with-defaults.stderr index f226921816d09..684a22ce45c92 100644 --- a/src/test/ui/generic/generic-type-more-params-with-defaults.stderr +++ b/src/test/ui/generic/generic-type-more-params-with-defaults.stderr @@ -2,7 +2,7 @@ error[E0244]: wrong number of type arguments: expected at most 2, found 3 --> $DIR/generic-type-more-params-with-defaults.rs:19:12 | LL | let _: Vec; - | ^^^^^^^^^^^^^^^^^^^^^^ expected at most 2 type argument + | ^^^^^^^^^^^^^^^^^^^^^^ expected at most 2 type arguments error: aborting due to previous error From 200c6d9fb58ceafd8a6f3742382f9fce122bb157 Mon Sep 17 00:00:00 2001 From: Aaron Power Date: Wed, 22 Aug 2018 21:18:31 +0100 Subject: [PATCH 18/21] Update RELEASES.md --- RELEASES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index ac7fd5c873756..7e727e0d41bb3 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -39,8 +39,8 @@ Misc will demote `deny` and `forbid` lints to `warn`. - [`rustc` and `rustdoc` will now have the exit code of `1` if compilation fails, and `101` if there is a panic.][52197] -- [Added a preview of clippy has been made available through rustup][51122] - Install with `rustup component add clippy-preview` +- [A preview of clippy has been made available through rustup.][51122] + You can install the preview with `rustup component add clippy-preview` Compatibility Notes ------------------- From b34503e60ee674b31797790b2b8d8a20f1a54e48 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 18 Aug 2018 00:52:34 +0300 Subject: [PATCH 19/21] Stabilize a few secondary macro features `tool_attributes`, `proc_macro_path_invoc`, partially `proc_macro_gen` --- .../src/language-features/tool-attributes.md | 26 ------------------- src/librustc_resolve/macros.rs | 15 ----------- src/libsyntax/ext/expand.rs | 15 ++++------- src/libsyntax/feature_gate.rs | 9 +++---- .../proc-macro/auxiliary/more-gates.rs | 11 -------- .../proc-macro/more-gates.rs | 7 +---- .../proc-macro/proc-macro-gates.rs | 6 ----- .../run-pass-fulldeps/proc-macro/derive-b.rs | 2 +- .../proc-macro/issue-42708.rs | 2 +- .../proc-macro/issue-50061.rs | 2 +- src/test/run-pass/tool_attributes.rs | 1 - .../ui-fulldeps/proc-macro/generate-mod.rs | 2 -- .../proc-macro/generate-mod.stderr | 16 ++++++------ src/test/ui/custom-attribute-multisegment.rs | 2 +- .../feature-gate-tool_attributes.rs | 15 ----------- .../feature-gate-tool_attributes.stderr | 11 -------- .../tool-attributes-misplaced-1.rs | 2 +- .../tool-attributes-misplaced-2.rs | 2 -- .../tool-attributes-misplaced-2.stderr | 4 +-- .../tool-attributes-shadowing.rs | 2 -- .../tool-attributes-shadowing.stderr | 2 +- src/test/ui/unknown-tool-name.rs | 2 -- src/test/ui/unknown-tool-name.stderr | 2 +- 23 files changed, 27 insertions(+), 131 deletions(-) delete mode 100644 src/doc/unstable-book/src/language-features/tool-attributes.md delete mode 100644 src/test/ui/feature-gates/feature-gate-tool_attributes.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-tool_attributes.stderr diff --git a/src/doc/unstable-book/src/language-features/tool-attributes.md b/src/doc/unstable-book/src/language-features/tool-attributes.md deleted file mode 100644 index 15fc84a3e2a3d..0000000000000 --- a/src/doc/unstable-book/src/language-features/tool-attributes.md +++ /dev/null @@ -1,26 +0,0 @@ -# `tool_attributes` - -The tracking issue for this feature is: [#44690] - -[#44690]: https://github.com/rust-lang/rust/issues/44690 - ------------------------- - -Tool attributes let you use scoped attributes to control the behavior -of certain tools. - -Currently tool names which can be appear in scoped attributes are restricted to -`clippy` and `rustfmt`. - -## An example - -```rust -#![feature(tool_attributes)] - -#[rustfmt::skip] -fn foo() { println!("hello, world"); } - -fn main() { - foo(); -} -``` diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 1161d57417b18..382a53b720ac1 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -367,17 +367,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> { let def = def?; - if path.segments.len() > 1 { - if kind != MacroKind::Bang { - if def != Def::NonMacroAttr(NonMacroAttrKind::Tool) && - !self.session.features_untracked().proc_macro_path_invoc { - let msg = format!("non-ident {} paths are unstable", kind.descr()); - emit_feature_err(&self.session.parse_sess, "proc_macro_path_invoc", - path.span, GateIssue::Language, &msg); - } - } - } - match def { Def::Macro(def_id, macro_kind) => { self.unused_macros.remove(&def_id); @@ -390,10 +379,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> { Def::NonMacroAttr(attr_kind) => { if kind == MacroKind::Attr { let features = self.session.features_untracked(); - if attr_kind == NonMacroAttrKind::Tool && !features.tool_attributes { - feature_err(&self.session.parse_sess, "tool_attributes", path.span, - GateIssue::Language, "tool attributes are unstable").emit(); - } if attr_kind == NonMacroAttrKind::Custom { assert!(path.segments.len() == 1); let name = path.segments[0].ident.name.as_str(); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 97279e00869c6..494f6d29832dd 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -666,30 +666,25 @@ impl<'a, 'b> MacroExpander<'a, 'b> { None => return, }; - fragment.visit_with(&mut DisallowModules { + fragment.visit_with(&mut DisallowMacros { span, parse_sess: self.cx.parse_sess, }); - struct DisallowModules<'a> { + struct DisallowMacros<'a> { span: Span, parse_sess: &'a ParseSess, } - impl<'ast, 'a> Visitor<'ast> for DisallowModules<'a> { + impl<'ast, 'a> Visitor<'ast> for DisallowMacros<'a> { fn visit_item(&mut self, i: &'ast ast::Item) { - let name = match i.node { - ast::ItemKind::Mod(_) => Some("modules"), - ast::ItemKind::MacroDef(_) => Some("macro definitions"), - _ => None, - }; - if let Some(name) = name { + if let ast::ItemKind::MacroDef(_) = i.node { emit_feature_err( self.parse_sess, "proc_macro_gen", self.span, GateIssue::Language, - &format!("procedural macros cannot expand to {}", name), + &format!("procedural macros cannot expand to macro definitions"), ); } visit::walk_item(self, i); diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 71ad118ed8eac..5e569025ab377 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -438,9 +438,6 @@ declare_features! ( (active, tbm_target_feature, "1.27.0", Some(44839), None), (active, wasm_target_feature, "1.30.0", Some(44839), None), - // Allows macro invocations of the form `#[foo::bar]` - (active, proc_macro_path_invoc, "1.27.0", Some(38356), None), - // Allows macro invocations on modules expressions and statements and // procedural macros to expand to non-items. (active, proc_macro_mod, "1.27.0", Some(38356), None), @@ -454,8 +451,6 @@ declare_features! ( // Access to crate names passed via `--extern` through prelude (active, extern_prelude, "1.27.0", Some(44660), Some(Edition::Edition2018)), - // Scoped attributes - (active, tool_attributes, "1.25.0", Some(44690), None), // Scoped lints (active, tool_lints, "1.28.0", Some(44690), None), @@ -652,6 +647,10 @@ declare_features! ( (accepted, use_extern_macros, "1.30.0", Some(35896), None), // Allows keywords to be escaped for use as identifiers (accepted, raw_identifiers, "1.30.0", Some(48589), None), + // Attributes scoped to tools + (accepted, tool_attributes, "1.30.0", Some(44690), None), + // Allows multi-segment paths in attributes and derives + (accepted, proc_macro_path_invoc, "1.30.0", Some(38356), None), ); // If you change this, please modify src/doc/unstable-book as well. You must diff --git a/src/test/compile-fail-fulldeps/proc-macro/auxiliary/more-gates.rs b/src/test/compile-fail-fulldeps/proc-macro/auxiliary/more-gates.rs index 4d89384137b80..67fe93058aa89 100644 --- a/src/test/compile-fail-fulldeps/proc-macro/auxiliary/more-gates.rs +++ b/src/test/compile-fail-fulldeps/proc-macro/auxiliary/more-gates.rs @@ -16,11 +16,6 @@ extern crate proc_macro; use proc_macro::*; -#[proc_macro_attribute] -pub fn attr2mod(_: TokenStream, _: TokenStream) -> TokenStream { - "mod test {}".parse().unwrap() -} - #[proc_macro_attribute] pub fn attr2mac1(_: TokenStream, _: TokenStream) -> TokenStream { "macro_rules! foo1 { (a) => (a) }".parse().unwrap() @@ -31,11 +26,6 @@ pub fn attr2mac2(_: TokenStream, _: TokenStream) -> TokenStream { "macro foo2(a) { a }".parse().unwrap() } -#[proc_macro] -pub fn mac2mod(_: TokenStream) -> TokenStream { - "mod test2 {}".parse().unwrap() -} - #[proc_macro] pub fn mac2mac1(_: TokenStream) -> TokenStream { "macro_rules! foo3 { (a) => (a) }".parse().unwrap() @@ -49,7 +39,6 @@ pub fn mac2mac2(_: TokenStream) -> TokenStream { #[proc_macro] pub fn tricky(_: TokenStream) -> TokenStream { "fn foo() { - mod test {} macro_rules! foo { (a) => (a) } }".parse().unwrap() } diff --git a/src/test/compile-fail-fulldeps/proc-macro/more-gates.rs b/src/test/compile-fail-fulldeps/proc-macro/more-gates.rs index b7ab978b8ed0a..4c038179544ff 100644 --- a/src/test/compile-fail-fulldeps/proc-macro/more-gates.rs +++ b/src/test/compile-fail-fulldeps/proc-macro/more-gates.rs @@ -14,9 +14,6 @@ extern crate more_gates as foo; use foo::*; -#[attr2mod] -//~^ ERROR: cannot expand to modules -pub fn a() {} #[attr2mac1] //~^ ERROR: cannot expand to macro definitions pub fn a() {} @@ -24,12 +21,10 @@ pub fn a() {} //~^ ERROR: cannot expand to macro definitions pub fn a() {} -mac2mod!(); //~ ERROR: cannot expand to modules mac2mac1!(); //~ ERROR: cannot expand to macro definitions mac2mac2!(); //~ ERROR: cannot expand to macro definitions tricky!(); -//~^ ERROR: cannot expand to modules -//~| ERROR: cannot expand to macro definitions +//~^ ERROR: cannot expand to macro definitions fn main() {} diff --git a/src/test/compile-fail-fulldeps/proc-macro/proc-macro-gates.rs b/src/test/compile-fail-fulldeps/proc-macro/proc-macro-gates.rs index 96f68341db7a7..5cf65103ba3eb 100644 --- a/src/test/compile-fail-fulldeps/proc-macro/proc-macro-gates.rs +++ b/src/test/compile-fail-fulldeps/proc-macro/proc-macro-gates.rs @@ -10,7 +10,6 @@ // aux-build:proc-macro-gates.rs // gate-test-proc_macro_non_items -// gate-test-proc_macro_path_invoc // gate-test-proc_macro_mod line // gate-test-proc_macro_expr // gate-test-proc_macro_mod @@ -22,20 +21,15 @@ extern crate proc_macro_gates as foo; use foo::*; -#[foo::a] //~ ERROR: non-ident attribute macro paths are unstable -fn _test() {} - fn _test_inner() { #![a] // OK } #[a] //~ ERROR: custom attributes cannot be applied to modules -//~| ERROR: procedural macros cannot expand to modules mod _test2 {} mod _test2_inner { #![a] //~ ERROR: custom attributes cannot be applied to modules - //~| ERROR: procedural macros cannot expand to modules } #[a = y] //~ ERROR: must only be followed by a delimiter token diff --git a/src/test/run-pass-fulldeps/proc-macro/derive-b.rs b/src/test/run-pass-fulldeps/proc-macro/derive-b.rs index 1de6496e29f8b..ac9eca3822669 100644 --- a/src/test/run-pass-fulldeps/proc-macro/derive-b.rs +++ b/src/test/run-pass-fulldeps/proc-macro/derive-b.rs @@ -11,7 +11,7 @@ // aux-build:derive-b.rs // ignore-stage1 -#![feature(proc_macro_path_invoc, unrestricted_attribute_tokens)] +#![feature(unrestricted_attribute_tokens)] extern crate derive_b; diff --git a/src/test/run-pass-fulldeps/proc-macro/issue-42708.rs b/src/test/run-pass-fulldeps/proc-macro/issue-42708.rs index d4af99f97c5c8..7bbdbc6505db5 100644 --- a/src/test/run-pass-fulldeps/proc-macro/issue-42708.rs +++ b/src/test/run-pass-fulldeps/proc-macro/issue-42708.rs @@ -11,7 +11,7 @@ // aux-build:issue-42708.rs // ignore-stage1 -#![feature(decl_macro, proc_macro_path_invoc)] +#![feature(decl_macro)] #![allow(unused)] extern crate issue_42708; diff --git a/src/test/run-pass-fulldeps/proc-macro/issue-50061.rs b/src/test/run-pass-fulldeps/proc-macro/issue-50061.rs index 53783e7fedb29..410faaeb3eeac 100644 --- a/src/test/run-pass-fulldeps/proc-macro/issue-50061.rs +++ b/src/test/run-pass-fulldeps/proc-macro/issue-50061.rs @@ -11,7 +11,7 @@ // aux-build:issue-50061.rs // ignore-stage1 -#![feature(proc_macro_path_invoc, decl_macro)] +#![feature(decl_macro)] extern crate issue_50061; diff --git a/src/test/run-pass/tool_attributes.rs b/src/test/run-pass/tool_attributes.rs index eb13930de403f..9d8e56e44cbb3 100644 --- a/src/test/run-pass/tool_attributes.rs +++ b/src/test/run-pass/tool_attributes.rs @@ -10,7 +10,6 @@ // Scoped attributes should not trigger an unused attributes lint. -#![feature(tool_attributes)] #![deny(unused_attributes)] fn main() { diff --git a/src/test/ui-fulldeps/proc-macro/generate-mod.rs b/src/test/ui-fulldeps/proc-macro/generate-mod.rs index 6ac6e4f6def5c..977faf7decdf5 100644 --- a/src/test/ui-fulldeps/proc-macro/generate-mod.rs +++ b/src/test/ui-fulldeps/proc-macro/generate-mod.rs @@ -12,8 +12,6 @@ // aux-build:generate-mod.rs -#![feature(proc_macro_gen, proc_macro_path_invoc)] - extern crate generate_mod; struct FromOutside; diff --git a/src/test/ui-fulldeps/proc-macro/generate-mod.stderr b/src/test/ui-fulldeps/proc-macro/generate-mod.stderr index 87e5fe2554264..a981b1bc8b85a 100644 --- a/src/test/ui-fulldeps/proc-macro/generate-mod.stderr +++ b/src/test/ui-fulldeps/proc-macro/generate-mod.stderr @@ -1,29 +1,29 @@ error[E0412]: cannot find type `FromOutside` in this scope - --> $DIR/generate-mod.rs:21:1 + --> $DIR/generate-mod.rs:19:1 | LL | generate_mod::check!(); //~ ERROR cannot find type `FromOutside` in this scope | ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope error[E0412]: cannot find type `Outer` in this scope - --> $DIR/generate-mod.rs:21:1 + --> $DIR/generate-mod.rs:19:1 | LL | generate_mod::check!(); //~ ERROR cannot find type `FromOutside` in this scope | ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope error[E0412]: cannot find type `FromOutside` in this scope - --> $DIR/generate-mod.rs:24:1 + --> $DIR/generate-mod.rs:22:1 | LL | #[generate_mod::check_attr] //~ ERROR cannot find type `FromOutside` in this scope | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope error[E0412]: cannot find type `OuterAttr` in this scope - --> $DIR/generate-mod.rs:24:1 + --> $DIR/generate-mod.rs:22:1 | LL | #[generate_mod::check_attr] //~ ERROR cannot find type `FromOutside` in this scope | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope warning: cannot find type `FromOutside` in this scope - --> $DIR/generate-mod.rs:28:10 + --> $DIR/generate-mod.rs:26:10 | LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope | ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import @@ -33,7 +33,7 @@ LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside = note: for more information, see issue #50504 warning: cannot find type `OuterDerive` in this scope - --> $DIR/generate-mod.rs:28:10 + --> $DIR/generate-mod.rs:26:10 | LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope | ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import @@ -42,7 +42,7 @@ LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside = note: for more information, see issue #50504 warning: cannot find type `FromOutside` in this scope - --> $DIR/generate-mod.rs:35:14 + --> $DIR/generate-mod.rs:33:14 | LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope | ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import @@ -51,7 +51,7 @@ LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOut = note: for more information, see issue #50504 warning: cannot find type `OuterDerive` in this scope - --> $DIR/generate-mod.rs:35:14 + --> $DIR/generate-mod.rs:33:14 | LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope | ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import diff --git a/src/test/ui/custom-attribute-multisegment.rs b/src/test/ui/custom-attribute-multisegment.rs index ad8e0e76e1413..a8d82a3594649 100644 --- a/src/test/ui/custom-attribute-multisegment.rs +++ b/src/test/ui/custom-attribute-multisegment.rs @@ -10,7 +10,7 @@ // Unresolved multi-segment attributes are not treated as custom. -#![feature(custom_attribute, proc_macro_path_invoc)] +#![feature(custom_attribute)] mod existent {} diff --git a/src/test/ui/feature-gates/feature-gate-tool_attributes.rs b/src/test/ui/feature-gates/feature-gate-tool_attributes.rs deleted file mode 100644 index 5aa1670b82888..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-tool_attributes.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - #[rustfmt::skip] //~ ERROR tool attributes are unstable - let x = 3 - ; -} diff --git a/src/test/ui/feature-gates/feature-gate-tool_attributes.stderr b/src/test/ui/feature-gates/feature-gate-tool_attributes.stderr deleted file mode 100644 index b024059d45014..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-tool_attributes.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0658]: tool attributes are unstable (see issue #44690) - --> $DIR/feature-gate-tool_attributes.rs:12:7 - | -LL | #[rustfmt::skip] //~ ERROR tool attributes are unstable - | ^^^^^^^^^^^^^ - | - = help: add #![feature(tool_attributes)] to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/tool-attributes/tool-attributes-misplaced-1.rs b/src/test/ui/tool-attributes/tool-attributes-misplaced-1.rs index 7a6b9ae9943bc..8d3cfb5a16706 100644 --- a/src/test/ui/tool-attributes/tool-attributes-misplaced-1.rs +++ b/src/test/ui/tool-attributes/tool-attributes-misplaced-1.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(tool_attributes, custom_attribute)] +#![feature(custom_attribute)] type A = rustfmt; //~ ERROR expected type, found tool module `rustfmt` type B = rustfmt::skip; //~ ERROR expected type, found tool attribute `rustfmt::skip` diff --git a/src/test/ui/tool-attributes/tool-attributes-misplaced-2.rs b/src/test/ui/tool-attributes/tool-attributes-misplaced-2.rs index 102edf2813b21..e61ea9d5b443f 100644 --- a/src/test/ui/tool-attributes/tool-attributes-misplaced-2.rs +++ b/src/test/ui/tool-attributes/tool-attributes-misplaced-2.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(tool_attributes)] - #[derive(rustfmt::skip)] //~ ERROR expected a macro, found tool attribute struct S; diff --git a/src/test/ui/tool-attributes/tool-attributes-misplaced-2.stderr b/src/test/ui/tool-attributes/tool-attributes-misplaced-2.stderr index 5b968cd6b8ecd..ae47203a97580 100644 --- a/src/test/ui/tool-attributes/tool-attributes-misplaced-2.stderr +++ b/src/test/ui/tool-attributes/tool-attributes-misplaced-2.stderr @@ -1,11 +1,11 @@ error: expected a macro, found tool attribute - --> $DIR/tool-attributes-misplaced-2.rs:13:10 + --> $DIR/tool-attributes-misplaced-2.rs:11:10 | LL | #[derive(rustfmt::skip)] //~ ERROR expected a macro, found tool attribute | ^^^^^^^^^^^^^ error: expected a macro, found tool attribute - --> $DIR/tool-attributes-misplaced-2.rs:17:5 + --> $DIR/tool-attributes-misplaced-2.rs:15:5 | LL | rustfmt::skip!(); //~ ERROR expected a macro, found tool attribute | ^^^^^^^^^^^^^ diff --git a/src/test/ui/tool-attributes/tool-attributes-shadowing.rs b/src/test/ui/tool-attributes/tool-attributes-shadowing.rs index 7913c9f40b553..b6a24ccf748e1 100644 --- a/src/test/ui/tool-attributes/tool-attributes-shadowing.rs +++ b/src/test/ui/tool-attributes/tool-attributes-shadowing.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(tool_attributes, proc_macro_path_invoc)] - mod rustfmt {} #[rustfmt::skip] //~ ERROR failed to resolve. Could not find `skip` in `rustfmt` diff --git a/src/test/ui/tool-attributes/tool-attributes-shadowing.stderr b/src/test/ui/tool-attributes/tool-attributes-shadowing.stderr index f668d677f7a20..d593350f123c6 100644 --- a/src/test/ui/tool-attributes/tool-attributes-shadowing.stderr +++ b/src/test/ui/tool-attributes/tool-attributes-shadowing.stderr @@ -1,5 +1,5 @@ error[E0433]: failed to resolve. Could not find `skip` in `rustfmt` - --> $DIR/tool-attributes-shadowing.rs:15:12 + --> $DIR/tool-attributes-shadowing.rs:13:12 | LL | #[rustfmt::skip] //~ ERROR failed to resolve. Could not find `skip` in `rustfmt` | ^^^^ Could not find `skip` in `rustfmt` diff --git a/src/test/ui/unknown-tool-name.rs b/src/test/ui/unknown-tool-name.rs index 99c336c28cd29..cd2aeb7494a5a 100644 --- a/src/test/ui/unknown-tool-name.rs +++ b/src/test/ui/unknown-tool-name.rs @@ -8,7 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(proc_macro_path_invoc)] - #[foo::bar] //~ ERROR failed to resolve. Use of undeclared type or module `foo` fn main() {} diff --git a/src/test/ui/unknown-tool-name.stderr b/src/test/ui/unknown-tool-name.stderr index 151f957ac568a..8381c6de83a67 100644 --- a/src/test/ui/unknown-tool-name.stderr +++ b/src/test/ui/unknown-tool-name.stderr @@ -1,5 +1,5 @@ error[E0433]: failed to resolve. Use of undeclared type or module `foo` - --> $DIR/unknown-tool-name.rs:13:3 + --> $DIR/unknown-tool-name.rs:11:3 | LL | #[foo::bar] //~ ERROR failed to resolve. Use of undeclared type or module `foo` | ^^^ Use of undeclared type or module `foo` From a15b61780b24a2311a3e42a3437b3418921a3ed3 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 22 Aug 2018 15:18:45 -0700 Subject: [PATCH 20/21] tidy: Stop requiring a license header Previously approved in rust-lang/rust#43498 ; update tidy to match. --- src/tools/tidy/src/style.rs | 53 ------------------------------------- 1 file changed, 53 deletions(-) diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index f2f35f0f58602..6b431ccda0883 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -17,7 +17,6 @@ //! * No trailing whitespace //! * No CR characters //! * No `TODO` or `XXX` directives -//! * A valid license header is at the top //! * No unexplained ` ```ignore ` or ` ```rust,ignore ` doc tests //! //! A number of these checks can be opted-out of with various directives like @@ -28,16 +27,6 @@ use std::io::prelude::*; use std::path::Path; const COLS: usize = 100; -const LICENSE: &'static str = "\ -Copyright The Rust Project Developers. See the COPYRIGHT -file at the top-level directory of this distribution and at -http://rust-lang.org/COPYRIGHT. - -Licensed under the Apache License, Version 2.0 or the MIT license -, at your -option. This file may not be copied, modified, or distributed -except according to those terms."; const UNEXPLAINED_IGNORE_DOCTEST_INFO: &str = r#"unexplained "```ignore" doctest; try one: @@ -168,9 +157,6 @@ pub fn check(path: &Path, bad: &mut bool) { trailing_new_lines = 0; } } - if !licenseck(file, &contents) { - tidy_error!(bad, "{}: incorrect license", file.display()); - } match trailing_new_lines { 0 => tidy_error!(bad, "{}: missing trailing newline", file.display()), 1 | 2 => {} @@ -178,42 +164,3 @@ pub fn check(path: &Path, bad: &mut bool) { }; }) } - -fn licenseck(file: &Path, contents: &str) -> bool { - if contents.contains("ignore-license") { - return true - } - let exceptions = [ - "libstd/sync/mpsc/mpsc_queue.rs", - "libstd/sync/mpsc/spsc_queue.rs", - ]; - if exceptions.iter().any(|f| file.ends_with(f)) { - return true - } - - // Skip the BOM if it's there - let bom = "\u{feff}"; - let contents = if contents.starts_with(bom) {&contents[3..]} else {contents}; - - // See if the license shows up in the first 100 lines - let lines = contents.lines().take(100).collect::>(); - lines.windows(LICENSE.lines().count()).any(|window| { - let offset = if window.iter().all(|w| w.starts_with("//")) { - 2 - } else if window.iter().all(|w| w.starts_with('#')) { - 1 - } else if window.iter().all(|w| w.starts_with(" *")) { - 2 - } else { - return false - }; - window.iter().map(|a| a[offset..].trim()) - .zip(LICENSE.lines()).all(|(a, b)| { - a == b || match b.find("") { - Some(i) => a.starts_with(&b[..i]) && a.ends_with(&b[i+6..]), - None => false, - } - }) - }) - -} From b188c2a4eb7a3eede8477e3fbeaea623fc256586 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 21 Aug 2018 14:44:36 +0100 Subject: [PATCH 21/21] Lament the invincibility of the Turbofish --- src/test/ui/bastion-of-the-turbofish.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/ui/bastion-of-the-turbofish.rs b/src/test/ui/bastion-of-the-turbofish.rs index bd789737552c1..eadd23896095d 100644 --- a/src/test/ui/bastion-of-the-turbofish.rs +++ b/src/test/ui/bastion-of-the-turbofish.rs @@ -36,6 +36,10 @@ // My heart aches in sorrow, for I know I am defeated. Let this be a warning // to all those who come after. Here stands the bastion of the Turbofish. +// See https://github.com/rust-lang/rust/pull/53562 +// and https://github.com/rust-lang/rfcs/pull/2527 +// for context. + fn main() { let (oh, woe, is, me) = ("the", "Turbofish", "remains", "undefeated"); let _: (bool, bool) = (oh(me));