Skip to content

Rollup of 9 pull requests #39470

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

Merged
merged 18 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
65147b6
Update nomicon to describe `#[may_dangle]`
apasel422 Jan 19, 2017
b996a7e
Fix doc cfg(test) and tests directory
Jan 4, 2017
1363cda
Remove unnecessary LLVMRustPersonalityFn binding
nagisa Jan 26, 2017
95227a4
Remove ToPrimitive trait.
Mark-Simulacrum Jan 28, 2017
d880bbb
Remove the workaround for gh32959
nagisa Jan 29, 2017
fe324ce
rustdoc: mark ffi functions with unsafety icon
tspiteri Jan 30, 2017
d73e84d
use suggestions instead of helps with code in them
oli-obk Jan 31, 2017
4b52600
update mailmap for @pliniker
steveklabnik Jan 31, 2017
4a07e72
In std:rc, clarify the lack of mutability inside an Rc
federicomenaquintero Jan 25, 2017
5ada328
Rollup merge of #38823 - Freyskeyd:doc-missingInformationCfgTest, r=s…
GuillaumeGomez Feb 2, 2017
38ae923
Rollup merge of #39196 - apasel422:nomicon, r=petrochenkov
GuillaumeGomez Feb 2, 2017
b03436d
Rollup merge of #39299 - federicomenaquintero:master, r=GuillaumeGomez
GuillaumeGomez Feb 2, 2017
bcfa2f1
Rollup merge of #39319 - nagisa:remove-rustsetpersonalityfn, r=pnkfelix
GuillaumeGomez Feb 2, 2017
a768827
Rollup merge of #39373 - Mark-Simulacrum:remove-toprimitive, r=aturon
GuillaumeGomez Feb 2, 2017
7bc3222
Rollup merge of #39383 - nagisa:mir-uninhabited-destinations, r=pnkfelix
GuillaumeGomez Feb 2, 2017
9559c4d
Rollup merge of #39416 - tspiteri:ffi-unsafe-icon, r=brson
GuillaumeGomez Feb 2, 2017
a561ad8
Rollup merge of #39420 - oli-obk:sugg, r=pnkfelix
GuillaumeGomez Feb 2, 2017
d09e4de
Rollup merge of #39427 - steveklabnik:pliniker-mailmap, r=alexcrichton
GuillaumeGomez Feb 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ Ožbolt Menegatti <[email protected]> gareins <[email protected]
Paul Faria <[email protected]> Paul Faria <[email protected]>
Peer Aramillo Irizar <[email protected]> parir <[email protected]>
Peter Elmers <[email protected]> <[email protected]>
Peter Liniker <[email protected]>
Peter Zotov <[email protected]>
Phil Dawes <[email protected]> Phil Dawes <[email protected]>
Philipp Brüschweiler <[email protected]> <[email protected]>
Expand Down
4 changes: 4 additions & 0 deletions src/doc/book/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ be imported in every test with `mod common;`
That's all there is to the `tests` directory. The `tests` module isn't needed
here, since the whole thing is focused on tests.

Note, when building integration tests, cargo will not pass the `test` attribute
to the compiler. It means that all parts in `cfg(test)` won't be included in
the build used in your integration tests.

Let's finally check out that third section: documentation tests.

# Documentation tests
Expand Down
30 changes: 24 additions & 6 deletions src/doc/nomicon/dropck.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,42 @@ assert (unsafely) that a generic type's destructor is *guaranteed* to
not access any expired data, even if its type gives it the capability
to do so.

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

```rust,ignore
struct Inspector<'a>(&'a u8, &'static str);
impl<'a> Drop for Inspector<'a> {
#[unsafe_destructor_blind_to_params]
unsafe impl<#[may_dangle] 'a> Drop for Inspector<'a> {
fn drop(&mut self) {
println!("Inspector(_, {}) knows when *not* to inspect.", self.1);
}
}
```

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

