Skip to content

Commit 09cd547

Browse files
Call skip_binder before self_ty to get old behavior
1 parent 69a8a88 commit 09cd547

File tree

6 files changed

+39
-22
lines changed

6 files changed

+39
-22
lines changed

src/librustc_trait_selection/traits/error_reporting/mod.rs

+21-11
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
289289
(
290290
Some(format!(
291291
"`?` couldn't convert the error to `{}`",
292-
trait_ref.self_ty(),
292+
trait_ref.skip_binder().self_ty(),
293293
)),
294294
Some(
295295
"the question mark operation (`?`) implicitly performs a \
@@ -339,7 +339,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
339339
if let Some(ret_span) = self.return_type_span(obligation) {
340340
err.span_label(
341341
ret_span,
342-
&format!("expected `{}` because of this", trait_ref.self_ty()),
342+
&format!(
343+
"expected `{}` because of this",
344+
trait_ref.skip_binder().self_ty()
345+
),
343346
);
344347
}
345348
}
@@ -352,7 +355,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
352355
"{}the trait `{}` is not implemented for `{}`",
353356
pre_message,
354357
trait_ref.print_only_trait_path(),
355-
trait_ref.self_ty(),
358+
trait_ref.skip_binder().self_ty(),
356359
)
357360
};
358361

@@ -638,7 +641,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
638641
return;
639642
}
640643

641-
let found_trait_ty = found_trait_ref.self_ty();
644+
let found_trait_ty = match found_trait_ref.self_ty().no_bound_vars() {
645+
Some(ty) => ty,
646+
None => return,
647+
};
642648

643649
let found_did = match found_trait_ty.kind {
644650
ty::Closure(did, _) | ty::Foreign(did) | ty::FnDef(did, _) => Some(did),
@@ -1352,11 +1358,15 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
13521358
) {
13531359
let get_trait_impl = |trait_def_id| {
13541360
let mut trait_impl = None;
1355-
self.tcx.for_each_relevant_impl(trait_def_id, trait_ref.self_ty(), |impl_def_id| {
1356-
if trait_impl.is_none() {
1357-
trait_impl = Some(impl_def_id);
1358-
}
1359-
});
1361+
self.tcx.for_each_relevant_impl(
1362+
trait_def_id,
1363+
trait_ref.skip_binder().self_ty(),
1364+
|impl_def_id| {
1365+
if trait_impl.is_none() {
1366+
trait_impl = Some(impl_def_id);
1367+
}
1368+
},
1369+
);
13601370
trait_impl
13611371
};
13621372
let required_trait_path = self.tcx.def_path_str(trait_ref.def_id());
@@ -1419,7 +1429,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
14191429
let mut err = match predicate.kind() {
14201430
ty::PredicateKind::Trait(ref data, _) => {
14211431
let trait_ref = data.to_poly_trait_ref();
1422-
let self_ty = trait_ref.self_ty();
1432+
let self_ty = trait_ref.skip_binder().self_ty();
14231433
debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind, trait_ref);
14241434

14251435
if predicate.references_error() {
@@ -1537,7 +1547,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
15371547
}
15381548
ty::PredicateKind::Projection(ref data) => {
15391549
let trait_ref = data.to_poly_trait_ref(self.tcx);
1540-
let self_ty = trait_ref.self_ty();
1550+
let self_ty = trait_ref.skip_binder().self_ty();
15411551
let ty = data.skip_binder().ty;
15421552
if predicate.references_error() {
15431553
return;

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
318318
trait_ref: ty::PolyTraitRef<'tcx>,
319319
body_id: hir::HirId,
320320
) {
321-
let self_ty = trait_ref.self_ty();
321+
let self_ty = trait_ref.skip_binder().self_ty();
322322
let (param_ty, projection) = match &self_ty.kind {
323323
ty::Param(_) => (true, None),
324324
ty::Projection(projection) => (false, Some(projection)),
@@ -524,7 +524,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
524524
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
525525
points_at_arg: bool,
526526
) {
527-
let self_ty = trait_ref.self_ty();
527+
let self_ty = match trait_ref.self_ty().no_bound_vars() {
528+
None => return,
529+
Some(ty) => ty,
530+
};
531+
528532
let (def_id, output_ty, callable) = match self_ty.kind {
529533
ty::Closure(def_id, substs) => (def_id, substs.as_closure().sig().output(), "closure"),
530534
ty::FnDef(def_id, _) => (def_id, self_ty.fn_sig(self.tcx).output(), "function"),
@@ -828,6 +832,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
828832
span: Span,
829833
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
830834
) {
835+
let is_empty_tuple =
836+
|ty: ty::Binder<Ty<'_>>| ty.skip_binder().kind == ty::Tuple(ty::List::empty());
837+
831838
let hir = self.tcx.hir();
832839
let parent_node = hir.get_parent_node(obligation.cause.body_id);
833840
let node = hir.find(parent_node);
@@ -839,7 +846,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
839846
if let hir::ExprKind::Block(blk, _) = &body.value.kind {
840847
if sig.decl.output.span().overlaps(span)
841848
&& blk.expr.is_none()
842-
&& "()" == &trait_ref.self_ty().to_string()
849+
&& is_empty_tuple(trait_ref.self_ty())
843850
{
844851
// FIXME(estebank): When encountering a method with a trait
845852
// bound not satisfied in the return type with a body that has
@@ -1270,7 +1277,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12701277
ObligationCauseCode::DerivedObligation(derived_obligation)
12711278
| ObligationCauseCode::BuiltinDerivedObligation(derived_obligation)
12721279
| ObligationCauseCode::ImplDerivedObligation(derived_obligation) => {
1273-
let ty = derived_obligation.parent_trait_ref.self_ty();
1280+
let ty = derived_obligation.parent_trait_ref.skip_binder().self_ty();
12741281
debug!(
12751282
"maybe_note_obligation_cause_for_async_await: \
12761283
parent_trait_ref={:?} self_ty.kind={:?}",
@@ -1910,7 +1917,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
19101917

19111918
let impls_future = self.tcx.type_implements_trait((
19121919
future_trait,
1913-
self_ty,
1920+
self_ty.skip_binder(),
19141921
ty::List::empty(),
19151922
obligation.param_env,
19161923
));
@@ -1926,7 +1933,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
19261933
let projection_ty = ty::ProjectionTy {
19271934
// `T`
19281935
substs: self.tcx.mk_substs_trait(
1929-
trait_ref.self_ty(),
1936+
trait_ref.self_ty().skip_binder(),
19301937
self.fresh_substs_for_item(span, item_def_id),
19311938
),
19321939
// `Future::Output`

src/librustc_trait_selection/traits/specialize/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String>
496496
for (p, _) in predicates {
497497
if let Some(poly_trait_ref) = p.to_opt_poly_trait_ref() {
498498
if Some(poly_trait_ref.def_id()) == sized_trait {
499-
types_without_default_bounds.remove(poly_trait_ref.self_ty());
499+
types_without_default_bounds.remove(poly_trait_ref.self_ty().skip_binder());
500500
continue;
501501
}
502502
}

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3820,7 +3820,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38203820
trait_ref: ty::PolyTraitRef<'tcx>,
38213821
expected_vid: ty::TyVid,
38223822
) -> bool {
3823-
let self_ty = self.shallow_resolve(trait_ref.self_ty());
3823+
let self_ty = self.shallow_resolve(trait_ref.skip_binder().self_ty());
38243824
debug!(
38253825
"self_type_matches_expected_vid(trait_ref={:?}, self_ty={:?}, expected_vid={:?})",
38263826
trait_ref, self_ty, expected_vid

src/librustdoc/clean/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl<'a> Clean<WherePredicate> for ty::PolyTraitPredicate<'a> {
501501
fn clean(&self, cx: &DocContext<'_>) -> WherePredicate {
502502
let poly_trait_ref = self.map_bound(|pred| pred.trait_ref);
503503
WherePredicate::BoundPredicate {
504-
ty: poly_trait_ref.self_ty().clean(cx),
504+
ty: poly_trait_ref.skip_binder().self_ty().clean(cx),
505505
bounds: vec![poly_trait_ref.clean(cx)],
506506
}
507507
}
@@ -756,7 +756,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
756756
let mut projection = None;
757757
let param_idx = (|| {
758758
if let Some(trait_ref) = p.to_opt_poly_trait_ref() {
759-
if let ty::Param(param) = trait_ref.self_ty().kind {
759+
if let ty::Param(param) = trait_ref.skip_binder().self_ty().kind {
760760
return Some(param.index);
761761
}
762762
} else if let Some(outlives) = p.to_opt_type_outlives() {

src/tools/clippy/clippy_lints/src/future_not_send.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FutureNotSend {
9595
let trait_ref = trait_pred.to_poly_trait_ref();
9696
db.note(&*format!(
9797
"`{}` doesn't implement `{}`",
98-
trait_ref.self_ty(),
98+
trait_ref.skip_binder().self_ty(),
9999
trait_ref.print_only_trait_path(),
100100
));
101101
}

0 commit comments

Comments
 (0)