From 26fdde994d0c2a80bfa2322f81a93baaa90e788c Mon Sep 17 00:00:00 2001 From: bishtpawan Date: Tue, 31 Mar 2020 18:45:26 +0530 Subject: [PATCH 1/7] Add long error explanation for E0708 #61137 Refactor code as per the suggestions Refacotor code provide edition support --- src/librustc_error_codes/error_codes.rs | 3 +-- src/librustc_error_codes/error_codes/E0708.md | 26 +++++++++++++++++++ .../no-params-non-move-async-closure.stderr | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/librustc_error_codes/error_codes/E0708.md diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index 2f0a3fc1d1c..759a0b98e51 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -393,6 +393,7 @@ E0703: include_str!("./error_codes/E0703.md"), E0704: include_str!("./error_codes/E0704.md"), E0705: include_str!("./error_codes/E0705.md"), E0706: include_str!("./error_codes/E0706.md"), +E0708: include_str!("./error_codes/E0708.md"), E0710: include_str!("./error_codes/E0710.md"), E0712: include_str!("./error_codes/E0712.md"), E0713: include_str!("./error_codes/E0713.md"), @@ -605,8 +606,6 @@ E0751: include_str!("./error_codes/E0751.md"), E0696, // `continue` pointing to a labeled block // E0702, // replaced with a generic attribute input check // E0707, // multiple elided lifetimes used in arguments of `async fn` - E0708, // `async` non-`move` closures with parameters are not currently - // supported // E0709, // multiple different lifetimes used in arguments of `async fn` E0711, // a feature has been declared with conflicting stability attributes E0717, // rustc_promotable without stability attribute diff --git a/src/librustc_error_codes/error_codes/E0708.md b/src/librustc_error_codes/error_codes/E0708.md new file mode 100644 index 00000000000..a0f53e38b53 --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0708.md @@ -0,0 +1,26 @@ +`async` non-`move` closures with parameters are currently not supported. + +Erroneous code example: + +```compile_fail,edition2018 +#![feature(async_closure)] + +fn main() { + let add_one = async |num: u8| { // error! + num + 1 + }; +} +``` + +`async` with non-move is currently not supported with the current +version, you can use successfully by using move: + +```edition2018 +#![feature(async_closure)] + +fn main() { + let add_one = async move |num: u8| { // ok! + num + 1 + }; +} +``` diff --git a/src/test/ui/async-await/no-params-non-move-async-closure.stderr b/src/test/ui/async-await/no-params-non-move-async-closure.stderr index 04c8c325fe7..1f589c516a9 100644 --- a/src/test/ui/async-await/no-params-non-move-async-closure.stderr +++ b/src/test/ui/async-await/no-params-non-move-async-closure.stderr @@ -8,3 +8,4 @@ LL | let _ = async |x: u8| {}; error: aborting due to previous error +For more information about this error, try `rustc --explain E0708`. From d167408cb4efff3c0a5e404dbe5f097b87fa54fa Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 16 Apr 2020 14:24:52 +0200 Subject: [PATCH 2/7] simplify unused unsafe block handling --- src/librustc_mir/transform/check_unsafety.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 3ce9b875e16..595b0432015 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -641,13 +641,17 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) { } } - let mut unsafe_blocks: Vec<_> = unsafe_blocks.iter().collect(); - unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_id_to_node_id(*hir_id)); - let used_unsafe: FxHashSet<_> = - unsafe_blocks.iter().flat_map(|&&(id, used)| used.then_some(id)).collect(); - for &(block_id, is_used) in unsafe_blocks { - if !is_used { - report_unused_unsafe(tcx, &used_unsafe, block_id); + let (mut unsafe_used, mut unsafe_unused): (FxHashSet<_>, Vec<_>) = Default::default(); + for &(block_id, is_used) in unsafe_blocks.iter() { + if is_used { + unsafe_used.insert(block_id); + } else { + unsafe_unused.push(block_id); } } + unsafe_unused.sort_by_cached_key(|hir_id| tcx.hir().hir_id_to_node_id(*hir_id)); + + for &block_id in &unsafe_unused { + report_unused_unsafe(tcx, &unsafe_used, block_id); + } } From 672b7682b0e836d87ad4e06e0fed2daaa6c065e6 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 16 Apr 2020 14:53:09 +0200 Subject: [PATCH 3/7] sort unused unsafe blocks by Span instead of NodeId --- src/librustc_mir/transform/check_unsafety.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 595b0432015..567fa42c83a 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -649,7 +649,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) { unsafe_unused.push(block_id); } } - unsafe_unused.sort_by_cached_key(|hir_id| tcx.hir().hir_id_to_node_id(*hir_id)); + unsafe_unused.sort_by_cached_key(|hir_id| tcx.hir().span(*hir_id)); for &block_id in &unsafe_unused { report_unused_unsafe(tcx, &unsafe_used, block_id); From 26ba0dd45c29beb25307403ff827793429f6c1c3 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 16 Apr 2020 10:16:11 -0700 Subject: [PATCH 4/7] Update cargo --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cargo b/src/tools/cargo index 74e3a7d5b75..ebda5065ee8 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 74e3a7d5b756d7c0e94399fc29fcd154e792c22a +Subproject commit ebda5065ee8a1e46801380abcbac21a25bc7e755 From 66575c9962188aa2f16df04fa1fef1786f0d216f Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 16 Apr 2020 20:00:54 +0200 Subject: [PATCH 5/7] comment on the sorting of unused unsafe blocks --- src/librustc_mir/transform/check_unsafety.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 567fa42c83a..9f6b1963ce7 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -649,6 +649,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) { unsafe_unused.push(block_id); } } + // The unused unsafe blocks might not be in source order; sort them so that the unused unsafe + // error messages are properly aligned and the issue-45107 and lint-unused-unsafe tests pass. unsafe_unused.sort_by_cached_key(|hir_id| tcx.hir().span(*hir_id)); for &block_id in &unsafe_unused { From 9707bec3c5692774e01aaab51465f874107da160 Mon Sep 17 00:00:00 2001 From: Youngsuk Kim Date: Thu, 16 Apr 2020 16:26:14 -0400 Subject: [PATCH 6/7] Minor fixes to doc comments of 'VecDequeue' 1. Changed descriptions of `fn get` & `fn get_mut`. Since both of these functions are returning references, and not the owned value, I thought the doc comments could be fixed to be consistent with doc comments of `fn front` & `fn front_mut`. 2. Other changes are minor fixes or additions for clarification. Thank you for taking a look :) --- src/liballoc/collections/vec_deque.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index 0ed9773630e..06e00465e12 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -488,7 +488,7 @@ impl VecDeque { VecDeque { tail: 0, head: 0, buf: RawVec::with_capacity(cap) } } - /// Retrieves an element in the `VecDeque` by index. + /// Provides a reference to the element at the given index. /// /// Element at index 0 is the front of the queue. /// @@ -513,7 +513,7 @@ impl VecDeque { } } - /// Retrieves an element in the `VecDeque` mutably by index. + /// Provides a mutable reference to the element at the given index. /// /// Element at index 0 is the front of the queue. /// @@ -651,7 +651,7 @@ impl VecDeque { } } - /// Tries to reserves the minimum capacity for exactly `additional` more elements to + /// Tries to reserve the minimum capacity for exactly `additional` more elements to /// be inserted in the given `VecDeque`. After calling `reserve_exact`, /// capacity will be greater than or equal to `self.len() + additional`. /// Does nothing if the capacity is already sufficient. @@ -662,7 +662,7 @@ impl VecDeque { /// /// # Errors /// - /// If the capacity overflows, or the allocator reports a failure, then an error + /// If the capacity overflows `usize`, or the allocator reports a failure, then an error /// is returned. /// /// # Examples @@ -678,7 +678,7 @@ impl VecDeque { /// // Pre-reserve the memory, exiting if we can't /// output.try_reserve_exact(data.len())?; /// - /// // Now we know this can't OOM in the middle of our complex work + /// // Now we know this can't OOM(Out-Of-Memory) in the middle of our complex work /// output.extend(data.iter().map(|&val| { /// val * 2 + 5 // very complicated /// })); @@ -700,7 +700,7 @@ impl VecDeque { /// /// # Errors /// - /// If the capacity overflows, or the allocator reports a failure, then an error + /// If the capacity overflows `usize`, or the allocator reports a failure, then an error /// is returned. /// /// # Examples From 554847c513cecbc66ab20d253f8f7ce077b75256 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 16 Apr 2020 13:58:47 -0700 Subject: [PATCH 7/7] Dogfood or_patterns in rustdoc --- src/librustdoc/clean/mod.rs | 8 +++++--- src/librustdoc/clean/utils.rs | 2 +- src/librustdoc/html/highlight.rs | 8 ++------ src/librustdoc/html/markdown.rs | 4 ++-- src/librustdoc/html/render/cache.rs | 11 +++++++---- src/librustdoc/lib.rs | 1 + .../passes/collect_intra_doc_links.rs | 12 ++++++------ src/librustdoc/visit_ast.rs | 17 +++++++++-------- 8 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6e50264c098..ad9d54c345c 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -377,9 +377,11 @@ impl Clean for hir::Lifetime { fn clean(&self, cx: &DocContext<'_>) -> Lifetime { let def = cx.tcx.named_region(self.hir_id); match def { - Some(rl::Region::EarlyBound(_, node_id, _)) - | Some(rl::Region::LateBound(_, node_id, _)) - | Some(rl::Region::Free(_, node_id)) => { + Some( + rl::Region::EarlyBound(_, node_id, _) + | rl::Region::LateBound(_, node_id, _) + | rl::Region::Free(_, node_id), + ) => { if let Some(lt) = cx.lt_substs.borrow().get(&node_id).cloned() { return lt; } diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 2626ca638e8..24817170e36 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -586,7 +586,7 @@ pub fn resolve_type(cx: &DocContext<'_>, path: Path, id: hir::HirId) -> Type { Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => { return Generic(format!("{:#}", path.print())); } - Res::SelfTy(..) | Res::Def(DefKind::TyParam, _) | Res::Def(DefKind::AssocTy, _) => true, + Res::SelfTy(..) | Res::Def(DefKind::TyParam | DefKind::AssocTy, _) => true, _ => false, }; let did = register_res(&*cx, path.res); diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 02f1947c99e..c4bc73770a7 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -235,9 +235,7 @@ impl<'a> Classifier<'a> { // If this '&' or '*' token is followed by a non-whitespace token, assume that it's the // reference or dereference operator or a reference or pointer type, instead of the // bit-and or multiplication operator. - token::BinOp(token::And) | token::BinOp(token::Star) - if self.peek()? != &token::Whitespace => - { + token::BinOp(token::And | token::Star) if self.peek()? != &token::Whitespace => { Class::RefKeyWord } @@ -275,9 +273,7 @@ impl<'a> Classifier<'a> { | token::ModSep | token::LArrow | token::OpenDelim(_) - | token::CloseDelim(token::Brace) - | token::CloseDelim(token::Paren) - | token::CloseDelim(token::NoDelim) => Class::None, + | token::CloseDelim(token::Brace | token::Paren | token::NoDelim) => Class::None, token::Question => Class::QuestionMark, diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 9fe3e35d197..941e3a5fa98 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -850,7 +850,7 @@ pub fn plain_summary_line(md: &str) -> String { Event::Start(Tag::Heading(_)) => (None, 1), Event::Code(code) => (Some(format!("`{}`", code)), 0), Event::Text(ref s) if self.is_in > 0 => (Some(s.as_ref().to_owned()), 0), - Event::End(Tag::Paragraph) | Event::End(Tag::Heading(_)) => (None, -1), + Event::End(Tag::Paragraph | Tag::Heading(_)) => (None, -1), _ => (None, 0), }; if is_in > 0 || (is_in < 0 && self.is_in > 0) { @@ -909,7 +909,7 @@ pub fn markdown_links(md: &str) -> Vec<(String, Option>)> { debug!("found link: {}", dest); links.push(match dest { CowStr::Borrowed(s) => (s.to_owned(), locate(s)), - s @ CowStr::Boxed(..) | s @ CowStr::Inlined(..) => (s.into_string(), None), + s @ (CowStr::Boxed(..) | CowStr::Inlined(..)) => (s.into_string(), None), }); } } diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs index a8efb16a1d3..f3c5c12810b 100644 --- a/src/librustdoc/html/render/cache.rs +++ b/src/librustdoc/html/render/cache.rs @@ -294,10 +294,13 @@ impl DocFolder for Cache { // for where the type was defined. On the other // hand, `paths` always has the right // information if present. - Some(&(ref fqp, ItemType::Trait)) - | Some(&(ref fqp, ItemType::Struct)) - | Some(&(ref fqp, ItemType::Union)) - | Some(&(ref fqp, ItemType::Enum)) => Some(&fqp[..fqp.len() - 1]), + Some(&( + ref fqp, + ItemType::Trait + | ItemType::Struct + | ItemType::Union + | ItemType::Enum, + )) => Some(&fqp[..fqp.len() - 1]), Some(..) => Some(&*self.stack), None => None, }; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index b0d5a8e58e1..5fb7b7bf959 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -7,6 +7,7 @@ #![feature(box_syntax)] #![feature(in_band_lifetimes)] #![feature(nll)] +#![feature(or_patterns)] #![feature(test)] #![feature(vec_remove_item)] #![feature(ptr_offset_from)] diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 1821635bde4..8bfd42ac56a 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -149,7 +149,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { // In case this is a trait item, skip the // early return and try looking for the trait. let value = match res { - Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::AssocConst, _) => true, + Res::Def(DefKind::AssocFn | DefKind::AssocConst, _) => true, Res::Def(DefKind::AssocTy, _) => false, Res::Def(DefKind::Variant, _) => { return handle_variant(cx, res, extra_fragment); @@ -226,10 +226,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { } let ty_res = ty_res.map_id(|_| panic!("unexpected node_id")); match ty_res { - Res::Def(DefKind::Struct, did) - | Res::Def(DefKind::Union, did) - | Res::Def(DefKind::Enum, did) - | Res::Def(DefKind::TyAlias, did) => { + Res::Def( + DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::TyAlias, + did, + ) => { let item = cx .tcx .inherent_impls(did) @@ -814,7 +814,7 @@ fn ambiguity_error( for (res, ns) in candidates { let (action, mut suggestion) = match res { - Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::Fn, _) => { + Res::Def(DefKind::AssocFn | DefKind::Fn, _) => { ("add parentheses", format!("{}()", path_str)) } Res::Def(DefKind::Macro(..), _) => { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index bf4c4487927..b7a3b13cf04 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -309,14 +309,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { let attrs = clean::inline::load_attrs(self.cx, res_did); let self_is_hidden = attrs.lists(sym::doc).has_word(sym::hidden); match res { - Res::Def(DefKind::Trait, did) - | Res::Def(DefKind::Struct, did) - | Res::Def(DefKind::Union, did) - | Res::Def(DefKind::Enum, did) - | Res::Def(DefKind::ForeignTy, did) - | Res::Def(DefKind::TyAlias, did) - if !self_is_hidden => - { + Res::Def( + DefKind::Trait + | DefKind::Struct + | DefKind::Union + | DefKind::Enum + | DefKind::ForeignTy + | DefKind::TyAlias, + did, + ) if !self_is_hidden => { self.cx.renderinfo.get_mut().access_levels.map.insert(did, AccessLevel::Public); } Res::Def(DefKind::Mod, did) => {