From bc78d0cbf1efb76fa6d7c80bb029a4b6d9af92c3 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 14 Jun 2023 05:20:31 +0000 Subject: Error on unconstrained lifetime in RPITIT --- .../in-trait/method-signature-matches.lt.stderr | 21 ++++++ .../method-signature-matches.mismatch.stderr | 20 ++++++ .../method-signature-matches.mismatch_async.stderr | 20 ++++++ .../in-trait/method-signature-matches.rs | 21 ++++-- .../in-trait/method-signature-matches.stderr | 74 ---------------------- .../method-signature-matches.too_few.stderr | 12 ++++ .../method-signature-matches.too_many.stderr | 12 ++++ .../in-trait/unconstrained-lt.current.stderr | 9 +++ .../in-trait/unconstrained-lt.next.stderr | 9 +++ tests/ui/impl-trait/in-trait/unconstrained-lt.rs | 16 +++++ 10 files changed, 135 insertions(+), 79 deletions(-) create mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr create mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.mismatch.stderr create mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.mismatch_async.stderr delete mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.stderr create mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.too_few.stderr create mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.too_many.stderr create mode 100644 tests/ui/impl-trait/in-trait/unconstrained-lt.current.stderr create mode 100644 tests/ui/impl-trait/in-trait/unconstrained-lt.next.stderr create mode 100644 tests/ui/impl-trait/in-trait/unconstrained-lt.rs (limited to 'tests') diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr new file mode 100644 index 00000000000..f604ada6ac7 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr @@ -0,0 +1,21 @@ +error[E0053]: method `early` has an incompatible type for trait + --> $DIR/method-signature-matches.rs:58:27 + | +LL | fn early<'late, T>(_: &'late ()) {} + | - ^^^^^^^^^ + | | | + | | expected type parameter `T`, found `()` + | | help: change the parameter type to match the trait: `&'early T` + | this type parameter + | +note: type in trait + --> $DIR/method-signature-matches.rs:53:28 + | +LL | fn early<'early, T>(x: &'early T) -> impl Sized; + | ^^^^^^^^^ + = note: expected signature `fn(&'early T)` + found signature `fn(&())` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0053`. diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch.stderr new file mode 100644 index 00000000000..d3183b92e84 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch.stderr @@ -0,0 +1,20 @@ +error[E0053]: method `owo` has an incompatible type for trait + --> $DIR/method-signature-matches.rs:14:15 + | +LL | fn owo(_: u8) {} + | ^^ + | | + | expected `()`, found `u8` + | help: change the parameter type to match the trait: `()` + | +note: type in trait + --> $DIR/method-signature-matches.rs:9:15 + | +LL | fn owo(x: ()) -> impl Sized; + | ^^ + = note: expected signature `fn(())` + found signature `fn(u8)` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0053`. diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch_async.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch_async.stderr new file mode 100644 index 00000000000..80fda1c9fe1 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch_async.stderr @@ -0,0 +1,20 @@ +error[E0053]: method `owo` has an incompatible type for trait + --> $DIR/method-signature-matches.rs:25:21 + | +LL | async fn owo(_: u8) {} + | ^^ + | | + | expected `()`, found `u8` + | help: change the parameter type to match the trait: `()` + | +note: type in trait + --> $DIR/method-signature-matches.rs:20:21 + | +LL | async fn owo(x: ()) {} + | ^^ + = note: expected signature `fn(()) -> _` + found signature `fn(u8) -> _` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0053`. diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.rs b/tests/ui/impl-trait/in-trait/method-signature-matches.rs index c848ee3f643..294f93b30d0 100644 --- a/tests/ui/impl-trait/in-trait/method-signature-matches.rs +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.rs @@ -1,51 +1,62 @@ // edition: 2021 +// revisions: mismatch mismatch_async too_many too_few lt #![feature(return_position_impl_trait_in_trait, async_fn_in_trait)] #![allow(incomplete_features)] +#[cfg(mismatch)] trait Uwu { fn owo(x: ()) -> impl Sized; } +#[cfg(mismatch)] impl Uwu for () { fn owo(_: u8) {} - //~^ ERROR method `owo` has an incompatible type for trait + //[mismatch]~^ ERROR method `owo` has an incompatible type for trait } +#[cfg(mismatch_async)] trait AsyncUwu { async fn owo(x: ()) {} } +#[cfg(mismatch_async)] impl AsyncUwu for () { async fn owo(_: u8) {} - //~^ ERROR method `owo` has an incompatible type for trait + //[mismatch_async]~^ ERROR method `owo` has an incompatible type for trait } +#[cfg(too_many)] trait TooMuch { fn calm_down_please() -> impl Sized; } +#[cfg(too_many)] impl TooMuch for () { fn calm_down_please(_: (), _: (), _: ()) {} - //~^ ERROR method `calm_down_please` has 3 parameters but the declaration in trait `TooMuch::calm_down_please` has 0 + //[too_many]~^ ERROR method `calm_down_please` has 3 parameters but the declaration in trait `TooMuch::calm_down_please` has 0 } +#[cfg(too_few)] trait TooLittle { fn come_on_a_little_more_effort(_: (), _: (), _: ()) -> impl Sized; } +#[cfg(too_few)] impl TooLittle for () { fn come_on_a_little_more_effort() {} - //~^ ERROR method `come_on_a_little_more_effort` has 0 parameters but the declaration in trait `TooLittle::come_on_a_little_more_effort` has 3 + //[too_few]~^ ERROR method `come_on_a_little_more_effort` has 0 parameters but the declaration in trait `TooLittle::come_on_a_little_more_effort` has 3 } +#[cfg(lt)] trait Lifetimes { fn early<'early, T>(x: &'early T) -> impl Sized; } +#[cfg(lt)] impl Lifetimes for () { fn early<'late, T>(_: &'late ()) {} - //~^ ERROR method `early` has an incompatible type for trait + //[lt]~^ ERROR method `early` has an incompatible type for trait } fn main() {} diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.stderr deleted file mode 100644 index 3ec62020e6c..00000000000 --- a/tests/ui/impl-trait/in-trait/method-signature-matches.stderr +++ /dev/null @@ -1,74 +0,0 @@ -error[E0053]: method `owo` has an incompatible type for trait - --> $DIR/method-signature-matches.rs:11:15 - | -LL | fn owo(_: u8) {} - | ^^ - | | - | expected `()`, found `u8` - | help: change the parameter type to match the trait: `()` - | -note: type in trait - --> $DIR/method-signature-matches.rs:7:15 - | -LL | fn owo(x: ()) -> impl Sized; - | ^^ - = note: expected signature `fn(())` - found signature `fn(u8)` - -error[E0053]: method `owo` has an incompatible type for trait - --> $DIR/method-signature-matches.rs:20:21 - | -LL | async fn owo(_: u8) {} - | ^^ - | | - | expected `()`, found `u8` - | help: change the parameter type to match the trait: `()` - | -note: type in trait - --> $DIR/method-signature-matches.rs:16:21 - | -LL | async fn owo(x: ()) {} - | ^^ - = note: expected signature `fn(()) -> _` - found signature `fn(u8) -> _` - -error[E0050]: method `calm_down_please` has 3 parameters but the declaration in trait `TooMuch::calm_down_please` has 0 - --> $DIR/method-signature-matches.rs:29:28 - | -LL | fn calm_down_please() -> impl Sized; - | ------------------------------------ trait requires 0 parameters -... -LL | fn calm_down_please(_: (), _: (), _: ()) {} - | ^^^^^^^^^^^^^^^^ expected 0 parameters, found 3 - -error[E0050]: method `come_on_a_little_more_effort` has 0 parameters but the declaration in trait `TooLittle::come_on_a_little_more_effort` has 3 - --> $DIR/method-signature-matches.rs:38:5 - | -LL | fn come_on_a_little_more_effort(_: (), _: (), _: ()) -> impl Sized; - | ---------------- trait requires 3 parameters -... -LL | fn come_on_a_little_more_effort() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 3 parameters, found 0 - -error[E0053]: method `early` has an incompatible type for trait - --> $DIR/method-signature-matches.rs:47:27 - | -LL | fn early<'late, T>(_: &'late ()) {} - | - ^^^^^^^^^ - | | | - | | expected type parameter `T`, found `()` - | | help: change the parameter type to match the trait: `&'early T` - | this type parameter - | -note: type in trait - --> $DIR/method-signature-matches.rs:43:28 - | -LL | fn early<'early, T>(x: &'early T) -> impl Sized; - | ^^^^^^^^^ - = note: expected signature `fn(&'early T)` - found signature `fn(&())` - -error: aborting due to 5 previous errors - -Some errors have detailed explanations: E0050, E0053. -For more information about an error, try `rustc --explain E0050`. diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.too_few.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.too_few.stderr new file mode 100644 index 00000000000..24bcfeb748f --- /dev/null +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.too_few.stderr @@ -0,0 +1,12 @@ +error[E0050]: method `come_on_a_little_more_effort` has 0 parameters but the declaration in trait `TooLittle::come_on_a_little_more_effort` has 3 + --> $DIR/method-signature-matches.rs:47:5 + | +LL | fn come_on_a_little_more_effort(_: (), _: (), _: ()) -> impl Sized; + | ---------------- trait requires 3 parameters +... +LL | fn come_on_a_little_more_effort() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 3 parameters, found 0 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0050`. diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.too_many.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.too_many.stderr new file mode 100644 index 00000000000..616cbd2905c --- /dev/null +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.too_many.stderr @@ -0,0 +1,12 @@ +error[E0050]: method `calm_down_please` has 3 parameters but the declaration in trait `TooMuch::calm_down_please` has 0 + --> $DIR/method-signature-matches.rs:36:28 + | +LL | fn calm_down_please() -> impl Sized; + | ------------------------------------ trait requires 0 parameters +... +LL | fn calm_down_please(_: (), _: (), _: ()) {} + | ^^^^^^^^^^^^^^^^ expected 0 parameters, found 3 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0050`. diff --git a/tests/ui/impl-trait/in-trait/unconstrained-lt.current.stderr b/tests/ui/impl-trait/in-trait/unconstrained-lt.current.stderr new file mode 100644 index 00000000000..bf088ae8b25 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/unconstrained-lt.current.stderr @@ -0,0 +1,9 @@ +error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates + --> $DIR/unconstrained-lt.rs:10:6 + | +LL | impl<'a, T> Foo for T { + | ^^ unconstrained lifetime parameter + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0207`. diff --git a/tests/ui/impl-trait/in-trait/unconstrained-lt.next.stderr b/tests/ui/impl-trait/in-trait/unconstrained-lt.next.stderr new file mode 100644 index 00000000000..bf088ae8b25 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/unconstrained-lt.next.stderr @@ -0,0 +1,9 @@ +error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates + --> $DIR/unconstrained-lt.rs:10:6 + | +LL | impl<'a, T> Foo for T { + | ^^ unconstrained lifetime parameter + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0207`. diff --git a/tests/ui/impl-trait/in-trait/unconstrained-lt.rs b/tests/ui/impl-trait/in-trait/unconstrained-lt.rs new file mode 100644 index 00000000000..f966be43a6e --- /dev/null +++ b/tests/ui/impl-trait/in-trait/unconstrained-lt.rs @@ -0,0 +1,16 @@ +// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty +// revisions: current next + +#![feature(return_position_impl_trait_in_trait)] + +trait Foo { + fn test() -> impl Sized; +} + +impl<'a, T> Foo for T { + //~^ ERROR the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates + + fn test() -> &'a () { &() } +} + +fn main() {} -- cgit 1.4.1-3-g733a5 From 72531b7463db02b9e049e8ad7f095cce928ffc1e Mon Sep 17 00:00:00 2001 From: Sam Ginnett Date: Tue, 13 Jun 2023 22:59:03 -0700 Subject: Fix explicit-outlives-requirements lint span --- compiler/rustc_lint/src/builtin.rs | 19 ++++++++++++------- tests/ui/rust-2018/edition-lint-infer-outlives.fixed | 6 ++++++ tests/ui/rust-2018/edition-lint-infer-outlives.rs | 8 ++++++++ tests/ui/rust-2018/edition-lint-infer-outlives.stderr | 11 ++++++++++- 4 files changed, 36 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index ff2989112af..7b05bff5151 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2124,12 +2124,16 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements { } let ty_generics = cx.tcx.generics_of(def_id); + let num_where_predicates = hir_generics + .predicates + .iter() + .filter(|predicate| predicate.in_where_clause()) + .count(); let mut bound_count = 0; let mut lint_spans = Vec::new(); let mut where_lint_spans = Vec::new(); - let mut dropped_predicate_count = 0; - let num_predicates = hir_generics.predicates.len(); + let mut dropped_where_predicate_count = 0; for (i, where_predicate) in hir_generics.predicates.iter().enumerate() { let (relevant_lifetimes, bounds, predicate_span, in_where_clause) = match where_predicate { @@ -2186,8 +2190,8 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements { bound_count += bound_spans.len(); let drop_predicate = bound_spans.len() == bounds.len(); - if drop_predicate { - dropped_predicate_count += 1; + if drop_predicate && in_where_clause { + dropped_where_predicate_count += 1; } if drop_predicate { @@ -2196,7 +2200,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements { } else if predicate_span.from_expansion() { // Don't try to extend the span if it comes from a macro expansion. where_lint_spans.push(predicate_span); - } else if i + 1 < num_predicates { + } else if i + 1 < num_where_predicates { // If all the bounds on a predicate were inferable and there are // further predicates, we want to eat the trailing comma. let next_predicate_span = hir_generics.predicates[i + 1].span(); @@ -2224,9 +2228,10 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements { } } - // If all predicates are inferable, drop the entire clause + // If all predicates in where clause are inferable, drop the entire clause // (including the `where`) - if hir_generics.has_where_clause_predicates && dropped_predicate_count == num_predicates + if hir_generics.has_where_clause_predicates + && dropped_where_predicate_count == num_where_predicates { let where_span = hir_generics.where_clause_span; // Extend the where clause back to the closing `>` of the diff --git a/tests/ui/rust-2018/edition-lint-infer-outlives.fixed b/tests/ui/rust-2018/edition-lint-infer-outlives.fixed index 868bdf2e068..5058d61b588 100644 --- a/tests/ui/rust-2018/edition-lint-infer-outlives.fixed +++ b/tests/ui/rust-2018/edition-lint-infer-outlives.fixed @@ -801,4 +801,10 @@ where yoo: &'a U } +// https://github.com/rust-lang/rust/issues/105150 +struct InferredWhereBoundWithInlineBound<'a, T: ?Sized> +{ + data: &'a T, +} + fn main() {} diff --git a/tests/ui/rust-2018/edition-lint-infer-outlives.rs b/tests/ui/rust-2018/edition-lint-infer-outlives.rs index 75783764ad6..3f63cb8e900 100644 --- a/tests/ui/rust-2018/edition-lint-infer-outlives.rs +++ b/tests/ui/rust-2018/edition-lint-infer-outlives.rs @@ -801,4 +801,12 @@ where yoo: &'a U } +// https://github.com/rust-lang/rust/issues/105150 +struct InferredWhereBoundWithInlineBound<'a, T: ?Sized> +//~^ ERROR outlives requirements can be inferred + where T: 'a, +{ + data: &'a T, +} + fn main() {} diff --git a/tests/ui/rust-2018/edition-lint-infer-outlives.stderr b/tests/ui/rust-2018/edition-lint-infer-outlives.stderr index e655fb4842c..dbf301fd8a1 100644 --- a/tests/ui/rust-2018/edition-lint-infer-outlives.stderr +++ b/tests/ui/rust-2018/edition-lint-infer-outlives.stderr @@ -10,6 +10,15 @@ note: the lint level is defined here LL | #![deny(explicit_outlives_requirements)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: outlives requirements can be inferred + --> $DIR/edition-lint-infer-outlives.rs:805:56 + | +LL | struct InferredWhereBoundWithInlineBound<'a, T: ?Sized> + | ________________________________________________________^ +LL | | +LL | | where T: 'a, + | |________________^ help: remove this bound + error: outlives requirements can be inferred --> $DIR/edition-lint-infer-outlives.rs:26:31 | @@ -922,5 +931,5 @@ error: outlives requirements can be inferred LL | union BeeWhereOutlivesAyTeeWhereDebug<'a, 'b, T> where 'b: 'a, T: Debug { | ^^^^^^^^ help: remove this bound -error: aborting due to 153 previous errors +error: aborting due to 154 previous errors -- cgit 1.4.1-3-g733a5 From df9a46f60ff1fa803378dce41e6dd96ca2349024 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 14 Jun 2023 10:37:19 +0200 Subject: Replace unicode value with character in shortcuts.goml test --- tests/rustdoc-gui/shortcuts.goml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/rustdoc-gui/shortcuts.goml b/tests/rustdoc-gui/shortcuts.goml index 667df89ec9b..2c61ee5428b 100644 --- a/tests/rustdoc-gui/shortcuts.goml +++ b/tests/rustdoc-gui/shortcuts.goml @@ -13,7 +13,7 @@ press-key: "Escape" assert-css: ("#help-button .popover", {"display": "none"}) // Checking doc collapse and expand. // It should be displaying a "-": -assert-text: ("#toggle-all-docs", "[\u2212]") +assert-text: ("#toggle-all-docs", "[−]") press-key: "-" wait-for-text: ("#toggle-all-docs", "[+]") assert-attribute: ("#toggle-all-docs", {"class": "will-expand"}) @@ -23,9 +23,9 @@ assert-text: ("#toggle-all-docs", "[+]") assert-attribute: ("#toggle-all-docs", {"class": "will-expand"}) // Expanding now. press-key: "+" -wait-for-text: ("#toggle-all-docs", "[\u2212]") +wait-for-text: ("#toggle-all-docs", "[−]") assert-attribute: ("#toggle-all-docs", {"class": ""}) // Pressing it again shouldn't do anything. press-key: "+" -assert-text: ("#toggle-all-docs", "[\u2212]") +assert-text: ("#toggle-all-docs", "[−]") assert-attribute: ("#toggle-all-docs", {"class": ""}) -- cgit 1.4.1-3-g733a5 From fced6383c2ff25be0d0c5eaa82aea8980cb540ca Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 14 Jun 2023 16:23:00 +0200 Subject: Fix `href` attribute value check on Windows (`DOC_PATH` lacks an extra `/`) --- tests/rustdoc-gui/source-code-page.goml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/rustdoc-gui/source-code-page.goml b/tests/rustdoc-gui/source-code-page.goml index d5dd511b1d3..f8f73398d9b 100644 --- a/tests/rustdoc-gui/source-code-page.goml +++ b/tests/rustdoc-gui/source-code-page.goml @@ -64,23 +64,23 @@ call-function: ("check-colors", { compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y")) // Check the `href` property so that users can treat anchors as links. assert-property: (".src-line-numbers > a:nth-child(1)", { - "href": "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#1" -}) + "href": |DOC_PATH| + "/src/test_docs/lib.rs.html#1" +}, ENDS_WITH) assert-property: (".src-line-numbers > a:nth-child(2)", { - "href": "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#2" -}) + "href": |DOC_PATH| + "/src/test_docs/lib.rs.html#2" +}, ENDS_WITH) assert-property: (".src-line-numbers > a:nth-child(3)", { - "href": "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#3" -}) + "href": |DOC_PATH| + "/src/test_docs/lib.rs.html#3" +}, ENDS_WITH) assert-property: (".src-line-numbers > a:nth-child(4)", { - "href": "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#4" -}) + "href": |DOC_PATH| + "/src/test_docs/lib.rs.html#4" +}, ENDS_WITH) assert-property: (".src-line-numbers > a:nth-child(5)", { - "href": "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#5" -}) + "href": |DOC_PATH| + "/src/test_docs/lib.rs.html#5" +}, ENDS_WITH) assert-property: (".src-line-numbers > a:nth-child(6)", { - "href": "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#6" -}) + "href": |DOC_PATH| + "/src/test_docs/lib.rs.html#6" +}, ENDS_WITH) // Assert that the line numbers text is aligned to the right. assert-css: (".src-line-numbers", {"text-align": "right"}) -- cgit 1.4.1-3-g733a5