Skip to content

Commit 587e8fd

Browse files
committed
Loop over all opaque types instead of looking at just the first one with the same DefId
1 parent 95f296d commit 587e8fd

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

compiler/rustc_typeck/src/collect/type_of.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -542,13 +542,14 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
542542
}
543543
// Use borrowck to get the type with unerased regions.
544544
let concrete_opaque_types = &self.tcx.mir_borrowck(def_id).concrete_opaque_types;
545-
if let Some((opaque_type_key, concrete_type)) =
546-
concrete_opaque_types.iter().find(|(key, _)| key.def_id == self.def_id)
547-
{
548-
debug!(
549-
"find_opaque_ty_constraints: found constraint for `{:?}` at `{:?}`: {:?}",
550-
self.def_id, def_id, concrete_type,
551-
);
545+
debug!(?concrete_opaque_types);
546+
for (opaque_type_key, concrete_type) in concrete_opaque_types {
547+
if opaque_type_key.def_id != self.def_id {
548+
// Ignore constraints for other opaque types.
549+
continue;
550+
}
551+
552+
debug!(?concrete_type, ?opaque_type_key.substs, "found constraint");
552553

553554
// FIXME(oli-obk): trace the actual span from inference to improve errors.
554555
let span = self.tcx.def_span(def_id);
@@ -613,11 +614,6 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
613614
} else {
614615
self.found = Some((span, concrete_type));
615616
}
616-
} else {
617-
debug!(
618-
"find_opaque_ty_constraints: no constraint for `{:?}` at `{:?}`",
619-
self.def_id, def_id,
620-
);
621617
}
622618
}
623619
}

src/test/ui/type-alias-impl-trait/issue-85113.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ trait Output<'a> {}
1212
impl<'a> Output<'a> for &'a str {}
1313

1414
fn cool_fn<'a>(arg: &'a str) -> OpaqueOutputImpl<'a> {
15+
//~^ ERROR: concrete type differs from previous defining opaque type use
1516
let out: OpaqueOutputImpl<'a> = arg;
1617
arg
1718
}

src/test/ui/type-alias-impl-trait/issue-85113.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ note: hidden type `&'<empty> str` captures lifetime smaller than the function bo
1010
LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

13+
error: concrete type differs from previous defining opaque type use
14+
--> $DIR/issue-85113.rs:14:1
15+
|
16+
LL | fn cool_fn<'a>(arg: &'a str) -> OpaqueOutputImpl<'a> {
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&'<empty> str`, got `&'a str`
18+
|
19+
note: previous use here
20+
--> $DIR/issue-85113.rs:14:1
21+
|
22+
LL | fn cool_fn<'a>(arg: &'a str) -> OpaqueOutputImpl<'a> {
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
1325
error[E0477]: the type `&'<empty> str` does not fulfill the required lifetime
1426
--> $DIR/issue-85113.rs:5:29
1527
|
@@ -42,7 +54,7 @@ LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
4254
= note: expected `Output<'a>`
4355
found `Output<'_>`
4456

45-
error: aborting due to 3 previous errors
57+
error: aborting due to 4 previous errors
4658

4759
Some errors have detailed explanations: E0477, E0495, E0700.
4860
For more information about an error, try `rustc --explain E0477`.

0 commit comments

Comments
 (0)