From 2caaa074984cb504efbc72f6db67e37bcb3601f3 Mon Sep 17 00:00:00 2001 From: Liigo Zhuang Date: Thu, 20 May 2021 18:11:01 +0800 Subject: [PATCH 01/14] the foundation owns rust trademarks --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index af6a4090a27cb..330116c629208 100644 --- a/README.md +++ b/README.md @@ -273,8 +273,8 @@ See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT), and ## Trademark The Rust programming language is an open source, community project governed -by a core team. It is also sponsored by the Mozilla Foundation (“Mozilla”), -which owns and protects the Rust and Cargo trademarks and logos +by [the Rust Foundation][rust-foundation], +which also owns and protects the Rust and Cargo trademarks and logos (the “Rust Trademarks”). If you want to use these names or brands, please read the [media guide][media-guide]. @@ -282,5 +282,6 @@ If you want to use these names or brands, please read the [media guide][media-gu Third-party logos may be subject to third-party copyrights and trademarks. See [Licenses][policies-licenses] for details. +[rust-foundation]: https://foundation.rust-lang.org/ [media-guide]: https://www.rust-lang.org/policies/media-guide [policies-licenses]: https://www.rust-lang.org/policies/licenses From 9c65f9f47016aa478fe18225f91e962277113d96 Mon Sep 17 00:00:00 2001 From: Liigo Zhuang Date: Wed, 26 May 2021 10:51:13 +0800 Subject: [PATCH 02/14] this section is just about trademarks, not governance --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 330116c629208..d5bf2b2088268 100644 --- a/README.md +++ b/README.md @@ -272,10 +272,8 @@ See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT), and ## Trademark -The Rust programming language is an open source, community project governed -by [the Rust Foundation][rust-foundation], -which also owns and protects the Rust and Cargo trademarks and logos -(the “Rust Trademarks”). +[The Rust Foundation][rust-foundation] owns and protects the Rust and Cargo +trademarks and logos (the “Rust Trademarks”). If you want to use these names or brands, please read the [media guide][media-guide]. From 4e08bb52252a1b13410b83ab956597a869da124a Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Sun, 23 May 2021 13:31:04 +0200 Subject: [PATCH 03/14] Fix typo and improve documentation for E0632 --- compiler/rustc_error_codes/src/error_codes.rs | 3 +-- .../src/error_codes/E0632.md | 25 +++++++++++++++++++ compiler/rustc_lint/src/builtin.rs | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0632.md diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index ff7a2344e6953..df162f8dce026 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -361,6 +361,7 @@ E0626: include_str!("./error_codes/E0626.md"), E0627: include_str!("./error_codes/E0627.md"), E0628: include_str!("./error_codes/E0628.md"), E0631: include_str!("./error_codes/E0631.md"), +E0632: include_str!("./error_codes/E0632.md"), E0633: include_str!("./error_codes/E0633.md"), E0634: include_str!("./error_codes/E0634.md"), E0635: include_str!("./error_codes/E0635.md"), @@ -623,8 +624,6 @@ E0783: include_str!("./error_codes/E0783.md"), // E0629, // missing 'feature' (rustc_const_unstable) // E0630, // rustc_const_unstable attribute must be paired with stable/unstable // attribute - E0632, // cannot provide explicit generic arguments when `impl Trait` is - // used in argument position E0640, // infer outlives requirements // E0645, // trait aliases not finished E0667, // `impl Trait` in projections diff --git a/compiler/rustc_error_codes/src/error_codes/E0632.md b/compiler/rustc_error_codes/src/error_codes/E0632.md new file mode 100644 index 0000000000000..40840e894d623 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0632.md @@ -0,0 +1,25 @@ +An explicit generic argument was provided when calling a function that +uses `impl Trait` in argument position. + +Erroneous code example: + +```compile_fail,E0632 +fn foo(a: T, b: impl Clone) {} + +foo::(0i32, "abc".to_string()); +``` + +Either all generic arguments should be inferred at the call site, or +the function definition should use an explicit generic type parameter +instead of `impl Trait`. Example: + +``` +fn foo(a: T, b: impl Clone) {} +fn bar(a: T, b: U) {} + +foo(0i32, "abc".to_string()); + +bar::(0i32, "abc".to_string()); +bar::<_, _>(0i32, "abc".to_string()); +bar(0i32, "abc".to_string()); +``` diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 5479af1dc3099..76525abe3410a 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1084,7 +1084,7 @@ declare_lint! { /// /// ### Explanation /// - /// An function with generics must have its symbol mangled to accommodate + /// A function with generics must have its symbol mangled to accommodate /// the generic parameter. The [`no_mangle` attribute] has no effect in /// this situation, and should be removed. /// From 69c8573ab5901a478e363e0ad24bca765c2d3085 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Tue, 29 Jun 2021 12:49:08 +0200 Subject: [PATCH 04/14] Bless UI tests --- .../const-generics/impl-trait-with-const-arguments.full.stderr | 1 + .../ui/const-generics/impl-trait-with-const-arguments.min.stderr | 1 + src/test/ui/impl-trait/issues/universal-issue-48703.stderr | 1 + .../issues/universal-turbofish-in-method-issue-50950.stderr | 1 + src/test/ui/synthetic-param.stderr | 1 + 5 files changed, 5 insertions(+) diff --git a/src/test/ui/const-generics/impl-trait-with-const-arguments.full.stderr b/src/test/ui/const-generics/impl-trait-with-const-arguments.full.stderr index 26b965901a4c4..ebc8f458f79c7 100644 --- a/src/test/ui/const-generics/impl-trait-with-const-arguments.full.stderr +++ b/src/test/ui/const-generics/impl-trait-with-const-arguments.full.stderr @@ -6,3 +6,4 @@ LL | assert_eq!(f::<4usize>(Usizable), 20usize); error: aborting due to previous error +For more information about this error, try `rustc --explain E0632`. diff --git a/src/test/ui/const-generics/impl-trait-with-const-arguments.min.stderr b/src/test/ui/const-generics/impl-trait-with-const-arguments.min.stderr index 26b965901a4c4..ebc8f458f79c7 100644 --- a/src/test/ui/const-generics/impl-trait-with-const-arguments.min.stderr +++ b/src/test/ui/const-generics/impl-trait-with-const-arguments.min.stderr @@ -6,3 +6,4 @@ LL | assert_eq!(f::<4usize>(Usizable), 20usize); error: aborting due to previous error +For more information about this error, try `rustc --explain E0632`. diff --git a/src/test/ui/impl-trait/issues/universal-issue-48703.stderr b/src/test/ui/impl-trait/issues/universal-issue-48703.stderr index 8f05ab3c4940c..6800b37b5b175 100644 --- a/src/test/ui/impl-trait/issues/universal-issue-48703.stderr +++ b/src/test/ui/impl-trait/issues/universal-issue-48703.stderr @@ -6,3 +6,4 @@ LL | foo::('a'); error: aborting due to previous error +For more information about this error, try `rustc --explain E0632`. diff --git a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr b/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr index c980e9463e48a..db66d46109599 100644 --- a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr +++ b/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr @@ -8,3 +8,4 @@ LL | evt.handle_event::(|_evt| { error: aborting due to previous error +For more information about this error, try `rustc --explain E0632`. diff --git a/src/test/ui/synthetic-param.stderr b/src/test/ui/synthetic-param.stderr index 951d7edb7f523..101132d05fa0e 100644 --- a/src/test/ui/synthetic-param.stderr +++ b/src/test/ui/synthetic-param.stderr @@ -18,3 +18,4 @@ LL | Bar::::func::(42); error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0632`. From 2586e962e0924d832c708a7308d88da27d8bc01b Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Tue, 29 Jun 2021 22:11:48 +0200 Subject: [PATCH 05/14] Check node kind to avoid ICE in `check_expr_return()` --- compiler/rustc_typeck/src/check/expr.rs | 28 +++++++++++-------- .../ui/typeck/issue-86721-return-expr-ice.rs | 8 ++++++ .../typeck/issue-86721-return-expr-ice.stderr | 9 ++++++ 3 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 src/test/ui/typeck/issue-86721-return-expr-ice.rs create mode 100644 src/test/ui/typeck/issue-86721-return-expr-ice.stderr diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index f69839bf85903..1f929af6cc5e2 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -682,23 +682,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let encl_item_id = self.tcx.hir().get_parent_item(expr.hir_id); - let encl_item = self.tcx.hir().expect_item(encl_item_id); - if let hir::ItemKind::Fn(..) = encl_item.kind { - // We are inside a function body, so reporting "return statement - // outside of function body" needs an explanation. + // Somewhat confusingly, get_parent_item() does not necessarily return an + // item -- it can also return a Foreign-/Impl-/TraitItem or a Crate (see + // issue #86721). If it does, we still report the same error. + if let Some(hir::Node::Item(encl_item)) = self.tcx.hir().find(encl_item_id) { + if let hir::ItemKind::Fn(..) = encl_item.kind { + // We are inside a function body, so reporting "return statement + // outside of function body" needs an explanation. - let encl_body_owner_id = self.tcx.hir().enclosing_body_owner(expr.hir_id); + let encl_body_owner_id = self.tcx.hir().enclosing_body_owner(expr.hir_id); - // If this didn't hold, we would not have to report an error in - // the first place. - assert_ne!(encl_item_id, encl_body_owner_id); + // If this didn't hold, we would not have to report an error in + // the first place. + assert_ne!(encl_item_id, encl_body_owner_id); - let encl_body_id = self.tcx.hir().body_owned_by(encl_body_owner_id); - let encl_body = self.tcx.hir().body(encl_body_id); + let encl_body_id = self.tcx.hir().body_owned_by(encl_body_owner_id); + let encl_body = self.tcx.hir().body(encl_body_id); - err.encl_body_span = Some(encl_body.value.span); - err.encl_fn_span = Some(encl_item.span); + err.encl_body_span = Some(encl_body.value.span); + err.encl_fn_span = Some(encl_item.span); + } } self.tcx.sess.emit_err(err); diff --git a/src/test/ui/typeck/issue-86721-return-expr-ice.rs b/src/test/ui/typeck/issue-86721-return-expr-ice.rs new file mode 100644 index 0000000000000..9216fb0d17139 --- /dev/null +++ b/src/test/ui/typeck/issue-86721-return-expr-ice.rs @@ -0,0 +1,8 @@ +// Regression test for the ICE described in #86721. + +#![crate_type="lib"] + +trait T { + const U: usize = return; + //~^ ERROR: return statement outside of function body [E0572] +} diff --git a/src/test/ui/typeck/issue-86721-return-expr-ice.stderr b/src/test/ui/typeck/issue-86721-return-expr-ice.stderr new file mode 100644 index 0000000000000..39f8fb8da146d --- /dev/null +++ b/src/test/ui/typeck/issue-86721-return-expr-ice.stderr @@ -0,0 +1,9 @@ +error[E0572]: return statement outside of function body + --> $DIR/issue-86721-return-expr-ice.rs:6:22 + | +LL | const U: usize = return; + | ^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0572`. From fe822fe64dacc7e73b0b7e0bf1306b3b652bcc0e Mon Sep 17 00:00:00 2001 From: 1000teslas <47207223+1000teslas@users.noreply.github.com> Date: Sun, 13 Jun 2021 21:45:22 +1000 Subject: [PATCH 06/14] copy rust-lld as ld in dist --- src/bootstrap/dist.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 19895baf08f16..92853378e5881 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -400,12 +400,12 @@ impl Step for Rustc { // Copy over lld if it's there if builder.config.lld_enabled { - let exe = exe("rust-lld", compiler.host); - builder.copy(&src_dir.join(&exe), &dst_dir.join(&exe)); + let rust_lld = exe("rust-lld", compiler.host); + builder.copy(&src_dir.join(&rust_lld), &dst_dir.join(&rust_lld)); // for `-Z gcc-ld=lld` let gcc_lld_dir = dst_dir.join("gcc-ld"); t!(fs::create_dir(&gcc_lld_dir)); - builder.copy(&src_dir.join(&exe), &gcc_lld_dir.join(&exe)); + builder.copy(&src_dir.join(&rust_lld), &gcc_lld_dir.join(exe("ld", compiler.host))); } // Copy over llvm-dwp if it's there From 11fd8579e44950c0cca82bb389d255962854b9ce Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Wed, 30 Jun 2021 13:56:26 +0200 Subject: [PATCH 07/14] Emit explanatory note for functions in trait and impl items as well --- compiler/rustc_typeck/src/check/expr.rs | 24 ++++++++++++---- .../issue-86188-return-not-in-fn-body.rs | 19 +++++++++++++ .../issue-86188-return-not-in-fn-body.stderr | 28 +++++++++++++++++-- ...> issue-86721-return-expr-ice.rev1.stderr} | 2 +- .../issue-86721-return-expr-ice.rev2.stderr | 9 ++++++ .../ui/typeck/issue-86721-return-expr-ice.rs | 11 +++++++- 6 files changed, 83 insertions(+), 10 deletions(-) rename src/test/ui/typeck/{issue-86721-return-expr-ice.stderr => issue-86721-return-expr-ice.rev1.stderr} (83%) create mode 100644 src/test/ui/typeck/issue-86721-return-expr-ice.rev2.stderr diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 1f929af6cc5e2..de38c41e93ccd 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -683,11 +683,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let encl_item_id = self.tcx.hir().get_parent_item(expr.hir_id); - // Somewhat confusingly, get_parent_item() does not necessarily return an - // item -- it can also return a Foreign-/Impl-/TraitItem or a Crate (see - // issue #86721). If it does, we still report the same error. - if let Some(hir::Node::Item(encl_item)) = self.tcx.hir().find(encl_item_id) { - if let hir::ItemKind::Fn(..) = encl_item.kind { + if self.tcx.hir().maybe_body_owned_by(encl_item_id).is_some() { + if let Some(hir::Node::Item(hir::Item { + kind: hir::ItemKind::Fn(..), + span: encl_fn_span, + .. + })) + | Some(hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Fn(..), + span: encl_fn_span, + .. + })) + | Some(hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::Fn(..), + span: encl_fn_span, + .. + })) = self.tcx.hir().find(encl_item_id) + { // We are inside a function body, so reporting "return statement // outside of function body" needs an explanation. @@ -701,7 +713,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let encl_body = self.tcx.hir().body(encl_body_id); err.encl_body_span = Some(encl_body.value.span); - err.encl_fn_span = Some(encl_item.span); + err.encl_fn_span = Some(*encl_fn_span); } } diff --git a/src/test/ui/return/issue-86188-return-not-in-fn-body.rs b/src/test/ui/return/issue-86188-return-not-in-fn-body.rs index 23cc9f0512ca1..4f076fa069383 100644 --- a/src/test/ui/return/issue-86188-return-not-in-fn-body.rs +++ b/src/test/ui/return/issue-86188-return-not-in-fn-body.rs @@ -12,6 +12,25 @@ const C: [(); 42] = { }] }; +struct S {} +trait Tr { + fn foo(); + fn bar() { + //~^ NOTE: ...not the enclosing function body + [(); return]; + //~^ ERROR: return statement outside of function body [E0572] + //~| NOTE: the return is part of this body... + } +} +impl Tr for S { + fn foo() { + //~^ NOTE: ...not the enclosing function body + [(); return]; + //~^ ERROR: return statement outside of function body [E0572] + //~| NOTE: the return is part of this body... + } +} + fn main() { //~^ NOTE: ...not the enclosing function body [(); return || { diff --git a/src/test/ui/return/issue-86188-return-not-in-fn-body.stderr b/src/test/ui/return/issue-86188-return-not-in-fn-body.stderr index 9275cb91dd356..d7eeb3a729099 100644 --- a/src/test/ui/return/issue-86188-return-not-in-fn-body.stderr +++ b/src/test/ui/return/issue-86188-return-not-in-fn-body.stderr @@ -9,7 +9,31 @@ LL | | }] | |_____^ error[E0572]: return statement outside of function body - --> $DIR/issue-86188-return-not-in-fn-body.rs:17:10 + --> $DIR/issue-86188-return-not-in-fn-body.rs:20:14 + | +LL | / fn bar() { +LL | | +LL | | [(); return]; + | | ^^^^^^ the return is part of this body... +LL | | +LL | | +LL | | } + | |_____- ...not the enclosing function body + +error[E0572]: return statement outside of function body + --> $DIR/issue-86188-return-not-in-fn-body.rs:28:14 + | +LL | / fn foo() { +LL | | +LL | | [(); return]; + | | ^^^^^^ the return is part of this body... +LL | | +LL | | +LL | | } + | |_____- ...not the enclosing function body + +error[E0572]: return statement outside of function body + --> $DIR/issue-86188-return-not-in-fn-body.rs:36:10 | LL | / fn main() { LL | | @@ -23,6 +47,6 @@ LL | || }]; LL | | } | |_- ...not the enclosing function body -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0572`. diff --git a/src/test/ui/typeck/issue-86721-return-expr-ice.stderr b/src/test/ui/typeck/issue-86721-return-expr-ice.rev1.stderr similarity index 83% rename from src/test/ui/typeck/issue-86721-return-expr-ice.stderr rename to src/test/ui/typeck/issue-86721-return-expr-ice.rev1.stderr index 39f8fb8da146d..b1111fcf1484c 100644 --- a/src/test/ui/typeck/issue-86721-return-expr-ice.stderr +++ b/src/test/ui/typeck/issue-86721-return-expr-ice.rev1.stderr @@ -1,5 +1,5 @@ error[E0572]: return statement outside of function body - --> $DIR/issue-86721-return-expr-ice.rs:6:22 + --> $DIR/issue-86721-return-expr-ice.rs:9:22 | LL | const U: usize = return; | ^^^^^^ diff --git a/src/test/ui/typeck/issue-86721-return-expr-ice.rev2.stderr b/src/test/ui/typeck/issue-86721-return-expr-ice.rev2.stderr new file mode 100644 index 0000000000000..f489ae2002a13 --- /dev/null +++ b/src/test/ui/typeck/issue-86721-return-expr-ice.rev2.stderr @@ -0,0 +1,9 @@ +error[E0572]: return statement outside of function body + --> $DIR/issue-86721-return-expr-ice.rs:15:20 + | +LL | fn foo(a: [(); return]); + | ^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0572`. diff --git a/src/test/ui/typeck/issue-86721-return-expr-ice.rs b/src/test/ui/typeck/issue-86721-return-expr-ice.rs index 9216fb0d17139..cd7135f18b112 100644 --- a/src/test/ui/typeck/issue-86721-return-expr-ice.rs +++ b/src/test/ui/typeck/issue-86721-return-expr-ice.rs @@ -1,8 +1,17 @@ // Regression test for the ICE described in #86721. +// revisions: rev1 rev2 +#![cfg_attr(any(), rev1, rev2)] #![crate_type="lib"] +#[cfg(any(rev1))] trait T { const U: usize = return; - //~^ ERROR: return statement outside of function body [E0572] + //[rev1]~^ ERROR: return statement outside of function body [E0572] +} + +#[cfg(any(rev2))] +trait T2 { + fn foo(a: [(); return]); + //[rev2]~^ ERROR: return statement outside of function body [E0572] } From 7b62d28cf2ca427dde2635e1ae5147a774442c99 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 30 Jun 2021 14:11:09 +0200 Subject: [PATCH 08/14] Enforce search typed queries --- src/librustdoc/html/static/search.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/search.js b/src/librustdoc/html/static/search.js index 0aebb0e9d6588..f6343e4c3d246 100644 --- a/src/librustdoc/html/static/search.js +++ b/src/librustdoc/html/static/search.js @@ -801,7 +801,8 @@ window.initSearch = function(rawSearchIndex) { results_returned[fullId].lev = Math.min(results_returned[fullId].lev, returned); } - if (index !== -1 || lev <= MAX_LEV_DISTANCE) { + if (typePassesFilter(typeFilter, ty.ty) && + (index !== -1 || lev <= MAX_LEV_DISTANCE)) { if (index !== -1 && paths.length < 2) { lev = 0; } From 855923c895681976d7a3ce6ff376f9b4c3b21ae8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 30 Jun 2021 14:20:17 +0200 Subject: [PATCH 09/14] Add test to ensure that the typed queries are not including other types --- src/test/rustdoc-js-std/typed-query.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/test/rustdoc-js-std/typed-query.js diff --git a/src/test/rustdoc-js-std/typed-query.js b/src/test/rustdoc-js-std/typed-query.js new file mode 100644 index 0000000000000..f656aa72986fd --- /dev/null +++ b/src/test/rustdoc-js-std/typed-query.js @@ -0,0 +1,12 @@ +// exact-check + +const QUERY = 'macro:print'; + +const EXPECTED = { + 'others': [ + { 'path': 'std', 'name': 'print' }, + { 'path': 'std', 'name': 'eprint' }, + { 'path': 'std', 'name': 'println' }, + { 'path': 'std', 'name': 'eprintln' }, + ], +}; From 3b9453bfe23a861ac1622f3562df7f1f980a4b34 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 30 Jun 2021 23:56:43 +0800 Subject: [PATCH 10/14] use is_const_fn_raw when encoding constness this properly encodes cross-crate constness data. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 7600739800041..4231db620b012 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1223,7 +1223,12 @@ impl EncodeContext<'a, 'tcx> { let fn_data = if let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind { FnData { asyncness: sig.header.asyncness, - constness: sig.header.constness, + // Can be inside `impl const Trait`, so using sig.header.constness is not reliable + constness: if self.tcx.is_const_fn_raw(def_id) { + hir::Constness::Const + } else { + hir::Constness::NotConst + }, param_names: self.encode_fn_param_names_for_body(body), } } else { From c424510746c3e890157e3c30ad7fcf2051b9f769 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 30 Jun 2021 23:57:17 +0800 Subject: [PATCH 11/14] Add tests for cross-crate usage of `impl const` --- .../auxiliary/cross-crate.rs | 22 +++++++++++++++++++ .../cross-crate-feature-disabled.rs | 18 +++++++++++++++ .../cross-crate-feature-disabled.stderr | 15 +++++++++++++ .../cross-crate-feature-enabled.rs | 20 +++++++++++++++++ .../cross-crate-feature-enabled.stderr | 9 ++++++++ 5 files changed, 84 insertions(+) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/auxiliary/cross-crate.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-disabled.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-disabled.stderr create mode 100644 src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.stderr diff --git a/src/test/ui/rfc-2632-const-trait-impl/auxiliary/cross-crate.rs b/src/test/ui/rfc-2632-const-trait-impl/auxiliary/cross-crate.rs new file mode 100644 index 0000000000000..4285eaf18aaad --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/auxiliary/cross-crate.rs @@ -0,0 +1,22 @@ +#![feature(const_trait_impl)] +#![allow(incomplete_features)] + +pub trait MyTrait { + fn func(self); +} + +pub struct NonConst; + +impl MyTrait for NonConst { + fn func(self) { + + } +} + +pub struct Const; + +impl const MyTrait for Const { + fn func(self) { + + } +} diff --git a/src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-disabled.rs b/src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-disabled.rs new file mode 100644 index 0000000000000..abd11d8b0e923 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-disabled.rs @@ -0,0 +1,18 @@ +// aux-build: cross-crate.rs +extern crate cross_crate; + +use cross_crate::*; + +fn non_const_context() { + NonConst.func(); + Const.func(); +} + +const fn const_context() { + NonConst.func(); + //~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants + Const.func(); + //~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-disabled.stderr b/src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-disabled.stderr new file mode 100644 index 0000000000000..b86583b9e079f --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-disabled.stderr @@ -0,0 +1,15 @@ +error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants + --> $DIR/cross-crate-feature-disabled.rs:12:5 + | +LL | NonConst.func(); + | ^^^^^^^^^^^^^^^ + +error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants + --> $DIR/cross-crate-feature-disabled.rs:14:5 + | +LL | Const.func(); + | ^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0015`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.rs b/src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.rs new file mode 100644 index 0000000000000..b79ccc7712ff2 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.rs @@ -0,0 +1,20 @@ +#![feature(const_trait_impl)] +#![allow(incomplete_features)] + +// aux-build: cross-crate.rs +extern crate cross_crate; + +use cross_crate::*; + +fn non_const_context() { + NonConst.func(); + Const.func(); +} + +const fn const_context() { + NonConst.func(); + //~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants + Const.func(); +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.stderr b/src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.stderr new file mode 100644 index 0000000000000..a544c0dd285fc --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.stderr @@ -0,0 +1,9 @@ +error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants + --> $DIR/cross-crate-feature-enabled.rs:15:5 + | +LL | NonConst.func(); + | ^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0015`. From 0c267830d5afdeea2058f0b97e69cf1afbb3d3da Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Wed, 30 Jun 2021 18:27:07 +0200 Subject: [PATCH 12/14] Match on `hir::TraitFn::Provided` instead of using `maybe_body_owned_by` --- compiler/rustc_typeck/src/check/expr.rs | 62 ++++++++++++------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index de38c41e93ccd..cfe1d1c6871f0 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -683,38 +683,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let encl_item_id = self.tcx.hir().get_parent_item(expr.hir_id); - if self.tcx.hir().maybe_body_owned_by(encl_item_id).is_some() { - if let Some(hir::Node::Item(hir::Item { - kind: hir::ItemKind::Fn(..), - span: encl_fn_span, - .. - })) - | Some(hir::Node::TraitItem(hir::TraitItem { - kind: hir::TraitItemKind::Fn(..), - span: encl_fn_span, - .. - })) - | Some(hir::Node::ImplItem(hir::ImplItem { - kind: hir::ImplItemKind::Fn(..), - span: encl_fn_span, - .. - })) = self.tcx.hir().find(encl_item_id) - { - // We are inside a function body, so reporting "return statement - // outside of function body" needs an explanation. - - let encl_body_owner_id = self.tcx.hir().enclosing_body_owner(expr.hir_id); - - // If this didn't hold, we would not have to report an error in - // the first place. - assert_ne!(encl_item_id, encl_body_owner_id); - - let encl_body_id = self.tcx.hir().body_owned_by(encl_body_owner_id); - let encl_body = self.tcx.hir().body(encl_body_id); - - err.encl_body_span = Some(encl_body.value.span); - err.encl_fn_span = Some(*encl_fn_span); - } + if let Some(hir::Node::Item(hir::Item { + kind: hir::ItemKind::Fn(..), + span: encl_fn_span, + .. + })) + | Some(hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)), + span: encl_fn_span, + .. + })) + | Some(hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::Fn(..), + span: encl_fn_span, + .. + })) = self.tcx.hir().find(encl_item_id) + { + // We are inside a function body, so reporting "return statement + // outside of function body" needs an explanation. + + let encl_body_owner_id = self.tcx.hir().enclosing_body_owner(expr.hir_id); + + // If this didn't hold, we would not have to report an error in + // the first place. + assert_ne!(encl_item_id, encl_body_owner_id); + + let encl_body_id = self.tcx.hir().body_owned_by(encl_body_owner_id); + let encl_body = self.tcx.hir().body(encl_body_id); + + err.encl_body_span = Some(encl_body.value.span); + err.encl_fn_span = Some(*encl_fn_span); } self.tcx.sess.emit_err(err); From 7c9445d4a78909e324c5190759d1a015e7a48990 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Wed, 30 Jun 2021 19:41:49 +0200 Subject: [PATCH 13/14] alloc: `RawVec::shrink` can be in `no_global_oom_handling`. Found in https://github.com/Rust-for-Linux/linux/pull/402. Signed-off-by: Miguel Ojeda --- library/alloc/src/raw_vec.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 2e2c9b76bd4ba..d11d4031f7754 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -463,7 +463,6 @@ impl RawVec { Ok(()) } - #[cfg(not(no_global_oom_handling))] fn shrink(&mut self, amount: usize) -> Result<(), TryReserveError> { assert!(amount <= self.capacity(), "Tried to shrink to a larger capacity"); From 2a60f090b9d39e5600dcbcf83229bbaec2f02176 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sun, 27 Jun 2021 18:15:16 -0500 Subject: [PATCH 14/14] Add suggestion for missing compile flag group --- compiler/rustc_driver/src/lib.rs | 17 +++++++++++++---- .../codegen-option-without-group.rs | 1 + .../codegen-option-without-group.stderr | 2 ++ .../debug-option-without-group.rs | 1 + .../debug-option-without-group.stderr | 2 ++ 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/invalid-compile-flags/codegen-option-without-group.rs create mode 100644 src/test/ui/invalid-compile-flags/codegen-option-without-group.stderr create mode 100644 src/test/ui/invalid-compile-flags/debug-option-without-group.rs create mode 100644 src/test/ui/invalid-compile-flags/debug-option-without-group.stderr diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 35a6495946ff0..2ad2820fac0a8 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -29,7 +29,7 @@ use rustc_middle::middle::cstore::MetadataLoader; use rustc_save_analysis as save; use rustc_save_analysis::DumpHandler; use rustc_serialize::json::{self, ToJson}; -use rustc_session::config::nightly_options; +use rustc_session::config::{nightly_options, CG_OPTIONS, DB_OPTIONS}; use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, TrimmedDefPaths}; use rustc_session::getopts; use rustc_session::lint::{Lint, LintId}; @@ -1017,9 +1017,18 @@ pub fn handle_options(args: &[String]) -> Option { for option in config::rustc_optgroups() { (option.apply)(&mut options); } - let matches = options - .parse(args) - .unwrap_or_else(|f| early_error(ErrorOutputType::default(), &f.to_string())); + let matches = options.parse(args).unwrap_or_else(|e| { + let msg = match e { + getopts::Fail::UnrecognizedOption(ref opt) => CG_OPTIONS + .iter() + .map(|&(name, ..)| ('C', name)) + .chain(DB_OPTIONS.iter().map(|&(name, ..)| ('Z', name))) + .find(|&(_, name)| *opt == name.replace("_", "-")) + .map(|(flag, _)| format!("{}. Did you mean `-{} {}`?", e, flag, opt)), + _ => None, + }; + early_error(ErrorOutputType::default(), &msg.unwrap_or_else(|| e.to_string())); + }); // For all options we just parsed, we check a few aspects: // diff --git a/src/test/ui/invalid-compile-flags/codegen-option-without-group.rs b/src/test/ui/invalid-compile-flags/codegen-option-without-group.rs new file mode 100644 index 0000000000000..7bbf47a383951 --- /dev/null +++ b/src/test/ui/invalid-compile-flags/codegen-option-without-group.rs @@ -0,0 +1 @@ +// compile-flags: --llvm-args diff --git a/src/test/ui/invalid-compile-flags/codegen-option-without-group.stderr b/src/test/ui/invalid-compile-flags/codegen-option-without-group.stderr new file mode 100644 index 0000000000000..c5a0c29cad965 --- /dev/null +++ b/src/test/ui/invalid-compile-flags/codegen-option-without-group.stderr @@ -0,0 +1,2 @@ +error: Unrecognized option: 'llvm-args'. Did you mean `-C llvm-args`? + diff --git a/src/test/ui/invalid-compile-flags/debug-option-without-group.rs b/src/test/ui/invalid-compile-flags/debug-option-without-group.rs new file mode 100644 index 0000000000000..86e40c1785405 --- /dev/null +++ b/src/test/ui/invalid-compile-flags/debug-option-without-group.rs @@ -0,0 +1 @@ +// compile-flags: --unpretty=hir diff --git a/src/test/ui/invalid-compile-flags/debug-option-without-group.stderr b/src/test/ui/invalid-compile-flags/debug-option-without-group.stderr new file mode 100644 index 0000000000000..0e57e31ad3dfa --- /dev/null +++ b/src/test/ui/invalid-compile-flags/debug-option-without-group.stderr @@ -0,0 +1,2 @@ +error: Unrecognized option: 'unpretty'. Did you mean `-Z unpretty`? +