Skip to content
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

Missing self_in_typedefs help message #54563

Closed
leonardo-m opened this issue Sep 25, 2018 · 6 comments
Closed

Missing self_in_typedefs help message #54563

leonardo-m opened this issue Sep 25, 2018 · 6 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@leonardo-m
Copy link

leonardo-m commented Sep 25, 2018

This code compiles with recent Nightly:

#![feature(self_in_typedefs)]
enum Tree { Empty, Node(Box<Self>, i32, Box<Self>) }
fn main() {}

If I remove the feature, on Nightly:

enum Tree { Empty, Node(Box<Self>, i32, Box<Self>) }
fn main() {}

It gives error messages but no suggestion to add the self_in_typedefs feature:

error[E0411]: cannot find type `Self` in this scope
 --> ...\test.rs:1:29
  |
1 | enum Tree { Empty, Node(Box<Self>, i32, Box<Self>) }
  |                             ^^^^ `Self` is only available in traits and impls

error[E0411]: cannot find type `Self` in this scope
 --> ...\test.rs:1:45
  |
1 | enum Tree { Empty, Node(Box<Self>, i32, Box<Self>) }
  |                                             ^^^^ `Self` is only available in traits and impls

error: aborting due to 2 previous errors

For some other features Rustc gives such help:

enum Tree { Empty, Node(Box<Tree>, i32, Box<Tree>) }
fn main() {
    let t = Tree::Node(box Tree::Empty, 0, box Tree::Empty);
}
error[E0658]: box expression syntax is experimental; you can call `Box::new` instead. (see issue #49733)
 --> ...\test.rs:3:24
  |
3 |     let t = Tree::Node(box Tree::Empty, 0, box Tree::Empty);
  |                        ^^^^^^^^^^^^^^^
  |
  = help: add #![feature(box_syntax)] to the crate attributes to enable
@Centril
Copy link
Contributor

Centril commented Sep 25, 2018

cc @alexreg and #49303

@Centril Centril added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 25, 2018
@estebank
Copy link
Contributor

estebank commented Sep 25, 2018

The help needs to be added here

if is_self_type(path, ns) {
__diagnostic_used!(E0411);
err.code(DiagnosticId::Error("E0411".into()));
let available_in = if this.session.features_untracked().self_in_typedefs {
"impls, traits, and type definitions"
} else {
"traits and impls"
};
err.span_label(span, format!("`Self` is only available in {}", available_in));
return (err, Vec::new());

You can see how such a help text was added in the past.

You can also use ::rustc::session::config::nightly_options::is_nightly_build() to only suggest it in nightly builds.

@estebank estebank added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Sep 25, 2018
@alexreg
Copy link
Contributor

alexreg commented Sep 26, 2018

Thanks for the above guidance, @estebank. And sorry I forgot to include this with the initial PR.

Let me add that this is slightly tricky, due to the fact we do not know the context of the Self usage at the point the error is emitted. We have to work it out again. I'll see if I can come up with something.

@alexreg
Copy link
Contributor

alexreg commented Sep 27, 2018

@estebank I noticed there's also tcx.sess.opts.unstable_features.is_nightly_build(). I this any different?

@estebank
Copy link
Contributor

Nope, if that is available use that one. They should both be the same value.

@alexreg
Copy link
Contributor

alexreg commented Sep 27, 2018

Okay sure. We don't have a tcx in this case though, I later realised, so I'll use your original approach! Ready to merge?

kennytm added a commit to kennytm/rust that referenced this issue Sep 29, 2018
…tebank

Added help message for `self_in_typedefs` feature gate

Fixes rust-lang#54563.

CC @Centril @estebank @leonardo-m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

No branches or pull requests

4 participants