Skip to content

Commit c2e510b

Browse files
committed
Recognize edition = "required" idiom
1 parent 965044a commit c2e510b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

rust/private/rust.bzl

+7-4
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,21 @@ def _determine_lib_name(name, crate_type, toolchain, lib_hash = None):
106106
extension = extension,
107107
)
108108

109-
def get_edition(attr, toolchain):
109+
def get_edition(attr, toolchain, label):
110110
"""Returns the Rust edition from either the current rule's attirbutes or the current `rust_toolchain`
111111
112112
Args:
113113
attr (struct): The current rule's attributes
114114
toolchain (rust_toolchain): The `rust_toolchain` for the current target
115+
label (Label): The label of the target being built
115116
116117
Returns:
117118
str: The target Rust edition
118119
"""
119120
if getattr(attr, "edition"):
120121
return attr.edition
122+
elif toolchain.default_edition == "required":
123+
fail("Attribute `edition` is required for {}.".format(label))
121124
else:
122125
return toolchain.default_edition
123126

@@ -280,7 +283,7 @@ def _rust_library_common(ctx, crate_type):
280283
proc_macro_deps = depset(proc_macro_deps),
281284
aliases = ctx.attr.aliases,
282285
output = rust_lib,
283-
edition = get_edition(ctx.attr, toolchain),
286+
edition = get_edition(ctx.attr, toolchain, ctx.label),
284287
rustc_env = ctx.attr.rustc_env,
285288
is_test = False,
286289
compile_data = depset(ctx.files.compile_data),
@@ -320,7 +323,7 @@ def _rust_binary_impl(ctx):
320323
proc_macro_deps = depset(proc_macro_deps),
321324
aliases = ctx.attr.aliases,
322325
output = output,
323-
edition = get_edition(ctx.attr, toolchain),
326+
edition = get_edition(ctx.attr, toolchain, ctx.label),
324327
rustc_env = ctx.attr.rustc_env,
325328
is_test = False,
326329
compile_data = depset(ctx.files.compile_data),
@@ -386,7 +389,7 @@ def _rust_test_common(ctx, toolchain, output):
386389
proc_macro_deps = depset(proc_macro_deps),
387390
aliases = ctx.attr.aliases,
388391
output = output,
389-
edition = get_edition(ctx.attr, toolchain),
392+
edition = get_edition(ctx.attr, toolchain, ctx.label),
390393
rustc_env = ctx.attr.rustc_env,
391394
is_test = True,
392395
compile_data = depset(ctx.files.compile_data),

0 commit comments

Comments
 (0)