Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2022,22 +2022,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
let tcx = self.tcx;

let adt_ty = self.try_structurally_resolve_type(path_span, adt_ty);
let adt_ty_hint = expected.only_has_type(self).and_then(|expected| {
self.fudge_inference_if_ok(|| {
// We eagerly constrain the generic arguments of our ADT to
// guide inference if possible.
//
// This is necessary if we need to coerce the field, e.g. see
// tests/ui/traits/next-solver/typeck/guide-ctors.rs.
if let Some(expected) = expected.only_has_type(self) {
let _ = self.commit_if_ok(|_| {
let ocx = ObligationCtxt::new(self);
ocx.sup(&self.misc(path_span), self.param_env, expected, adt_ty)?;
if !ocx.try_evaluate_obligations().is_empty() {
return Err(TypeError::Mismatch);
Err(TypeError::Mismatch)
} else {
Ok(())
}
Ok(self.resolve_vars_if_possible(adt_ty))
})
.ok()
});
if let Some(adt_ty_hint) = adt_ty_hint {
// re-link the variables that the fudging above can create.
self.demand_eqtype(path_span, adt_ty_hint, adt_ty);
});
}
let adt_ty = self.try_structurally_resolve_type(path_span, adt_ty);

let ty::Adt(adt, args) = adt_ty.kind() else {
span_bug!(path_span, "non-ADT passed to check_expr_struct_fields");
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/async-await/drop-track-bad-field-in-fru.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
error[E0559]: variant `Option<_>::None` has no field named `value`
--> $DIR/drop-track-bad-field-in-fru.rs:6:12
|
LL | None { value: (), ..Default::default() }.await;
| ^^^^^ `Option<_>::None` does not have this field
|
= note: all struct fields are already assigned

error[E0277]: `Option<_>` is not a future
--> $DIR/drop-track-bad-field-in-fru.rs:6:46
|
Expand All @@ -21,6 +13,14 @@ LL - None { value: (), ..Default::default() }.await;
LL + None { value: (), ..Default::default() };
|

error[E0559]: variant `Option<_>::None` has no field named `value`
--> $DIR/drop-track-bad-field-in-fru.rs:6:12
|
LL | None { value: (), ..Default::default() }.await;
| ^^^^^ `Option<_>::None` does not have this field
|
= note: all struct fields are already assigned

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0277, E0559.
Expand Down
14 changes: 9 additions & 5 deletions tests/ui/async-await/issue-98634.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ error[E0271]: expected `callback` to return `Pin<Box<dyn Future<Output = ()>>>`,
LL | StructAsync { callback }.await;
| ^^^^^ expected `Pin<Box<dyn Future<Output = ()>>>`, found future
|
note: required by a bound in `StructAsync`
--> $DIR/issue-98634.rs:9:35
|
LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync`
note: required for `StructAsync<fn() -> impl Future<Output = ()> {callback}>` to implement `Future`
--> $DIR/issue-98634.rs:13:9
|
LL | impl<F> Future for StructAsync<F>
| ^^^^^^ ^^^^^^^^^^^^^^
LL | where
LL | F: Fn() -> Pin<Box<dyn Future<Output = ()>>>,
| --------------------------------- unsatisfied trait bound introduced here
= note: required for `StructAsync<fn() -> impl Future<Output = ()> {callback}>` to implement `IntoFuture`

error: aborting due to 3 previous errors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
error[E0308]: mismatched types
--> $DIR/issue-72819-generic-in-const-eval.rs:20:12
|
LL | let x: Arr<{usize::MAX}> = Arr {};
| ^^^^^^^^^^^^^^^^^ expected `false`, found `true`
|
= note: expected constant `false`
found constant `true`
note: required by a bound in `Arr`
--> $DIR/issue-72819-generic-in-const-eval.rs:8:39
|
LL | struct Arr<const N: usize>
| --- required by a bound in this struct
LL | where Assert::<{N < usize::MAX / 2}>: IsTrue,
| ^^^^^^ required by this bound in `Arr`

error[E0308]: mismatched types
--> $DIR/issue-72819-generic-in-const-eval.rs:20:32
|
Expand All @@ -30,6 +14,6 @@ LL | struct Arr<const N: usize>
LL | where Assert::<{N < usize::MAX / 2}>: IsTrue,
| ^^^^^^ required by this bound in `Arr`

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ impl IsTrue for Assert<true> {}
fn main() {
let x: Arr<{usize::MAX}> = Arr {};
//[full]~^ ERROR mismatched types
//[full]~| ERROR mismatched types
}
1 change: 0 additions & 1 deletion tests/ui/const-generics/issues/issue-73260.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ impl IsTrue for Assert<true> {}
fn main() {
let x: Arr<{usize::MAX}> = Arr {};
//~^ ERROR mismatched types
//~| ERROR mismatched types
}
19 changes: 1 addition & 18 deletions tests/ui/const-generics/issues/issue-73260.stderr
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
error[E0308]: mismatched types
--> $DIR/issue-73260.rs:15:12
|
LL | let x: Arr<{usize::MAX}> = Arr {};
| ^^^^^^^^^^^^^^^^^ expected `false`, found `true`
|
= note: expected constant `false`
found constant `true`
note: required by a bound in `Arr`
--> $DIR/issue-73260.rs:5:37
|
LL | struct Arr<const N: usize>
| --- required by a bound in this struct
LL | where
LL | Assert::<{N < usize::MAX / 2}>: IsTrue,
| ^^^^^^ required by this bound in `Arr`

error[E0308]: mismatched types
--> $DIR/issue-73260.rs:15:32
|
Expand All @@ -32,6 +15,6 @@ LL | where
LL | Assert::<{N < usize::MAX / 2}>: IsTrue,
| ^^^^^^ required by this bound in `Arr`

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
12 changes: 6 additions & 6 deletions tests/ui/derives/deriving-copyclone.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `B<C>: Copy` is not satisfied
error[E0277]: the trait bound `B<_>: Copy` is not satisfied
--> $DIR/deriving-copyclone.rs:31:26
|
LL | is_copy(B { a: 1, b: C });
| ------- ^ the trait `Copy` is not implemented for `B<C>`
| ------- ^ the trait `Copy` is not implemented for `B<_>`
| |
| required by a bound introduced by this call
|
Expand All @@ -21,11 +21,11 @@ help: consider borrowing here
LL | is_copy(B { a: 1, b: &C });
| +

error[E0277]: the trait bound `B<C>: Clone` is not satisfied
error[E0277]: the trait bound `B<_>: Clone` is not satisfied
--> $DIR/deriving-copyclone.rs:32:27
|
LL | is_clone(B { a: 1, b: C });
| -------- ^ the trait `Clone` is not implemented for `B<C>`
| -------- ^ the trait `Clone` is not implemented for `B<_>`
| |
| required by a bound introduced by this call
|
Expand All @@ -44,11 +44,11 @@ help: consider borrowing here
LL | is_clone(B { a: 1, b: &C });
| +

error[E0277]: the trait bound `B<D>: Copy` is not satisfied
error[E0277]: the trait bound `B<_>: Copy` is not satisfied
--> $DIR/deriving-copyclone.rs:35:26
|
LL | is_copy(B { a: 1, b: D });
| ------- ^ the trait `Copy` is not implemented for `B<D>`
| ------- ^ the trait `Copy` is not implemented for `B<_>`
| |
| required by a bound introduced by this call
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait Ty<'a> {

fn main() {
let v = Unit2.m(
L { //~ ERROR type mismatch
L {
f: |x| {
drop(x);
Unit4 //~ ERROR to return `Unit3`, but it returns `Unit4`
Expand Down
33 changes: 1 addition & 32 deletions tests/ui/higher-ranked/trait-bounds/issue-62203-hrtb-ice.stderr
Original file line number Diff line number Diff line change
@@ -1,34 +1,3 @@
error[E0271]: type mismatch resolving `<L<{[email protected]:40:16}> as T0<'r, (&u8,)>>::O == <_ as Ty<'r>>::V`
--> $DIR/issue-62203-hrtb-ice.rs:39:9
|
LL | let v = Unit2.m(
| - required by a bound introduced by this call
LL | / L {
LL | | f: |x| {
LL | | drop(x);
LL | | Unit4
LL | | },
LL | | },
| |_________^ type mismatch resolving `<L<{[email protected]:40:16}> as T0<'r, (&u8,)>>::O == <_ as Ty<'r>>::V`
|
note: expected this to be `<_ as Ty<'_>>::V`
--> $DIR/issue-62203-hrtb-ice.rs:21:14
|
LL | type O = T::Output;
| ^^^^^^^^^
= note: expected associated type `<_ as Ty<'_>>::V`
found struct `Unit4`
= help: consider constraining the associated type `<_ as Ty<'_>>::V` to `Unit4` or calling a method that returns `<_ as Ty<'_>>::V`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
note: required by a bound in `T1::m`
--> $DIR/issue-62203-hrtb-ice.rs:27:51
|
LL | fn m<'a, B: Ty<'a>, F>(&self, f: F) -> Unit1
| - required by a bound in this associated function
LL | where
LL | F: for<'r> T0<'r, (<Self as Ty<'r>>::V,), O = <B as Ty<'r>>::V>,
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `T1::m`

error[E0271]: expected `{[email protected]:40:16}` to return `Unit3`, but it returns `Unit4`
--> $DIR/issue-62203-hrtb-ice.rs:42:17
|
Expand Down Expand Up @@ -58,6 +27,6 @@ LL | where
LL | F: for<'r> T0<'r, (<Self as Ty<'r>>::V,), O = <B as Ty<'r>>::V>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `T1::m`

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0271`.
12 changes: 6 additions & 6 deletions tests/ui/iterators/ranges.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
error[E0277]: `RangeTo<{integer}>` is not an iterator
error[E0277]: `RangeTo<_>` is not an iterator
--> $DIR/ranges.rs:2:14
|
LL | for _ in ..10 {}
| ^^^^ if you meant to iterate until a value, add a starting value
|
= help: the trait `Iterator` is not implemented for `RangeTo<{integer}>`
= help: the trait `Iterator` is not implemented for `RangeTo<_>`
= note: `..end` is a `RangeTo`, which cannot be iterated on; you might have meant to have a bounded `Range`: `0..end`
= note: required for `RangeTo<{integer}>` to implement `IntoIterator`
= note: required for `RangeTo<_>` to implement `IntoIterator`

error[E0277]: `std::ops::RangeToInclusive<{integer}>` is not an iterator
error[E0277]: `std::ops::RangeToInclusive<_>` is not an iterator
--> $DIR/ranges.rs:4:14
|
LL | for _ in ..=10 {}
| ^^^^^ if you meant to iterate until a value (including it), add a starting value
|
= help: the trait `Iterator` is not implemented for `std::ops::RangeToInclusive<{integer}>`
= help: the trait `Iterator` is not implemented for `std::ops::RangeToInclusive<_>`
= note: `..=end` is a `RangeToInclusive`, which cannot be iterated on; you might have meant to have a bounded `RangeInclusive`: `0..=end`
= note: required for `std::ops::RangeToInclusive<{integer}>` to implement `IntoIterator`
= note: required for `std::ops::RangeToInclusive<_>` to implement `IntoIterator`

error: aborting due to 2 previous errors

Expand Down
1 change: 0 additions & 1 deletion tests/ui/wf/wf-const-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ struct NotCopy;
const FOO: IsCopy<Option<NotCopy>> = IsCopy { t: None };
//~^ ERROR E0277
//~| ERROR E0277
//~| ERROR E0277


fn main() { }
21 changes: 1 addition & 20 deletions tests/ui/wf/wf-const-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,6 @@ LL + #[derive(Copy)]
LL | struct NotCopy;
|

error[E0277]: the trait bound `NotCopy: Copy` is not satisfied
--> $DIR/wf-const-type.rs:10:12
|
LL | const FOO: IsCopy<Option<NotCopy>> = IsCopy { t: None };
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopy`
|
= note: required for `Option<NotCopy>` to implement `Copy`
note: required by a bound in `IsCopy`
--> $DIR/wf-const-type.rs:7:17
|
LL | struct IsCopy<T:Copy> { t: T }
| ^^^^ required by this bound in `IsCopy`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider annotating `NotCopy` with `#[derive(Copy)]`
|
LL + #[derive(Copy)]
LL | struct NotCopy;
|

error[E0277]: the trait bound `NotCopy: Copy` is not satisfied
--> $DIR/wf-const-type.rs:10:50
|
Expand All @@ -53,6 +34,6 @@ LL + #[derive(Copy)]
LL | struct NotCopy;
|

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
Loading