fix(rustc_typeck): report function argument errors on matching type
Fixes #90101
This commit is contained in:
parent
84c2a8505d
commit
8520105464
@ -1492,6 +1492,9 @@ fn get_parent_trait_ref(
|
||||
}
|
||||
}
|
||||
}
|
||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => {
|
||||
self.get_parent_trait_ref(&parent_code)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -1422,6 +1422,9 @@ fn maybe_note_obligation_cause_for_async_await(
|
||||
while let Some(code) = next_code {
|
||||
debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code);
|
||||
match code {
|
||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => {
|
||||
next_code = Some(parent_code.as_ref());
|
||||
}
|
||||
ObligationCauseCode::DerivedObligation(derived_obligation)
|
||||
| ObligationCauseCode::BuiltinDerivedObligation(derived_obligation)
|
||||
| ObligationCauseCode::ImplDerivedObligation(derived_obligation) => {
|
||||
|
@ -370,6 +370,8 @@ pub(in super::super) fn check_argument_types(
|
||||
// `ExpectHasType(expected_ty)`, or the `formal_ty` otherwise.
|
||||
let coerce_ty = expected.only_has_type(self).unwrap_or(formal_ty);
|
||||
|
||||
final_arg_types.push((i, checked_ty, coerce_ty));
|
||||
|
||||
// Cause selection errors caused by resolving a single argument to point at the
|
||||
// argument and not the call. This is otherwise redundant with the `demand_coerce`
|
||||
// call immediately after, but it lets us customize the span pointed to in the
|
||||
@ -377,38 +379,20 @@ pub(in super::super) fn check_argument_types(
|
||||
let _ = self.resolve_vars_with_obligations_and_mutate_fulfillment(
|
||||
coerce_ty,
|
||||
|errors| {
|
||||
// This is not coming from a macro or a `derive`.
|
||||
if sp.desugaring_kind().is_none()
|
||||
&& !arg.span.from_expansion()
|
||||
// Do not change the spans of `async fn`s.
|
||||
&& !matches!(
|
||||
expr.kind,
|
||||
hir::ExprKind::Call(
|
||||
hir::Expr {
|
||||
kind: hir::ExprKind::Path(hir::QPath::LangItem(_, _)),
|
||||
..
|
||||
},
|
||||
_
|
||||
)
|
||||
) {
|
||||
for error in errors {
|
||||
error.obligation.cause.make_mut().span = arg.span;
|
||||
let code = error.obligation.cause.code.clone();
|
||||
error.obligation.cause.make_mut().code =
|
||||
ObligationCauseCode::FunctionArgumentObligation {
|
||||
arg_hir_id: arg.hir_id,
|
||||
call_hir_id: expr.hir_id,
|
||||
parent_code: Lrc::new(code),
|
||||
};
|
||||
}
|
||||
}
|
||||
self.point_at_type_arg_instead_of_call_if_possible(errors, expr);
|
||||
self.point_at_arg_instead_of_call_if_possible(
|
||||
errors,
|
||||
&final_arg_types,
|
||||
expr,
|
||||
sp,
|
||||
args,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
// We're processing function arguments so we definitely want to use
|
||||
// two-phase borrows.
|
||||
self.demand_coerce(&arg, checked_ty, coerce_ty, None, AllowTwoPhase::Yes);
|
||||
final_arg_types.push((i, checked_ty, coerce_ty));
|
||||
|
||||
// 3. Relate the expected type and the formal one,
|
||||
// if the expected type was used for the coercion.
|
||||
@ -973,45 +957,79 @@ fn point_at_arg_instead_of_call_if_possible(
|
||||
continue;
|
||||
}
|
||||
|
||||
if let ty::PredicateKind::Trait(predicate) =
|
||||
error.obligation.predicate.kind().skip_binder()
|
||||
{
|
||||
// Collect the argument position for all arguments that could have caused this
|
||||
// `FulfillmentError`.
|
||||
let mut referenced_in = final_arg_types
|
||||
.iter()
|
||||
.map(|&(i, checked_ty, _)| (i, checked_ty))
|
||||
.chain(final_arg_types.iter().map(|&(i, _, coerced_ty)| (i, coerced_ty)))
|
||||
.flat_map(|(i, ty)| {
|
||||
let ty = self.resolve_vars_if_possible(ty);
|
||||
// We walk the argument type because the argument's type could have
|
||||
// been `Option<T>`, but the `FulfillmentError` references `T`.
|
||||
if ty.walk(self.tcx).any(|arg| arg == predicate.self_ty().into()) {
|
||||
Some(i)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<usize>>();
|
||||
// Peel derived obligation, because it's the type that originally
|
||||
// started this inference chain that matters, not the one we wound
|
||||
// up with at the end.
|
||||
fn unpeel_to_top(
|
||||
mut code: Lrc<ObligationCauseCode<'_>>,
|
||||
) -> Lrc<ObligationCauseCode<'_>> {
|
||||
let mut result_code = code.clone();
|
||||
loop {
|
||||
let parent = match &*code {
|
||||
ObligationCauseCode::BuiltinDerivedObligation(c)
|
||||
| ObligationCauseCode::ImplDerivedObligation(c)
|
||||
| ObligationCauseCode::DerivedObligation(c) => c.parent_code.clone(),
|
||||
_ => break,
|
||||
};
|
||||
result_code = std::mem::replace(&mut code, parent);
|
||||
}
|
||||
result_code
|
||||
}
|
||||
let self_: ty::subst::GenericArg<'_> = match &*unpeel_to_top(Lrc::new(error.obligation.cause.code.clone())) {
|
||||
ObligationCauseCode::BuiltinDerivedObligation(code) |
|
||||
ObligationCauseCode::ImplDerivedObligation(code) |
|
||||
ObligationCauseCode::DerivedObligation(code) => {
|
||||
code.parent_trait_ref.self_ty().skip_binder().into()
|
||||
}
|
||||
_ if let ty::PredicateKind::Trait(predicate) =
|
||||
error.obligation.predicate.kind().skip_binder() => {
|
||||
predicate.self_ty().into()
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
let self_ = self.resolve_vars_if_possible(self_);
|
||||
|
||||
// Both checked and coerced types could have matched, thus we need to remove
|
||||
// duplicates.
|
||||
// Collect the argument position for all arguments that could have caused this
|
||||
// `FulfillmentError`.
|
||||
let mut referenced_in = final_arg_types
|
||||
.iter()
|
||||
.map(|&(i, checked_ty, _)| (i, checked_ty))
|
||||
.chain(final_arg_types.iter().map(|&(i, _, coerced_ty)| (i, coerced_ty)))
|
||||
.flat_map(|(i, ty)| {
|
||||
let ty = self.resolve_vars_if_possible(ty);
|
||||
// We walk the argument type because the argument's type could have
|
||||
// been `Option<T>`, but the `FulfillmentError` references `T`.
|
||||
if ty.walk(self.tcx).any(|arg| arg == self_) { Some(i) } else { None }
|
||||
})
|
||||
.collect::<Vec<usize>>();
|
||||
|
||||
// We sort primitive type usize here and can use unstable sort
|
||||
referenced_in.sort_unstable();
|
||||
referenced_in.dedup();
|
||||
// Both checked and coerced types could have matched, thus we need to remove
|
||||
// duplicates.
|
||||
|
||||
if let (Some(ref_in), None) = (referenced_in.pop(), referenced_in.pop()) {
|
||||
// We make sure that only *one* argument matches the obligation failure
|
||||
// and we assign the obligation's span to its expression's.
|
||||
error.obligation.cause.make_mut().span = args[ref_in].span;
|
||||
let code = error.obligation.cause.code.clone();
|
||||
error.obligation.cause.make_mut().code =
|
||||
ObligationCauseCode::FunctionArgumentObligation {
|
||||
arg_hir_id: args[ref_in].hir_id,
|
||||
call_hir_id: expr.hir_id,
|
||||
parent_code: Lrc::new(code),
|
||||
};
|
||||
// We sort primitive type usize here and can use unstable sort
|
||||
referenced_in.sort_unstable();
|
||||
referenced_in.dedup();
|
||||
|
||||
if let (Some(ref_in), None) = (referenced_in.pop(), referenced_in.pop()) {
|
||||
// Do not point at the inside of a macro.
|
||||
// That would often result in poor error messages.
|
||||
if args[ref_in].span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
// We make sure that only *one* argument matches the obligation failure
|
||||
// and we assign the obligation's span to its expression's.
|
||||
error.obligation.cause.make_mut().span = args[ref_in].span;
|
||||
let code = error.obligation.cause.code.clone();
|
||||
error.obligation.cause.make_mut().code =
|
||||
ObligationCauseCode::FunctionArgumentObligation {
|
||||
arg_hir_id: args[ref_in].hir_id,
|
||||
call_hir_id: expr.hir_id,
|
||||
parent_code: Lrc::new(code),
|
||||
};
|
||||
} else if error.obligation.cause.make_mut().span == call_sp {
|
||||
// Make function calls point at the callee, not the whole thing.
|
||||
if let hir::ExprKind::Call(callee, _) = expr.kind {
|
||||
error.obligation.cause.make_mut().span = callee.span;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,13 @@ pub fn f1_int_uint() {
|
||||
pub fn f1_uint_uint() {
|
||||
f1(2u32, 4u32);
|
||||
//~^ 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
|
||||
}
|
||||
|
||||
pub fn f2_int() {
|
||||
|
@ -9,11 +9,29 @@ help: change the type of the numeric literal from `i32` to `u32`
|
||||
LL | f1(2i32, 4u32);
|
||||
| ~~~
|
||||
|
||||
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`
|
||||
|
|
||||
note: required by a bound in `f1`
|
||||
--> $DIR/associated-types-path-2.rs:13:14
|
||||
|
|
||||
LL | pub fn f1<T: Foo>(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:14
|
||||
|
|
||||
LL | f1(2u32, 4u32);
|
||||
| -- ^^^^ the trait `Foo` is not implemented for `u32`
|
||||
| ^^^^ the trait `Foo` is not implemented for `u32`
|
||||
|
||||
error[E0277]: the trait bound `u32: Foo` is not satisfied
|
||||
--> $DIR/associated-types-path-2.rs:35:8
|
||||
|
|
||||
LL | f1(2u32, 4i32);
|
||||
| -- ^^^^ the trait `Foo` is not implemented for `u32`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
@ -24,21 +42,13 @@ LL | pub fn f1<T: Foo>(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:34:14
|
||||
--> $DIR/associated-types-path-2.rs:35:14
|
||||
|
|
||||
LL | f1(2u32, 4i32);
|
||||
| -- ^^^^ the trait `Foo` is not implemented for `u32`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
note: required by a bound in `f1`
|
||||
--> $DIR/associated-types-path-2.rs:13:14
|
||||
|
|
||||
LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
|
||||
| ^^^ required by this bound in `f1`
|
||||
| ^^^^ the trait `Foo` is not implemented for `u32`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/associated-types-path-2.rs:39:18
|
||||
--> $DIR/associated-types-path-2.rs:41:18
|
||||
|
|
||||
LL | let _: i32 = f2(2i32);
|
||||
| --- ^^^^^^^^ expected `i32`, found `u32`
|
||||
@ -50,7 +60,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 4 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`.
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: future cannot be sent between threads safely
|
||||
--> $DIR/async-fn-nonsend.rs:49:5
|
||||
--> $DIR/async-fn-nonsend.rs:49:17
|
||||
|
|
||||
LL | assert_send(local_dropped_before_await());
|
||||
| ^^^^^^^^^^^ future returned by `local_dropped_before_await` is not `Send`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `local_dropped_before_await` is not `Send`
|
||||
|
|
||||
= help: within `impl Future`, the trait `Send` is not implemented for `Rc<()>`
|
||||
note: future is not `Send` as this value is used across an await
|
||||
@ -22,10 +22,10 @@ LL | fn assert_send(_: impl Send) {}
|
||||
| ^^^^ required by this bound in `assert_send`
|
||||
|
||||
error: future cannot be sent between threads safely
|
||||
--> $DIR/async-fn-nonsend.rs:51:5
|
||||
--> $DIR/async-fn-nonsend.rs:51:17
|
||||
|
|
||||
LL | assert_send(non_send_temporary_in_match());
|
||||
| ^^^^^^^^^^^ future returned by `non_send_temporary_in_match` is not `Send`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `non_send_temporary_in_match` is not `Send`
|
||||
|
|
||||
= help: within `impl Future`, the trait `Send` is not implemented for `Rc<()>`
|
||||
note: future is not `Send` as this value is used across an await
|
||||
@ -45,10 +45,10 @@ LL | fn assert_send(_: impl Send) {}
|
||||
| ^^^^ required by this bound in `assert_send`
|
||||
|
||||
error: future cannot be sent between threads safely
|
||||
--> $DIR/async-fn-nonsend.rs:53:5
|
||||
--> $DIR/async-fn-nonsend.rs:53:17
|
||||
|
|
||||
LL | assert_send(non_sync_with_method_call());
|
||||
| ^^^^^^^^^^^ future returned by `non_sync_with_method_call` is not `Send`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `non_sync_with_method_call` is not `Send`
|
||||
|
|
||||
= help: the trait `Send` is not implemented for `dyn std::fmt::Write`
|
||||
note: future is not `Send` as this value is used across an await
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: future cannot be shared between threads safely
|
||||
--> $DIR/issue-64130-1-sync.rs:21:5
|
||||
--> $DIR/issue-64130-1-sync.rs:21:13
|
||||
|
|
||||
LL | is_sync(bar());
|
||||
| ^^^^^^^ future returned by `bar` is not `Sync`
|
||||
| ^^^^^ future returned by `bar` is not `Sync`
|
||||
|
|
||||
= help: within `impl Future`, the trait `Sync` is not implemented for `Foo`
|
||||
note: future is not `Sync` as this value is used across an await
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: future cannot be sent between threads safely
|
||||
--> $DIR/issue-64130-2-send.rs:21:5
|
||||
--> $DIR/issue-64130-2-send.rs:21:13
|
||||
|
|
||||
LL | is_send(bar());
|
||||
| ^^^^^^^ future returned by `bar` is not `Send`
|
||||
| ^^^^^ future returned by `bar` is not `Send`
|
||||
|
|
||||
= help: within `impl Future`, the trait `Send` is not implemented for `Foo`
|
||||
note: future is not `Send` as this value is used across an await
|
||||
|
@ -1,11 +1,11 @@
|
||||
error[E0277]: the trait bound `Foo: Qux` is not satisfied in `impl Future`
|
||||
--> $DIR/issue-64130-3-other.rs:24:5
|
||||
--> $DIR/issue-64130-3-other.rs:24:12
|
||||
|
|
||||
LL | async fn bar() {
|
||||
| - within this `impl Future`
|
||||
...
|
||||
LL | is_qux(bar());
|
||||
| ^^^^^^ within `impl Future`, the trait `Qux` is not implemented for `Foo`
|
||||
| ^^^^^ within `impl Future`, the trait `Qux` is not implemented for `Foo`
|
||||
|
|
||||
note: future does not implement `Qux` as this value is used across an await
|
||||
--> $DIR/issue-64130-3-other.rs:18:5
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: future cannot be sent between threads safely
|
||||
--> $DIR/issue-64130-non-send-future-diags.rs:21:5
|
||||
--> $DIR/issue-64130-non-send-future-diags.rs:21:13
|
||||
|
|
||||
LL | is_send(foo());
|
||||
| ^^^^^^^ future returned by `foo` is not `Send`
|
||||
| ^^^^^ future returned by `foo` is not `Send`
|
||||
|
|
||||
= help: within `impl Future`, the trait `Send` is not implemented for `MutexGuard<'_, u32>`
|
||||
note: future is not `Send` as this value is used across an await
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: future cannot be sent between threads safely
|
||||
--> $DIR/issue-71137.rs:20:3
|
||||
--> $DIR/issue-71137.rs:20:14
|
||||
|
|
||||
LL | fake_spawn(wrong_mutex());
|
||||
| ^^^^^^^^^^ future returned by `wrong_mutex` is not `Send`
|
||||
| ^^^^^^^^^^^^^ future returned by `wrong_mutex` is not `Send`
|
||||
|
|
||||
= help: within `impl Future`, the trait `Send` is not implemented for `MutexGuard<'_, i32>`
|
||||
note: future is not `Send` as this value is used across an await
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: generator cannot be sent between threads safely
|
||||
--> $DIR/issue-67893.rs:9:5
|
||||
--> $DIR/issue-67893.rs:9:7
|
||||
|
|
||||
LL | g(issue_67893::run())
|
||||
| ^ generator is not `Send`
|
||||
| ^^^^^^^^^^^^^^^^^^ generator is not `Send`
|
||||
|
|
||||
= help: within `impl Future`, the trait `Send` is not implemented for `MutexGuard<'_, ()>`
|
||||
note: required by a bound in `g`
|
||||
|
@ -1,8 +1,10 @@
|
||||
error[E0277]: `PhantomPinned` cannot be unpinned
|
||||
--> $DIR/pin-needed-to-poll-2.rs:43:9
|
||||
--> $DIR/pin-needed-to-poll-2.rs:43:18
|
||||
|
|
||||
LL | Pin::new(&mut self.sleep).poll(cx)
|
||||
| ^^^^^^^^ within `Sleep`, the trait `Unpin` is not implemented for `PhantomPinned`
|
||||
| -------- ^^^^^^^^^^^^^^^ within `Sleep`, the trait `Unpin` is not implemented for `PhantomPinned`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= note: consider using `Box::pin`
|
||||
note: required because it appears within the type `Sleep`
|
||||
|
@ -1,8 +1,10 @@
|
||||
error[E0277]: the trait bound `(): _Contains<&C>` is not satisfied
|
||||
--> $DIR/issue-85848.rs:24:5
|
||||
--> $DIR/issue-85848.rs:24:29
|
||||
|
|
||||
LL | writes_to_specific_path(&cap);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `_Contains<&C>` is not implemented for `()`
|
||||
| ----------------------- ^^^^ the trait `_Contains<&C>` is not implemented for `()`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
note: required because of the requirements on the impl of `Contains<(), true>` for `&C`
|
||||
--> $DIR/issue-85848.rs:21:12
|
||||
@ -21,10 +23,12 @@ LL | fn writes_to_specific_path<C: Delegates<()>>(cap: &C) {}
|
||||
| ^^^^^^^^^^^^^ required by this bound in `writes_to_specific_path`
|
||||
|
||||
error: unconstrained generic constant
|
||||
--> $DIR/issue-85848.rs:24:5
|
||||
--> $DIR/issue-85848.rs:24:29
|
||||
|
|
||||
LL | writes_to_specific_path(&cap);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ----------------------- ^^^^
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: try adding a `where` bound using this expression: `where [(); { contains::<T, U>() }]:`
|
||||
note: required because of the requirements on the impl of `Contains<(), true>` for `&C`
|
||||
|
@ -37,8 +37,8 @@ trait Ty<'a> {
|
||||
fn main() {
|
||||
let v = Unit2.m(
|
||||
//~^ ERROR type mismatch
|
||||
//~| ERROR type mismatch
|
||||
L {
|
||||
//~^ ERROR type mismatch
|
||||
f : |x| { drop(x); Unit4 }
|
||||
});
|
||||
}
|
||||
|
@ -10,10 +10,16 @@ LL | let v = Unit2.m(
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
|
||||
|
||||
error[E0271]: type mismatch resolving `for<'r> <[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39] as FnOnce<((&'r u8,),)>>::Output == Unit3`
|
||||
--> $DIR/issue-62203-hrtb-ice.rs:38:19
|
||||
--> $DIR/issue-62203-hrtb-ice.rs:40:9
|
||||
|
|
||||
LL | let v = Unit2.m(
|
||||
| ^ expected struct `Unit4`, found struct `Unit3`
|
||||
LL | let v = Unit2.m(
|
||||
| - required by a bound introduced by this call
|
||||
LL |
|
||||
LL | / L {
|
||||
LL | |
|
||||
LL | | f : |x| { drop(x); Unit4 }
|
||||
LL | | });
|
||||
| |_________^ expected struct `Unit4`, found struct `Unit3`
|
||||
|
|
||||
note: required because of the requirements on the impl of `for<'r> T0<'r, (&'r u8,)>` for `L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39]>`
|
||||
--> $DIR/issue-62203-hrtb-ice.rs:17:16
|
||||
|
@ -1,11 +1,13 @@
|
||||
error[E0277]: `Rc<Cell<i32>>` cannot be sent between threads safely
|
||||
--> $DIR/auto-trait-leak2.rs:13:5
|
||||
--> $DIR/auto-trait-leak2.rs:13:10
|
||||
|
|
||||
LL | fn before() -> impl Fn(i32) {
|
||||
| ------------ within this `impl Fn<(i32,)>`
|
||||
...
|
||||
LL | send(before());
|
||||
| ^^^^ `Rc<Cell<i32>>` cannot be sent between threads safely
|
||||
| ---- ^^^^^^^^ `Rc<Cell<i32>>` cannot be sent between threads safely
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: within `impl Fn<(i32,)>`, the trait `Send` is not implemented for `Rc<Cell<i32>>`
|
||||
= note: required because it appears within the type `[closure@$DIR/auto-trait-leak2.rs:7:5: 7:22]`
|
||||
@ -17,10 +19,12 @@ LL | fn send<T: Send>(_: T) {}
|
||||
| ^^^^ required by this bound in `send`
|
||||
|
||||
error[E0277]: `Rc<Cell<i32>>` cannot be sent between threads safely
|
||||
--> $DIR/auto-trait-leak2.rs:16:5
|
||||
--> $DIR/auto-trait-leak2.rs:16:10
|
||||
|
|
||||
LL | send(after());
|
||||
| ^^^^ `Rc<Cell<i32>>` cannot be sent between threads safely
|
||||
| ---- ^^^^^^^ `Rc<Cell<i32>>` cannot be sent between threads safely
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
...
|
||||
LL | fn after() -> impl Fn(i32) {
|
||||
| ------------ within this `impl Fn<(i32,)>`
|
||||
|
@ -7,6 +7,7 @@ const fn not_fn_items() {
|
||||
//~^ ERROR expected a `FnOnce<()>` closure
|
||||
const_eval_select((), 42, 0xDEADBEEF);
|
||||
//~^ ERROR expected a `FnOnce<()>` closure
|
||||
//~| ERROR expected a `FnOnce<()>` closure
|
||||
}
|
||||
|
||||
const fn foo(n: i32) -> i32 {
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0277]: expected a `FnOnce<()>` closure, found `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:32]`
|
||||
--> $DIR/const-eval-select-bad.rs:6:34
|
||||
--> $DIR/const-eval-select-bad.rs:6:27
|
||||
|
|
||||
LL | const_eval_select((), || {}, || {});
|
||||
| ----------------- ^^^^^ expected an `FnOnce<()>` closure, found `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:32]`
|
||||
| ----------------- ^^^^^ expected an `FnOnce<()>` closure, found `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:32]`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
@ -14,6 +14,22 @@ note: required by a bound in `const_eval_select`
|
||||
LL | F: ~const FnOnce<ARG, Output = RET>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select`
|
||||
|
||||
error[E0277]: expected a `FnOnce<()>` closure, found `{integer}`
|
||||
--> $DIR/const-eval-select-bad.rs:8:27
|
||||
|
|
||||
LL | const_eval_select((), 42, 0xDEADBEEF);
|
||||
| ----------------- ^^ expected an `FnOnce<()>` closure, found `{integer}`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the trait `FnOnce<()>` is not implemented for `{integer}`
|
||||
= note: wrap the `{integer}` in a closure with no arguments: `|| { /* code */ }`
|
||||
note: required by a bound in `const_eval_select`
|
||||
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
|
||||
|
|
||||
LL | F: ~const FnOnce<ARG, Output = RET>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select`
|
||||
|
||||
error[E0277]: expected a `FnOnce<()>` closure, found `{integer}`
|
||||
--> $DIR/const-eval-select-bad.rs:8:31
|
||||
|
|
||||
@ -27,11 +43,11 @@ LL | const_eval_select((), 42, 0xDEADBEEF);
|
||||
note: required by a bound in `const_eval_select`
|
||||
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
|
||||
|
|
||||
LL | F: ~const FnOnce<ARG, Output = RET>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select`
|
||||
LL | G: FnOnce<ARG, Output = RET> + ~const Drop,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select`
|
||||
|
||||
error[E0271]: type mismatch resolving `<fn(i32) -> bool {bar} as FnOnce<(i32,)>>::Output == i32`
|
||||
--> $DIR/const-eval-select-bad.rs:27:5
|
||||
--> $DIR/const-eval-select-bad.rs:28:5
|
||||
|
|
||||
LL | const_eval_select((1,), foo, bar);
|
||||
| ^^^^^^^^^^^^^^^^^ expected `i32`, found `bool`
|
||||
@ -43,13 +59,13 @@ LL | G: FnOnce<ARG, Output = RET> + ~const Drop,
|
||||
| ^^^^^^^^^^^^ required by this bound in `const_eval_select`
|
||||
|
||||
error[E0631]: type mismatch in function arguments
|
||||
--> $DIR/const-eval-select-bad.rs:32:37
|
||||
--> $DIR/const-eval-select-bad.rs:33:32
|
||||
|
|
||||
LL | const fn foo(n: i32) -> i32 {
|
||||
| --------------------------- found signature of `fn(i32) -> _`
|
||||
...
|
||||
LL | const_eval_select((true,), foo, baz);
|
||||
| ----------------- ^^^ expected signature of `fn(bool) -> _`
|
||||
| ----------------- ^^^ expected signature of `fn(bool) -> _`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
@ -59,7 +75,7 @@ note: required by a bound in `const_eval_select`
|
||||
LL | F: ~const FnOnce<ARG, Output = RET>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0271, E0277, E0631.
|
||||
For more information about an error, try `rustc --explain E0271`.
|
||||
|
@ -1,8 +1,10 @@
|
||||
error[E0277]: `Rc<Foo>` cannot be shared between threads safely
|
||||
--> $DIR/issue-40827.rs:14:5
|
||||
--> $DIR/issue-40827.rs:14:7
|
||||
|
|
||||
LL | f(Foo(Arc::new(Bar::B(None))));
|
||||
| ^ `Rc<Foo>` cannot be shared between threads safely
|
||||
| - ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rc<Foo>` cannot be shared between threads safely
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: within `Bar`, the trait `Sync` is not implemented for `Rc<Foo>`
|
||||
note: required because it appears within the type `Bar`
|
||||
@ -23,10 +25,12 @@ LL | fn f<T: Send>(_: T) {}
|
||||
| ^^^^ required by this bound in `f`
|
||||
|
||||
error[E0277]: `Rc<Foo>` cannot be sent between threads safely
|
||||
--> $DIR/issue-40827.rs:14:5
|
||||
--> $DIR/issue-40827.rs:14:7
|
||||
|
|
||||
LL | f(Foo(Arc::new(Bar::B(None))));
|
||||
| ^ `Rc<Foo>` cannot be sent between threads safely
|
||||
| - ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rc<Foo>` cannot be sent between threads safely
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: within `Bar`, the trait `Send` is not implemented for `Rc<Foo>`
|
||||
note: required because it appears within the type `Bar`
|
||||
|
@ -1,8 +1,10 @@
|
||||
error[E0277]: `NoSync` cannot be shared between threads safely
|
||||
--> $DIR/mutable-enum-indirect.rs:17:5
|
||||
--> $DIR/mutable-enum-indirect.rs:17:9
|
||||
|
|
||||
LL | bar(&x);
|
||||
| ^^^ `NoSync` cannot be shared between threads safely
|
||||
| --- ^^ `NoSync` cannot be shared between threads safely
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: within `&Foo`, the trait `Sync` is not implemented for `NoSync`
|
||||
note: required because it appears within the type `Foo`
|
||||
|
@ -1,8 +1,10 @@
|
||||
error[E0277]: `NoSend` cannot be sent between threads safely
|
||||
--> $DIR/no_send-enum.rs:16:5
|
||||
--> $DIR/no_send-enum.rs:16:9
|
||||
|
|
||||
LL | bar(x);
|
||||
| ^^^ `NoSend` cannot be sent between threads safely
|
||||
| --- ^ `NoSend` cannot be sent between threads safely
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: within `Foo`, the trait `Send` is not implemented for `NoSend`
|
||||
note: required because it appears within the type `Foo`
|
||||
|
@ -1,8 +1,10 @@
|
||||
error[E0277]: `NoSync` cannot be shared between threads safely
|
||||
--> $DIR/no_share-enum.rs:14:5
|
||||
--> $DIR/no_share-enum.rs:14:9
|
||||
|
|
||||
LL | bar(x);
|
||||
| ^^^ `NoSync` cannot be shared between threads safely
|
||||
| --- ^ `NoSync` cannot be shared between threads safely
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: within `Foo`, the trait `Sync` is not implemented for `NoSync`
|
||||
note: required because it appears within the type `Foo`
|
||||
|
@ -51,9 +51,6 @@ LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
|
||||
error[E0277]: the trait bound `NonTrivialDrop: A` is not satisfied
|
||||
--> $DIR/const-drop-fail.rs:49:5
|
||||
|
|
||||
LL | const _: () = check($exp);
|
||||
| ----- required by a bound introduced by this call
|
||||
...
|
||||
LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `A` is not implemented for `NonTrivialDrop`
|
||||
|
|
||||
|
@ -51,9 +51,6 @@ LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
|
||||
error[E0277]: the trait bound `NonTrivialDrop: A` is not satisfied
|
||||
--> $DIR/const-drop-fail.rs:49:5
|
||||
|
|
||||
LL | const _: () = check($exp);
|
||||
| ----- required by a bound introduced by this call
|
||||
...
|
||||
LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `A` is not implemented for `NonTrivialDrop`
|
||||
|
|
||||
|
@ -1,8 +1,10 @@
|
||||
error[E0277]: the trait bound `&str: From<String>` is not satisfied
|
||||
--> $DIR/into-str.rs:4:5
|
||||
--> $DIR/into-str.rs:4:9
|
||||
|
|
||||
LL | foo(String::new());
|
||||
| ^^^ the trait `From<String>` is not implemented for `&str`
|
||||
| --- ^^^^^^^^^^^^^ the trait `From<String>` is not implemented for `&str`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= note: to coerce a `String` into a `&str`, use `&*` as a prefix
|
||||
= note: required because of the requirements on the impl of `Into<&str>` for `String`
|
||||
|
@ -5,7 +5,7 @@ LL | #[derive(Clone)]
|
||||
| ----- in this derive macro expansion
|
||||
LL | struct FooHolster {
|
||||
LL | the_foos: Vec<Foo>,
|
||||
| ^^^^^^^^^^^^^^^^^^ expected an implementor of trait `Clone`
|
||||
| ^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Foo`
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Clone` for `Vec<Foo>`
|
||||
note: required by `clone`
|
||||
|
@ -49,7 +49,7 @@ LL | is_send((8, TestType));
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the trait `Send` is not implemented for `dummy1c::TestType`
|
||||
= help: within `({integer}, dummy1c::TestType)`, the trait `Send` is not implemented for `dummy1c::TestType`
|
||||
= note: required because it appears within the type `({integer}, dummy1c::TestType)`
|
||||
note: required by a bound in `is_send`
|
||||
--> $DIR/negated-auto-traits-error.rs:16:15
|
||||
@ -86,7 +86,7 @@ LL | is_send(Box::new(Outer2(TestType)));
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the trait `Send` is not implemented for `dummy3::TestType`
|
||||
= help: within `Outer2<dummy3::TestType>`, the trait `Send` is not implemented for `dummy3::TestType`
|
||||
note: required because it appears within the type `Outer2<dummy3::TestType>`
|
||||
--> $DIR/negated-auto-traits-error.rs:12:8
|
||||
|
|
||||
|
@ -1,11 +1,13 @@
|
||||
error[E0277]: `Rc<u32>` cannot be sent between threads safely
|
||||
--> $DIR/auto-trait-leakage2.rs:17:5
|
||||
--> $DIR/auto-trait-leakage2.rs:17:13
|
||||
|
|
||||
LL | type Foo = impl std::fmt::Debug;
|
||||
| -------------------- within this `impl Debug`
|
||||
...
|
||||
LL | is_send(m::foo());
|
||||
| ^^^^^^^ `Rc<u32>` cannot be sent between threads safely
|
||||
| ------- ^^^^^^^^ `Rc<u32>` cannot be sent between threads safely
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: within `impl Debug`, the trait `Send` is not implemented for `Rc<u32>`
|
||||
= note: required because it appears within the type `impl Debug`
|
||||
|
8
src/test/ui/typeck/issue-90101.rs
Normal file
8
src/test/ui/typeck/issue-90101.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn func(path: impl Into<PathBuf>, code: impl Into<String>) {}
|
||||
|
||||
fn main() {
|
||||
func(Path::new("hello").to_path_buf().to_string_lossy(), "world")
|
||||
//~^ ERROR [E0277]
|
||||
}
|
24
src/test/ui/typeck/issue-90101.stderr
Normal file
24
src/test/ui/typeck/issue-90101.stderr
Normal file
@ -0,0 +1,24 @@
|
||||
error[E0277]: the trait bound `PathBuf: From<Cow<'_, str>>` is not satisfied
|
||||
--> $DIR/issue-90101.rs:6:10
|
||||
|
|
||||
LL | func(Path::new("hello").to_path_buf().to_string_lossy(), "world")
|
||||
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<Cow<'_, str>>` is not implemented for `PathBuf`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<PathBuf as From<&T>>
|
||||
<PathBuf as From<Box<Path>>>
|
||||
<PathBuf as From<Cow<'a, Path>>>
|
||||
<PathBuf as From<OsString>>
|
||||
<PathBuf as From<String>>
|
||||
= note: required because of the requirements on the impl of `Into<PathBuf>` for `Cow<'_, str>`
|
||||
note: required by a bound in `func`
|
||||
--> $DIR/issue-90101.rs:3:20
|
||||
|
|
||||
LL | fn func(path: impl Into<PathBuf>, code: impl Into<String>) {}
|
||||
| ^^^^^^^^^^^^^ required by this bound in `func`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
@ -29,10 +29,12 @@ LL | fn test<T: Sync>(s: T) {}
|
||||
| ^^^^ required by this bound in `test`
|
||||
|
||||
error[E0277]: `UnsafeCell<NoSync>` cannot be shared between threads safely
|
||||
--> $DIR/typeck-unsafe-always-share.rs:27:5
|
||||
--> $DIR/typeck-unsafe-always-share.rs:27:10
|
||||
|
|
||||
LL | test(ms);
|
||||
| ^^^^ `UnsafeCell<NoSync>` cannot be shared between threads safely
|
||||
| ---- ^^ `UnsafeCell<NoSync>` cannot be shared between threads safely
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: within `MySync<NoSync>`, the trait `Sync` is not implemented for `UnsafeCell<NoSync>`
|
||||
note: required because it appears within the type `MySync<NoSync>`
|
||||
|
@ -16,7 +16,7 @@ LL | udrop::<A<[u8]>>(A { 0: *foo() });
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `[u8]`
|
||||
= 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
|
||||
|
|
||||
|
Loading…
Reference in New Issue
Block a user