Add doc comment to hiding portions of code example#50852
Add doc comment to hiding portions of code example#50852bors merged 2 commits intorust-lang:masterfrom
Conversation
|
(rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Why is there a println!?
There was a problem hiding this comment.
yes, r=me with this line removed :)
There was a problem hiding this comment.
yes, r=me with this line removed :)
|
The foo function is there to show how to hide code. I wanted to add the println to show how normal code would look like in addition to hidden code. |
|
Then you definitely need to update the next code example as well. But that seems really strange. Why would you put a doc comment on a hidden function? Doesn't make sense to me... |
Refactor hiding example to be more complete
440944b to
8d74cf8
Compare
|
The PR attempts to show users that one needs doc comments on all of their example code so that they don't write something like the following: /// # Examples
/// /// Some documentation
# fn foo() {}
/// println("Hi");
|
|
@mandeep that makes sense, but I'd prefer the examples to have actual syntax, then. You need curlies, for example. |
|
@steveklabnik Are curly braces needed somewhere besides the foo function? |
|
I discussed this on IRC and there may have been confusion with my example in my comment that contains code. I've updated the example to match the commit of the PR. |
|
I have to admit that I still don't understand at all why there is a doc comment on a hidden function in an example. Or even why there is a doc comment in an example... |
|
Ping from triage! What's the status on this? |
|
@GuillaumeGomez maybe an example will help: /// Find the barycentric coordinates of the given point with respect to the given triangle
///
/// # Examples
///
/// ```
/// let points = vec![Vector3::new(0, 0, 0), Vector3::new(2, 2, 2), Vector3::new(0, 2, 2)]
/// let point = Point3::new(1.0, 1.0, 0.0);
/// let barycentric_coordinates: Point3<f64> = find_barycentric(&points, &point);
/// ```
///
fn find_barycentric(points: &Vec<Point3<f64>>, point: &Point3<f64>) -> Point3<f64> {
let u = Vector3::new(points[2].x - points[0].x, points[1].x - points[0].x, points[0].x - point.x);
let v = Vector3::new(points[2].y - points[0].y, points[1].y - points[0].y, points[0].y - point.y);
let w = u.cross(&v);
if (w.z).abs() < 1.0 {
return Point3::new(-1.0, 1.0, 1.0);
} else {
return Point3::new(1.0 - (w.x + w.y) as f64 / w.z as f64, w.y as f64 / w.z as f64, w.x as f64 / w.z as f64);
}
}As for the hidden function, the docs being changed have a full example of hidden functions: https://doc.rust-lang.org/rustdoc/documentation-tests.html#hiding-portions-of-the-example |
|
I still don't get it. :-/ |
|
The use case is not immediately apparent, but since this omission is causing problems I think we need to add this commit. If you think more information is needed, let me know and I'd be happy to add more. |
|
Ok, then let's just move forward. @bors: r+ rollup |
|
📌 Commit 8d74cf8 has been approved by |
…, r=GuillaumeGomez Add doc comment to hiding portions of code example fixes rust-lang#50816 Not sure if this is all that's needed, but I think it's a good start. One thing to note is that the code block is a text block where it could possibly be a rust block.
Rollup of 7 pull requests Successful merges: - #50852 (Add doc comment to hiding portions of code example) - #51183 (Update rustdoc book to suggest using Termination trait instead of hidden ‘foo’ function) - #51255 (Fix confusing error message for sub_instant) - #51256 (Fix crate-name option in rustdoc) - #51308 (Check array indices in constant propagation) - #51343 (test: Ignore some problematic tests on sparc and sparc64) - #51358 (Tests that #39963 is fixed on MIR borrowck) Failed merges:
fixes #50816
Not sure if this is all that's needed, but I think it's a good start. One thing to note is that the code block is a text block where it could possibly be a rust block.