Skip to content

Commit

Permalink
register opaques that reference errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemjay committed Mar 20, 2024
1 parent f3d0ef0 commit d42e39f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 29 deletions.
3 changes: 0 additions & 3 deletions compiler/rustc_infer/src/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ impl<'tcx> InferCtxt<'tcx> {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
21 changes: 18 additions & 3 deletions tests/ui/const-generics/generic_const_exprs/issue-109141.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 + '_ {
| ++++

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0425, E0596.
Some errors have detailed explanations: E0425, E0596, E0700.
For more information about an error, try `rustc --explain E0425`.
3 changes: 2 additions & 1 deletion tests/ui/impl-trait/nested-rpit-hrtb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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> {}
Expand Down
34 changes: 22 additions & 12 deletions tests/ui/impl-trait/nested-rpit-hrtb.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 ()`
Expand All @@ -105,15 +115,15 @@ 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
|
= 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`.
1 change: 0 additions & 1 deletion tests/ui/type-alias-impl-trait/escaping-bound-var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ();
Expand Down
10 changes: 1 addition & 9 deletions tests/ui/type-alias-impl-trait/escaping-bound-var.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

0 comments on commit d42e39f

Please sign in to comment.