File tree Expand file tree Collapse file tree 1 file changed +44
-1
lines changed Expand file tree Collapse file tree 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`).
18991899[1]: https://github.com/rust-lang/rfcs/pull/1156
19001900"## ,
19011901
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+
19021946E0492 : r##"
19031947A borrow of a constant containing interior mutability was attempted. Erroneous
19041948code example:
@@ -2175,7 +2219,6 @@ register_diagnostics! {
21752219 E0314 , // closure outlives stack frame
21762220 E0315 , // cannot invoke closure outside of its lifetime
21772221 E0316 , // nested quantification of lifetimes
2178- E0400 , // overloaded derefs are not allowed in constants
21792222 E0452 , // malformed lint attribute
21802223 E0453 , // overruled by outer forbid
21812224 E0471 , // constant evaluation error: ..
You can’t perform that action at this time.
0 commit comments