From aaa6de7905b4e5a9d194b8eb6810761861d4280a Mon Sep 17 00:00:00 2001 From: Ophir LOJKINE Date: Fri, 3 Sep 2021 12:14:55 +0200 Subject: [PATCH 01/10] Add a better error message for #39364 There is a known bug in the implementation of mpsc channels in rust. This adds a clearer error message when the bug occurs, so that developers don't lose too much time looking for the origin of the bug. See https://github.com/rust-lang/rust/issues/39364 --- library/std/src/sync/mpsc/shared.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sync/mpsc/shared.rs b/library/std/src/sync/mpsc/shared.rs index 0c32e636a5633..d4ee1b414d9b0 100644 --- a/library/std/src/sync/mpsc/shared.rs +++ b/library/std/src/sync/mpsc/shared.rs @@ -248,7 +248,7 @@ impl Packet { // Returns true if blocking should proceed. fn decrement(&self, token: SignalToken) -> StartResult { unsafe { - assert_eq!(self.to_wake.load(Ordering::SeqCst), 0); + assert_eq!(self.to_wake.load(Ordering::SeqCst), 0, "This is a known bug in rust. See https://github.com/rust-lang/rust/issues/39364"); let ptr = token.cast_to_usize(); self.to_wake.store(ptr, Ordering::SeqCst); From f63096e4f2a08e80eaa4d564946d4fa4d363fc44 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Sun, 5 Sep 2021 22:55:56 +0100 Subject: [PATCH 02/10] rust fmt --- library/std/src/sync/mpsc/shared.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/std/src/sync/mpsc/shared.rs b/library/std/src/sync/mpsc/shared.rs index d4ee1b414d9b0..619a79f437b8a 100644 --- a/library/std/src/sync/mpsc/shared.rs +++ b/library/std/src/sync/mpsc/shared.rs @@ -248,7 +248,11 @@ impl Packet { // Returns true if blocking should proceed. fn decrement(&self, token: SignalToken) -> StartResult { unsafe { - assert_eq!(self.to_wake.load(Ordering::SeqCst), 0, "This is a known bug in rust. See https://github.com/rust-lang/rust/issues/39364"); + assert_eq!( + self.to_wake.load(Ordering::SeqCst), + 0, + "This is a known bug in rust. See https://github.com/rust-lang/rust/issues/39364" + ); let ptr = token.cast_to_usize(); self.to_wake.store(ptr, Ordering::SeqCst); From 250a3e482f125e96b37d66d6d87be7b09436be5c Mon Sep 17 00:00:00 2001 From: Theo Date: Thu, 16 Sep 2021 21:00:11 +0200 Subject: [PATCH 03/10] Resolve issue 85066 Fix : use struct_dummy Fix different os messages --- compiler/rustc_parse/src/parser/expr.rs | 14 ++++++++++++++ .../attributes/extented-attribute-macro-error.rs | 8 ++++++++ .../extented-attribute-macro-error.stderr | 10 ++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/test/ui/attributes/extented-attribute-macro-error.rs create mode 100644 src/test/ui/attributes/extented-attribute-macro-error.stderr diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index dc80dab8c6c5f..9216c2fe2e4a4 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1493,6 +1493,20 @@ impl<'a> Parser<'a> { pub(super) fn parse_lit(&mut self) -> PResult<'a, Lit> { self.parse_opt_lit().ok_or_else(|| { + if let token::Interpolated(inner) = &self.token.kind { + let expr = match inner.as_ref() { + token::NtExpr(expr) => Some(expr), + token::NtLiteral(expr) => Some(expr), + _ => None, + }; + if let Some(expr) = expr { + if matches!(expr.kind, ExprKind::Err) { + self.diagnostic() + .delay_span_bug(self.token.span, &"invalid interpolated expression"); + return self.diagnostic().struct_dummy(); + } + } + } let msg = format!("unexpected token: {}", super::token_descr(&self.token)); self.struct_span_err(self.token.span, &msg) }) diff --git a/src/test/ui/attributes/extented-attribute-macro-error.rs b/src/test/ui/attributes/extented-attribute-macro-error.rs new file mode 100644 index 0000000000000..f5f75f9f4dac5 --- /dev/null +++ b/src/test/ui/attributes/extented-attribute-macro-error.rs @@ -0,0 +1,8 @@ +// normalize-stderr-test: "couldn't read.*" -> "couldn't read the file" + +#![feature(extended_key_value_attributes)] +#![doc = include_str!("../not_existing_file.md")] +struct Documented {} +//~^^ ERROR couldn't read + +fn main() {} diff --git a/src/test/ui/attributes/extented-attribute-macro-error.stderr b/src/test/ui/attributes/extented-attribute-macro-error.stderr new file mode 100644 index 0000000000000..e4deeacd0ff60 --- /dev/null +++ b/src/test/ui/attributes/extented-attribute-macro-error.stderr @@ -0,0 +1,10 @@ +error: couldn't read the file + --> $DIR/extented-attribute-macro-error.rs:4:10 + | +LL | #![doc = include_str!("../not_existing_file.md")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + From da6f01d964ece92bb0812d619f176db5c44e818a Mon Sep 17 00:00:00 2001 From: Hans Kratz Date: Wed, 22 Sep 2021 09:05:39 +0200 Subject: [PATCH 04/10] Run no_core rustdoc tests on Linux only. Windows on Macos ARM64 produce linker errors. --- src/test/rustdoc/cross-crate-primitive-doc.rs | 2 +- src/test/rustdoc/intra-doc/prim-methods-external-core.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/rustdoc/cross-crate-primitive-doc.rs b/src/test/rustdoc/cross-crate-primitive-doc.rs index 120b6e9747f4a..4ba296ee04a1a 100644 --- a/src/test/rustdoc/cross-crate-primitive-doc.rs +++ b/src/test/rustdoc/cross-crate-primitive-doc.rs @@ -1,6 +1,6 @@ // aux-build:primitive-doc.rs // compile-flags: --extern-html-root-url=primitive_doc=../ -Z unstable-options -// ignore-windows +// only-linux #![feature(no_core)] #![no_core] diff --git a/src/test/rustdoc/intra-doc/prim-methods-external-core.rs b/src/test/rustdoc/intra-doc/prim-methods-external-core.rs index 5a92a28556ede..9d869984bbd7c 100644 --- a/src/test/rustdoc/intra-doc/prim-methods-external-core.rs +++ b/src/test/rustdoc/intra-doc/prim-methods-external-core.rs @@ -1,7 +1,7 @@ // aux-build:my-core.rs // build-aux-docs // ignore-cross-compile -// ignore-windows +// only-linux #![deny(broken_intra_doc_links)] #![feature(no_core, lang_items)] From b69bc8447adc21226b044bbd01a67b0295278d4f Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Thu, 23 Sep 2021 00:43:51 +0900 Subject: [PATCH 05/10] change singular to plural --- compiler/rustc_infer/src/infer/error_reporting/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index b8089b2499b66..5f5e1fcc4c949 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -7,7 +7,7 @@ //! inference graph arose so that we can explain to the user what gave //! rise to a particular error. //! -//! The basis of the system are the "origin" types. An "origin" is the +//! The bases of the system are the "origin" types. An "origin" is the //! reason that a constraint or inference variable arose. There are //! different "origin" enums for different kinds of constraints/variables //! (e.g., `TypeOrigin`, `RegionVariableOrigin`). An origin always has From 598e5b27beef291c016c13f4dfaf724350f37fce Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 22 Sep 2021 20:20:33 +0200 Subject: [PATCH 06/10] Update library/std/src/sync/mpsc/shared.rs --- library/std/src/sync/mpsc/shared.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sync/mpsc/shared.rs b/library/std/src/sync/mpsc/shared.rs index 619a79f437b8a..8487a5f8b50d3 100644 --- a/library/std/src/sync/mpsc/shared.rs +++ b/library/std/src/sync/mpsc/shared.rs @@ -251,7 +251,7 @@ impl Packet { assert_eq!( self.to_wake.load(Ordering::SeqCst), 0, - "This is a known bug in rust. See https://github.com/rust-lang/rust/issues/39364" + "This is a known bug in the Rust standard library. See https://github.com/rust-lang/rust/issues/39364" ); let ptr = token.cast_to_usize(); self.to_wake.store(ptr, Ordering::SeqCst); From 3ece63b64e192146fcdd1724e25856a93d7626aa Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 22 Sep 2021 13:56:01 -0700 Subject: [PATCH 07/10] Temporarily rename int_roundings functions to avoid conflicts These functions are unstable, but because they're inherent they still introduce conflicts with stable trait functions in crates. Temporarily rename them to fix these conflicts, until we can resolve those conflicts in a better way. --- library/core/src/num/int_macros.rs | 38 +++++++++++++-------------- library/core/src/num/uint_macros.rs | 14 +++++----- library/core/tests/num/int_macros.rs | 34 ++++++++++++------------ library/core/tests/num/uint_macros.rs | 10 +++---- 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 2a02545041dcf..daef5c98967cc 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -1849,17 +1849,17 @@ macro_rules! int_impl { #[doc = concat!("let a: ", stringify!($SelfT)," = 8;")] /// let b = 3; /// - /// assert_eq!(a.div_floor(b), 2); - /// assert_eq!(a.div_floor(-b), -3); - /// assert_eq!((-a).div_floor(b), -3); - /// assert_eq!((-a).div_floor(-b), 2); + /// assert_eq!(a.unstable_div_floor(b), 2); + /// assert_eq!(a.unstable_div_floor(-b), -3); + /// assert_eq!((-a).unstable_div_floor(b), -3); + /// assert_eq!((-a).unstable_div_floor(-b), 2); /// ``` #[unstable(feature = "int_roundings", issue = "88581")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] #[rustc_inherit_overflow_checks] - pub const fn div_floor(self, rhs: Self) -> Self { + pub const fn unstable_div_floor(self, rhs: Self) -> Self { let d = self / rhs; let r = self % rhs; if (r > 0 && rhs < 0) || (r < 0 && rhs > 0) { @@ -1884,17 +1884,17 @@ macro_rules! int_impl { #[doc = concat!("let a: ", stringify!($SelfT)," = 8;")] /// let b = 3; /// - /// assert_eq!(a.div_ceil(b), 3); - /// assert_eq!(a.div_ceil(-b), -2); - /// assert_eq!((-a).div_ceil(b), -2); - /// assert_eq!((-a).div_ceil(-b), 3); + /// assert_eq!(a.unstable_div_ceil(b), 3); + /// assert_eq!(a.unstable_div_ceil(-b), -2); + /// assert_eq!((-a).unstable_div_ceil(b), -2); + /// assert_eq!((-a).unstable_div_ceil(-b), 3); /// ``` #[unstable(feature = "int_roundings", issue = "88581")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] #[rustc_inherit_overflow_checks] - pub const fn div_ceil(self, rhs: Self) -> Self { + pub const fn unstable_div_ceil(self, rhs: Self) -> Self { let d = self / rhs; let r = self % rhs; if (r > 0 && rhs > 0) || (r < 0 && rhs < 0) { @@ -1919,21 +1919,21 @@ macro_rules! int_impl { /// /// ``` /// #![feature(int_roundings)] - #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".next_multiple_of(8), 16);")] - #[doc = concat!("assert_eq!(23_", stringify!($SelfT), ".next_multiple_of(8), 24);")] - #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".next_multiple_of(-8), 16);")] - #[doc = concat!("assert_eq!(23_", stringify!($SelfT), ".next_multiple_of(-8), 16);")] - #[doc = concat!("assert_eq!((-16_", stringify!($SelfT), ").next_multiple_of(8), -16);")] - #[doc = concat!("assert_eq!((-23_", stringify!($SelfT), ").next_multiple_of(8), -16);")] - #[doc = concat!("assert_eq!((-16_", stringify!($SelfT), ").next_multiple_of(-8), -16);")] - #[doc = concat!("assert_eq!((-23_", stringify!($SelfT), ").next_multiple_of(-8), -24);")] + #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".unstable_next_multiple_of(8), 16);")] + #[doc = concat!("assert_eq!(23_", stringify!($SelfT), ".unstable_next_multiple_of(8), 24);")] + #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".unstable_next_multiple_of(-8), 16);")] + #[doc = concat!("assert_eq!(23_", stringify!($SelfT), ".unstable_next_multiple_of(-8), 16);")] + #[doc = concat!("assert_eq!((-16_", stringify!($SelfT), ").unstable_next_multiple_of(8), -16);")] + #[doc = concat!("assert_eq!((-23_", stringify!($SelfT), ").unstable_next_multiple_of(8), -16);")] + #[doc = concat!("assert_eq!((-16_", stringify!($SelfT), ").unstable_next_multiple_of(-8), -16);")] + #[doc = concat!("assert_eq!((-23_", stringify!($SelfT), ").unstable_next_multiple_of(-8), -24);")] /// ``` #[unstable(feature = "int_roundings", issue = "88581")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] #[rustc_inherit_overflow_checks] - pub const fn next_multiple_of(self, rhs: Self) -> Self { + pub const fn unstable_next_multiple_of(self, rhs: Self) -> Self { // This would otherwise fail when calculating `r` when self == T::MIN. if rhs == -1 { return self; diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 7523d8ec976dd..8ce8266263091 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1859,12 +1859,12 @@ macro_rules! uint_impl { /// /// ``` /// #![feature(int_roundings)] - #[doc = concat!("assert_eq!(7_", stringify!($SelfT), ".div_floor(4), 1);")] + #[doc = concat!("assert_eq!(7_", stringify!($SelfT), ".unstable_div_floor(4), 1);")] /// ``` #[unstable(feature = "int_roundings", issue = "88581")] #[inline(always)] #[rustc_inherit_overflow_checks] - pub const fn div_floor(self, rhs: Self) -> Self { + pub const fn unstable_div_floor(self, rhs: Self) -> Self { self / rhs } @@ -1880,12 +1880,12 @@ macro_rules! uint_impl { /// /// ``` /// #![feature(int_roundings)] - #[doc = concat!("assert_eq!(7_", stringify!($SelfT), ".div_ceil(4), 2);")] + #[doc = concat!("assert_eq!(7_", stringify!($SelfT), ".unstable_div_ceil(4), 2);")] /// ``` #[unstable(feature = "int_roundings", issue = "88581")] #[inline] #[rustc_inherit_overflow_checks] - pub const fn div_ceil(self, rhs: Self) -> Self { + pub const fn unstable_div_ceil(self, rhs: Self) -> Self { let d = self / rhs; let r = self % rhs; if r > 0 && rhs > 0 { @@ -1908,15 +1908,15 @@ macro_rules! uint_impl { /// /// ``` /// #![feature(int_roundings)] - #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".next_multiple_of(8), 16);")] - #[doc = concat!("assert_eq!(23_", stringify!($SelfT), ".next_multiple_of(8), 24);")] + #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".unstable_next_multiple_of(8), 16);")] + #[doc = concat!("assert_eq!(23_", stringify!($SelfT), ".unstable_next_multiple_of(8), 24);")] /// ``` #[unstable(feature = "int_roundings", issue = "88581")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] #[rustc_inherit_overflow_checks] - pub const fn next_multiple_of(self, rhs: Self) -> Self { + pub const fn unstable_next_multiple_of(self, rhs: Self) -> Self { match self % rhs { 0 => self, r => self + (rhs - r) diff --git a/library/core/tests/num/int_macros.rs b/library/core/tests/num/int_macros.rs index d2d655ea2c750..0ad85bf6d943d 100644 --- a/library/core/tests/num/int_macros.rs +++ b/library/core/tests/num/int_macros.rs @@ -294,33 +294,33 @@ macro_rules! int_module { fn test_div_floor() { let a: $T = 8; let b = 3; - assert_eq!(a.div_floor(b), 2); - assert_eq!(a.div_floor(-b), -3); - assert_eq!((-a).div_floor(b), -3); - assert_eq!((-a).div_floor(-b), 2); + assert_eq!(a.unstable_div_floor(b), 2); + assert_eq!(a.unstable_div_floor(-b), -3); + assert_eq!((-a).unstable_div_floor(b), -3); + assert_eq!((-a).unstable_div_floor(-b), 2); } #[test] fn test_div_ceil() { let a: $T = 8; let b = 3; - assert_eq!(a.div_ceil(b), 3); - assert_eq!(a.div_ceil(-b), -2); - assert_eq!((-a).div_ceil(b), -2); - assert_eq!((-a).div_ceil(-b), 3); + assert_eq!(a.unstable_div_ceil(b), 3); + assert_eq!(a.unstable_div_ceil(-b), -2); + assert_eq!((-a).unstable_div_ceil(b), -2); + assert_eq!((-a).unstable_div_ceil(-b), 3); } #[test] fn test_next_multiple_of() { - assert_eq!((16 as $T).next_multiple_of(8), 16); - assert_eq!((23 as $T).next_multiple_of(8), 24); - assert_eq!((16 as $T).next_multiple_of(-8), 16); - assert_eq!((23 as $T).next_multiple_of(-8), 16); - assert_eq!((-16 as $T).next_multiple_of(8), -16); - assert_eq!((-23 as $T).next_multiple_of(8), -16); - assert_eq!((-16 as $T).next_multiple_of(-8), -16); - assert_eq!((-23 as $T).next_multiple_of(-8), -24); - assert_eq!(MIN.next_multiple_of(-1), MIN); + assert_eq!((16 as $T).unstable_next_multiple_of(8), 16); + assert_eq!((23 as $T).unstable_next_multiple_of(8), 24); + assert_eq!((16 as $T).unstable_next_multiple_of(-8), 16); + assert_eq!((23 as $T).unstable_next_multiple_of(-8), 16); + assert_eq!((-16 as $T).unstable_next_multiple_of(8), -16); + assert_eq!((-23 as $T).unstable_next_multiple_of(8), -16); + assert_eq!((-16 as $T).unstable_next_multiple_of(-8), -16); + assert_eq!((-23 as $T).unstable_next_multiple_of(-8), -24); + assert_eq!(MIN.unstable_next_multiple_of(-1), MIN); } #[test] diff --git a/library/core/tests/num/uint_macros.rs b/library/core/tests/num/uint_macros.rs index 49f8f1f13fad4..35ec88c6af7d6 100644 --- a/library/core/tests/num/uint_macros.rs +++ b/library/core/tests/num/uint_macros.rs @@ -208,19 +208,19 @@ macro_rules! uint_module { #[test] fn test_div_floor() { - assert_eq!((8 as $T).div_floor(3), 2); + assert_eq!((8 as $T).unstable_div_floor(3), 2); } #[test] fn test_div_ceil() { - assert_eq!((8 as $T).div_ceil(3), 3); + assert_eq!((8 as $T).unstable_div_ceil(3), 3); } #[test] fn test_next_multiple_of() { - assert_eq!((16 as $T).next_multiple_of(8), 16); - assert_eq!((23 as $T).next_multiple_of(8), 24); - assert_eq!(MAX.next_multiple_of(1), MAX); + assert_eq!((16 as $T).unstable_next_multiple_of(8), 16); + assert_eq!((23 as $T).unstable_next_multiple_of(8), 24); + assert_eq!(MAX.unstable_next_multiple_of(1), MAX); } #[test] From c713ffbe39e2e3213a218491d139638344fce68d Mon Sep 17 00:00:00 2001 From: Hirochika Matsumoto Date: Thu, 23 Sep 2021 18:57:23 +0900 Subject: [PATCH 08/10] Fix typo --- compiler/rustc_middle/src/query/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index c13d7720e3754..b4f7a9fa8e9d6 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -599,7 +599,7 @@ rustc_queries! { desc { "computing the inferred outlives predicates for items in this crate" } } - /// Maps from an impl/trait `DefId to a list of the `DefId`s of its items. + /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items. query associated_item_def_ids(key: DefId) -> &'tcx [DefId] { desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) } } From d997a62a3f4bf49015a1c38efeb86baf758382f8 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda <41065217+TaKO8Ki@users.noreply.github.com> Date: Thu, 23 Sep 2021 20:27:20 +0900 Subject: [PATCH 09/10] Update compiler/rustc_infer/src/infer/error_reporting/mod.rs Co-authored-by: mbartlett21 <29034492+mbartlett21@users.noreply.github.com> --- compiler/rustc_infer/src/infer/error_reporting/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 5f5e1fcc4c949..d9b7022f03ac1 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -7,7 +7,7 @@ //! inference graph arose so that we can explain to the user what gave //! rise to a particular error. //! -//! The bases of the system are the "origin" types. An "origin" is the +//! The system is based around a set of "origin" types. An "origin" is the //! reason that a constraint or inference variable arose. There are //! different "origin" enums for different kinds of constraints/variables //! (e.g., `TypeOrigin`, `RegionVariableOrigin`). An origin always has From affea730e9693623d7c0f6bad35b3fab36df02e4 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Tue, 21 Sep 2021 13:18:26 +0000 Subject: [PATCH 10/10] Suggest `_` in turbofish if param will be inferred from fn argument --- .../wrong_number_of_generic_args.rs | 21 ++++++++++++++++++- .../missing-type-param-used-in-param.fixed | 8 +++++++ .../missing-type-param-used-in-param.rs | 8 +++++++ .../missing-type-param-used-in-param.stderr | 21 +++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/suggestions/missing-type-param-used-in-param.fixed create mode 100644 src/test/ui/suggestions/missing-type-param-used-in-param.rs create mode 100644 src/test/ui/suggestions/missing-type-param-used-in-param.stderr diff --git a/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs index 7e69ad21d0343..2e3db4d6d655f 100644 --- a/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs @@ -1,6 +1,7 @@ use crate::structured_errors::StructuredDiagnostic; use rustc_errors::{pluralize, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc_hir as hir; +use rustc_middle::hir::map::fn_sig; use rustc_middle::middle::resolve_lifetime::LifetimeScopeForPath; use rustc_middle::ty::{self as ty, TyCtxt}; use rustc_session::Session; @@ -292,12 +293,30 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { &self, num_params_to_take: usize, ) -> String { + let fn_sig = self.tcx.hir().get_if_local(self.def_id).and_then(|node| fn_sig(node)); + let is_used_in_input = |def_id| { + fn_sig.map_or(false, |fn_sig| { + fn_sig.decl.inputs.iter().any(|ty| match ty.kind { + hir::TyKind::Path(hir::QPath::Resolved( + None, + hir::Path { res: hir::def::Res::Def(_, id), .. }, + )) if *id == def_id => true, + _ => false, + }) + }) + }; self.gen_params .params .iter() .skip(self.params_offset + self.num_provided_type_or_const_args()) .take(num_params_to_take) - .map(|param| param.name.to_string()) + .map(|param| match param.kind { + // This is being infered from the item's inputs, no need to set it. + ty::GenericParamDefKind::Type { .. } if is_used_in_input(param.def_id) => { + "_".to_string() + } + _ => param.name.to_string(), + }) .collect::>() .join(", ") } diff --git a/src/test/ui/suggestions/missing-type-param-used-in-param.fixed b/src/test/ui/suggestions/missing-type-param-used-in-param.fixed new file mode 100644 index 0000000000000..cc4120041b986 --- /dev/null +++ b/src/test/ui/suggestions/missing-type-param-used-in-param.fixed @@ -0,0 +1,8 @@ +// run-rustfix + +fn two_type_params(_: B) {} + +fn main() { + two_type_params::(100); //~ ERROR this function takes 2 generic arguments + two_type_params::(100); +} diff --git a/src/test/ui/suggestions/missing-type-param-used-in-param.rs b/src/test/ui/suggestions/missing-type-param-used-in-param.rs new file mode 100644 index 0000000000000..19286331b6023 --- /dev/null +++ b/src/test/ui/suggestions/missing-type-param-used-in-param.rs @@ -0,0 +1,8 @@ +// run-rustfix + +fn two_type_params(_: B) {} + +fn main() { + two_type_params::(100); //~ ERROR this function takes 2 generic arguments + two_type_params::(100); +} diff --git a/src/test/ui/suggestions/missing-type-param-used-in-param.stderr b/src/test/ui/suggestions/missing-type-param-used-in-param.stderr new file mode 100644 index 0000000000000..4f7058a649259 --- /dev/null +++ b/src/test/ui/suggestions/missing-type-param-used-in-param.stderr @@ -0,0 +1,21 @@ +error[E0107]: this function takes 2 generic arguments but 1 generic argument was supplied + --> $DIR/missing-type-param-used-in-param.rs:6:5 + | +LL | two_type_params::(100); + | ^^^^^^^^^^^^^^^ ------ supplied 1 generic argument + | | + | expected 2 generic arguments + | +note: function defined here, with 2 generic parameters: `A`, `B` + --> $DIR/missing-type-param-used-in-param.rs:3:4 + | +LL | fn two_type_params(_: B) {} + | ^^^^^^^^^^^^^^^ - - +help: add missing generic argument + | +LL | two_type_params::(100); + | +++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0107`.