From 0337cc117d3c972b7b98e5c09212d58d3d16a009 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 21 Aug 2019 00:37:17 +0000 Subject: [PATCH 01/14] Use more optimal Ord implementation for integers --- src/libcore/cmp.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index cb9feb074dd70..74e9ceb510a99 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -1012,9 +1012,9 @@ mod impls { impl Ord for $t { #[inline] fn cmp(&self, other: &$t) -> Ordering { - if *self == *other { Equal } - else if *self < *other { Less } - else { Greater } + if *self < *other { Less } + else if *self > *other { Greater } + else { Equal } } } )*) From 96983fc53009a2a2d2f93e7cec012634800be1fa Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 21 Aug 2019 06:25:37 +0000 Subject: [PATCH 02/14] Add comment to avoid accidentally remove the changes. --- src/libcore/cmp.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 74e9ceb510a99..167a9dd1c3620 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -1012,6 +1012,8 @@ mod impls { impl Ord for $t { #[inline] fn cmp(&self, other: &$t) -> Ordering { + // The order here is important to generate more optimal assembly. + // See for more info. if *self < *other { Less } else if *self > *other { Greater } else { Equal } From 3375b05cd03a60cd7e2df0e21e232c73ff8a01cb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 21 Aug 2019 13:10:06 +0200 Subject: [PATCH 03/14] Fix confusion in theme picker functions --- src/librustdoc/html/render.rs | 16 ++++++++-------- src/librustdoc/html/static/main.js | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ea97cea942820..ae988f6f9cafe 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -876,22 +876,22 @@ r#"var themes = document.getElementById("theme-choices"); var themePicker = document.getElementById("theme-picker"); function showThemeButtonState() {{ - themes.style.display = "none"; - themePicker.style.borderBottomRightRadius = "3px"; - themePicker.style.borderBottomLeftRadius = "3px"; -}} - -function hideThemeButtonState() {{ themes.style.display = "block"; themePicker.style.borderBottomRightRadius = "0"; themePicker.style.borderBottomLeftRadius = "0"; }} +function hideThemeButtonState() {{ + themes.style.display = "none"; + themePicker.style.borderBottomRightRadius = "3px"; + themePicker.style.borderBottomLeftRadius = "3px"; +}} + function switchThemeButtonState() {{ if (themes.style.display === "block") {{ - showThemeButtonState(); - }} else {{ hideThemeButtonState(); + }} else {{ + showThemeButtonState(); }} }}; diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 82d2c11b2497b..3d0f00095aca3 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -105,9 +105,9 @@ if (!DOMTokenList.prototype.remove) { sidebar.appendChild(div); } } - var themePicker = document.getElementsByClassName("theme-picker"); - if (themePicker && themePicker.length > 0) { - themePicker[0].style.display = "none"; + var themePickers = document.getElementsByClassName("theme-picker"); + if (themePickers && themePickers.length > 0) { + themePickers[0].style.display = "none"; } } @@ -123,9 +123,9 @@ if (!DOMTokenList.prototype.remove) { filler.remove(); } document.getElementsByTagName("body")[0].style.marginTop = ""; - var themePicker = document.getElementsByClassName("theme-picker"); - if (themePicker && themePicker.length > 0) { - themePicker[0].style.display = null; + var themePickers = document.getElementsByClassName("theme-picker"); + if (themePickers && themePickers.length > 0) { + themePickers[0].style.display = null; } } From a9900be9f41176003c0a1a613686b2e443342466 Mon Sep 17 00:00:00 2001 From: Mark Mansi Date: Wed, 21 Aug 2019 10:16:57 -0500 Subject: [PATCH 04/14] add amanjeev --- src/tools/publish_toolstate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/publish_toolstate.py b/src/tools/publish_toolstate.py index b8dcba3afc3a1..648838d26efe9 100755 --- a/src/tools/publish_toolstate.py +++ b/src/tools/publish_toolstate.py @@ -34,7 +34,7 @@ '@ryankurte @thejpster @therealprof' ), 'edition-guide': '@ehuss @Centril @steveklabnik', - 'rustc-guide': '@mark-i-m @spastorino' + 'rustc-guide': '@mark-i-m @spastorino @amanjeev' } REPOS = { From f5b16f6212d2d72d505d4d6b1dedc2c9c61dd014 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 21 Aug 2019 15:50:43 +0000 Subject: [PATCH 05/14] Add codegen test for integers compare --- src/test/codegen/integer-cmp.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/codegen/integer-cmp.rs diff --git a/src/test/codegen/integer-cmp.rs b/src/test/codegen/integer-cmp.rs new file mode 100644 index 0000000000000..1373b12e3721c --- /dev/null +++ b/src/test/codegen/integer-cmp.rs @@ -0,0 +1,28 @@ +// This is test for more optimal Ord implementation for integers. +// See for more info. + +// compile-flags: -C opt-level=3 + +#![crate_type = "lib"] + +use std::cmp::Ordering; + +// CHECK-LABEL: @cmp_signed +#[no_mangle] +pub fn cmp_signed(a: i64, b: i64) -> Ordering { +// CHECK: icmp slt +// CHECK: icmp sgt +// CHECK: zext i1 +// CHECK: select i1 + a.cmp(&b) +} + +// CHECK-LABEL: @cmp_unsigned +#[no_mangle] +pub fn cmp_unsigned(a: u32, b: u32) -> Ordering { +// CHECK: icmp ult +// CHECK: icmp ugt +// CHECK: zext i1 +// CHECK: select i1 + a.cmp(&b) +} From 1c829877824aeda82e78ed3a0ecb12a3cb0b2d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 21 Aug 2019 11:46:31 -0700 Subject: [PATCH 06/14] Fix typo in E0308 if/else label --- src/librustc/infer/error_reporting/mod.rs | 2 +- src/librustc/ty/error.rs | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 84687b8cab5c0..9be73cf3c6d16 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1650,7 +1650,7 @@ impl<'tcx> ObligationCause<'tcx> { hir::MatchSource::IfLetDesugar { .. } => "`if let` arms have compatible types", _ => "match arms have compatible types", }, - IfExpression { .. } => "if and else have compatible types", + IfExpression { .. } => "if and else have incompatible types", IfExpressionWithNoElse => "if missing an else returns ()", MainFunctionType => "`main` function has the correct type", StartFunctionType => "`start` function has the correct type", diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index d6d17a67e01e9..6daecd7ae941a 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -247,13 +247,15 @@ impl<'tcx> ty::TyS<'tcx> { } impl<'tcx> TyCtxt<'tcx> { - pub fn note_and_explain_type_err(self, - db: &mut DiagnosticBuilder<'_>, - err: &TypeError<'tcx>, - sp: Span) { + pub fn note_and_explain_type_err( + self, + db: &mut DiagnosticBuilder<'_>, + err: &TypeError<'tcx>, + sp: Span, + ) { use self::TypeError::*; - match err.clone() { + match err { Sorts(values) => { let expected_str = values.expected.sort_string(self); let found_str = values.found.sort_string(self); @@ -261,6 +263,15 @@ impl<'tcx> TyCtxt<'tcx> { db.note("no two closures, even if identical, have the same type"); db.help("consider boxing your closure and/or using it as a trait object"); } + if expected_str == found_str && expected_str == "opaque type" { // Issue #63167 + db.note("distinct uses of `impl Trait` result in different opaque types"); + let e_str = values.expected.to_string(); + let f_str = values.found.to_string(); + if &e_str == &f_str && &e_str == "impl std::future::Future" { + db.help("if both futures resolve to the same type, consider `await`ing \ + on both of them"); + } + } if let (ty::Infer(ty::IntVar(_)), ty::Float(_)) = (&values.found.sty, &values.expected.sty) // Issue #53280 { From ba8e09415b00fdfcda8feeb1cf233f2f065ef6c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 21 Aug 2019 11:49:51 -0700 Subject: [PATCH 07/14] Add clarification on E0308 about opaque types --- src/librustc/ty/error.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 6daecd7ae941a..c1593799286ef 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -268,6 +268,7 @@ impl<'tcx> TyCtxt<'tcx> { let e_str = values.expected.to_string(); let f_str = values.found.to_string(); if &e_str == &f_str && &e_str == "impl std::future::Future" { + // FIXME: use non-string based check. db.help("if both futures resolve to the same type, consider `await`ing \ on both of them"); } From 8c07d7814d2eb2cab14e5c57313e68880b60a14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 15 Aug 2019 18:58:20 -0700 Subject: [PATCH 08/14] When declaring a declarative macro in an item it's only accessible inside it --- src/librustc/hir/map/mod.rs | 13 +++--- src/librustc_privacy/lib.rs | 60 +++++++++++++++------------ src/test/ui/macros/macro-in-fn.rs | 9 ++++ src/test/ui/macros/macro-in-fn.stderr | 8 ++++ 4 files changed, 58 insertions(+), 32 deletions(-) create mode 100644 src/test/ui/macros/macro-in-fn.rs create mode 100644 src/test/ui/macros/macro-in-fn.stderr diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 7292428ec378c..5bf310ce8d956 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -514,8 +514,11 @@ impl<'hir> Map<'hir> { &self.forest.krate.attrs } - pub fn get_module(&self, module: DefId) -> (&'hir Mod, Span, HirId) - { + pub fn get_module(&self, module: DefId) -> (&'hir Mod, Span, HirId) { + self.get_if_module(module).expect("not a module") + } + + pub fn get_if_module(&self, module: DefId) -> Option<(&'hir Mod, Span, HirId)> { let hir_id = self.as_local_hir_id(module).unwrap(); self.read(hir_id); match self.find_entry(hir_id).unwrap().node { @@ -523,9 +526,9 @@ impl<'hir> Map<'hir> { span, node: ItemKind::Mod(ref m), .. - }) => (m, span, hir_id), - Node::Crate => (&self.forest.krate.module, self.forest.krate.span, hir_id), - _ => panic!("not a module") + }) => Some((m, span, hir_id)), + Node::Crate => Some((&self.forest.krate.module, self.forest.krate.span, hir_id)), + _ => None, } } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index bca77621e553e..dc787d2253884 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -508,39 +508,45 @@ impl EmbargoVisitor<'tcx> { } } - fn update_macro_reachable_mod( - &mut self, - reachable_mod: hir::HirId, - defining_mod: DefId, - ) { - let module_def_id = self.tcx.hir().local_def_id(reachable_mod); - let module = self.tcx.hir().get_module(module_def_id).0; - for item_id in &module.item_ids { - let hir_id = item_id.id; - let item_def_id = self.tcx.hir().local_def_id(hir_id); - if let Some(def_kind) = self.tcx.def_kind(item_def_id) { - let item = self.tcx.hir().expect_item(hir_id); - let vis = ty::Visibility::from_hir(&item.vis, hir_id, self.tcx); - self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod); + fn update_macro_reachable_mod(&mut self, reachable_mod: hir::HirId, defining_mod: DefId) { + let set_vis = |this: &mut Self, hir_id: hir::HirId| { + let item_def_id = this.tcx.hir().local_def_id(hir_id); + if let Some(def_kind) = this.tcx.def_kind(item_def_id) { + let item = this.tcx.hir().expect_item(hir_id); + let vis = ty::Visibility::from_hir(&item.vis, hir_id, this.tcx); + this.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod); } - } + }; - if let Some(exports) = self.tcx.module_exports(module_def_id) { - for export in exports { - if export.vis.is_accessible_from(defining_mod, self.tcx) { - if let Res::Def(def_kind, def_id) = export.res { - let vis = def_id_visibility(self.tcx, def_id).0; - if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) { - self.update_macro_reachable_def( - hir_id, - def_kind, - vis, - defining_mod, - ); + let module_def_id = self.tcx.hir().local_def_id(reachable_mod); + if let Some((module, _, _)) = self.tcx.hir().get_if_module(module_def_id) { + for item_id in &module.item_ids { + let hir_id = item_id.id; + set_vis(self, hir_id); + } + if let Some(exports) = self.tcx.module_exports(module_def_id) { + for export in exports { + if export.vis.is_accessible_from(defining_mod, self.tcx) { + if let Res::Def(def_kind, def_id) = export.res { + let vis = def_id_visibility(self.tcx, def_id).0; + if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) { + self.update_macro_reachable_def( + hir_id, + def_kind, + vis, + defining_mod, + ); + } } } } } + } else if let Some(hir::Node::Item(hir::Item { + hir_id, + .. + })) = self.tcx.hir().get_if_local(module_def_id) { // #63164 + // `macro` defined inside of an item is only visible inside of that item's scope. + set_vis(self, *hir_id); } } diff --git a/src/test/ui/macros/macro-in-fn.rs b/src/test/ui/macros/macro-in-fn.rs new file mode 100644 index 0000000000000..1e46346fc01ea --- /dev/null +++ b/src/test/ui/macros/macro-in-fn.rs @@ -0,0 +1,9 @@ +#![feature(decl_macro)] + +pub fn moo() { + pub macro ABC() {{}} +} + +fn main() { + ABC!(); //~ ERROR cannot find macro `ABC!` in this scope +} diff --git a/src/test/ui/macros/macro-in-fn.stderr b/src/test/ui/macros/macro-in-fn.stderr new file mode 100644 index 0000000000000..0c35fe65aa285 --- /dev/null +++ b/src/test/ui/macros/macro-in-fn.stderr @@ -0,0 +1,8 @@ +error: cannot find macro `ABC!` in this scope + --> $DIR/macro-in-fn.rs:8:5 + | +LL | ABC!(); + | ^^^ + +error: aborting due to previous error + From 4971667f175e7e3d84b7a87f46633b3e069e48ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 21 Aug 2019 16:11:01 -0700 Subject: [PATCH 09/14] review comments --- src/librustc/hir/map/mod.rs | 20 ++++++---- src/librustc_privacy/lib.rs | 54 +++++++++++---------------- src/test/ui/macros/macro-in-fn.rs | 5 +-- src/test/ui/macros/macro-in-fn.stderr | 8 ---- 4 files changed, 36 insertions(+), 51 deletions(-) delete mode 100644 src/test/ui/macros/macro-in-fn.stderr diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 5bf310ce8d956..f80e527dfd9b7 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -515,10 +515,6 @@ impl<'hir> Map<'hir> { } pub fn get_module(&self, module: DefId) -> (&'hir Mod, Span, HirId) { - self.get_if_module(module).expect("not a module") - } - - pub fn get_if_module(&self, module: DefId) -> Option<(&'hir Mod, Span, HirId)> { let hir_id = self.as_local_hir_id(module).unwrap(); self.read(hir_id); match self.find_entry(hir_id).unwrap().node { @@ -526,9 +522,9 @@ impl<'hir> Map<'hir> { span, node: ItemKind::Mod(ref m), .. - }) => Some((m, span, hir_id)), - Node::Crate => Some((&self.forest.krate.module, self.forest.krate.span, hir_id)), - _ => None, + }) => (m, span, hir_id), + Node::Crate => (&self.forest.krate.module, self.forest.krate.span, hir_id), + node => panic!("not a module: {:?}", node), } } @@ -682,6 +678,16 @@ impl<'hir> Map<'hir> { } } + /// Wether `hir_id` corresponds to a `mod` or a crate. + pub fn is_hir_id_module(&self, hir_id: HirId) -> bool { + match self.lookup(hir_id) { + Some(Entry { node: Node::Item(Item { node: ItemKind::Mod(_), .. }), .. }) | + Some(Entry { node: Node::Crate, .. }) => true, + _ => false, + } + } + + /// If there is some error when walking the parents (e.g., a node does not /// have a parent in the map or a node can't be found), then we return the /// last good `HirId` we found. Note that reaching the crate root (`id == 0`), diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index dc787d2253884..146058963b69d 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -509,44 +509,28 @@ impl EmbargoVisitor<'tcx> { } fn update_macro_reachable_mod(&mut self, reachable_mod: hir::HirId, defining_mod: DefId) { - let set_vis = |this: &mut Self, hir_id: hir::HirId| { - let item_def_id = this.tcx.hir().local_def_id(hir_id); - if let Some(def_kind) = this.tcx.def_kind(item_def_id) { - let item = this.tcx.hir().expect_item(hir_id); - let vis = ty::Visibility::from_hir(&item.vis, hir_id, this.tcx); - this.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod); - } - }; - let module_def_id = self.tcx.hir().local_def_id(reachable_mod); - if let Some((module, _, _)) = self.tcx.hir().get_if_module(module_def_id) { - for item_id in &module.item_ids { - let hir_id = item_id.id; - set_vis(self, hir_id); + let module = self.tcx.hir().get_module(module_def_id).0; + for item_id in &module.item_ids { + let hir_id = item_id.id; + let item_def_id = self.tcx.hir().local_def_id(hir_id); + if let Some(def_kind) = self.tcx.def_kind(item_def_id) { + let item = self.tcx.hir().expect_item(hir_id); + let vis = ty::Visibility::from_hir(&item.vis, hir_id, self.tcx); + self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod); } - if let Some(exports) = self.tcx.module_exports(module_def_id) { - for export in exports { - if export.vis.is_accessible_from(defining_mod, self.tcx) { - if let Res::Def(def_kind, def_id) = export.res { - let vis = def_id_visibility(self.tcx, def_id).0; - if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) { - self.update_macro_reachable_def( - hir_id, - def_kind, - vis, - defining_mod, - ); - } + } + if let Some(exports) = self.tcx.module_exports(module_def_id) { + for export in exports { + if export.vis.is_accessible_from(defining_mod, self.tcx) { + if let Res::Def(def_kind, def_id) = export.res { + let vis = def_id_visibility(self.tcx, def_id).0; + if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) { + self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod); } } } } - } else if let Some(hir::Node::Item(hir::Item { - hir_id, - .. - })) = self.tcx.hir().get_if_local(module_def_id) { // #63164 - // `macro` defined inside of an item is only visible inside of that item's scope. - set_vis(self, *hir_id); } } @@ -898,10 +882,14 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { self.tcx.hir().local_def_id(md.hir_id) ).unwrap(); let mut module_id = self.tcx.hir().as_local_hir_id(macro_module_def_id).unwrap(); + if !self.tcx.hir().is_hir_id_module(module_id) { + // `module_id` doesn't correspond to a `mod`, return early (#63164). + return; + } let level = if md.vis.node.is_pub() { self.get(module_id) } else { None }; let new_level = self.update(md.hir_id, level); if new_level.is_none() { - return + return; } loop { diff --git a/src/test/ui/macros/macro-in-fn.rs b/src/test/ui/macros/macro-in-fn.rs index 1e46346fc01ea..d354fe4a7dbfa 100644 --- a/src/test/ui/macros/macro-in-fn.rs +++ b/src/test/ui/macros/macro-in-fn.rs @@ -1,9 +1,8 @@ +// run-pass #![feature(decl_macro)] pub fn moo() { pub macro ABC() {{}} } -fn main() { - ABC!(); //~ ERROR cannot find macro `ABC!` in this scope -} +fn main() {} diff --git a/src/test/ui/macros/macro-in-fn.stderr b/src/test/ui/macros/macro-in-fn.stderr deleted file mode 100644 index 0c35fe65aa285..0000000000000 --- a/src/test/ui/macros/macro-in-fn.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: cannot find macro `ABC!` in this scope - --> $DIR/macro-in-fn.rs:8:5 - | -LL | ABC!(); - | ^^^ - -error: aborting due to previous error - From a710c610b2ea1550014e9f6bd20e5e4aed8a716c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 21 Aug 2019 15:35:38 -0700 Subject: [PATCH 10/14] review comments: reword and add test --- src/librustc/ty/error.rs | 4 ++-- src/test/ui/suggestions/opaque-type-error.rs | 24 +++++++++++++++++++ .../ui/suggestions/opaque-type-error.stderr | 20 ++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/suggestions/opaque-type-error.rs create mode 100644 src/test/ui/suggestions/opaque-type-error.stderr diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index c1593799286ef..c70006b68d69a 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -269,8 +269,8 @@ impl<'tcx> TyCtxt<'tcx> { let f_str = values.found.to_string(); if &e_str == &f_str && &e_str == "impl std::future::Future" { // FIXME: use non-string based check. - db.help("if both futures resolve to the same type, consider `await`ing \ - on both of them"); + db.help("if both `Future`s have the same `Output` type, consider \ + `.await`ing on both of them"); } } if let (ty::Infer(ty::IntVar(_)), ty::Float(_)) = diff --git a/src/test/ui/suggestions/opaque-type-error.rs b/src/test/ui/suggestions/opaque-type-error.rs new file mode 100644 index 0000000000000..979bb60d48c12 --- /dev/null +++ b/src/test/ui/suggestions/opaque-type-error.rs @@ -0,0 +1,24 @@ +// edition:2018 +use core::future::Future; + +async fn base_thing() -> Result<(), ()> { + Ok(()) +} + +fn thing_one() -> impl Future> { + base_thing() +} + +fn thing_two() -> impl Future> { + base_thing() +} + +async fn thing() -> Result<(), ()> { + if true { + thing_one() + } else { + thing_two() //~ ERROR if and else have incompatible types + }.await +} + +fn main() {} diff --git a/src/test/ui/suggestions/opaque-type-error.stderr b/src/test/ui/suggestions/opaque-type-error.stderr new file mode 100644 index 0000000000000..3c9ea05aeceb2 --- /dev/null +++ b/src/test/ui/suggestions/opaque-type-error.stderr @@ -0,0 +1,20 @@ +error[E0308]: if and else have incompatible types + --> $DIR/opaque-type-error.rs:20:9 + | +LL | / if true { +LL | | thing_one() + | | ----------- expected because of this +LL | | } else { +LL | | thing_two() + | | ^^^^^^^^^^^ expected opaque type, found a different opaque type +LL | | }.await + | |_____- if and else have incompatible types + | + = note: expected type `impl std::future::Future` (opaque type) + found type `impl std::future::Future` (opaque type) + = note: distinct uses of `impl Trait` result in different opaque types + = help: if both `Future`s have the same `Output` type, consider `.await`ing on both of them + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 4f613ffeb000642ef2f7f3c2e3f25b5bd1938b5a Mon Sep 17 00:00:00 2001 From: YangHau Date: Tue, 20 Aug 2019 19:46:23 +0800 Subject: [PATCH 11/14] Fix naming misspelling --- ...terger-atomic.rs => non-integer-atomic.rs} | 0 ...tomic.stderr => non-integer-atomic.stderr} | 32 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) rename src/test/ui/{non-interger-atomic.rs => non-integer-atomic.rs} (100%) rename src/test/ui/{non-interger-atomic.stderr => non-integer-atomic.stderr} (83%) diff --git a/src/test/ui/non-interger-atomic.rs b/src/test/ui/non-integer-atomic.rs similarity index 100% rename from src/test/ui/non-interger-atomic.rs rename to src/test/ui/non-integer-atomic.rs diff --git a/src/test/ui/non-interger-atomic.stderr b/src/test/ui/non-integer-atomic.stderr similarity index 83% rename from src/test/ui/non-interger-atomic.stderr rename to src/test/ui/non-integer-atomic.stderr index 7d1130d238e2c..b3cf788d834d8 100644 --- a/src/test/ui/non-interger-atomic.stderr +++ b/src/test/ui/non-integer-atomic.stderr @@ -1,95 +1,95 @@ error[E0511]: invalid monomorphization of `atomic_load` intrinsic: expected basic integer type, found `bool` - --> $DIR/non-interger-atomic.rs:13:5 + --> $DIR/non-integer-atomic.rs:13:5 | LL | intrinsics::atomic_load(p); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer type, found `bool` - --> $DIR/non-interger-atomic.rs:18:5 + --> $DIR/non-integer-atomic.rs:18:5 | LL | intrinsics::atomic_store(p, v); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer type, found `bool` - --> $DIR/non-interger-atomic.rs:23:5 + --> $DIR/non-integer-atomic.rs:23:5 | LL | intrinsics::atomic_xchg(p, v); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer type, found `bool` - --> $DIR/non-interger-atomic.rs:28:5 + --> $DIR/non-integer-atomic.rs:28:5 | LL | intrinsics::atomic_cxchg(p, v, v); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_load` intrinsic: expected basic integer type, found `Foo` - --> $DIR/non-interger-atomic.rs:33:5 + --> $DIR/non-integer-atomic.rs:33:5 | LL | intrinsics::atomic_load(p); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer type, found `Foo` - --> $DIR/non-interger-atomic.rs:38:5 + --> $DIR/non-integer-atomic.rs:38:5 | LL | intrinsics::atomic_store(p, v); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer type, found `Foo` - --> $DIR/non-interger-atomic.rs:43:5 + --> $DIR/non-integer-atomic.rs:43:5 | LL | intrinsics::atomic_xchg(p, v); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer type, found `Foo` - --> $DIR/non-interger-atomic.rs:48:5 + --> $DIR/non-integer-atomic.rs:48:5 | LL | intrinsics::atomic_cxchg(p, v, v); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_load` intrinsic: expected basic integer type, found `&dyn std::ops::Fn()` - --> $DIR/non-interger-atomic.rs:53:5 + --> $DIR/non-integer-atomic.rs:53:5 | LL | intrinsics::atomic_load(p); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer type, found `&dyn std::ops::Fn()` - --> $DIR/non-interger-atomic.rs:58:5 + --> $DIR/non-integer-atomic.rs:58:5 | LL | intrinsics::atomic_store(p, v); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer type, found `&dyn std::ops::Fn()` - --> $DIR/non-interger-atomic.rs:63:5 + --> $DIR/non-integer-atomic.rs:63:5 | LL | intrinsics::atomic_xchg(p, v); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer type, found `&dyn std::ops::Fn()` - --> $DIR/non-interger-atomic.rs:68:5 + --> $DIR/non-integer-atomic.rs:68:5 | LL | intrinsics::atomic_cxchg(p, v, v); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_load` intrinsic: expected basic integer type, found `[u8; 100]` - --> $DIR/non-interger-atomic.rs:73:5 + --> $DIR/non-integer-atomic.rs:73:5 | LL | intrinsics::atomic_load(p); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer type, found `[u8; 100]` - --> $DIR/non-interger-atomic.rs:78:5 + --> $DIR/non-integer-atomic.rs:78:5 | LL | intrinsics::atomic_store(p, v); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer type, found `[u8; 100]` - --> $DIR/non-interger-atomic.rs:83:5 + --> $DIR/non-integer-atomic.rs:83:5 | LL | intrinsics::atomic_xchg(p, v); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer type, found `[u8; 100]` - --> $DIR/non-interger-atomic.rs:88:5 + --> $DIR/non-integer-atomic.rs:88:5 | LL | intrinsics::atomic_cxchg(p, v, v); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From b7ad3f9fc4b293fd5ada4b975910be26105e5847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 22 Aug 2019 11:44:57 +0200 Subject: [PATCH 12/14] Apply clippy::redundant_field_names suggestion --- src/build_helper/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs index a1aa18922b5c5..131d2034675e3 100644 --- a/src/build_helper/lib.rs +++ b/src/build_helper/lib.rs @@ -262,7 +262,7 @@ pub fn native_lib_boilerplate( if !up_to_date(Path::new("build.rs"), ×tamp) || !up_to_date(src_dir, ×tamp) { Ok(NativeLibBoilerplate { src_dir: src_dir.to_path_buf(), - out_dir: out_dir, + out_dir, }) } else { Err(()) From 7f4aba40fcdc00c41438a77d202276eaf5b58a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 22 Aug 2019 11:47:36 +0200 Subject: [PATCH 13/14] Apply clippy::needless_return suggestions --- src/libcore/iter/adapters/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/iter/adapters/mod.rs b/src/libcore/iter/adapters/mod.rs index a63434abd6c9f..f50781890ab22 100644 --- a/src/libcore/iter/adapters/mod.rs +++ b/src/libcore/iter/adapters/mod.rs @@ -1309,7 +1309,7 @@ impl DoubleEndedIterator for Peekable where I: DoubleEndedIterator { Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try { match self.peeked.take() { - Some(None) => return Try::from_ok(init), + Some(None) => Try::from_ok(init), Some(Some(v)) => match self.iter.try_rfold(init, &mut f).into_result() { Ok(acc) => f(acc, v), Err(e) => { @@ -1326,7 +1326,7 @@ impl DoubleEndedIterator for Peekable where I: DoubleEndedIterator { where Fold: FnMut(Acc, Self::Item) -> Acc, { match self.peeked { - Some(None) => return init, + Some(None) => init, Some(Some(v)) => { let acc = self.iter.rfold(init, &mut fold); fold(acc, v) From edabcddf4dbcc70228ac1db03b10df60decaf83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 22 Aug 2019 11:51:59 +0200 Subject: [PATCH 14/14] Apply clippy::let_and_return suggestion --- src/libcore/slice/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index bfbbb15c8d488..931768564ca3c 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -3026,8 +3026,7 @@ macro_rules! len { if size == 0 { // This _cannot_ use `unchecked_sub` because we depend on wrapping // to represent the length of long ZST slice iterators. - let diff = ($self.end as usize).wrapping_sub(start as usize); - diff + ($self.end as usize).wrapping_sub(start as usize) } else { // We know that `start <= end`, so can do better than `offset_from`, // which needs to deal in signed. By setting appropriate flags here