Skip to content

Commit eedaa94

Browse files
committed
Auto merge of #39470 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 9 pull requests - Successful merges: #38823, #39196, #39299, #39319, #39373, #39383, #39416, #39420, #39427 - Failed merges:
2 parents a47a6ea + d09e4de commit eedaa94

File tree

17 files changed

+75
-137
lines changed

17 files changed

+75
-137
lines changed

.mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Ožbolt Menegatti <[email protected]> gareins <[email protected]
167167
Paul Faria <[email protected]> Paul Faria <[email protected]>
168168
Peer Aramillo Irizar <[email protected]> parir <[email protected]>
169169
170+
Peter Liniker <[email protected]>
170171
Peter Zotov <[email protected]>
171172
Phil Dawes <[email protected]> Phil Dawes <[email protected]>
172173
Philipp Brüschweiler <[email protected]> <[email protected]>

src/doc/book/testing.md

+4
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@ be imported in every test with `mod common;`
499499
That's all there is to the `tests` directory. The `tests` module isn't needed
500500
here, since the whole thing is focused on tests.
501501

502+
Note, when building integration tests, cargo will not pass the `test` attribute
503+
to the compiler. It means that all parts in `cfg(test)` won't be included in
504+
the build used in your integration tests.
505+
502506
Let's finally check out that third section: documentation tests.
503507

504508
# Documentation tests

src/doc/nomicon/dropck.md

+24-6
Original file line numberDiff line numberDiff line change
@@ -199,24 +199,42 @@ assert (unsafely) that a generic type's destructor is *guaranteed* to
199199
not access any expired data, even if its type gives it the capability
200200
to do so.
201201

