Skip to content

Add E0400 error explanation #30167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,50 @@ contain references (with a maximum lifetime of `'a`).
[1]: https://github.com/rust-lang/rfcs/pull/1156
"##,

E0400: r##"
A user-defined dereference was attempted in an invalid context. Erroneous
code example:

```
use std::ops::Deref;

struct A;

impl Deref for A {
type Target = str;

fn deref(&self)-> &str { "foo" }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't change the code.

When I say that it should be moved inline, I mean directly writing *A in the code where S was going to be used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you're asking in here.

const S: &'static str = &A;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you meant *A?

// error: user-defined dereference operators are not allowed in constants

fn main() {
let foo = S;
}
```

You cannot directly use a dereference operation whilst initializing a constant
or a static. To fix this error, restructure your code to avoid this dereference,
perharps moving it inline:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I arrived a little too late to point out the spelling error: "perharps" before bors started its run...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I'll fix it next error explanation I create. :)


```
use std::ops::Deref;

struct A;

impl Deref for A {
type Target = str;

fn deref(&self)-> &str { "foo" }
}

fn main() {
let foo : &str = &A;
}
```
"##,

E0492: r##"
A borrow of a constant containing interior mutability was attempted. Erroneous
code example:
Expand Down Expand Up @@ -2175,7 +2219,6 @@ register_diagnostics! {
E0314, // closure outlives stack frame
E0315, // cannot invoke closure outside of its lifetime
E0316, // nested quantification of lifetimes
E0400, // overloaded derefs are not allowed in constants
E0452, // malformed lint attribute
E0453, // overruled by outer forbid
E0471, // constant evaluation error: ..
Expand Down