Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ICE in printing RPITIT type #102597

Merged
merged 1 commit into from
Oct 3, 2022
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
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ pub trait PrettyPrinter<'tcx>:
// unless we can find out what generator return type it comes from.
let term = if let Some(ty) = term.skip_binder().ty()
&& let ty::Projection(proj) = ty.kind()
&& let assoc = tcx.associated_item(proj.item_def_id)
&& let Some(assoc) = tcx.opt_associated_item(proj.item_def_id)
&& assoc.trait_container(tcx) == tcx.lang_items().gen_trait()
&& assoc.name == rustc_span::sym::Return
{
Expand Down
24 changes: 24 additions & 0 deletions src/test/ui/impl-trait/in-trait/issue-102571.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![feature(return_position_impl_trait_in_trait)]
#![allow(incomplete_features)]

use std::fmt::Display;
use std::ops::Deref;

trait Foo {
fn bar(self) -> impl Deref<Target = impl Display + ?Sized>;
}

struct A;

impl Foo for A {
fn bar(self) -> &'static str {
"Hello, world"
}
}

fn foo<T: Foo>(t: T) {
let () = t.bar();
//~^ ERROR mismatched types
}

fn main() {}
14 changes: 14 additions & 0 deletions src/test/ui/impl-trait/in-trait/issue-102571.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0308]: mismatched types
--> $DIR/issue-102571.rs:20:9
|
LL | let () = t.bar();
| ^^ ------- this expression has type `impl Deref<Target = impl std::fmt::Display + ?Sized>`
| |
| expected associated type, found `()`
|
= note: expected associated type `impl Deref<Target = impl std::fmt::Display + ?Sized>`
found unit type `()`

error: aborting due to previous error

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