Skip to content

Commit 807bd98

Browse files
committed
Delay a bug if no RPITITs were found
1 parent b3df0d7 commit 807bd98

File tree

3 files changed

+74
-21
lines changed

3 files changed

+74
-21
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,9 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
639639
}
640640
}
641641

642-
if !unnormalized_trait_sig.output().references_error() {
643-
debug_assert!(
644-
!collector.types.is_empty(),
645-
"expect >0 RPITITs in call to `collect_return_position_impl_trait_in_trait_tys`"
642+
if !unnormalized_trait_sig.output().references_error() && collector.types.is_empty() {
643+
tcx.dcx().delayed_bug(
644+
"expect >0 RPITITs in call to `collect_return_position_impl_trait_in_trait_tys`",
646645
);
647646
}
648647

tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
struct Wrapper<'rom>(T);
2-
//~^ ERROR cannot find type `T` in this scope
1+
struct Wrapper<'rom>(&'rom ());
32

43
trait Foo {
54
fn bar() -> Wrapper<impl Sized>;
@@ -15,4 +14,18 @@ impl Foo for () {
1514
}
1615
}
1716

17+
trait Bar {
18+
fn foo() -> Wrapper<impl Sized>;
19+
//~^ ERROR missing lifetime specifier
20+
//~| ERROR struct takes 0 generic arguments but 1 generic argument was supplied
21+
}
22+
23+
impl Bar for () {
24+
fn foo() -> Wrapper<impl Sized> {
25+
//~^ ERROR missing lifetime specifier
26+
//~| ERROR struct takes 0 generic arguments but 1 generic argument was supplied
27+
Wrapper(&())
28+
}
29+
}
30+
1831
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0106]: missing lifetime specifier
2-
--> $DIR/opaque-and-lifetime-mismatch.rs:5:24
2+
--> $DIR/opaque-and-lifetime-mismatch.rs:4:24
33
|
44
LL | fn bar() -> Wrapper<impl Sized>;
55
| ^ expected named lifetime parameter
@@ -10,19 +10,32 @@ help: consider using the `'static` lifetime, but this is uncommon unless you're
1010
LL | fn bar() -> Wrapper<'static, impl Sized>;
1111
| ++++++++
1212

13-
error[E0412]: cannot find type `T` in this scope
14-
--> $DIR/opaque-and-lifetime-mismatch.rs:1:22
13+
error[E0106]: missing lifetime specifier
14+
--> $DIR/opaque-and-lifetime-mismatch.rs:18:24
15+
|
16+
LL | fn foo() -> Wrapper<impl Sized>;
17+
| ^ expected named lifetime parameter
18+
|
19+
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
20+
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`, or if you will only have owned values
21+
|
22+
LL | fn foo() -> Wrapper<'static, impl Sized>;
23+
| ++++++++
24+
25+
error[E0106]: missing lifetime specifier
26+
--> $DIR/opaque-and-lifetime-mismatch.rs:24:24
1527
|
16-
LL | struct Wrapper<'rom>(T);
17-
| ^ not found in this scope
28+
LL | fn foo() -> Wrapper<impl Sized> {
29+
| ^ expected named lifetime parameter
1830
|
19-
help: you might be missing a type parameter
31+
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
32+
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`, or if you will only have owned values
2033
|
21-
LL | struct Wrapper<'rom, T>(T);
22-
| +++
34+
LL | fn foo() -> Wrapper<'static, impl Sized> {
35+
| ++++++++
2336

2437
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
25-
--> $DIR/opaque-and-lifetime-mismatch.rs:5:17
38+
--> $DIR/opaque-and-lifetime-mismatch.rs:4:17
2639
|
2740
LL | fn bar() -> Wrapper<impl Sized>;
2841
| ^^^^^^^ ---------- help: remove this generic argument
@@ -32,11 +45,25 @@ LL | fn bar() -> Wrapper<impl Sized>;
3245
note: struct defined here, with 0 generic parameters
3346
--> $DIR/opaque-and-lifetime-mismatch.rs:1:8
3447
|
35-
LL | struct Wrapper<'rom>(T);
48+
LL | struct Wrapper<'rom>(&'rom ());
49+
| ^^^^^^^
50+
51+
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
52+
--> $DIR/opaque-and-lifetime-mismatch.rs:18:17
53+
|
54+
LL | fn foo() -> Wrapper<impl Sized>;
55+
| ^^^^^^^ ---------- help: remove this generic argument
56+
| |
57+
| expected 0 generic arguments
58+
|
59+
note: struct defined here, with 0 generic parameters
60+
--> $DIR/opaque-and-lifetime-mismatch.rs:1:8
61+
|
62+
LL | struct Wrapper<'rom>(&'rom ());
3663
| ^^^^^^^
3764

3865
error[E0053]: method `bar` has an incompatible return type for trait
39-
--> $DIR/opaque-and-lifetime-mismatch.rs:11:17
66+
--> $DIR/opaque-and-lifetime-mismatch.rs:10:17
4067
|
4168
LL | fn bar() -> i32 {
4269
| ^^^
@@ -45,7 +72,7 @@ LL | fn bar() -> i32 {
4572
| return type in trait
4673

4774
error[E0053]: method `bar` has an incompatible type for trait
48-
--> $DIR/opaque-and-lifetime-mismatch.rs:11:17
75+
--> $DIR/opaque-and-lifetime-mismatch.rs:10:17
4976
|
5077
LL | fn bar() -> i32 {
5178
| ^^^
@@ -54,14 +81,28 @@ LL | fn bar() -> i32 {
5481
| help: change the output type to match the trait: `Wrapper<'static>`
5582
|
5683
note: type in trait
57-
--> $DIR/opaque-and-lifetime-mismatch.rs:5:17
84+
--> $DIR/opaque-and-lifetime-mismatch.rs:4:17
5885
|
5986
LL | fn bar() -> Wrapper<impl Sized>;
6087
| ^^^^^^^^^^^^^^^^^^^
6188
= note: expected signature `fn() -> Wrapper<'static>`
6289
found signature `fn() -> i32`
6390

64-
error: aborting due to 5 previous errors
91+
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
92+
--> $DIR/opaque-and-lifetime-mismatch.rs:24:17
93+
|
94+
LL | fn foo() -> Wrapper<impl Sized> {
95+
| ^^^^^^^ ---------- help: remove this generic argument
96+
| |
97+
| expected 0 generic arguments
98+
|
99+
note: struct defined here, with 0 generic parameters
100+
--> $DIR/opaque-and-lifetime-mismatch.rs:1:8
101+
|
102+
LL | struct Wrapper<'rom>(&'rom ());
103+
| ^^^^^^^
104+
105+
error: aborting due to 8 previous errors
65106

66-
Some errors have detailed explanations: E0053, E0106, E0107, E0412.
107+
Some errors have detailed explanations: E0053, E0106, E0107.
67108
For more information about an error, try `rustc --explain E0053`.

0 commit comments

Comments
 (0)