The attribute can be applied to any number of lifetime and type parameters. In
the following example, we assert that we access no data behind a reference of
lifetime `'b` and that the only uses of `T` will be moves or drops, but omit
the attribute from `'a` and `U`, because we do access data with that lifetime
and that type:

```rust,ignore
use std::fmt::Display;
struct Inspector<'a, 'b, T, U: Display>(&'a u8, &'b u8, T, U);
unsafe impl<'a, #[may_dangle] 'b, #[may_dangle] T, U: Display> Drop for Inspector<'a, 'b, T, U> {
fn drop(&mut self) {
println!("Inspector({}, _, _, {})", self.0, self.3);
}
}
```

It is sometimes obvious that no such access can occur, like the case above.
However, when dealing with a generic type parameter, such access can
occur indirectly. Examples of such indirect access are:
Expand Down Expand Up @@ -263,7 +281,7 @@ some other method invoked by the destructor, rather than being written
directly within it.

In all of the above cases where the `&'a u8` is accessed in the
destructor, adding the `#[unsafe_destructor_blind_to_params]`
destructor, adding the `#[may_dangle]`
attribute makes the type vulnerable to misuse that the borrower
checker will not catch, inviting havoc. It is better to avoid adding
the attribute.
Expand Down
9 changes: 6 additions & 3 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
//! pointer to the same value in the heap. When the last [`Rc`] pointer to a
//! given value is destroyed, the pointed-to value is also destroyed.
//!
//! Shared references in Rust disallow mutation by default, and `Rc` is no
//! exception. If you need to mutate through an [`Rc`], use [`Cell`] or
//! [`RefCell`].
//! Shared references in Rust disallow mutation by default, and [`Rc`]
//! is no exception: you cannot obtain a mutable reference to
//! something inside an [`Rc`]. If you need mutability, put a [`Cell`]
//! or [`RefCell`] inside the [`Rc`]; see [an example of mutability
//! inside an Rc][mutability].
//!
//! [`Rc`] uses non-atomic reference counting. This means that overhead is very
//! low, but an [`Rc`] cannot be sent between threads, and consequently [`Rc`]
Expand Down Expand Up @@ -214,6 +216,7 @@
//! [upgrade]: struct.Weak.html#method.upgrade
//! [`None`]: ../../std/option/enum.Option.html#variant.None
//! [assoc]: ../../book/method-syntax.html#associated-functions
//! [mutability]: ../../std/cell/index.html#introducing-mutability-inside-of-something-immutable

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
1 change: 0 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ pub mod util {
pub mod common;
pub mod ppaux;
pub mod nodemap;
pub mod num;
pub mod fs;
}

Expand Down
98 changes: 0 additions & 98 deletions src/librustc/util/num.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/librustc_const_eval/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//#![allow(non_camel_case_types)]

use rustc::middle::const_val::ConstVal::*;
use rustc::middle::const_val::ConstVal;
use self::ErrKind::*;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ extern "C" {
Name: *const c_char)
-> ValueRef;
pub fn LLVMRustAddHandler(CatchSwitch: ValueRef, Handler: BasicBlockRef);
pub fn LLVMRustSetPersonalityFn(B: BuilderRef, Pers: ValueRef);
pub fn LLVMSetPersonalityFn(Func: ValueRef, Pers: ValueRef);

