# Same-type requirement makes generic parameters 'T' and 'Pointee' equivalent; this is an error in Swift 6 warning

**URL:** <https://forums.swift.org/t/same-type-requirement-makes-generic-parameters-t-and-pointee-equivalent-this-is-an-error-in-swift-6-warning/62908>\
**Category:** Using Swift\
**Tags:** generics, c, pointers, buffer\
**Created:** [February 2, 2023, 7:33am UTC](https://forums.swift.org/t/same-type-requirement-makes-generic-parameters-t-and-pointee-equivalent-this-is-an-error-in-swift-6-warning/62908 "2023-02-02T07:33:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrAma999](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/drama999/32/12679_2.png) [@DrAma999](https://forums.swift.org/u/DrAma999)\
**Post date:** [February 2, 2023, 7:33am UTC](https://forums.swift.org/t/same-type-requirement-makes-generic-parameters-t-and-pointee-equivalent-this-is-an-error-in-swift-6-warning/62908/1 "2023-02-02T07:33:45Z")

</div>

I had this this extensions that used to work before swift 5.7, now it throws a warning.  
It is used to create a contiguous array from a buffer of C structs.

```swift
extension UnsafeMutablePointer {
   func toContiguousArray<T>(count: Int) -> ContiguousArray<T> where Pointee == T {
        let size = MemoryLayout<T>.size
        let bufferPtr = UnsafeMutablePointer<T>.allocate(capacity: count)
        memcpy(bufferPtr, self, count * size)
        let buffer = UnsafeBufferPointer(start: self, count: count)
        let values = ContiguousArray(buffer)
        defer {
            bufferPtr.deinitialize(count: count)
            bufferPtr.deallocate()
        }
        return values
    }
}

```

If I remove the constraint I get this error:

`Cannot convert return expression of type 'ContiguousArray<Pointee>' to return type 'ContiguousArray<T>'`

Event if I say that the type alias Pointee is equals to T I get the the same error.  
` typealias Pointee = T`  
Which is the correct way to fix that issue?

---

<div class="post-metadata">

**Author:** ![dnadoba](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dnadoba/32/11438_2.png) [@dnadoba](https://forums.swift.org/u/dnadoba)\
**Post date:** [February 2, 2023, 8:31am UTC](https://forums.swift.org/t/same-type-requirement-makes-generic-parameters-t-and-pointee-equivalent-this-is-an-error-in-swift-6-warning/62908/2 "2023-02-02T08:31:01Z")

</div>

You need to remove the generic method parameter `T` completely and just use `Pointee` everywhere you are currently using `T`.

* * *

Looking at the implementing, I think that you probably want to use `stride` instead of `size` to compute the total size of the contiguous storage in memory as stride respects the alignment of the type. If this is the case, we can simplify it quite a bit by just using the appropriate initialiser on UnsafeBufferPointer:

```swift
extension UnsafeMutablePointer {
    func toContiguousArray(count: Int) -> ContiguousArray<Pointee> {
        ContiguousArray(UnsafeBufferPointer(start: self, count: count))
    }
}

```

And as always, it's best to not use anything with `unsafe` in the name but I can't recommend anything else without more context.

---

<div class="post-metadata">

**Author:** ![DrAma999](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/drama999/32/12679_2.png) [@DrAma999](https://forums.swift.org/u/DrAma999)\
**Post date:** [February 2, 2023, 8:36am UTC](https://forums.swift.org/t/same-type-requirement-makes-generic-parameters-t-and-pointee-equivalent-this-is-an-error-in-swift-6-warning/62908/3 "2023-02-02T08:36:42Z")

</div>

OMG, it was so easy, need to rest.  
Thank you!!
