From 43330916251221764c28e6bc650f01be8713b79b Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 16 Oct 2021 02:49:58 +0900 Subject: [PATCH 01/16] Update E0637 description to mention `&` w/o an explicit lifetime name --- .../src/error_codes/E0637.md | 36 +++++++++++++------ src/test/ui/error-codes/E0637.rs | 18 +++++++--- src/test/ui/error-codes/E0637.stderr | 31 +++++++++------- 3 files changed, 58 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0637.md b/compiler/rustc_error_codes/src/error_codes/E0637.md index d9068950bdfee..62d5565df2798 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0637.md +++ b/compiler/rustc_error_codes/src/error_codes/E0637.md @@ -1,35 +1,51 @@ -An underscore `_` character has been used as the identifier for a lifetime. +`'_` lifetime name or `&T` without an explicit lifetime name has been used +on illegal place. Erroneous code example: ```compile_fail,E0106,E0637 -fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { - //^^ `'_` is a reserved lifetime name +fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { + //^^ `'_` is a reserved lifetime name if str1.len() > str2.len() { str1 } else { str2 } } + +fn and_without_explicit_lifetime() +where + T: Into<&u32>, + //^ `&` without an explicit lifetime name +{ +} ``` -`'_`, cannot be used as a lifetime identifier because it is a reserved for the -anonymous lifetime. To fix this, use a lowercase letter such as 'a, or a series -of lowercase letters such as `'foo`. For more information, see [the -book][bk-no]. For more information on using the anonymous lifetime in rust -nightly, see [the nightly book][bk-al]. +First, `'_` cannot be used as a lifetime identifier in some places +because it is a reserved for the anonymous lifetime. Second, `&T` +without an explicit lifetime name cannot also be used in some places. +To fix them, use a lowercase letter such as `'a`, or a series +of lowercase letters such as `'foo`. For more information about lifetime +identifier, see [the book][bk-no]. For more information on using +the anonymous lifetime in Rust 2018, see [the Rust 2018 blog post][blog-al]. Corrected example: ``` -fn longest<'a>(str1: &'a str, str2: &'a str) -> &'a str { +fn underscore_lifetime<'a>(str1: &'a str, str2: &'a str) -> &'a str { if str1.len() > str2.len() { str1 } else { str2 } } + +fn and_without_explicit_lifetime<'foo, T>() +where + T: Into<&'foo u32>, +{ +} ``` [bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols -[bk-al]: https://doc.rust-lang.org/nightly/edition-guide/rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.html +[blog-al]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#more-lifetime-elision-rules diff --git a/src/test/ui/error-codes/E0637.rs b/src/test/ui/error-codes/E0637.rs index b4888d4af6a21..382ce3ed01f34 100644 --- a/src/test/ui/error-codes/E0637.rs +++ b/src/test/ui/error-codes/E0637.rs @@ -1,9 +1,17 @@ -struct Foo<'a: '_>(&'a u8); //~ ERROR cannot be used here -fn foo<'a: '_>(_: &'a u8) {} //~ ERROR cannot be used here +fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { + //~^ ERROR: `'_` cannot be used here [E0637] + //~| ERROR: missing lifetime specifier + if str1.len() > str2.len() { + str1 + } else { + str2 + } +} -struct Bar<'a>(&'a u8); -impl<'a: '_> Bar<'a> { //~ ERROR cannot be used here - fn bar() {} +fn and_without_explicit_lifetime() +where + T: Into<&u32>, //~ ERROR: `&` without an explicit lifetime name cannot be used here [E0637] +{ } fn main() {} diff --git a/src/test/ui/error-codes/E0637.stderr b/src/test/ui/error-codes/E0637.stderr index d19ebfd15a52c..87aaba65a73ad 100644 --- a/src/test/ui/error-codes/E0637.stderr +++ b/src/test/ui/error-codes/E0637.stderr @@ -1,21 +1,28 @@ error[E0637]: `'_` cannot be used here - --> $DIR/E0637.rs:1:16 + --> $DIR/E0637.rs:1:24 | -LL | struct Foo<'a: '_>(&'a u8); - | ^^ `'_` is a reserved lifetime name +LL | fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { + | ^^ `'_` is a reserved lifetime name -error[E0637]: `'_` cannot be used here - --> $DIR/E0637.rs:2:12 +error[E0637]: `&` without an explicit lifetime name cannot be used here + --> $DIR/E0637.rs:13:13 | -LL | fn foo<'a: '_>(_: &'a u8) {} - | ^^ `'_` is a reserved lifetime name +LL | T: Into<&u32>, + | ^ explicit lifetime name needed here -error[E0637]: `'_` cannot be used here - --> $DIR/E0637.rs:5:10 +error[E0106]: missing lifetime specifier + --> $DIR/E0637.rs:1:62 + | +LL | fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { + | ------- ------- ^^ expected named lifetime parameter + | + = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `str1` or `str2` +help: consider introducing a named lifetime parameter | -LL | impl<'a: '_> Bar<'a> { - | ^^ `'_` is a reserved lifetime name +LL | fn underscore_lifetime<'a, '_>(str1: &'a str, str2: &'a str) -> &'a str { + | +++ ~~ ~~ ~~ error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0637`. +Some errors have detailed explanations: E0106, E0637. +For more information about an error, try `rustc --explain E0106`. From d2470e74e133de90c227e6d22dfd3391277333b3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 18 Oct 2021 00:06:40 +0300 Subject: [PATCH 02/16] rustc_ast: Turn `MutVisitor::token_visiting_enabled` into a constant It's a visitor property rather than something that needs to be determined at runtime --- compiler/rustc_ast/src/mut_visit.rs | 12 +++++------- compiler/rustc_expand/src/mbe/transcribe.rs | 4 +--- compiler/rustc_expand/src/mut_visit/tests.rs | 5 ++--- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index ba86036577ac5..df88cf35db242 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -37,9 +37,7 @@ pub trait MutVisitor: Sized { /// Mutable token visiting only exists for the `macro_rules` token marker and should not be /// used otherwise. Token visitor would be entirely separate from the regular visitor if /// the marker didn't have to visit AST fragments in nonterminal tokens. - fn token_visiting_enabled(&self) -> bool { - false - } + const VISIT_TOKENS: bool = false; // Methods in this trait have one of three forms: // @@ -363,7 +361,7 @@ pub fn visit_mac_args(args: &mut MacArgs, vis: &mut T) { } MacArgs::Eq(eq_span, token) => { vis.visit_span(eq_span); - if vis.token_visiting_enabled() { + if T::VISIT_TOKENS { visit_token(token, vis); } else { // The value in `#[key = VALUE]` must be visited as an expression for backward @@ -682,7 +680,7 @@ pub fn visit_tt(tt: &mut TokenTree, vis: &mut T) { // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. pub fn visit_tts(TokenStream(tts): &mut TokenStream, vis: &mut T) { - if vis.token_visiting_enabled() && !tts.is_empty() { + if T::VISIT_TOKENS && !tts.is_empty() { let tts = Lrc::make_mut(tts); visit_vec(tts, |(tree, _is_joint)| visit_tt(tree, vis)); } @@ -692,14 +690,14 @@ pub fn visit_attr_annotated_tts( AttrAnnotatedTokenStream(tts): &mut AttrAnnotatedTokenStream, vis: &mut T, ) { - if vis.token_visiting_enabled() && !tts.is_empty() { + if T::VISIT_TOKENS && !tts.is_empty() { let tts = Lrc::make_mut(tts); visit_vec(tts, |(tree, _is_joint)| visit_attr_annotated_tt(tree, vis)); } } pub fn visit_lazy_tts_opt_mut(lazy_tts: Option<&mut LazyTokenStream>, vis: &mut T) { - if vis.token_visiting_enabled() { + if T::VISIT_TOKENS { if let Some(lazy_tts) = lazy_tts { let mut tts = lazy_tts.create_token_stream(); visit_attr_annotated_tts(&mut tts, vis); diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 9ed5c8b8ffba5..6bf7a2a1b798b 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -19,9 +19,7 @@ use std::mem; struct Marker(LocalExpnId, Transparency); impl MutVisitor for Marker { - fn token_visiting_enabled(&self) -> bool { - true - } + const VISIT_TOKENS: bool = true; fn visit_span(&mut self, span: &mut Span) { *span = span.apply_mark(self.0.to_expn_id(), self.1) diff --git a/compiler/rustc_expand/src/mut_visit/tests.rs b/compiler/rustc_expand/src/mut_visit/tests.rs index 0068539fb3bd4..8974d45b4d8cf 100644 --- a/compiler/rustc_expand/src/mut_visit/tests.rs +++ b/compiler/rustc_expand/src/mut_visit/tests.rs @@ -15,9 +15,8 @@ fn print_crate_items(krate: &ast::Crate) -> String { struct ToZzIdentMutVisitor; impl MutVisitor for ToZzIdentMutVisitor { - fn token_visiting_enabled(&self) -> bool { - true - } + const VISIT_TOKENS: bool = true; + fn visit_ident(&mut self, ident: &mut Ident) { *ident = Ident::from_str("zz"); } From 7581bae99615f0b7b3dd973a59448659d2946656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Tue, 19 Oct 2021 00:00:00 +0000 Subject: [PATCH 03/16] Fix const qualification when executed after promotion The const qualification was so far performed before the promotion and the implementation assumed that it will never encounter a promoted. With `const_precise_live_drops` feature, checking for live drops is delayed until after drop elaboration, which in turn runs after promotion. so the assumption is no longer true. When evaluating `NeedsNonConstDrop` it is now possible to encounter promoteds. Use type base qualification for the promoted. It is a sound approximation in general, and in the specific case of promoteds and `NeedsNonConstDrop` it is precise. --- .../src/transform/check_consts/qualifs.rs | 5 +++-- src/test/ui/consts/precise-drop-with-promoted.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/consts/precise-drop-with-promoted.rs diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index 5418f6fc007ca..0a57d9adc46a9 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -309,8 +309,9 @@ where // Check the qualifs of the value of `const` items. if let Some(ct) = constant.literal.const_for_ty() { - if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted }) = ct.val { - assert!(promoted.is_none()); + if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted: None }) = + ct.val + { // Don't peek inside trait associated constants. if cx.tcx.trait_of_item(def.did).is_none() { let qualifs = if let Some((did, param_did)) = def.as_const_arg() { diff --git a/src/test/ui/consts/precise-drop-with-promoted.rs b/src/test/ui/consts/precise-drop-with-promoted.rs new file mode 100644 index 0000000000000..6f2317a5a27a8 --- /dev/null +++ b/src/test/ui/consts/precise-drop-with-promoted.rs @@ -0,0 +1,9 @@ +// Regression test for issue #89938. +// check-pass +// compile-flags: --crate-type=lib +#![feature(const_precise_live_drops)] + +pub const fn f() { + let _: Option = None; + let _: &'static Option = &None; +} From 21d02bf132e58a1ea04f0804140faed329494f26 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 20 Oct 2021 11:09:06 +0900 Subject: [PATCH 04/16] Add a regression test for issue-83479 --- src/test/ui/query-system/issue-83479.rs | 16 ++++++++ src/test/ui/query-system/issue-83479.stderr | 44 +++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/test/ui/query-system/issue-83479.rs create mode 100644 src/test/ui/query-system/issue-83479.stderr diff --git a/src/test/ui/query-system/issue-83479.rs b/src/test/ui/query-system/issue-83479.rs new file mode 100644 index 0000000000000..32676dfe9c8fa --- /dev/null +++ b/src/test/ui/query-system/issue-83479.rs @@ -0,0 +1,16 @@ +#![feature(type_alias_impl_trait)] + +type PairCoupledTypes: Trait< + //~^ ERROR: bounds on `type`s in this context have no effect + //~| ERROR: cannot find trait `Trait` in this scope + [u32; { + static FOO: usize; //~ ERROR: free static item without body + }], +> = impl Trait< + //~^ ERROR: cannot find trait `Trait` in this scope + [u32; { + static FOO: usize; //~ ERROR: free static item without body + }], +>; + +fn main() {} diff --git a/src/test/ui/query-system/issue-83479.stderr b/src/test/ui/query-system/issue-83479.stderr new file mode 100644 index 0000000000000..7cb41f5cbe51c --- /dev/null +++ b/src/test/ui/query-system/issue-83479.stderr @@ -0,0 +1,44 @@ +error: bounds on `type`s in this context have no effect + --> $DIR/issue-83479.rs:3:24 + | +LL | type PairCoupledTypes: Trait< + | ________________________^ +LL | | +LL | | +LL | | [u32; { +LL | | static FOO: usize; +LL | | }], +LL | | > = impl Trait< + | |_^ + +error: free static item without body + --> $DIR/issue-83479.rs:7:9 + | +LL | static FOO: usize; + | ^^^^^^^^^^^^^^^^^- + | | + | help: provide a definition for the static: `= ;` + +error: free static item without body + --> $DIR/issue-83479.rs:12:9 + | +LL | static FOO: usize; + | ^^^^^^^^^^^^^^^^^- + | | + | help: provide a definition for the static: `= ;` + +error[E0405]: cannot find trait `Trait` in this scope + --> $DIR/issue-83479.rs:3:24 + | +LL | type PairCoupledTypes: Trait< + | ^^^^^ not found in this scope + +error[E0405]: cannot find trait `Trait` in this scope + --> $DIR/issue-83479.rs:9:10 + | +LL | > = impl Trait< + | ^^^^^ not found in this scope + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0405`. From 396a4f49843cd91d38c47376e7a5324fc4115ca3 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 20 Oct 2021 11:28:11 +0900 Subject: [PATCH 05/16] Increase `ROOT_ENTRY_LIMIT` to 1331 --- src/tools/tidy/src/ui_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index a341527c84cf0..4afa36502aca1 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -7,7 +7,7 @@ use std::path::Path; const ENTRY_LIMIT: usize = 1000; // FIXME: The following limits should be reduced eventually. -const ROOT_ENTRY_LIMIT: usize = 1330; +const ROOT_ENTRY_LIMIT: usize = 1331; const ISSUES_ENTRY_LIMIT: usize = 2488; fn check_entries(path: &Path, bad: &mut bool) { From 6469fba44ed6873e85cc916cf1aa51d4d1b2cb46 Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 20 Oct 2021 22:56:42 +0100 Subject: [PATCH 06/16] Trait objects --- .../const-generics/defaults/trait_objects.rs | 45 +++++++++++++++++++ .../defaults/trait_objects_fail.rs | 32 +++++++++++++ .../defaults/trait_objects_fail.stderr | 27 +++++++++++ 3 files changed, 104 insertions(+) create mode 100644 src/test/ui/const-generics/defaults/trait_objects.rs create mode 100644 src/test/ui/const-generics/defaults/trait_objects_fail.rs create mode 100644 src/test/ui/const-generics/defaults/trait_objects_fail.stderr diff --git a/src/test/ui/const-generics/defaults/trait_objects.rs b/src/test/ui/const-generics/defaults/trait_objects.rs new file mode 100644 index 0000000000000..9ba928c43c509 --- /dev/null +++ b/src/test/ui/const-generics/defaults/trait_objects.rs @@ -0,0 +1,45 @@ +// run-pass +#![feature(const_generics_defaults)] + +trait Trait { + fn uwu(&self) -> u8 { + N + } +} + +impl Trait for u32 {} + +impl Trait<12> for u64 { + fn uwu(&self) -> u8 { + *self as u8 + } +} + +fn foo(arg: &dyn Trait) -> u8 { + arg.uwu() +} + +trait Traitor { + fn owo(&self) -> u8 { + M + } +} + +impl Traitor<2> for bool { } +impl Traitor for u8 { + fn owo(&self) -> u8 { + *self + } +} + +fn bar(arg: &dyn Traitor) -> u8 { + arg.owo() +} + +fn main() { + assert_eq!(foo(&10_u32), 12); + assert_eq!(foo(&3_u64), 3); + + assert_eq!(bar(&true), 2); + assert_eq!(bar(&1_u8), 1); +} diff --git a/src/test/ui/const-generics/defaults/trait_objects_fail.rs b/src/test/ui/const-generics/defaults/trait_objects_fail.rs new file mode 100644 index 0000000000000..09e4265a7a0ef --- /dev/null +++ b/src/test/ui/const-generics/defaults/trait_objects_fail.rs @@ -0,0 +1,32 @@ +#![feature(const_generics_defaults)] + +trait Trait { + fn uwu(&self) -> u8 { + N + } +} + +impl Trait<2> for u32 {} + +fn foo(arg: &dyn Trait) -> u8 { + arg.uwu() +} + +trait Traitor { + fn owo(&self) -> u8 { + M + } +} + +impl Traitor<2, 3> for bool { } + +fn bar(arg: &dyn Traitor) -> u8 { + arg.owo() +} + +fn main() { + foo(&10_u32); + //~^ error: the trait bound `u32: Trait` is not satisfied + bar(&true); + //~^ error: the trait bound `bool: Traitor<{_: u8}, {_: u8}>` is not satisfied +} diff --git a/src/test/ui/const-generics/defaults/trait_objects_fail.stderr b/src/test/ui/const-generics/defaults/trait_objects_fail.stderr new file mode 100644 index 0000000000000..b097c8cd4bae1 --- /dev/null +++ b/src/test/ui/const-generics/defaults/trait_objects_fail.stderr @@ -0,0 +1,27 @@ +error[E0277]: the trait bound `u32: Trait` is not satisfied + --> $DIR/trait_objects_fail.rs:28:9 + | +LL | foo(&10_u32); + | --- ^^^^^^^ the trait `Trait` is not implemented for `u32` + | | + | required by a bound introduced by this call + | + = help: the following implementations were found: + > + = note: required for the cast to the object type `dyn Trait` + +error[E0277]: the trait bound `bool: Traitor<{_: u8}, {_: u8}>` is not satisfied + --> $DIR/trait_objects_fail.rs:30:9 + | +LL | bar(&true); + | --- ^^^^^ the trait `Traitor<{_: u8}, {_: u8}>` is not implemented for `bool` + | | + | required by a bound introduced by this call + | + = help: the following implementations were found: + > + = note: required for the cast to the object type `dyn Traitor<{_: u8}, {_: u8}>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. From a81e4891017efed225318493f490f53e5c5111e7 Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 20 Oct 2021 23:18:26 +0100 Subject: [PATCH 07/16] Return pos impl trait --- .../const-generics/defaults/rp_impl_trait.rs | 31 +++++++++++++++++ .../defaults/rp_impl_trait_fail.rs | 33 +++++++++++++++++++ .../defaults/rp_impl_trait_fail.stderr | 30 +++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 src/test/ui/const-generics/defaults/rp_impl_trait.rs create mode 100644 src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs create mode 100644 src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr diff --git a/src/test/ui/const-generics/defaults/rp_impl_trait.rs b/src/test/ui/const-generics/defaults/rp_impl_trait.rs new file mode 100644 index 0000000000000..1447ebe5348f6 --- /dev/null +++ b/src/test/ui/const-generics/defaults/rp_impl_trait.rs @@ -0,0 +1,31 @@ +// run-pass +#![feature(const_generics_defaults)] + +struct Uwu; + +trait Trait {} +impl Trait for Uwu {} + +fn rawr() -> impl Trait { + Uwu:: +} + +trait Traitor { } + +impl Traitor for u32 {} +impl Traitor<1, 1> for u64 {} + +fn uwu() -> impl Traitor { + 1_u32 +} + +fn owo() -> impl Traitor { + 1_u64 +} + +fn main() { + rawr::<3>(); + rawr::<7>(); + uwu::<{ u8::MAX }>(); + owo(); +} diff --git a/src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs b/src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs new file mode 100644 index 0000000000000..c989fc8338b90 --- /dev/null +++ b/src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs @@ -0,0 +1,33 @@ +#![feature(const_generics_defaults)] + +struct Uwu; + +trait Trait {} +impl Trait for Uwu {} + +fn rawr() -> impl Trait { + //~^ error: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied + Uwu::<10, 12> +} + +trait Traitor { } + +impl Traitor for u32 {} +impl Traitor<1, 2> for u64 {} + + +fn uwu() -> impl Traitor { + //~^ error: the trait bound `u32: Traitor` is not satisfied + 1_u32 +} + +fn owo() -> impl Traitor { + //~^ error: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied + 1_u64 +} + +fn main() { + rawr(); + uwu(); + owo(); +} diff --git a/src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr b/src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr new file mode 100644 index 0000000000000..cf28932177a7a --- /dev/null +++ b/src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr @@ -0,0 +1,30 @@ +error[E0277]: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied + --> $DIR/rp_impl_trait_fail.rs:8:14 + | +LL | fn rawr() -> impl Trait { + | ^^^^^^^^^^ the trait `Trait` is not implemented for `Uwu<10_u32, 12_u32>` + | + = help: the following implementations were found: + as Trait> + +error[E0277]: the trait bound `u32: Traitor` is not satisfied + --> $DIR/rp_impl_trait_fail.rs:19:26 + | +LL | fn uwu() -> impl Traitor { + | ^^^^^^^^^^^^^^^ the trait `Traitor` is not implemented for `u32` + | + = help: the following implementations were found: + > + +error[E0277]: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied + --> $DIR/rp_impl_trait_fail.rs:24:13 + | +LL | fn owo() -> impl Traitor { + | ^^^^^^^^^^^^ the trait `Traitor<1_u8, 1_u8>` is not implemented for `u64` + | + = help: the following implementations were found: + > + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. From 83a1834c14cbdd526f48f496d19a430b9f53ae38 Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 20 Oct 2021 23:31:08 +0100 Subject: [PATCH 08/16] Wfness --- src/test/ui/const-generics/defaults/wfness.rs | 21 ++++++++++ .../ui/const-generics/defaults/wfness.stderr | 38 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/test/ui/const-generics/defaults/wfness.rs create mode 100644 src/test/ui/const-generics/defaults/wfness.stderr diff --git a/src/test/ui/const-generics/defaults/wfness.rs b/src/test/ui/const-generics/defaults/wfness.rs new file mode 100644 index 0000000000000..d2b53eaf9299a --- /dev/null +++ b/src/test/ui/const-generics/defaults/wfness.rs @@ -0,0 +1,21 @@ +#![feature(const_generics_defaults)] + +struct Ooopsies; +//~^ error: evaluation of constant value failed + +trait Trait {} +impl Trait<3> for () {} +struct WhereClause where (): Trait; +//~^ error: the trait bound `(): Trait<2_u8>` is not satisfied + +trait Traitor {} +struct WhereClauseTooGeneric(T) where (): Traitor; + +// no error on struct def +struct DependentDefaultWfness>(T); +fn foo() -> DependentDefaultWfness { + //~^ error: the trait bound `(): Trait<1_u8>` is not satisfied + loop {} +} + +fn main() {} diff --git a/src/test/ui/const-generics/defaults/wfness.stderr b/src/test/ui/const-generics/defaults/wfness.stderr new file mode 100644 index 0000000000000..9826af8802a27 --- /dev/null +++ b/src/test/ui/const-generics/defaults/wfness.stderr @@ -0,0 +1,38 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/wfness.rs:3:33 + | +LL | struct Ooopsies; + | ^^^^^^^^^^^ attempt to compute `u8::MAX + 1_u8`, which would overflow + +error[E0277]: the trait bound `(): Trait<2_u8>` is not satisfied + --> $DIR/wfness.rs:8:47 + | +LL | struct WhereClause where (): Trait; + | ^^^^^^^^ the trait `Trait<2_u8>` is not implemented for `()` + | + = help: the following implementations were found: + <() as Trait<3_u8>> +note: required by `WhereClause` + --> $DIR/wfness.rs:8:1 + | +LL | struct WhereClause where (): Trait; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `(): Trait<1_u8>` is not satisfied + --> $DIR/wfness.rs:16:13 + | +LL | fn foo() -> DependentDefaultWfness { + | ^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<1_u8>` is not implemented for `()` + | + = help: the following implementations were found: + <() as Trait<3_u8>> +note: required by a bound in `WhereClause` + --> $DIR/wfness.rs:8:47 + | +LL | struct WhereClause where (): Trait; + | ^^^^^^^^ required by this bound in `WhereClause` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0080, E0277. +For more information about an error, try `rustc --explain E0080`. From 8f237791d5131384279d10676fe54f9833a9e436 Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 20 Oct 2021 23:36:50 +0100 Subject: [PATCH 09/16] Inference --- .../ui/const-generics/defaults/doesnt_infer.rs | 15 +++++++++++++++ .../const-generics/defaults/doesnt_infer.stderr | 11 +++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/test/ui/const-generics/defaults/doesnt_infer.rs create mode 100644 src/test/ui/const-generics/defaults/doesnt_infer.stderr diff --git a/src/test/ui/const-generics/defaults/doesnt_infer.rs b/src/test/ui/const-generics/defaults/doesnt_infer.rs new file mode 100644 index 0000000000000..c7f14e47a9d64 --- /dev/null +++ b/src/test/ui/const-generics/defaults/doesnt_infer.rs @@ -0,0 +1,15 @@ +#![feature(const_generics_defaults)] + +// test that defaulted const params are not used to help type inference + +struct Foo; + +impl Foo { + fn foo() -> Self { loop {} } +} + +fn main() { + let foo = Foo::<1>::foo(); + let foo = Foo::foo(); + //~^ error: type annotations needed for `Foo<{_: u32}>` +} diff --git a/src/test/ui/const-generics/defaults/doesnt_infer.stderr b/src/test/ui/const-generics/defaults/doesnt_infer.stderr new file mode 100644 index 0000000000000..b57975e26f290 --- /dev/null +++ b/src/test/ui/const-generics/defaults/doesnt_infer.stderr @@ -0,0 +1,11 @@ +error[E0282]: type annotations needed for `Foo<{_: u32}>` + --> $DIR/doesnt_infer.rs:13:15 + | +LL | let foo = Foo::foo(); + | --- ^^^^^^^^ cannot infer the value of const parameter `N` + | | + | consider giving `foo` the explicit type `Foo<{_: u32}>`, where the type parameter `N` is specified + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. From 7a8bd2d13320ce770b90e0cda583f89221ef63e8 Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 20 Oct 2021 23:37:36 +0100 Subject: [PATCH 10/16] add fixme --- src/test/ui/const-generics/defaults/default-annotation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/const-generics/defaults/default-annotation.rs b/src/test/ui/const-generics/defaults/default-annotation.rs index 2b41dbb58873e..5517bf8ac5fb2 100644 --- a/src/test/ui/const-generics/defaults/default-annotation.rs +++ b/src/test/ui/const-generics/defaults/default-annotation.rs @@ -2,7 +2,7 @@ #![feature(staged_api)] #![feature(const_generics_defaults)] #![allow(incomplete_features)] -// FIXME(const_generics): It seems like we aren't testing the right thing here, +// FIXME(const_generics_defaults): It seems like we aren't testing the right thing here, // I would assume that we want the attributes to apply to the const parameter defaults // themselves. #![stable(feature = "const_default_test", since="none")] From c75d8cb2126f9ac4716059792d053c6a9f76dc9d Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 20 Oct 2021 23:44:50 +0100 Subject: [PATCH 11/16] Ordering --- src/test/ui/const-generics/defaults/wrong-order.rs | 3 +++ src/test/ui/const-generics/defaults/wrong-order.stderr | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/test/ui/const-generics/defaults/wrong-order.rs b/src/test/ui/const-generics/defaults/wrong-order.rs index 33564a48448a7..94e7367b1fb76 100644 --- a/src/test/ui/const-generics/defaults/wrong-order.rs +++ b/src/test/ui/const-generics/defaults/wrong-order.rs @@ -5,4 +5,7 @@ struct A { arg: T, } +struct Foo(T); +//~^ error: generic parameters with a default must be trailing + fn main() {} diff --git a/src/test/ui/const-generics/defaults/wrong-order.stderr b/src/test/ui/const-generics/defaults/wrong-order.stderr index 47a2c6f3f4193..143ce5c4fea7e 100644 --- a/src/test/ui/const-generics/defaults/wrong-order.stderr +++ b/src/test/ui/const-generics/defaults/wrong-order.stderr @@ -4,5 +4,11 @@ error: generic parameters with a default must be trailing LL | struct A { | ^ -error: aborting due to previous error +error: generic parameters with a default must be trailing + --> $DIR/wrong-order.rs:8:18 + | +LL | struct Foo(T); + | ^ + +error: aborting due to 2 previous errors From e7a9e820d28e02d63065aeb1f961e1d8ba83759d Mon Sep 17 00:00:00 2001 From: Ellen Date: Thu, 21 Oct 2021 00:16:49 +0100 Subject: [PATCH 12/16] *dust dust* --- src/test/ui/const-generics/defaults/trait_objects.rs | 2 +- src/test/ui/const-generics/defaults/wfness.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/ui/const-generics/defaults/trait_objects.rs b/src/test/ui/const-generics/defaults/trait_objects.rs index 9ba928c43c509..e36f23fadb272 100644 --- a/src/test/ui/const-generics/defaults/trait_objects.rs +++ b/src/test/ui/const-generics/defaults/trait_objects.rs @@ -39,7 +39,7 @@ fn bar(arg: &dyn Traitor) -> u8 { fn main() { assert_eq!(foo(&10_u32), 12); assert_eq!(foo(&3_u64), 3); - + assert_eq!(bar(&true), 2); assert_eq!(bar(&1_u8), 1); } diff --git a/src/test/ui/const-generics/defaults/wfness.rs b/src/test/ui/const-generics/defaults/wfness.rs index d2b53eaf9299a..c171f292fd698 100644 --- a/src/test/ui/const-generics/defaults/wfness.rs +++ b/src/test/ui/const-generics/defaults/wfness.rs @@ -11,7 +11,7 @@ struct WhereClause where (): Trait; trait Traitor {} struct WhereClauseTooGeneric(T) where (): Traitor; -// no error on struct def +// no error on struct def struct DependentDefaultWfness>(T); fn foo() -> DependentDefaultWfness { //~^ error: the trait bound `(): Trait<1_u8>` is not satisfied From 74c6636d27fe95e79d130f7420302d5db2559c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Thu, 21 Oct 2021 00:00:00 +0000 Subject: [PATCH 13/16] Verify that only NeedsNonConstDrop expects promoteds --- .../src/transform/check_consts/qualifs.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index 0a57d9adc46a9..aaeb1eeb04397 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -46,6 +46,9 @@ pub trait Qualif { /// Whether this `Qualif` is cleared when a local is moved from. const IS_CLEARED_ON_MOVE: bool = false; + /// Whether this `Qualif` might be evaluated after the promotion and can encounter a promoted. + const ALLOW_PROMOTED: bool = false; + /// Extracts the field of `ConstQualifs` that corresponds to this `Qualif`. fn in_qualifs(qualifs: &ConstQualifs) -> bool; @@ -129,6 +132,7 @@ pub struct NeedsNonConstDrop; impl Qualif for NeedsNonConstDrop { const ANALYSIS_NAME: &'static str = "flow_needs_nonconst_drop"; const IS_CLEARED_ON_MOVE: bool = true; + const ALLOW_PROMOTED: bool = true; fn in_qualifs(qualifs: &ConstQualifs) -> bool { qualifs.needs_non_const_drop @@ -309,11 +313,13 @@ where // Check the qualifs of the value of `const` items. if let Some(ct) = constant.literal.const_for_ty() { - if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted: None }) = - ct.val - { + if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted }) = ct.val { + // Use qualifs of the type for the promoted. Promoteds in MIR body should be possible + // only for `NeedsNonConstDrop` with precise drop checking. This is the only const + // check performed after the promotion. Verify that with an assertion. + assert!(promoted.is_none() || Q::ALLOW_PROMOTED); // Don't peek inside trait associated constants. - if cx.tcx.trait_of_item(def.did).is_none() { + if promoted.is_none() && cx.tcx.trait_of_item(def.did).is_none() { let qualifs = if let Some((did, param_did)) = def.as_const_arg() { cx.tcx.at(constant.span).mir_const_qualif_const_arg((did, param_did)) } else { From ab44e46345653803e86e6e05358fdb1bb1a6d07b Mon Sep 17 00:00:00 2001 From: samlich <1349989+samlich@users.noreply.github.com> Date: Wed, 20 Oct 2021 22:51:31 +0000 Subject: [PATCH 14/16] Add test for issue #78561 --- src/test/ui/nll/issue-78561.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/test/ui/nll/issue-78561.rs diff --git a/src/test/ui/nll/issue-78561.rs b/src/test/ui/nll/issue-78561.rs new file mode 100644 index 0000000000000..55147fcd1bd27 --- /dev/null +++ b/src/test/ui/nll/issue-78561.rs @@ -0,0 +1,23 @@ +// check-pass +#![feature(type_alias_impl_trait)] + +pub trait Trait { + type A; + + fn f() -> Self::A; +} + +pub trait Tr2<'a, 'b> {} + +pub struct A(T); +pub trait Tr { + type B; +} + +impl<'a, 'b, T: Tr>> Trait for A { + type A = impl core::fmt::Debug; + + fn f() -> Self::A {} +} + +fn main() {} From d50832ba0965b035cc939af4c832ee2c468e2c51 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Thu, 21 Oct 2021 15:07:36 +0200 Subject: [PATCH 15/16] triagebot: Treat `I-*nominated` like `I-nominated` rustbot doesn't allow unauthenticated users to set `I-nominated`; apply the same permissions to the new `I-*nominated` labels. --- triagebot.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/triagebot.toml b/triagebot.toml index 1e4df4d3fb79a..48c7a00de7830 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -5,8 +5,8 @@ allow-unauthenticated = [ "requires-nightly", "regression-*", "perf-*", - # I-* without I-nominated - "I-*", "!I-nominated", + # I-* without I-*nominated + "I-*", "!I-*nominated", "AsyncAwait-OnDeck", ] From 04c1ec51f1e2073c4df56f4239d08fb4522aa081 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Tue, 27 Jul 2021 23:13:42 -0700 Subject: [PATCH 16/16] Clarify undefined behaviour for binary heap, btree and hashset Previously, it wasn't clear whether "This could include" was referring to logic errors, or undefined behaviour. Tweak wording to clarify this sentence does not relate to UB. --- library/alloc/src/collections/binary_heap.rs | 6 +++--- library/alloc/src/collections/btree/map.rs | 6 +++--- library/alloc/src/collections/btree/set.rs | 6 +++--- library/std/src/collections/hash/set.rs | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 9bded6c0f1cf2..d7620c68f2cae 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -162,9 +162,9 @@ use super::SpecExtend; /// item's ordering relative to any other item, as determined by the [`Ord`] /// trait, changes while it is in the heap. This is normally only possible /// through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. The -/// behavior resulting from such a logic error is not specified, but will -/// not result in undefined behavior. This could include panics, incorrect -/// results, aborts, memory leaks, and non-termination. +/// behavior resulting from such a logic error is not specified (it +/// could include panics, incorrect results, aborts, memory leaks, or +/// non-termination) but will not be undefined behavior. /// /// # Examples /// diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index fa86e611565e6..07920a6dba619 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -61,9 +61,9 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT; /// It is a logic error for a key to be modified in such a way that the key's ordering relative to /// any other key, as determined by the [`Ord`] trait, changes while it is in the map. This is /// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. -/// The behavior resulting from such a logic error is not specified, but will not result in -/// undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and -/// non-termination. +/// The behavior resulting from such a logic error is not specified (it could include panics, +/// incorrect results, aborts, memory leaks, or non-termination) but will not be undefined +/// behavior. /// /// [B-Tree]: https://en.wikipedia.org/wiki/B-tree /// [`Cell`]: core::cell::Cell diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index d732f65b0d05f..237e0107f2475 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -23,9 +23,9 @@ use super::Recover; /// It is a logic error for an item to be modified in such a way that the item's ordering relative /// to any other item, as determined by the [`Ord`] trait, changes while it is in the set. This is /// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. -/// The behavior resulting from such a logic error is not specified, but will not result in -/// undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and -/// non-termination. +/// The behavior resulting from such a logic error is not specified (it could include panics, +/// incorrect results, aborts, memory leaks, or non-termination) but will not be undefined +/// behavior. /// /// [`Ord`]: core::cmp::Ord /// [`Cell`]: core::cell::Cell diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 5804701892e6e..546c43faecfdc 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -38,8 +38,8 @@ use super::map::{map_try_reserve_error, RandomState}; /// determined by the [`Eq`] trait, changes while it is in the set. This is /// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or /// unsafe code. The behavior resulting from such a logic error is not -/// specified, but will not result in undefined behavior. This could include -/// panics, incorrect results, aborts, memory leaks, and non-termination. +/// specified (it could include panics, incorrect results, aborts, memory +/// leaks, or non-termination) but will not be undefined behavior. /// /// # Examples ///