@@ -106,18 +106,21 @@ def _determine_lib_name(name, crate_type, toolchain, lib_hash = None):
106
106
extension = extension ,
107
107
)
108
108
109
- def get_edition (attr , toolchain ):
109
+ def get_edition (attr , toolchain , label ):
110
110
"""Returns the Rust edition from either the current rule's attirbutes or the current `rust_toolchain`
111
111
112
112
Args:
113
113
attr (struct): The current rule's attributes
114
114
toolchain (rust_toolchain): The `rust_toolchain` for the current target
115
+ label (Label): The label of the target being built
115
116
116
117
Returns:
117
118
str: The target Rust edition
118
119
"""
119
120
if getattr (attr , "edition" ):
120
121
return attr .edition
122
+ elif toolchain .default_edition == "required" :
123
+ fail ("Attribute `edition` is required for {}." .format (label ))
121
124
else :
122
125
return toolchain .default_edition
123
126
@@ -280,7 +283,7 @@ def _rust_library_common(ctx, crate_type):
280
283
proc_macro_deps = depset (proc_macro_deps ),
281
284
aliases = ctx .attr .aliases ,
282
285
output = rust_lib ,
283
- edition = get_edition (ctx .attr , toolchain ),
286
+ edition = get_edition (ctx .attr , toolchain , ctx . label ),
284
287
rustc_env = ctx .attr .rustc_env ,
285
288
is_test = False ,
286
289
compile_data = depset (ctx .files .compile_data ),
@@ -320,7 +323,7 @@ def _rust_binary_impl(ctx):
320
323
proc_macro_deps = depset (proc_macro_deps ),
321
324
aliases = ctx .attr .aliases ,
322
325
output = output ,
323
- edition = get_edition (ctx .attr , toolchain ),
326
+ edition = get_edition (ctx .attr , toolchain , ctx . label ),
324
327
rustc_env = ctx .attr .rustc_env ,
325
328
is_test = False ,
326
329
compile_data = depset (ctx .files .compile_data ),
@@ -386,7 +389,7 @@ def _rust_test_common(ctx, toolchain, output):
386
389
proc_macro_deps = depset (proc_macro_deps ),
387
390
aliases = ctx .attr .aliases ,
388
391
output = output ,
389
- edition = get_edition (ctx .attr , toolchain ),
392
+ edition = get_edition (ctx .attr , toolchain , ctx . label ),
390
393
rustc_env = ctx .attr .rustc_env ,
391
394
is_test = True ,
392
395
compile_data = depset (ctx .files .compile_data ),
0 commit comments