Skip to content

Commit 976dd25

Browse files
authored
Auto merge of #34358 - Manishearth:rollup, r=Manishearth
Rollup of 4 pull requests - Successful merges: #34313, #34335, #34340, #34356 - Failed merges:
2 parents 5522e67 + e3740b3 commit 976dd25

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

src/doc/book/compiler-plugins.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ code that manipulates syntax trees at
3434
compile time.
3535

3636
Let's write a plugin
37-
[`roman_numerals.rs`](https://github.com/rust-lang/rust/tree/master/src/test/auxiliary/roman_numerals.rs)
37+
[`roman_numerals.rs`](https://github.com/rust-lang/rust/blob/master/src/test/run-pass-fulldeps/auxiliary/roman_numerals.rs)
3838
that implements Roman numeral integer literals.
3939

4040
```rust,ignore
@@ -166,7 +166,8 @@ quasiquote as an ordinary plugin library.
166166

167167
Plugins can extend [Rust's lint
168168
infrastructure](../reference.html#lint-check-attributes) with additional checks for
169-
code style, safety, etc. Now let's write a plugin [`lint_plugin_test.rs`](https://github.com/rust-lang/rust/blob/master/src/test/auxiliary/lint_plugin_test.rs)
169+
code style, safety, etc. Now let's write a plugin
170+
[`lint_plugin_test.rs`](https://github.com/rust-lang/rust/blob/master/src/test/run-pass-fulldeps/auxiliary/lint_plugin_test.rs)
170171
that warns about any item named `lintme`.
171172

172173
```rust,ignore

src/doc/rustc-ux-guidelines.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,19 @@ Error explanations are long form descriptions of error messages provided with
5656
the compiler. They are accessible via the `--explain` flag. Each explanation
5757
comes with an example of how to trigger it and advice on how to fix it.
5858

59-
* All of them are accessible [online](https://github.com/rust-lang/rust/blob/master/src/librustc/diagnostics.rs).
59+
* All of them are accessible [online](http://doc.rust-lang.org/error-index.html),
60+
which are auto-generated from rustc source code in different places:
61+
[librustc](https://github.com/rust-lang/rust/blob/master/src/librustc/diagnostics.rs),
62+
[librustc_borrowck](https://github.com/rust-lang/rust/blob/master/src/librustc_borrowck/diagnostics.rs),
63+
[librustc_const_eval](https://github.com/rust-lang/rust/blob/master/src/librustc_const_eval/diagnostics.rs),
64+
[librustc_lint](https://github.com/rust-lang/rust/blob/master/src/librustc_lint/types.rs),
65+
[librustc_metadata](https://github.com/rust-lang/rust/blob/master/src/librustc_metadata/diagnostics.rs),
66+
[librustc_mir](https://github.com/rust-lang/rust/blob/master/src/librustc_mir/diagnostics.rs),
67+
[librustc_passes](https://github.com/rust-lang/rust/blob/master/src/librustc_passes/diagnostics.rs),
68+
[librustc_privacy](https://github.com/rust-lang/rust/blob/master/src/librustc_privacy/diagnostics.rs),
69+
[librustc_resolve](https://github.com/rust-lang/rust/blob/master/src/librustc_resolve/diagnostics.rs),
70+
[librustc_trans](https://github.com/rust-lang/rust/blob/master/src/librustc_trans/diagnostics.rs),
71+
[librustc_typeck](https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/diagnostics.rs).
6072
* Explanations have full markdown support. Use it, especially to highlight
6173
code with backticks.
6274
* When talking about the compiler, call it `the compiler`, not `Rust` or

src/libcore/ops.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,7 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
16081608
/// See the [`contains()`](#method.contains) method for its characterization.
16091609
///
16101610
/// It cannot serve as an iterator because it doesn't have a starting point.
1611+
///
16111612
/// ```
16121613
/// fn main() {
16131614
/// assert_eq!((..5), std::ops::RangeTo{ end: 5 });

src/libstd/ffi/c_str.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,38 @@ impl CStr {
509509
/// The returned pointer will be valid for as long as `self` is and points
510510
/// to a contiguous region of memory terminated with a 0 byte to represent
511511
/// the end of the string.
512+
///
513+
/// **WARNING**
514+
///
515+
/// It is your responsibility to make sure that the underlying memory is not
516+
/// freed too early. For example, the following code will cause undefined
517+
/// behaviour when `ptr` is used inside the `unsafe` block:
518+
///
519+
/// ```no_run
520+
/// use std::ffi::{CString};
521+
///
522+
/// let ptr = CString::new("Hello").unwrap().as_ptr();
523+
/// unsafe {
524+
/// // `ptr` is dangling
525+
/// *ptr;
526+
/// }
527+
/// ```
528+
///
529+
/// This happens because the pointer returned by `as_ptr` does not carry any
530+
/// lifetime information and the string is deallocated immediately after
531+
/// the `CString::new("Hello").unwrap().as_ptr()` expression is evaluated.
532+
/// To fix the problem, bind the string to a local variable:
533+
///
534+
/// ```no_run
535+
/// use std::ffi::{CString};
536+
///
537+
/// let hello = CString::new("Hello").unwrap();
538+
/// let ptr = hello.as_ptr();
539+
/// unsafe {
540+
/// // `ptr` is valid because `hello` is in scope
541+
/// *ptr;
542+
/// }
543+
/// ```
512544
#[stable(feature = "rust1", since = "1.0.0")]
513545
pub fn as_ptr(&self) -> *const c_char {
514546
self.inner.as_ptr()

0 commit comments

Comments
 (0)