Skip to content

Commit 8ee6812

Browse files
committed
Remove delay_as_bug for fn call with unsized Self that return Self.
1 parent d8f5b14 commit 8ee6812

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use rustc_middle::ty::{
4848
use rustc_middle::{bug, span_bug};
4949
use rustc_session::Limit;
5050
use rustc_span::def_id::LOCAL_CRATE;
51-
use rustc_span::symbol::{kw, sym};
51+
use rustc_span::symbol::sym;
5252
use rustc_span::{BytePos, ExpnKind, Span, Symbol, DUMMY_SP};
5353
use std::borrow::Cow;
5454
use std::fmt;
@@ -638,28 +638,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
638638
err.span_label(span, explanation);
639639
}
640640

641-
if Some(trait_ref.def_id()) == self.tcx.lang_items().sized_trait()
642-
&& let ObligationCauseCode::SizedCallReturnType(did)
643-
= obligation.cause.code()
644-
{
645-
let fn_sig = self.tcx.fn_sig(did);
646-
let ret_kind =
647-
fn_sig.skip_binder().output().skip_binder().kind();
648-
if let ty::Param(param_ty) = ret_kind
649-
&& param_ty.name == kw::SelfUpper
650-
{
651-
// We expect the return type of an fn call is expected to be
652-
// `Sized`. In the test `trait-missing-dyn-in-qualified-path.rs`
653-
// under edition 2018, when writing `<Default>::default()`, we will
654-
// check both `dyn Default` and `<dyn Default>::default()` for
655-
// being `Sized`, but in every case where an associated function
656-
// like `Default::default` which returns `Self`, if the returned
657-
// value is `!Sized`, so will be the `Self`, so we'd always have
658-
// two redundat errors.
659-
return err.delay_as_bug();
660-
}
661-
}
662-
663641
if let ObligationCauseCode::Coercion { source, target, .. } =
664642
*obligation.cause.code().peel_derives()
665643
{

tests/ui/dyn-keyword/trait-missing-dyn-in-qualified-path.edition2018.stderr

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,16 @@ LL | let x: u32 = <Default>::default();
6868
= note: the trait cannot be made into an object because it requires `Self: Sized`
6969
= note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
7070

71-
error: aborting due to 4 previous errors; 1 warning emitted
71+
error[E0277]: the size for values of type `dyn Default` cannot be known at compilation time
72+
--> $DIR/trait-missing-dyn-in-qualified-path.rs:5:18
73+
|
74+
LL | let x: u32 = <Default>::default();
75+
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
76+
|
77+
= help: the trait `Sized` is not implemented for `dyn Default`
78+
= note: the return type of a function must have a statically known size
79+
80+
error: aborting due to 5 previous errors; 1 warning emitted
7281

7382
Some errors have detailed explanations: E0038, E0277, E0308.
7483
For more information about an error, try `rustc --explain E0038`.

tests/ui/dyn-keyword/trait-missing-dyn-in-qualified-path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fn main() {
88
//[edition2018]~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
99
//[edition2018]~| ERROR trait `Default` cannot be made into an object
1010
//[edition2018]~| ERROR trait `Default` cannot be made into an object
11+
//[edition2018]~| ERROR the size for values of type `dyn Default` cannot be known at compilation time
1112
//[edition2018]~| ERROR mismatched types
1213
//[edition2018]~| ERROR the size for values of type `dyn Default` cannot be known at compilation time
1314
}

0 commit comments

Comments
 (0)