1
Fork 0

Targeted fixes addressing erroneous suggestions

This commit is contained in:
Michael Goulet 2022-08-17 06:48:09 +00:00
parent 6848ba2665
commit 8917894fda
7 changed files with 29 additions and 39 deletions

View file

@ -671,11 +671,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
trait_pred: ty::PolyTraitPredicate<'tcx>,
) -> bool {
// It only make sense when suggesting dereferences for arguments
let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } = obligation.cause.code() else {
return false;
};
let param_env = obligation.param_env;
let body_id = obligation.cause.body_id;
let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } = obligation.cause.code()
else { return false; };
let Some(typeck_results) = self.in_progress_typeck_results
else { return false; };
let typeck_results = typeck_results.borrow();
let hir::Node::Expr(expr) = self.tcx.hir().get(*arg_hir_id)
else { return false; };
let Some(arg_ty) = typeck_results.expr_ty_adjusted_opt(expr)
else { return false; };
let span = obligation.cause.span;
let mut real_trait_pred = trait_pred;
let mut code = obligation.cause.code();
@ -687,9 +692,19 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// Skipping binder here, remapping below
let real_ty = real_trait_pred.self_ty().skip_binder();
if self.can_eq(obligation.param_env, real_ty, arg_ty).is_err() {
continue;
}
if let ty::Ref(region, base_ty, mutbl) = *real_ty.kind() {
let mut autoderef = Autoderef::new(self, param_env, body_id, span, base_ty, span);
let mut autoderef = Autoderef::new(
self,
obligation.param_env,
obligation.cause.body_id,
span,
base_ty,
span,
);
if let Some(steps) = autoderef.find_map(|(ty, steps)| {
// Re-add the `&`
let ty = self.tcx.mk_ref(region, TypeAndMut { ty, mutbl });
@ -697,8 +712,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// Remapping bound vars here
let real_trait_pred_and_ty =
real_trait_pred.map_bound(|inner_trait_pred| (inner_trait_pred, ty));
let obligation = self
.mk_trait_obligation_with_new_self_ty(param_env, real_trait_pred_and_ty);
let obligation = self.mk_trait_obligation_with_new_self_ty(
obligation.param_env,
real_trait_pred_and_ty,
);
Some(steps).filter(|_| self.predicate_may_hold(&obligation))
}) {
if steps > 0 {
@ -727,7 +744,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let real_trait_pred_and_base_ty =
real_trait_pred.map_bound(|inner_trait_pred| (inner_trait_pred, base_ty));
let obligation = self.mk_trait_obligation_with_new_self_ty(
param_env,
obligation.param_env,
real_trait_pred_and_base_ty,
);
if self.predicate_may_hold(&obligation) {
@ -855,6 +872,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
_ => return false,
};
if matches!(obligation.cause.code(), ObligationCauseCode::FunctionArgumentObligation { .. })
&& obligation.cause.span.can_be_used_for_suggestions()
{
// When the obligation error has been ensured to have been caused by
// an argument, the `obligation.cause.span` points at the expression

View file

@ -19,12 +19,8 @@ LL | assert_eq!(foo, y);
| ^^^^^^^^^^^^^^^^^^ `for<'r> fn(&'r i32) -> &'r i32 {foo}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= help: the trait `Debug` is not implemented for `for<'r> fn(&'r i32) -> &'r i32 {foo}`
= help: use parentheses to call the function: `foo(s)`
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
help: use parentheses to call the function
--> $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
LL | $crate::panicking::assert_failed(kind, &*left_val(s), &*right_val, $crate::option::Option::None);
| +++
error: aborting due to 2 previous errors

View file

@ -22,10 +22,6 @@ note: required by a bound in `spawn`
|
LL | F: Send + 'static,
| ^^^^ required by this bound in `spawn`
help: consider dereferencing here
|
LL | let t = thread::spawn(*|| {
| +
error[E0277]: `Sender<()>` cannot be shared between threads safely
--> $DIR/closure-move-sync.rs:18:19
@ -47,10 +43,6 @@ note: required by a bound in `spawn`
|
LL | F: Send + 'static,
| ^^^^ required by this bound in `spawn`
help: consider dereferencing here
|
LL | thread::spawn(*|| tx.send(()).unwrap());
| +
error: aborting due to 2 previous errors

View file

@ -23,10 +23,6 @@ note: required by a bound in `assert_send`
|
LL | fn assert_send<T: Send>(_: T) {}
| ^^^^ required by this bound in `assert_send`
help: consider dereferencing here
|
LL | assert_send(*|| {
| +
error: generator cannot be shared between threads safely
--> $DIR/not-send-sync.rs:9:17

View file

@ -23,10 +23,6 @@ note: required by a bound in `assert_send`
|
LL | fn assert_send<T: Send>(_: T) {}
| ^^^^ required by this bound in `assert_send`
help: consider dereferencing here
|
LL | assert_send(*|| {
| +
error: generator cannot be shared between threads safely
--> $DIR/generator-print-verbose-2.rs:12:17

View file

@ -19,10 +19,6 @@ note: required by a bound in `catch_unwind`
|
LL | pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
| ^^^^^^^^^^ required by this bound in `catch_unwind`
help: consider dereferencing here
|
LL | catch_unwind(*|| { x.set(23); });
| +
error: aborting due to previous error

View file

@ -34,12 +34,8 @@ LL | assert_eq!(a, 0);
| ^^^^^^^^^^^^^^^^ `fn() -> i32 {a}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= help: the trait `Debug` is not implemented for `fn() -> i32 {a}`
= help: use parentheses to call the function: `a()`
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
help: use parentheses to call the function
--> $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
LL | $crate::panicking::assert_failed(kind, &*left_val(), &*right_val, $crate::option::Option::None);
| ++
error: aborting due to 3 previous errors