@@ -13,9 +13,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
1313use rustc_data_structures:: sorted_map:: SortedMap ;
1414use rustc_data_structures:: unord:: UnordSet ;
1515use rustc_errors:: codes:: * ;
16- use rustc_errors:: {
17- Applicability , Diag , DiagStyledString , MultiSpan , StashKey , pluralize, struct_span_code_err,
18- } ;
16+ use rustc_errors:: { Applicability , Diag , MultiSpan , StashKey , pluralize, struct_span_code_err} ;
1917use rustc_hir:: attrs:: AttributeKind ;
2018use rustc_hir:: def:: { CtorKind , DefKind , Res } ;
2119use rustc_hir:: def_id:: DefId ;
@@ -1572,11 +1570,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15721570 ) ;
15731571 }
15741572
1575- if rcvr_ty. is_numeric ( ) && rcvr_ty. is_fresh ( )
1576- || restrict_type_params
1577- || suggested_derive
1578- || self . lookup_alternative_tuple_impls ( & mut err, & unsatisfied_predicates)
1579- {
1573+ if rcvr_ty. is_numeric ( ) && rcvr_ty. is_fresh ( ) || restrict_type_params || suggested_derive {
15801574 } else {
15811575 self . suggest_traits_to_import (
15821576 & mut err,
@@ -1753,119 +1747,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17531747 err. emit ( )
17541748 }
17551749
1756- /// If the predicate failure is caused by an unmet bound on a tuple, recheck if the bound would
1757- /// succeed if all the types on the tuple had no borrows. This is a common problem for libraries
1758- /// like Bevy and ORMs, which rely heavily on traits being implemented on tuples.
1759- fn lookup_alternative_tuple_impls (
1760- & self ,
1761- err : & mut Diag < ' _ > ,
1762- unsatisfied_predicates : & [ (
1763- ty:: Predicate < ' tcx > ,
1764- Option < ty:: Predicate < ' tcx > > ,
1765- Option < ObligationCause < ' tcx > > ,
1766- ) ] ,
1767- ) -> bool {
1768- let mut found_tuple = false ;
1769- for ( pred, root, _ob) in unsatisfied_predicates {
1770- let mut preds = vec ! [ pred] ;
1771- if let Some ( root) = root {
1772- // We will look at both the current predicate and the root predicate that caused it
1773- // to be needed. If calling something like `<(A, &B)>::default()`, then `pred` is
1774- // `&B: Default` and `root` is `(A, &B): Default`, which is the one we are checking
1775- // for further down, so we check both.
1776- preds. push ( root) ;
1777- }
1778- for pred in preds {
1779- if let Some ( clause) = pred. as_clause ( )
1780- && let Some ( clause) = clause. as_trait_clause ( )
1781- && let ty = clause. self_ty ( ) . skip_binder ( )
1782- && let ty:: Tuple ( types) = ty. kind ( )
1783- {
1784- let path = clause. skip_binder ( ) . trait_ref . print_only_trait_path ( ) ;
1785- let def_id = clause. def_id ( ) ;
1786- let ty = Ty :: new_tup (
1787- self . tcx ,
1788- self . tcx . mk_type_list_from_iter ( types. iter ( ) . map ( |ty| ty. peel_refs ( ) ) ) ,
1789- ) ;
1790- let args = ty:: GenericArgs :: for_item ( self . tcx , def_id, |param, _| {
1791- if param. index == 0 {
1792- ty. into ( )
1793- } else {
1794- self . infcx . var_for_def ( DUMMY_SP , param)
1795- }
1796- } ) ;
1797- if self
1798- . infcx
1799- . type_implements_trait ( def_id, args, self . param_env )
1800- . must_apply_modulo_regions ( )
1801- {
1802- // "`Trait` is implemented for `(A, B)` but not for `(A, &B)`"
1803- let mut msg = DiagStyledString :: normal ( format ! ( "`{path}` " ) ) ;
1804- msg. push_highlighted ( "is" ) ;
1805- msg. push_normal ( " implemented for `(" ) ;
1806- let len = types. len ( ) ;
1807- for ( i, t) in types. iter ( ) . enumerate ( ) {
1808- msg. push (
1809- format ! ( "{}" , with_forced_trimmed_paths!( t. peel_refs( ) ) ) ,
1810- t. peel_refs ( ) != t,
1811- ) ;
1812- if i < len - 1 {
1813- msg. push_normal ( ", " ) ;
1814- }
1815- }
1816- msg. push_normal ( ")` but " ) ;
1817- msg. push_highlighted ( "not" ) ;
1818- msg. push_normal ( " for `(" ) ;
1819- for ( i, t) in types. iter ( ) . enumerate ( ) {
1820- msg. push (
1821- format ! ( "{}" , with_forced_trimmed_paths!( t) ) ,
1822- t. peel_refs ( ) != t,
1823- ) ;
1824- if i < len - 1 {
1825- msg. push_normal ( ", " ) ;
1826- }
1827- }
1828- msg. push_normal ( ")`" ) ;
1829-
1830- // Find the span corresponding to the impl that was found to point at it.
1831- if let Some ( impl_span) = self
1832- . tcx
1833- . all_impls ( def_id)
1834- . filter ( |& impl_def_id| {
1835- let header = self . tcx . impl_trait_header ( impl_def_id) . unwrap ( ) ;
1836- let trait_ref = header. trait_ref . instantiate (
1837- self . tcx ,
1838- self . infcx . fresh_args_for_item ( DUMMY_SP , impl_def_id) ,
1839- ) ;
1840-
1841- let value = ty:: fold_regions ( self . tcx , ty, |_, _| {
1842- self . tcx . lifetimes . re_erased
1843- } ) ;
1844- // FIXME: Don't bother dealing with non-lifetime binders here...
1845- if value. has_escaping_bound_vars ( ) {
1846- return false ;
1847- }
1848- self . infcx . can_eq ( ty:: ParamEnv :: empty ( ) , trait_ref. self_ty ( ) , value)
1849- && header. polarity == ty:: ImplPolarity :: Positive
1850- } )
1851- . map ( |impl_def_id| self . tcx . def_span ( impl_def_id) )
1852- . next ( )
1853- {
1854- err. highlighted_span_note ( impl_span, msg. 0 ) ;
1855- } else {
1856- err. highlighted_note ( msg. 0 ) ;
1857- }
1858- found_tuple = true ;
1859- }
1860- // If `pred` was already on the tuple, we don't need to look at the root
1861- // obligation too.
1862- break ;
1863- }
1864- }
1865- }
1866- found_tuple
1867- }
1868-
18691750 /// If an appropriate error source is not found, check method chain for possible candidates
18701751 fn lookup_segments_chain_for_no_match_method (
18711752 & self ,
0 commit comments