Go-vet acts wired

When copying the struct with sync.Mutex, Vet is throwing warning as expected.But when I use the method instead of direct copy, It didn’t throw warning.(toggle the lines to see the behaviors)

// You can edit this code!
// Click here and start typing.
package main

import “fmt”
import “sync”

type person struct {
Name string
initMu sync.Mutex
}
type college struct {
student *person
}

type school struct {
student person
}

func (c *college) getPerson() *person{
return c.student
}

func main() {
name := “student1”
a := person{ Name : name}
col := college { student : &a }

school := school{}

//toggle below two lines	
school.student = *col.student
//school.student = *col.getPerson()

fmt.Println(school.student.Name)
fmt.Printf("%p\n", &a)
fmt.Printf("%p\n", col.student)
fmt.Printf("%p\n", col.getPerson())
fmt.Printf("%p\n", &school.student)

col.student.Name = "student2"
fmt.Println(school.student.Name)

}

I guess vet cannot see the copy through the function call. Sounds to me like either a bug or a new feature to add checking for that. I would recommend submitting an issue.

thanks for clarification, I like to copy the values from one struct(which has sync.mutex) to another one without vet warning.How can we do that?

You have to manually copy all the fields except for the mutex manually. In your example, just copy the Name field. If you have lots of fields where that becomes a problem, I’d be interested to know why you’re copying the struct.