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

Change handling of doc comments to warn when mis-parsed, not error. #2789

Closed
brson opened this issue Jul 3, 2012 · 18 comments
Closed

Change handling of doc comments to warn when mis-parsed, not error. #2789

brson opened this issue Jul 3, 2012 · 18 comments
Assignees
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-parser Area: The parsing of Rust source code to an AST E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@brson
Copy link
Contributor

brson commented Jul 3, 2012

Now that we've implemented doc comments as attributes I am doubtful that it was the correct thing to do. There are a lot of positions where attributes aren't valid and now the parser rejects things like:

let x = y; //// xy

I was planning putting some smarts into the lexer to detect four slashes and not consider those doc attributes, but then patrick checked in some code like ///< comment which was rejected.

Comments not being treated as whitespace is weird.

@brson
Copy link
Contributor Author

brson commented Jul 3, 2012

On second thought, I kind of want to see how the current arrangement works before changing it. There is some amount of value in catching incorrect doc comments, which is sort of what happened with the ///< comment.

@brson
Copy link
Contributor Author

brson commented Jul 6, 2012

I've run into another case where sections were formatted like /****** Some Stuff ******/. It failed to compile with an error that wouldn't lead you to expect that the comment was incorrect.

@catamorphism
Copy link
Contributor

Nominating for "maturity #4 - well covered"

@graydon
Copy link
Contributor

graydon commented Apr 23, 2013

It represents a potential backwards incompatibility, so belongs on the backward compatible maturity milestone (or closed as wontfix)

@emberian
Copy link
Member

I don't see how this could be a backwards incompatibility. Fixing the error to be better is no problem and allowing this behavior wouldn't break any valid code.

Nominating for production ready.

@emberian
Copy link
Member

Example errors:

foo.rs:6:24: 7:0 error: expected item after attributes
foo.rs:6     let x = Foo{x: 5u}; /// bar
foo.rs:7 }
foo.rs:5:0: 6:0 error: expected item after attributes
foo.rs:5 /****** Some Stuff ******/
foo.rs:6     let x = Foo{x: 5u};

Which honestly isn't that bad but it's not good either.

@huonw
Copy link
Member

huonw commented Aug 19, 2013

Triage visit; all the examples reproduce.

I'm absorbing #4106 into this bug (#4106 has a lot of historical discussion).

@pzol
Copy link
Contributor

pzol commented Feb 26, 2014

Visiting for triage, still broken.

@mikedilger
Copy link
Contributor

First off, I LOVE you guys and am so glad rust is happening. But I'm frustrated today about this issue. I'm still very new to rust, and it took me hours to figure out the problem, mostly because the error message I get is very misdirecting:

  mymod.js:6:3: 6:4 error: an inner attribute is not permitted in this context
  mymod.js:6 #![feature(phase)]

I strongly recommend a better error message, if at all possible, so you don't lose new people to the community.

My code was something like this:

/**
 * My mod
 */

// For log related macros:
#![feature(phase)]
#[phase(syntax, link)] extern crate log;

fn main() {
  error!("We have logging!");
}

iliekturtles added a commit to iliekturtles/rust that referenced this issue Sep 20, 2014
Display an explicit message about items missing after sugared doc
comment attributes. References rust-lang#2789.
bors added a commit that referenced this issue Sep 20, 2014
…huonw

Display an explicit message about items missing after sugared doc
comment attributes. References #2789.

 * I tried looking through `parser.rs` for an appropriate location for `expected_item_err` and ended up putting it just above the first use. Is there a better location?
 * Did I add enough test cases? Too many? Should I add more cases for the original error message?
@caipre
Copy link
Contributor

caipre commented Sep 22, 2014

I'll take a look at this.

@Manishearth
Copy link
Member

What if we conditionally convert them to attributes if they are correct, else leave them as a comment and throw a warning?

@carols10cents
Copy link
Member

(Hi, I'm trying to help make E-easy issues more accessible to newcomers 😸)

Checking reproducibility:

<anon>:3:16: 3:33 error: expected item after doc comment
<anon>:3     let x = 3; /// three slashes
                        ^~~~~~~~~~~~~~~~~

which seems clearer than the "expected item after attributes" error, so I think this is fixed

<anon>:6:3: 6:4 error: an inner attribute is not permitted in this context
<anon>:6 #![feature(phase)]
           ^
<anon>:6:3: 6:4 help: place inner attribute at the top of the module or block
error: aborting due to previous error

I'm not totally convinced this is the same problem as the others though... but maybe it is? A smaller example:

/**
 * If you remove this comment, the compiler error will go away.
 * It's not very clear from the error message what the problem is.
 */

#![feature(phase)]
fn main() {
    println!("hi");
}

From #4106:

So it looks like there are still some less-than-ideal cases, and that the fix would be a better error message indicating that there was a doc comment in an unsupported location? Is that correct?

If so, where would one start looking to go about making the error message better for the remaining cases?

@Manishearth
Copy link
Member

Thanks! 😄

@Manishearth
Copy link
Member

and that the fix would be a better error message indicating that there was a doc comment in an unsupported location? Is that correct?

Yes. We basically want to add a note around https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/parser.rs#L3415

It would be even better if these were parsed correctly, but that's not an easy fix.

@Manishearth Manishearth added the E-help-wanted Call for participation: Help is requested to fix this issue. label Nov 20, 2015
@wafflespeanut
Copy link
Contributor

I'll try this! :)

@Manishearth Manishearth self-assigned this Nov 20, 2015
@Manishearth Manishearth removed the E-help-wanted Call for participation: Help is requested to fix this issue. label Feb 29, 2016
@cflewis
Copy link

cflewis commented May 18, 2016

Should this be closed?

@mikedilger
Copy link
Contributor

My comment above is still applicable, 2 years on. If it has been determined to be a separate issue, I can file it separately. Otherwise I think this should stay open.

@brson
Copy link
Contributor Author

brson commented Jun 28, 2016

I've opened a new issue specifically to deal with @mikedilger's issue: #34516

@brson brson closed this as completed Jun 28, 2016
RalfJung pushed a commit to RalfJung/rust that referenced this issue Feb 26, 2023
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Deprecate kani::slice::any_slice in Kani 0.38.0 (and the related AnySlice struct), and remove it in a later version.

Motivation: The Kani library's `slice::any_slice` API is doing more harm than benefit: it is meant to provide a convenient way for users to generate non-deterministic slices, but its current implementation aims to avoid any unsoundness by making sure that for the non-deterministic slice returned by the API, accessing memory beyond the slice length is flagged as an out-of-bounds access (see rust-lang#1009 for details). However, in practical scenarios, using it ends up causing memory to blowup for CBMC. Given that users may not care about this type of unsoundness, which is only possible through using a pointer dereference inside an unsafe block (see discussion in rust-lang#2634). Thus, we should leave it to the user to decide the suitable method for generating slices that fits their verification needs. For example, they can use Kani's alternative API, `any_slice_of_array` that extracts a slice of a non-deterministic start and end from a given array.
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
…-lang#2860)

Kani's `any_slice` function (and related code) has been deprecated since
Kani 0.38.0 (see rust-lang#2789). This PR officially obsoletes it by deleting the
code.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-parser Area: The parsing of Rust source code to an AST E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.