diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index dfef5c88cf..589ca3a859 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -106,7 +106,7 @@ def _determine_lib_name(name, crate_type, toolchain, lib_hash = None): extension = extension, ) -def get_edition(attr, toolchain): +def get_edition(ctx, toolchain): """Returns the Rust edition from either the current rule's attirbutes or the current `rust_toolchain` Args: @@ -116,8 +116,10 @@ def get_edition(attr, toolchain): Returns: str: The target Rust edition """ - if getattr(attr, "edition"): - return attr.edition + if getattr(ctx.attr, "edition"): + return ctx.attr.edition + elif toolchain.default_edition == "required": + fail("Attribute `edition` is required for {}.".format(ctx.label)) else: return toolchain.default_edition @@ -280,7 +282,7 @@ def _rust_library_common(ctx, crate_type): proc_macro_deps = depset(proc_macro_deps), aliases = ctx.attr.aliases, output = rust_lib, - edition = get_edition(ctx.attr, toolchain), + edition = get_edition(ctx, toolchain), rustc_env = ctx.attr.rustc_env, is_test = False, compile_data = depset(ctx.files.compile_data), @@ -320,7 +322,7 @@ def _rust_binary_impl(ctx): proc_macro_deps = depset(proc_macro_deps), aliases = ctx.attr.aliases, output = output, - edition = get_edition(ctx.attr, toolchain), + edition = get_edition(ctx, toolchain), rustc_env = ctx.attr.rustc_env, is_test = False, compile_data = depset(ctx.files.compile_data), @@ -386,7 +388,7 @@ def _rust_test_common(ctx, toolchain, output): proc_macro_deps = depset(proc_macro_deps), aliases = ctx.attr.aliases, output = output, - edition = get_edition(ctx.attr, toolchain), + edition = get_edition(ctx, toolchain), rustc_env = ctx.attr.rustc_env, is_test = True, compile_data = depset(ctx.files.compile_data),