diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index ebb8d443421..7d7fa9f2941 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -38,6 +38,15 @@ pub struct OpaqueTypeDecl<'tcx> { pub origin: hir::OpaqueTyOrigin, } +pub enum ReplaceOpaqueTypes { + /// Closures can't create hidden types for opaque types of their parent, as they + /// do not have all the outlives information available. Also `type_of` looks for + /// hidden types in the owner (so the closure's parent), so it would not find these + /// definitions. + OnlyForRPIT, + All, +} + impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn replace_opaque_types_with_inference_vars( &self, @@ -46,27 +55,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { span: Span, code: ObligationCauseCode<'tcx>, param_env: ty::ParamEnv<'tcx>, + replace: ReplaceOpaqueTypes, ) -> InferOk<'tcx, Ty<'tcx>> { if !ty.has_opaque_types() { return InferOk { value: ty, obligations: vec![] }; } let mut obligations = vec![]; + let replace_opaque_type = |def_id| match self.opaque_type_origin(def_id, span) { + None => false, + Some(OpaqueTyOrigin::FnReturn(..)) => true, + // Not using `==` or `matches!` here to make sure we exhaustively match variants. + Some(_) => match replace { + ReplaceOpaqueTypes::OnlyForRPIT => false, + ReplaceOpaqueTypes::All => true, + }, + }; let value = ty.fold_with(&mut ty::fold::BottomUpFolder { tcx: self.tcx, lt_op: |lt| lt, ct_op: |ct| ct, ty_op: |ty| match *ty.kind() { - // Closures can't create hidden types for opaque types of their parent, as they - // do not have all the outlives information available. Also `type_of` looks for - // hidden types in the owner (so the closure's parent), so it would not find these - // definitions. - ty::Opaque(def_id, _substs) - if matches!( - self.opaque_type_origin(def_id, span), - Some(OpaqueTyOrigin::FnReturn(..)) - ) => - { - let span = if span.is_dummy() { self.tcx.def_span(def_id) } else { span }; + ty::Opaque(def_id, _substs) if replace_opaque_type(def_id) => { + let def_span = self.tcx.def_span(def_id); + let span = if span.contains(def_span) { def_span } else { span }; let cause = ObligationCause::new(span, body_id, code.clone()); // FIXME(compiler-errors): We probably should add a new TypeVariableOriginKind // for opaque types, and then use that kind to fix the spans for type errors diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 8ffffbed93c..184bc4188c5 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -13,6 +13,7 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::Visitor; use rustc_hir::lang_items::LangItem; use rustc_hir::{ItemKind, Node, PathSegment}; +use rustc_infer::infer::opaque_types::ReplaceOpaqueTypes; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt}; use rustc_infer::traits::Obligation; @@ -95,9 +96,10 @@ pub(super) fn check_fn<'a, 'tcx>( fcx.register_infer_ok_obligations(fcx.infcx.replace_opaque_types_with_inference_vars( declared_ret_ty, body.value.hir_id, - DUMMY_SP, + decl.output.span(), traits::ObligationCauseCode::OpaqueReturnType(None), param_env, + ReplaceOpaqueTypes::All, )); // If we replaced declared_ret_ty with infer vars, then we must be infering // an opaque type, so set a flag so we can improve diagnostics. diff --git a/compiler/rustc_typeck/src/check/closure.rs b/compiler/rustc_typeck/src/check/closure.rs index cce11305119..918a42cf02b 100644 --- a/compiler/rustc_typeck/src/check/closure.rs +++ b/compiler/rustc_typeck/src/check/closure.rs @@ -7,6 +7,7 @@ use crate::rustc_middle::ty::subst::Subst; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::lang_items::LangItem; +use rustc_infer::infer::opaque_types::ReplaceOpaqueTypes; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::LateBoundRegionConversionTime; use rustc_infer::infer::{InferOk, InferResult}; @@ -645,6 +646,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { result } + /// Closures can't create hidden types for opaque types of their parent, as they + /// do not have all the outlives information available. Also `type_of` looks for + /// hidden types in the owner (so the closure's parent), so it would not find these + /// definitions. fn hide_parent_opaque_types(&self, ty: Ty<'tcx>, span: Span, body_id: hir::HirId) -> Ty<'tcx> { let InferOk { value, obligations } = self.replace_opaque_types_with_inference_vars( ty, @@ -652,6 +657,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span, ObligationCauseCode::MiscObligation, self.param_env, + ReplaceOpaqueTypes::OnlyForRPIT, ); self.register_predicates(obligations); value @@ -671,8 +677,37 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ret_ty = ret_coercion.borrow().expected_ty(); let ret_ty = self.inh.infcx.shallow_resolve(ret_ty); - let (def_id, substs) = match *ret_ty.kind() { - ty::Opaque(def_id, substs) => (def_id, substs), + + let get_future_output = |predicate: ty::Predicate<'tcx>, span| { + // Search for a pending obligation like + // + // `::Output = T` + // + // where R is the return type we are expecting. This type `T` + // will be our output. + let bound_predicate = predicate.kind(); + if let ty::PredicateKind::Projection(proj_predicate) = bound_predicate.skip_binder() { + self.deduce_future_output_from_projection( + span, + bound_predicate.rebind(proj_predicate), + ) + } else { + None + } + }; + + let output_ty = match *ret_ty.kind() { + ty::Infer(ty::TyVar(ret_vid)) => { + self.obligations_for_self_ty(ret_vid).find_map(|(_, obligation)| { + get_future_output(obligation.predicate, obligation.cause.span) + }) + } + ty::Opaque(def_id, substs) => self + .tcx + .bound_explicit_item_bounds(def_id) + .transpose_iter() + .map(|e| e.map_bound(|e| *e).transpose_tuple2()) + .find_map(|(p, s)| get_future_output(p.subst(self.tcx, substs), s.0)), ty::Error(_) => return None, _ => span_bug!( self.tcx.def_span(expr_def_id), @@ -680,30 +715,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ), }; - let item_bounds = self.tcx.bound_explicit_item_bounds(def_id); - - // Search for a pending obligation like - // - // `::Output = T` - // - // where R is the return type we are expecting. This type `T` - // will be our output. - let output_ty = item_bounds - .transpose_iter() - .map(|e| e.map_bound(|e| *e).transpose_tuple2()) - .find_map(|(predicate, span)| { - let bound_predicate = predicate.subst(self.tcx, substs).kind(); - if let ty::PredicateKind::Projection(proj_predicate) = bound_predicate.skip_binder() - { - self.deduce_future_output_from_projection( - span.0, - bound_predicate.rebind(proj_predicate), - ) - } else { - None - } - }); - debug!("deduce_future_output_from_obligations: output_ty={:?}", output_ty); output_ty } diff --git a/src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.rs b/src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.rs index 67b97c21805..4c36289f47b 100644 --- a/src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.rs +++ b/src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.rs @@ -30,7 +30,7 @@ impl Thing for AssocNoCopy { type Out = Box>; fn func() -> Self::Out { - Box::new(AssocNoCopy) //~^ ERROR the trait bound `String: Copy` is not satisfied + Box::new(AssocNoCopy) } } diff --git a/src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr b/src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr index f40e6585b38..a32ab453152 100644 --- a/src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr +++ b/src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr @@ -1,10 +1,8 @@ error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:33:9 + --> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:32:18 | -LL | Box::new(AssocNoCopy) - | ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` - | - = note: required for the cast from `AssocNoCopy` to the object type `dyn Bar::Out::{opaque#0}>` +LL | fn func() -> Self::Out { + | ^^^^^^^^^ the trait `Copy` is not implemented for `String` error: aborting due to previous error diff --git a/src/test/ui/async-await/issues/issue-65159.rs b/src/test/ui/async-await/issues/issue-65159.rs index df2ca025705..1dbf5db6c32 100644 --- a/src/test/ui/async-await/issues/issue-65159.rs +++ b/src/test/ui/async-await/issues/issue-65159.rs @@ -6,6 +6,7 @@ async fn copy() -> Result<()> //~^ ERROR this enum takes 2 generic arguments { Ok(()) + //~^ ERROR type annotations needed } fn main() { } diff --git a/src/test/ui/async-await/issues/issue-65159.stderr b/src/test/ui/async-await/issues/issue-65159.stderr index 45f5ec40cd7..9918f569cbc 100644 --- a/src/test/ui/async-await/issues/issue-65159.stderr +++ b/src/test/ui/async-await/issues/issue-65159.stderr @@ -16,6 +16,18 @@ help: add missing generic argument LL | async fn copy() -> Result<(), E> | +++ -error: aborting due to previous error +error[E0282]: type annotations needed + --> $DIR/issue-65159.rs:8:5 + | +LL | Ok(()) + | ^^ cannot infer type of the type parameter `E` declared on the enum `Result` + | +help: consider specifying the generic arguments + | +LL | Ok::<(), E>(()) + | +++++++++ -For more information about this error, try `rustc --explain E0107`. +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0107, E0282. +For more information about an error, try `rustc --explain E0107`. diff --git a/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs b/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs index dd0320bc53b..2c8a700bc2e 100644 --- a/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs +++ b/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs @@ -17,6 +17,7 @@ async fn buy_lock(generator: &Mutex) -> LockedMarket<'_> { //~^ ERROR this struct takes 0 lifetime arguments but 1 lifetime argument was supplied //~^^ ERROR this struct takes 1 generic argument but 0 generic arguments were supplied LockedMarket(generator.lock().unwrap().buy()) + //~^ ERROR cannot return value referencing temporary } struct LockedMarket(T); diff --git a/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr b/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr index d2b927fb664..4bd06673043 100644 --- a/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr +++ b/src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr @@ -7,7 +7,7 @@ LL | async fn buy_lock(generator: &Mutex) -> LockedMarket<'_> | expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters - --> $DIR/issue-82126-mismatched-subst-and-hir.rs:22:8 + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:23:8 | LL | struct LockedMarket(T); | ^^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | async fn buy_lock(generator: &Mutex) -> LockedMarket<'_> | ^^^^^^^^^^^^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` - --> $DIR/issue-82126-mismatched-subst-and-hir.rs:22:8 + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:23:8 | LL | struct LockedMarket(T); | ^^^^^^^^^^^^ - @@ -28,6 +28,16 @@ help: add missing generic argument LL | async fn buy_lock(generator: &Mutex) -> LockedMarket<'_, T> { | +++ -error: aborting due to 2 previous errors +error[E0515]: cannot return value referencing temporary value + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:19:5 + | +LL | LockedMarket(generator.lock().unwrap().buy()) + | ^^^^^^^^^^^^^-------------------------^^^^^^^ + | | | + | | temporary value created here + | returns a value referencing data owned by the current function -For more information about this error, try `rustc --explain E0107`. +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0107, E0515. +For more information about an error, try `rustc --explain E0107`. diff --git a/src/test/ui/chalkify/bugs/async.stderr b/src/test/ui/chalkify/bugs/async.stderr index 5b7ca8d46cf..f53ed53f73c 100644 --- a/src/test/ui/chalkify/bugs/async.stderr +++ b/src/test/ui/chalkify/bugs/async.stderr @@ -29,13 +29,10 @@ LL | T: Generator, | ^^^^^^^^^^ required by this bound in `std::future::from_generator` error[E0280]: the requirement ` as Future>::Output == u32` is not satisfied - --> $DIR/async.rs:7:29 + --> $DIR/async.rs:7:25 | -LL | async fn foo(x: u32) -> u32 { - | _____________________________^ -LL | | x -LL | | } - | |_^ +LL | async fn foo(x: u32) -> u32 { + | ^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/generic-associated-types/bugs/issue-89008.stderr b/src/test/ui/generic-associated-types/bugs/issue-89008.stderr index 5cbadfacc1b..50844fdc14d 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-89008.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-89008.stderr @@ -1,10 +1,10 @@ error[E0271]: type mismatch resolving ` as Stream>::Item == Repr` - --> $DIR/issue-89008.rs:40:9 + --> $DIR/issue-89008.rs:39:43 | LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> { - | ---- this type parameter -LL | async {empty()} - | ^^^^^^^^^^^^^^^ type mismatch resolving ` as Stream>::Item == Repr` + | ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving ` as Stream>::Item == Repr` + | | + | this type parameter | note: expected this to be `()` --> $DIR/issue-89008.rs:18:17 diff --git a/src/test/ui/impl-trait/issue-55872-1.rs b/src/test/ui/impl-trait/issue-55872-1.rs index a75b9b43b3e..22ff7ffa23c 100644 --- a/src/test/ui/impl-trait/issue-55872-1.rs +++ b/src/test/ui/impl-trait/issue-55872-1.rs @@ -11,9 +11,9 @@ impl Bar for S { fn foo() -> Self::E { //~^ ERROR impl has stricter requirements than trait - (S::default(), T::default()) - //~^ ERROR the trait bound `S: Copy` is not satisfied in `(S, T)` [E0277] + //~| ERROR the trait bound `S: Copy` is not satisfied in `(S, T)` [E0277] //~| ERROR the trait bound `T: Copy` is not satisfied in `(S, T)` [E0277] + (S::default(), T::default()) } } diff --git a/src/test/ui/impl-trait/issue-55872-1.stderr b/src/test/ui/impl-trait/issue-55872-1.stderr index efc57da7461..8912cce1b4b 100644 --- a/src/test/ui/impl-trait/issue-55872-1.stderr +++ b/src/test/ui/impl-trait/issue-55872-1.stderr @@ -8,10 +8,10 @@ LL | fn foo() -> Self::E { | ^^^^^^^ impl has extra requirement `T: Default` error[E0277]: the trait bound `S: Copy` is not satisfied in `(S, T)` - --> $DIR/issue-55872-1.rs:14:9 + --> $DIR/issue-55872-1.rs:12:29 | -LL | (S::default(), T::default()) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S` +LL | fn foo() -> Self::E { + | ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S` | = note: required because it appears within the type `(S, T)` help: consider further restricting this bound @@ -20,10 +20,10 @@ LL | impl Bar for S { | +++++++++++++++++++ error[E0277]: the trait bound `T: Copy` is not satisfied in `(S, T)` - --> $DIR/issue-55872-1.rs:14:9 + --> $DIR/issue-55872-1.rs:12:29 | -LL | (S::default(), T::default()) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T` +LL | fn foo() -> Self::E { + | ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T` | = note: required because it appears within the type `(S, T)` help: consider further restricting this bound diff --git a/src/test/ui/impl-trait/issue-55872-3.rs b/src/test/ui/impl-trait/issue-55872-3.rs index 36d9fdede10..3ffce85e61b 100644 --- a/src/test/ui/impl-trait/issue-55872-3.rs +++ b/src/test/ui/impl-trait/issue-55872-3.rs @@ -12,8 +12,8 @@ pub trait Bar { impl Bar for S { type E = impl std::marker::Copy; fn foo() -> Self::E { + //~^ ERROR the trait bound `impl Future: Copy` is not satisfied [E0277] async {} - //~^ ERROR the trait bound `impl Future: Copy` is not satisfied [E0277] } } diff --git a/src/test/ui/impl-trait/issue-55872-3.stderr b/src/test/ui/impl-trait/issue-55872-3.stderr index e7023e8127c..6ab540e8751 100644 --- a/src/test/ui/impl-trait/issue-55872-3.stderr +++ b/src/test/ui/impl-trait/issue-55872-3.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `impl Future: Copy` is not satisfied - --> $DIR/issue-55872-3.rs:15:9 + --> $DIR/issue-55872-3.rs:14:20 | -LL | async {} - | ^^^^^^^^ the trait `Copy` is not implemented for `impl Future` +LL | fn foo() -> Self::E { + | ^^^^^^^ the trait `Copy` is not implemented for `impl Future` error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-70877.rs b/src/test/ui/impl-trait/issues/issue-70877.rs index 1a86fa00ed1..8169cfafac7 100644 --- a/src/test/ui/impl-trait/issues/issue-70877.rs +++ b/src/test/ui/impl-trait/issues/issue-70877.rs @@ -13,7 +13,7 @@ impl Iterator for Bar { type Item = FooItem; fn next(&mut self) -> Option { - Some(Box::new(quux)) //~ ERROR mismatched types + Some(Box::new(quux)) } } diff --git a/src/test/ui/impl-trait/issues/issue-70877.stderr b/src/test/ui/impl-trait/issues/issue-70877.stderr index 7cbd58bdabf..8813bff3c35 100644 --- a/src/test/ui/impl-trait/issues/issue-70877.stderr +++ b/src/test/ui/impl-trait/issues/issue-70877.stderr @@ -1,17 +1,3 @@ -error[E0308]: mismatched types - --> $DIR/issue-70877.rs:16:9 - | -LL | type FooRet = impl std::fmt::Debug; - | -------------------- the expected opaque type -... -LL | fn next(&mut self) -> Option { - | ------------------ expected `Option Fn(&'r (dyn ToString + 'r)) -> FooRet + 'static)>>` because of return type -LL | Some(Box::new(quux)) - | ^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Fn`, found fn item - | - = note: expected enum `Option Fn(&'r (dyn ToString + 'r)) -> FooRet + 'static)>>` - found enum `Option fn(&'r (dyn ToString + 'r)) -> FooRet {quux}>>` - error: opaque type's hidden type cannot be another opaque type from the same scope --> $DIR/issue-70877.rs:31:12 | @@ -29,6 +15,5 @@ note: opaque type being used as hidden type LL | type FooRet = impl std::fmt::Debug; | ^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to previous error -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/impl-trait/issues/issue-78722.rs b/src/test/ui/impl-trait/issues/issue-78722.rs index 5498793bc28..002e4cde40a 100644 --- a/src/test/ui/impl-trait/issues/issue-78722.rs +++ b/src/test/ui/impl-trait/issues/issue-78722.rs @@ -7,7 +7,8 @@ type F = impl core::future::Future; struct Bug { V1: [(); { fn concrete_use() -> F { - async {} //~ ERROR type mismatch + //~^ ERROR type mismatch + async {} } let f: F = async { 1 }; //~^ ERROR `async` blocks are not allowed in constants diff --git a/src/test/ui/impl-trait/issues/issue-78722.stderr b/src/test/ui/impl-trait/issues/issue-78722.stderr index 7a057c7f51b..690d6abc766 100644 --- a/src/test/ui/impl-trait/issues/issue-78722.stderr +++ b/src/test/ui/impl-trait/issues/issue-78722.stderr @@ -1,5 +1,5 @@ error[E0658]: `async` blocks are not allowed in constants - --> $DIR/issue-78722.rs:12:20 + --> $DIR/issue-78722.rs:13:20 | LL | let f: F = async { 1 }; | ^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | let f: F = async { 1 }; = help: add `#![feature(const_async_blocks)]` to the crate attributes to enable error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/issue-78722.rs:12:13 + --> $DIR/issue-78722.rs:13:13 | LL | let f: F = async { 1 }; | ^ constants cannot evaluate destructors @@ -17,10 +17,10 @@ LL | }], | - value is dropped here error[E0271]: type mismatch resolving ` as Future>::Output == u8` - --> $DIR/issue-78722.rs:10:13 + --> $DIR/issue-78722.rs:9:30 | -LL | async {} - | ^^^^^^^^ expected `()`, found `u8` +LL | fn concrete_use() -> F { + | ^ expected `()`, found `u8` error: aborting due to 3 previous errors diff --git a/src/test/ui/impl-trait/issues/issue-83919.rs b/src/test/ui/impl-trait/issues/issue-83919.rs index 58aca77fdf1..e76443a65db 100644 --- a/src/test/ui/impl-trait/issues/issue-83919.rs +++ b/src/test/ui/impl-trait/issues/issue-83919.rs @@ -19,8 +19,9 @@ impl Foo for Implementor { type Fut = impl Future; fn get_fut(&self) -> Self::Fut { + //~^ ERROR `{integer}` is not a future async move { - 42 //~^ ERROR `{integer}` is not a future + 42 // 42 does not impl Future and rustc does actually point out the error, // but rustc used to panic. // Putting a valid Future here always worked fine. diff --git a/src/test/ui/impl-trait/issues/issue-83919.stderr b/src/test/ui/impl-trait/issues/issue-83919.stderr index ebd0130be8d..d39dcf7fbf5 100644 --- a/src/test/ui/impl-trait/issues/issue-83919.stderr +++ b/src/test/ui/impl-trait/issues/issue-83919.stderr @@ -1,13 +1,8 @@ error[E0277]: `{integer}` is not a future - --> $DIR/issue-83919.rs:22:9 + --> $DIR/issue-83919.rs:21:26 | -LL | / async move { -LL | | 42 -LL | | // 42 does not impl Future and rustc does actually point out the error, -LL | | // but rustc used to panic. -LL | | // Putting a valid Future here always worked fine. -LL | | } - | |_________^ `{integer}` is not a future +LL | fn get_fut(&self) -> Self::Fut { + | ^^^^^^^^^ `{integer}` is not a future | = help: the trait `Future` is not implemented for `{integer}` = note: {integer} must be a future or must implement `IntoFuture` to be awaited diff --git a/src/test/ui/impl-trait/nested-return-type2-tait2.rs b/src/test/ui/impl-trait/nested-return-type2-tait2.rs index af8e0663054..fcc077ec18e 100644 --- a/src/test/ui/impl-trait/nested-return-type2-tait2.rs +++ b/src/test/ui/impl-trait/nested-return-type2-tait2.rs @@ -24,8 +24,8 @@ type Traitable = impl Trait; // var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque // type does not implement `Duh`, even if its hidden type does. So we error out. fn foo() -> Traitable { - || 42 //~^ ERROR `Sendable: Duh` is not satisfied + || 42 } fn main() { diff --git a/src/test/ui/impl-trait/nested-return-type2-tait2.stderr b/src/test/ui/impl-trait/nested-return-type2-tait2.stderr index 42e65e69248..3e19ad7b5c6 100644 --- a/src/test/ui/impl-trait/nested-return-type2-tait2.stderr +++ b/src/test/ui/impl-trait/nested-return-type2-tait2.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `Sendable: Duh` is not satisfied - --> $DIR/nested-return-type2-tait2.rs:27:5 + --> $DIR/nested-return-type2-tait2.rs:26:13 | -LL | || 42 - | ^^^^^ the trait `Duh` is not implemented for `Sendable` +LL | fn foo() -> Traitable { + | ^^^^^^^^^ the trait `Duh` is not implemented for `Sendable` | = help: the trait `Duh` is implemented for `i32` -note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait2.rs:27:5: 27:10]` +note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait2.rs:28:5: 28:10]` --> $DIR/nested-return-type2-tait2.rs:14:31 | LL | impl R> Trait for F { diff --git a/src/test/ui/impl-trait/nested-return-type2-tait3.rs b/src/test/ui/impl-trait/nested-return-type2-tait3.rs index 74fd8a9dda0..665c7a8cab9 100644 --- a/src/test/ui/impl-trait/nested-return-type2-tait3.rs +++ b/src/test/ui/impl-trait/nested-return-type2-tait3.rs @@ -23,8 +23,8 @@ type Traitable = impl Trait; // var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque // type does not implement `Duh`, even if its hidden type does. So we error out. fn foo() -> Traitable { - || 42 //~^ ERROR `impl Send: Duh` is not satisfied + || 42 } fn main() { diff --git a/src/test/ui/impl-trait/nested-return-type2-tait3.stderr b/src/test/ui/impl-trait/nested-return-type2-tait3.stderr index 4d3691d0e07..6185e4872a5 100644 --- a/src/test/ui/impl-trait/nested-return-type2-tait3.stderr +++ b/src/test/ui/impl-trait/nested-return-type2-tait3.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `impl Send: Duh` is not satisfied - --> $DIR/nested-return-type2-tait3.rs:26:5 + --> $DIR/nested-return-type2-tait3.rs:25:13 | -LL | || 42 - | ^^^^^ the trait `Duh` is not implemented for `impl Send` +LL | fn foo() -> Traitable { + | ^^^^^^^^^ the trait `Duh` is not implemented for `impl Send` | = help: the trait `Duh` is implemented for `i32` -note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait3.rs:26:5: 26:10]` +note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait3.rs:27:5: 27:10]` --> $DIR/nested-return-type2-tait3.rs:14:31 | LL | impl R> Trait for F { diff --git a/src/test/ui/lazy-type-alias-impl-trait/branches.rs b/src/test/ui/lazy-type-alias-impl-trait/branches.rs index aa172f3f19b..e7db10bd7cd 100644 --- a/src/test/ui/lazy-type-alias-impl-trait/branches.rs +++ b/src/test/ui/lazy-type-alias-impl-trait/branches.rs @@ -1,5 +1,7 @@ #![feature(type_alias_impl_trait)] +// check-pass + type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { @@ -7,7 +9,6 @@ fn foo(b: bool) -> Foo { vec![42_i32] } else { std::iter::empty().collect() - //~^ ERROR `Foo` cannot be built from an iterator over elements of type `_` } } diff --git a/src/test/ui/lazy-type-alias-impl-trait/branches.stderr b/src/test/ui/lazy-type-alias-impl-trait/branches.stderr deleted file mode 100644 index c3902f34706..00000000000 --- a/src/test/ui/lazy-type-alias-impl-trait/branches.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0277]: a value of type `Foo` cannot be built from an iterator over elements of type `_` - --> $DIR/branches.rs:9:28 - | -LL | std::iter::empty().collect() - | ^^^^^^^ value of type `Foo` cannot be built from `std::iter::Iterator` - | - = help: the trait `FromIterator<_>` is not implemented for `Foo` -note: required by a bound in `collect` - --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL - | -LL | fn collect>(self) -> B - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/lazy-type-alias-impl-trait/branches2.rs b/src/test/ui/lazy-type-alias-impl-trait/branches2.rs index af605e4d806..04218f5643d 100644 --- a/src/test/ui/lazy-type-alias-impl-trait/branches2.rs +++ b/src/test/ui/lazy-type-alias-impl-trait/branches2.rs @@ -1,6 +1,6 @@ #![feature(type_alias_impl_trait)] -// run-pass +// check-pass type Foo = impl std::iter::FromIterator + PartialEq> + std::fmt::Debug; diff --git a/src/test/ui/lazy-type-alias-impl-trait/branches3.rs b/src/test/ui/lazy-type-alias-impl-trait/branches3.rs new file mode 100644 index 00000000000..30c0af8a5dc --- /dev/null +++ b/src/test/ui/lazy-type-alias-impl-trait/branches3.rs @@ -0,0 +1,36 @@ +#![feature(type_alias_impl_trait)] + +type Foo = impl for<'a> FnOnce(&'a str) -> usize; +type Bar = impl FnOnce(&'static str) -> usize; + +fn foo() -> Foo { + if true { + |s| s.len() //~ ERROR type annotations needed + } else { + panic!() + } +} +fn bar() -> Bar { + if true { + |s| s.len() //~ ERROR type annotations needed + } else { + panic!() + } +} + +fn foo2() -> impl for<'a> FnOnce(&'a str) -> usize { + if true { + |s| s.len() //~ ERROR type annotations needed + } else { + panic!() + } +} +fn bar2() -> impl FnOnce(&'static str) -> usize { + if true { + |s| s.len() //~ ERROR type annotations needed + } else { + panic!() + } +} + +fn main() {} diff --git a/src/test/ui/lazy-type-alias-impl-trait/branches3.stderr b/src/test/ui/lazy-type-alias-impl-trait/branches3.stderr new file mode 100644 index 00000000000..77ce1d48480 --- /dev/null +++ b/src/test/ui/lazy-type-alias-impl-trait/branches3.stderr @@ -0,0 +1,51 @@ +error[E0282]: type annotations needed + --> $DIR/branches3.rs:8:10 + | +LL | |s| s.len() + | ^ + | + = note: type must be known at this point +help: consider giving this closure parameter an explicit type + | +LL | |s: _| s.len() + | +++ + +error[E0282]: type annotations needed + --> $DIR/branches3.rs:15:10 + | +LL | |s| s.len() + | ^ + | + = note: type must be known at this point +help: consider giving this closure parameter an explicit type + | +LL | |s: _| s.len() + | +++ + +error[E0282]: type annotations needed + --> $DIR/branches3.rs:23:10 + | +LL | |s| s.len() + | ^ + | + = note: type must be known at this point +help: consider giving this closure parameter an explicit type + | +LL | |s: _| s.len() + | +++ + +error[E0282]: type annotations needed + --> $DIR/branches3.rs:30:10 + | +LL | |s| s.len() + | ^ + | + = note: type must be known at this point +help: consider giving this closure parameter an explicit type + | +LL | |s: _| s.len() + | +++ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/lazy-type-alias-impl-trait/recursion2.rs b/src/test/ui/lazy-type-alias-impl-trait/recursion2.rs index 1cc64ea17e7..6b3d9ff4cde 100644 --- a/src/test/ui/lazy-type-alias-impl-trait/recursion2.rs +++ b/src/test/ui/lazy-type-alias-impl-trait/recursion2.rs @@ -1,5 +1,7 @@ #![feature(type_alias_impl_trait)] +// check-pass + type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { @@ -7,7 +9,7 @@ fn foo(b: bool) -> Foo { return vec![]; } let x: Vec = foo(false); - std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator + std::iter::empty().collect() } fn bar(b: bool) -> impl std::fmt::Debug { diff --git a/src/test/ui/lazy-type-alias-impl-trait/recursion2.stderr b/src/test/ui/lazy-type-alias-impl-trait/recursion2.stderr deleted file mode 100644 index 1f6201a8300..00000000000 --- a/src/test/ui/lazy-type-alias-impl-trait/recursion2.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0277]: a value of type `Foo` cannot be built from an iterator over elements of type `_` - --> $DIR/recursion2.rs:10:24 - | -LL | std::iter::empty().collect() - | ^^^^^^^ value of type `Foo` cannot be built from `std::iter::Iterator` - | - = help: the trait `FromIterator<_>` is not implemented for `Foo` -note: required by a bound in `collect` - --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL - | -LL | fn collect>(self) -> B - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/never_type/impl_trait_fallback2.rs b/src/test/ui/never_type/impl_trait_fallback2.rs index f73d953bdbd..12c187b9e82 100644 --- a/src/test/ui/never_type/impl_trait_fallback2.rs +++ b/src/test/ui/never_type/impl_trait_fallback2.rs @@ -13,6 +13,7 @@ fn should_ret_unit() -> impl T { type Foo = impl T; fn a() -> Foo { + //~^ ERROR `(): T` is not satisfied panic!() } diff --git a/src/test/ui/never_type/impl_trait_fallback2.stderr b/src/test/ui/never_type/impl_trait_fallback2.stderr index 4a78e73e5f6..78cc83bdbfa 100644 --- a/src/test/ui/never_type/impl_trait_fallback2.stderr +++ b/src/test/ui/never_type/impl_trait_fallback2.stderr @@ -6,6 +6,14 @@ LL | fn should_ret_unit() -> impl T { | = help: the trait `T` is implemented for `i32` -error: aborting due to previous error +error[E0277]: the trait bound `(): T` is not satisfied + --> $DIR/impl_trait_fallback2.rs:15:11 + | +LL | fn a() -> Foo { + | ^^^ the trait `T` is not implemented for `()` + | + = help: the trait `T` is implemented for `i32` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/never_type/impl_trait_fallback3.rs b/src/test/ui/never_type/impl_trait_fallback3.rs index 26ce9b93105..ed645b82394 100644 --- a/src/test/ui/never_type/impl_trait_fallback3.rs +++ b/src/test/ui/never_type/impl_trait_fallback3.rs @@ -7,9 +7,9 @@ trait T { } type Foo = impl T; -//~^ ERROR unconstrained opaque type fn a() -> Foo { + //~^ ERROR the trait bound `(): T` is not satisfied // This is not a defining use, it doesn't actually constrain the opaque type. panic!() } diff --git a/src/test/ui/never_type/impl_trait_fallback3.stderr b/src/test/ui/never_type/impl_trait_fallback3.stderr index 121019d5f69..5d5d216fb9b 100644 --- a/src/test/ui/never_type/impl_trait_fallback3.stderr +++ b/src/test/ui/never_type/impl_trait_fallback3.stderr @@ -1,10 +1,9 @@ -error: unconstrained opaque type - --> $DIR/impl_trait_fallback3.rs:9:12 +error[E0277]: the trait bound `(): T` is not satisfied + --> $DIR/impl_trait_fallback3.rs:11:11 | -LL | type Foo = impl T; - | ^^^^^^ - | - = note: `Foo` must be used in combination with a concrete type within the same module +LL | fn a() -> Foo { + | ^^^ the trait `T` is not implemented for `()` error: aborting due to previous error +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/closures_in_branches.rs b/src/test/ui/type-alias-impl-trait/closures_in_branches.rs index a1a9401acc2..7bb490bbec8 100644 --- a/src/test/ui/type-alias-impl-trait/closures_in_branches.rs +++ b/src/test/ui/type-alias-impl-trait/closures_in_branches.rs @@ -4,7 +4,7 @@ type Foo = impl std::ops::FnOnce(String) -> usize; fn foo(b: bool) -> Foo { if b { - |x| x.len() + |x| x.len() //~ ERROR type annotations needed } else { panic!() } diff --git a/src/test/ui/type-alias-impl-trait/closures_in_branches.stderr b/src/test/ui/type-alias-impl-trait/closures_in_branches.stderr index b3ca260894b..b7a7871143c 100644 --- a/src/test/ui/type-alias-impl-trait/closures_in_branches.stderr +++ b/src/test/ui/type-alias-impl-trait/closures_in_branches.stderr @@ -1,3 +1,15 @@ +error[E0282]: type annotations needed + --> $DIR/closures_in_branches.rs:7:10 + | +LL | |x| x.len() + | ^ + | + = note: type must be known at this point +help: consider giving this closure parameter an explicit type + | +LL | |x: _| x.len() + | +++ + error[E0282]: type annotations needed --> $DIR/closures_in_branches.rs:21:10 | @@ -10,6 +22,6 @@ help: consider giving this closure parameter an explicit type LL | |x: _| x.len() | +++ -error: aborting due to previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/type-alias-impl-trait/fallback.rs b/src/test/ui/type-alias-impl-trait/fallback.rs index d7e93335f47..d8cf7d71fef 100644 --- a/src/test/ui/type-alias-impl-trait/fallback.rs +++ b/src/test/ui/type-alias-impl-trait/fallback.rs @@ -1,7 +1,6 @@ // Tests that we correctly handle opaque types being used opaquely, // even within their defining scope. // -// check-pass #![feature(type_alias_impl_trait)] type Foo = impl Copy; @@ -23,6 +22,7 @@ fn constrained_foo() -> Foo { // constraints on it. fn unconstrained_foo() -> Wrapper { Wrapper::Second + //~^ ERROR: type annotations needed } fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/fallback.stderr b/src/test/ui/type-alias-impl-trait/fallback.stderr new file mode 100644 index 00000000000..e009399a60a --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/fallback.stderr @@ -0,0 +1,15 @@ +error[E0283]: type annotations needed + --> $DIR/fallback.rs:24:5 + | +LL | Wrapper::Second + | ^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the enum `Wrapper` + | + = note: cannot satisfy `_: Copy` +help: consider specifying the generic argument + | +LL | Wrapper::::Second + | +++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs b/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs index 6c838f41003..377ce85e8b2 100644 --- a/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs +++ b/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs @@ -3,7 +3,8 @@ type Foo = impl Fn() -> Foo; fn foo() -> Foo { - foo //~ ERROR: overflow evaluating the requirement `fn() -> Foo {foo}: Sized` +//~^ ERROR: overflow evaluating the requirement `fn() -> Foo {foo}: Sized` + foo } fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr b/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr index a9c2c18630c..d20b1cc6d85 100644 --- a/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr @@ -1,8 +1,8 @@ error[E0275]: overflow evaluating the requirement `fn() -> Foo {foo}: Sized` - --> $DIR/issue-53398-cyclic-types.rs:6:5 + --> $DIR/issue-53398-cyclic-types.rs:5:13 | -LL | foo - | ^^^ +LL | fn foo() -> Foo { + | ^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_53398_cyclic_types`) diff --git a/src/test/ui/type-alias-impl-trait/issue-60371.stderr b/src/test/ui/type-alias-impl-trait/issue-60371.stderr index d0c04371bd7..082b0f0c309 100644 --- a/src/test/ui/type-alias-impl-trait/issue-60371.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-60371.stderr @@ -11,7 +11,7 @@ error[E0277]: the trait bound `(): Bug` is not satisfied --> $DIR/issue-60371.rs:10:40 | LL | const FUN: fn() -> Self::Item = || (); - | ^^ the trait `Bug` is not implemented for `()` + | ^ the trait `Bug` is not implemented for `()` | = help: the trait `Bug` is implemented for `&()` diff --git a/src/test/ui/type-alias-impl-trait/issue-63279.rs b/src/test/ui/type-alias-impl-trait/issue-63279.rs index 057a908bbee..97332e16d84 100644 --- a/src/test/ui/type-alias-impl-trait/issue-63279.rs +++ b/src/test/ui/type-alias-impl-trait/issue-63279.rs @@ -5,6 +5,7 @@ type Closure = impl FnOnce(); fn c() -> Closure { + //~^ ERROR: expected a `FnOnce<()>` closure, found `()` || -> Closure { || () } //~^ ERROR: mismatched types //~| ERROR: mismatched types diff --git a/src/test/ui/type-alias-impl-trait/issue-63279.stderr b/src/test/ui/type-alias-impl-trait/issue-63279.stderr index ab39ee74be4..57fc660901c 100644 --- a/src/test/ui/type-alias-impl-trait/issue-63279.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-63279.stderr @@ -1,5 +1,14 @@ error[E0277]: expected a `FnOnce<()>` closure, found `()` - --> $DIR/issue-63279.rs:8:11 + --> $DIR/issue-63279.rs:7:11 + | +LL | fn c() -> Closure { + | ^^^^^^^ expected an `FnOnce<()>` closure, found `()` + | + = help: the trait `FnOnce<()>` is not implemented for `()` + = note: wrap the `()` in a closure with no arguments: `|| { /* code */ }` + +error[E0277]: expected a `FnOnce<()>` closure, found `()` + --> $DIR/issue-63279.rs:9:11 | LL | || -> Closure { || () } | ^^^^^^^ expected an `FnOnce<()>` closure, found `()` @@ -8,33 +17,32 @@ LL | || -> Closure { || () } = note: wrap the `()` in a closure with no arguments: `|| { /* code */ }` error[E0308]: mismatched types - --> $DIR/issue-63279.rs:8:21 + --> $DIR/issue-63279.rs:9:21 | LL | || -> Closure { || () } | ^^^^^ expected `()`, found closure | = note: expected unit type `()` - found closure `[closure@$DIR/issue-63279.rs:8:21: 8:26]` + found closure `[closure@$DIR/issue-63279.rs:9:21: 9:26]` help: use parentheses to call this closure | LL | || -> Closure { (|| ())() } | + +++ error[E0308]: mismatched types - --> $DIR/issue-63279.rs:8:5 + --> $DIR/issue-63279.rs:9:5 | -LL | type Closure = impl FnOnce(); - | ------------- the expected opaque type -LL | -LL | fn c() -> Closure { - | ------- expected `Closure` because of return type LL | || -> Closure { || () } | ^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found closure | - = note: expected opaque type `Closure` - found closure `[closure@$DIR/issue-63279.rs:8:5: 8:28]` + = note: expected unit type `()` + found closure `[closure@$DIR/issue-63279.rs:9:5: 9:28]` +help: use parentheses to call this closure + | +LL | (|| -> Closure { || () })() + | + +++ -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0277, E0308. For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/issue-74280.stderr b/src/test/ui/type-alias-impl-trait/issue-74280.stderr index 573e691b4cc..5ed29e0ac94 100644 --- a/src/test/ui/type-alias-impl-trait/issue-74280.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-74280.stderr @@ -1,17 +1,11 @@ error[E0308]: mismatched types --> $DIR/issue-74280.rs:9:5 | -LL | type Test = impl Copy; - | --------- the expected opaque type -LL | LL | fn test() -> Test { - | ---- expected `Test` because of return type + | ---- expected `_` because of return type LL | let y = || -> Test { () }; LL | 7 | ^ expected `()`, found integer - | - = note: expected opaque type `Test` - found type `{integer}` error: aborting due to previous error diff --git a/src/test/ui/type-alias-impl-trait/issue-94429.rs b/src/test/ui/type-alias-impl-trait/issue-94429.rs index 51d69c1271e..2c965b875a0 100644 --- a/src/test/ui/type-alias-impl-trait/issue-94429.rs +++ b/src/test/ui/type-alias-impl-trait/issue-94429.rs @@ -13,7 +13,8 @@ impl Runnable for Implementor { type Gen = impl Generator; fn run(&mut self) -> Self::Gen { - move || { //~ ERROR: type mismatch resolving + //~^ ERROR: type mismatch resolving + move || { yield 1; } } diff --git a/src/test/ui/type-alias-impl-trait/issue-94429.stderr b/src/test/ui/type-alias-impl-trait/issue-94429.stderr index 4546f82b83b..57550104087 100644 --- a/src/test/ui/type-alias-impl-trait/issue-94429.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-94429.stderr @@ -1,10 +1,8 @@ -error[E0271]: type mismatch resolving `<[generator@$DIR/issue-94429.rs:16:9: 18:10] as Generator>::Yield == ()` - --> $DIR/issue-94429.rs:16:9 +error[E0271]: type mismatch resolving `<[generator@$DIR/issue-94429.rs:17:9: 19:10] as Generator>::Yield == ()` + --> $DIR/issue-94429.rs:15:26 | -LL | / move || { -LL | | yield 1; -LL | | } - | |_________^ expected integer, found `()` +LL | fn run(&mut self) -> Self::Gen { + | ^^^^^^^^^ expected integer, found `()` error: aborting due to previous error diff --git a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs index 46bac5a34f5..da845e86147 100644 --- a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs +++ b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs @@ -7,8 +7,8 @@ type X = impl Into<&'static A>; fn f(a: &'static A, b: B) -> (X, X) { - (a, a) //~^ ERROR the trait bound `&'static B: From<&A>` is not satisfied + (a, a) } fn main() { diff --git a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr index 198f3e26393..cdaae99e286 100644 --- a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr +++ b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `&'static B: From<&A>` is not satisfied - --> $DIR/multiple-def-uses-in-one-fn.rs:10:9 + --> $DIR/multiple-def-uses-in-one-fn.rs:9:45 | -LL | (a, a) - | ^ the trait `From<&A>` is not implemented for `&'static B` +LL | fn f(a: &'static A, b: B) -> (X, X) { + | ^^^^^^^^^^^^^^^^^^ the trait `From<&A>` is not implemented for `&'static B` | = note: required because of the requirements on the impl of `Into<&'static B>` for `&A` help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement diff --git a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.stderr b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.stderr index db4b60461ef..bbe709dccab 100644 --- a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.stderr +++ b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.stderr @@ -1,9 +1,6 @@ error[E0308]: mismatched types --> $DIR/multiple-def-uses-in-one-fn3.rs:14:9 | -LL | type X = impl ToString; - | ------------- the expected opaque type -... LL | fn g(a: A, b: B) -> (X, X) { | - - found type parameter | | @@ -11,8 +8,8 @@ LL | fn g(a: A, b: B) -> (X, X` - found type parameter `B` + = note: expected type parameter `A` + found type parameter `B` = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters diff --git a/src/test/ui/type-alias-impl-trait/self-referential-2.rs b/src/test/ui/type-alias-impl-trait/self-referential-2.rs index dc7054da5ec..8781196c39f 100644 --- a/src/test/ui/type-alias-impl-trait/self-referential-2.rs +++ b/src/test/ui/type-alias-impl-trait/self-referential-2.rs @@ -4,7 +4,7 @@ type Foo = impl std::fmt::Debug; type Bar = impl PartialEq; fn bar() -> Bar { - 42_i32 //~ ERROR can't compare `i32` with `Foo` + 42_i32 //~^ ERROR can't compare `i32` with `Foo` } fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/self-referential-2.stderr b/src/test/ui/type-alias-impl-trait/self-referential-2.stderr index 348696f25e3..2b505d30730 100644 --- a/src/test/ui/type-alias-impl-trait/self-referential-2.stderr +++ b/src/test/ui/type-alias-impl-trait/self-referential-2.stderr @@ -1,8 +1,10 @@ error[E0277]: can't compare `i32` with `Foo` - --> $DIR/self-referential-2.rs:7:5 + --> $DIR/self-referential-2.rs:6:13 | +LL | fn bar() -> Bar { + | ^^^ no implementation for `i32 == Foo` LL | 42_i32 - | ^^^^^^ no implementation for `i32 == Foo` + | ------ return type was inferred to be `i32` here | = help: the trait `PartialEq` is not implemented for `i32` = help: the following other types implement trait `PartialEq`: diff --git a/src/test/ui/type-alias-impl-trait/self-referential-4.rs b/src/test/ui/type-alias-impl-trait/self-referential-4.rs index 697ec56825a..36742c8ad57 100644 --- a/src/test/ui/type-alias-impl-trait/self-referential-4.rs +++ b/src/test/ui/type-alias-impl-trait/self-referential-4.rs @@ -3,19 +3,19 @@ type Bar<'a, 'b> = impl PartialEq> + std::fmt::Debug; fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { - i //~ ERROR can't compare `&i32` with `Bar<'b, 'static>` + i //~^ ERROR can't compare `&i32` with `Bar<'b, 'static>` } type Foo<'a, 'b> = impl PartialEq> + std::fmt::Debug; fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { - i //~ ERROR can't compare `&i32` with `Foo<'static, 'b>` + i //~^ ERROR can't compare `&i32` with `Foo<'static, 'b>` } type Moo<'a, 'b> = impl PartialEq> + std::fmt::Debug; fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> { - i //~ ERROR can't compare `&i32` with `Moo<'static, 'a>` + i //~^ ERROR can't compare `&i32` with `Moo<'static, 'a>` } fn main() { diff --git a/src/test/ui/type-alias-impl-trait/self-referential-4.stderr b/src/test/ui/type-alias-impl-trait/self-referential-4.stderr index 83826479419..27880f792f4 100644 --- a/src/test/ui/type-alias-impl-trait/self-referential-4.stderr +++ b/src/test/ui/type-alias-impl-trait/self-referential-4.stderr @@ -1,8 +1,10 @@ error[E0277]: can't compare `&i32` with `Bar<'b, 'static>` - --> $DIR/self-referential-4.rs:6:5 + --> $DIR/self-referential-4.rs:5:31 | +LL | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { + | ^^^^^^^^^^^ no implementation for `&i32 == Bar<'b, 'static>` LL | i - | ^ no implementation for `&i32 == Bar<'b, 'static>` + | - return type was inferred to be `&i32` here | = help: the trait `PartialEq>` is not implemented for `&i32` = help: the following other types implement trait `PartialEq`: @@ -17,10 +19,12 @@ LL | i and 6 others error[E0277]: can't compare `&i32` with `Foo<'static, 'b>` - --> $DIR/self-referential-4.rs:12:5 + --> $DIR/self-referential-4.rs:11:31 | +LL | fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { + | ^^^^^^^^^^^ no implementation for `&i32 == Foo<'static, 'b>` LL | i - | ^ no implementation for `&i32 == Foo<'static, 'b>` + | - return type was inferred to be `&i32` here | = help: the trait `PartialEq>` is not implemented for `&i32` = help: the following other types implement trait `PartialEq`: @@ -35,10 +39,12 @@ LL | i and 6 others error[E0277]: can't compare `&i32` with `Moo<'static, 'a>` - --> $DIR/self-referential-4.rs:18:5 + --> $DIR/self-referential-4.rs:17:31 | +LL | fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> { + | ^^^^^^^^^^^ no implementation for `&i32 == Moo<'static, 'a>` LL | i - | ^ no implementation for `&i32 == Moo<'static, 'a>` + | - return type was inferred to be `&i32` here | = help: the trait `PartialEq>` is not implemented for `&i32` = help: the following other types implement trait `PartialEq`: diff --git a/src/test/ui/type-alias-impl-trait/self-referential.rs b/src/test/ui/type-alias-impl-trait/self-referential.rs index 4974ac72dad..3ff5406a382 100644 --- a/src/test/ui/type-alias-impl-trait/self-referential.rs +++ b/src/test/ui/type-alias-impl-trait/self-referential.rs @@ -3,19 +3,22 @@ type Bar<'a, 'b> = impl PartialEq> + std::fmt::Debug; fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { - i //~ ERROR can't compare `&i32` with `Bar<'b, 'a>` + //~^ ERROR can't compare `&i32` with `Bar<'b, 'a>` + i } type Foo<'a, 'b> = (i32, impl PartialEq> + std::fmt::Debug); fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { - (42, i) //~ ERROR can't compare `&i32` with `(i32, &i32)` + //~^ ERROR can't compare `&i32` with `(i32, &i32)` + (42, i) } type Moo<'a, 'b> = (i32, impl PartialEq> + std::fmt::Debug); fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> { - (42, i) //~ ERROR can't compare `&i32` with `(i32, Moo<'b, 'a>::{opaque#0})` + //~^ ERROR can't compare `&i32` with `(i32, Moo<'b, 'a>::{opaque#0})` + (42, i) } fn main() { diff --git a/src/test/ui/type-alias-impl-trait/self-referential.stderr b/src/test/ui/type-alias-impl-trait/self-referential.stderr index 2ebb15b8803..97d510f6830 100644 --- a/src/test/ui/type-alias-impl-trait/self-referential.stderr +++ b/src/test/ui/type-alias-impl-trait/self-referential.stderr @@ -1,8 +1,11 @@ error[E0277]: can't compare `&i32` with `Bar<'b, 'a>` - --> $DIR/self-referential.rs:6:5 + --> $DIR/self-referential.rs:5:31 | +LL | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { + | ^^^^^^^^^^^ no implementation for `&i32 == Bar<'b, 'a>` +LL | LL | i - | ^ no implementation for `&i32 == Bar<'b, 'a>` + | - return type was inferred to be `&i32` here | = help: the trait `PartialEq>` is not implemented for `&i32` = help: the following other types implement trait `PartialEq`: @@ -17,10 +20,13 @@ LL | i and 6 others error[E0277]: can't compare `&i32` with `(i32, &i32)` - --> $DIR/self-referential.rs:12:10 + --> $DIR/self-referential.rs:12:31 | +LL | fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { + | ^^^^^^^^^^^ no implementation for `&i32 == (i32, &i32)` +LL | LL | (42, i) - | ^ no implementation for `&i32 == (i32, &i32)` + | ------- return type was inferred to be `(i32, &i32)` here | = help: the trait `PartialEq<(i32, &i32)>` is not implemented for `&i32` = help: the following other types implement trait `PartialEq`: @@ -35,10 +41,13 @@ LL | (42, i) and 6 others error[E0277]: can't compare `&i32` with `(i32, Moo<'b, 'a>::{opaque#0})` - --> $DIR/self-referential.rs:18:10 + --> $DIR/self-referential.rs:19:31 | +LL | fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> { + | ^^^^^^^^^^^ no implementation for `&i32 == (i32, Moo<'b, 'a>::{opaque#0})` +LL | LL | (42, i) - | ^ no implementation for `&i32 == (i32, Moo<'b, 'a>::{opaque#0})` + | ------- return type was inferred to be `(i32, &i32)` here | = help: the trait `PartialEq<(i32, Moo<'b, 'a>::{opaque#0})>` is not implemented for `&i32` = help: the following other types implement trait `PartialEq`: