register opaques that reference errors

This commit is contained in:
Ali MJ Al-Nasrawy 2024-03-20 17:24:07 +00:00
parent 19e0ea4a6d
commit 0dc006b3a8
7 changed files with 44 additions and 29 deletions

View File

@ -94,9 +94,6 @@ pub fn handle_opaque_type(
cause: &ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> InferResult<'tcx, ()> {
if a.references_error() || b.references_error() {
return Ok(InferOk { value: (), obligations: vec![] });
}
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => {
let def_id = def_id.expect_local();

View File

@ -4,6 +4,7 @@
impl EntriesBuffer {
fn a(&self) -> impl Iterator {
self.0.iter_mut() //~ ERROR: cannot borrow `*self.0` as mutable, as it is behind a `&` reference
//~| ERROR captures lifetime that does not appear in bounds
}
}

View File

@ -1,5 +1,5 @@
error[E0425]: cannot find value `HashesEntryLEN` in this scope
--> $DIR/issue-109141.rs:10:32
--> $DIR/issue-109141.rs:11:32
|
LL | struct EntriesBuffer(Box<[[u8; HashesEntryLEN]; 5]>);
| ^^^^^^^^^^^^^^ not found in this scope
@ -20,7 +20,22 @@ help: consider changing this to be a mutable reference
LL | fn a(&mut self) -> impl Iterator {
| ~~~~~~~~~
error: aborting due to 2 previous errors
error[E0700]: hidden type for `impl Iterator` captures lifetime that does not appear in bounds
--> $DIR/issue-109141.rs:6:9
|
LL | fn a(&self) -> impl Iterator {
| ----- ------------- opaque type defined here
| |
| hidden type `std::slice::IterMut<'_, [u8; {const error}]>` captures the anonymous lifetime defined here
LL | self.0.iter_mut()
| ^^^^^^^^^^^^^^^^^
|
help: to declare that `impl Iterator` captures `'_`, you can add an explicit `'_` lifetime bound
|
LL | fn a(&self) -> impl Iterator + '_ {
| ++++
Some errors have detailed explanations: E0425, E0596.
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0425, E0596, E0700.
For more information about an error, try `rustc --explain E0425`.

View File

@ -31,6 +31,7 @@ fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
//~| ERROR implementation of `Bar` is not general enough
fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
//~^ 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
// This should resolve.
fn one_hrtb_mention_fn_trait_param_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Qux<'b>> {}
//~^ ERROR: the trait bound `for<'a> &'a (): Qux<'b>` is not satisfied
//~^ ERROR type annotations needed: cannot satisfy `for<'a> &'a (): Qux<'b>`
// This should resolve.
fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'b> {}

View File

@ -1,5 +1,5 @@
error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/nested-rpit-hrtb.rs:56:77
--> $DIR/nested-rpit-hrtb.rs:57:77
|
LL | fn two_htrb_outlives() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Sized + 'b> {}
| ^^ undeclared lifetime
@ -15,7 +15,7 @@ LL | fn two_htrb_outlives<'b>() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Siz
| ++++
error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/nested-rpit-hrtb.rs:64:82
--> $DIR/nested-rpit-hrtb.rs:65:82
|
LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
| ^^ undeclared lifetime
@ -65,29 +65,39 @@ note: lifetime declared here
LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
| ^^
error: implementation of `Bar` is not general enough
--> $DIR/nested-rpit-hrtb.rs:32:78
|
LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
| ^^ implementation of `Bar` is not general enough
|
= note: `()` must implement `Bar<'a>`
= note: ...but it actually implements `Bar<'0>`, for some specific lifetime `'0`
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
--> $DIR/nested-rpit-hrtb.rs:35:73
--> $DIR/nested-rpit-hrtb.rs:36:73
|
LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
| ^^
|
note: lifetime declared here
--> $DIR/nested-rpit-hrtb.rs:35:44
--> $DIR/nested-rpit-hrtb.rs:36:44
|
LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
| ^^
error[E0277]: the trait bound `for<'a> &'a (): Qux<'b>` is not satisfied
--> $DIR/nested-rpit-hrtb.rs:45:79
error[E0283]: type annotations needed: cannot satisfy `for<'a> &'a (): Qux<'b>`
--> $DIR/nested-rpit-hrtb.rs:46:79
|
LL | fn one_hrtb_mention_fn_trait_param_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Qux<'b>> {}
| ^^^^^^^^^^^^ the trait `for<'a> Qux<'b>` is not implemented for `&'a ()`
| ^^^^^^^^^^^^
|
= note: cannot satisfy `for<'a> &'a (): Qux<'b>`
= help: the trait `Qux<'_>` is implemented for `()`
= help: for that trait implementation, expected `()`, found `&'a ()`
error: implementation of `Bar` is not general enough
--> $DIR/nested-rpit-hrtb.rs:49:93
--> $DIR/nested-rpit-hrtb.rs:50:93
|
LL | fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'b> {}
| ^^ 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 =
= note: ...but it actually implements `Bar<'0>`, for some specific lifetime `'0`
error[E0277]: the trait bound `for<'a, 'b> &'a (): Qux<'b>` is not satisfied
--> $DIR/nested-rpit-hrtb.rs:60:64
--> $DIR/nested-rpit-hrtb.rs:61:64
|
LL | fn two_htrb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Qux<'b>> {}
| ^^^^^^^^^^^^^^^^^^^^ the trait `for<'a, 'b> Qux<'b>` is not implemented for `&'a ()`
@ -105,7 +115,7 @@ LL | fn two_htrb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b>
= help: for that trait implementation, expected `()`, found `&'a ()`
error: implementation of `Bar` is not general enough
--> $DIR/nested-rpit-hrtb.rs:64:86
--> $DIR/nested-rpit-hrtb.rs:65:86
|
LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
| ^^ implementation of `Bar` is not general enough
@ -113,7 +123,7 @@ LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Si
= note: `()` must implement `Bar<'a>`
= note: ...but it actually implements `Bar<'0>`, for some specific lifetime `'0`
error: aborting due to 10 previous errors
error: aborting due to 11 previous errors
Some errors have detailed explanations: E0261, E0277, E0657.
Some errors have detailed explanations: E0261, E0277, E0283, E0657.
For more information about an error, try `rustc --explain E0261`.

View File

@ -8,7 +8,6 @@ trait Test<'a> {}
pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
//~| ERROR unconstrained opaque type
impl Trait<'_> for () {
type Assoc = ();

View File

@ -10,14 +10,6 @@ note: lifetime declared here
LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
| ^^
error: unconstrained opaque type
--> $DIR/escaping-bound-var.rs:9:47
|
LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
| ^^^^^^^^^^^^^
|
= note: `Foo` must be used in combination with a concrete type within the same module
error: aborting due to 2 previous errors
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0657`.