From c6e946093316217b57b8d69a6982af873aa0bd48 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 12 Mar 2025 19:33:27 +0000 Subject: [PATCH 1/2] Don't emit error within cast function, propagate it as a CastError --- compiler/rustc_hir_typeck/src/cast.rs | 33 +++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 70b49fea34f1c..5270c8ed3566f 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -32,6 +32,7 @@ use rustc_ast::util::parser::ExprPrecedence; use rustc_data_structures::fx::FxHashSet; use rustc_errors::codes::*; use rustc_errors::{Applicability, Diag, ErrorGuaranteed}; +use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, ExprKind}; use rustc_infer::infer::DefineOpaqueTypes; use rustc_macros::{TypeFoldable, TypeVisitable}; @@ -155,7 +156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } -#[derive(Copy, Clone, Debug)] +#[derive(Debug)] enum CastError<'tcx> { ErrorGuaranteed(ErrorGuaranteed), @@ -182,6 +183,7 @@ enum CastError<'tcx> { /// when we're typechecking a type parameter with a ?Sized bound. IntToWideCast(Option<&'static str>), ForeignNonExhaustiveAdt, + PtrPtrAddingAutoTrait(Vec), } impl From for CastError<'_> { @@ -596,6 +598,21 @@ impl<'a, 'tcx> CastCheck<'tcx> { .with_note("cannot cast an enum with a non-exhaustive variant when it's defined in another crate") .emit(); } + CastError::PtrPtrAddingAutoTrait(added) => { + fcx.dcx().emit_err(errors::PtrCastAddAutoToObject { + span: self.span, + traits_len: added.len(), + traits: { + let mut traits: Vec<_> = added + .into_iter() + .map(|trait_did| fcx.tcx.def_path_str(trait_did)) + .collect(); + + traits.sort(); + traits.into() + }, + }); + } } } @@ -940,19 +957,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { .collect::>(); if !added.is_empty() { - tcx.dcx().emit_err(errors::PtrCastAddAutoToObject { - span: self.span, - traits_len: added.len(), - traits: { - let mut traits: Vec<_> = added - .into_iter() - .map(|trait_did| tcx.def_path_str(trait_did)) - .collect(); - - traits.sort(); - traits.into() - }, - }); + return Err(CastError::PtrPtrAddingAutoTrait(added)); } Ok(CastKind::PtrPtrCast) From 655100801e213968c9b8faa3f57b94cd9343f461 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 13 Mar 2025 01:05:00 +0000 Subject: [PATCH 2/2] Delay coercion error --- compiler/rustc_hir_typeck/src/cast.rs | 24 ++++ compiler/rustc_hir_typeck/src/coercion.rs | 122 +++++++++--------- compiler/rustc_hir_typeck/src/demand.rs | 6 + .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 24 ++++ .../src/traits/select/confirmation.rs | 9 ++ ...block-control-flow-static-semantics.stderr | 22 ++-- tests/ui/cross/cross-borrow-trait.stderr | 4 + tests/ui/custom_test_frameworks/mismatch.rs | 2 + .../ui/custom_test_frameworks/mismatch.stderr | 17 ++- tests/ui/dst/dst-object-from-unsized-type.rs | 1 + .../dst/dst-object-from-unsized-type.stderr | 18 ++- .../trait-bounds/span-bug-issue-121597.rs | 1 - .../trait-bounds/span-bug-issue-121597.stderr | 21 +-- .../impl-trait/unsized_coercion2.old.stderr | 12 -- tests/ui/impl-trait/unsized_coercion2.rs | 3 +- .../impl-trait/unsized_coercion3.next.stderr | 2 +- .../impl-trait/unsized_coercion3.old.stderr | 19 ++- tests/ui/impl-trait/unsized_coercion3.rs | 3 +- tests/ui/issues/issue-19380.rs | 1 + tests/ui/issues/issue-19380.stderr | 14 +- tests/ui/issues/issue-40000.stderr | 16 +-- tests/ui/issues/issue-50781.stderr | 10 +- tests/ui/lub-glb/old-lub-glb-object.stderr | 8 +- tests/ui/mismatched_types/cast-rfc0401.rs | 4 +- tests/ui/mismatched_types/cast-rfc0401.stderr | 36 +++--- tests/ui/nll/issue-57843.rs | 2 +- tests/ui/nll/issue-57843.stderr | 17 ++- tests/ui/rfcs/rfc-1623-static/rfc1623-2.rs | 5 +- .../ui/rfcs/rfc-1623-static/rfc1623-2.stderr | 38 +----- .../missing-bound-in-derive-copy-impl-2.fixed | 3 +- .../missing-bound-in-derive-copy-impl-2.rs | 1 + ...missing-bound-in-derive-copy-impl-2.stderr | 27 +++- .../missing-bound-in-derive-copy-impl.rs | 1 + .../missing-bound-in-derive-copy-impl.stderr | 27 +++- .../supertrait-dyn-compatibility.rs | 1 - .../supertrait-dyn-compatibility.stderr | 18 +-- .../higher-ranked-upcasting-ub.current.stderr | 20 +-- .../higher-ranked-upcasting-ub.rs | 1 - 38 files changed, 322 insertions(+), 238 deletions(-) delete mode 100644 tests/ui/impl-trait/unsized_coercion2.old.stderr diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 5270c8ed3566f..2cd09091f69c5 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -353,6 +353,14 @@ impl<'a, 'tcx> CastCheck<'tcx> { PointerKind::Thin, ) | (PointerKind::Length, PointerKind::Length) => { + if let Some(_guar) = fcx.emit_specialized_coerce_unsize_error( + self.expr.span, + self.expr_ty, + self.cast_ty, + ) { + return; + } + span_bug!(self.span, "unexpected cast error: {e:?}") } } @@ -401,6 +409,14 @@ impl<'a, 'tcx> CastCheck<'tcx> { err.emit(); } CastError::NonScalar => { + if let Some(_guar) = fcx.emit_specialized_coerce_unsize_error( + self.expr.span, + self.expr_ty, + self.cast_ty, + ) { + return; + } + let mut err = type_error_struct!( fcx.dcx(), self.span, @@ -550,6 +566,14 @@ impl<'a, 'tcx> CastCheck<'tcx> { err.emit(); } CastError::SizedUnsizedCast => { + if let Some(_guar) = fcx.emit_specialized_coerce_unsize_error( + self.expr.span, + self.expr_ty, + self.cast_ty, + ) { + return; + } + let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty); let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty); fcx.dcx().emit_err(errors::CastThinPointerToWidePointer { diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index d7b5c1ed5e15b..fcf4e91f726f7 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -48,7 +48,7 @@ use rustc_infer::infer::relate::RelateResult; use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult}; use rustc_infer::traits::{ IfExpressionCause, MatchExpressionArmCause, Obligation, PredicateObligation, - PredicateObligations, + PredicateObligations, SelectionError, }; use rustc_middle::span_bug; use rustc_middle::ty::adjustment::{ @@ -56,12 +56,12 @@ use rustc_middle::ty::adjustment::{ }; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::visit::TypeVisitableExt; -use rustc_middle::ty::{self, AliasTy, GenericArgsRef, Ty, TyCtxt}; -use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Span}; +use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt}; +use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, ErrorGuaranteed, Span}; use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; use rustc_trait_selection::traits::{ - self, NormalizeExt, ObligationCause, ObligationCauseCode, ObligationCtxt, + self, FulfillmentErrorCode, NormalizeExt, ObligationCause, ObligationCauseCode, ObligationCtxt, }; use smallvec::{SmallVec, smallvec}; use tracing::{debug, instrument}; @@ -600,55 +600,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { ty::TraitRef::new(self.tcx, coerce_unsized_did, [coerce_source, coerce_target]), ); - // If the root `Source: CoerceUnsized` obligation can't possibly hold, - // we don't have to assume that this is unsizing coercion (it will always lead to an error) - // - // However, we don't want to bail early all the time, since the unholdable obligations - // may be interesting for diagnostics (such as trying to coerce `&T` to `&dyn Id`), - // so we only bail if there (likely) is another way to convert the types. if !self.infcx.predicate_may_hold(&root_obligation) { - if let Some(dyn_metadata_adt_def_id) = self.tcx.lang_items().get(LangItem::DynMetadata) - && let Some(metadata_type_def_id) = self.tcx.lang_items().get(LangItem::Metadata) - { - self.probe(|_| { - let ocx = ObligationCtxt::new(&self.infcx); - - // returns `true` if `::Metadata` is `DynMetadata<_>` - let has_dyn_trait_metadata = |ty| { - let metadata_ty: Result<_, _> = ocx.structurally_normalize_ty( - &ObligationCause::dummy(), - self.fcx.param_env, - Ty::new_alias( - self.tcx, - ty::AliasTyKind::Projection, - AliasTy::new(self.tcx, metadata_type_def_id, [ty]), - ), - ); - - metadata_ty.is_ok_and(|metadata_ty| { - metadata_ty - .ty_adt_def() - .is_some_and(|d| d.did() == dyn_metadata_adt_def_id) - }) - }; - - // If both types are raw pointers to a (wrapper over a) trait object, - // this might be a cast like `*const W -> *const dyn Trait`. - // So it's better to bail and try that. (even if the cast is not possible, for - // example due to vtables not matching, cast diagnostic will likely still be better) - // - // N.B. use `target`, not `coerce_target` (the latter is a var) - if let &ty::RawPtr(source_pointee, _) = coerce_source.kind() - && let &ty::RawPtr(target_pointee, _) = target.kind() - && has_dyn_trait_metadata(source_pointee) - && has_dyn_trait_metadata(target_pointee) - { - return Err(TypeError::Mismatch); - } - - Ok(()) - })?; - } + return Err(TypeError::Mismatch); } // Use a FIFO queue for this custom fulfillment procedure. @@ -725,17 +678,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { return Err(TypeError::Mismatch); } - // Dyn-compatibility violations or miscellaneous. + // Should have been filtered out by the `predicate_may_hold` check. Err(err) => { - let guar = self.err_ctxt().report_selection_error( - obligation.clone(), - &obligation, - &err, - ); - self.fcx.set_tainted_by_errors(guar); - // Treat this like an obligation and follow through - // with the unsizing - the lack of a coercion should - // be silent, as it causes a type mismatch later. + debug!("coerce_unsized: early return - selection error: {err:?}"); + return Err(TypeError::Mismatch); } Ok(Some(impl_source)) => queue.extend(impl_source.nested_obligations()), @@ -1120,6 +1066,50 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }) } + pub(crate) fn emit_specialized_coerce_unsize_error( + &self, + span: Span, + source: Ty<'tcx>, + target: Ty<'tcx>, + ) -> Option { + let ocx = ObligationCtxt::new_with_diagnostics(self); + let coerce_unsized_def_id = self.tcx.require_lang_item(LangItem::CoerceUnsized, Some(span)); + let unsize_def_id = self.tcx.require_lang_item(LangItem::Unsize, Some(span)); + ocx.register_obligation(Obligation::new( + self.tcx, + self.cause(span, ObligationCauseCode::Coercion { source, target }), + self.param_env, + ty::TraitRef::new(self.tcx, coerce_unsized_def_id, [source, target]), + )); + + let mut errors = ocx.select_where_possible(); + // Retain the errors that don't mention, but also as a HACK we will adjust their + // root obligation, too. This is a nasty hack to preserve diagnostic parity that + // should probably be fixed by emitting better errors for failed `CoerceUnsized`. + errors.retain_mut(|err| { + if matches!( + err.code, + FulfillmentErrorCode::Select(SelectionError::TraitDynIncompatible(_)), + ) || err.obligation.predicate.as_trait_clause().is_none_or(|trait_clause| { + trait_clause.def_id() != coerce_unsized_def_id + && trait_clause.def_id() != unsize_def_id + }) { + err.root_obligation = err.obligation.clone(); + true + } else { + false + } + }); + + if errors.is_empty() { + None + } else { + let guar = self.err_ctxt().report_fulfillment_errors(errors); + self.set_tainted_by_errors(guar); + Some(guar) + } + } + /// Probe whether `expr_ty` can be coerced to `target_ty`. This has no side-effects, /// and may return false positives if types are not yet fully constrained by inference. /// @@ -1666,6 +1656,14 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { } } Err(coercion_error) => { + if let Some(_guar) = fcx.emit_specialized_coerce_unsize_error( + cause.span, + expression_ty, + self.merged_ty(), + ) { + return; + } + // Mark that we've failed to coerce the types here to suppress // any superfluous errors we might encounter while trying to // emit or provide suggestions on how to fix the initial error. diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index aa917ee07ff5c..2ac58e49976fb 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -268,6 +268,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Err(e) => e, }; + if let Some(guar) = + self.emit_specialized_coerce_unsize_error(expr.span, checked_ty, expected) + { + return Ok(Ty::new_error(self.tcx, guar)); + } + self.adjust_expr_for_assert_eq_macro(&mut expr, &mut expected_ty_expr); self.set_tainted_by_errors(self.dcx().span_delayed_bug( diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index b851770166702..dd17383e9b5ef 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -972,6 +972,30 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { true }); + // We need to handle type mismatches due to unsizing failures specially. + errors.retain(|err| { + if let Error::Invalid( + provided_idx, + expected_idx, + Compatibility::Incompatible(Some(_)), + ) = *err + { + let (_, expected_ty) = formal_and_expected_inputs[expected_idx]; + let (provided_ty, provided_arg_span) = provided_arg_tys[provided_idx]; + + if let Some(guar) = self.emit_specialized_coerce_unsize_error( + provided_arg_span, + provided_ty, + expected_ty, + ) { + reported = Some(guar); + return false; + } + } + + true + }); + // We're done if we found errors, but we already emitted them. if let Some(reported) = reported && errors.is_empty() diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 6db97fc321a8d..e8e890eadee51 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -1237,6 +1237,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { &obligation.cause, ); + let pointer_like_goal = normalize_with_depth_to( + self, + obligation.param_env, + obligation.cause.clone(), + obligation.recursion_depth, + pointer_like_goal, + &mut nested, + ); + nested.push(predicate_to_obligation(pointer_like_goal.upcast(tcx))); } } diff --git a/tests/ui/async-await/async-block-control-flow-static-semantics.stderr b/tests/ui/async-await/async-block-control-flow-static-semantics.stderr index 4ed15a942c674..0b6d27629a92f 100644 --- a/tests/ui/async-await/async-block-control-flow-static-semantics.stderr +++ b/tests/ui/async-await/async-block-control-flow-static-semantics.stderr @@ -14,6 +14,14 @@ LL | async { LL | break 0u8; | ^^^^^^^^^ cannot `break` inside `async` block +error[E0271]: expected `{async block@$DIR/async-block-control-flow-static-semantics.rs:23:17: 23:22}` to be a future that resolves to `()`, but it resolves to `u8` + --> $DIR/async-block-control-flow-static-semantics.rs:26:39 + | +LL | let _: &dyn Future = █ + | ^^^^^^ expected `()`, found `u8` + | + = note: required for the cast from `&{async block@$DIR/async-block-control-flow-static-semantics.rs:23:17: 23:22}` to `&dyn Future` + error[E0308]: mismatched types --> $DIR/async-block-control-flow-static-semantics.rs:21:58 | @@ -26,13 +34,13 @@ LL | | return 0u8; LL | | } | |_^ expected `u8`, found `()` -error[E0271]: expected `{async block@$DIR/async-block-control-flow-static-semantics.rs:23:17: 23:22}` to be a future that resolves to `()`, but it resolves to `u8` - --> $DIR/async-block-control-flow-static-semantics.rs:26:39 +error[E0271]: expected `{async block@$DIR/async-block-control-flow-static-semantics.rs:14:17: 14:22}` to be a future that resolves to `()`, but it resolves to `u8` + --> $DIR/async-block-control-flow-static-semantics.rs:17:39 | LL | let _: &dyn Future = █ | ^^^^^^ expected `()`, found `u8` | - = note: required for the cast from `&{async block@$DIR/async-block-control-flow-static-semantics.rs:23:17: 23:22}` to `&dyn Future` + = note: required for the cast from `&{async block@$DIR/async-block-control-flow-static-semantics.rs:14:17: 14:22}` to `&dyn Future` error[E0308]: mismatched types --> $DIR/async-block-control-flow-static-semantics.rs:12:43 @@ -42,14 +50,6 @@ LL | fn return_targets_async_block_not_fn() -> u8 { | | | implicitly returns `()` as its body has no tail or `return` expression -error[E0271]: expected `{async block@$DIR/async-block-control-flow-static-semantics.rs:14:17: 14:22}` to be a future that resolves to `()`, but it resolves to `u8` - --> $DIR/async-block-control-flow-static-semantics.rs:17:39 - | -LL | let _: &dyn Future = █ - | ^^^^^^ expected `()`, found `u8` - | - = note: required for the cast from `&{async block@$DIR/async-block-control-flow-static-semantics.rs:14:17: 14:22}` to `&dyn Future` - error[E0308]: mismatched types --> $DIR/async-block-control-flow-static-semantics.rs:49:44 | diff --git a/tests/ui/cross/cross-borrow-trait.stderr b/tests/ui/cross/cross-borrow-trait.stderr index b670de39f6dbf..abd9331d26105 100644 --- a/tests/ui/cross/cross-borrow-trait.stderr +++ b/tests/ui/cross/cross-borrow-trait.stderr @@ -8,6 +8,10 @@ LL | let _y: &dyn Trait = x; | = note: expected reference `&dyn Trait` found struct `Box` +help: consider borrowing here + | +LL | let _y: &dyn Trait = &x; + | + error: aborting due to 1 previous error diff --git a/tests/ui/custom_test_frameworks/mismatch.rs b/tests/ui/custom_test_frameworks/mismatch.rs index c4773c13264e8..fce1ae4efdcdb 100644 --- a/tests/ui/custom_test_frameworks/mismatch.rs +++ b/tests/ui/custom_test_frameworks/mismatch.rs @@ -1,3 +1,5 @@ +//~ ERROR mismatched types + //@ aux-build:example_runner.rs //@ compile-flags:--test #![feature(custom_test_frameworks)] diff --git a/tests/ui/custom_test_frameworks/mismatch.stderr b/tests/ui/custom_test_frameworks/mismatch.stderr index dad93cfbba4cb..c14a84b93a5c5 100644 --- a/tests/ui/custom_test_frameworks/mismatch.stderr +++ b/tests/ui/custom_test_frameworks/mismatch.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `TestDescAndFn: Testable` is not satisfied - --> $DIR/mismatch.rs:9:1 + --> $DIR/mismatch.rs:11:1 | LL | #[test] | ------- in this procedural macro expansion @@ -9,6 +9,17 @@ LL | fn wrong_kind(){} = note: required for the cast from `&TestDescAndFn` to `&dyn Testable` = note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 1 previous error +error[E0308]: mismatched types + | + = note: expected reference `&[&dyn Testable]` + found reference `&[!; 1]` +note: function defined here + --> $DIR/auxiliary/example_runner.rs:6:8 + | +LL | pub fn runner(tests: &[&dyn Testable]) { + | ^^^^^^ + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0277`. +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/dst/dst-object-from-unsized-type.rs b/tests/ui/dst/dst-object-from-unsized-type.rs index 3cd5b1ed6f462..2e1f58b7bc937 100644 --- a/tests/ui/dst/dst-object-from-unsized-type.rs +++ b/tests/ui/dst/dst-object-from-unsized-type.rs @@ -17,6 +17,7 @@ fn test2(t: &T) { fn test3() { let _: &[&dyn Foo] = &["hi"]; //~^ ERROR the size for values of type + //~| ERROR mismatched types } fn test4(x: &[u8]) { diff --git a/tests/ui/dst/dst-object-from-unsized-type.stderr b/tests/ui/dst/dst-object-from-unsized-type.stderr index cbb7dc5e9f421..0393602cab16e 100644 --- a/tests/ui/dst/dst-object-from-unsized-type.stderr +++ b/tests/ui/dst/dst-object-from-unsized-type.stderr @@ -37,8 +37,19 @@ LL | let _: &[&dyn Foo] = &["hi"]; = help: the trait `Sized` is not implemented for `str` = note: required for the cast from `&'static str` to `&dyn Foo` +error[E0308]: mismatched types + --> $DIR/dst-object-from-unsized-type.rs:18:26 + | +LL | let _: &[&dyn Foo] = &["hi"]; + | ----------- ^^^^^^^ expected `&[&dyn Foo]`, found `&[!; 1]` + | | + | expected due to this + | + = note: expected reference `&[&dyn Foo]` + found reference `&[!; 1]` + error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/dst-object-from-unsized-type.rs:23:23 + --> $DIR/dst-object-from-unsized-type.rs:24:23 | LL | let _: &dyn Foo = x as &dyn Foo; | ^ doesn't have a size known at compile-time @@ -46,6 +57,7 @@ LL | let _: &dyn Foo = x as &dyn Foo; = help: the trait `Sized` is not implemented for `[u8]` = note: required for the cast from `&[u8]` to `&dyn Foo` -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0277`. +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.rs b/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.rs index 5d039cd5dc656..b4e9814a56ac4 100644 --- a/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.rs +++ b/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.rs @@ -16,5 +16,4 @@ fn main() { //~| ERROR the trait `Foo` is not dyn compatible needs_bar(x); - //~^ ERROR mismatched types } diff --git a/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.stderr b/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.stderr index 183ee678d7a46..8f7b5aee8b051 100644 --- a/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.stderr +++ b/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.stderr @@ -29,23 +29,6 @@ LL | trait Foo: for Bar {} | | | this trait is not dyn compatible... -error[E0308]: mismatched types - --> $DIR/span-bug-issue-121597.rs:18:15 - | -LL | needs_bar(x); - | --------- ^ types differ in mutability - | | - | arguments to this function are incorrect - | - = note: expected raw pointer `*mut Type2` - found reference `&dyn Foo` -note: function defined here - --> $DIR/span-bug-issue-121597.rs:11:4 - | -LL | fn needs_bar(_: *mut Type2) {} - | ^^^^^^^^^ ------------- - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0038, E0308. -For more information about an error, try `rustc --explain E0038`. +For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/impl-trait/unsized_coercion2.old.stderr b/tests/ui/impl-trait/unsized_coercion2.old.stderr deleted file mode 100644 index a89d40f1130c1..0000000000000 --- a/tests/ui/impl-trait/unsized_coercion2.old.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time - --> $DIR/unsized_coercion2.rs:15:33 - | -LL | let y: Box = x; - | ^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `impl Trait + ?Sized` - = note: required for the cast from `Box` to `Box` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/unsized_coercion2.rs b/tests/ui/impl-trait/unsized_coercion2.rs index 7368d47dbe2c0..a2a7bae984396 100644 --- a/tests/ui/impl-trait/unsized_coercion2.rs +++ b/tests/ui/impl-trait/unsized_coercion2.rs @@ -3,7 +3,7 @@ //@ revisions: next old //@[next] compile-flags: -Znext-solver -//@[next] check-pass +//@ check-pass trait Trait {} @@ -13,7 +13,6 @@ fn hello() -> Box { if true { let x = hello(); let y: Box = x; - //[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know } Box::new(1u32) } diff --git a/tests/ui/impl-trait/unsized_coercion3.next.stderr b/tests/ui/impl-trait/unsized_coercion3.next.stderr index 28771e01813ae..daf794e7d2218 100644 --- a/tests/ui/impl-trait/unsized_coercion3.next.stderr +++ b/tests/ui/impl-trait/unsized_coercion3.next.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `dyn Send: Trait` is not satisfied - --> $DIR/unsized_coercion3.rs:13:17 + --> $DIR/unsized_coercion3.rs:14:17 | LL | let x = hello(); | ^^^^^^^ the trait `Trait` is not implemented for `dyn Send` diff --git a/tests/ui/impl-trait/unsized_coercion3.old.stderr b/tests/ui/impl-trait/unsized_coercion3.old.stderr index 52a72b84a8dd6..33cd6c3a0ff5b 100644 --- a/tests/ui/impl-trait/unsized_coercion3.old.stderr +++ b/tests/ui/impl-trait/unsized_coercion3.old.stderr @@ -1,12 +1,19 @@ -error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time - --> $DIR/unsized_coercion3.rs:15:32 +error[E0277]: the trait bound `dyn Send: Trait` is not satisfied + --> $DIR/unsized_coercion3.rs:16:32 | LL | let y: Box = x; - | ^ doesn't have a size known at compile-time + | ^ the trait `Trait` is not implemented for `dyn Send` | - = help: the trait `Sized` is not implemented for `impl Trait + ?Sized` - = note: required for the cast from `Box` to `Box` + = help: the trait `Trait` is implemented for `u32` -error: aborting due to 1 previous error +error[E0277]: the trait bound `dyn Send: Trait` is not satisfied + --> $DIR/unsized_coercion3.rs:11:19 + | +LL | fn hello() -> Box { + | ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `dyn Send` + | + = help: the trait `Trait` is implemented for `u32` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/unsized_coercion3.rs b/tests/ui/impl-trait/unsized_coercion3.rs index ebfbb2955de55..d76a4fd83d7f5 100644 --- a/tests/ui/impl-trait/unsized_coercion3.rs +++ b/tests/ui/impl-trait/unsized_coercion3.rs @@ -9,11 +9,12 @@ trait Trait {} impl Trait for u32 {} fn hello() -> Box { + //[old]~^ ERROR: the trait bound `dyn Send: Trait` is not satisfied if true { let x = hello(); //[next]~^ ERROR: the trait bound `dyn Send: Trait` is not satisfied let y: Box = x; - //[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know + //[old]~^ ERROR: the trait bound `dyn Send: Trait` is not satisfied } Box::new(1u32) } diff --git a/tests/ui/issues/issue-19380.rs b/tests/ui/issues/issue-19380.rs index 8b3fe4d2b099b..4ba4db73bb575 100644 --- a/tests/ui/issues/issue-19380.rs +++ b/tests/ui/issues/issue-19380.rs @@ -16,5 +16,6 @@ const FOO : Foo = Foo; const BAR : Bar = Bar { foos: &[&FOO]}; //~^ ERROR E0038 //~| ERROR E0038 +//~| ERROR mismatched types fn main() { } diff --git a/tests/ui/issues/issue-19380.stderr b/tests/ui/issues/issue-19380.stderr index f8509891d3abb..dd95a1886940c 100644 --- a/tests/ui/issues/issue-19380.stderr +++ b/tests/ui/issues/issue-19380.stderr @@ -47,6 +47,15 @@ help: alternatively, consider constraining `qiz` so it does not apply to trait o LL | fn qiz() where Self: Sized; | +++++++++++++++++ +error[E0308]: mismatched types + --> $DIR/issue-19380.rs:16:31 + | +LL | const BAR : Bar = Bar { foos: &[&FOO]}; + | ^^^^^^^ expected `&[&dyn Qiz]`, found `&[!; 1]` + | + = note: expected reference `&'static [&'static (dyn Qiz + 'static)]` + found reference `&[!; 1]` + error[E0038]: the trait `Qiz` is not dyn compatible --> $DIR/issue-19380.rs:16:31 | @@ -71,6 +80,7 @@ help: alternatively, consider constraining `qiz` so it does not apply to trait o LL | fn qiz() where Self: Sized; | +++++++++++++++++ -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0038`. +Some errors have detailed explanations: E0038, E0308. +For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/issues/issue-40000.stderr b/tests/ui/issues/issue-40000.stderr index 0737a9610e294..e395db43c03fa 100644 --- a/tests/ui/issues/issue-40000.stderr +++ b/tests/ui/issues/issue-40000.stderr @@ -1,20 +1,20 @@ error[E0308]: mismatched types - --> $DIR/issue-40000.rs:6:9 + --> $DIR/issue-40000.rs:6:5 | LL | foo(bar); - | ^^^ one type is more general than the other + | ^^^^^^^^ one type is more general than the other | - = note: expected trait object `dyn for<'a> Fn(&'a i32)` - found trait object `dyn Fn(&i32)` + = note: expected struct `Box<(dyn for<'a> Fn(&'a i32) + 'static)>` + found struct `Box` error[E0308]: mismatched types - --> $DIR/issue-40000.rs:6:9 + --> $DIR/issue-40000.rs:6:5 | LL | foo(bar); - | ^^^ one type is more general than the other + | ^^^^^^^^ one type is more general than the other | - = note: expected trait object `dyn for<'a> Fn(&'a i32)` - found trait object `dyn Fn(&i32)` + = note: expected struct `Box<(dyn for<'a> Fn(&'a i32) + 'static)>` + found struct `Box` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 2 previous errors diff --git a/tests/ui/issues/issue-50781.stderr b/tests/ui/issues/issue-50781.stderr index 88b83a83e0cfa..dbec9c34409a8 100644 --- a/tests/ui/issues/issue-50781.stderr +++ b/tests/ui/issues/issue-50781.stderr @@ -16,10 +16,10 @@ LL | fn foo(&self) where Self: Trait; = help: only type `()` implements `X`; consider using it directly instead. error[E0038]: the trait `X` is not dyn compatible - --> $DIR/issue-50781.rs:16:23 + --> $DIR/issue-50781.rs:16:6 | LL | ::foo(&()); - | ^^^ `X` is not dyn compatible + | ^^^^^ `X` is not dyn compatible | note: for a trait to be dyn compatible it needs to allow building a vtable for more information, visit @@ -31,13 +31,12 @@ LL | fn foo(&self) where Self: Trait; | ^^^ ...because method `foo` references the `Self` type in its `where` clause = help: consider moving `foo` to another trait = help: only type `()` implements `X`; consider using it directly instead. - = note: required for the cast from `&()` to `&dyn X` error[E0038]: the trait `X` is not dyn compatible - --> $DIR/issue-50781.rs:16:6 + --> $DIR/issue-50781.rs:16:23 | LL | ::foo(&()); - | ^^^^^ `X` is not dyn compatible + | ^^^ `X` is not dyn compatible | note: for a trait to be dyn compatible it needs to allow building a vtable for more information, visit @@ -49,6 +48,7 @@ LL | fn foo(&self) where Self: Trait; | ^^^ ...because method `foo` references the `Self` type in its `where` clause = help: consider moving `foo` to another trait = help: only type `()` implements `X`; consider using it directly instead. + = note: required for the cast from `&()` to `&dyn X` error: aborting due to 3 previous errors diff --git a/tests/ui/lub-glb/old-lub-glb-object.stderr b/tests/ui/lub-glb/old-lub-glb-object.stderr index c476d6f692b7b..eb0ca1612ec34 100644 --- a/tests/ui/lub-glb/old-lub-glb-object.stderr +++ b/tests/ui/lub-glb/old-lub-glb-object.stderr @@ -4,8 +4,8 @@ error[E0308]: mismatched types LL | _ => y, | ^ one type is more general than the other | - = note: expected trait object `dyn for<'a, 'b> Foo<&'a u8, &'b u8>` - found trait object `dyn for<'a> Foo<&'a u8, &'a u8>` + = note: expected reference `&dyn for<'a, 'b> Foo<&'a u8, &'b u8>` + found reference `&dyn for<'a> Foo<&'a u8, &'a u8>` error[E0308]: mismatched types --> $DIR/old-lub-glb-object.rs:9:14 @@ -13,8 +13,8 @@ error[E0308]: mismatched types LL | _ => y, | ^ one type is more general than the other | - = note: expected trait object `dyn for<'a, 'b> Foo<&'a u8, &'b u8>` - found trait object `dyn for<'a> Foo<&'a u8, &'a u8>` + = note: expected reference `&dyn for<'a, 'b> Foo<&'a u8, &'b u8>` + found reference `&dyn for<'a> Foo<&'a u8, &'a u8>` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 2 previous errors diff --git a/tests/ui/mismatched_types/cast-rfc0401.rs b/tests/ui/mismatched_types/cast-rfc0401.rs index b2ff5b4a0c063..ef9ef002e199e 100644 --- a/tests/ui/mismatched_types/cast-rfc0401.rs +++ b/tests/ui/mismatched_types/cast-rfc0401.rs @@ -50,7 +50,7 @@ fn main() let _ = 42usize as *const [u8]; //~ ERROR cannot cast `usize` to a pointer that is wide let _ = v as *const [u8]; //~ ERROR cannot cast - let _ = fat_v as *const dyn Foo; //~ ERROR the size for values of type + let _ = fat_v as *const dyn Foo; //~ ERROR casting let _ = foo as *const str; //~ ERROR is invalid let _ = foo as *mut str; //~ ERROR is invalid let _ = main as *mut str; //~ ERROR is invalid @@ -59,7 +59,7 @@ fn main() let _ = fat_sv as usize; //~ ERROR is invalid let a : *const str = "hello"; - let _ = a as *const dyn Foo; //~ ERROR the size for values of type + let _ = a as *const dyn Foo; //~ ERROR casting // check no error cascade let _ = main.f as *const u32; //~ ERROR no field diff --git a/tests/ui/mismatched_types/cast-rfc0401.stderr b/tests/ui/mismatched_types/cast-rfc0401.stderr index a427639594415..70cbeabc3df1e 100644 --- a/tests/ui/mismatched_types/cast-rfc0401.stderr +++ b/tests/ui/mismatched_types/cast-rfc0401.stderr @@ -165,6 +165,14 @@ error[E0607]: cannot cast thin pointer `*const u8` to wide pointer `*const [u8]` LL | let _ = v as *const [u8]; | ^^^^^^^^^^^^^^^^ +error[E0606]: casting `*const [u8]` as `*const dyn Foo` is invalid + --> $DIR/cast-rfc0401.rs:53:13 + | +LL | let _ = fat_v as *const dyn Foo; + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the pointers have different metadata + error[E0606]: casting `&dyn Foo` as `*const str` is invalid --> $DIR/cast-rfc0401.rs:54:13 | @@ -203,6 +211,14 @@ LL | let _ = fat_sv as usize; | = help: cast through a thin pointer first +error[E0606]: casting `*const str` as `*const dyn Foo` is invalid + --> $DIR/cast-rfc0401.rs:62:13 + | +LL | let _ = a as *const dyn Foo; + | ^^^^^^^^^^^^^^^^^^^ + | + = note: the pointers have different metadata + error[E0606]: casting `*const dyn Foo` as `*const [u16]` is invalid --> $DIR/cast-rfc0401.rs:68:13 | @@ -219,24 +235,6 @@ LL | let _ = cf as *const dyn Bar; | = note: the trait objects may have different vtables -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/cast-rfc0401.rs:53:13 - | -LL | let _ = fat_v as *const dyn Foo; - | ^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: required for the cast from `*const [u8]` to `*const dyn Foo` - -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/cast-rfc0401.rs:62:13 - | -LL | let _ = a as *const dyn Foo; - | ^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `str` - = note: required for the cast from `*const str` to `*const dyn Foo` - error[E0606]: casting `&{float}` as `f32` is invalid --> $DIR/cast-rfc0401.rs:71:30 | @@ -250,5 +248,5 @@ LL | vec![0.0].iter().map(|s| *s as f32).collect::>(); error: aborting due to 34 previous errors -Some errors have detailed explanations: E0054, E0277, E0604, E0605, E0606, E0607, E0609. +Some errors have detailed explanations: E0054, E0604, E0605, E0606, E0607, E0609. For more information about an error, try `rustc --explain E0054`. diff --git a/tests/ui/nll/issue-57843.rs b/tests/ui/nll/issue-57843.rs index 11629690ecc5e..da4733aad168e 100644 --- a/tests/ui/nll/issue-57843.rs +++ b/tests/ui/nll/issue-57843.rs @@ -22,5 +22,5 @@ where struct Foo(Box ClonableFn<&'a bool>>); fn main() { - Foo(Box::new(|_| ())); //~ ERROR implementation of `FnOnce` is not general enough + Foo(Box::new(|_| ())); //~ ERROR mismatched types } diff --git a/tests/ui/nll/issue-57843.stderr b/tests/ui/nll/issue-57843.stderr index eed511460cac7..e9e5238331153 100644 --- a/tests/ui/nll/issue-57843.stderr +++ b/tests/ui/nll/issue-57843.stderr @@ -1,11 +1,20 @@ -error: implementation of `FnOnce` is not general enough +error[E0308]: mismatched types --> $DIR/issue-57843.rs:25:9 | LL | Foo(Box::new(|_| ())); - | ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough + | --- ^^^^^^^^^^^^^^^^ expected `Box>`, found `Box<{closure@issue-57843.rs:25:18}>` + | | + | arguments to this struct are incorrect | - = note: closure with signature `fn(&'2 bool)` must implement `FnOnce<(&'1 bool,)>`, for any lifetime `'1`... - = note: ...but it actually implements `FnOnce<(&'2 bool,)>`, for some specific lifetime `'2` + = note: expected struct `Box<(dyn for<'a> ClonableFn<&'a bool> + 'static)>` + found struct `Box<{closure@$DIR/issue-57843.rs:25:18: 25:21}>` + = help: `{closure@$DIR/issue-57843.rs:25:18: 25:21}` implements `ClonableFn` so you could box the found value and coerce it to the trait object `Box`, you will have to change the expected type as well +note: tuple struct defined here + --> $DIR/issue-57843.rs:22:8 + | +LL | struct Foo(Box ClonableFn<&'a bool>>); + | ^^^ error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/rfcs/rfc-1623-static/rfc1623-2.rs b/tests/ui/rfcs/rfc-1623-static/rfc1623-2.rs index 97fc1276f6175..bae0e6dff54fb 100644 --- a/tests/ui/rfcs/rfc-1623-static/rfc1623-2.rs +++ b/tests/ui/rfcs/rfc-1623-static/rfc1623-2.rs @@ -26,10 +26,7 @@ static SOME_STRUCT: &SomeStruct = &SomeStruct { foo: &Foo { bools: &[false, true] }, bar: &Bar { bools: &[true, true] }, f: &id, - //~^ ERROR implementation of `FnOnce` is not general enough - //~| ERROR implementation of `FnOnce` is not general enough - //~| ERROR implementation of `Fn` is not general enough - //~| ERROR implementation of `Fn` is not general enough + //~^ ERROR mismatched types }; // very simple test for a 'static static with default lifetime diff --git a/tests/ui/rfcs/rfc-1623-static/rfc1623-2.stderr b/tests/ui/rfcs/rfc-1623-static/rfc1623-2.stderr index 5c98a9d4fb4ce..47e363ffa33cd 100644 --- a/tests/ui/rfcs/rfc-1623-static/rfc1623-2.stderr +++ b/tests/ui/rfcs/rfc-1623-static/rfc1623-2.stderr @@ -1,38 +1,12 @@ -error: implementation of `Fn` is not general enough +error[E0308]: mismatched types --> $DIR/rfc1623-2.rs:28:8 | LL | f: &id, - | ^^^ implementation of `Fn` is not general enough + | ^^^ expected `&dyn Fn(&Foo<'b>) -> &Foo<'_>`, found `&fn(&Foo<'_>) -> &Foo<'_> {id::<&...>}` | - = note: `fn(&'2 Foo<'_>) -> &'2 Foo<'_> {id::<&'2 Foo<'_>>}` must implement `Fn<(&'1 Foo<'b>,)>`, for any lifetime `'1`... - = note: ...but it actually implements `Fn<(&'2 Foo<'_>,)>`, for some specific lifetime `'2` + = note: expected reference `&dyn for<'a, 'b> Fn(&'a Foo<'b>) -> &'a Foo<'b>` + found reference `&fn(&Foo<'_>) -> &Foo<'_> {id::<&Foo<'_>>}` -error: implementation of `Fn` is not general enough - --> $DIR/rfc1623-2.rs:28:8 - | -LL | f: &id, - | ^^^ implementation of `Fn` is not general enough - | - = note: `fn(&Foo<'2>) -> &Foo<'2> {id::<&Foo<'2>>}` must implement `Fn<(&'a Foo<'1>,)>`, for any lifetime `'1`... - = note: ...but it actually implements `Fn<(&Foo<'2>,)>`, for some specific lifetime `'2` - -error: implementation of `FnOnce` is not general enough - --> $DIR/rfc1623-2.rs:28:8 - | -LL | f: &id, - | ^^^ implementation of `FnOnce` is not general enough - | - = note: `fn(&'2 Foo<'_>) -> &'2 Foo<'_> {id::<&'2 Foo<'_>>}` must implement `FnOnce<(&'1 Foo<'b>,)>`, for any lifetime `'1`... - = note: ...but it actually implements `FnOnce<(&'2 Foo<'_>,)>`, for some specific lifetime `'2` - -error: implementation of `FnOnce` is not general enough - --> $DIR/rfc1623-2.rs:28:8 - | -LL | f: &id, - | ^^^ implementation of `FnOnce` is not general enough - | - = note: `fn(&Foo<'2>) -> &Foo<'2> {id::<&Foo<'2>>}` must implement `FnOnce<(&'a Foo<'1>,)>`, for any lifetime `'1`... - = note: ...but it actually implements `FnOnce<(&Foo<'2>,)>`, for some specific lifetime `'2` - -error: aborting due to 4 previous errors +error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/suggestions/missing-bound-in-derive-copy-impl-2.fixed b/tests/ui/suggestions/missing-bound-in-derive-copy-impl-2.fixed index 99433f7332042..9240254382c1c 100644 --- a/tests/ui/suggestions/missing-bound-in-derive-copy-impl-2.fixed +++ b/tests/ui/suggestions/missing-bound-in-derive-copy-impl-2.fixed @@ -8,11 +8,12 @@ pub struct Vector2 { } #[derive(Debug, Copy, Clone)] -pub struct AABB { +pub struct AABB { pub loc: Vector2, //~ ERROR the trait bound `K: Copy` is not satisfied //~^ ERROR the trait bound `K: Copy` is not satisfied //~| ERROR the trait bound `K: Copy` is not satisfied pub size: Vector2, //~ ERROR the trait bound `K: Copy` is not satisfied + //~^ ERROR the trait bound `K: Copy` is not satisfied } fn main() {} diff --git a/tests/ui/suggestions/missing-bound-in-derive-copy-impl-2.rs b/tests/ui/suggestions/missing-bound-in-derive-copy-impl-2.rs index c0777e0817f03..83ab23e0b6f1a 100644 --- a/tests/ui/suggestions/missing-bound-in-derive-copy-impl-2.rs +++ b/tests/ui/suggestions/missing-bound-in-derive-copy-impl-2.rs @@ -13,6 +13,7 @@ pub struct AABB { //~^ ERROR the trait bound `K: Copy` is not satisfied //~| ERROR the trait bound `K: Copy` is not satisfied pub size: Vector2, //~ ERROR the trait bound `K: Copy` is not satisfied + //~^ ERROR the trait bound `K: Copy` is not satisfied } fn main() {} diff --git a/tests/ui/suggestions/missing-bound-in-derive-copy-impl-2.stderr b/tests/ui/suggestions/missing-bound-in-derive-copy-impl-2.stderr index 4408fe0a0a4bb..e6a5ef5bd1e83 100644 --- a/tests/ui/suggestions/missing-bound-in-derive-copy-impl-2.stderr +++ b/tests/ui/suggestions/missing-bound-in-derive-copy-impl-2.stderr @@ -37,6 +37,31 @@ help: consider further restricting type parameter `K` with trait `Copy` LL | pub struct AABB { | +++++++++++++++++++ +error[E0277]: the trait bound `K: Copy` is not satisfied + --> $DIR/missing-bound-in-derive-copy-impl-2.rs:15:5 + | +LL | #[derive(Debug, Copy, Clone)] + | ----- in this derive macro expansion +... +LL | pub size: Vector2, + | ^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `K` + | +note: required for `Vector2` to implement `Debug` + --> $DIR/missing-bound-in-derive-copy-impl-2.rs:4:10 + | +LL | #[derive(Debug, Copy, Clone)] + | ^^^^^ +LL | pub struct Vector2 { + | ---- unsatisfied trait bound introduced in this `derive` macro + = note: 1 redundant requirement hidden + = note: required for `&Vector2` to implement `Debug` + = note: required for the cast from `&&Vector2` to `&dyn Debug` + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider further restricting type parameter `K` with trait `Copy` + | +LL | pub struct AABB { + | +++++++++++++++++++ + error[E0277]: the trait bound `K: Copy` is not satisfied --> $DIR/missing-bound-in-derive-copy-impl-2.rs:12:5 | @@ -79,6 +104,6 @@ help: consider further restricting type parameter `K` with trait `Copy` LL | pub struct AABB { | +++++++++++++++++++ -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/suggestions/missing-bound-in-derive-copy-impl.rs b/tests/ui/suggestions/missing-bound-in-derive-copy-impl.rs index 0ffc1b8f7a25e..0fcbc871a1eb9 100644 --- a/tests/ui/suggestions/missing-bound-in-derive-copy-impl.rs +++ b/tests/ui/suggestions/missing-bound-in-derive-copy-impl.rs @@ -17,6 +17,7 @@ pub struct AABB { pub size: Vector2, //~^ ERROR doesn't implement `Debug` //~| ERROR `K: Copy` is not satisfied + //~| ERROR `K: Copy` is not satisfied } fn main() {} diff --git a/tests/ui/suggestions/missing-bound-in-derive-copy-impl.stderr b/tests/ui/suggestions/missing-bound-in-derive-copy-impl.stderr index 8b5cced4c4aaa..b1b7f96f0f4ef 100644 --- a/tests/ui/suggestions/missing-bound-in-derive-copy-impl.stderr +++ b/tests/ui/suggestions/missing-bound-in-derive-copy-impl.stderr @@ -73,6 +73,31 @@ help: consider restricting type parameter `K` with trait `Copy` LL | pub struct AABB { | +++++++++++++++++++ +error[E0277]: the trait bound `K: Copy` is not satisfied + --> $DIR/missing-bound-in-derive-copy-impl.rs:17:5 + | +LL | #[derive(Debug, Copy, Clone)] + | ----- in this derive macro expansion +... +LL | pub size: Vector2, + | ^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `K` + | +note: required for `Vector2` to implement `Debug` + --> $DIR/missing-bound-in-derive-copy-impl.rs:3:10 + | +LL | #[derive(Debug, Copy, Clone)] + | ^^^^^ +LL | pub struct Vector2 { + | ---- unsatisfied trait bound introduced in this `derive` macro + = note: 1 redundant requirement hidden + = note: required for `&Vector2` to implement `Debug` + = note: required for the cast from `&&Vector2` to `&dyn Debug` + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider restricting type parameter `K` with trait `Copy` + | +LL | pub struct AABB { + | +++++++++++++++++++ + error[E0277]: `K` doesn't implement `Debug` --> $DIR/missing-bound-in-derive-copy-impl.rs:11:5 | @@ -145,7 +170,7 @@ help: consider restricting type parameter `K` with trait `Copy` LL | pub struct AABB { | +++++++++++++++++++ -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors Some errors have detailed explanations: E0204, E0277. For more information about an error, try `rustc --explain E0204`. diff --git a/tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.rs b/tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.rs index 28785ae3dea14..f6699c08444b0 100644 --- a/tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.rs +++ b/tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.rs @@ -20,5 +20,4 @@ fn main() { //~^ ERROR the trait `Foo` is not dyn compatible //~| ERROR the trait `Foo` is not dyn compatible needs_bar(x); - //~^ ERROR the trait `Foo` is not dyn compatible } diff --git a/tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.stderr b/tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.stderr index 43b69d0b50e48..5a3984fe7cb36 100644 --- a/tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.stderr +++ b/tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.stderr @@ -40,22 +40,6 @@ LL | trait Foo: for Bar {} | this trait is not dyn compatible... = help: only type `()` implements `Foo`; consider using it directly instead. -error[E0038]: the trait `Foo` is not dyn compatible - --> $DIR/supertrait-dyn-compatibility.rs:22:5 - | -LL | needs_bar(x); - | ^^^^^^^^^ `Foo` is not dyn compatible - | -note: for a trait to be dyn compatible it needs to allow building a vtable - for more information, visit - --> $DIR/supertrait-dyn-compatibility.rs:4:12 - | -LL | trait Foo: for Bar {} - | --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables - | | - | this trait is not dyn compatible... - = help: only type `()` implements `Foo`; consider using it directly instead. - -error: aborting due to 3 previous errors; 1 warning emitted +error: aborting due to 2 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/traits/trait-upcasting/higher-ranked-upcasting-ub.current.stderr b/tests/ui/traits/trait-upcasting/higher-ranked-upcasting-ub.current.stderr index e5885ea35a71e..b82f1eef42b5a 100644 --- a/tests/ui/traits/trait-upcasting/higher-ranked-upcasting-ub.current.stderr +++ b/tests/ui/traits/trait-upcasting/higher-ranked-upcasting-ub.current.stderr @@ -1,22 +1,14 @@ error[E0308]: mismatched types --> $DIR/higher-ranked-upcasting-ub.rs:22:5 | +LL | fn unsound(x: &dyn for<'a> Subtrait<'a, 'a>) -> &dyn for<'a, 'b> Supertrait<'a, 'b> { + | ----------------------------------- expected `&dyn for<'a, 'b> Supertrait<'a, 'b>` because of return type LL | x - | ^ one type is more general than the other + | ^ expected trait `Supertrait`, found trait `Subtrait` | - = note: expected existential trait ref `for<'a, 'b> Supertrait<'a, 'b>` - found existential trait ref `for<'a> Supertrait<'a, 'a>` + = note: expected reference `&dyn for<'a, 'b> Supertrait<'a, 'b>` + found reference `&dyn for<'a> Subtrait<'a, 'a>` -error[E0308]: mismatched types - --> $DIR/higher-ranked-upcasting-ub.rs:22:5 - | -LL | x - | ^ one type is more general than the other - | - = note: expected existential trait ref `for<'a, 'b> Supertrait<'a, 'b>` - found existential trait ref `for<'a> Supertrait<'a, 'a>` - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/traits/trait-upcasting/higher-ranked-upcasting-ub.rs b/tests/ui/traits/trait-upcasting/higher-ranked-upcasting-ub.rs index af2594b95f3d2..4a0995a3117e0 100644 --- a/tests/ui/traits/trait-upcasting/higher-ranked-upcasting-ub.rs +++ b/tests/ui/traits/trait-upcasting/higher-ranked-upcasting-ub.rs @@ -20,7 +20,6 @@ impl<'a> Supertrait<'a, 'a> for () { impl<'a> Subtrait<'a, 'a> for () {} fn unsound(x: &dyn for<'a> Subtrait<'a, 'a>) -> &dyn for<'a, 'b> Supertrait<'a, 'b> { x //~ ERROR mismatched types - //[current]~^ ERROR mismatched types } fn transmute<'a, 'b>(x: &'a str) -> &'b str {