Skip to content

Commit 0dc006b

Browse files
committed
register opaques that reference errors
1 parent 19e0ea4 commit 0dc006b

File tree

7 files changed

+44
-29
lines changed

7 files changed

+44
-29
lines changed

compiler/rustc_infer/src/infer/opaque_types/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ impl<'tcx> InferCtxt<'tcx> {
9494
cause: &ObligationCause<'tcx>,
9595
param_env: ty::ParamEnv<'tcx>,
9696
) -> InferResult<'tcx, ()> {
97-
if a.references_error() || b.references_error() {
98-
return Ok(InferOk { value: (), obligations: vec![] });
99-
}
10097
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
10198
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => {
10299
let def_id = def_id.expect_local();

tests/ui/const-generics/generic_const_exprs/issue-109141.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
impl EntriesBuffer {
55
fn a(&self) -> impl Iterator {
66
self.0.iter_mut() //~ ERROR: cannot borrow `*self.0` as mutable, as it is behind a `&` reference
7+
//~| ERROR captures lifetime that does not appear in bounds
78
}
89
}
910

tests/ui/const-generics/generic_const_exprs/issue-109141.stderr

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0425]: cannot find value `HashesEntryLEN` in this scope
2-
--> $DIR/issue-109141.rs:10:32
2+
--> $DIR/issue-109141.rs:11:32
33
|
44
LL | struct EntriesBuffer(Box<[[u8; HashesEntryLEN]; 5]>);
55
| ^^^^^^^^^^^^^^ not found in this scope
@@ -20,7 +20,22 @@ help: consider changing this to be a mutable reference
2020
LL | fn a(&mut self) -> impl Iterator {
2121
| ~~~~~~~~~
2222

23-
error: aborting due to 2 previous errors
23+
error[E0700]: hidden type for `impl Iterator` captures lifetime that does not appear in bounds
24+
--> $DIR/issue-109141.rs:6:9
25+
|
26+
LL | fn a(&self) -> impl Iterator {
27+
| ----- ------------- opaque type defined here
28+
| |
29+
| hidden type `std::slice::IterMut<'_, [u8; {const error}]>` captures the anonymous lifetime defined here
30+
LL | self.0.iter_mut()
31+
| ^^^^^^^^^^^^^^^^^
32+
|
33+
help: to declare that `impl Iterator` captures `'_`, you can add an explicit `'_` lifetime bound
34+
|
35+
LL | fn a(&self) -> impl Iterator + '_ {
36+
| ++++
37+
38+
error: aborting due to 3 previous errors
2439

25-
Some errors have detailed explanations: E0425, E0596.
40+
Some errors have detailed explanations: E0425, E0596, E0700.
2641
For more information about an error, try `rustc --explain E0425`.

tests/ui/impl-trait/nested-rpit-hrtb.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
3131

3232
fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
3333
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
34+
//~| ERROR implementation of `Bar` is not general enough
3435

3536
fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
3637
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
@@ -43,7 +44,7 @@ fn one_hrtb_mention_fn_outlives<'b>() -> impl for<'a> Foo<'a, Assoc = impl Sized
4344

4445
// This should resolve.
4546
fn one_hrtb_mention_fn_trait_param_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Qux<'b>> {}
46-
//~^ ERROR: the trait bound `for<'a> &'a (): Qux<'b>` is not satisfied
47+
//~^ ERROR type annotations needed: cannot satisfy `for<'a> &'a (): Qux<'b>`
4748

4849
// This should resolve.
4950
fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'b> {}

tests/ui/impl-trait/nested-rpit-hrtb.stderr

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0261]: use of undeclared lifetime name `'b`
2-
--> $DIR/nested-rpit-hrtb.rs:56:77
2+
--> $DIR/nested-rpit-hrtb.rs:57:77
33
|
44
LL | fn two_htrb_outlives() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Sized + 'b> {}
55
| ^^ undeclared lifetime
@@ -15,7 +15,7 @@ LL | fn two_htrb_outlives<'b>() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Siz
1515
| ++++
1616

1717
error[E0261]: use of undeclared lifetime name `'b`
18-
--> $DIR/nested-rpit-hrtb.rs:64:82
18+
--> $DIR/nested-rpit-hrtb.rs:65:82
1919
|
2020
LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
2121
| ^^ undeclared lifetime
@@ -65,29 +65,39 @@ note: lifetime declared here
6565
LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
6666
| ^^
6767

68+
error: implementation of `Bar` is not general enough
69+
--> $DIR/nested-rpit-hrtb.rs:32:78
70+
|
71+
LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
72+
| ^^ implementation of `Bar` is not general enough
73+
|
74+
= note: `()` must implement `Bar<'a>`
75+
= note: ...but it actually implements `Bar<'0>`, for some specific lifetime `'0`
76+
6877
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
69-
--> $DIR/nested-rpit-hrtb.rs:35:73
78+
--> $DIR/nested-rpit-hrtb.rs:36:73
7079
|
7180
LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
7281
| ^^
7382
|
7483
note: lifetime declared here
75-
--> $DIR/nested-rpit-hrtb.rs:35:44
84+
--> $DIR/nested-rpit-hrtb.rs:36:44
7685
|
7786
LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
7887
| ^^
7988

80-
error[E0277]: the trait bound `for<'a> &'a (): Qux<'b>` is not satisfied
81-
--> $DIR/nested-rpit-hrtb.rs:45:79
89+
error[E0283]: type annotations needed: cannot satisfy `for<'a> &'a (): Qux<'b>`
90+
--> $DIR/nested-rpit-hrtb.rs:46:79
8291
|
8392
LL | fn one_hrtb_mention_fn_trait_param_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Qux<'b>> {}
84-
| ^^^^^^^^^^^^ the trait `for<'a> Qux<'b>` is not implemented for `&'a ()`
93+
| ^^^^^^^^^^^^
8594
|
95+
= note: cannot satisfy `for<'a> &'a (): Qux<'b>`
8696
= help: the trait `Qux<'_>` is implemented for `()`
8797
= help: for that trait implementation, expected `()`, found `&'a ()`
8898

8999
error: implementation of `Bar` is not general enough
90-
--> $DIR/nested-rpit-hrtb.rs:49:93
100+
--> $DIR/nested-rpit-hrtb.rs:50:93
91101
|
92102
LL | fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'b> {}
93103
| ^^ implementation of `Bar` is not general enough
@@ -96,7 +106,7 @@ LL | fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc =
96106
= note: ...but it actually implements `Bar<'0>`, for some specific lifetime `'0`
97107

98108
error[E0277]: the trait bound `for<'a, 'b> &'a (): Qux<'b>` is not satisfied
99-
--> $DIR/nested-rpit-hrtb.rs:60:64
109+
--> $DIR/nested-rpit-hrtb.rs:61:64
100110
|
101111
LL | fn two_htrb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Qux<'b>> {}
102112
| ^^^^^^^^^^^^^^^^^^^^ the trait `for<'a, 'b> Qux<'b>` is not implemented for `&'a ()`
@@ -105,15 +115,15 @@ LL | fn two_htrb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b>
105115
= help: for that trait implementation, expected `()`, found `&'a ()`
106116

107117
error: implementation of `Bar` is not general enough
108-
--> $DIR/nested-rpit-hrtb.rs:64:86
118+
--> $DIR/nested-rpit-hrtb.rs:65:86
109119
|
110120
LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
111121
| ^^ implementation of `Bar` is not general enough
112122
|
113123
= note: `()` must implement `Bar<'a>`
114124
= note: ...but it actually implements `Bar<'0>`, for some specific lifetime `'0`
115125

116-
error: aborting due to 10 previous errors
126+
error: aborting due to 11 previous errors
117127

118-
Some errors have detailed explanations: E0261, E0277, E0657.
128+
Some errors have detailed explanations: E0261, E0277, E0283, E0657.
119129
For more information about an error, try `rustc --explain E0261`.

tests/ui/type-alias-impl-trait/escaping-bound-var.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ trait Test<'a> {}
88

99
pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
1010
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
11-
//~| ERROR unconstrained opaque type
1211

1312
impl Trait<'_> for () {
1413
type Assoc = ();

tests/ui/type-alias-impl-trait/escaping-bound-var.stderr

+1-9
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ note: lifetime declared here
1010
LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
1111
| ^^
1212

13-
error: unconstrained opaque type
14-
--> $DIR/escaping-bound-var.rs:9:47
15-
|
16-
LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
17-
| ^^^^^^^^^^^^^
18-
|
19-
= note: `Foo` must be used in combination with a concrete type within the same module
20-
21-
error: aborting due to 2 previous errors
13+
error: aborting due to 1 previous error
2214

2315
For more information about this error, try `rustc --explain E0657`.

0 commit comments

Comments
 (0)