From 92781ad72610090dd2076dcaaff0001ad8fda6d9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 24 Aug 2022 18:36:44 +0000 Subject: [PATCH 1/5] Revert "Remove deferred sized checks" This reverts commit 33212bf7f527798a8cfa2bbb38781742f4ca718a. --- compiler/rustc_typeck/src/check/expr.rs | 15 ++-- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 11 +++ compiler/rustc_typeck/src/check/inherited.rs | 6 ++ compiler/rustc_typeck/src/check/mod.rs | 5 ++ .../associated-types-path-2.rs | 2 + .../associated-types-path-2.stderr | 24 +++++-- .../feature-gate-unsized_fn_params.stderr | 5 +- src/test/ui/iterators/issue-28098.rs | 6 ++ src/test/ui/iterators/issue-28098.stderr | 60 ++++++++++++++-- .../ui/on-unimplemented/multiple-impls.rs | 6 ++ .../ui/on-unimplemented/multiple-impls.stderr | 72 ++++++++++++++++++- src/test/ui/on-unimplemented/on-impl.rs | 2 + src/test/ui/on-unimplemented/on-impl.stderr | 20 +++++- src/test/ui/ufcs/ufcs-qpath-self-mismatch.rs | 1 + .../ui/ufcs/ufcs-qpath-self-mismatch.stderr | 24 ++++++- src/test/ui/unsized/issue-30355.stderr | 5 +- 16 files changed, 229 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 71ae54bedce46..1a97fc505fddd 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -561,17 +561,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // We just want to check sizedness, so instead of introducing // placeholder lifetimes with probing, we just replace higher lifetimes // with fresh vars. - let arg_span = args.get(i).map(|a| a.span); - let span = arg_span.unwrap_or(expr.span); + let span = args.get(i).map(|a| a.span).unwrap_or(expr.span); let input = self.replace_bound_vars_with_fresh_vars( span, infer::LateBoundRegionConversionTime::FnCall, fn_sig.input(i), ); - self.require_type_is_sized( - self.normalize_associated_types_in(span, input), + self.require_type_is_sized_deferred( + input, span, - traits::SizedArgumentType(arg_span), + traits::SizedArgumentType(None), ); } } @@ -586,11 +585,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { infer::LateBoundRegionConversionTime::FnCall, fn_sig.output(), ); - self.require_type_is_sized( - self.normalize_associated_types_in(expr.span, output), - expr.span, - traits::SizedReturnType, - ); + self.require_type_is_sized_deferred(output, expr.span, traits::SizedReturnType); } // We always require that the type provided as the value for diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 20d25d508d224..1f47aabefdec7 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -442,6 +442,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } + pub fn require_type_is_sized_deferred( + &self, + ty: Ty<'tcx>, + span: Span, + code: traits::ObligationCauseCode<'tcx>, + ) { + if !ty.references_error() { + self.deferred_sized_obligations.borrow_mut().push((ty, span, code)); + } + } + pub fn register_bound( &self, ty: Ty<'tcx>, diff --git a/compiler/rustc_typeck/src/check/inherited.rs b/compiler/rustc_typeck/src/check/inherited.rs index f3115fc5c0232..cd152eb97f1bf 100644 --- a/compiler/rustc_typeck/src/check/inherited.rs +++ b/compiler/rustc_typeck/src/check/inherited.rs @@ -35,6 +35,11 @@ pub struct Inherited<'a, 'tcx> { pub(super) fulfillment_cx: RefCell>>, + // Some additional `Sized` obligations badly affect type inference. + // These obligations are added in a later stage of typeck. + pub(super) deferred_sized_obligations: + RefCell, Span, traits::ObligationCauseCode<'tcx>)>>, + // When we process a call like `c()` where `c` is a closure type, // we may not have decided yet whether `c` is a `Fn`, `FnMut`, or // `FnOnce` closure. In that case, we defer full resolution of the @@ -112,6 +117,7 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> { infcx, fulfillment_cx: RefCell::new(>::new(tcx)), locals: RefCell::new(Default::default()), + deferred_sized_obligations: RefCell::new(Vec::new()), deferred_call_resolutions: RefCell::new(Default::default()), deferred_cast_checks: RefCell::new(Vec::new()), deferred_transmute_checks: RefCell::new(Vec::new()), diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index fb675212e3ffb..07c202859cc9b 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -466,6 +466,11 @@ fn typeck_with_fallback<'tcx>( fcx.resolve_rvalue_scopes(def_id.to_def_id()); fcx.resolve_generator_interiors(def_id.to_def_id()); + for (ty, span, code) in fcx.deferred_sized_obligations.borrow_mut().drain(..) { + let ty = fcx.normalize_ty(span, ty); + fcx.require_type_is_sized(ty, span, code); + } + fcx.select_all_obligations_or_error(); if !fcx.infcx.is_tainted_by_errors() { diff --git a/src/test/ui/associated-types/associated-types-path-2.rs b/src/test/ui/associated-types/associated-types-path-2.rs index c993e1d27202d..00066efccb8dd 100644 --- a/src/test/ui/associated-types/associated-types-path-2.rs +++ b/src/test/ui/associated-types/associated-types-path-2.rs @@ -29,12 +29,14 @@ pub fn f1_uint_uint() { f1(2u32, 4u32); //~^ ERROR `u32: Foo` is not satisfied //~| ERROR `u32: Foo` is not satisfied + //~| ERROR `u32: Foo` is not satisfied } pub fn f1_uint_int() { f1(2u32, 4i32); //~^ ERROR `u32: Foo` is not satisfied //~| ERROR `u32: Foo` is not satisfied + //~| ERROR `u32: Foo` is not satisfied } pub fn f2_int() { diff --git a/src/test/ui/associated-types/associated-types-path-2.stderr b/src/test/ui/associated-types/associated-types-path-2.stderr index 5edd5c864e135..206f490241026 100644 --- a/src/test/ui/associated-types/associated-types-path-2.stderr +++ b/src/test/ui/associated-types/associated-types-path-2.stderr @@ -31,6 +31,14 @@ note: required by a bound in `f1` LL | pub fn f1(a: T, x: T::A) {} | ^^^ required by this bound in `f1` +error[E0277]: the trait bound `u32: Foo` is not satisfied + --> $DIR/associated-types-path-2.rs:29:5 + | +LL | f1(2u32, 4u32); + | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u32` + | + = help: the trait `Foo` is implemented for `i32` + error[E0277]: the trait bound `u32: Foo` is not satisfied --> $DIR/associated-types-path-2.rs:29:14 | @@ -40,7 +48,7 @@ LL | f1(2u32, 4u32); = help: the trait `Foo` is implemented for `i32` error[E0277]: the trait bound `u32: Foo` is not satisfied - --> $DIR/associated-types-path-2.rs:35:8 + --> $DIR/associated-types-path-2.rs:36:8 | LL | f1(2u32, 4i32); | -- ^^^^ the trait `Foo` is not implemented for `u32` @@ -55,7 +63,15 @@ LL | pub fn f1(a: T, x: T::A) {} | ^^^ required by this bound in `f1` error[E0277]: the trait bound `u32: Foo` is not satisfied - --> $DIR/associated-types-path-2.rs:35:14 + --> $DIR/associated-types-path-2.rs:36:5 + | +LL | f1(2u32, 4i32); + | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u32` + | + = help: the trait `Foo` is implemented for `i32` + +error[E0277]: the trait bound `u32: Foo` is not satisfied + --> $DIR/associated-types-path-2.rs:36:14 | LL | f1(2u32, 4i32); | ^^^^ the trait `Foo` is not implemented for `u32` @@ -63,7 +79,7 @@ LL | f1(2u32, 4i32); = help: the trait `Foo` is implemented for `i32` error[E0308]: mismatched types - --> $DIR/associated-types-path-2.rs:41:18 + --> $DIR/associated-types-path-2.rs:43:18 | LL | let _: i32 = f2(2i32); | --- ^^^^^^^^ expected `i32`, found `u32` @@ -75,7 +91,7 @@ help: you can convert a `u32` to an `i32` and panic if the converted value doesn LL | let _: i32 = f2(2i32).try_into().unwrap(); | ++++++++++++++++++++ -error: aborting due to 6 previous errors +error: aborting due to 8 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/feature-gates/feature-gate-unsized_fn_params.stderr b/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr index b7757740d9e34..0f7520ef7f8a9 100644 --- a/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr +++ b/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr @@ -18,11 +18,8 @@ LL | foo(*x); | ^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `(dyn Foo + 'static)` + = note: all function arguments must have a statically known size = help: unsized fn params are gated as an unstable feature -help: function arguments must have a statically known size, borrowed types always have a known size - | -LL | foo(&*x); - | + error: aborting due to 2 previous errors diff --git a/src/test/ui/iterators/issue-28098.rs b/src/test/ui/iterators/issue-28098.rs index c4addaccefc10..80c77edae9eb1 100644 --- a/src/test/ui/iterators/issue-28098.rs +++ b/src/test/ui/iterators/issue-28098.rs @@ -1,12 +1,15 @@ fn main() { let _ = Iterator::next(&mut ()); //~^ ERROR `()` is not an iterator + //~| ERROR `()` is not an iterator + //~| ERROR `()` is not an iterator for _ in false {} //~^ ERROR `bool` is not an iterator let _ = Iterator::next(&mut ()); //~^ ERROR `()` is not an iterator + //~| ERROR `()` is not an iterator other() } @@ -16,9 +19,12 @@ pub fn other() { let _ = Iterator::next(&mut ()); //~^ ERROR `()` is not an iterator + //~| ERROR `()` is not an iterator + //~| ERROR `()` is not an iterator let _ = Iterator::next(&mut ()); //~^ ERROR `()` is not an iterator + //~| ERROR `()` is not an iterator for _ in false {} //~^ ERROR `bool` is not an iterator diff --git a/src/test/ui/iterators/issue-28098.stderr b/src/test/ui/iterators/issue-28098.stderr index 53b610c172392..3256e57d4361b 100644 --- a/src/test/ui/iterators/issue-28098.stderr +++ b/src/test/ui/iterators/issue-28098.stderr @@ -8,8 +8,16 @@ LL | let _ = Iterator::next(&mut ()); | = help: the trait `Iterator` is not implemented for `()` +error[E0277]: `()` is not an iterator + --> $DIR/issue-28098.rs:2:13 + | +LL | let _ = Iterator::next(&mut ()); + | ^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator + | + = help: the trait `Iterator` is not implemented for `()` + error[E0277]: `bool` is not an iterator - --> $DIR/issue-28098.rs:5:14 + --> $DIR/issue-28098.rs:7:14 | LL | for _ in false {} | ^^^^^ `bool` is not an iterator @@ -18,7 +26,7 @@ LL | for _ in false {} = note: required for `bool` to implement `IntoIterator` error[E0277]: `()` is not an iterator - --> $DIR/issue-28098.rs:8:28 + --> $DIR/issue-28098.rs:10:28 | LL | let _ = Iterator::next(&mut ()); | -------------- ^^^^^^^ `()` is not an iterator @@ -28,7 +36,23 @@ LL | let _ = Iterator::next(&mut ()); = help: the trait `Iterator` is not implemented for `()` error[E0277]: `()` is not an iterator - --> $DIR/issue-28098.rs:17:28 + --> $DIR/issue-28098.rs:10:13 + | +LL | let _ = Iterator::next(&mut ()); + | ^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator + | + = help: the trait `Iterator` is not implemented for `()` + +error[E0277]: `()` is not an iterator + --> $DIR/issue-28098.rs:2:13 + | +LL | let _ = Iterator::next(&mut ()); + | ^^^^^^^^^^^^^^ `()` is not an iterator + | + = help: the trait `Iterator` is not implemented for `()` + +error[E0277]: `()` is not an iterator + --> $DIR/issue-28098.rs:20:28 | LL | let _ = Iterator::next(&mut ()); | -------------- ^^^^^^^ `()` is not an iterator @@ -38,7 +62,15 @@ LL | let _ = Iterator::next(&mut ()); = help: the trait `Iterator` is not implemented for `()` error[E0277]: `()` is not an iterator - --> $DIR/issue-28098.rs:20:28 + --> $DIR/issue-28098.rs:20:13 + | +LL | let _ = Iterator::next(&mut ()); + | ^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator + | + = help: the trait `Iterator` is not implemented for `()` + +error[E0277]: `()` is not an iterator + --> $DIR/issue-28098.rs:25:28 | LL | let _ = Iterator::next(&mut ()); | -------------- ^^^^^^^ `()` is not an iterator @@ -47,8 +79,16 @@ LL | let _ = Iterator::next(&mut ()); | = help: the trait `Iterator` is not implemented for `()` +error[E0277]: `()` is not an iterator + --> $DIR/issue-28098.rs:25:13 + | +LL | let _ = Iterator::next(&mut ()); + | ^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator + | + = help: the trait `Iterator` is not implemented for `()` + error[E0277]: `bool` is not an iterator - --> $DIR/issue-28098.rs:23:14 + --> $DIR/issue-28098.rs:29:14 | LL | for _ in false {} | ^^^^^ `bool` is not an iterator @@ -56,6 +96,14 @@ LL | for _ in false {} = help: the trait `Iterator` is not implemented for `bool` = note: required for `bool` to implement `IntoIterator` -error: aborting due to 6 previous errors +error[E0277]: `()` is not an iterator + --> $DIR/issue-28098.rs:20:13 + | +LL | let _ = Iterator::next(&mut ()); + | ^^^^^^^^^^^^^^ `()` is not an iterator + | + = help: the trait `Iterator` is not implemented for `()` + +error: aborting due to 12 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/on-unimplemented/multiple-impls.rs b/src/test/ui/on-unimplemented/multiple-impls.rs index 79c40f650db81..a32fd4566231d 100644 --- a/src/test/ui/on-unimplemented/multiple-impls.rs +++ b/src/test/ui/on-unimplemented/multiple-impls.rs @@ -32,8 +32,14 @@ impl Index> for [i32] { fn main() { Index::index(&[] as &[i32], 2u32); //~^ ERROR E0277 + //~| ERROR E0277 + //~| ERROR E0277 Index::index(&[] as &[i32], Foo(2u32)); //~^ ERROR E0277 + //~| ERROR E0277 + //~| ERROR E0277 Index::index(&[] as &[i32], Bar(2u32)); //~^ ERROR E0277 + //~| ERROR E0277 + //~| ERROR E0277 } diff --git a/src/test/ui/on-unimplemented/multiple-impls.stderr b/src/test/ui/on-unimplemented/multiple-impls.stderr index d47a398412fe4..d628b159a66d2 100644 --- a/src/test/ui/on-unimplemented/multiple-impls.stderr +++ b/src/test/ui/on-unimplemented/multiple-impls.stderr @@ -11,8 +11,19 @@ LL | Index::index(&[] as &[i32], 2u32); <[i32] as Index>> <[i32] as Index>> +error[E0277]: the trait bound `[i32]: Index` is not satisfied + --> $DIR/multiple-impls.rs:33:5 + | +LL | Index::index(&[] as &[i32], 2u32); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait message + | + = help: the trait `Index` is not implemented for `[i32]` + = help: the following other types implement trait `Index`: + <[i32] as Index>> + <[i32] as Index>> + error[E0277]: the trait bound `[i32]: Index>` is not satisfied - --> $DIR/multiple-impls.rs:35:33 + --> $DIR/multiple-impls.rs:37:33 | LL | Index::index(&[] as &[i32], Foo(2u32)); | ------------ ^^^^^^^^^ on impl for Foo @@ -24,8 +35,19 @@ LL | Index::index(&[] as &[i32], Foo(2u32)); <[i32] as Index>> <[i32] as Index>> +error[E0277]: the trait bound `[i32]: Index>` is not satisfied + --> $DIR/multiple-impls.rs:37:5 + | +LL | Index::index(&[] as &[i32], Foo(2u32)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ on impl for Foo + | + = help: the trait `Index>` is not implemented for `[i32]` + = help: the following other types implement trait `Index`: + <[i32] as Index>> + <[i32] as Index>> + error[E0277]: the trait bound `[i32]: Index>` is not satisfied - --> $DIR/multiple-impls.rs:37:33 + --> $DIR/multiple-impls.rs:41:33 | LL | Index::index(&[] as &[i32], Bar(2u32)); | ------------ ^^^^^^^^^ on impl for Bar @@ -37,6 +59,50 @@ LL | Index::index(&[] as &[i32], Bar(2u32)); <[i32] as Index>> <[i32] as Index>> -error: aborting due to 3 previous errors +error[E0277]: the trait bound `[i32]: Index>` is not satisfied + --> $DIR/multiple-impls.rs:41:5 + | +LL | Index::index(&[] as &[i32], Bar(2u32)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ on impl for Bar + | + = help: the trait `Index>` is not implemented for `[i32]` + = help: the following other types implement trait `Index`: + <[i32] as Index>> + <[i32] as Index>> + +error[E0277]: the trait bound `[i32]: Index` is not satisfied + --> $DIR/multiple-impls.rs:33:5 + | +LL | Index::index(&[] as &[i32], 2u32); + | ^^^^^^^^^^^^ trait message + | + = help: the trait `Index` is not implemented for `[i32]` + = help: the following other types implement trait `Index`: + <[i32] as Index>> + <[i32] as Index>> + +error[E0277]: the trait bound `[i32]: Index>` is not satisfied + --> $DIR/multiple-impls.rs:37:5 + | +LL | Index::index(&[] as &[i32], Foo(2u32)); + | ^^^^^^^^^^^^ on impl for Foo + | + = help: the trait `Index>` is not implemented for `[i32]` + = help: the following other types implement trait `Index`: + <[i32] as Index>> + <[i32] as Index>> + +error[E0277]: the trait bound `[i32]: Index>` is not satisfied + --> $DIR/multiple-impls.rs:41:5 + | +LL | Index::index(&[] as &[i32], Bar(2u32)); + | ^^^^^^^^^^^^ on impl for Bar + | + = help: the trait `Index>` is not implemented for `[i32]` + = help: the following other types implement trait `Index`: + <[i32] as Index>> + <[i32] as Index>> + +error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/on-unimplemented/on-impl.rs b/src/test/ui/on-unimplemented/on-impl.rs index b03e1f7c6a8df..d0537810ce11e 100644 --- a/src/test/ui/on-unimplemented/on-impl.rs +++ b/src/test/ui/on-unimplemented/on-impl.rs @@ -21,4 +21,6 @@ impl Index for [i32] { fn main() { Index::::index(&[1, 2, 3] as &[i32], 2u32); //~^ ERROR E0277 + //~| ERROR E0277 + //~| ERROR E0277 } diff --git a/src/test/ui/on-unimplemented/on-impl.stderr b/src/test/ui/on-unimplemented/on-impl.stderr index 01315b854098e..2253c5992a64a 100644 --- a/src/test/ui/on-unimplemented/on-impl.stderr +++ b/src/test/ui/on-unimplemented/on-impl.stderr @@ -9,6 +9,24 @@ LL | Index::::index(&[1, 2, 3] as &[i32], 2u32); = help: the trait `Index` is not implemented for `[i32]` = help: the trait `Index` is implemented for `[i32]` -error: aborting due to previous error +error[E0277]: the trait bound `[i32]: Index` is not satisfied + --> $DIR/on-impl.rs:22:5 + | +LL | Index::::index(&[1, 2, 3] as &[i32], 2u32); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice + | + = help: the trait `Index` is not implemented for `[i32]` + = help: the trait `Index` is implemented for `[i32]` + +error[E0277]: the trait bound `[i32]: Index` is not satisfied + --> $DIR/on-impl.rs:22:5 + | +LL | Index::::index(&[1, 2, 3] as &[i32], 2u32); + | ^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice + | + = help: the trait `Index` is not implemented for `[i32]` + = help: the trait `Index` is implemented for `[i32]` + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/ufcs/ufcs-qpath-self-mismatch.rs b/src/test/ui/ufcs/ufcs-qpath-self-mismatch.rs index 939b3c5223c48..ec86213f8629d 100644 --- a/src/test/ui/ufcs/ufcs-qpath-self-mismatch.rs +++ b/src/test/ui/ufcs/ufcs-qpath-self-mismatch.rs @@ -3,6 +3,7 @@ use std::ops::Add; fn main() { >::add(1, 2); //~^ ERROR cannot add `u32` to `i32` + //~| ERROR cannot add `u32` to `i32` >::add(1u32, 2); //~^ ERROR mismatched types >::add(1, 2u32); diff --git a/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr b/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr index f08c81bc1e937..eaab6ff3d9a04 100644 --- a/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr +++ b/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr @@ -19,7 +19,7 @@ LL | >::add(1, 2); and 48 others error[E0308]: mismatched types - --> $DIR/ufcs-qpath-self-mismatch.rs:6:28 + --> $DIR/ufcs-qpath-self-mismatch.rs:7:28 | LL | >::add(1u32, 2); | ---------------------- ^^^^ expected `i32`, found `u32` @@ -37,7 +37,7 @@ LL | >::add(1i32, 2); | ~~~ error[E0308]: mismatched types - --> $DIR/ufcs-qpath-self-mismatch.rs:8:31 + --> $DIR/ufcs-qpath-self-mismatch.rs:9:31 | LL | >::add(1, 2u32); | ---------------------- ^^^^ expected `i32`, found `u32` @@ -54,7 +54,25 @@ help: change the type of the numeric literal from `u32` to `i32` LL | >::add(1, 2i32); | ~~~ -error: aborting due to 3 previous errors +error[E0277]: cannot add `u32` to `i32` + --> $DIR/ufcs-qpath-self-mismatch.rs:4:5 + | +LL | >::add(1, 2); + | ^^^^^^^^^^^^^^^^^^^^^^ no implementation for `i32 + u32` + | + = help: the trait `Add` is not implemented for `i32` + = help: the following other types implement trait `Add`: + <&'a f32 as Add> + <&'a f64 as Add> + <&'a i128 as Add> + <&'a i16 as Add> + <&'a i32 as Add> + <&'a i64 as Add> + <&'a i8 as Add> + <&'a isize as Add> + and 48 others + +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/unsized/issue-30355.stderr b/src/test/ui/unsized/issue-30355.stderr index f5491552a45d2..71bbdf5dec769 100644 --- a/src/test/ui/unsized/issue-30355.stderr +++ b/src/test/ui/unsized/issue-30355.stderr @@ -5,11 +5,8 @@ LL | &X(*Y) | ^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` + = note: all function arguments must have a statically known size = help: unsized fn params are gated as an unstable feature -help: function arguments must have a statically known size, borrowed types always have a known size - | -LL | &X(&*Y) - | + error: aborting due to previous error From 8fd06e44d45358943b23e1713e23d1f1ed30d141 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 24 Aug 2022 19:59:06 +0000 Subject: [PATCH 2/5] Pass arg span to sized arg cause code --- compiler/rustc_typeck/src/check/expr.rs | 9 ++--- .../associated-types-path-2.rs | 2 -- .../associated-types-path-2.stderr | 34 ++++++++----------- .../feature-gate-unsized_fn_params.stderr | 5 ++- src/test/ui/unsized/issue-30355.rs | 1 + src/test/ui/unsized/issue-30355.stderr | 21 ++++++++++-- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 1a97fc505fddd..818f04ec1d54d 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -561,17 +561,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // We just want to check sizedness, so instead of introducing // placeholder lifetimes with probing, we just replace higher lifetimes // with fresh vars. - let span = args.get(i).map(|a| a.span).unwrap_or(expr.span); + let arg_span = args.get(i).map(|a| a.span); + let span = arg_span.unwrap_or(expr.span); let input = self.replace_bound_vars_with_fresh_vars( span, infer::LateBoundRegionConversionTime::FnCall, fn_sig.input(i), ); - self.require_type_is_sized_deferred( - input, - span, - traits::SizedArgumentType(None), - ); + self.require_type_is_sized(input, span, traits::SizedArgumentType(arg_span)); } } // Here we want to prevent struct constructors from returning unsized types. diff --git a/src/test/ui/associated-types/associated-types-path-2.rs b/src/test/ui/associated-types/associated-types-path-2.rs index 00066efccb8dd..c993e1d27202d 100644 --- a/src/test/ui/associated-types/associated-types-path-2.rs +++ b/src/test/ui/associated-types/associated-types-path-2.rs @@ -29,14 +29,12 @@ pub fn f1_uint_uint() { f1(2u32, 4u32); //~^ ERROR `u32: Foo` is not satisfied //~| ERROR `u32: Foo` is not satisfied - //~| ERROR `u32: Foo` is not satisfied } pub fn f1_uint_int() { f1(2u32, 4i32); //~^ ERROR `u32: Foo` is not satisfied //~| ERROR `u32: Foo` is not satisfied - //~| ERROR `u32: Foo` is not satisfied } pub fn f2_int() { diff --git a/src/test/ui/associated-types/associated-types-path-2.stderr b/src/test/ui/associated-types/associated-types-path-2.stderr index 206f490241026..e06a92bfcfc6f 100644 --- a/src/test/ui/associated-types/associated-types-path-2.stderr +++ b/src/test/ui/associated-types/associated-types-path-2.stderr @@ -31,14 +31,6 @@ note: required by a bound in `f1` LL | pub fn f1(a: T, x: T::A) {} | ^^^ required by this bound in `f1` -error[E0277]: the trait bound `u32: Foo` is not satisfied - --> $DIR/associated-types-path-2.rs:29:5 - | -LL | f1(2u32, 4u32); - | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u32` - | - = help: the trait `Foo` is implemented for `i32` - error[E0277]: the trait bound `u32: Foo` is not satisfied --> $DIR/associated-types-path-2.rs:29:14 | @@ -46,9 +38,14 @@ LL | f1(2u32, 4u32); | ^^^^ the trait `Foo` is not implemented for `u32` | = help: the trait `Foo` is implemented for `i32` + = help: unsized fn params are gated as an unstable feature +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | f1(2u32, &4u32); + | + error[E0277]: the trait bound `u32: Foo` is not satisfied - --> $DIR/associated-types-path-2.rs:36:8 + --> $DIR/associated-types-path-2.rs:35:8 | LL | f1(2u32, 4i32); | -- ^^^^ the trait `Foo` is not implemented for `u32` @@ -63,23 +60,20 @@ LL | pub fn f1(a: T, x: T::A) {} | ^^^ required by this bound in `f1` error[E0277]: the trait bound `u32: Foo` is not satisfied - --> $DIR/associated-types-path-2.rs:36:5 - | -LL | f1(2u32, 4i32); - | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u32` - | - = help: the trait `Foo` is implemented for `i32` - -error[E0277]: the trait bound `u32: Foo` is not satisfied - --> $DIR/associated-types-path-2.rs:36:14 + --> $DIR/associated-types-path-2.rs:35:14 | LL | f1(2u32, 4i32); | ^^^^ the trait `Foo` is not implemented for `u32` | = help: the trait `Foo` is implemented for `i32` + = help: unsized fn params are gated as an unstable feature +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | f1(2u32, &4i32); + | + error[E0308]: mismatched types - --> $DIR/associated-types-path-2.rs:43:18 + --> $DIR/associated-types-path-2.rs:41:18 | LL | let _: i32 = f2(2i32); | --- ^^^^^^^^ expected `i32`, found `u32` @@ -91,7 +85,7 @@ help: you can convert a `u32` to an `i32` and panic if the converted value doesn LL | let _: i32 = f2(2i32).try_into().unwrap(); | ++++++++++++++++++++ -error: aborting due to 8 previous errors +error: aborting due to 6 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/feature-gates/feature-gate-unsized_fn_params.stderr b/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr index 0f7520ef7f8a9..b7757740d9e34 100644 --- a/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr +++ b/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr @@ -18,8 +18,11 @@ LL | foo(*x); | ^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `(dyn Foo + 'static)` - = note: all function arguments must have a statically known size = help: unsized fn params are gated as an unstable feature +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | foo(&*x); + | + error: aborting due to 2 previous errors diff --git a/src/test/ui/unsized/issue-30355.rs b/src/test/ui/unsized/issue-30355.rs index 6ff5b37f6e5b9..0181109050320 100644 --- a/src/test/ui/unsized/issue-30355.rs +++ b/src/test/ui/unsized/issue-30355.rs @@ -4,6 +4,7 @@ pub static Y: &'static X = { const Y: &'static [u8] = b""; &X(*Y) //~^ ERROR E0277 + //~| ERROR E0277 }; fn main() {} diff --git a/src/test/ui/unsized/issue-30355.stderr b/src/test/ui/unsized/issue-30355.stderr index 71bbdf5dec769..32ee0a21aa487 100644 --- a/src/test/ui/unsized/issue-30355.stderr +++ b/src/test/ui/unsized/issue-30355.stderr @@ -5,9 +5,26 @@ LL | &X(*Y) | ^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` - = note: all function arguments must have a statically known size = help: unsized fn params are gated as an unstable feature +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | &X(&*Y) + | + + +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time + --> $DIR/issue-30355.rs:5:6 + | +LL | &X(*Y) + | ^ doesn't have a size known at compile-time + | + = help: within `X`, the trait `Sized` is not implemented for `[u8]` +note: required because it appears within the type `X` + --> $DIR/issue-30355.rs:1:12 + | +LL | pub struct X([u8]); + | ^ + = note: the return type of a function must have a statically known size -error: aborting due to previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. From 047c4fa919a058f918b56ffbb41520acd9b4b453 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 24 Aug 2022 20:15:29 +0000 Subject: [PATCH 3/5] Delay all sized checks --- .../src/traits/error_reporting/suggestions.rs | 2 +- compiler/rustc_typeck/src/check/expr.rs | 2 +- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 16 ++-- compiler/rustc_typeck/src/check/inherited.rs | 4 +- compiler/rustc_typeck/src/check/mod.rs | 9 +-- src/test/ui/asm/type-check-1.rs | 6 +- src/test/ui/asm/type-check-1.stderr | 40 +++------- .../associated-types-path-2.rs | 2 + .../associated-types-path-2.stderr | 34 +++++---- src/test/ui/error-codes/E0282.rs | 2 +- src/test/ui/error-codes/E0282.stderr | 18 +++-- src/test/ui/generator/sized-yield.stderr | 26 +++---- src/test/ui/impl-trait/rpit-not-sized.stderr | 3 + src/test/ui/inference/issue-72690.stderr | 16 ++-- .../inference/question-mark-type-infer.stderr | 14 +++- src/test/ui/issues/issue-12187-1.stderr | 2 +- src/test/ui/issues/issue-12187-2.stderr | 2 +- src/test/ui/issues/issue-24036.stderr | 9 ++- src/test/ui/issues/issue-5883.rs | 2 +- src/test/ui/issues/issue-5883.stderr | 18 +---- .../ui/iterators/collect-into-slice.stderr | 20 ++--- src/test/ui/str/str-array-assignment.stderr | 20 ++--- src/test/ui/str/str-mut-idx.rs | 1 - src/test/ui/str/str-mut-idx.stderr | 19 ++--- .../trivial-bounds/trivial-bounds-leak.stderr | 2 + src/test/ui/unsized-locals/unsized-exprs.rs | 2 - .../ui/unsized-locals/unsized-exprs.stderr | 34 +-------- src/test/ui/unsized/issue-30355.rs | 1 - src/test/ui/unsized/issue-30355.stderr | 16 +--- src/test/ui/unsized/unsized3.stderr | 32 ++++---- src/test/ui/unsized/unsized6.rs | 4 - src/test/ui/unsized/unsized6.stderr | 76 +------------------ 32 files changed, 160 insertions(+), 294 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index a93f9ec0397d2..2edbae29766b3 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1398,7 +1398,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { (_, ty)| { let ty = self.resolve_vars_if_possible(ty); same &= - !matches!(ty.kind(), ty::Error(_)) + !ty.references_error() && last_ty.map_or(true, |last_ty| { // FIXME: ideally we would use `can_coerce` here instead, but `typeck` comes // *after* in the dependency graph. diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 818f04ec1d54d..d619cab6c5879 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -582,7 +582,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { infer::LateBoundRegionConversionTime::FnCall, fn_sig.output(), ); - self.require_type_is_sized_deferred(output, expr.span, traits::SizedReturnType); + self.require_type_is_sized(output, expr.span, traits::SizedReturnType); } // We always require that the type provided as the value for diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 1f47aabefdec7..8545b1c3d6f75 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -13,7 +13,6 @@ use rustc_errors::{Applicability, Diagnostic, ErrorGuaranteed, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; -use rustc_hir::lang_items::LangItem; use rustc_hir::{ExprKind, GenericArg, Node, QPath}; use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse}; use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282; @@ -437,19 +436,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { code: traits::ObligationCauseCode<'tcx>, ) { if !ty.references_error() { - let lang_item = self.tcx.require_lang_item(LangItem::Sized, None); - self.require_type_meets(ty, span, code, lang_item); + if let Some(deferred_sized_obligations) = + &mut *self.deferred_sized_obligations.borrow_mut() + { + deferred_sized_obligations.push((ty, span, code)); + } else { + self.require_type_is_sized_eager(ty, span, code); + } } } - pub fn require_type_is_sized_deferred( + pub fn require_type_is_sized_eager( &self, ty: Ty<'tcx>, span: Span, code: traits::ObligationCauseCode<'tcx>, ) { + let ty = self.normalize_associated_types_in(span, ty); if !ty.references_error() { - self.deferred_sized_obligations.borrow_mut().push((ty, span, code)); + let lang_item = self.tcx.require_lang_item(hir::LangItem::Sized, None); + self.require_type_meets(ty, span, code, lang_item); } } diff --git a/compiler/rustc_typeck/src/check/inherited.rs b/compiler/rustc_typeck/src/check/inherited.rs index cd152eb97f1bf..dce554cebc78e 100644 --- a/compiler/rustc_typeck/src/check/inherited.rs +++ b/compiler/rustc_typeck/src/check/inherited.rs @@ -38,7 +38,7 @@ pub struct Inherited<'a, 'tcx> { // Some additional `Sized` obligations badly affect type inference. // These obligations are added in a later stage of typeck. pub(super) deferred_sized_obligations: - RefCell, Span, traits::ObligationCauseCode<'tcx>)>>, + RefCell, Span, traits::ObligationCauseCode<'tcx>)>>>, // When we process a call like `c()` where `c` is a closure type, // we may not have decided yet whether `c` is a `Fn`, `FnMut`, or @@ -117,7 +117,7 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> { infcx, fulfillment_cx: RefCell::new(>::new(tcx)), locals: RefCell::new(Default::default()), - deferred_sized_obligations: RefCell::new(Vec::new()), + deferred_sized_obligations: RefCell::new(Some(Vec::new())), deferred_call_resolutions: RefCell::new(Default::default()), deferred_cast_checks: RefCell::new(Vec::new()), deferred_transmute_checks: RefCell::new(Vec::new()), diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index 07c202859cc9b..b74d8cb803c69 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -450,6 +450,10 @@ fn typeck_with_fallback<'tcx>( fcx }; + for (ty, span, code) in fcx.deferred_sized_obligations.borrow_mut().take().unwrap() { + fcx.require_type_is_sized_eager(ty, span, code); + } + let fallback_has_occurred = fcx.type_inference_fallback(); // Even though coercion casts provide type hints, we check casts after fallback for @@ -466,11 +470,6 @@ fn typeck_with_fallback<'tcx>( fcx.resolve_rvalue_scopes(def_id.to_def_id()); fcx.resolve_generator_interiors(def_id.to_def_id()); - for (ty, span, code) in fcx.deferred_sized_obligations.borrow_mut().drain(..) { - let ty = fcx.normalize_ty(span, ty); - fcx.require_type_is_sized(ty, span, code); - } - fcx.select_all_obligations_or_error(); if !fcx.infcx.is_tainted_by_errors() { diff --git a/src/test/ui/asm/type-check-1.rs b/src/test/ui/asm/type-check-1.rs index 50b369ae04527..90c1136a08be7 100644 --- a/src/test/ui/asm/type-check-1.rs +++ b/src/test/ui/asm/type-check-1.rs @@ -24,11 +24,9 @@ fn main() { //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time //~| ERROR cannot use value of type `[u64]` for inline assembly asm!("{}", out(reg) v[..]); - //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time - //~| ERROR cannot use value of type `[u64]` for inline assembly + //~^ ERROR cannot use value of type `[u64]` for inline assembly asm!("{}", inout(reg) v[..]); - //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time - //~| ERROR cannot use value of type `[u64]` for inline assembly + //~^ ERROR cannot use value of type `[u64]` for inline assembly // Constants must be... constant diff --git a/src/test/ui/asm/type-check-1.stderr b/src/test/ui/asm/type-check-1.stderr index 162ff1d32bc44..d3760cd122edf 100644 --- a/src/test/ui/asm/type-check-1.stderr +++ b/src/test/ui/asm/type-check-1.stderr @@ -1,5 +1,5 @@ error[E0435]: attempt to use a non-constant value in a constant - --> $DIR/type-check-1.rs:42:26 + --> $DIR/type-check-1.rs:40:26 | LL | let x = 0; | ----- help: consider using `const` instead of `let`: `const x` @@ -8,7 +8,7 @@ LL | asm!("{}", const x); | ^ non-constant value error[E0435]: attempt to use a non-constant value in a constant - --> $DIR/type-check-1.rs:45:36 + --> $DIR/type-check-1.rs:43:36 | LL | let x = 0; | ----- help: consider using `const` instead of `let`: `const x` @@ -17,7 +17,7 @@ LL | asm!("{}", const const_foo(x)); | ^ non-constant value error[E0435]: attempt to use a non-constant value in a constant - --> $DIR/type-check-1.rs:48:36 + --> $DIR/type-check-1.rs:46:36 | LL | let x = 0; | ----- help: consider using `const` instead of `let`: `const x` @@ -26,7 +26,7 @@ LL | asm!("{}", const const_bar(x)); | ^ non-constant value error: invalid `sym` operand - --> $DIR/type-check-1.rs:50:24 + --> $DIR/type-check-1.rs:48:24 | LL | asm!("{}", sym x); | ^ is a local variable @@ -54,24 +54,6 @@ LL | asm!("{}", in(reg) v[..]); = help: the trait `Sized` is not implemented for `[u64]` = note: all inline asm arguments must have a statically known size -error[E0277]: the size for values of type `[u64]` cannot be known at compilation time - --> $DIR/type-check-1.rs:26:29 - | -LL | asm!("{}", out(reg) v[..]); - | ^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u64]` - = note: all inline asm arguments must have a statically known size - -error[E0277]: the size for values of type `[u64]` cannot be known at compilation time - --> $DIR/type-check-1.rs:29:31 - | -LL | asm!("{}", inout(reg) v[..]); - | ^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u64]` - = note: all inline asm arguments must have a statically known size - error: cannot use value of type `[u64]` for inline assembly --> $DIR/type-check-1.rs:23:28 | @@ -89,7 +71,7 @@ LL | asm!("{}", out(reg) v[..]); = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly error: cannot use value of type `[u64]` for inline assembly - --> $DIR/type-check-1.rs:29:31 + --> $DIR/type-check-1.rs:28:31 | LL | asm!("{}", inout(reg) v[..]); | ^^^^^ @@ -97,13 +79,13 @@ LL | asm!("{}", inout(reg) v[..]); = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly error[E0308]: mismatched types - --> $DIR/type-check-1.rs:58:26 + --> $DIR/type-check-1.rs:56:26 | LL | asm!("{}", const 0f32); | ^^^^ expected integer, found `f32` error[E0308]: mismatched types - --> $DIR/type-check-1.rs:60:26 + --> $DIR/type-check-1.rs:58:26 | LL | asm!("{}", const 0 as *mut u8); | ^^^^^^^^^^^^ expected integer, found *-ptr @@ -112,7 +94,7 @@ LL | asm!("{}", const 0 as *mut u8); found raw pointer `*mut u8` error[E0308]: mismatched types - --> $DIR/type-check-1.rs:62:26 + --> $DIR/type-check-1.rs:60:26 | LL | asm!("{}", const &0); | ^^ expected integer, found `&{integer}` @@ -124,13 +106,13 @@ LL + asm!("{}", const 0); | error[E0308]: mismatched types - --> $DIR/type-check-1.rs:76:25 + --> $DIR/type-check-1.rs:74:25 | LL | global_asm!("{}", const 0f32); | ^^^^ expected integer, found `f32` error[E0308]: mismatched types - --> $DIR/type-check-1.rs:78:25 + --> $DIR/type-check-1.rs:76:25 | LL | global_asm!("{}", const 0 as *mut u8); | ^^^^^^^^^^^^ expected integer, found *-ptr @@ -138,7 +120,7 @@ LL | global_asm!("{}", const 0 as *mut u8); = note: expected type `{integer}` found raw pointer `*mut u8` -error: aborting due to 17 previous errors +error: aborting due to 15 previous errors Some errors have detailed explanations: E0277, E0308, E0435. For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/associated-types/associated-types-path-2.rs b/src/test/ui/associated-types/associated-types-path-2.rs index c993e1d27202d..00066efccb8dd 100644 --- a/src/test/ui/associated-types/associated-types-path-2.rs +++ b/src/test/ui/associated-types/associated-types-path-2.rs @@ -29,12 +29,14 @@ pub fn f1_uint_uint() { f1(2u32, 4u32); //~^ ERROR `u32: Foo` is not satisfied //~| ERROR `u32: Foo` is not satisfied + //~| ERROR `u32: Foo` is not satisfied } pub fn f1_uint_int() { f1(2u32, 4i32); //~^ ERROR `u32: Foo` is not satisfied //~| ERROR `u32: Foo` is not satisfied + //~| ERROR `u32: Foo` is not satisfied } pub fn f2_int() { diff --git a/src/test/ui/associated-types/associated-types-path-2.stderr b/src/test/ui/associated-types/associated-types-path-2.stderr index e06a92bfcfc6f..206f490241026 100644 --- a/src/test/ui/associated-types/associated-types-path-2.stderr +++ b/src/test/ui/associated-types/associated-types-path-2.stderr @@ -31,6 +31,14 @@ note: required by a bound in `f1` LL | pub fn f1(a: T, x: T::A) {} | ^^^ required by this bound in `f1` +error[E0277]: the trait bound `u32: Foo` is not satisfied + --> $DIR/associated-types-path-2.rs:29:5 + | +LL | f1(2u32, 4u32); + | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u32` + | + = help: the trait `Foo` is implemented for `i32` + error[E0277]: the trait bound `u32: Foo` is not satisfied --> $DIR/associated-types-path-2.rs:29:14 | @@ -38,14 +46,9 @@ LL | f1(2u32, 4u32); | ^^^^ the trait `Foo` is not implemented for `u32` | = help: the trait `Foo` is implemented for `i32` - = help: unsized fn params are gated as an unstable feature -help: function arguments must have a statically known size, borrowed types always have a known size - | -LL | f1(2u32, &4u32); - | + error[E0277]: the trait bound `u32: Foo` is not satisfied - --> $DIR/associated-types-path-2.rs:35:8 + --> $DIR/associated-types-path-2.rs:36:8 | LL | f1(2u32, 4i32); | -- ^^^^ the trait `Foo` is not implemented for `u32` @@ -60,20 +63,23 @@ LL | pub fn f1(a: T, x: T::A) {} | ^^^ required by this bound in `f1` error[E0277]: the trait bound `u32: Foo` is not satisfied - --> $DIR/associated-types-path-2.rs:35:14 + --> $DIR/associated-types-path-2.rs:36:5 | LL | f1(2u32, 4i32); - | ^^^^ the trait `Foo` is not implemented for `u32` + | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u32` | = help: the trait `Foo` is implemented for `i32` - = help: unsized fn params are gated as an unstable feature -help: function arguments must have a statically known size, borrowed types always have a known size + +error[E0277]: the trait bound `u32: Foo` is not satisfied + --> $DIR/associated-types-path-2.rs:36:14 | -LL | f1(2u32, &4i32); - | + +LL | f1(2u32, 4i32); + | ^^^^ the trait `Foo` is not implemented for `u32` + | + = help: the trait `Foo` is implemented for `i32` error[E0308]: mismatched types - --> $DIR/associated-types-path-2.rs:41:18 + --> $DIR/associated-types-path-2.rs:43:18 | LL | let _: i32 = f2(2i32); | --- ^^^^^^^^ expected `i32`, found `u32` @@ -85,7 +91,7 @@ help: you can convert a `u32` to an `i32` and panic if the converted value doesn LL | let _: i32 = f2(2i32).try_into().unwrap(); | ++++++++++++++++++++ -error: aborting due to 6 previous errors +error: aborting due to 8 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/error-codes/E0282.rs b/src/test/ui/error-codes/E0282.rs index 9bd16abb7bb83..1df5c7f7dbb33 100644 --- a/src/test/ui/error-codes/E0282.rs +++ b/src/test/ui/error-codes/E0282.rs @@ -1,3 +1,3 @@ fn main() { - let x = "hello".chars().rev().collect(); //~ ERROR E0282 + let x = "hello".chars().rev().collect(); //~ ERROR E0283 } diff --git a/src/test/ui/error-codes/E0282.stderr b/src/test/ui/error-codes/E0282.stderr index d01aa3617c764..3be534fdda1c1 100644 --- a/src/test/ui/error-codes/E0282.stderr +++ b/src/test/ui/error-codes/E0282.stderr @@ -1,14 +1,20 @@ -error[E0282]: type annotations needed +error[E0283]: type annotations needed --> $DIR/E0282.rs:2:9 | LL | let x = "hello".chars().rev().collect(); - | ^ + | ^ ------- type must be known at this point | -help: consider giving `x` an explicit type + = note: cannot satisfy `_: FromIterator` +note: required by a bound in `collect` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | -LL | let x: _ = "hello".chars().rev().collect(); - | +++ +LL | fn collect>(self) -> B + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect` +help: consider specifying the type argument in the function call + | +LL | let x = "hello".chars().rev().collect::(); + | +++++ error: aborting due to previous error -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0283`. diff --git a/src/test/ui/generator/sized-yield.stderr b/src/test/ui/generator/sized-yield.stderr index ea2a48d13cee6..f65599ebb1354 100644 --- a/src/test/ui/generator/sized-yield.stderr +++ b/src/test/ui/generator/sized-yield.stderr @@ -1,16 +1,3 @@ -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/sized-yield.rs:8:26 - | -LL | let mut gen = move || { - | __________________________^ -LL | | -LL | | yield s[..]; -LL | | }; - | |____^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `str` - = note: the yield type of a generator must have a statically known size - error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/sized-yield.rs:12:23 | @@ -24,6 +11,19 @@ note: required by a bound in `GeneratorState` LL | pub enum GeneratorState { | ^ required by this bound in `GeneratorState` +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/sized-yield.rs:8:26 + | +LL | let mut gen = move || { + | __________________________^ +LL | | +LL | | yield s[..]; +LL | | }; + | |____^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` + = note: the yield type of a generator must have a statically known size + error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/impl-trait/rpit-not-sized.stderr b/src/test/ui/impl-trait/rpit-not-sized.stderr index 608c94fc07237..b247c2bfeca1c 100644 --- a/src/test/ui/impl-trait/rpit-not-sized.stderr +++ b/src/test/ui/impl-trait/rpit-not-sized.stderr @@ -3,6 +3,9 @@ error[E0277]: the size for values of type `impl ?Sized` cannot be known at compi | LL | fn foo() -> impl ?Sized { | ^^^^^^^^^^^ doesn't have a size known at compile-time +LL | +LL | () + | -- this returned value is of type `()` | = help: the trait `Sized` is not implemented for `impl ?Sized` = note: the return type of a function must have a statically known size diff --git a/src/test/ui/inference/issue-72690.stderr b/src/test/ui/inference/issue-72690.stderr index d4eeda07366a8..b74970c61a099 100644 --- a/src/test/ui/inference/issue-72690.stderr +++ b/src/test/ui/inference/issue-72690.stderr @@ -24,16 +24,15 @@ help: try using a fully qualified path to specify the expected types LL | String::from(>::as_ref("x")); | ++++++++++++++++++++++++++ ~ -error[E0282]: type annotations needed - --> $DIR/issue-72690.rs:12:6 +error[E0283]: type annotations needed + --> $DIR/issue-72690.rs:12:9 | LL | |x| String::from("x".as_ref()); - | ^ - | -help: consider giving this closure parameter an explicit type + | ^^^^^^^^^^^^ cannot infer type for reference `&_` | -LL | |x: _| String::from("x".as_ref()); - | +++ + = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: + - impl<> From<&String> for String; + - impl<> From<&str> for String; error[E0283]: type annotations needed --> $DIR/issue-72690.rs:12:26 @@ -225,5 +224,4 @@ LL | String::from(>::as_ref("x")); error: aborting due to 17 previous errors -Some errors have detailed explanations: E0282, E0283. -For more information about an error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0283`. diff --git a/src/test/ui/inference/question-mark-type-infer.stderr b/src/test/ui/inference/question-mark-type-infer.stderr index 9b822714f828a..920dd166cf032 100644 --- a/src/test/ui/inference/question-mark-type-infer.stderr +++ b/src/test/ui/inference/question-mark-type-infer.stderr @@ -1,9 +1,15 @@ -error[E0282]: type annotations needed - --> $DIR/question-mark-type-infer.rs:10:30 +error[E0284]: type annotations needed + --> $DIR/question-mark-type-infer.rs:10:21 | LL | l.iter().map(f).collect()? - | ^ cannot infer type + | ^^^^^^^ cannot infer type of the type parameter `B` declared on the associated function `collect` + | + = note: cannot satisfy `<_ as Try>::Residual == _` +help: consider specifying the generic argument + | +LL | l.iter().map(f).collect::()? + | +++++ error: aborting due to previous error -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0284`. diff --git a/src/test/ui/issues/issue-12187-1.stderr b/src/test/ui/issues/issue-12187-1.stderr index 806b7f0ac05e9..de00a2df49253 100644 --- a/src/test/ui/issues/issue-12187-1.stderr +++ b/src/test/ui/issues/issue-12187-1.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `&T` LL | let &v = new(); | ^^ | -help: consider giving this pattern a type, where the placeholders `_` are specified +help: consider giving this pattern a type, where the type for type parameter `T` is specified | LL | let &v: &T = new(); | ++++ diff --git a/src/test/ui/issues/issue-12187-2.stderr b/src/test/ui/issues/issue-12187-2.stderr index a1fa0a2b00245..09de8ae4deabb 100644 --- a/src/test/ui/issues/issue-12187-2.stderr +++ b/src/test/ui/issues/issue-12187-2.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `&T` LL | let &v = new(); | ^^ | -help: consider giving this pattern a type, where the placeholders `_` are specified +help: consider giving this pattern a type, where the type for type parameter `T` is specified | LL | let &v: &T = new(); | ++++ diff --git a/src/test/ui/issues/issue-24036.stderr b/src/test/ui/issues/issue-24036.stderr index a42e35c4cad5c..37a3f29e2bb4b 100644 --- a/src/test/ui/issues/issue-24036.stderr +++ b/src/test/ui/issues/issue-24036.stderr @@ -11,12 +11,13 @@ LL | x = |c| c + 1; = note: no two closures, even if identical, have the same type = help: consider boxing your closure and/or using it as a trait object -error[E0282]: type annotations needed +error[E0284]: type annotations needed --> $DIR/issue-24036.rs:9:15 | LL | 1 => |c| c + 1, - | ^ + | ^ - type must be known at this point | + = note: cannot satisfy `<_ as Add>::Output == _` help: consider giving this closure parameter an explicit type | LL | 1 => |c: _| c + 1, @@ -24,5 +25,5 @@ LL | 1 => |c: _| c + 1, error: aborting due to 2 previous errors -Some errors have detailed explanations: E0282, E0308. -For more information about an error, try `rustc --explain E0282`. +Some errors have detailed explanations: E0284, E0308. +For more information about an error, try `rustc --explain E0284`. diff --git a/src/test/ui/issues/issue-5883.rs b/src/test/ui/issues/issue-5883.rs index 82866b355573c..f9dd2c54d997f 100644 --- a/src/test/ui/issues/issue-5883.rs +++ b/src/test/ui/issues/issue-5883.rs @@ -6,7 +6,7 @@ struct Struct { fn new_struct( r: dyn A + 'static //~ ERROR the size for values of type -) -> Struct { //~ ERROR the size for values of type +) -> Struct { Struct { r: r } } diff --git a/src/test/ui/issues/issue-5883.stderr b/src/test/ui/issues/issue-5883.stderr index 8a20a60853a63..fa542f3e6deea 100644 --- a/src/test/ui/issues/issue-5883.stderr +++ b/src/test/ui/issues/issue-5883.stderr @@ -11,22 +11,6 @@ help: function arguments must have a statically known size, borrowed types alway LL | r: &dyn A + 'static | + -error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time - --> $DIR/issue-5883.rs:9:6 - | -LL | ) -> Struct { - | ^^^^^^ doesn't have a size known at compile-time -LL | Struct { r: r } - | --------------- this returned value is of type `Struct` - | - = help: within `Struct`, the trait `Sized` is not implemented for `(dyn A + 'static)` -note: required because it appears within the type `Struct` - --> $DIR/issue-5883.rs:3:8 - | -LL | struct Struct { - | ^^^^^^ - = note: the return type of a function must have a statically known size - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/iterators/collect-into-slice.stderr b/src/test/ui/iterators/collect-into-slice.stderr index bce40118bdfa0..207bb50bff508 100644 --- a/src/test/ui/iterators/collect-into-slice.stderr +++ b/src/test/ui/iterators/collect-into-slice.stderr @@ -1,13 +1,3 @@ -error[E0277]: the size for values of type `[i32]` cannot be known at compilation time - --> $DIR/collect-into-slice.rs:8:9 - | -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: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - error[E0277]: the size for values of type `[i32]` cannot be known at compilation time --> $DIR/collect-into-slice.rs:8:38 | @@ -36,6 +26,16 @@ note: required by a bound in `collect` LL | fn collect>(self) -> B | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect` +error[E0277]: the size for values of type `[i32]` cannot be known at compilation time + --> $DIR/collect-into-slice.rs:8:9 + | +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: all local variables must have a statically known size + = help: unsized locals are gated as an unstable feature + error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/str/str-array-assignment.stderr b/src/test/ui/str/str-array-assignment.stderr index c23400a1d14a7..660eebf187054 100644 --- a/src/test/ui/str/str-array-assignment.stderr +++ b/src/test/ui/str/str-array-assignment.stderr @@ -15,6 +15,16 @@ LL | let u: &str = if true { s[..2] } else { s }; | expected `&str`, found `str` | help: consider borrowing here: `&s[..2]` +error[E0308]: mismatched types + --> $DIR/str-array-assignment.rs:9:17 + | +LL | let w: &str = s[..2]; + | ---- ^^^^^^ + | | | + | | expected `&str`, found `str` + | | help: consider borrowing here: `&s[..2]` + | expected due to this + error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/str-array-assignment.rs:7:7 | @@ -29,16 +39,6 @@ help: consider borrowing here LL | let v = &s[..2]; | + -error[E0308]: mismatched types - --> $DIR/str-array-assignment.rs:9:17 - | -LL | let w: &str = s[..2]; - | ---- ^^^^^^ - | | | - | | expected `&str`, found `str` - | | help: consider borrowing here: `&s[..2]` - | expected due to this - error: aborting due to 4 previous errors Some errors have detailed explanations: E0277, E0308. diff --git a/src/test/ui/str/str-mut-idx.rs b/src/test/ui/str/str-mut-idx.rs index 575a9eae85946..89318b46679e4 100644 --- a/src/test/ui/str/str-mut-idx.rs +++ b/src/test/ui/str/str-mut-idx.rs @@ -3,7 +3,6 @@ fn bot() -> T { loop {} } fn mutate(s: &mut str) { s[1..2] = bot(); //~^ ERROR the size for values of type - //~| ERROR the size for values of type s[1usize] = bot(); //~^ ERROR the type `str` cannot be indexed by `usize` s.get_mut(1); diff --git a/src/test/ui/str/str-mut-idx.stderr b/src/test/ui/str/str-mut-idx.stderr index b165c482590a2..70963efa8307c 100644 --- a/src/test/ui/str/str-mut-idx.stderr +++ b/src/test/ui/str/str-mut-idx.stderr @@ -15,17 +15,8 @@ help: consider relaxing the implicit `Sized` restriction LL | fn bot() -> T { loop {} } | ++++++++ -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/str-mut-idx.rs:4:5 - | -LL | s[1..2] = bot(); - | ^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `str` - = note: the left-hand-side of an assignment must have a statically known size - error[E0277]: the type `str` cannot be indexed by `usize` - --> $DIR/str-mut-idx.rs:7:7 + --> $DIR/str-mut-idx.rs:6:7 | LL | s[1usize] = bot(); | ^^^^^^ string indices are ranges of `usize` @@ -35,7 +26,7 @@ LL | s[1usize] = bot(); = note: required for `str` to implement `Index` error[E0277]: the type `str` cannot be indexed by `{integer}` - --> $DIR/str-mut-idx.rs:9:15 + --> $DIR/str-mut-idx.rs:8:15 | LL | s.get_mut(1); | ------- ^ string indices are ranges of `usize` @@ -53,7 +44,7 @@ LL | pub const fn get_mut>(&mut self, i: I) -> Opt | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::::get_mut` error[E0277]: the type `str` cannot be indexed by `{integer}` - --> $DIR/str-mut-idx.rs:11:25 + --> $DIR/str-mut-idx.rs:10:25 | LL | s.get_unchecked_mut(1); | ----------------- ^ string indices are ranges of `usize` @@ -71,7 +62,7 @@ LL | pub const unsafe fn get_unchecked_mut>( | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::::get_unchecked_mut` error[E0277]: the type `str` cannot be indexed by `char` - --> $DIR/str-mut-idx.rs:13:7 + --> $DIR/str-mut-idx.rs:12:7 | LL | s['c']; | ^^^ string indices are ranges of `usize` @@ -79,6 +70,6 @@ LL | s['c']; = help: the trait `SliceIndex` is not implemented for `char` = note: required for `str` to implement `Index` -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/trivial-bounds/trivial-bounds-leak.stderr b/src/test/ui/trivial-bounds/trivial-bounds-leak.stderr index 02c5d5d248403..7c57189af87fd 100644 --- a/src/test/ui/trivial-bounds/trivial-bounds-leak.stderr +++ b/src/test/ui/trivial-bounds/trivial-bounds-leak.stderr @@ -3,6 +3,8 @@ error[E0277]: the size for values of type `str` cannot be known at compilation t | LL | fn cant_return_str() -> str { | ^^^ doesn't have a size known at compile-time +LL | *"Sized".to_string().into_boxed_str() + | ------------------------------------- this returned value is of type `str` | = help: the trait `Sized` is not implemented for `str` = note: the return type of a function must have a statically known size diff --git a/src/test/ui/unsized-locals/unsized-exprs.rs b/src/test/ui/unsized-locals/unsized-exprs.rs index 1729b9ffa8670..6127b3f563e95 100644 --- a/src/test/ui/unsized-locals/unsized-exprs.rs +++ b/src/test/ui/unsized-locals/unsized-exprs.rs @@ -22,7 +22,5 @@ fn main() { udrop::<(i32, [u8])>((42, *foo())); //~^ERROR E0277 udrop::>(A { 0: *foo() }); - //~^ERROR E0277 udrop::>(A(*foo())); - //~^ERROR E0277 } diff --git a/src/test/ui/unsized-locals/unsized-exprs.stderr b/src/test/ui/unsized-locals/unsized-exprs.stderr index a7f57e3fd1566..228d69572023e 100644 --- a/src/test/ui/unsized-locals/unsized-exprs.stderr +++ b/src/test/ui/unsized-locals/unsized-exprs.stderr @@ -4,38 +4,10 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation LL | udrop::<(i32, [u8])>((42, *foo())); | ^^^^^^^^^^^^ doesn't have a size known at compile-time | - = help: within `({integer}, [u8])`, the trait `Sized` is not implemented for `[u8]` - = note: required because it appears within the type `({integer}, [u8])` + = help: within `(i32, [u8])`, the trait `Sized` is not implemented for `[u8]` + = note: required because it appears within the type `(i32, [u8])` = note: tuples must have a statically known size to be initialized -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/unsized-exprs.rs:24:22 - | -LL | udrop::>(A { 0: *foo() }); - | ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: within `A<[u8]>`, the trait `Sized` is not implemented for `[u8]` -note: required because it appears within the type `A<[u8]>` - --> $DIR/unsized-exprs.rs:3:8 - | -LL | struct A(X); - | ^ - = note: structs must have a statically known size to be initialized - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/unsized-exprs.rs:26:22 - | -LL | udrop::>(A(*foo())); - | ^ doesn't have a size known at compile-time - | - = help: within `A<[u8]>`, the trait `Sized` is not implemented for `[u8]` -note: required because it appears within the type `A<[u8]>` - --> $DIR/unsized-exprs.rs:3:8 - | -LL | struct A(X); - | ^ - = note: the return type of a function must have a statically known size - -error: aborting due to 3 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unsized/issue-30355.rs b/src/test/ui/unsized/issue-30355.rs index 0181109050320..6ff5b37f6e5b9 100644 --- a/src/test/ui/unsized/issue-30355.rs +++ b/src/test/ui/unsized/issue-30355.rs @@ -4,7 +4,6 @@ pub static Y: &'static X = { const Y: &'static [u8] = b""; &X(*Y) //~^ ERROR E0277 - //~| ERROR E0277 }; fn main() {} diff --git a/src/test/ui/unsized/issue-30355.stderr b/src/test/ui/unsized/issue-30355.stderr index 32ee0a21aa487..f5491552a45d2 100644 --- a/src/test/ui/unsized/issue-30355.stderr +++ b/src/test/ui/unsized/issue-30355.stderr @@ -11,20 +11,6 @@ help: function arguments must have a statically known size, borrowed types alway LL | &X(&*Y) | + -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/issue-30355.rs:5:6 - | -LL | &X(*Y) - | ^ doesn't have a size known at compile-time - | - = help: within `X`, the trait `Sized` is not implemented for `[u8]` -note: required because it appears within the type `X` - --> $DIR/issue-30355.rs:1:12 - | -LL | pub struct X([u8]); - | ^ - = note: the return type of a function must have a statically known size - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unsized/unsized3.stderr b/src/test/ui/unsized/unsized3.stderr index 9ad1ac6b4df61..a3668306fe4f3 100644 --- a/src/test/ui/unsized/unsized3.stderr +++ b/src/test/ui/unsized/unsized3.stderr @@ -99,12 +99,14 @@ LL + fn f9(x1: Box>) { | error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized3.rs:45:9 + --> $DIR/unsized3.rs:45:8 | LL | fn f10(x1: Box>) { | - this type parameter needs to be `std::marker::Sized` LL | f5(&(32, *x1)); - | ^^^^^^^^^ doesn't have a size known at compile-time + | -- ^^^^^^^^^^ doesn't have a size known at compile-time + | | + | required by a bound introduced by this call | note: required because it appears within the type `S` --> $DIR/unsized3.rs:28:8 @@ -112,22 +114,28 @@ note: required because it appears within the type `S` LL | struct S { | ^ = note: required because it appears within the type `({integer}, S)` - = note: tuples must have a statically known size to be initialized +note: required by a bound in `f5` + --> $DIR/unsized3.rs:24:7 + | +LL | fn f5(x: &Y) {} + | ^ required by this bound in `f5` help: consider removing the `?Sized` bound to make the type parameter `Sized` | LL - fn f10(x1: Box>) { LL + fn f10(x1: Box>) { | +help: consider relaxing the implicit `Sized` restriction + | +LL | fn f5(x: &Y) {} + | ++++++++ error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized3.rs:45:8 + --> $DIR/unsized3.rs:45:9 | LL | fn f10(x1: Box>) { | - this type parameter needs to be `std::marker::Sized` LL | f5(&(32, *x1)); - | -- ^^^^^^^^^^ doesn't have a size known at compile-time - | | - | required by a bound introduced by this call + | ^^^^^^^^^ doesn't have a size known at compile-time | note: required because it appears within the type `S` --> $DIR/unsized3.rs:28:8 @@ -135,20 +143,12 @@ note: required because it appears within the type `S` LL | struct S { | ^ = note: required because it appears within the type `({integer}, S)` -note: required by a bound in `f5` - --> $DIR/unsized3.rs:24:7 - | -LL | fn f5(x: &Y) {} - | ^ required by this bound in `f5` + = note: tuples must have a statically known size to be initialized help: consider removing the `?Sized` bound to make the type parameter `Sized` | LL - fn f10(x1: Box>) { LL + fn f10(x1: Box>) { | -help: consider relaxing the implicit `Sized` restriction - | -LL | fn f5(x: &Y) {} - | ++++++++ error: aborting due to 6 previous errors diff --git a/src/test/ui/unsized/unsized6.rs b/src/test/ui/unsized/unsized6.rs index 79133554d5472..7c2f49c384752 100644 --- a/src/test/ui/unsized/unsized6.rs +++ b/src/test/ui/unsized/unsized6.rs @@ -22,17 +22,13 @@ fn f3(x1: Box, x2: Box, x3: Box) { let y: X = *x1; //~^ ERROR the size for values of type let y = *x2; - //~^ ERROR the size for values of type let (y, z) = (*x3, 4); - //~^ ERROR the size for values of type } fn f4(x1: Box, x2: Box, x3: Box) { let y: X = *x1; //~^ ERROR the size for values of type let y = *x2; - //~^ ERROR the size for values of type let (y, z) = (*x3, 4); - //~^ ERROR the size for values of type } fn g1(x: X) {} diff --git a/src/test/ui/unsized/unsized6.stderr b/src/test/ui/unsized/unsized6.stderr index 011f2b426c7cf..2bce81fdc6019 100644 --- a/src/test/ui/unsized/unsized6.stderr +++ b/src/test/ui/unsized/unsized6.stderr @@ -96,41 +96,7 @@ LL + fn f3(x1: Box, x2: Box, x3: Box) { | error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:24:9 - | -LL | fn f3(x1: Box, x2: Box, x3: Box) { - | - this type parameter needs to be `std::marker::Sized` -... -LL | let y = *x2; - | ^ doesn't have a size known at compile-time - | - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature -help: consider removing the `?Sized` bound to make the type parameter `Sized` - | -LL - fn f3(x1: Box, x2: Box, x3: Box) { -LL + fn f3(x1: Box, x2: Box, x3: Box) { - | - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:26:10 - | -LL | fn f3(x1: Box, x2: Box, x3: Box) { - | - this type parameter needs to be `std::marker::Sized` -... -LL | let (y, z) = (*x3, 4); - | ^ doesn't have a size known at compile-time - | - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature -help: consider removing the `?Sized` bound to make the type parameter `Sized` - | -LL - fn f3(x1: Box, x2: Box, x3: Box) { -LL + fn f3(x1: Box, x2: Box, x3: Box) { - | - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:30:9 + --> $DIR/unsized6.rs:28:9 | LL | fn f4(x1: Box, x2: Box, x3: Box) { | - this type parameter needs to be `std::marker::Sized` @@ -146,41 +112,7 @@ LL + fn f4(x1: Box, x2: Box, x3: Box) { | error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:32:9 - | -LL | fn f4(x1: Box, x2: Box, x3: Box) { - | - this type parameter needs to be `std::marker::Sized` -... -LL | let y = *x2; - | ^ doesn't have a size known at compile-time - | - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature -help: consider removing the `?Sized` bound to make the type parameter `Sized` - | -LL - fn f4(x1: Box, x2: Box, x3: Box) { -LL + fn f4(x1: Box, x2: Box, x3: Box) { - | - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:34:10 - | -LL | fn f4(x1: Box, x2: Box, x3: Box) { - | - this type parameter needs to be `std::marker::Sized` -... -LL | let (y, z) = (*x3, 4); - | ^ doesn't have a size known at compile-time - | - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature -help: consider removing the `?Sized` bound to make the type parameter `Sized` - | -LL - fn f4(x1: Box, x2: Box, x3: Box) { -LL + fn f4(x1: Box, x2: Box, x3: Box) { - | - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:38:18 + --> $DIR/unsized6.rs:34:18 | LL | fn g1(x: X) {} | - ^ doesn't have a size known at compile-time @@ -199,7 +131,7 @@ LL | fn g1(x: &X) {} | + error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:40:22 + --> $DIR/unsized6.rs:36:22 | LL | fn g2(x: X) {} | - ^ doesn't have a size known at compile-time @@ -217,6 +149,6 @@ help: function arguments must have a statically known size, borrowed types alway LL | fn g2(x: &X) {} | + -error: aborting due to 13 previous errors +error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0277`. From b6124edc00b74095319530c278f251fdf8002985 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 25 Aug 2022 19:14:58 +0000 Subject: [PATCH 4/5] Globally deduplicate matching fulfillment errors --- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 15 ++-- .../rustc_typeck/src/check/fn_ctxt/mod.rs | 10 +++ .../associated-types-path-2.rs | 2 - .../associated-types-path-2.stderr | 24 ++----- src/test/ui/box/into-boxed-slice-fail.rs | 2 - src/test/ui/box/into-boxed-slice-fail.stderr | 22 +----- src/test/ui/iterators/issue-28098.rs | 6 -- src/test/ui/iterators/issue-28098.stderr | 60 ++-------------- .../ui/on-unimplemented/multiple-impls.rs | 6 -- .../ui/on-unimplemented/multiple-impls.stderr | 72 +------------------ src/test/ui/on-unimplemented/on-impl.rs | 2 - src/test/ui/on-unimplemented/on-impl.stderr | 20 +----- .../suggestions/mut-borrow-needed-by-trait.rs | 1 - .../mut-borrow-needed-by-trait.stderr | 17 +---- .../negated-auto-traits-error.rs | 1 - .../negated-auto-traits-error.stderr | 25 ++----- src/test/ui/ufcs/ufcs-qpath-self-mismatch.rs | 1 - .../ui/ufcs/ufcs-qpath-self-mismatch.stderr | 24 +------ 18 files changed, 42 insertions(+), 268 deletions(-) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 03bd485096a9c..7dfd420e1916d 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -15,7 +15,6 @@ use crate::check::{ use crate::structured_errors::StructuredDiagnostic; use rustc_ast as ast; -use rustc_data_structures::fx::FxHashSet; use rustc_errors::{pluralize, Applicability, Diagnostic, DiagnosticId, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; @@ -1618,12 +1617,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, errors: &mut Vec>, ) { - // Store a mapping from `(Span, Predicate) -> ObligationCause`, so that - // other errors that have the same span and predicate can also get fixed, - // even if their `ObligationCauseCode` isn't an `Expr*Obligation` kind. - // This is important since if we adjust one span but not the other, then - // we will have "duplicated" the error on the UI side. - let mut remap_cause = FxHashSet::default(); let mut not_adjusted = vec![]; for error in errors { @@ -1634,6 +1627,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Store both the predicate and the predicate *without constness* // since sometimes we instantiate and check both of these in a // method call, for example. + let mut remap_cause = self.remap_fulfillment_cause.borrow_mut(); remap_cause.insert(( before_span, error.obligation.predicate, @@ -1652,9 +1646,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } for error in not_adjusted { - for (span, predicate, cause) in &remap_cause { + for (span, predicate, cause) in &*self.remap_fulfillment_cause.borrow() { if *predicate == error.obligation.predicate - && span.contains(error.obligation.cause.span) + && span.overlaps(error.obligation.cause.span) { error.obligation.cause = cause.clone(); continue; @@ -1667,7 +1661,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, error: &mut traits::FulfillmentError<'tcx>, ) -> bool { - let (traits::ExprItemObligation(def_id, hir_id, idx) | traits::ExprBindingObligation(def_id, _, hir_id, idx)) + let (traits::ExprItemObligation(def_id, hir_id, idx) + | traits::ExprBindingObligation(def_id, _, hir_id, idx)) = *error.obligation.cause.code().peel_derives() else { return false; }; let hir = self.tcx.hir(); let hir::Node::Expr(expr) = hir.get(hir_id) else { return false; }; diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs index e008d50aa514a..055a601648295 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs @@ -4,6 +4,7 @@ mod checks; mod suggestions; pub use _impl::*; +use rustc_data_structures::fx::FxHashSet; pub use suggestions::*; use crate::astconv::AstConv; @@ -129,6 +130,14 @@ pub struct FnCtxt<'a, 'tcx> { /// True if the return type has an Opaque type pub(super) return_type_has_opaque: bool, + + // Store a mapping from `(Span, Predicate) -> ObligationCause`, so that + // other errors that have the same span and predicate can also get fixed, + // even if their `ObligationCauseCode` isn't an `Expr{Item,Binding}Obligation`. + // This is important since if we adjust one span but not the other, then + // we will have "duplicated" the error on the UI side. + pub(super) remap_fulfillment_cause: + RefCell, ObligationCause<'tcx>)>>, } impl<'a, 'tcx> FnCtxt<'a, 'tcx> { @@ -156,6 +165,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { inh, return_type_pre_known: true, return_type_has_opaque: false, + remap_fulfillment_cause: Default::default(), } } diff --git a/src/test/ui/associated-types/associated-types-path-2.rs b/src/test/ui/associated-types/associated-types-path-2.rs index 00066efccb8dd..c993e1d27202d 100644 --- a/src/test/ui/associated-types/associated-types-path-2.rs +++ b/src/test/ui/associated-types/associated-types-path-2.rs @@ -29,14 +29,12 @@ pub fn f1_uint_uint() { f1(2u32, 4u32); //~^ ERROR `u32: Foo` is not satisfied //~| ERROR `u32: Foo` is not satisfied - //~| ERROR `u32: Foo` is not satisfied } pub fn f1_uint_int() { f1(2u32, 4i32); //~^ ERROR `u32: Foo` is not satisfied //~| ERROR `u32: Foo` is not satisfied - //~| ERROR `u32: Foo` is not satisfied } pub fn f2_int() { diff --git a/src/test/ui/associated-types/associated-types-path-2.stderr b/src/test/ui/associated-types/associated-types-path-2.stderr index 206f490241026..5edd5c864e135 100644 --- a/src/test/ui/associated-types/associated-types-path-2.stderr +++ b/src/test/ui/associated-types/associated-types-path-2.stderr @@ -31,14 +31,6 @@ note: required by a bound in `f1` LL | pub fn f1(a: T, x: T::A) {} | ^^^ required by this bound in `f1` -error[E0277]: the trait bound `u32: Foo` is not satisfied - --> $DIR/associated-types-path-2.rs:29:5 - | -LL | f1(2u32, 4u32); - | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u32` - | - = help: the trait `Foo` is implemented for `i32` - error[E0277]: the trait bound `u32: Foo` is not satisfied --> $DIR/associated-types-path-2.rs:29:14 | @@ -48,7 +40,7 @@ LL | f1(2u32, 4u32); = help: the trait `Foo` is implemented for `i32` error[E0277]: the trait bound `u32: Foo` is not satisfied - --> $DIR/associated-types-path-2.rs:36:8 + --> $DIR/associated-types-path-2.rs:35:8 | LL | f1(2u32, 4i32); | -- ^^^^ the trait `Foo` is not implemented for `u32` @@ -63,15 +55,7 @@ LL | pub fn f1(a: T, x: T::A) {} | ^^^ required by this bound in `f1` error[E0277]: the trait bound `u32: Foo` is not satisfied - --> $DIR/associated-types-path-2.rs:36:5 - | -LL | f1(2u32, 4i32); - | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u32` - | - = help: the trait `Foo` is implemented for `i32` - -error[E0277]: the trait bound `u32: Foo` is not satisfied - --> $DIR/associated-types-path-2.rs:36:14 + --> $DIR/associated-types-path-2.rs:35:14 | LL | f1(2u32, 4i32); | ^^^^ the trait `Foo` is not implemented for `u32` @@ -79,7 +63,7 @@ LL | f1(2u32, 4i32); = help: the trait `Foo` is implemented for `i32` error[E0308]: mismatched types - --> $DIR/associated-types-path-2.rs:43:18 + --> $DIR/associated-types-path-2.rs:41:18 | LL | let _: i32 = f2(2i32); | --- ^^^^^^^^ expected `i32`, found `u32` @@ -91,7 +75,7 @@ help: you can convert a `u32` to an `i32` and panic if the converted value doesn LL | let _: i32 = f2(2i32).try_into().unwrap(); | ++++++++++++++++++++ -error: aborting due to 8 previous errors +error: aborting due to 6 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/box/into-boxed-slice-fail.rs b/src/test/ui/box/into-boxed-slice-fail.rs index 49dbb170f8e78..db2e5623264e6 100644 --- a/src/test/ui/box/into-boxed-slice-fail.rs +++ b/src/test/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/src/test/ui/box/into-boxed-slice-fail.stderr b/src/test/ui/box/into-boxed-slice-fail.stderr index de654fdc1a4b5..d3a5d6f3f7b08 100644 --- a/src/test/ui/box/into-boxed-slice-fail.stderr +++ b/src/test/ui/box/into-boxed-slice-fail.stderr @@ -13,17 +13,8 @@ note: required by a bound in `Box::::into_boxed_slice` LL | impl Box { | ^ required by this bound in `Box::::into_boxed_slice` -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 @@ -37,15 +28,6 @@ note: required by a bound in `Box::::into_boxed_slice` LL | impl Box { | ^ required by this bound in `Box::::into_boxed_slice` -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/src/test/ui/iterators/issue-28098.rs b/src/test/ui/iterators/issue-28098.rs index 80c77edae9eb1..c4addaccefc10 100644 --- a/src/test/ui/iterators/issue-28098.rs +++ b/src/test/ui/iterators/issue-28098.rs @@ -1,15 +1,12 @@ fn main() { let _ = Iterator::next(&mut ()); //~^ ERROR `()` is not an iterator - //~| ERROR `()` is not an iterator - //~| ERROR `()` is not an iterator for _ in false {} //~^ ERROR `bool` is not an iterator let _ = Iterator::next(&mut ()); //~^ ERROR `()` is not an iterator - //~| ERROR `()` is not an iterator other() } @@ -19,12 +16,9 @@ pub fn other() { let _ = Iterator::next(&mut ()); //~^ ERROR `()` is not an iterator - //~| ERROR `()` is not an iterator - //~| ERROR `()` is not an iterator let _ = Iterator::next(&mut ()); //~^ ERROR `()` is not an iterator - //~| ERROR `()` is not an iterator for _ in false {} //~^ ERROR `bool` is not an iterator diff --git a/src/test/ui/iterators/issue-28098.stderr b/src/test/ui/iterators/issue-28098.stderr index 3256e57d4361b..53b610c172392 100644 --- a/src/test/ui/iterators/issue-28098.stderr +++ b/src/test/ui/iterators/issue-28098.stderr @@ -8,16 +8,8 @@ LL | let _ = Iterator::next(&mut ()); | = help: the trait `Iterator` is not implemented for `()` -error[E0277]: `()` is not an iterator - --> $DIR/issue-28098.rs:2:13 - | -LL | let _ = Iterator::next(&mut ()); - | ^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator - | - = help: the trait `Iterator` is not implemented for `()` - error[E0277]: `bool` is not an iterator - --> $DIR/issue-28098.rs:7:14 + --> $DIR/issue-28098.rs:5:14 | LL | for _ in false {} | ^^^^^ `bool` is not an iterator @@ -26,7 +18,7 @@ LL | for _ in false {} = note: required for `bool` to implement `IntoIterator` error[E0277]: `()` is not an iterator - --> $DIR/issue-28098.rs:10:28 + --> $DIR/issue-28098.rs:8:28 | LL | let _ = Iterator::next(&mut ()); | -------------- ^^^^^^^ `()` is not an iterator @@ -36,23 +28,7 @@ LL | let _ = Iterator::next(&mut ()); = help: the trait `Iterator` is not implemented for `()` error[E0277]: `()` is not an iterator - --> $DIR/issue-28098.rs:10:13 - | -LL | let _ = Iterator::next(&mut ()); - | ^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator - | - = help: the trait `Iterator` is not implemented for `()` - -error[E0277]: `()` is not an iterator - --> $DIR/issue-28098.rs:2:13 - | -LL | let _ = Iterator::next(&mut ()); - | ^^^^^^^^^^^^^^ `()` is not an iterator - | - = help: the trait `Iterator` is not implemented for `()` - -error[E0277]: `()` is not an iterator - --> $DIR/issue-28098.rs:20:28 + --> $DIR/issue-28098.rs:17:28 | LL | let _ = Iterator::next(&mut ()); | -------------- ^^^^^^^ `()` is not an iterator @@ -62,15 +38,7 @@ LL | let _ = Iterator::next(&mut ()); = help: the trait `Iterator` is not implemented for `()` error[E0277]: `()` is not an iterator - --> $DIR/issue-28098.rs:20:13 - | -LL | let _ = Iterator::next(&mut ()); - | ^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator - | - = help: the trait `Iterator` is not implemented for `()` - -error[E0277]: `()` is not an iterator - --> $DIR/issue-28098.rs:25:28 + --> $DIR/issue-28098.rs:20:28 | LL | let _ = Iterator::next(&mut ()); | -------------- ^^^^^^^ `()` is not an iterator @@ -79,16 +47,8 @@ LL | let _ = Iterator::next(&mut ()); | = help: the trait `Iterator` is not implemented for `()` -error[E0277]: `()` is not an iterator - --> $DIR/issue-28098.rs:25:13 - | -LL | let _ = Iterator::next(&mut ()); - | ^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator - | - = help: the trait `Iterator` is not implemented for `()` - error[E0277]: `bool` is not an iterator - --> $DIR/issue-28098.rs:29:14 + --> $DIR/issue-28098.rs:23:14 | LL | for _ in false {} | ^^^^^ `bool` is not an iterator @@ -96,14 +56,6 @@ LL | for _ in false {} = help: the trait `Iterator` is not implemented for `bool` = note: required for `bool` to implement `IntoIterator` -error[E0277]: `()` is not an iterator - --> $DIR/issue-28098.rs:20:13 - | -LL | let _ = Iterator::next(&mut ()); - | ^^^^^^^^^^^^^^ `()` is not an iterator - | - = help: the trait `Iterator` is not implemented for `()` - -error: aborting due to 12 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/on-unimplemented/multiple-impls.rs b/src/test/ui/on-unimplemented/multiple-impls.rs index a32fd4566231d..79c40f650db81 100644 --- a/src/test/ui/on-unimplemented/multiple-impls.rs +++ b/src/test/ui/on-unimplemented/multiple-impls.rs @@ -32,14 +32,8 @@ impl Index> for [i32] { fn main() { Index::index(&[] as &[i32], 2u32); //~^ ERROR E0277 - //~| ERROR E0277 - //~| ERROR E0277 Index::index(&[] as &[i32], Foo(2u32)); //~^ ERROR E0277 - //~| ERROR E0277 - //~| ERROR E0277 Index::index(&[] as &[i32], Bar(2u32)); //~^ ERROR E0277 - //~| ERROR E0277 - //~| ERROR E0277 } diff --git a/src/test/ui/on-unimplemented/multiple-impls.stderr b/src/test/ui/on-unimplemented/multiple-impls.stderr index d628b159a66d2..d47a398412fe4 100644 --- a/src/test/ui/on-unimplemented/multiple-impls.stderr +++ b/src/test/ui/on-unimplemented/multiple-impls.stderr @@ -11,19 +11,8 @@ LL | Index::index(&[] as &[i32], 2u32); <[i32] as Index>> <[i32] as Index>> -error[E0277]: the trait bound `[i32]: Index` is not satisfied - --> $DIR/multiple-impls.rs:33:5 - | -LL | Index::index(&[] as &[i32], 2u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait message - | - = help: the trait `Index` is not implemented for `[i32]` - = help: the following other types implement trait `Index`: - <[i32] as Index>> - <[i32] as Index>> - error[E0277]: the trait bound `[i32]: Index>` is not satisfied - --> $DIR/multiple-impls.rs:37:33 + --> $DIR/multiple-impls.rs:35:33 | LL | Index::index(&[] as &[i32], Foo(2u32)); | ------------ ^^^^^^^^^ on impl for Foo @@ -35,19 +24,8 @@ LL | Index::index(&[] as &[i32], Foo(2u32)); <[i32] as Index>> <[i32] as Index>> -error[E0277]: the trait bound `[i32]: Index>` is not satisfied - --> $DIR/multiple-impls.rs:37:5 - | -LL | Index::index(&[] as &[i32], Foo(2u32)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ on impl for Foo - | - = help: the trait `Index>` is not implemented for `[i32]` - = help: the following other types implement trait `Index`: - <[i32] as Index>> - <[i32] as Index>> - error[E0277]: the trait bound `[i32]: Index>` is not satisfied - --> $DIR/multiple-impls.rs:41:33 + --> $DIR/multiple-impls.rs:37:33 | LL | Index::index(&[] as &[i32], Bar(2u32)); | ------------ ^^^^^^^^^ on impl for Bar @@ -59,50 +37,6 @@ LL | Index::index(&[] as &[i32], Bar(2u32)); <[i32] as Index>> <[i32] as Index>> -error[E0277]: the trait bound `[i32]: Index>` is not satisfied - --> $DIR/multiple-impls.rs:41:5 - | -LL | Index::index(&[] as &[i32], Bar(2u32)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ on impl for Bar - | - = help: the trait `Index>` is not implemented for `[i32]` - = help: the following other types implement trait `Index`: - <[i32] as Index>> - <[i32] as Index>> - -error[E0277]: the trait bound `[i32]: Index` is not satisfied - --> $DIR/multiple-impls.rs:33:5 - | -LL | Index::index(&[] as &[i32], 2u32); - | ^^^^^^^^^^^^ trait message - | - = help: the trait `Index` is not implemented for `[i32]` - = help: the following other types implement trait `Index`: - <[i32] as Index>> - <[i32] as Index>> - -error[E0277]: the trait bound `[i32]: Index>` is not satisfied - --> $DIR/multiple-impls.rs:37:5 - | -LL | Index::index(&[] as &[i32], Foo(2u32)); - | ^^^^^^^^^^^^ on impl for Foo - | - = help: the trait `Index>` is not implemented for `[i32]` - = help: the following other types implement trait `Index`: - <[i32] as Index>> - <[i32] as Index>> - -error[E0277]: the trait bound `[i32]: Index>` is not satisfied - --> $DIR/multiple-impls.rs:41:5 - | -LL | Index::index(&[] as &[i32], Bar(2u32)); - | ^^^^^^^^^^^^ on impl for Bar - | - = help: the trait `Index>` is not implemented for `[i32]` - = help: the following other types implement trait `Index`: - <[i32] as Index>> - <[i32] as Index>> - -error: aborting due to 9 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/on-unimplemented/on-impl.rs b/src/test/ui/on-unimplemented/on-impl.rs index d0537810ce11e..b03e1f7c6a8df 100644 --- a/src/test/ui/on-unimplemented/on-impl.rs +++ b/src/test/ui/on-unimplemented/on-impl.rs @@ -21,6 +21,4 @@ impl Index for [i32] { fn main() { Index::::index(&[1, 2, 3] as &[i32], 2u32); //~^ ERROR E0277 - //~| ERROR E0277 - //~| ERROR E0277 } diff --git a/src/test/ui/on-unimplemented/on-impl.stderr b/src/test/ui/on-unimplemented/on-impl.stderr index 2253c5992a64a..01315b854098e 100644 --- a/src/test/ui/on-unimplemented/on-impl.stderr +++ b/src/test/ui/on-unimplemented/on-impl.stderr @@ -9,24 +9,6 @@ LL | Index::::index(&[1, 2, 3] as &[i32], 2u32); = help: the trait `Index` is not implemented for `[i32]` = help: the trait `Index` is implemented for `[i32]` -error[E0277]: the trait bound `[i32]: Index` is not satisfied - --> $DIR/on-impl.rs:22:5 - | -LL | Index::::index(&[1, 2, 3] as &[i32], 2u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice - | - = help: the trait `Index` is not implemented for `[i32]` - = help: the trait `Index` is implemented for `[i32]` - -error[E0277]: the trait bound `[i32]: Index` is not satisfied - --> $DIR/on-impl.rs:22:5 - | -LL | Index::::index(&[1, 2, 3] as &[i32], 2u32); - | ^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice - | - = help: the trait `Index` is not implemented for `[i32]` - = help: the trait `Index` is implemented for `[i32]` - -error: aborting due to 3 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/suggestions/mut-borrow-needed-by-trait.rs b/src/test/ui/suggestions/mut-borrow-needed-by-trait.rs index 66e1e77c905e0..1686a7dddb137 100644 --- a/src/test/ui/suggestions/mut-borrow-needed-by-trait.rs +++ b/src/test/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/src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr b/src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr index d121932c842e3..baa3a0d102b42 100644 --- a/src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr +++ b/src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr @@ -13,21 +13,8 @@ note: required by a bound in `BufWriter::::new` LL | impl BufWriter { | ^^^^^ required by this bound in `BufWriter::::new` -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/std/src/io/buffered/bufwriter.rs:LL:COL - | -LL | pub struct BufWriter { - | ^^^^^ required by this bound in `BufWriter` - 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:5 + --> $DIR/mut-borrow-needed-by-trait.rs:20:5 | LL | writeln!(fp, "hello world").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `BufWriter<&dyn std::io::Write>` due to unsatisfied trait bounds @@ -42,7 +29,7 @@ LL | pub struct BufWriter { which is required by `BufWriter<&dyn std::io::Write>: std::io::Write` = note: this error originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info) -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/src/test/ui/traits/negative-impls/negated-auto-traits-error.rs b/src/test/ui/traits/negative-impls/negated-auto-traits-error.rs index 4bdad5dc591c5..523876c9f2a4f 100644 --- a/src/test/ui/traits/negative-impls/negated-auto-traits-error.rs +++ b/src/test/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/src/test/ui/traits/negative-impls/negated-auto-traits-error.stderr b/src/test/ui/traits/negative-impls/negated-auto-traits-error.stderr index 41fc3600fcd54..1307e367f99a4 100644 --- a/src/test/ui/traits/negative-impls/negated-auto-traits-error.stderr +++ b/src/test/ui/traits/negative-impls/negated-auto-traits-error.stderr @@ -13,21 +13,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` -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 @@ -42,7 +29,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 @@ -58,7 +45,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 `Unique` @@ -79,7 +66,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 @@ -101,7 +88,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:13 + --> $DIR/negated-auto-traits-error.rs:65:13 | LL | is_sync(Outer2(TestType)); | ------- ^^^^^^^^^^^^^^^^ `main::TestType` cannot be sent between threads safely @@ -120,6 +107,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/src/test/ui/ufcs/ufcs-qpath-self-mismatch.rs b/src/test/ui/ufcs/ufcs-qpath-self-mismatch.rs index ec86213f8629d..939b3c5223c48 100644 --- a/src/test/ui/ufcs/ufcs-qpath-self-mismatch.rs +++ b/src/test/ui/ufcs/ufcs-qpath-self-mismatch.rs @@ -3,7 +3,6 @@ use std::ops::Add; fn main() { >::add(1, 2); //~^ ERROR cannot add `u32` to `i32` - //~| ERROR cannot add `u32` to `i32` >::add(1u32, 2); //~^ ERROR mismatched types >::add(1, 2u32); diff --git a/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr b/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr index eaab6ff3d9a04..f08c81bc1e937 100644 --- a/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr +++ b/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr @@ -19,7 +19,7 @@ LL | >::add(1, 2); and 48 others error[E0308]: mismatched types - --> $DIR/ufcs-qpath-self-mismatch.rs:7:28 + --> $DIR/ufcs-qpath-self-mismatch.rs:6:28 | LL | >::add(1u32, 2); | ---------------------- ^^^^ expected `i32`, found `u32` @@ -37,7 +37,7 @@ LL | >::add(1i32, 2); | ~~~ error[E0308]: mismatched types - --> $DIR/ufcs-qpath-self-mismatch.rs:9:31 + --> $DIR/ufcs-qpath-self-mismatch.rs:8:31 | LL | >::add(1, 2u32); | ---------------------- ^^^^ expected `i32`, found `u32` @@ -54,25 +54,7 @@ help: change the type of the numeric literal from `u32` to `i32` LL | >::add(1, 2i32); | ~~~ -error[E0277]: cannot add `u32` to `i32` - --> $DIR/ufcs-qpath-self-mismatch.rs:4:5 - | -LL | >::add(1, 2); - | ^^^^^^^^^^^^^^^^^^^^^^ no implementation for `i32 + u32` - | - = help: the trait `Add` is not implemented for `i32` - = help: the following other types implement trait `Add`: - <&'a f32 as Add> - <&'a f64 as Add> - <&'a i128 as Add> - <&'a i16 as Add> - <&'a i32 as Add> - <&'a i64 as Add> - <&'a i8 as Add> - <&'a isize as Add> - and 48 others - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0277, E0308. For more information about an error, try `rustc --explain E0277`. From 4c8ffb7a9b8cc697fb850d50f869de9a9cc36b2b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 25 Aug 2022 20:03:15 +0000 Subject: [PATCH 5/5] Make E0282 actually E0282 --- src/test/ui/error-codes/E0282.rs | 2 +- src/test/ui/error-codes/E0282.stderr | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/test/ui/error-codes/E0282.rs b/src/test/ui/error-codes/E0282.rs index 1df5c7f7dbb33..ca82078decc70 100644 --- a/src/test/ui/error-codes/E0282.rs +++ b/src/test/ui/error-codes/E0282.rs @@ -1,3 +1,3 @@ fn main() { - let x = "hello".chars().rev().collect(); //~ ERROR E0283 + let x: _ = "hello".chars().rev().collect(); //~ ERROR E0282 } diff --git a/src/test/ui/error-codes/E0282.stderr b/src/test/ui/error-codes/E0282.stderr index 3be534fdda1c1..8476e6b50a6f2 100644 --- a/src/test/ui/error-codes/E0282.stderr +++ b/src/test/ui/error-codes/E0282.stderr @@ -1,20 +1,14 @@ -error[E0283]: type annotations needed - --> $DIR/E0282.rs:2:9 +error[E0282]: type annotations needed + --> $DIR/E0282.rs:2:38 | -LL | let x = "hello".chars().rev().collect(); - | ^ ------- type must be known at this point +LL | let x: _ = "hello".chars().rev().collect(); + | ^^^^^^^ cannot infer type of the type parameter `B` declared on the associated function `collect` | - = note: cannot satisfy `_: FromIterator` -note: required by a bound in `collect` - --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL +help: consider specifying the generic argument | -LL | fn collect>(self) -> B - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect` -help: consider specifying the type argument in the function call - | -LL | let x = "hello".chars().rev().collect::(); - | +++++ +LL | let x: _ = "hello".chars().rev().collect::(); + | +++++ error: aborting due to previous error -For more information about this error, try `rustc --explain E0283`. +For more information about this error, try `rustc --explain E0282`.