// Add a case to the switch instruction
pub fn LLVMAddCase(Switch: ValueRef, OnVal: ValueRef, Dest: BasicBlockRef);
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_mir/build/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use rustc::hir;
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
pub fn ast_block(&mut self,
destination: &Lvalue<'tcx>,
// FIXME(#32959): temporary measure for the issue
dest_is_unit: bool,
mut block: BasicBlock,
ast_block: &'tcx hir::Block)
-> BlockAnd<()> {
Expand Down Expand Up @@ -83,8 +81,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
// of the block.
if let Some(expr) = expr {
unpack!(block = this.into(destination, block, expr));
} else if dest_is_unit {
// FIXME(#31472)
} else {
let source_info = this.source_info(span);
this.cfg.push_assign_unit(block, source_info, destination);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
this.in_scope(extent, block, |this| this.into(destination, block, value))
}
ExprKind::Block { body: ast_block } => {
this.ast_block(destination, expr.ty.is_nil(), block, ast_block)
this.ast_block(destination, block, ast_block)
}
ExprKind::Match { discriminant, arms } => {
this.match_expr(destination, expr_span, block, discriminant, arms)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

pub fn set_personality_fn(&self, personality: ValueRef) {
unsafe {
llvm::LLVMRustSetPersonalityFn(self.llbuilder, personality);
llvm::LLVMSetPersonalityFn(self.llfn(), personality);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/librustc_trans/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ pub fn trans_mir<'a, 'tcx: 'a>(
mircx.cleanup_kinds.iter_enumerated().map(|(bb, cleanup_kind)| {
if let CleanupKind::Funclet = *cleanup_kind {
let bcx = mircx.get_builder(bb);
bcx.set_personality_fn(mircx.ccx.eh_personality());
unsafe {
llvm::LLVMSetPersonalityFn(mircx.llfn, mircx.ccx.eh_personality());
}
if base::wants_msvc_seh(ccx.sess()) {
return Some(Funclet::new(bcx.cleanup_pad(None, &[])));
}
Expand Down
11 changes: 6 additions & 5 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1806,12 +1806,13 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
String::new()
};

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

let doc_value = myitem.doc_value().unwrap_or("");
write!(w, "
Expand Down
27 changes: 23 additions & 4 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2456,9 +2456,21 @@ impl<'a> Parser<'a> {
Some(f) => f,
None => continue,
};
err.help(&format!("try parenthesizing the first index; e.g., `(foo.{}){}`",
float.trunc() as usize,
format!(".{}", fstr.splitn(2, ".").last().unwrap())));
let sugg = pprust::to_string(|s| {
use print::pprust::PrintState;
use print::pp::word;
s.popen()?;
s.print_expr(&e)?;
word(&mut s.s, ".")?;
s.print_usize(float.trunc() as usize)?;
s.pclose()?;
word(&mut s.s, ".")?;
word(&mut s.s, fstr.splitn(2, ".").last().unwrap())
});
err.span_suggestion(
prev_span,
"try parenthesizing the first index",
sugg);
}
return Err(err);

Expand Down Expand Up @@ -3900,7 +3912,14 @@ impl<'a> Parser<'a> {
if self.eat(&token::Semi) {
stmt_span.hi = self.prev_span.hi;
}
e.span_help(stmt_span, "try placing this code inside a block");
let sugg = pprust::to_string(|s| {
use print::pprust::{PrintState, INDENT_UNIT};
s.ibox(INDENT_UNIT)?;
s.bopen()?;
s.print_stmt(&stmt)?;
s.bclose_maybe_open(stmt.span, INDENT_UNIT, false)
});
e.span_suggestion(stmt_span, "try placing this code inside a block", sugg);
}
Err(mut e) => {
self.recover_stmt_(SemiColonMode::Break);
Expand Down
8 changes: 0 additions & 8 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,14 +1082,6 @@ extern "C" void LLVMRustAddHandler(LLVMValueRef CatchSwitchRef,
#endif
}

extern "C" void LLVMRustSetPersonalityFn(LLVMBuilderRef B,
LLVMValueRef Personality) {
#if LLVM_VERSION_GE(3, 8)
unwrap(B)->GetInsertBlock()->getParent()->setPersonalityFn(
cast<Function>(unwrap(Personality)));
#endif
}

#if LLVM_VERSION_GE(3, 8)
extern "C" OperandBundleDef *LLVMRustBuildOperandBundleDef(const char *Name,
LLVMValueRef *Inputs,
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/missing-block-hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fn main() {
{
if (foo)
bar; //~ ERROR expected `{`, found `bar`
//^ HELP try placing this code inside a block
//~^ HELP try placing this code inside a block
//~| SUGGESTION { bar; }
}
}
3 changes: 2 additions & 1 deletion src/test/parse-fail/tuple-float-index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@

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