diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 1e75902884fe1..76fd59577f248 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -964,8 +964,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), res = res.and(enter_wf_checking_ctxt(tcx, def_id, |wfcx| { let ty = tcx.type_of(def_id).instantiate_identity(); let ty_span = tcx.ty_span(def_id); - let ty = wfcx.deeply_normalize(ty_span, Some(WellFormedLoc::Ty(def_id)), ty); - wfcx.register_wf_obligation(ty_span, Some(WellFormedLoc::Ty(def_id)), ty.into()); + let ty = wfcx.deeply_normalize(ty_span, WellFormedLoc::Ty(def_id), ty); + wfcx.register_wf_obligation(ty_span, WellFormedLoc::Ty(def_id), ty.into()); wfcx.register_bound( traits::ObligationCause::new( ty_span, @@ -993,12 +993,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), let span = tcx.def_span(def_id); if tcx.type_alias_is_checked(def_id) { res = res.and(enter_wf_checking_ctxt(tcx, def_id, |wfcx| { - let item_ty = wfcx.deeply_normalize(span, Some(WellFormedLoc::Ty(def_id)), ty); - wfcx.register_wf_obligation( - span, - Some(WellFormedLoc::Ty(def_id)), - item_ty.into(), - ); + let item_ty = wfcx.deeply_normalize(span, WellFormedLoc::Ty(def_id), ty); + wfcx.register_wf_obligation(span, WellFormedLoc::Ty(def_id), item_ty.into()); check_where_clauses(wfcx, def_id); Ok(()) })); diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 043e3fad05056..86f386381b9e2 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -68,12 +68,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> { // Convenience function to normalize during wfcheck. This performs // `ObligationCtxt::normalize`, but provides a nice `ObligationCauseCode`. - fn normalize( - &self, - span: Span, - loc: Option, - value: Unnormalized<'tcx, T>, - ) -> T + fn normalize(&self, span: Span, loc: WellFormedLoc, value: Unnormalized<'tcx, T>) -> T where T: TypeFoldable>, { @@ -96,7 +91,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> { pub(super) fn deeply_normalize( &self, span: Span, - loc: Option, + loc: WellFormedLoc, value: Unnormalized<'tcx, T>, ) -> T where @@ -122,7 +117,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> { pub(super) fn register_wf_obligation( &self, span: Span, - loc: Option, + loc: WellFormedLoc, term: ty::Term<'tcx>, ) { let cause = traits::ObligationCause::new( @@ -802,7 +797,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), Er if tcx.features().const_param_ty_unchecked() { enter_wf_checking_ctxt(tcx, tcx.local_parent(def_id), |wfcx| { - wfcx.register_wf_obligation(span, None, ty.into()); + wfcx.register_wf_obligation(span, WellFormedLoc::None, ty.into()); Ok(()) }) } else if tcx.features().adt_const_params() || tcx.features().min_adt_const_params() { @@ -916,7 +911,7 @@ pub(crate) fn check_associated_item( tcx: TyCtxt<'_>, def_id: LocalDefId, ) -> Result<(), ErrorGuaranteed> { - let loc = Some(WellFormedLoc::Ty(def_id)); + let loc = WellFormedLoc::Ty(def_id); enter_wf_checking_ctxt(tcx, def_id, |wfcx| { let item = tcx.associated_item(def_id); @@ -936,7 +931,7 @@ pub(crate) fn check_associated_item( match item.kind { ty::AssocKind::Const { .. } => { let ty = tcx.type_of(def_id).instantiate_identity(); - let ty = wfcx.deeply_normalize(span, Some(WellFormedLoc::Ty(def_id)), ty); + let ty = wfcx.deeply_normalize(span, WellFormedLoc::Ty(def_id), ty); wfcx.register_wf_obligation(span, loc, ty.into()); if item.defaultness(tcx).has_value() { @@ -964,7 +959,7 @@ pub(crate) fn check_associated_item( } if item.defaultness(tcx).has_value() { let ty = tcx.type_of(def_id).instantiate_identity(); - let ty = wfcx.deeply_normalize(span, Some(WellFormedLoc::Ty(def_id)), ty); + let ty = wfcx.deeply_normalize(span, WellFormedLoc::Ty(def_id), ty); wfcx.register_wf_obligation(span, loc, ty.into()); } Ok(()) @@ -1013,10 +1008,10 @@ pub(crate) fn check_type_defn<'tcx>( let span = tcx.ty_span(field_id); let ty = wfcx.deeply_normalize( span, - None, + WellFormedLoc::None, tcx.type_of(field.did).instantiate_identity(), ); - wfcx.register_wf_obligation(span, Some(WellFormedLoc::Ty(field_id)), ty.into()); + wfcx.register_wf_obligation(span, WellFormedLoc::Ty(field_id), ty.into()); if matches!(ty.kind(), ty::Adt(def, _) if def.repr().scalable()) && !matches!(adt_def.repr().scalable, Some(ScalableElt::Container)) @@ -1051,7 +1046,11 @@ pub(crate) fn check_type_defn<'tcx>( { let last = idx == variant.fields.len() - 1; let span = tcx.ty_span(field.did.expect_local()); - let ty = wfcx.normalize(span, None, tcx.type_of(field.did).instantiate_identity()); + let ty = wfcx.normalize( + span, + WellFormedLoc::None, + tcx.type_of(field.did).instantiate_identity(), + ); wfcx.register_bound( traits::ObligationCause::new( span, @@ -1215,7 +1214,7 @@ pub(crate) fn check_static_item<'tcx>( } let span = tcx.ty_span(item_id); - let loc = Some(WellFormedLoc::Ty(item_id)); + let loc = WellFormedLoc::Ty(item_id); let item_ty = wfcx.deeply_normalize(span, loc, Unnormalized::new_wip(ty)); let is_foreign_item = tcx.is_foreign_item(item_id); @@ -1231,7 +1230,7 @@ pub(crate) fn check_static_item<'tcx>( }; let forbid_unsized = !(is_foreign_item && is_structurally_foreign_item()); - wfcx.register_wf_obligation(span, Some(WellFormedLoc::Ty(item_id)), item_ty.into()); + wfcx.register_wf_obligation(span, WellFormedLoc::Ty(item_id), item_ty.into()); if forbid_unsized { let span = tcx.def_span(item_id); wfcx.register_bound( @@ -1300,12 +1299,16 @@ pub(super) fn check_const_item<'tcx>( if let Some(direct_rhs) = tcx.const_of_item(def_id) { let raw_ct = direct_rhs.instantiate_identity(); - let norm_ct = wfcx.deeply_normalize(span, Some(WellFormedLoc::Ty(def_id)), raw_ct); - wfcx.register_wf_obligation(span, Some(WellFormedLoc::Ty(def_id)), norm_ct.into()); + let norm_ct = wfcx.deeply_normalize(span, WellFormedLoc::Ty(def_id), raw_ct); + wfcx.register_wf_obligation(span, WellFormedLoc::Ty(def_id), norm_ct.into()); wfcx.register_obligation(Obligation::new( tcx, - ObligationCause::new(span, def_id, ObligationCauseCode::WellFormed(None)), + ObligationCause::new( + span, + def_id, + ObligationCauseCode::WellFormed(WellFormedLoc::Ty(def_id)), + ), wfcx.param_env, ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(norm_ct, item_ty)), )); @@ -1330,7 +1333,7 @@ fn check_impl<'tcx>( let trait_span = of_trait.trait_ref.path.span; let trait_ref = wfcx.deeply_normalize( trait_span, - Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)), + WellFormedLoc::Ty(item.hir_id().expect_owner().def_id), trait_ref, ); let trait_pred = @@ -1367,7 +1370,7 @@ fn check_impl<'tcx>( { let bound = wfcx.normalize( item.span, - Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)), + WellFormedLoc::Ty(item.hir_id().expect_owner().def_id), bound, ); wfcx.register_obligation(Obligation::new( @@ -1375,7 +1378,9 @@ fn check_impl<'tcx>( ObligationCause::new( impl_.self_ty.span, wfcx.body_def_id, - ObligationCauseCode::WellFormed(None), + ObligationCauseCode::WellFormed(WellFormedLoc::HirId( + of_trait.trait_ref.hir_ref_id, + )), ), wfcx.param_env, bound.to_host_effect_clause(tcx, ty::BoundConstness::Maybe), @@ -1390,12 +1395,12 @@ fn check_impl<'tcx>( let self_ty = tcx.type_of(item.owner_id).instantiate_identity().skip_norm_wip(); let self_ty = wfcx.deeply_normalize( item.span, - Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)), + WellFormedLoc::Ty(item.hir_id().expect_owner().def_id), Unnormalized::new_wip(self_ty), ); wfcx.register_wf_obligation( impl_.self_ty.span, - Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)), + WellFormedLoc::Ty(item.hir_id().expect_owner().def_id), self_ty.into(), ); } @@ -1437,7 +1442,8 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: wfcx.register_wf_obligation( tcx.def_span(param.def_id), matches!(param.kind, GenericParamDefKind::Type { .. }) - .then(|| WellFormedLoc::Ty(param.def_id.expect_local())), + .then(|| WellFormedLoc::Ty(param.def_id.expect_local())) + .unwrap_or(WellFormedLoc::None), default.as_term().unwrap(), ); } else { @@ -1466,7 +1472,7 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: let cause = traits::ObligationCause::new( tcx.def_span(param.def_id), wfcx.body_def_id, - ObligationCauseCode::WellFormed(None), + ObligationCauseCode::WellFormed(WellFormedLoc::Ty(def_id)), ); wfcx.register_obligation(Obligation::new( tcx, @@ -1560,7 +1566,7 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: // Note the subtle difference from how we handle `gen_clauses` // below: there, we are not trying to prove those clauses // to be *true* but merely *well-formed*. - let clause = wfcx.normalize(sp, None, clause); + let clause = wfcx.normalize(sp, WellFormedLoc::None, clause); let cause = traits::ObligationCause::new( sp, wfcx.body_def_id, @@ -1636,12 +1642,12 @@ fn check_fn_or_method<'tcx>( tcx.mk_type_list_from_iter(sig.inputs_and_output.iter().enumerate().map(|(idx, ty)| { wfcx.deeply_normalize( arg_span(idx), - Some(WellFormedLoc::Param { + WellFormedLoc::Param { function: def_id, // Note that the `param_idx` of the output type is // one greater than the index of the last input type. param_idx: idx, - }), + }, Unnormalized::new_wip(ty), ) })); @@ -1649,7 +1655,7 @@ fn check_fn_or_method<'tcx>( for (idx, ty) in sig.inputs_and_output.iter().enumerate() { wfcx.register_wf_obligation( arg_span(idx), - Some(WellFormedLoc::Param { function: def_id, param_idx: idx }), + WellFormedLoc::Param { function: def_id, param_idx: idx }, ty.into(), ); } @@ -1726,7 +1732,7 @@ fn check_method_receiver<'tcx>( } let span = fn_sig.decl.inputs[0].span; - let loc = Some(WellFormedLoc::Param { function: method.def_id.expect_local(), param_idx: 0 }); + let loc = WellFormedLoc::Param { function: method.def_id.expect_local(), param_idx: 0 }; let sig = tcx.fn_sig(method.def_id).instantiate_identity().skip_norm_wip(); let sig = tcx.liberate_late_bound_regions(method.def_id, sig); @@ -2319,7 +2325,8 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> { // Match the existing behavior. if clause.is_global() && !clause.has_type_flags(TypeFlags::HAS_BINDER_VARS) { - let clause = self.normalize(span, None, Unnormalized::new_wip(clause)); + let clause = + self.normalize(span, WellFormedLoc::None, Unnormalized::new_wip(clause)); // only use the span of the predicate clause (#90869) let hir_node = tcx.hir_node_by_def_id(self.body_def_id); diff --git a/compiler/rustc_hir_analysis/src/hir_wf_check.rs b/compiler/rustc_hir_analysis/src/hir_wf_check.rs index 9b05789a28f49..9806b7b873918 100644 --- a/compiler/rustc_hir_analysis/src/hir_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/hir_wf_check.rs @@ -19,7 +19,8 @@ pub(super) fn diagnostic_hir_wf_check<'tcx>( ) -> Option> { let def_id = match loc { WellFormedLoc::Ty(def_id) => def_id, - WellFormedLoc::Param { function, param_idx: _ } => function, + WellFormedLoc::Param { function, .. } => function, + WellFormedLoc::HirId(_) | WellFormedLoc::None => return None, }; let hir_id = tcx.local_def_id_to_hir_id(def_id); @@ -85,7 +86,7 @@ pub(super) fn diagnostic_hir_wf_check<'tcx>( let cause = traits::ObligationCause::new( ty.span, self.def_id, - traits::ObligationCauseCode::WellFormed(None), + traits::ObligationCauseCode::WellFormed(WellFormedLoc::HirId(ty.hir_id)), ); ocx.register_obligation(traits::Obligation::new( @@ -191,7 +192,7 @@ pub(super) fn diagnostic_hir_wf_check<'tcx>( } ref node => bug!("Unexpected node {:?}", node), }, - WellFormedLoc::Param { function: _, param_idx } => { + WellFormedLoc::Param { param_idx, .. } => { let fn_decl = tcx.hir_fn_decl_by_hir_id(hir_id).unwrap(); // Get return type if param_idx as usize == fn_decl.inputs.len() { @@ -204,6 +205,7 @@ pub(super) fn diagnostic_hir_wf_check<'tcx>( vec![&fn_decl.inputs[param_idx as usize]] } } + WellFormedLoc::HirId(_) | WellFormedLoc::None => return None, }; for ty in tys { visitor.visit_ty_unambig(ty); diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 025c64896edb7..5ddbb3c502c98 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -11,7 +11,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, HirId}; use rustc_hir_analysis::autoderef::Autoderef; use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes}; -use rustc_infer::traits::{Obligation, ObligationCause, ObligationCauseCode}; +use rustc_infer::traits::{Obligation, ObligationCause, ObligationCauseCode, WellFormedLoc}; use rustc_middle::ty::adjustment::{ Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, }; @@ -177,7 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.register_wf_obligation( output.into(), call_expr.span, - ObligationCauseCode::WellFormed(None), + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(call_expr.hir_id)), ); output @@ -728,7 +728,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // now we have to unify it with signature input in order to resolve // all inference variables. After that we update input signature for // adjustments search for mapped arguments. - let cause = self.cause(call_expr.span, ObligationCauseCode::Misc); + let cause = self.cause( + call_expr.span, + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(call_expr.hir_id)), + ); if self .at(&cause, self.param_env) .sup(DefineOpaqueTypes::Yes, formal_input_tys[0], adjusted_arg_type) diff --git a/compiler/rustc_hir_typeck/src/check.rs b/compiler/rustc_hir_typeck/src/check.rs index b1b7aa5727097..8061e522f43aa 100644 --- a/compiler/rustc_hir_typeck/src/check.rs +++ b/compiler/rustc_hir_typeck/src/check.rs @@ -72,10 +72,10 @@ pub(super) fn check_fn<'a, 'tcx>( fcx.register_wf_obligation( param_ty.into(), param.span, - ObligationCauseCode::WellFormed(Some(WellFormedLoc::Param { + ObligationCauseCode::WellFormed(WellFormedLoc::Param { function: fn_def_id, param_idx: idx, - })), + }), ); } diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 9f0d00d5274fa..a301cb6a397d9 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -25,6 +25,7 @@ use rustc_hir::{ExprKind, HirId, QPath, is_range_literal}; use rustc_hir_analysis::diagnostics::{NoFieldOnType, NoVariantNamed}; use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer as _; use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk, RegionVariableOrigin}; +use rustc_infer::traits::WellFormedLoc; use rustc_infer::traits::query::NoSolution; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase}; use rustc_middle::ty::consts::ConstExt; @@ -699,14 +700,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.require_type_is_sized_deferred( output, call_expr_and_args.map_or(expr.span, |(e, _)| e.span), - ObligationCauseCode::SizedCallReturnType, + ObligationCauseCode::SizedCallReturnType(expr.hir_id), ); } // We always require that the type provided as the value for // a type parameter outlives the moment of instantiation. let args = self.typeck_results.borrow().node_args(expr.hir_id); - self.add_wf_bounds(args, expr.span); + self.add_wf_bounds(args, expr.span, expr.hir_id); ty } @@ -1772,7 +1773,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.deferred_repeat_expr_checks.borrow_mut().push((element, element_ty, count)); let ty = Ty::new_array_with_const_len(tcx, t, count); - self.register_wf_obligation(ty.into(), expr.span, ObligationCauseCode::WellFormed(None)); + self.register_wf_obligation( + ty.into(), + expr.span, + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(expr.hir_id)), + ); ty } @@ -1944,7 +1949,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.register_wf_obligation( field_type.into(), field.expr.span, - ObligationCauseCode::WellFormed(None), + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(field.expr.hir_id)), ); // Make sure to give a type to the field even if there's @@ -3895,7 +3900,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.require_type_is_sized( field_ty, expr.span, - ObligationCauseCode::Misc, + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(expr.hir_id)), ); } @@ -3924,7 +3929,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.require_type_is_sized( field_ty, expr.span, - ObligationCauseCode::Misc, + ObligationCauseCode::WellFormed(WellFormedLoc::HirId( + expr.hir_id, + )), ); } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 1ad6225a8c467..b0f940dd7a21a 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -22,7 +22,7 @@ use rustc_hir_analysis::hir_ty_lowering::{ }; use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse}; use rustc_infer::infer::{DefineOpaqueTypes, InferResult}; -use rustc_infer::traits::TraitErrors; +use rustc_infer::traits::{TraitErrors, WellFormedLoc}; use rustc_lint_defs::builtin::{SELF_CONSTRUCTOR_FROM_OUTER_ITEM, UNREACHABLE_CODE}; use rustc_middle::ty::adjustment::{ Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, DerefAdjustKind, @@ -543,7 +543,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn lower_ty(&self, hir_ty: &hir::Ty<'_>) -> LoweredTy<'tcx> { let ty = self.lowerer().lower_ty(hir_ty); - self.register_wf_obligation(ty.into(), hir_ty.span, ObligationCauseCode::WellFormed(None)); + self.register_wf_obligation( + ty.into(), + hir_ty.span, + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(hir_ty.hir_id)), + ); LoweredTy::from_raw(self, hir_ty.span, ty) } @@ -608,7 +612,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.register_wf_obligation( ct.into(), self.tcx.hir_span(const_arg.hir_id), - ObligationCauseCode::WellFormed(None), + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(const_arg.hir_id)), ); ct } @@ -664,9 +668,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } /// Registers obligations that all `args` are well-formed. - pub(crate) fn add_wf_bounds(&self, args: GenericArgsRef<'tcx>, span: Span) { + pub(crate) fn add_wf_bounds(&self, args: GenericArgsRef<'tcx>, span: Span, hir_id: HirId) { for term in args.iter().filter_map(ty::GenericArg::as_term) { - self.register_wf_obligation(term, span, ObligationCauseCode::WellFormed(None)); + self.register_wf_obligation( + term, + span, + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(hir_id)), + ); } } @@ -810,7 +818,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.register_wf_obligation( ty.raw.into(), qself.span, - ObligationCauseCode::WellFormed(None), + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(hir_id)), ); self.select_obligations_where_possible(|_| {}); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 937182c2030da..8ecd7838a0e69 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -19,6 +19,7 @@ use rustc_index::IndexVec; use rustc_infer::infer::{ BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TypeTrace, relate, }; +use rustc_infer::traits::WellFormedLoc; use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::print::with_forced_trimmed_paths; @@ -230,7 +231,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.register_wf_obligation( fn_input_ty.into(), arg_expr.span, - ObligationCauseCode::WellFormed(None), + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(arg_expr.hir_id)), ); self.check_place_expr_if_unsized(fn_input_ty, arg_expr); @@ -1197,7 +1198,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.register_wf_obligation( decl_ty.into(), decl.pat.span, - ObligationCauseCode::WellFormed(None), + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(decl.pat.hir_id)), ); } self.overwrite_local_ty_if_err(decl.hir_id, decl.pat, pat_ty); diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 5efb2775c77fe..2945a6b3b5136 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -193,7 +193,7 @@ fn typeck_with_inspect<'tcx>( let expected_type = fcx.normalize(body.value.span, Unnormalized::new_wip(expected_type)); - let wf_code = ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(def_id))); + let wf_code = ObligationCauseCode::WellFormed(WellFormedLoc::Ty(def_id)); fcx.register_wf_obligation(expected_type.into(), body.value.span, wf_code); if let hir::Node::AnonConst(_) = node { diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 4518e419aea0f..721e9a38fc50c 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -13,6 +13,7 @@ use rustc_hir_analysis::hir_ty_lowering::{ use rustc_infer::infer::{ BoundRegionConversionTime, DefineOpaqueTypes, InferOk, RegionVariableOrigin, }; +use rustc_infer::traits::WellFormedLoc; use rustc_lint_defs::builtin::{ AMBIGUOUS_GLOB_IMPORTED_TRAITS, RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS, }; @@ -648,7 +649,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // this is a projection from a trait reference, so we have to // make sure that the trait reference inputs are well-formed. - self.add_wf_bounds(all_args, self.call_expr.span); + self.add_wf_bounds(all_args, self.call_expr.span, self.call_expr.hir_id); // the function type must also be well-formed (this is not // implied by the args being well-formed because of inherent @@ -657,7 +658,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { self.register_wf_obligation( ty.into(), self.span, - ObligationCauseCode::WellFormed(None), + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(self.call_expr.hir_id)), ); } } diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 341ea9a70dbc7..6a34bd4884d73 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -78,6 +78,7 @@ impl<'tcx> InferCtxt<'tcx> { selection_cache: self.selection_cache.clone(), evaluation_cache: self.evaluation_cache.clone(), reported_trait_errors: self.reported_trait_errors.clone(), + reported_hir_errors: self.reported_hir_errors.clone(), reported_signature_mismatch: self.reported_signature_mismatch.clone(), tainted_by_errors: self.tainted_by_errors.clone(), universe: self.universe.clone(), @@ -108,6 +109,7 @@ impl<'tcx> InferCtxt<'tcx> { selection_cache: Default::default(), evaluation_cache: Default::default(), reported_trait_errors: self.reported_trait_errors.clone(), + reported_hir_errors: self.reported_hir_errors.clone(), reported_signature_mismatch: self.reported_signature_mismatch.clone(), tainted_by_errors: self.tainted_by_errors.clone(), universe: self.universe.clone(), diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index a7ce6a4353b59..c45c5e44aaa31 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -307,6 +307,11 @@ pub struct InferCtxt<'tcx> { pub reported_trait_errors: RefCell>>, ErrorGuaranteed)>>, + /// A set of predicates *on a specific* HIR node (the originating expression and its enclosing + /// statement), to avoid reporting multiple errors pointing at different sub-expressions in the + /// same method chain. + pub reported_hir_errors: RefCell>>>, + pub reported_signature_mismatch: RefCell)>>, /// When an error occurs, we want to avoid reporting "derived" @@ -689,6 +694,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> { selection_cache: Default::default(), evaluation_cache: Default::default(), reported_trait_errors: Default::default(), + reported_hir_errors: Default::default(), reported_signature_mismatch: Default::default(), tainted_by_errors: Cell::new(None), universe: Cell::new(ty::UniverseIndex::ROOT), diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 493f6989f342c..7c4c2d5aed157 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -238,7 +238,7 @@ pub enum ObligationCauseCode<'tcx> { /// Return type must be `Sized`. SizedReturnType, /// Return type of a call expression must be `Sized`. - SizedCallReturnType, + SizedCallReturnType(HirId), /// Yield type must be `Sized`. SizedYieldType, /// Inline asm operand type must be `Sized`. @@ -384,7 +384,7 @@ pub enum ObligationCauseCode<'tcx> { /// This is purely for diagnostic purposes - it is always /// correct to use `Misc` instead, or to specify /// `WellFormed(None)`. - WellFormed(Option), + WellFormed(WellFormedLoc), /// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching /// against. @@ -461,6 +461,8 @@ pub enum WellFormedLoc { /// being the last 'parameter' param_idx: usize, }, + HirId(HirId), + None, } impl<'tcx> ObligationCauseCode<'tcx> { diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs index 961d39ec8e5ca..31490a49b695c 100644 --- a/compiler/rustc_passes/src/layout_test.rs +++ b/compiler/rustc_passes/src/layout_test.rs @@ -41,7 +41,7 @@ pub fn ensure_wf<'tcx>( traits::ObligationCause::new( span, def_id, - traits::ObligationCauseCode::WellFormed(Some(traits::WellFormedLoc::Ty(def_id))), + traits::ObligationCauseCode::WellFormed(traits::WellFormedLoc::Ty(def_id)), ), param_env, pred, diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 3b21c5e5f19ba..1614899ece03d 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -21,7 +21,7 @@ use rustc_hir::intravisit::Visitor; use rustc_hir::{self as hir, Node, expr_needs_parens}; use rustc_infer::infer::{InferOk, TypeTrace}; use rustc_infer::traits::solve::Goal; -use rustc_infer::traits::{ImplSource, TraitErrors}; +use rustc_infer::traits::{ImplSource, TraitErrors, WellFormedLoc}; use rustc_middle::traits::SignatureMismatchData; use rustc_middle::traits::select::OverflowError; use rustc_middle::ty::abstract_const::NotConstEvaluatable; @@ -74,9 +74,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { SelectionError::Unimplemented => { // If this obligation was generated as a result of well-formedness checking, see if we // can get a better error message by performing HIR-based well-formedness checking. - if let ObligationCauseCode::WellFormed(Some(wf_loc)) = + if let ObligationCauseCode::WellFormed(wf_loc) = root_obligation.cause.code().peel_derives() && !obligation.predicate.has_non_region_infer() + && !matches!(wf_loc, WellFormedLoc::None) { if let Some(cause) = self.tcx.diagnostic_hir_wf_check(( tcx.erase_and_anonymize_regions(obligation.predicate), @@ -831,6 +832,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { }; self.note_obligation_cause(&mut err, &obligation); + self.silence_redundant_cause(&mut err, &obligation, &root_obligation); err.emit_err() } } @@ -3083,6 +3085,61 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } } + /// Register when multiple obligations come from the same statement and only emit one. + /// + /// This can significantly reduce the number of `_: Sized` failures on method chains. + fn silence_redundant_cause( + &self, + err: &mut Diag<'_>, + obligation: &PredicateObligation<'tcx>, + root_obligation: &PredicateObligation<'tcx>, + ) { + let hir_id = match root_obligation.cause.code() { + ObligationCauseCode::WellFormed(WellFormedLoc::HirId(hir_id)) + | ObligationCauseCode::VariableType(hir_id) + | ObligationCauseCode::WhereClauseInExpr(_, _, hir_id, _) + | ObligationCauseCode::SizedCallReturnType(hir_id) => *hir_id, + ObligationCauseCode::WellFormed(WellFormedLoc::Param { function, .. }) => { + self.tcx.local_def_id_to_hir_id(*function) + } + _ => return, + }; + + // The lifetimes for different sub-expressions would be different inference variables. + let pred = self.tcx.erase_and_anonymize_regions(obligation.predicate); + + // Registering the expression itself is necessary to catch tail expressions and literals. + if let Some(preds) = self.reported_hir_errors.borrow().get(&hir_id) + && preds.contains(&pred) + { + err.downgrade_to_delayed_bug(); + } else { + self.reported_hir_errors.borrow_mut().entry(hir_id).or_default().insert(pred); + } + + // Look for the expression's parent statement, bail otherwise. We'll register the predicate + // against the statement's HirId. + for (_, node) in self.tcx.hir_parent_iter(hir_id) { + let hir_id = match node { + hir::Node::LetStmt(stmt) => stmt.hir_id, + hir::Node::Stmt(stmt) => stmt.hir_id, + hir::Node::Crate(_) + | hir::Node::Item(_) + | hir::Node::ImplItem(_) + | hir::Node::TraitItem(_) => break, + _ => continue, + }; + if let Some(preds) = self.reported_hir_errors.borrow().get(&hir_id) + && preds.contains(&pred) + { + err.downgrade_to_delayed_bug(); + } else { + self.reported_hir_errors.borrow_mut().entry(hir_id).or_default().insert(pred); + } + break; + } + } + pub fn note_obligation_cause( &self, err: &mut Diag<'_>, diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 76755eb481db7..a2aae724228ba 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -4325,7 +4325,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { err.help("unsized fn params are gated as an unstable feature"); } } - ObligationCauseCode::SizedReturnType | ObligationCauseCode::SizedCallReturnType => { + ObligationCauseCode::SizedReturnType | ObligationCauseCode::SizedCallReturnType(_) => { err.note("the return type of a function must have a statically known size"); } ObligationCauseCode::SizedYieldType => { diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index ba463184a41f8..41e6797e71d2d 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -7,7 +7,9 @@ use std::iter; use rustc_attr_ir::lang_items::LangItem; use rustc_hir as hir; -use rustc_infer::traits::{ObligationCauseCode, PredicateObligation, PredicateObligations}; +use rustc_infer::traits::{ + ObligationCauseCode, PredicateObligation, PredicateObligations, WellFormedLoc, +}; use rustc_middle::ty::{ self, DelayedSet, GenericArgsRef, PredicateProxy, Term, TermKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, @@ -352,7 +354,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { return self.out; } - let cause = self.cause(ObligationCauseCode::WellFormed(None)); + let cause = self.cause(ObligationCauseCode::WellFormed(WellFormedLoc::None)); let param_env = self.param_env; let mut obligations = PredicateObligations::with_capacity(self.out.len()); for mut obligation in self.out { @@ -519,7 +521,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { &mut traits::SelectionContext::new(self.infcx), self.param_env, data, - self.cause(ObligationCauseCode::WellFormed(None)), + self.cause(ObligationCauseCode::WellFormed(WellFormedLoc::None)), self.recursion_depth, &mut self.out, ); @@ -532,7 +534,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { fn add_wf_preds_for_projection_args(&mut self, args: GenericArgsRef<'tcx>) { let tcx = self.tcx(); - let cause = self.cause(ObligationCauseCode::WellFormed(None)); + let cause = self.cause(ObligationCauseCode::WellFormed(WellFormedLoc::None)); let param_env = self.param_env; let depth = self.recursion_depth; @@ -976,7 +978,7 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { let principal_def_id = principal.skip_binder().def_id; self.out.push(traits::Obligation::with_depth( tcx, - self.cause(ObligationCauseCode::WellFormed(None)), + self.cause(ObligationCauseCode::WellFormed(WellFormedLoc::None)), self.recursion_depth, self.param_env, ty::Binder::dummy(ty::PredicateKind::DynCompatible(principal_def_id)), @@ -1044,7 +1046,7 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { if let Some(pred_binder) = pred_binder { self.out.push(traits::Obligation::with_depth( tcx, - self.cause(ObligationCauseCode::WellFormed(None)), + self.cause(ObligationCauseCode::WellFormed(WellFormedLoc::None)), self.recursion_depth, self.param_env, pred_binder, @@ -1067,7 +1069,7 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { // See also the comment on `fn obligations`, describing cycle // prevention, which happens before this can be reached. ty::Infer(_) => { - let cause = self.cause(ObligationCauseCode::WellFormed(None)); + let cause = self.cause(ObligationCauseCode::WellFormed(WellFormedLoc::None)); self.out.push(traits::Obligation::with_depth( tcx, cause, @@ -1094,7 +1096,8 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { let predicate = ty::Binder::dummy(ty::PredicateKind::Clause( ty::ClauseKind::ConstEvaluatable(c), )); - let cause = self.cause(ObligationCauseCode::WellFormed(None)); + let cause = + self.cause(ObligationCauseCode::WellFormed(WellFormedLoc::None)); self.out.push(traits::Obligation::with_depth( tcx, cause, @@ -1128,7 +1131,7 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { } } ty::ConstKind::Infer(_) => { - let cause = self.cause(ObligationCauseCode::WellFormed(None)); + let cause = self.cause(ObligationCauseCode::WellFormed(WellFormedLoc::None)); self.out.push(traits::Obligation::with_depth( tcx, @@ -1151,7 +1154,7 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { let predicate = ty::Binder::dummy(ty::PredicateKind::Clause( ty::ClauseKind::ConstEvaluatable(c), )); - let cause = self.cause(ObligationCauseCode::WellFormed(None)); + let cause = self.cause(ObligationCauseCode::WellFormed(WellFormedLoc::None)); self.out.push(traits::Obligation::with_depth( tcx, cause, @@ -1174,7 +1177,8 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { ty::Adt(adt_def, args) => { let adt_val = val.destructure_adt_const(); let variant_def = adt_def.variant(adt_val.variant); - let cause = self.cause(ObligationCauseCode::WellFormed(None)); + let cause = + self.cause(ObligationCauseCode::WellFormed(WellFormedLoc::None)); self.out.extend(variant_def.fields.iter().zip(adt_val.fields).map( |(field_def, &field_val)| { let field_ty = tcx @@ -1196,7 +1200,8 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { } ty::Tuple(field_tys) => { let field_vals = val.to_branch(); - let cause = self.cause(ObligationCauseCode::WellFormed(None)); + let cause = + self.cause(ObligationCauseCode::WellFormed(WellFormedLoc::None)); self.out.extend(field_tys.iter().zip(field_vals).map( |(field_ty, &field_val)| { let predicate = ty::PredicateKind::Clause( @@ -1214,7 +1219,8 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { } ty::Array(elem_ty, _len) => { let elem_vals = val.to_branch(); - let cause = self.cause(ObligationCauseCode::WellFormed(None)); + let cause = + self.cause(ObligationCauseCode::WellFormed(WellFormedLoc::None)); self.out.extend(elem_vals.iter().map(|&elem_val| { let predicate = ty::PredicateKind::Clause( diff --git a/tests/ui/associated-consts/associated-const-in-trait.rs b/tests/ui/associated-consts/associated-const-in-trait.rs index da68a0fa97c82..90ad596b23ee1 100644 --- a/tests/ui/associated-consts/associated-const-in-trait.rs +++ b/tests/ui/associated-consts/associated-const-in-trait.rs @@ -8,7 +8,6 @@ impl dyn Trait { //~^ ERROR the trait `Trait` is not dyn compatible [E0038] const fn n() -> usize { Self::N } //~^ ERROR the trait `Trait` is not dyn compatible [E0038] - //~| ERROR the trait `Trait` is not dyn compatible [E0038] } fn main() {} diff --git a/tests/ui/associated-consts/associated-const-in-trait.stderr b/tests/ui/associated-consts/associated-const-in-trait.stderr index 4085f8c990785..64ac88856fdc4 100644 --- a/tests/ui/associated-consts/associated-const-in-trait.stderr +++ b/tests/ui/associated-consts/associated-const-in-trait.stderr @@ -30,22 +30,6 @@ LL | const N: usize; | ^ ...because it contains associated const `N` = help: consider moving `N` to another trait -error[E0038]: the trait `Trait` is not dyn compatible - --> $DIR/associated-const-in-trait.rs:9:29 - | -LL | const fn n() -> usize { Self::N } - | ^^^^^^^ `Trait` is not dyn compatible - | -note: for a trait to be dyn compatible it needs to allow building a vtable - for more information, visit - --> $DIR/associated-const-in-trait.rs:4:11 - | -LL | trait Trait { - | ----- this trait is not dyn compatible... -LL | const N: usize; - | ^ ...because it contains associated const `N` - = help: consider moving `N` to another trait - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/associated-types/hr-associated-type-bound-object.rs b/tests/ui/associated-types/hr-associated-type-bound-object.rs index 825e129dbbda1..62ed7c7edfe79 100644 --- a/tests/ui/associated-types/hr-associated-type-bound-object.rs +++ b/tests/ui/associated-types/hr-associated-type-bound-object.rs @@ -8,8 +8,6 @@ fn f<'a, T: X<'a> + ?Sized>(x: &>::U) { //~^ ERROR the trait bound `for<'b> >::U: Clone` is not satisfied <>::U>::clone(x); //~^ ERROR the trait bound `for<'b> >::U: Clone` is not satisfied - //~| ERROR the trait bound `for<'b> >::U: Clone` is not satisfied - //~| ERROR the trait bound `for<'b> >::U: Clone` is not satisfied //~| ERROR the trait bound `>::U: Clone` is not satisfied } diff --git a/tests/ui/associated-types/hr-associated-type-bound-object.stderr b/tests/ui/associated-types/hr-associated-type-bound-object.stderr index d1563c923bc7a..0a6831ad8801b 100644 --- a/tests/ui/associated-types/hr-associated-type-bound-object.stderr +++ b/tests/ui/associated-types/hr-associated-type-bound-object.stderr @@ -48,42 +48,6 @@ help: consider further restricting the associated type LL | fn f<'a, T: X<'a> + ?Sized>(x: &>::U) where >::U: Clone { | ++++++++++++++++++++++++++++ -error[E0277]: the trait bound `for<'b> >::U: Clone` is not satisfied - --> $DIR/hr-associated-type-bound-object.rs:9:5 - | -LL | <>::U>::clone(x); - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'b> Clone` is not implemented for `>::U` - | -note: required by a bound in `X` - --> $DIR/hr-associated-type-bound-object.rs:3:33 - | -LL | trait X<'a> -LL | where -LL | for<'b> >::U: Clone, - | ^^^^^ required by this bound in `X` -help: consider further restricting the associated type - | -LL | fn f<'a, T: X<'a> + ?Sized>(x: &>::U) where for<'b> >::U: Clone { - | ++++++++++++++++++++++++++++++++++++ - -error[E0277]: the trait bound `for<'b> >::U: Clone` is not satisfied - --> $DIR/hr-associated-type-bound-object.rs:9:5 - | -LL | <>::U>::clone(x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'b> Clone` is not implemented for `>::U` - | -note: required by a bound in `X` - --> $DIR/hr-associated-type-bound-object.rs:3:33 - | -LL | trait X<'a> -LL | where -LL | for<'b> >::U: Clone, - | ^^^^^ required by this bound in `X` -help: consider further restricting the associated type - | -LL | fn f<'a, T: X<'a> + ?Sized>(x: &>::U) where for<'b> >::U: Clone { - | ++++++++++++++++++++++++++++++++++++ - -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/associated-types/hr-associated-type-bound-param-2.rs b/tests/ui/associated-types/hr-associated-type-bound-param-2.rs index d6546c24dc50b..7e40cec345f7e 100644 --- a/tests/ui/associated-types/hr-associated-type-bound-param-2.rs +++ b/tests/ui/associated-types/hr-associated-type-bound-param-2.rs @@ -9,8 +9,6 @@ where fn h(&self, x: &T::W) { ::clone(x); //~^ ERROR the trait bound `str: Clone` is not satisfied - //~| ERROR the trait bound `str: Clone` is not satisfied - //~| ERROR the trait bound `str: Clone` is not satisfied } } diff --git a/tests/ui/associated-types/hr-associated-type-bound-param-2.stderr b/tests/ui/associated-types/hr-associated-type-bound-param-2.stderr index f025798750a58..b1a7e8ac4062a 100644 --- a/tests/ui/associated-types/hr-associated-type-bound-param-2.stderr +++ b/tests/ui/associated-types/hr-associated-type-bound-param-2.stderr @@ -15,7 +15,7 @@ LL | for<'b> >::W: Clone, | ^^^^^ required by this bound in `Z` error[E0277]: the trait bound `str: Clone` is not satisfied - --> $DIR/hr-associated-type-bound-param-2.rs:18:14 + --> $DIR/hr-associated-type-bound-param-2.rs:16:14 | LL | type W = str; | ^^^ the trait `Clone` is not implemented for `str` @@ -67,39 +67,7 @@ LL | type W: ?Sized; | error[E0277]: the trait bound `str: Clone` is not satisfied - --> $DIR/hr-associated-type-bound-param-2.rs:10:9 - | -LL | ::clone(x); - | ^^^^^^^^^^^^^ the trait `Clone` is not implemented for `str` - | -help: the trait `Clone` is implemented for `String` - --> $SRC_DIR/alloc/src/string.rs:LL:COL -note: required by a bound in `Z` - --> $DIR/hr-associated-type-bound-param-2.rs:6:35 - | -LL | trait Z<'a, T: ?Sized> -... -LL | for<'b> >::W: Clone, - | ^^^^^ required by this bound in `Z` - -error[E0277]: the trait bound `str: Clone` is not satisfied - --> $DIR/hr-associated-type-bound-param-2.rs:10:9 - | -LL | ::clone(x); - | ^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `str` - | -help: the trait `Clone` is implemented for `String` - --> $SRC_DIR/alloc/src/string.rs:LL:COL -note: required by a bound in `Z` - --> $DIR/hr-associated-type-bound-param-2.rs:6:35 - | -LL | trait Z<'a, T: ?Sized> -... -LL | for<'b> >::W: Clone, - | ^^^^^ required by this bound in `Z` - -error[E0277]: the trait bound `str: Clone` is not satisfied - --> $DIR/hr-associated-type-bound-param-2.rs:23:10 + --> $DIR/hr-associated-type-bound-param-2.rs:21:10 | LL | 1u16.h("abc"); | ^ the trait `Clone` is not implemented for `str` @@ -117,6 +85,6 @@ LL | for<'b> >::W: Clone, LL | fn h(&self, x: &T::W) { | -error: aborting due to 7 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/async-await/async-closures/async-future-out-must-be-sized.rs b/tests/ui/async-await/async-closures/async-future-out-must-be-sized.rs index e5d70e30eb5f6..2daed6b09dcc9 100644 --- a/tests/ui/async-await/async-closures/async-future-out-must-be-sized.rs +++ b/tests/ui/async-await/async-closures/async-future-out-must-be-sized.rs @@ -16,5 +16,4 @@ async fn is_async_fn(f: impl AsyncFn()) { fn main() { is_async_fn(foo()); //~^ ERROR the size for values of type `dyn Future` cannot be known at compilation time - //~| ERROR the size for values of type `dyn Future` cannot be known at compilation time } diff --git a/tests/ui/async-await/async-closures/async-future-out-must-be-sized.stderr b/tests/ui/async-await/async-closures/async-future-out-must-be-sized.stderr index f993247d8b90a..1168a854f5d32 100644 --- a/tests/ui/async-await/async-closures/async-future-out-must-be-sized.stderr +++ b/tests/ui/async-await/async-closures/async-future-out-must-be-sized.stderr @@ -13,19 +13,6 @@ note: required by a bound in `is_async_fn` LL | async fn is_async_fn(f: impl AsyncFn()) { | ^^^^^^^^^ required by this bound in `is_async_fn` -error[E0277]: the size for values of type `dyn Future` cannot be known at compilation time - --> $DIR/async-future-out-must-be-sized.rs:17:5 - | -LL | is_async_fn(foo()); - | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `dyn Future` -note: required by a bound in `is_async_fn` - --> $DIR/async-future-out-must-be-sized.rs:12:30 - | -LL | async fn is_async_fn(f: impl AsyncFn()) { - | ^^^^^^^^^ required by this bound in `is_async_fn` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/box/into-boxed-slice-fail.rs b/tests/ui/box/into-boxed-slice-fail.rs index 49dbb170f8e78..db2e5623264e6 100644 --- a/tests/ui/box/into-boxed-slice-fail.rs +++ b/tests/ui/box/into-boxed-slice-fail.rs @@ -6,9 +6,7 @@ fn main() { let boxed_slice = Box::new([1,2,3]) as Box<[u8]>; let _ = Box::into_boxed_slice(boxed_slice); //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time - //~^^ ERROR the size for values of type `[u8]` cannot be known at compilation time let boxed_trait: Box = Box::new(5u8); let _ = Box::into_boxed_slice(boxed_trait); //~^ ERROR the size for values of type `dyn Debug` cannot be known at compilation time - //~^^ ERROR the size for values of type `dyn Debug` cannot be known at compilation time } diff --git a/tests/ui/box/into-boxed-slice-fail.stderr b/tests/ui/box/into-boxed-slice-fail.stderr index f102f666dc276..a66fa533c6f02 100644 --- a/tests/ui/box/into-boxed-slice-fail.stderr +++ b/tests/ui/box/into-boxed-slice-fail.stderr @@ -10,17 +10,8 @@ LL | let _ = Box::into_boxed_slice(boxed_slice); note: required by a bound in `Box::::into_boxed_slice` --> $SRC_DIR/alloc/src/boxed.rs:LL:COL -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/into-boxed-slice-fail.rs:7:13 - | -LL | let _ = Box::into_boxed_slice(boxed_slice); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: slice and array elements must have `Sized` type - error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time - --> $DIR/into-boxed-slice-fail.rs:11:35 + --> $DIR/into-boxed-slice-fail.rs:10:35 | LL | let _ = Box::into_boxed_slice(boxed_trait); | --------------------- ^^^^^^^^^^^ doesn't have a size known at compile-time @@ -31,15 +22,6 @@ LL | let _ = Box::into_boxed_slice(boxed_trait); note: required by a bound in `Box::::into_boxed_slice` --> $SRC_DIR/alloc/src/boxed.rs:LL:COL -error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time - --> $DIR/into-boxed-slice-fail.rs:11:13 - | -LL | let _ = Box::into_boxed_slice(boxed_trait); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `dyn Debug` - = note: slice and array elements must have `Sized` type - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/closures/unsized-return-suggest-ref-issue-152064.fixed b/tests/ui/closures/unsized-return-suggest-ref-issue-152064.fixed deleted file mode 100644 index 2e1d10fb2804c..0000000000000 --- a/tests/ui/closures/unsized-return-suggest-ref-issue-152064.fixed +++ /dev/null @@ -1,18 +0,0 @@ -#![allow(unused_variables, for_loops_over_fallibles)] -//@ run-rustfix - -fn main() { - // Basic case from the issue: str slice - let o = Some("Hello, world!"); - for s in o.map(|s| &s[3..8]) {} - //~^ ERROR the size for values of type `str` cannot be known at compilation time - //~| ERROR the size for values of type `str` cannot be known at compilation time - //~| ERROR `Option` is not an iterator - - // Byte slice case - let arr = Some(b"Hello, world!"); - for s in arr.map(|s| &s[3..8]) {} - //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time - //~| ERROR the size for values of type `[u8]` cannot be known at compilation time - //~| ERROR `Option<[u8]>` is not an iterator -} diff --git a/tests/ui/closures/unsized-return-suggest-ref-issue-152064.rs b/tests/ui/closures/unsized-return-suggest-ref-issue-152064.rs index 6a0573248ff8b..f88bf3c908685 100644 --- a/tests/ui/closures/unsized-return-suggest-ref-issue-152064.rs +++ b/tests/ui/closures/unsized-return-suggest-ref-issue-152064.rs @@ -1,18 +1,15 @@ #![allow(unused_variables, for_loops_over_fallibles)] -//@ run-rustfix fn main() { // Basic case from the issue: str slice let o = Some("Hello, world!"); for s in o.map(|s| s[3..8]) {} //~^ ERROR the size for values of type `str` cannot be known at compilation time - //~| ERROR the size for values of type `str` cannot be known at compilation time //~| ERROR `Option` is not an iterator // Byte slice case let arr = Some(b"Hello, world!"); for s in arr.map(|s| s[3..8]) {} //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time - //~| ERROR the size for values of type `[u8]` cannot be known at compilation time //~| ERROR `Option<[u8]>` is not an iterator } diff --git a/tests/ui/closures/unsized-return-suggest-ref-issue-152064.stderr b/tests/ui/closures/unsized-return-suggest-ref-issue-152064.stderr index c5e5e71cd8823..de08baa48461a 100644 --- a/tests/ui/closures/unsized-return-suggest-ref-issue-152064.stderr +++ b/tests/ui/closures/unsized-return-suggest-ref-issue-152064.stderr @@ -1,5 +1,5 @@ error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/unsized-return-suggest-ref-issue-152064.rs:7:16 + --> $DIR/unsized-return-suggest-ref-issue-152064.rs:6:16 | LL | for s in o.map(|s| s[3..8]) {} | ^^^ doesn't have a size known at compile-time @@ -8,22 +8,8 @@ LL | for s in o.map(|s| s[3..8]) {} note: required by an implicit `Sized` bound in `Option::::map` --> $SRC_DIR/core/src/option.rs:LL:COL -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/unsized-return-suggest-ref-issue-152064.rs:7:14 - | -LL | for s in o.map(|s| s[3..8]) {} - | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `str` -note: required by an implicit `Sized` bound in `Option` - --> $SRC_DIR/core/src/option.rs:LL:COL -help: consider borrowing the value - | -LL | for s in o.map(|s| &s[3..8]) {} - | + - error[E0277]: `Option` is not an iterator - --> $DIR/unsized-return-suggest-ref-issue-152064.rs:7:14 + --> $DIR/unsized-return-suggest-ref-issue-152064.rs:6:14 | LL | for s in o.map(|s| s[3..8]) {} | ^^^^^^^^^^^^^^^^^^ `Option` is not an iterator @@ -41,7 +27,7 @@ help: the following other types implement trait `IntoIterator` = note: `&mut Option` error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/unsized-return-suggest-ref-issue-152064.rs:14:18 + --> $DIR/unsized-return-suggest-ref-issue-152064.rs:12:18 | LL | for s in arr.map(|s| s[3..8]) {} | ^^^ doesn't have a size known at compile-time @@ -50,22 +36,8 @@ LL | for s in arr.map(|s| s[3..8]) {} note: required by an implicit `Sized` bound in `Option::::map` --> $SRC_DIR/core/src/option.rs:LL:COL -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/unsized-return-suggest-ref-issue-152064.rs:14:14 - | -LL | for s in arr.map(|s| s[3..8]) {} - | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` -note: required by an implicit `Sized` bound in `Option` - --> $SRC_DIR/core/src/option.rs:LL:COL -help: consider borrowing the value - | -LL | for s in arr.map(|s| &s[3..8]) {} - | + - error[E0277]: `Option<[u8]>` is not an iterator - --> $DIR/unsized-return-suggest-ref-issue-152064.rs:14:14 + --> $DIR/unsized-return-suggest-ref-issue-152064.rs:12:14 | LL | for s in arr.map(|s| s[3..8]) {} | ^^^^^^^^^^^^^^^^^^^^ `Option<[u8]>` is not an iterator @@ -82,6 +54,6 @@ help: the following other types implement trait `IntoIterator` | = note: `&mut Option` -error: aborting due to 6 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.rs b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.rs index e575d0dc9b405..58936f3e741ec 100644 --- a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.rs +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.rs @@ -16,11 +16,11 @@ where { foo::<_, L>([(); L + 1 + L]); //~^ ERROR: mismatched types - //~^^ ERROR: unconstrained generic constant - //~^^^ ERROR: function takes 1 generic argument but 2 generic arguments were supplied - //~^^^^ ERROR: unconstrained generic constant - //~^^^^^ ERROR: unconstrained generic constant `L + 1 + L` - //~^^^^^^ ERROR: unconstrained generic constant `L + 1` + //~| ERROR: unconstrained generic constant + //~| ERROR: function takes 1 generic argument but 2 generic arguments were supplied + //~| ERROR: unconstrained generic constant + //~| ERROR: unconstrained generic constant `L + 1 + L` + //~| ERROR: unconstrained generic constant `L + 1` } fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs b/tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs index 304c176e85ae9..083c3bf47aad7 100644 --- a/tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs +++ b/tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs @@ -7,8 +7,6 @@ fn user() { let _ = const_evaluatable_lib::test1::(); //~^ ERROR unconstrained generic constant //~| ERROR unconstrained generic constant - //~| ERROR unconstrained generic constant - //~| ERROR unconstrained generic constant } fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.stderr b/tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.stderr index 5c2d9d22c48f0..c45509656ab36 100644 --- a/tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.stderr +++ b/tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.stderr @@ -32,34 +32,5 @@ help: try adding a `where` bound LL | fn user() where [(); std::mem::size_of::() - 1]: { | +++++++++++++++++++++++++++++++++++++++++ -error: unconstrained generic constant - --> $DIR/cross_crate_predicate.rs:7:13 - | -LL | let _ = const_evaluatable_lib::test1::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try adding a `where` bound - | -LL | fn user() where [(); std::mem::size_of::() - 1]: { - | +++++++++++++++++++++++++++++++++++++++++ - -error: unconstrained generic constant - --> $DIR/cross_crate_predicate.rs:7:13 - | -LL | let _ = const_evaluatable_lib::test1::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: required by a bound in `test1` - --> $DIR/auxiliary/const_evaluatable_lib.rs:5:10 - | -LL | pub fn test1() -> [u8; std::mem::size_of::() - 1] -LL | where -LL | [u8; std::mem::size_of::() - 1]: Sized, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `test1` -help: try adding a `where` bound - | -LL | fn user() where [(); std::mem::size_of::() - 1]: { - | +++++++++++++++++++++++++++++++++++++++++ - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/generic_const_exprs/dependence_lint.full.stderr b/tests/ui/const-generics/generic_const_exprs/dependence_lint.full.stderr index 810a87c35aed8..05c8f1e945ccc 100644 --- a/tests/ui/const-generics/generic_const_exprs/dependence_lint.full.stderr +++ b/tests/ui/const-generics/generic_const_exprs/dependence_lint.full.stderr @@ -1,5 +1,5 @@ error: generic parameters may not be used in const operations - --> $DIR/dependence_lint.rs:15:32 + --> $DIR/dependence_lint.rs:14:32 | LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce | ^ cannot perform const operation using `T` @@ -9,7 +9,7 @@ LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce = help: alternatively, you can use `#![feature(gca_const_items)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/dependence_lint.rs:22:37 + --> $DIR/dependence_lint.rs:21:37 | LL | let _: [u8; if true { size_of::() } else { 3 }]; // error on stable, error with gce | ^ cannot perform const operation using `T` @@ -29,7 +29,7 @@ LL | [0; size_of::<*mut T>()]; // lint on stable, error with `generic_const_ = note: `#[warn(const_evaluatable_unchecked)]` (part of `#[warn(future_incompatible)]`) on by default warning: cannot use constants which depend on generic parameters in types - --> $DIR/dependence_lint.rs:18:9 + --> $DIR/dependence_lint.rs:17:9 | LL | [0; if false { size_of::() } else { 3 }]; // lint on stable, error with gce | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/const-generics/generic_const_exprs/dependence_lint.gce.stderr b/tests/ui/const-generics/generic_const_exprs/dependence_lint.gce.stderr index 12ac980c97544..f6119c17bf47e 100644 --- a/tests/ui/const-generics/generic_const_exprs/dependence_lint.gce.stderr +++ b/tests/ui/const-generics/generic_const_exprs/dependence_lint.gce.stderr @@ -9,19 +9,8 @@ help: try adding a `where` bound LL | fn foo() where [(); size_of::<*mut T>()]: { | ++++++++++++++++++++++++++++++++ -error: unconstrained generic constant - --> $DIR/dependence_lint.rs:10:5 - | -LL | [0; size_of::<*mut T>()]; // lint on stable, error with `generic_const_exprs` - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try adding a `where` bound - | -LL | fn foo() where [(); size_of::<*mut T>()]: { - | ++++++++++++++++++++++++++++++++ - error: overly complex generic constant - --> $DIR/dependence_lint.rs:18:9 + --> $DIR/dependence_lint.rs:17:9 | LL | [0; if false { size_of::() } else { 3 }]; // lint on stable, error with gce | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ control flow is not supported in generic constants @@ -29,7 +18,7 @@ LL | [0; if false { size_of::() } else { 3 }]; // lint on stable, error w = help: consider moving this anonymous constant into a `const` function error: unconstrained generic constant - --> $DIR/dependence_lint.rs:15:12 + --> $DIR/dependence_lint.rs:14:12 | LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,12 +29,12 @@ LL | fn foo() where [(); size_of::<*mut T>()]: { | ++++++++++++++++++++++++++++++++ error: overly complex generic constant - --> $DIR/dependence_lint.rs:22:17 + --> $DIR/dependence_lint.rs:21:17 | LL | let _: [u8; if true { size_of::() } else { 3 }]; // error on stable, error with gce | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ control flow is not supported in generic constants | = help: consider moving this anonymous constant into a `const` function -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors diff --git a/tests/ui/const-generics/generic_const_exprs/dependence_lint.rs b/tests/ui/const-generics/generic_const_exprs/dependence_lint.rs index 6b3c8f84be3d1..107466cd1d9ca 100644 --- a/tests/ui/const-generics/generic_const_exprs/dependence_lint.rs +++ b/tests/ui/const-generics/generic_const_exprs/dependence_lint.rs @@ -9,8 +9,7 @@ use std::mem::size_of; fn foo() { [0; size_of::<*mut T>()]; // lint on stable, error with `generic_const_exprs` //[gce]~^ ERROR unconstrained - //[gce]~| ERROR unconstrained generic constant - //[full]~^^^ WARNING cannot use constants + //[full]~^^ WARNING cannot use constants //[full]~| WARNING this was previously accepted let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce //[full]~^ ERROR generic parameters may not be used diff --git a/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.rs b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.rs index 8243803c86d70..80c2863418929 100644 --- a/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.rs +++ b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.rs @@ -10,8 +10,6 @@ trait Bop { fn bop() { let _ = ::Bar::default(); //~^ ERROR: the size for values of type `T` cannot be known at compilation time - //~| ERROR: the size for values of type `T` cannot be known at compilation time - //~| ERROR: the size for values of type `T` cannot be known at compilation time } fn main() { diff --git a/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.stderr b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.stderr index 26f00fc72f868..9eb4e5bf5ef05 100644 --- a/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.stderr +++ b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.stderr @@ -24,58 +24,6 @@ help: consider relaxing the implicit `Sized` restriction LL | type Bar: Default + ?Sized | ++++++++ -error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/assoc_type_bounds_sized_used.rs:11:13 - | -LL | fn bop() { - | - this type parameter needs to be `Sized` -LL | let _ = ::Bar::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | -note: required by a bound in `Bop::Bar` - --> $DIR/assoc_type_bounds_sized_used.rs:7:15 - | -LL | trait Bop { -LL | type Bar: Default -LL | where -LL | Self: Sized; - | ^^^^^ required by this bound in `Bop::Bar` -help: consider removing the `?Sized` bound to make the type parameter `Sized` - | -LL - fn bop() { -LL + fn bop() { - | -help: consider relaxing the implicit `Sized` restriction - | -LL | type Bar: Default + ?Sized - | ++++++++ - -error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/assoc_type_bounds_sized_used.rs:11:13 - | -LL | fn bop() { - | - this type parameter needs to be `Sized` -LL | let _ = ::Bar::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | -note: required by a bound in `Bop::Bar` - --> $DIR/assoc_type_bounds_sized_used.rs:7:15 - | -LL | trait Bop { -LL | type Bar: Default -LL | where -LL | Self: Sized; - | ^^^^^ required by this bound in `Bop::Bar` -help: consider removing the `?Sized` bound to make the type parameter `Sized` - | -LL - fn bop() { -LL + fn bop() { - | -help: consider relaxing the implicit `Sized` restriction - | -LL | type Bar: Default + ?Sized - | ++++++++ - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/iterators/collect-into-slice.rs b/tests/ui/iterators/collect-into-slice.rs index c90cfa4e90d3a..462110d788106 100644 --- a/tests/ui/iterators/collect-into-slice.rs +++ b/tests/ui/iterators/collect-into-slice.rs @@ -6,14 +6,11 @@ fn main() { let some_generated_vec = (0..10).collect(); //~^ ERROR the size for values of type `[i32]` cannot be known at compilation time //~| NOTE required by a bound introduced by this call - //~| ERROR the size for values of type `[i32]` cannot be known at compilation time //~| ERROR a slice of type `[i32]` cannot be built since `[i32]` has no definite size //~| NOTE try explicitly collecting into a `Vec<{integer}>` - //~| NOTE required by an implicit `Sized` bound in `collect` //~| NOTE required by a bound in `collect` //~| NOTE all local variables must have a statically known size //~| NOTE doesn't have a size known at compile-time - //~| NOTE doesn't have a size known at compile-time process_slice(&some_generated_vec); let some_generated_vec = (0..10).collect(); diff --git a/tests/ui/iterators/collect-into-slice.stderr b/tests/ui/iterators/collect-into-slice.stderr index b5444a71cc177..f910bae958240 100644 --- a/tests/ui/iterators/collect-into-slice.stderr +++ b/tests/ui/iterators/collect-into-slice.stderr @@ -19,18 +19,8 @@ LL | let some_generated_vec = (0..10).collect(); = help: the trait `Sized` is not implemented for `[i32]` = note: all local variables must have a statically known size -error[E0277]: the size for values of type `[i32]` cannot be known at compilation time - --> $DIR/collect-into-slice.rs:6:38 - | -LL | let some_generated_vec = (0..10).collect(); - | ^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[i32]` -note: required by an implicit `Sized` bound in `collect` - --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL - error[E0277]: a slice of type `&[i32]` cannot be built since we need to store the elements somewhere - --> $DIR/collect-into-slice.rs:19:31 + --> $DIR/collect-into-slice.rs:16:31 | LL | let some_generated_vec = (0..10).collect(); | ^^^^^ ------- required by a bound introduced by this call @@ -41,6 +31,6 @@ LL | let some_generated_vec = (0..10).collect(); note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/iterators/iter-macro-not-async-closure.current.stderr b/tests/ui/iterators/iter-macro-not-async-closure.current.stderr index c896d226a7715..ca20bbf4e3150 100644 --- a/tests/ui/iterators/iter-macro-not-async-closure.current.stderr +++ b/tests/ui/iterators/iter-macro-not-async-closure.current.stderr @@ -12,42 +12,6 @@ note: required by a bound in `call_async_once` LL | async fn call_async_once(f: impl AsyncFnOnce()) { | ^^^^^^^^^^^^^ required by this bound in `call_async_once` -error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied - --> $DIR/iter-macro-not-async-closure.rs:31:18 - | -LL | let x = pin!(call_async_once(f)); - | ^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}` - | -note: required by a bound in `call_async_once` - --> $DIR/iter-macro-not-async-closure.rs:20:34 - | -LL | async fn call_async_once(f: impl AsyncFnOnce()) { - | ^^^^^^^^^^^^^ required by this bound in `call_async_once` - -error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied - --> $DIR/iter-macro-not-async-closure.rs:31:13 - | -LL | let x = pin!(call_async_once(f)); - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}` - | -note: required by a bound in `call_async_once` - --> $DIR/iter-macro-not-async-closure.rs:20:34 - | -LL | async fn call_async_once(f: impl AsyncFnOnce()) { - | ^^^^^^^^^^^^^ required by this bound in `call_async_once` - -error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied - --> $DIR/iter-macro-not-async-closure.rs:31:13 - | -LL | let x = pin!(call_async_once(f)); - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}` - | -note: required by a bound in `call_async_once` - --> $DIR/iter-macro-not-async-closure.rs:20:34 - | -LL | async fn call_async_once(f: impl AsyncFnOnce()) { - | ^^^^^^^^^^^^^ required by this bound in `call_async_once` - error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied --> $DIR/iter-macro-not-async-closure.rs:31:13 | @@ -61,7 +25,7 @@ LL | async fn call_async_once(f: impl AsyncFnOnce()) { | ^^^^^^^^^^^^^ required by this bound in `call_async_once` error[E0277]: the trait bound `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}: AsyncFnOnce()` is not satisfied - --> $DIR/iter-macro-not-async-closure.rs:37:5 + --> $DIR/iter-macro-not-async-closure.rs:34:5 | LL | x.poll(&mut Context::from_waker(Waker::noop())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsyncFnOnce()` is not implemented for `{gen closure@$DIR/iter-macro-not-async-closure.rs:25:21: 25:28}` @@ -72,6 +36,6 @@ note: required by a bound in `call_async_once` LL | async fn call_async_once(f: impl AsyncFnOnce()) { | ^^^^^^^^^^^^^ required by this bound in `call_async_once` -error: aborting due to 6 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/iterators/iter-macro-not-async-closure.rs b/tests/ui/iterators/iter-macro-not-async-closure.rs index 3cf9e2237d2e7..1736423065396 100644 --- a/tests/ui/iterators/iter-macro-not-async-closure.rs +++ b/tests/ui/iterators/iter-macro-not-async-closure.rs @@ -30,10 +30,7 @@ fn main() { let x = pin!(call_async_once(f)); //[current]~^ ERROR AsyncFnOnce()` is not satisfied - //[current]~^^ ERROR AsyncFnOnce()` is not satisfied - //[current]~^^^ ERROR AsyncFnOnce()` is not satisfied - //[current]~^^^^ ERROR AsyncFnOnce()` is not satisfied - //[current]~^^^^^ ERROR AsyncFnOnce()` is not satisfied + //[current]~| ERROR AsyncFnOnce()` is not satisfied x.poll(&mut Context::from_waker(Waker::noop())); //[current]~^ ERROR AsyncFnOnce()` is not satisfied } diff --git a/tests/ui/methods/bad-wf-when-selecting-method.rs b/tests/ui/methods/bad-wf-when-selecting-method.rs index 1f1a10f420462..c54ab963c2cfa 100644 --- a/tests/ui/methods/bad-wf-when-selecting-method.rs +++ b/tests/ui/methods/bad-wf-when-selecting-method.rs @@ -11,7 +11,6 @@ trait Trait { fn test(t: T) { Wrapper(t).needs_sized(); //~^ ERROR the trait bound `T: Wf` is not satisfied - //~| ERROR the trait bound `T: Wf` is not satisfied //~| ERROR the method `needs_sized` exists for struct `Wrapper`, but its trait bounds were not satisfied } diff --git a/tests/ui/methods/bad-wf-when-selecting-method.stderr b/tests/ui/methods/bad-wf-when-selecting-method.stderr index e6d500349670c..7a8a1fe3ab546 100644 --- a/tests/ui/methods/bad-wf-when-selecting-method.stderr +++ b/tests/ui/methods/bad-wf-when-selecting-method.stderr @@ -16,22 +16,6 @@ help: consider restricting type parameter `T` with trait `Wf` LL | fn test(t: T) { | ++++ -error[E0277]: the trait bound `T: Wf` is not satisfied - --> $DIR/bad-wf-when-selecting-method.rs:12:5 - | -LL | Wrapper(t).needs_sized(); - | ^^^^^^^^^^ the trait `Wf` is not implemented for `T` - | -note: required by a bound in `Wrapper` - --> $DIR/bad-wf-when-selecting-method.rs:5:19 - | -LL | struct Wrapper, U>(T); - | ^^^^^^^^^^^^^ required by this bound in `Wrapper` -help: consider restricting type parameter `T` with trait `Wf` - | -LL | fn test(t: T) { - | ++++ - error[E0599]: the method `needs_sized` exists for struct `Wrapper`, but its trait bounds were not satisfied --> $DIR/bad-wf-when-selecting-method.rs:12:16 | @@ -48,7 +32,7 @@ help: consider restricting the type parameter to satisfy the trait bound LL | fn test(t: T) where T: Wf { | +++++++++++ -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0277, E0599. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/sized/unsized-inference.rs b/tests/ui/sized/unsized-inference.rs new file mode 100644 index 0000000000000..1484b1f2d80ba --- /dev/null +++ b/tests/ui/sized/unsized-inference.rs @@ -0,0 +1,9 @@ +// Issue #84346. +use std::fmt::Display; + +fn main() { + let x = vec![1, 2, 3]; + let y: Vec = x.into_iter().collect(); + //~^ ERROR: the size for values of type `dyn std::fmt::Display` cannot be known at compilation time + //~| ERROR: a value of type `Vec` cannot be built from an iterator over elements of type `{integer}` +} diff --git a/tests/ui/sized/unsized-inference.stderr b/tests/ui/sized/unsized-inference.stderr new file mode 100644 index 0000000000000..dd8873430cee3 --- /dev/null +++ b/tests/ui/sized/unsized-inference.stderr @@ -0,0 +1,32 @@ +error[E0277]: the size for values of type `dyn std::fmt::Display` cannot be known at compilation time + --> $DIR/unsized-inference.rs:6:12 + | +LL | let y: Vec = x.into_iter().collect(); + | ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `dyn std::fmt::Display` +note: required by an implicit `Sized` bound in `Vec` + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + +error[E0277]: a value of type `Vec` cannot be built from an iterator over elements of type `{integer}` + --> $DIR/unsized-inference.rs:6:45 + | +LL | let y: Vec = x.into_iter().collect(); + | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` + | + = help: the trait `FromIterator<{integer}>` is not implemented for `Vec` +help: the trait `FromIterator` is implemented for `Vec` + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL +note: the method call chain might not have had the expected associated types + --> $DIR/unsized-inference.rs:6:33 + | +LL | let x = vec![1, 2, 3]; + | ------------- this expression has type `Vec<{integer}>` +LL | let y: Vec = x.into_iter().collect(); + | ^^^^^^^^^^^ `Iterator::Item` is `{integer}` here +note: required by a bound in `collect` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/sized/unsized-return-type-in-call.rs b/tests/ui/sized/unsized-return-type-in-call.rs new file mode 100644 index 0000000000000..a3ea0fd3c244e --- /dev/null +++ b/tests/ui/sized/unsized-return-type-in-call.rs @@ -0,0 +1,12 @@ +// Issue #105753. +trait T {} + +fn foo() -> dyn T { + //~^ ERROR: return type cannot be a trait object without pointer indirection + todo!() +} + +fn main() { + let x = foo(); + //~^ ERROR: the size for values of type `dyn T` cannot be known at compilation time +} diff --git a/tests/ui/sized/unsized-return-type-in-call.stderr b/tests/ui/sized/unsized-return-type-in-call.stderr new file mode 100644 index 0000000000000..8fad01645d84b --- /dev/null +++ b/tests/ui/sized/unsized-return-type-in-call.stderr @@ -0,0 +1,31 @@ +error[E0746]: return type cannot be a trait object without pointer indirection + --> $DIR/unsized-return-type-in-call.rs:4:13 + | +LL | fn foo() -> dyn T { + | ^^^^^ doesn't have a size known at compile-time + | +help: consider returning an `impl Trait` instead of a `dyn Trait` + | +LL - fn foo() -> dyn T { +LL + fn foo() -> impl T { + | +help: alternatively, box the return type, and wrap all of the returned values in `Box::new` + | +LL ~ fn foo() -> Box { +LL | +LL ~ Box::new(todo!()) + | + +error[E0277]: the size for values of type `dyn T` cannot be known at compilation time + --> $DIR/unsized-return-type-in-call.rs:10:9 + | +LL | let x = foo(); + | ^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `dyn T` + = note: all local variables must have a statically known size + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0277, E0746. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/structs/ice-missing-field-fn-sig-closure.rs b/tests/ui/structs/ice-missing-field-fn-sig-closure.rs index 6878dd85ff847..dde3fba2e5a46 100644 --- a/tests/ui/structs/ice-missing-field-fn-sig-closure.rs +++ b/tests/ui/structs/ice-missing-field-fn-sig-closure.rs @@ -10,7 +10,6 @@ fn main() { let c = |_: Wrapper<()>| {}; //~ ERROR the trait bound `(): Context` is not satisfied c(Wrapper { /* missing */ }); //~^ ERROR the trait bound `(): Context` is not satisfied - //~^^ ERROR missing field `container` in initializer of `Wrapper<_>` - //~^^^ ERROR the trait bound `(): Context` is not satisfied - //~^^^^ ERROR the trait bound `(): Context` is not satisfied + //~| ERROR missing field `container` in initializer of `Wrapper<_>` + //~| ERROR the trait bound `(): Context` is not satisfied } diff --git a/tests/ui/structs/ice-missing-field-fn-sig-closure.stderr b/tests/ui/structs/ice-missing-field-fn-sig-closure.stderr index 8e5b2fa931e4f..67048b657f17f 100644 --- a/tests/ui/structs/ice-missing-field-fn-sig-closure.stderr +++ b/tests/ui/structs/ice-missing-field-fn-sig-closure.stderr @@ -38,23 +38,6 @@ error[E0063]: missing field `container` in initializer of `Wrapper<_>` LL | c(Wrapper { /* missing */ }); | ^^^^^^^ missing `container` -error[E0277]: the trait bound `(): Context` is not satisfied - --> $DIR/ice-missing-field-fn-sig-closure.rs:11:7 - | -LL | c(Wrapper { /* missing */ }); - | ^^^^^^^ the trait `Context` is not implemented for `()` - | -help: this trait has no implementations, consider adding one - --> $DIR/ice-missing-field-fn-sig-closure.rs:4:1 - | -LL | trait Context {} - | ^^^^^^^^^^^^^ -note: required by a bound in `Wrapper` - --> $DIR/ice-missing-field-fn-sig-closure.rs:5:19 - | -LL | struct Wrapper { - | ^^^^^^^ required by this bound in `Wrapper` - error[E0277]: the trait bound `(): Context` is not satisfied --> $DIR/ice-missing-field-fn-sig-closure.rs:11:5 | @@ -72,7 +55,7 @@ note: required by a bound in `Wrapper` LL | struct Wrapper { | ^^^^^^^ required by this bound in `Wrapper` -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0063, E0277. For more information about an error, try `rustc --explain E0063`. diff --git a/tests/ui/structs/ice-missing-field-fn-sig.rs b/tests/ui/structs/ice-missing-field-fn-sig.rs index 9ba48f6a6e795..41467d91449e8 100644 --- a/tests/ui/structs/ice-missing-field-fn-sig.rs +++ b/tests/ui/structs/ice-missing-field-fn-sig.rs @@ -7,8 +7,7 @@ struct Wrapper { fn foobar(_: Wrapper<()>) { //~ ERROR the trait bound `(): Context` is not satisfied foobar(Wrapper { /* missing */ }) //~^ ERROR the trait bound `(): Context` is not satisfied -//~^^ ERROR missing field `container` in initializer of `Wrapper<_>` -//~^^^ ERROR the trait bound `(): Context` is not satisfied +//~| ERROR missing field `container` in initializer of `Wrapper<_>` } fn main() {} diff --git a/tests/ui/structs/ice-missing-field-fn-sig.stderr b/tests/ui/structs/ice-missing-field-fn-sig.stderr index 7be7886b2d975..5d8ed5bbf5eb5 100644 --- a/tests/ui/structs/ice-missing-field-fn-sig.stderr +++ b/tests/ui/structs/ice-missing-field-fn-sig.stderr @@ -38,24 +38,7 @@ error[E0063]: missing field `container` in initializer of `Wrapper<_>` LL | foobar(Wrapper { /* missing */ }) | ^^^^^^^ missing `container` -error[E0277]: the trait bound `(): Context` is not satisfied - --> $DIR/ice-missing-field-fn-sig.rs:8:12 - | -LL | foobar(Wrapper { /* missing */ }) - | ^^^^^^^ the trait `Context` is not implemented for `()` - | -help: this trait has no implementations, consider adding one - --> $DIR/ice-missing-field-fn-sig.rs:3:1 - | -LL | trait Context {} - | ^^^^^^^^^^^^^ -note: required by a bound in `Wrapper` - --> $DIR/ice-missing-field-fn-sig.rs:4:19 - | -LL | struct Wrapper { - | ^^^^^^^ required by this bound in `Wrapper` - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0063, E0277. For more information about an error, try `rustc --explain E0063`. diff --git a/tests/ui/suggestions/mut-borrow-needed-by-trait.rs b/tests/ui/suggestions/mut-borrow-needed-by-trait.rs index 66e1e77c905e0..1686a7dddb137 100644 --- a/tests/ui/suggestions/mut-borrow-needed-by-trait.rs +++ b/tests/ui/suggestions/mut-borrow-needed-by-trait.rs @@ -16,7 +16,6 @@ fn main() { let fp = BufWriter::new(fp); //~^ ERROR the trait bound `&dyn std::io::Write: std::io::Write` is not satisfied - //~| ERROR the trait bound `&dyn std::io::Write: std::io::Write` is not satisfied writeln!(fp, "hello world").unwrap(); //~ ERROR the method } diff --git a/tests/ui/suggestions/mut-borrow-needed-by-trait.stderr b/tests/ui/suggestions/mut-borrow-needed-by-trait.stderr index 5ba7fcb2479bb..6b2d315c96aac 100644 --- a/tests/ui/suggestions/mut-borrow-needed-by-trait.stderr +++ b/tests/ui/suggestions/mut-borrow-needed-by-trait.stderr @@ -10,24 +10,14 @@ LL | let fp = BufWriter::new(fp); note: required by a bound in `BufWriter::::new` --> $SRC_DIR/alloc/src/io/buffered/bufwriter.rs:LL:COL -error[E0277]: the trait bound `&dyn std::io::Write: std::io::Write` is not satisfied - --> $DIR/mut-borrow-needed-by-trait.rs:17:14 - | -LL | let fp = BufWriter::new(fp); - | ^^^^^^^^^^^^^^^^^^ the trait `std::io::Write` is not implemented for `&dyn std::io::Write` - | - = note: `std::io::Write` is implemented for `&mut dyn std::io::Write`, but not for `&dyn std::io::Write` -note: required by a bound in `BufWriter` - --> $SRC_DIR/alloc/src/io/buffered/bufwriter.rs:LL:COL - error[E0599]: the method `write_fmt` exists for struct `BufWriter<&dyn std::io::Write>`, but its trait bounds were not satisfied - --> $DIR/mut-borrow-needed-by-trait.rs:21:14 + --> $DIR/mut-borrow-needed-by-trait.rs:20:14 | LL | writeln!(fp, "hello world").unwrap(); | ---------^^---------------- method cannot be called on `BufWriter<&dyn std::io::Write>` due to unsatisfied trait bounds | note: must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method - --> $DIR/mut-borrow-needed-by-trait.rs:21:14 + --> $DIR/mut-borrow-needed-by-trait.rs:20:14 | LL | writeln!(fp, "hello world").unwrap(); | ^^ @@ -35,7 +25,7 @@ LL | writeln!(fp, "hello world").unwrap(); `&dyn std::io::Write: std::io::Write` which is required by `BufWriter<&dyn std::io::Write>: std::io::Write` -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0277, E0599. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/negative-impls/negated-auto-traits-error.rs b/tests/ui/traits/negative-impls/negated-auto-traits-error.rs index 4bdad5dc591c5..523876c9f2a4f 100644 --- a/tests/ui/traits/negative-impls/negated-auto-traits-error.rs +++ b/tests/ui/traits/negative-impls/negated-auto-traits-error.rs @@ -22,7 +22,6 @@ fn dummy() { Outer(TestType); //~^ ERROR `dummy::TestType` cannot be sent between threads safely - //~| ERROR `dummy::TestType` cannot be sent between threads safely } fn dummy1b() { diff --git a/tests/ui/traits/negative-impls/negated-auto-traits-error.stderr b/tests/ui/traits/negative-impls/negated-auto-traits-error.stderr index 64e9dae2633b8..60b6c712341c7 100644 --- a/tests/ui/traits/negative-impls/negated-auto-traits-error.stderr +++ b/tests/ui/traits/negative-impls/negated-auto-traits-error.stderr @@ -17,25 +17,8 @@ note: required by a bound in `Outer` LL | struct Outer(T); | ^^^^ required by this bound in `Outer` -error[E0277]: `dummy::TestType` cannot be sent between threads safely - --> $DIR/negated-auto-traits-error.rs:23:5 - | -LL | Outer(TestType); - | ^^^^^^^^^^^^^^^ `dummy::TestType` cannot be sent between threads safely - | -help: the trait `Send` is not implemented for `dummy::TestType` - --> $DIR/negated-auto-traits-error.rs:20:5 - | -LL | struct TestType; - | ^^^^^^^^^^^^^^^ -note: required by a bound in `Outer` - --> $DIR/negated-auto-traits-error.rs:10:17 - | -LL | struct Outer(T); - | ^^^^ required by this bound in `Outer` - error[E0277]: `dummy1b::TestType` cannot be sent between threads safely - --> $DIR/negated-auto-traits-error.rs:32:13 + --> $DIR/negated-auto-traits-error.rs:31:13 | LL | is_send(TestType); | ------- ^^^^^^^^ `dummy1b::TestType` cannot be sent between threads safely @@ -43,7 +26,7 @@ LL | is_send(TestType); | required by a bound introduced by this call | help: the trait `Send` is not implemented for `dummy1b::TestType` - --> $DIR/negated-auto-traits-error.rs:29:5 + --> $DIR/negated-auto-traits-error.rs:28:5 | LL | struct TestType; | ^^^^^^^^^^^^^^^ @@ -54,7 +37,7 @@ LL | fn is_send(_: T) {} | ^^^^ required by this bound in `is_send` error[E0277]: `dummy1c::TestType` cannot be sent between threads safely - --> $DIR/negated-auto-traits-error.rs:40:13 + --> $DIR/negated-auto-traits-error.rs:39:13 | LL | is_send((8, TestType)); | ------- ^^^^^^^^^^^^^ `dummy1c::TestType` cannot be sent between threads safely @@ -62,7 +45,7 @@ LL | is_send((8, TestType)); | required by a bound introduced by this call | help: within `({integer}, dummy1c::TestType)`, the trait `Send` is not implemented for `dummy1c::TestType` - --> $DIR/negated-auto-traits-error.rs:37:5 + --> $DIR/negated-auto-traits-error.rs:36:5 | LL | struct TestType; | ^^^^^^^^^^^^^^^ @@ -74,7 +57,7 @@ LL | fn is_send(_: T) {} | ^^^^ required by this bound in `is_send` error[E0277]: `dummy2::TestType` cannot be sent between threads safely - --> $DIR/negated-auto-traits-error.rs:48:13 + --> $DIR/negated-auto-traits-error.rs:47:13 | LL | is_send(Box::new(TestType)); | ------- ^^^^^^^^^^^^^^^^^^ the trait `Send` is not implemented for `std::ptr::Unique` @@ -96,7 +79,7 @@ LL | is_send(&Box::new(TestType)); | + error[E0277]: `dummy3::TestType` cannot be sent between threads safely - --> $DIR/negated-auto-traits-error.rs:56:13 + --> $DIR/negated-auto-traits-error.rs:55:13 | LL | is_send(Box::new(Outer2(TestType))); | ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ `dummy3::TestType` cannot be sent between threads safely @@ -104,7 +87,7 @@ LL | is_send(Box::new(Outer2(TestType))); | required by a bound introduced by this call | help: within `Outer2`, the trait `Send` is not implemented for `dummy3::TestType` - --> $DIR/negated-auto-traits-error.rs:53:5 + --> $DIR/negated-auto-traits-error.rs:52:5 | LL | struct TestType; | ^^^^^^^^^^^^^^^ @@ -123,7 +106,7 @@ LL | fn is_send(_: T) {} | ^^^^ required by this bound in `is_send` error[E0277]: `main::TestType` cannot be sent between threads safely - --> $DIR/negated-auto-traits-error.rs:66:20 + --> $DIR/negated-auto-traits-error.rs:65:20 | LL | is_sync(Outer2(TestType)); | ------- ^^^^^^^^ `main::TestType` cannot be sent between threads safely @@ -131,7 +114,7 @@ LL | is_sync(Outer2(TestType)); | required by a bound introduced by this call | help: the trait `Send` is not implemented for `main::TestType` - --> $DIR/negated-auto-traits-error.rs:61:5 + --> $DIR/negated-auto-traits-error.rs:60:5 | LL | struct TestType; | ^^^^^^^^^^^^^^^ @@ -148,6 +131,6 @@ note: required by a bound in `is_sync` LL | fn is_sync(_: T) {} | ^^^^ required by this bound in `is_sync` -error: aborting due to 7 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-issue-162440.rs b/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-issue-162440.rs index 9b6562ff578bf..1cd0445289fbb 100644 --- a/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-issue-162440.rs +++ b/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-issue-162440.rs @@ -8,5 +8,4 @@ fn main() { Some([0]).map(|s| s[..]); //~^ ERROR the size for values of type `[{integer}]` cannot be known at compilation time //~| ERROR the size for values of type `[{integer}]` cannot be known at compilation time - //~| ERROR the size for values of type `[{integer}]` cannot be known at compilation time } diff --git a/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-issue-162440.stderr b/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-issue-162440.stderr index 4aed7e179b8ef..40338cf23f004 100644 --- a/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-issue-162440.stderr +++ b/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-issue-162440.stderr @@ -17,25 +17,6 @@ LL | Some([0]).map(|s| s[..]); = help: the trait `Sized` is not implemented for `[{integer}]` = note: the return type of a function must have a statically known size -error[E0277]: the size for values of type `[{integer}]` cannot be known at compilation time - --> $DIR/closure-capture-uninferred-upvars-issue-162440.rs:8:19 - | -LL | Some([0]).map(|s| s[..]); - | --- ---^^^^^^ - | | | - | | doesn't have a size known at compile-time - | | within this `{closure@$DIR/closure-capture-uninferred-upvars-issue-162440.rs:8:19: 8:22}` - | required by a bound introduced by this call - | - = help: within `{closure@$DIR/closure-capture-uninferred-upvars-issue-162440.rs:8:19: 8:22}`, the trait `Sized` is not implemented for `[{integer}]` -note: required because it's used within this closure - --> $DIR/closure-capture-uninferred-upvars-issue-162440.rs:8:19 - | -LL | Some([0]).map(|s| s[..]); - | ^^^ -note: required by a bound in `Option::::map` - --> $SRC_DIR/core/src/option.rs:LL:COL - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-with-capture.rs b/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-with-capture.rs index ff4a9b67a3fee..62c6884a321ce 100644 --- a/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-with-capture.rs +++ b/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-with-capture.rs @@ -8,7 +8,6 @@ fn main() { Some([0]).map(|s| { //~^ ERROR the size for values of type `[{integer}]` cannot be known at compilation time - //~| ERROR the size for values of type `[{integer}]` cannot be known at compilation time //~| ERROR the size for values of type `[{integer}]` cannot be known at compilation time let _ = &x; s[..] diff --git a/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-with-capture.stderr b/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-with-capture.stderr index b19dca701f2fb..05a3a44504246 100644 --- a/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-with-capture.stderr +++ b/tests/ui/traits/next-solver/closure-capture-uninferred-upvars-with-capture.stderr @@ -13,7 +13,9 @@ error[E0277]: the size for values of type `[{integer}]` cannot be known at compi | LL | Some([0]).map(|s| { | _______________________^ -... | +LL | | +LL | | +LL | | let _ = &x; LL | | s[..] LL | | }); | |_____^ doesn't have a size known at compile-time @@ -21,29 +23,6 @@ LL | | }); = help: the trait `Sized` is not implemented for `[{integer}]` = note: the return type of a function must have a statically known size -error[E0277]: the size for values of type `[{integer}]` cannot be known at compilation time - --> $DIR/closure-capture-uninferred-upvars-with-capture.rs:9:19 - | -LL | Some([0]).map(|s| { - | --- ^-- - | | | - | _______________|___within this `{closure@$DIR/closure-capture-uninferred-upvars-with-capture.rs:9:19: 9:22}` - | | | - | | required by a bound introduced by this call -... | -LL | | s[..] -LL | | }); - | |_____^ doesn't have a size known at compile-time - | - = help: within `{closure@$DIR/closure-capture-uninferred-upvars-with-capture.rs:9:19: 9:22}`, the trait `Sized` is not implemented for `[{integer}]` -note: required because it's used within this closure - --> $DIR/closure-capture-uninferred-upvars-with-capture.rs:9:19 - | -LL | Some([0]).map(|s| { - | ^^^ -note: required by a bound in `Option::::map` - --> $SRC_DIR/core/src/option.rs:LL:COL - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/next-solver/opaques/implied-bounds-opaque-hidden-in-closure-sig.current.stderr b/tests/ui/traits/next-solver/opaques/implied-bounds-opaque-hidden-in-closure-sig.current.stderr index 1189f62601759..15516922d9276 100644 --- a/tests/ui/traits/next-solver/opaques/implied-bounds-opaque-hidden-in-closure-sig.current.stderr +++ b/tests/ui/traits/next-solver/opaques/implied-bounds-opaque-hidden-in-closure-sig.current.stderr @@ -19,44 +19,6 @@ LL | struct RequiresWf(F) LL | F::Output: Trait, | ^^^^^ required by this bound in `RequiresWf` -error[E0277]: the trait bound `impl Sized: Trait` is not satisfied - --> $DIR/implied-bounds-opaque-hidden-in-closure-sig.rs:35:14 - | -LL | (|_| ())(RequiresWf(opaque)); - | ^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `impl Sized` - | -help: the trait `Trait` is implemented for `()` - --> $DIR/implied-bounds-opaque-hidden-in-closure-sig.rs:17:1 - | -LL | impl Trait for () { - | ^^^^^^^^^^^^^^^^^ -note: required by a bound in `RequiresWf` - --> $DIR/implied-bounds-opaque-hidden-in-closure-sig.rs:31:16 - | -LL | struct RequiresWf(F) -... -LL | F::Output: Trait, - | ^^^^^ required by this bound in `RequiresWf` - -error[E0277]: the trait bound `impl Sized: Trait` is not satisfied - --> $DIR/implied-bounds-opaque-hidden-in-closure-sig.rs:35:7 - | -LL | (|_| ())(RequiresWf(opaque)); - | ^ the trait `Trait` is not implemented for `impl Sized` - | -help: the trait `Trait` is implemented for `()` - --> $DIR/implied-bounds-opaque-hidden-in-closure-sig.rs:17:1 - | -LL | impl Trait for () { - | ^^^^^^^^^^^^^^^^^ -note: required by a bound in `RequiresWf` - --> $DIR/implied-bounds-opaque-hidden-in-closure-sig.rs:31:16 - | -LL | struct RequiresWf(F) -... -LL | F::Output: Trait, - | ^^^^^ required by this bound in `RequiresWf` - error[E0277]: the trait bound `impl Sized: Trait` is not satisfied --> $DIR/implied-bounds-opaque-hidden-in-closure-sig.rs:35:5 | @@ -76,6 +38,6 @@ LL | struct RequiresWf(F) LL | F::Output: Trait, | ^^^^^ required by this bound in `RequiresWf` -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/next-solver/opaques/implied-bounds-opaque-hidden-in-closure-sig.rs b/tests/ui/traits/next-solver/opaques/implied-bounds-opaque-hidden-in-closure-sig.rs index 6fe74f0d4f9d3..324c99b5bab92 100644 --- a/tests/ui/traits/next-solver/opaques/implied-bounds-opaque-hidden-in-closure-sig.rs +++ b/tests/ui/traits/next-solver/opaques/implied-bounds-opaque-hidden-in-closure-sig.rs @@ -35,8 +35,6 @@ fn opaque() -> impl Sized { (|_| ())(RequiresWf(opaque)); //[current]~^ ERROR the trait bound `impl Sized: Trait` is not satisfied //[current]~| ERROR the trait bound `impl Sized: Trait` is not satisfied - //[current]~| ERROR the trait bound `impl Sized: Trait` is not satisfied - //[current]~| ERROR the trait bound `impl Sized: Trait` is not satisfied } fn main() {} diff --git a/tests/ui/traits/next-solver/overflow/incorrect-old-solver-caching-ice-148095.next.stderr b/tests/ui/traits/next-solver/overflow/incorrect-old-solver-caching-ice-148095.next.stderr index c285c42d380e8..021573324c9e5 100644 --- a/tests/ui/traits/next-solver/overflow/incorrect-old-solver-caching-ice-148095.next.stderr +++ b/tests/ui/traits/next-solver/overflow/incorrect-old-solver-caching-ice-148095.next.stderr @@ -93,15 +93,6 @@ help: consider extending the `where` clause, but there might be an alternative b LL | Quantity:, f32: Mul | +++++++++++++ -error[E0277]: cannot multiply `f32` by `S` - | - = help: the trait `Mul` is not implemented for `f32` -help: consider extending the `where` clause, but there might be an alternative better way to express this requirement - --> $DIR/incorrect-old-solver-caching-ice-148095.rs:27:28 - | -LL | Quantity:, f32: Mul - | +++++++++++++ - error: the type `Quantity<>::Output>` is not well-formed --> $DIR/incorrect-old-solver-caching-ice-148095.rs:30:21 | @@ -120,7 +111,7 @@ help: consider extending the `where` clause, but there might be an alternative b LL | Quantity:, f32: Mul | +++++++++++++ -error: aborting due to 11 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0207, E0276, E0277. For more information about an error, try `rustc --explain E0207`. diff --git a/tests/ui/type-inference/snapshot-infer-leakage/leak-infer-ice-120254.next.stderr b/tests/ui/type-inference/snapshot-infer-leakage/leak-infer-ice-120254.next.stderr index 39deff902a1a0..b96467228aa8d 100644 --- a/tests/ui/type-inference/snapshot-infer-leakage/leak-infer-ice-120254.next.stderr +++ b/tests/ui/type-inference/snapshot-infer-leakage/leak-infer-ice-120254.next.stderr @@ -1,25 +1,11 @@ error[E0277]: the trait bound `E: Dbg` is not satisfied - --> $DIR/leak-infer-ice-120254.rs:33:28 + --> $DIR/leak-infer-ice-120254.rs:31:28 | LL | fn record_err(self, _: ::Checkpoint) -> () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Dbg` is not implemented for `E` | note: required for `Foo` to implement `Bar` - --> $DIR/leak-infer-ice-120254.rs:24:22 - | -LL | impl Bar for Foo { - | --- ^^^ ^^^^^^^^^ - | | - | unsatisfied trait bound introduced here -help: consider restricting type parameter `E` with trait `Dbg` - | -LL | impl Foo { - | +++++ - -error[E0277]: the trait bound `E: Dbg` is not satisfied - | -note: required for `Foo` to implement `Bar` - --> $DIR/leak-infer-ice-120254.rs:24:22 + --> $DIR/leak-infer-ice-120254.rs:22:22 | LL | impl Bar for Foo { | --- ^^^ ^^^^^^^^^ @@ -31,19 +17,19 @@ LL | impl Foo { | +++++ error: the type ` as Bar>::Checkpoint` is not well-formed - --> $DIR/leak-infer-ice-120254.rs:33:28 + --> $DIR/leak-infer-ice-120254.rs:31:28 | LL | fn record_err(self, _: ::Checkpoint) -> () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `E: Dbg` is not satisfied - --> $DIR/leak-infer-ice-120254.rs:33:28 + --> $DIR/leak-infer-ice-120254.rs:31:28 | LL | fn record_err(self, _: ::Checkpoint) -> () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Dbg` is not implemented for `E` | note: required for `Foo` to implement `Bar` - --> $DIR/leak-infer-ice-120254.rs:24:22 + --> $DIR/leak-infer-ice-120254.rs:22:22 | LL | impl Bar for Foo { | --- ^^^ ^^^^^^^^^ @@ -55,6 +41,6 @@ help: consider restricting type parameter `E` with trait `Dbg` LL | impl Foo { | +++++ -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/type-inference/snapshot-infer-leakage/leak-infer-ice-120254.rs b/tests/ui/type-inference/snapshot-infer-leakage/leak-infer-ice-120254.rs index 0299381e17312..ccf1ed3d9826f 100644 --- a/tests/ui/type-inference/snapshot-infer-leakage/leak-infer-ice-120254.rs +++ b/tests/ui/type-inference/snapshot-infer-leakage/leak-infer-ice-120254.rs @@ -5,8 +5,6 @@ //@[old] dont-check-compiler-stderr //@[old] known-bug: #120254 -//[next]~^^^^^^^ ERROR: the trait bound `E: Dbg` is not satisfied - // Regression test for #120254. This no longer reproduces with the new solver // even though the underlying issue has not been fixed.