202-
That attribute is called `unsafe_destructor_blind_to_params`.
202+
That attribute is called `may_dangle` and was introduced in [RFC 1327]
203+
(https://github.com/rust-lang/rfcs/blob/master/text/1327-dropck-param-eyepatch.md).
203204
To deploy it on the Inspector example from above, we would write:
204205

205206
```rust,ignore
206207
struct Inspector<'a>(&'a u8, &'static str);
207208
208-
impl<'a> Drop for Inspector<'a> {
209-
#[unsafe_destructor_blind_to_params]
209+
unsafe impl<#[may_dangle] 'a> Drop for Inspector<'a> {
210210
fn drop(&mut self) {
211211
println!("Inspector(_, {}) knows when *not* to inspect.", self.1);
212212
}
213213
}
214214
```
215215

216-
This attribute has the word `unsafe` in it because the compiler is not
217-
checking the implicit assertion that no potentially expired data
216+
Use of this attribute requires the `Drop` impl to be marked `unsafe` because the
217+
compiler is not checking the implicit assertion that no potentially expired data
218218
(e.g. `self.0` above) is accessed.
219219

220+
The attribute can be applied to any number of lifetime and type parameters. In
221+
the following example, we assert that we access no data behind a reference of
222+
lifetime `'b` and that the only uses of `T` will be moves or drops, but omit
223+
the attribute from `'a` and `U`, because we do access data with that lifetime
224+
and that type:
225+
226+
```rust,ignore
227+
use std::fmt::Display;
228+
229+
struct Inspector<'a, 'b, T, U: Display>(&'a u8, &'b u8, T, U);
230+
231+
unsafe impl<'a, #[may_dangle] 'b, #[may_dangle] T, U: Display> Drop for Inspector<'a, 'b, T, U> {
232+
fn drop(&mut self) {
233+
println!("Inspector({}, _, _, {})", self.0, self.3);
234+
}
235+
}
236+
```
237+
220238
It is sometimes obvious that no such access can occur, like the case above.
221239
However, when dealing with a generic type parameter, such access can
222240
occur indirectly. Examples of such indirect access are:
@@ -263,7 +281,7 @@ some other method invoked by the destructor, rather than being written
263281
directly within it.
264282

265283
In all of the above cases where the `&'a u8` is accessed in the
266-
destructor, adding the `#[unsafe_destructor_blind_to_params]`
284+
destructor, adding the `#[may_dangle]`
267285
attribute makes the type vulnerable to misuse that the borrower
268286
checker will not catch, inviting havoc. It is better to avoid adding
269287
the attribute.

src/liballoc/rc.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
//! pointer to the same value in the heap. When the last [`Rc`] pointer to a
1818
//! given value is destroyed, the pointed-to value is also destroyed.
1919
//!
20-
//! Shared references in Rust disallow mutation by default, and `Rc` is no
21-
//! exception. If you need to mutate through an [`Rc`], use [`Cell`] or
22-
//! [`RefCell`].
20+
//! Shared references in Rust disallow mutation by default, and [`Rc`]
21+
//! is no exception: you cannot obtain a mutable reference to
22+
//! something inside an [`Rc`]. If you need mutability, put a [`Cell`]
23+
//! or [`RefCell`] inside the [`Rc`]; see [an example of mutability
24+
//! inside an Rc][mutability].
2325
//!
2426
//! [`Rc`] uses non-atomic reference counting. This means that overhead is very
2527
//! low, but an [`Rc`] cannot be sent between threads, and consequently [`Rc`]
@@ -214,6 +216,7 @@
214216
//! [upgrade]: struct.Weak.html#method.upgrade
215217
//! [`None`]: ../../std/option/enum.Option.html#variant.None
216218
//! [assoc]: ../../book/method-syntax.html#associated-functions
219+
//! [mutability]: ../../std/cell/index.html#introducing-mutability-inside-of-something-immutable
217220
218221
#![stable(feature = "rust1", since = "1.0.0")]
219222

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ pub mod util {
109109
pub mod common;
110110
pub mod ppaux;
111111
pub mod nodemap;
112-
pub mod num;
113112
pub mod fs;
114113
}
115114

src/librustc/util/num.rs

-98
This file was deleted.

src/librustc_const_eval/eval.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//#![allow(non_camel_case_types)]
12-
1311
use rustc::middle::const_val::ConstVal::*;
1412
use rustc::middle::const_val::ConstVal;
1513
use self::ErrKind::*;

src/librustc_llvm/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ extern "C" {
804804
Name: *const c_char)
805805
-> ValueRef;
806806
pub fn LLVMRustAddHandler(CatchSwitch: ValueRef, Handler: BasicBlockRef);
807-
pub fn LLVMRustSetPersonalityFn(B: BuilderRef, Pers: ValueRef);
807+
pub fn LLVMSetPersonalityFn(Func: ValueRef, Pers: ValueRef);
808808

809809
// Add a case to the switch instruction
810810
pub fn LLVMAddCase(Switch: ValueRef, OnVal: ValueRef, Dest: BasicBlockRef);

src/librustc_mir/build/block.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ use rustc::hir;
1616
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
1717
pub fn ast_block(&mut self,
1818
destination: &Lvalue<'tcx>,
19-
// FIXME(#32959): temporary measure for the issue
20-
dest_is_unit: bool,
2119
mut block: BasicBlock,
2220
ast_block: &'tcx hir::Block)
2321
-> BlockAnd<()> {
@@ -83,8 +81,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
8381
// of the block.
8482
if let Some(expr) = expr {
8583
unpack!(block = this.into(destination, block, expr));
86-
} else if dest_is_unit {
87-
// FIXME(#31472)
84+
} else {
8885
let source_info = this.source_info(span);
8986
this.cfg.push_assign_unit(block, source_info, destination);
9087
}

src/librustc_mir/build/expr/into.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
4040
this.in_scope(extent, block, |this| this.into(destination, block, value))
4141
}
4242
ExprKind::Block { body: ast_block } => {
43-
this.ast_block(destination, expr.ty.is_nil(), block, ast_block)
43+
this.ast_block(destination, block, ast_block)
4444
}
4545
ExprKind::Match { discriminant, arms } => {
4646
this.match_expr(destination, expr_span, block, discriminant, arms)

src/librustc_trans/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11071107

11081108
pub fn set_personality_fn(&self, personality: ValueRef) {
11091109
unsafe {
1110-
llvm::LLVMRustSetPersonalityFn(self.llbuilder, personality);
1110+
llvm::LLVMSetPersonalityFn(self.llfn(), personality);
11111111
}
11121112
}
11131113

src/librustc_trans/mir/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ pub fn trans_mir<'a, 'tcx: 'a>(
319319
mircx.cleanup_kinds.iter_enumerated().map(|(bb, cleanup_kind)| {
320320
if let CleanupKind::Funclet = *cleanup_kind {
321321
let bcx = mircx.get_builder(bb);
322-
bcx.set_personality_fn(mircx.ccx.eh_personality());
322+
unsafe {
323+
llvm::LLVMSetPersonalityFn(mircx.llfn, mircx.ccx.eh_personality());
324+
}
323325
if base::wants_msvc_seh(ccx.sess()) {
324326
return Some(Funclet::new(bcx.cleanup_pad(None, &[])));
325327
}

src/librustdoc/html/render.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1806,12 +1806,13 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
18061806
String::new()
18071807
};
18081808

1809-
let mut unsafety_flag = "";
1810-
if let clean::FunctionItem(ref func) = myitem.inner {
1811-
if func.unsafety == hir::Unsafety::Unsafe {
1812-
unsafety_flag = "<a title='unsafe function' href='#'><sup>⚠</sup></a>";
1809+
let unsafety_flag = match myitem.inner {
1810+
clean::FunctionItem(ref func) | clean::ForeignFunctionItem(ref func)
1811+
if func.unsafety == hir::Unsafety::Unsafe => {
1812+
"<a title='unsafe function' href='#'><sup>⚠</sup></a>"
18131813
}
1814-
}
1814+
_ => "",
1815+
};
18151816

18161817
let doc_value = myitem.doc_value().unwrap_or("");
18171818
write!(w, "

src/libsyntax/parse/parser.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -2456,9 +2456,21 @@ impl<'a> Parser<'a> {
24562456
Some(f) => f,
24572457
None => continue,
24582458
};
2459-
err.help(&format!("try parenthesizing the first index; e.g., `(foo.{}){}`",
2460-
float.trunc() as usize,
2461-
format!(".{}", fstr.splitn(2, ".").last().unwrap())));
2459+
let sugg = pprust::to_string(|s| {
2460+
use print::pprust::PrintState;
2461+
use print::pp::word;
2462+
s.popen()?;
2463+
s.print_expr(&e)?;
2464+
word(&mut s.s, ".")?;
2465+
s.print_usize(float.trunc() as usize)?;
2466+
s.pclose()?;
2467+
word(&mut s.s, ".")?;
2468+
word(&mut s.s, fstr.splitn(2, ".").last().unwrap())
2469+
});
2470+
err.span_suggestion(
2471+
prev_span,
2472+
"try parenthesizing the first index",
2473+
sugg);
24622474
}
24632475
return Err(err);
24642476

@@ -3900,7 +3912,14 @@ impl<'a> Parser<'a> {
39003912
if self.eat(&token::Semi) {
39013913
stmt_span.hi = self.prev_span.hi;
39023914
}
3903-
e.span_help(stmt_span, "try placing this code inside a block");
3915+
let sugg = pprust::to_string(|s| {
3916+
use print::pprust::{PrintState, INDENT_UNIT};
3917+
s.ibox(INDENT_UNIT)?;
3918+
s.bopen()?;
3919+
s.print_stmt(&stmt)?;
3920+
s.bclose_maybe_open(stmt.span, INDENT_UNIT, false)
3921+
});
3922+
e.span_suggestion(stmt_span, "try placing this code inside a block", sugg);
39043923
}
39053924
Err(mut e) => {
39063925
self.recover_stmt_(SemiColonMode::Break);

src/rustllvm/RustWrapper.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -1082,14 +1082,6 @@ extern "C" void LLVMRustAddHandler(LLVMValueRef CatchSwitchRef,
10821082
#endif
10831083
}
10841084

1085-
extern "C" void LLVMRustSetPersonalityFn(LLVMBuilderRef B,
1086-
LLVMValueRef Personality) {
1087-
#if LLVM_VERSION_GE(3, 8)
1088-
unwrap(B)->GetInsertBlock()->getParent()->setPersonalityFn(
1089-
cast<Function>(unwrap(Personality)));
1090-
#endif
1091-
}
1092-
10931085
#if LLVM_VERSION_GE(3, 8)
10941086
extern "C" OperandBundleDef *LLVMRustBuildOperandBundleDef(const char *Name,
10951087
LLVMValueRef *Inputs,

src/test/compile-fail/missing-block-hint.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn main() {
1515
{
1616
if (foo)
1717
bar; //~ ERROR expected `{`, found `bar`
18-
//^ HELP try placing this code inside a block
18+
//~^ HELP try placing this code inside a block
19+
//~| SUGGESTION { bar; }
1920
}
2021
}

src/test/parse-fail/tuple-float-index.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212

1313
fn main () {
1414
(1, (2, 3)).1.1; //~ ERROR unexpected token
15-
//~^ HELP try parenthesizing the first index; e.g., `(foo.1).1`
15+
//~^ HELP try parenthesizing the first index
16+
//~| SUGGESTION ((1, (2, 3)).1).1
1617
}

0 commit comments

Comments
 (0)