diff --git a/refactor/rename/mvpkg.go b/refactor/rename/mvpkg.go index bf8edd6f5a..e31166da81 100644 --- a/refactor/rename/mvpkg.go +++ b/refactor/rename/mvpkg.go @@ -244,9 +244,7 @@ func (m *mover) move() error { // None of the subpackages will change their name---only the from package // itself will. for p := range m.rev[m.from] { - _, err := importName( - m.iprog, m.iprog.Imported[p], m.from, path.Base(m.from), newName) - if err != nil { + if err := importName(m.iprog, m.iprog.Imported[p], m.from, path.Base(m.from), newName); err != nil { return err } } diff --git a/refactor/rename/rename.go b/refactor/rename/rename.go index d37f5b0043..18a3219477 100644 --- a/refactor/rename/rename.go +++ b/refactor/rename/rename.go @@ -164,10 +164,9 @@ var reportError = func(posn token.Position, message string) { // importName renames imports of the package with the given path in // the given package. If fromName is not empty, only imports as -// fromName will be renamed. Even if renaming is successful, there -// may be some files that are unchanged; they are reported in -// unchangedFiles. -func importName(iprog *loader.Program, info *loader.PackageInfo, fromPath, fromName, to string) (unchangedFiles []string, err error) { +// fromName will be renamed. If the renaming would lead to a conflict, +// the file is left unchanged. +func importName(iprog *loader.Program, info *loader.PackageInfo, fromPath, fromName, to string) error { for _, f := range info.Files { var from types.Object for _, imp := range f.Imports { @@ -193,13 +192,12 @@ func importName(iprog *loader.Program, info *loader.PackageInfo, fromPath, fromN r.check(from) if r.hadConflicts { continue // ignore errors; leave the existing name - unchangedFiles = append(unchangedFiles, f.Name.Name) } if err := r.update(); err != nil { - return nil, err + return err } } - return unchangedFiles, nil + return nil } func Main(ctxt *build.Context, offsetFlag, fromFlag, to string) error {