@@ -23,9 +23,8 @@ use crate::types::{
23
23
KnownFunction , KnownInstanceType , MethodWrapperKind , PropertyInstanceType , TupleType ,
24
24
UnionType , WrapperDescriptorKind ,
25
25
} ;
26
- use ruff_db:: diagnostic:: { Annotation , Severity , Span , SubDiagnostic } ;
26
+ use ruff_db:: diagnostic:: { Annotation , Severity , SubDiagnostic } ;
27
27
use ruff_python_ast as ast;
28
- use ruff_text_size:: Ranged ;
29
28
30
29
/// Binding information for a possible union of callables. At a call site, the arguments must be
31
30
/// compatible with _all_ of the types in the union for the call to be valid.
@@ -1386,47 +1385,6 @@ pub(crate) enum BindingError<'db> {
1386
1385
}
1387
1386
1388
1387
impl < ' db > BindingError < ' db > {
1389
- /// Returns a tuple of two spans. The first is
1390
- /// the span for the identifier of the function
1391
- /// definition for `callable_ty`. The second is
1392
- /// the span for the parameter in the function
1393
- /// definition for `callable_ty`.
1394
- ///
1395
- /// If there are no meaningful spans, then this
1396
- /// returns `None`.
1397
- fn parameter_span_from_index (
1398
- db : & ' db dyn Db ,
1399
- callable_ty : Type < ' db > ,
1400
- parameter_index : usize ,
1401
- ) -> Option < ( Span , Span ) > {
1402
- match callable_ty {
1403
- Type :: FunctionLiteral ( function) => {
1404
- let function_scope = function. body_scope ( db) ;
1405
- let span = Span :: from ( function_scope. file ( db) ) ;
1406
- let node = function_scope. node ( db) ;
1407
- if let Some ( func_def) = node. as_function ( ) {
1408
- let range = func_def
1409
- . parameters
1410
- . iter ( )
1411
- . nth ( parameter_index)
1412
- . map ( |param| param. range ( ) )
1413
- . unwrap_or ( func_def. parameters . range ) ;
1414
- let name_span = span. clone ( ) . with_range ( func_def. name . range ) ;
1415
- let parameter_span = span. with_range ( range) ;
1416
- Some ( ( name_span, parameter_span) )
1417
- } else {
1418
- None
1419
- }
1420
- }
1421
- Type :: BoundMethod ( bound_method) => Self :: parameter_span_from_index (
1422
- db,
1423
- Type :: FunctionLiteral ( bound_method. function ( db) ) ,
1424
- parameter_index,
1425
- ) ,
1426
- _ => None ,
1427
- }
1428
- }
1429
-
1430
1388
pub ( super ) fn report_diagnostic (
1431
1389
& self ,
1432
1390
context : & InferContext < ' db > ,
@@ -1454,7 +1412,7 @@ impl<'db> BindingError<'db> {
1454
1412
"Expected `{expected_ty_display}`, found `{provided_ty_display}`"
1455
1413
) ) ;
1456
1414
if let Some ( ( name_span, parameter_span) ) =
1457
- Self :: parameter_span_from_index ( context. db ( ) , callable_ty , parameter. index )
1415
+ callable_ty . parameter_span ( context. db ( ) , Some ( parameter. index ) )
1458
1416
{
1459
1417
let mut sub = SubDiagnostic :: new ( Severity :: Info , "Function defined here" ) ;
1460
1418
sub. annotate ( Annotation :: primary ( name_span) ) ;
0 commit comments