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

add puts() to libstd and the prelude #9361

Closed
wants to merge 2 commits into from
Closed

add puts() to libstd and the prelude #9361

wants to merge 2 commits into from

Conversation

flo-l
Copy link
Contributor

@flo-l flo-l commented Sep 20, 2013

I don't know if you want this function in the stdlib, but in my opinion it's a very useful little helper! ;)

It works, as stated in the code, like the puts method in ruby, except for the fact that it only takes one object as parameter and not a variable number of objects.

@@ -39,7 +39,7 @@ pub use option::{Option, Some, None};
pub use result::{Result, Ok, Err};

// Reexported functions
pub use io::{print, println};
pub use io::{print, println,puts};
Copy link
Member

Choose a reason for hiding this comment

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

This should be , puts with a space.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, I'll fix it ;)

@huonw
Copy link
Member

huonw commented Sep 20, 2013

Hi, thanks for the PR, but I think there are a few problems:

  • ToStr is being phased out: it always allocates a string (and possibly several, if it has to call to_str on subfields), which is highly suboptimal when one is just dumping that string straight to the OS io routines. This is resolved by the new traits in std::fmt, which "print" straight to a Writer (e.g. write the output straight to stdout).
  • This doesn't offer much over println!("{}", x) or println!("{:?}", x) for more debugging oriented output.

In summary, if this was rewritten to use the std::fmt::Default trait and println!("{}", input) it would have a much higher chance of being accepted, but, even then, it's very likely that it wouldn't accepted.

@flo-l
Copy link
Contributor Author

flo-l commented Sep 20, 2013

hmm ok, so I'll rewrite this (shouldn't be a lot of work) and we'll see ;)

I wanted to create some sort of shortcut for printing an object, without the .to_str() all the time ;)

@bstrie
Copy link
Contributor

bstrie commented Sep 20, 2013

@flo-l There might be a different way to do this than requiring a new function.

The following code works today:

printfln!(1);

However, printfln! is being replaced by println! (which uses the new, more efficient string formatting system), and it looks like nobody has yet duplicated this exact behavior for println!.

@bstrie
Copy link
Contributor

bstrie commented Sep 20, 2013

Also, there are vague plans to make it so that writing .to_str() all the time isn't necessary, by adding more magic to the format! macro. Not sure about the current status of those.

The point is, we feel your pain. :)

@flo-l
Copy link
Contributor Author

flo-l commented Sep 20, 2013

ok, this sounds great ;) but I'm afraid I don't know enough about the new string formatting system, can you give me a hint where I have to look for information?

@flo-l flo-l closed this Sep 20, 2013
Jarcho pushed a commit to Jarcho/rust that referenced this pull request Aug 29, 2022
Jarcho pushed a commit to Jarcho/rust that referenced this pull request Aug 29, 2022
Don't lint `needless_return` if `return` has attrs

Fixes rust-lang#9361

The lint used to have a mechanic to allow `cfg`-attrs on naked `return`-statements. This was well-intentioned, yet we can have any kind of attribute, e.g. `allow`, `expect` or even custom `derive`. So the mechanic was simply removed. We now never lint on a naked `return`-statement that has attributes on it.

Turns out that the ui-test had a Catch22 in it: In `check_expect()` the `#[expect(clippy::needless_return)]` is an attribute on the `return` statement that can and will be rustfixed away without side effects. But any other attribute would also have been removed, which is what rust-lang#9361 is about. The test proved the wrong thing. Removed the test, the body is tested elsewhere as well.

changelog: Ignore [`needless_return`] on `return`s with attrs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants