compiler: allow //go:embed in files underscore-importing embed
authorMichael Matloob <matloob@golang.org>
Tue, 2 Mar 2021 00:02:38 +0000 (19:02 -0500)
committerIan Lance Taylor <iant@golang.org>
Tue, 2 Mar 2021 22:03:26 +0000 (14:03 -0800)
commitd1776b7757001d9da47efcfd64d3bb20afb8d96d
treed7997fb88b53789753c231a10b79dceb040df38e
parentdf003d1e0bf2d0a8e2ed45a323d4e974b15dc95f
compiler: allow //go:embed in files underscore-importing embed

The embed spec allows for //go:embed to be used in files that
underscore-import package "embed". This is useful for embeds to
[]byte and string vars because the embed.FS type may not be referenced
if those are the only types of embeds in a file. Because the compiler
previously checked whether there were any aliases to the embed
package to decide if //go:embed could be used, it would reject
files with only underscore imports of embed. Instead, record
whether the embed import is encountered at all, similar to what
is done with unsafe, to decide whether //go:embed is allowed.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/297553
gcc/go/gofrontend/MERGE
gcc/go/gofrontend/embed.cc
gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/gogo.h
gcc/go/gofrontend/parse.cc