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

Rustdoc should show output of examples #12496

Closed
huonw opened this issue Feb 23, 2014 · 7 comments
Closed

Rustdoc should show output of examples #12496

huonw opened this issue Feb 23, 2014 · 7 comments
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@huonw
Copy link
Member

huonw commented Feb 23, 2014

e.g. std::path has an example that println!'s 3 things, but the user has to copy-paste and then wrap it in fn main() {} to actually see them.

@huonw
Copy link
Member Author

huonw commented Feb 23, 2014

cc @alexcrichton, @cmr

@alexcrichton
Copy link
Member

I'm a little confused, what's an example of what you're thinking about? Are you thinking that you can mouse-over to see the output? Rustdoc should inject the output?

@huonw
Copy link
Member Author

huonw commented Feb 23, 2014

The example on std::path could look something like:


let mut path = Path::new("/tmp/path");
println!("path: {}", path.display());
path.set_filename("foo");
path.push("bar");
println!("new path: {}", path.display());
println!("path exists: {}", path.exists());
Output
path: /tmp/path
new path: /tmp/foo/bar
path exists: false

Mouse-over vs. including it directly etc. can be decided by someone else. There's also been a suggestion of having editable/runnable examples in the tutorial (etc.) using a sandbox similar to the one IRC-rusti has; we could possibly do something similar for docs which would solve this (but then our docs are reliant on a rustc backend to see everything, not standalone).

@brson
Copy link
Contributor

brson commented Feb 26, 2014

There are two separate issues here: one is just making available the output of all examples, and the other is providing a tool with which authors can insert code blocks that contain the output of examples.

@steveklabnik
Copy link
Member

I like linking to the sandbox rather than printing it out.

@emberian
Copy link
Member

I agree, I think the sandbox is a lot more valuable and simple here. Do you agree, @huonw?

@emberian
Copy link
Member

I think the existence of the sandbox and that all code examples now linking to it closes this.

matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this issue Mar 21, 2024
Disable `cast_lossless` when casting to u128 from any (u)int type

Fixes rust-lang/rust-clippy#12492

Disables `cast_lossless` when casting to u128 from any int or uint type. The lint states that when casting to any int type, there can potentially be lossy behaviour if the source type ever exceeds the size of the destination type in the future, which is impossible with a destination of u128.

It's possible this is a bit of a niche edge case which is better addressed by just disabling the lint in code, but I personally couldn't think of any good reason to still lint in this specific case - maybe except if the source is a bool, for readability reasons :).

changelog: FP: `cast_lossless`: disable lint when casting to u128 from any (u)int type
flip1995 pushed a commit to flip1995/rust that referenced this issue Jul 25, 2024
Lint casts to `u128` in `cast_lossless`

Reverts rust-lang#12496 per https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Should.20.60as.20u128.60.20trigger.20cast_lossless

Also changes the lint messages and refactors the suggestion production - Fixes rust-lang#12695

changelog: [`cast_lossless`]: lint casts to `u128`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants