File tree 1 file changed +44
-1
lines changed
1 file changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -1899,6 +1899,50 @@ contain references (with a maximum lifetime of `'a`).
1899
1899
[1]: https://github.com/rust-lang/rfcs/pull/1156
1900
1900
"## ,
1901
1901
1902
+ E0400 : r##"
1903
+ A user-defined dereference was attempted in an invalid context. Erroneous
1904
+ code example:
1905
+
1906
+ ```
1907
+ use std::ops::Deref;
1908
+
1909
+ struct A;
1910
+
1911
+ impl Deref for A {
1912
+ type Target = str;
1913
+
1914
+ fn deref(&self)-> &str { "foo" }
1915
+ }
1916
+
1917
+ const S: &'static str = &A;
1918
+ // error: user-defined dereference operators are not allowed in constants
1919
+
1920
+ fn main() {
1921
+ let foo = S;
1922
+ }
1923
+ ```
1924
+
1925
+ You cannot directly use a dereference operation whilst initializing a constant
1926
+ or a static. To fix this error, restructure your code to avoid this dereference,
1927
+ perharps moving it inline:
1928
+
1929
+ ```
1930
+ use std::ops::Deref;
1931
+
1932
+ struct A;
1933
+
1934
+ impl Deref for A {
1935
+ type Target = str;
1936
+
1937
+ fn deref(&self)-> &str { "foo" }
1938
+ }
1939
+
1940
+ fn main() {
1941
+ let foo : &str = &A;
1942
+ }
1943
+ ```
1944
+ "## ,
1945
+
1902
1946
E0492 : r##"
1903
1947
A borrow of a constant containing interior mutability was attempted. Erroneous
1904
1948
code example:
@@ -2175,7 +2219,6 @@ register_diagnostics! {
2175
2219
E0314 , // closure outlives stack frame
2176
2220
E0315 , // cannot invoke closure outside of its lifetime
2177
2221
E0316 , // nested quantification of lifetimes
2178
- E0400 , // overloaded derefs are not allowed in constants
2179
2222
E0452 , // malformed lint attribute
2180
2223
E0453 , // overruled by outer forbid
2181
2224
E0471 , // constant evaluation error: ..
You can’t perform that action at this time.
0 commit comments