mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-26 13:01:27 +03:00
Rollup merge of #155685 - Walnut356:ret_type, r=jieyouxu
Fix `get_child_at_index` return type hints returning `None` is valid when the index is invalid, so the type hints should reflect that
This commit is contained in:
+19
-19
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
import sys
|
||||
from typing import Generator, List, TYPE_CHECKING
|
||||
from typing import Generator, List, TYPE_CHECKING, Optional
|
||||
|
||||
from lldb import (
|
||||
SBData,
|
||||
@@ -112,7 +112,7 @@ class DefaultSyntheticProvider:
|
||||
return self.valobj.Dereference().GetSyntheticValue()
|
||||
return self.valobj.GetIndexOfChildWithName(name)
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
return self.valobj.GetChildAtIndex(index)
|
||||
|
||||
def update(self):
|
||||
@@ -137,7 +137,7 @@ class IndirectionSyntheticProvider:
|
||||
return 0
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
if index == 0:
|
||||
return self.valobj.Dereference().GetSyntheticValue()
|
||||
return None
|
||||
@@ -164,7 +164,7 @@ class EmptySyntheticProvider:
|
||||
def get_child_index(self, name: str) -> int:
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
return None
|
||||
|
||||
def update(self):
|
||||
@@ -425,7 +425,7 @@ class StructSyntheticProvider:
|
||||
def get_child_index(self, name: str) -> int:
|
||||
return self.fields.get(name, -1)
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
if self.is_variant:
|
||||
field = self.type.GetFieldAtIndex(index + 1)
|
||||
else:
|
||||
@@ -470,7 +470,7 @@ class StdStringSyntheticProvider:
|
||||
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
if not 0 <= index < self.length:
|
||||
return None
|
||||
start = self.data_ptr.GetValueAsUnsigned()
|
||||
@@ -506,7 +506,7 @@ class MSVCStrSyntheticProvider:
|
||||
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
if not 0 <= index < self.length:
|
||||
return None
|
||||
start = self.data_ptr.GetValueAsUnsigned()
|
||||
@@ -562,7 +562,7 @@ class ClangEncodedEnumProvider:
|
||||
def get_child_index(self, name: str) -> int:
|
||||
return self.value.GetIndexOfChildWithName(name)
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
return self.value.GetChildAtIndex(index)
|
||||
|
||||
def update(self):
|
||||
@@ -768,7 +768,7 @@ class MSVCEnumSyntheticProvider:
|
||||
def get_child_index(self, name: str) -> int:
|
||||
return self.value.GetIndexOfChildWithName(name)
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
return self.value.GetChildAtIndex(index)
|
||||
|
||||
def has_children(self) -> bool:
|
||||
@@ -858,7 +858,7 @@ class TupleSyntheticProvider:
|
||||
else:
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
if self.is_variant:
|
||||
field = self.type.GetFieldAtIndex(index + 1)
|
||||
else:
|
||||
@@ -887,7 +887,7 @@ class MSVCTupleSyntheticProvider:
|
||||
def get_child_index(self, name: str) -> int:
|
||||
return self.valobj.GetIndexOfChildWithName(name)
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
child: SBValue = self.valobj.GetChildAtIndex(index)
|
||||
offset = self.valobj.GetType().GetFieldAtIndex(index).byte_offset
|
||||
return self.valobj.CreateChildAtOffset(str(index), offset, child.GetType())
|
||||
@@ -935,7 +935,7 @@ class StdVecSyntheticProvider:
|
||||
else:
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
start = self.data_ptr.GetValueAsUnsigned()
|
||||
address = start + index * self.element_type_size
|
||||
element = self.data_ptr.CreateValueFromAddress(
|
||||
@@ -983,7 +983,7 @@ class StdSliceSyntheticProvider:
|
||||
else:
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
start = self.data_ptr.GetValueAsUnsigned()
|
||||
address = start + index * self.element_size
|
||||
element = self.data_ptr.CreateValueFromAddress(
|
||||
@@ -1047,7 +1047,7 @@ class StdVecDequeSyntheticProvider:
|
||||
else:
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
start = self.data_ptr.GetValueAsUnsigned()
|
||||
address = start + ((index + self.head) % self.cap) * self.element_type_size
|
||||
element = self.data_ptr.CreateValueFromAddress(
|
||||
@@ -1106,7 +1106,7 @@ class StdOldHashMapSyntheticProvider:
|
||||
else:
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
# logger = Logger.Logger()
|
||||
start = self.data_ptr.GetValueAsUnsigned() & ~1
|
||||
|
||||
@@ -1195,7 +1195,7 @@ class StdHashMapSyntheticProvider:
|
||||
else:
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
pairs_start = self.data_ptr.GetValueAsUnsigned()
|
||||
idx = self.valid_indices[index]
|
||||
if self.new_layout:
|
||||
@@ -1318,7 +1318,7 @@ class StdRcSyntheticProvider:
|
||||
return 2
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
if index == 0:
|
||||
return self.value
|
||||
if index == 1:
|
||||
@@ -1351,7 +1351,7 @@ class StdCellSyntheticProvider:
|
||||
return 0
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
if index == 0:
|
||||
return self.value
|
||||
return None
|
||||
@@ -1406,7 +1406,7 @@ class StdRefSyntheticProvider:
|
||||
return 1
|
||||
return -1
|
||||
|
||||
def get_child_at_index(self, index: int) -> SBValue:
|
||||
def get_child_at_index(self, index: int) -> Optional[SBValue]:
|
||||
if index == 0:
|
||||
return self.value
|
||||
if index == 1:
|
||||
|
||||
Reference in New Issue
Block a user