@@ -27,7 +27,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2727use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder } ;
2828use rustc_hir as hir;
2929use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
30- use rustc_span:: source_map:: SourceMap ;
3130use rustc_span:: { ExpnKind , Span , DUMMY_SP } ;
3231use std:: fmt;
3332use syntax:: ast;
@@ -1427,74 +1426,3 @@ impl ArgKind {
14271426 }
14281427 }
14291428}
1430-
1431- /// Suggest restricting a type param with a new bound.
1432- pub fn suggest_constraining_type_param (
1433- generics : & hir:: Generics < ' _ > ,
1434- err : & mut DiagnosticBuilder < ' _ > ,
1435- param_name : & str ,
1436- constraint : & str ,
1437- source_map : & SourceMap ,
1438- span : Span ,
1439- ) -> bool {
1440- let restrict_msg = "consider further restricting this bound" ;
1441- if let Some ( param) =
1442- generics. params . iter ( ) . filter ( |p| p. name . ident ( ) . as_str ( ) == param_name) . next ( )
1443- {
1444- if param_name. starts_with ( "impl " ) {
1445- // `impl Trait` in argument:
1446- // `fn foo(x: impl Trait) {}` → `fn foo(t: impl Trait + Trait2) {}`
1447- err. span_suggestion (
1448- param. span ,
1449- restrict_msg,
1450- // `impl CurrentTrait + MissingTrait`
1451- format ! ( "{} + {}" , param_name, constraint) ,
1452- Applicability :: MachineApplicable ,
1453- ) ;
1454- } else if generics. where_clause . predicates . is_empty ( ) && param. bounds . is_empty ( ) {
1455- // If there are no bounds whatsoever, suggest adding a constraint
1456- // to the type parameter:
1457- // `fn foo<T>(t: T) {}` → `fn foo<T: Trait>(t: T) {}`
1458- err. span_suggestion (
1459- param. span ,
1460- "consider restricting this bound" ,
1461- format ! ( "{}: {}" , param_name, constraint) ,
1462- Applicability :: MachineApplicable ,
1463- ) ;
1464- } else if !generics. where_clause . predicates . is_empty ( ) {
1465- // There is a `where` clause, so suggest expanding it:
1466- // `fn foo<T>(t: T) where T: Debug {}` →
1467- // `fn foo<T>(t: T) where T: Debug, T: Trait {}`
1468- err. span_suggestion (
1469- generics. where_clause . span ( ) . unwrap ( ) . shrink_to_hi ( ) ,
1470- & format ! ( "consider further restricting type parameter `{}`" , param_name) ,
1471- format ! ( ", {}: {}" , param_name, constraint) ,
1472- Applicability :: MachineApplicable ,
1473- ) ;
1474- } else {
1475- // If there is no `where` clause lean towards constraining to the
1476- // type parameter:
1477- // `fn foo<X: Bar, T>(t: T, x: X) {}` → `fn foo<T: Trait>(t: T) {}`
1478- // `fn foo<T: Bar>(t: T) {}` → `fn foo<T: Bar + Trait>(t: T) {}`
1479- let sp = param. span . with_hi ( span. hi ( ) ) ;
1480- let span = source_map. span_through_char ( sp, ':' ) ;
1481- if sp != param. span && sp != span {
1482- // Only suggest if we have high certainty that the span
1483- // covers the colon in `foo<T: Trait>`.
1484- err. span_suggestion (
1485- span,
1486- restrict_msg,
1487- format ! ( "{}: {} + " , param_name, constraint) ,
1488- Applicability :: MachineApplicable ,
1489- ) ;
1490- } else {
1491- err. span_label (
1492- param. span ,
1493- & format ! ( "consider adding a `where {}: {}` bound" , param_name, constraint) ,
1494- ) ;
1495- }
1496- }
1497- return true ;
1498- }
1499- false
1500- }
0 commit comments