Skip to content

Commit 0b3807a

Browse files
committed
go/types, go/importer: importing package unsafe is responsibility of importer
TBR adonovan Fixes #13882. Change-Id: I8664669f5d6adfec6f16e154263b1f0ea8988175 Reviewed-on: https://go-review.googlesource.com/18445 Reviewed-by: Robert Griesemer <[email protected]>
1 parent 1f26864 commit 0b3807a

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

src/go/internal/gcimporter/gcimporter.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,11 @@ func ImportData(packages map[string]*types.Package, filename, id string, data io
112112
// The packages map must contain all packages already imported.
113113
//
114114
func Import(packages map[string]*types.Package, path, srcDir string) (pkg *types.Package, err error) {
115-
// package "unsafe" is handled by the type checker
116-
if path == "unsafe" {
117-
panic(`gcimporter.Import called for package "unsafe"`)
118-
}
119-
120115
filename, id := FindPkg(path, srcDir)
121116
if filename == "" {
117+
if path == "unsafe" {
118+
return types.Unsafe, nil
119+
}
122120
err = fmt.Errorf("can't find import: %s", id)
123121
return
124122
}

src/go/types/api.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ type Config struct {
112112
// error found.
113113
Error func(err error)
114114

115-
// Importer.Import is called for each import declaration except when
116-
// importing package "unsafe". An error is reported if an importer is
117-
// needed but none was installed.
118-
// If the installed Importer implements Importer2, the Import2 method
115+
// An importer is used to import packages referred to from
116+
// import declarations.
117+
// If the installed importer implements Importer2, Import2
119118
// is called instead of Import.
119+
// An error is reported if an importer is needed but none
120+
// was installed.
120121
Importer Importer
121122

122123
// If Sizes != nil, it provides the sizing functions for package unsafe.

src/go/types/resolver.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@ func (check *Checker) collectObjects() {
183183
// TODO(gri) shouldn't create a new one each time
184184
imp = NewPackage("C", "C")
185185
imp.fake = true
186-
} else if path == "unsafe" {
187-
// package "unsafe" is known to the language
188-
imp = Unsafe
189186
} else {
190187
// ordinary import
191188
if importer := check.conf.Importer; importer == nil {

0 commit comments

Comments
 (0)