1
1
- Start Date: 2015-2-3
2
2
- RFC PR: (leave this empty)
3
3
- Rust Issue: (leave this empty)
4
+ - Feature: ` ascription `
4
5
5
6
# Summary
6
7
@@ -113,6 +114,8 @@ expression are exactly those of the implicit coercion.
113
114
@eddyb has implemented the expressions part of this RFC,
114
115
[ PR] ( https://github.com/rust-lang/rust/pull/21836 ) .
115
116
117
+ This feature should land behind the ` ascription ` feature gate.
118
+
116
119
117
120
### coercion and ` as ` vs ` : `
118
121
@@ -126,23 +129,19 @@ confusing for users, since there is no reason to use type ascription rather than
126
129
as the default whether or not it is required, then it loses its function as a
127
130
warning sign for programmers to beware of.
128
131
129
- To address this I propose three lints which check for: trivial casts, coercible
130
- casts, and trivial numeric casts. Other than these lints we stick with the
131
- proposal from #401 that unnecessary casts will no longer be an error.
132
-
133
- A trivial cast is a cast ` x as T ` where ` x ` has type ` U ` and ` U ` is a subtype of
134
- ` T ` (note that subtyping includes reflexivity).
132
+ To address this I propose two lints which check for: trivial casts and trivial
133
+ numeric casts. Other than these lints we stick with the proposal from #401 that
134
+ unnecessary casts will no longer be an error.
135
135
136
- A coercible cast is a cast ` x as T ` where ` x ` has type ` U ` and ` x ` can be
137
- implicitly coerced to ` T ` , but ` U ` is not a subtype of ` T ` .
136
+ A trivial cast is a cast ` x as T ` where ` x ` has type ` U ` and ` x ` can be
137
+ implicitly coerced to ` T ` or is already a subtype of ` T ` .
138
138
139
139
A trivial numeric cast is a cast ` x as T ` where ` x ` has type ` U ` and ` x ` is
140
140
implicitly coercible to ` T ` or ` U ` is a subtype of ` T ` , and both ` U ` and ` T ` are
141
141
numeric types.
142
142
143
- Like any lints, these can be customised per-crate by the programmer. The trivial
144
- cast lint is 'deny' by default (i.e., causes an error); the coercible cast and
145
- trivial numeric cast lints are 'warn' by default.
143
+ Like any lints, these can be customised per-crate by the programmer. Both lints
144
+ are 'warn' by default.
146
145
147
146
Although this is a somewhat complex scheme, it allows code that works today to
148
147
work with only minor adjustment, it allows for a backwards compatible path to
0 commit comments