From d23c334707408057915a706351ac32b2db09d8c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sat, 24 Jun 2023 23:39:35 +0200 Subject: [PATCH 1/5] rustdoc: get rid of extra line when line-wrapping fn decls with empty arg list --- src/librustdoc/html/format.rs | 2 +- .../decl-line-wrapping-empty-arg-list.decl.html | 2 ++ tests/rustdoc/decl-line-wrapping-empty-arg-list.rs | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html create mode 100644 tests/rustdoc/decl-line-wrapping-empty-arg-list.rs diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index b710311c85872..b4aba2993c7fd 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -1408,7 +1408,7 @@ impl clean::FnDecl { let amp = if f.alternate() { "&" } else { "&" }; write!(f, "(")?; - if let Some(n) = line_wrapping_indent { + if let Some(n) = line_wrapping_indent && !self.inputs.values.is_empty() { write!(f, "\n{}", Indent(n + 4))?; } for (i, input) in self.inputs.values.iter().enumerate() { diff --git a/tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html b/tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html new file mode 100644 index 0000000000000..29c08c5bd5dec --- /dev/null +++ b/tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html @@ -0,0 +1,2 @@ +
pub fn create(
+) -> Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000
\ No newline at end of file diff --git a/tests/rustdoc/decl-line-wrapping-empty-arg-list.rs b/tests/rustdoc/decl-line-wrapping-empty-arg-list.rs new file mode 100644 index 0000000000000..4cfb87496b486 --- /dev/null +++ b/tests/rustdoc/decl-line-wrapping-empty-arg-list.rs @@ -0,0 +1,12 @@ +// Ensure that we don't add an extra line containing nothing but whitespace in between the two +// parentheses of an empty argument list when line-wrapping a function declaration. + +// ignore-tidy-linelength + +pub struct Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000; + +// @has 'decl_line_wrapping_empty_arg_list/fn.create.html' +// @snapshot decl - '//pre[@class="rust item-decl"]' +pub fn create() -> Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000 { + loop {} +} From 91351ef48676638101ee24bba3403e8cf81d510c Mon Sep 17 00:00:00 2001 From: dswij Date: Fri, 23 Jun 2023 02:53:34 +0800 Subject: [PATCH 2/5] Add test for futures with HRTB --- .../trait-bounds/future.classic.stderr | 6 +++ tests/ui/higher-ranked/trait-bounds/future.rs | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/ui/higher-ranked/trait-bounds/future.classic.stderr create mode 100644 tests/ui/higher-ranked/trait-bounds/future.rs diff --git a/tests/ui/higher-ranked/trait-bounds/future.classic.stderr b/tests/ui/higher-ranked/trait-bounds/future.classic.stderr new file mode 100644 index 0000000000000..33c0f7173a1d1 --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/future.classic.stderr @@ -0,0 +1,6 @@ +error: the compiler unexpectedly panicked. this is a bug. + +query stack during panic: +#0 [evaluate_obligation] evaluating trait selection obligation `for<'a> [async fn body@$DIR/future.rs:32:35: 34:2]: core::future::future::Future` +#1 [codegen_select_candidate] computing candidate for `` +end of query stack diff --git a/tests/ui/higher-ranked/trait-bounds/future.rs b/tests/ui/higher-ranked/trait-bounds/future.rs new file mode 100644 index 0000000000000..da7ee0343291e --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/future.rs @@ -0,0 +1,38 @@ +// ignore-tidy-linelength +// edition:2021 +// revisions: classic next +//[next] compile-flags: -Ztrait-solver=next +//[next] check-pass +//[classic] known-bug: #112347 +//[classic] build-fail +//[classic] failure-status: 101 +//[classic] normalize-stderr-test "note: .*\n\n" -> "" +//[classic] normalize-stderr-test "thread 'rustc' panicked.*\n" -> "" +//[classic] normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: " +//[classic] rustc-env:RUST_BACKTRACE=0 + +#![feature(unboxed_closures)] + +use std::future::Future; + +trait Trait { + fn func(&self, _: &str); +} + +impl Trait for T +where + for<'a> T: Fn<(&'a str,)> + Send + Sync, + for<'a> >::Output: Future + Send, +{ + fn func(&self, _: &str) { + println!("hello!"); + } +} + +async fn strlen(x: &str) -> usize { + x.len() +} + +fn main() { + strlen.func("hi"); +} From abe52cdcc79d654554789b35c85fbac4a79d3d42 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 25 Jun 2023 23:01:06 +0900 Subject: [PATCH 3/5] Add a regression test for #109071 Signed-off-by: Yuki Okushi --- .../issue-109071.no_gate.stderr | 35 +++++++++++++++++++ .../associated-inherent-types/issue-109071.rs | 18 ++++++++++ .../issue-109071.with_gate.stderr | 26 ++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 tests/ui/associated-inherent-types/issue-109071.no_gate.stderr create mode 100644 tests/ui/associated-inherent-types/issue-109071.rs create mode 100644 tests/ui/associated-inherent-types/issue-109071.with_gate.stderr diff --git a/tests/ui/associated-inherent-types/issue-109071.no_gate.stderr b/tests/ui/associated-inherent-types/issue-109071.no_gate.stderr new file mode 100644 index 0000000000000..8b6a8206569f6 --- /dev/null +++ b/tests/ui/associated-inherent-types/issue-109071.no_gate.stderr @@ -0,0 +1,35 @@ +error[E0637]: `&` without an explicit lifetime name cannot be used here + --> $DIR/issue-109071.rs:8:17 + | +LL | type Item = &[T]; + | ^ explicit lifetime name needed here + +error[E0107]: missing generics for struct `Windows` + --> $DIR/issue-109071.rs:7:9 + | +LL | impl Windows { + | ^^^^^^^ expected 1 generic argument + | +note: struct defined here, with 1 generic parameter: `T` + --> $DIR/issue-109071.rs:5:8 + | +LL | struct Windows {} + | ^^^^^^^ - +help: add missing generic argument + | +LL | impl Windows { + | +++ + +error[E0658]: inherent associated types are unstable + --> $DIR/issue-109071.rs:8:5 + | +LL | type Item = &[T]; + | ^^^^^^^^^^^^^^^^^ + | + = note: see issue #8995 for more information + = help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0107, E0637, E0658. +For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/associated-inherent-types/issue-109071.rs b/tests/ui/associated-inherent-types/issue-109071.rs new file mode 100644 index 0000000000000..73b969d5940ab --- /dev/null +++ b/tests/ui/associated-inherent-types/issue-109071.rs @@ -0,0 +1,18 @@ +// revisions: with_gate no_gate +#![cfg_attr(with_gate, feature(inherent_associated_types))] +#![cfg_attr(with_gate, allow(incomplete_features))] + +struct Windows {} + +impl Windows { //~ ERROR: missing generics for struct `Windows` + type Item = &[T]; //~ ERROR: `&` without an explicit lifetime name cannot be used here + //[no_gate]~^ ERROR: inherent associated types are unstable + + fn next() -> Option {} +} + +impl Windows { + fn T() -> Option {} +} + +fn main() {} diff --git a/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr b/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr new file mode 100644 index 0000000000000..a91bb7a5162e3 --- /dev/null +++ b/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr @@ -0,0 +1,26 @@ +error[E0637]: `&` without an explicit lifetime name cannot be used here + --> $DIR/issue-109071.rs:8:17 + | +LL | type Item = &[T]; + | ^ explicit lifetime name needed here + +error[E0107]: missing generics for struct `Windows` + --> $DIR/issue-109071.rs:7:9 + | +LL | impl Windows { + | ^^^^^^^ expected 1 generic argument + | +note: struct defined here, with 1 generic parameter: `T` + --> $DIR/issue-109071.rs:5:8 + | +LL | struct Windows {} + | ^^^^^^^ - +help: add missing generic argument + | +LL | impl Windows { + | +++ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0107, E0637. +For more information about an error, try `rustc --explain E0107`. From 421105b4537c9671580c45ce9d952982cb074954 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 25 Jun 2023 23:03:22 +0900 Subject: [PATCH 4/5] Add a regression test for #110933 Signed-off-by: Yuki Okushi --- tests/ui/associated-consts/issue-110933.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/ui/associated-consts/issue-110933.rs diff --git a/tests/ui/associated-consts/issue-110933.rs b/tests/ui/associated-consts/issue-110933.rs new file mode 100644 index 0000000000000..aa4882ae53577 --- /dev/null +++ b/tests/ui/associated-consts/issue-110933.rs @@ -0,0 +1,20 @@ +// check-pass + +#![feature(associated_const_equality)] + +pub trait Trait { + const ASSOC: usize; +} + +pub fn foo< + T: Trait< + ASSOC = { + let a = 10_usize; + let b: &'_ usize = &a; + *b + }, + >, +>() { +} + +fn main() {} From 83722c62b08a2ced521a79f25be05a0c16a907d1 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sun, 25 Jun 2023 22:28:04 +0900 Subject: [PATCH 5/5] accept `ReStatic` for RPITIT add an ui test for #112094 --- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 2 +- .../static-lifetime-return-position-impl-trait.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index f93f395caed68..f43c7bbe9b85b 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1550,7 +1550,7 @@ impl<'tcx> TypeVisitor> for ImplTraitInTraitFinder<'_, 'tcx> { { let opaque_ty = tcx.fold_regions(unshifted_opaque_ty, |re, _depth| { match re.kind() { - ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReError(_) => re, + ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReError(_) | ty::ReStatic => re, r => bug!("unexpected region: {r:?}"), } }); diff --git a/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs b/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs new file mode 100644 index 0000000000000..98dbaf036be7b --- /dev/null +++ b/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs @@ -0,0 +1,12 @@ +// check-pass + +#![allow(incomplete_features)] +#![feature(adt_const_params, return_position_impl_trait_in_trait)] + +pub struct Element; + +pub trait Node { + fn elements(&self) -> impl Iterator; +} + +fn main() {}