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

Fix documentation for base64 #9386

Closed
wants to merge 1 commit into from
Closed

Conversation

Geal
Copy link
Contributor

@Geal Geal commented Sep 21, 2013

Standard is now uppercase in the base64 module, and from_base64 now returns a Result

* printfln!("%s", result_str);
* let res = hello_str.from_base64();
* match res {
* Err(e) => println("could not decode base64: " + e);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that this will compile either because of the ; at the end

@Geal
Copy link
Contributor Author

Geal commented Sep 21, 2013

I also changed to from_utf8_opt, to prevent the condition from being raised, just to make the code more precise. I'm just beginning to learn Rust, and explicit examples are useful.

@adrientetar
Copy link
Contributor

I think he was referring to println! (the macro).

@alexcrichton
Copy link
Member

Yeah sadly it seems now that the example shows off less functionality :(. Also, @adridu59 is correct in that I was just wondering about moving from printfln! to println! as an example macro to call. It would be nice to still see some usage of from_base64 though.

@Geal
Copy link
Contributor Author

Geal commented Sep 22, 2013

Oh, I was not aware of that macro. Where is it defined?

I think I'll replace the pattern matching by is_ok and is_none, that would make it easier to read.

@huonw
Copy link
Member

huonw commented Sep 22, 2013

@Geal it's defined in syntax::ext::expand, but it's documented under std::fmt (that link may move to not have the /ng soon).

@emberian
Copy link
Member

@Geal: mind rebasing this to use

```rust
 ....
```

Rather than the tildes? Our doc syntax is changing, there's a PR to change it.

@alexcrichton
Copy link
Member

Needs a rebase against master. Also, would you mind squashing into just one commit? Thanks!

@Geal
Copy link
Contributor Author

Geal commented Oct 9, 2013

Here it is, rebased and squashed.

* println!("{:?}", bytes);
* let result_str = str::from_utf8(bytes);
* println!("{}", result_str);
* let hello_str = "Hello, World".to_base64(STANDARD);
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this still doesn't compile, to_base64 is only defined for &[u8], not &str. Perhaps this should use the bytes! macro to create an example?

@Geal
Copy link
Contributor Author

Geal commented Oct 9, 2013

hum, disregard that last patch, it uses into_bytes, I'll send another using the bytes! macro

@Geal
Copy link
Contributor Author

Geal commented Oct 9, 2013

that one should be ok. BTW, how can I grep for a macro like bytes? I tried using macro_rules, but did not find it.

@alexcrichton
Copy link
Member

It's actually a built-in syntax extension inside of ext/base.rs, so there's no corresponding macro_rules! defining it.

@Geal
Copy link
Contributor Author

Geal commented Oct 9, 2013

Ok. Is there a part of the documentation adressing those types of macro?
When I code, I always refer to the std and extra docs, that would be useful
to have the same for syntax tweaks.
Le 9 oct. 2013 18:45, "Alex Crichton" notifications@github.com a écrit :

It's actually a built-in syntax extension inside of ext/base.rs, so
there's no corresponding macro_rules! defining it.


Reply to this email directly or view it on GitHubhttps://github.com//pull/9386#issuecomment-25987258
.

@alexcrichton
Copy link
Member

There will be soon hopefully! We've recently started allowing attributes on macros, and the next step is to make a snapshot and then make "dummy versions" of all these macros inside libstd so they can all get documented. After that we need to surface them in rustdoc as well.

Basically, not yet, but soon!

bors added a commit that referenced this pull request Oct 9, 2013
Standard is now uppercase in the base64 module, and from_base64 now returns a Result
@bors bors closed this Oct 9, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 20, 2022
…ow, r=Jarcho

Further enhance `needless_borrow`, mildly refactor `redundant_clone`

This PR does the following:
* Moves some code from `redundant_clone` into a new `clippy_utils` module called `mir`, and wraps that code in a function called `dropped_without_further_use`.
* Relaxes the "is copyable" condition condition from rust-lang#9136 by also suggesting to remove borrows from values dropped without further use. The changes involve the just mentioned function.
* Separates `redundant_clone` into modules.

Strictly speaking, the last bullet is independent of the others. `redundant_clone` is somewhat hairy, IMO. Separating it into modules makes it slightly less so, by helping to delineate what depends upon what.

I've tried to break everything up into digestible commits.

r? `@Jarcho`

(`@Jarcho` I hope you don't mind.)

changelog: continuation of rust-lang#9136
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 21, 2022
Fix bug introduced by rust-lang#9386

rust-lang#9386 introduced a potential out-of-bounds array access. Specifically, a location returned by `local_assignments` could have  [`location.statement_index` equal to `mir.basic_blocks[location.block].statements.len()`](https://github.com/rust-lang/rust-clippy/blob/b8a9a507bf9e3149d287841454842116c72d66c4/clippy_utils/src/mir/mod.rs#L129), in which case the location would refer to the block terminator:
https://github.com/rust-lang/rust-clippy/blob/b8a9a507bf9e3149d287841454842116c72d66c4/clippy_lints/src/dereference.rs#L1204-L1206
I suspect the bug is not triggerable now, because of checks leading up to where it occurs. But a future code change could make it triggerable. Hence, it should be fixed.

r? `@Jarcho`

changelog: none
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.

6 participants