Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,21 @@ impl<T> Trait<T> for X {
values.found, values.expected,
)
};
if !(self.suggest_constraining_opaque_associated_type(
diag,
msg,
proj_ty,
values.expected,
) || self.suggest_constraint(
diag,
&msg,
body_owner_def_id,
proj_ty,
values.expected,
)) {
let suggested_projection_constraint = proj_ty.kind(tcx)
== ty::AliasTyKind::Projection
&& (self.suggest_constraining_opaque_associated_type(
diag,
msg,
proj_ty,
values.expected,
) || self.suggest_constraint(
diag,
&msg,
body_owner_def_id,
proj_ty,
values.expected,
));
if !suggested_projection_constraint {
diag.help(msg());
diag.note(
"for more information, visit \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ compile-flags: -Znext-solver=globally
#![feature(inherent_associated_types)]
#![expect(incomplete_features)]

// Regression test for https://github.com/rust-lang/rust/issues/153539:

struct S<'a>(&'a ());

impl<X> S<'_> {
//~^ ERROR the type parameter `X` is not constrained by the impl trait, self type, or predicates
type P = ();
}

fn ret_ref_local<'e>() -> &'e i32 {
let f: for<'a> fn(&'a i32) -> S<'a>::P = |x| _ = x;

f(&1)
//~^ ERROR mismatched types
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0207]: the type parameter `X` is not constrained by the impl trait, self type, or predicates
--> $DIR/inherent-assoc-ty-mismatch-issue-153539.rs:9:6
|
LL | impl<X> S<'_> {
| ^ unconstrained type parameter

error[E0308]: mismatched types
--> $DIR/inherent-assoc-ty-mismatch-issue-153539.rs:17:5
|
LL | fn ret_ref_local<'e>() -> &'e i32 {
| ------- expected `&'e i32` because of return type
...
LL | f(&1)
| ^^^^^ expected `&i32`, found associated type
|
= help: consider constraining the associated type `S<'_>::P` to `&'e i32`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0207, E0308.
For more information about an error, try `rustc --explain E0207`.
Loading