Skip to content

Commit

Permalink
Fix ICE in default impl error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Nov 1, 2022
1 parent 32dae91 commit 0f632c8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ impl<'tcx> TyCtxt<'tcx> {
(ty::Projection(_), ty::Projection(_)) => {
diag.note("an associated type was expected, but a different one was found");
}
(ty::Param(p), ty::Projection(proj)) | (ty::Projection(proj), ty::Param(p)) => {
(ty::Param(p), ty::Projection(proj)) | (ty::Projection(proj), ty::Param(p))
if self.def_kind(proj.item_def_id) != DefKind::ImplTraitPlaceholder =>
{
let generics = self.generics_of(body_owner_def_id);
let p_span = self.def_span(generics.type_param(p, self).def_id);
if !sp.contains(p_span) {
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/impl-trait/in-trait/specialization-broken.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// FIXME(compiler-errors): I'm not exactly sure if this is expected to pass or not.
// But we fixed an ICE anyways.

#![feature(specialization)]
#![feature(return_position_impl_trait_in_trait)]
#![allow(incomplete_features)]

trait Foo {
fn bar(&self) -> impl Sized;
}

default impl<U> Foo for U
where
U: Copy,
{
fn bar(&self) -> U {
//~^ ERROR method `bar` has an incompatible type for trait
*self
}
}

impl Foo for i32 {}

fn main() {
1i32.bar();
}
23 changes: 23 additions & 0 deletions src/test/ui/impl-trait/in-trait/specialization-broken.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0053]: method `bar` has an incompatible type for trait
--> $DIR/specialization-broken.rs:16:22
|
LL | default impl<U> Foo for U
| - this type parameter
...
LL | fn bar(&self) -> U {
| ^
| |
| expected associated type, found type parameter `U`
| help: change the output type to match the trait: `impl Sized`
|
note: type in trait
--> $DIR/specialization-broken.rs:9:22
|
LL | fn bar(&self) -> impl Sized;
| ^^^^^^^^^^
= note: expected fn pointer `fn(&U) -> impl Sized`
found fn pointer `fn(&U) -> U`

error: aborting due to previous error

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

0 comments on commit 0f632c8

Please sign in to comment.