6
6
# Summary
7
7
[ summary ] : #summary
8
8
9
- Starting in Rust 2024, stop allowing items inside functions or expressions to
9
+ Add a warn-by-default lint for items inside functions or expressions that
10
10
implement methods or traits that are visible outside the function or
11
- expression.
11
+ expression. Consider ramping that lint to deny-by-default for Rust 2024, and
12
+ evaluating a hard error for 2027.
12
13
13
14
# Motivation
14
15
[ motivation ] : #motivation
@@ -21,9 +22,10 @@ not cross-reference those definitions at all.
21
22
Humans cross-referencing such uses and definitions may find themselves
22
23
similarly baffled.
23
24
24
- With this change, both humans and tools can limit the scope of their search and
25
- avoid looking for definitions inside other functions or items, without missing
26
- any relevant definitions.
25
+ This change helps humans limit the scope of their search and avoid looking for
26
+ definitions inside other functions or items, without missing any relevant
27
+ definitions. If in the future we manage to forbid it entirely within a
28
+ subsequent Rust edtion, tools will be able to rely on this as well.
27
29
28
30
# Explanation
29
31
[ explanation ] : #explanation
@@ -35,7 +37,7 @@ expressions, including the definitions of other items:
35
37
- The values assigned to ` static ` /` const ` items
36
38
- The discriminant values assigned to ` enum ` variants
37
39
38
- Starting in the Rust 2024 edition :
40
+ Rust will emit a warn-by-default lint for all of the following cases :
39
41
- An item nested inside an expression-containing item (through any level of
40
42
nesting) may not define an ` impl Type ` block unless the ` Type ` is also nested
41
43
inside the same expression-containing item.
@@ -46,8 +48,9 @@ Starting in the Rust 2024 edition:
46
48
nesting) may not define an exported macro visible outside the
47
49
expression-containing item (e.g. using ` #[macro_export] ` ).
48
50
49
- Rust 2015, 2018, and 2021 continue to permit this, but will produce a
50
- warn-by-default lint.
51
+ In a future edition, we may consider making this lint deny-by-default, or
52
+ eventually making it a hard error. We'll evaluate the impact on the ecosystem
53
+ and existing use cases before doing so.
51
54
52
55
# Drawbacks
53
56
[ drawbacks ] : #drawbacks
0 commit comments