Skip to content

Commit

Permalink
Remove incorrect delay_span_bug
Browse files Browse the repository at this point in the history
The following code is supposed to compile

```rust
use std::ops::BitOr;

pub trait IntWrapper {
    type InternalStorage;
}

impl<T> BitOr for dyn IntWrapper<InternalStorage = T>
where
    Self: Sized,
    T: BitOr + BitOr<Output = T>,
{
    type Output = Self;
    fn bitor(self, _other: Self) -> Self {
        todo!()
    }
}
```

Before this change it would ICE. In #70998 the removed logic was added
to provide better suggestions, and the `delay_span_bug` guard was added
to  protect against a potential logic error when returning traits. As it
happens, there are cases, like the one above, where traits can indeed be
returned, so valid code was being rejected.

Fix #80207.
  • Loading branch information
estebank committed Feb 3, 2021
1 parent b81f581 commit ede0a71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 0 additions & 1 deletion compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ pub(super) fn check_fn<'a, 'tcx>(
// possible cases.
fcx.check_expr(&body.value);
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
tcx.sess.delay_span_bug(decl.output.span(), "`!Sized` return type");
} else {
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
fcx.check_return_expr(&body.value);
Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/typeck/issue-80207-unsized-return.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// check-pass

trait Foo {
fn do_stuff() -> Self;
}

trait Bar {
type Output;
}

impl<T> Foo for dyn Bar<Output = T>
where
Self: Sized,
{
fn do_stuff() -> Self {
todo!()
}
}

fn main() {}

0 comments on commit ede0a71

Please sign in to comment.