Skip to content

Rollup of 14 pull requests #54944

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

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
74bf59e
Documents reference equality by address (#54197)
lucasloisp Oct 2, 2018
68236e0
Cleans trailing whitespace
lucasloisp Oct 2, 2018
ac4945c
Fix #24840: make default for `optimize` independent of `debug` settin…
pnkfelix Oct 4, 2018
82444aa
Add doc comments about safest way to initialize a vector of zeros
mandeep Oct 5, 2018
c802e13
Update minifier version
GuillaumeGomez Oct 6, 2018
ded0bf5
Fix mobile doc display
GuillaumeGomez Oct 6, 2018
9a9894a
Fix tracking issue for Once::is_completed
SimonSapin Oct 7, 2018
b7248d5
Fix internal compiler error on malformed match arm pattern.
dsciarra Oct 6, 2018
91b71f5
Identify borrows captured by trait objects.
davidtwco Oct 5, 2018
72911fb
Update logic to search for casts.
davidtwco Oct 5, 2018
8c01c22
Stabilize the `Option::replace` method
Kerollmops Oct 8, 2018
c232ea1
Bump the `Option::replace` stabilize version to 1.31.0
Kerollmops Oct 8, 2018
f8c1b0c
Add struct field suggestions.
davidtwco Oct 4, 2018
9e49ac0
Change from label to suggestion.
davidtwco Oct 5, 2018
40e20e2
Added text explaining the (new) relative roles of `optimize`+`debug`
pnkfelix Oct 8, 2018
54a3583
it's auto traits that make for automatic implementations
RalfJung Oct 8, 2018
dd0f5e5
Unused result warning: "X which must" ↦ "X that must"
varkor Oct 8, 2018
be88961
Fix handling of #[must_use] on unit and uninhabited types
varkor Oct 8, 2018
3447473
parse_trait_item_ now handles interpolated blocks as function body decls
Oct 5, 2018
1e584bf
Refactor macro comment and add resize with zeros example
mandeep Oct 9, 2018
a0577ee
impl Eq+Hash for TyLayout
RalfJung Oct 9, 2018
e44b05a
Rollup merge of #54755 - lucasloisp:document-reference-address-eq, r=…
pietroalbini Oct 9, 2018
9f9ae6f
Rollup merge of #54811 - pnkfelix:issue-24840-separate-bootstrap-defa…
pietroalbini Oct 9, 2018
3a7093c
Rollup merge of #54831 - davidtwco:issue-52663-struct-field-suggestio…
pietroalbini Oct 9, 2018
b1cc3b8
Rollup merge of #54848 - davidtwco:issue-52663-trait-object, r=nikoma…
pietroalbini Oct 9, 2018
6890621
Rollup merge of #54850 - mcr431:fix-54707-trait-function-from-macro, …
pietroalbini Oct 9, 2018
83cc5a0
Rollup merge of #54860 - mandeep:vec-initialize, r=alexcrichton
pietroalbini Oct 9, 2018
f5869ef
Rollup merge of #54869 - GuillaumeGomez:fix-mobile-docs, r=QuietMisdr…
pietroalbini Oct 9, 2018
5750176
Rollup merge of #54891 - rust-lang:SimonSapin-patch-1, r=nagisa
pietroalbini Oct 9, 2018
e602205
Rollup merge of #54893 - dsciarra:issue-54379, r=pnkfelix
pietroalbini Oct 9, 2018
2f3569b
Rollup merge of #54904 - Kerollmops:stabilize-option-replace, r=Centril
pietroalbini Oct 9, 2018
7fee74b
Rollup merge of #54913 - RalfJung:unwind-safe, r=alexcrichton
pietroalbini Oct 9, 2018
440d313
Rollup merge of #54917 - varkor:unused-which, r=cramertj
pietroalbini Oct 9, 2018
a370112
Rollup merge of #54920 - varkor:must_use-unit, r=estebank
pietroalbini Oct 9, 2018
ec1b889
Rollup merge of #54936 - RalfJung:layout-hash, r=oli-obk
pietroalbini Oct 9, 2018
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
35 changes: 26 additions & 9 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,36 @@
# =============================================================================
[rust]

# Indicates that the build should be optimized for debugging Rust. Note that
# this is typically not what you want as it takes an incredibly large amount of
# time to have a debug-mode rustc compile any code (notably libstd). If this
# value is set to `true` it will affect a number of configuration options below
# as well, if unconfigured.
#debug = false

# Whether or not to optimize the compiler and standard library
# Whether or not to optimize the compiler and standard library.
#
# Note: the slowness of the non optimized compiler compiling itself usually
# outweighs the time gains in not doing optimizations, therefore a
# full bootstrap takes much more time with optimize set to false.
# full bootstrap takes much more time with `optimize` set to false.
#optimize = true

# Indicates that the build should be configured for debugging Rust. A
# `debug`-enabled compiler and standard library will be somewhat
# slower (due to e.g. checking of debug assertions) but should remain
# usable.
#
# Note: If this value is set to `true`, it will affect a number of
# configuration options below as well, if they have been left
# unconfigured in this file.
#
# Note: changes to the `debug` setting do *not* affect `optimize`
# above. In theory, a "maximally debuggable" environment would
# set `optimize` to `false` above to assist the introspection
# facilities of debuggers like lldb and gdb. To recreate such an
# environment, explicitly set `optimize` to `false` and `debug`
# to `true`. In practice, everyone leaves `optimize` set to
# `true`, because an unoptimized rustc with debugging
# enabled becomes *unusably slow* (e.g. rust-lang/rust#24840
# reported a 25x slowdown) and bootstrapping the supposed
# "maximally debuggable" environment (notably libstd) takes
# hours to build.
#
#debug = false

# Number of codegen units to use for each compiler invocation. A value of 0
# means "the number of cores on this machine", and 1+ is passed through to the
# compiler.
Expand Down
6 changes: 3 additions & 3 deletions src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "minifier"
version = "0.0.19"
version = "0.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"macro-utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -2484,7 +2484,7 @@ dependencies = [
name = "rustdoc"
version = "0.0.0"
dependencies = [
"minifier 0.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"minifier 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -3289,7 +3289,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum memchr 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a3b4142ab8738a78c51896f704f83c11df047ff1bda9a92a661aa6361552d93d"
"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum minifier 0.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "9908ed7c62f990c21ab41fdca53a864a3ada0da69d8729c4de727b397e27bc11"
"checksum minifier 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)" = "96c269bb45c39b333392b2b18ad71760b34ac65666591386b0e959ed58b3f474"
"checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4"
"checksum miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226"
"checksum new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0cdc457076c78ab54d5e0d6fa7c47981757f1e34dc39ff92787f217dede586c4"
Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ impl Config {
let default = false;
config.llvm_assertions = llvm_assertions.unwrap_or(default);

let default = true;
config.rust_optimize = optimize.unwrap_or(default);

let default = match &config.channel[..] {
"stable" | "beta" | "nightly" => true,
_ => false,
Expand All @@ -640,7 +643,6 @@ impl Config {
config.debug_jemalloc = debug_jemalloc.unwrap_or(default);
config.rust_debuginfo = debuginfo.unwrap_or(default);
config.rust_debug_assertions = debug_assertions.unwrap_or(default);
config.rust_optimize = optimize.unwrap_or(!default);

let default = config.channel == "dev";
config.ignore_git = ignore_git.unwrap_or(default);
Expand Down
6 changes: 3 additions & 3 deletions src/doc/rustc/src/lints/listing/warn-by-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ warning: functions generic over types must be mangled
1 | #[no_mangle]
| ------------ help: remove this attribute
2 | / fn foo<T>(t: T) {
3 | |
3 | |
4 | | }
| |_^
|
Expand Down Expand Up @@ -513,7 +513,7 @@ This will produce:
warning: borrow of packed field requires unsafe function or block (error E0133)
--> src/main.rs:11:13
|
11 | let y = &x.data.0;
11 | let y = &x.data.0;
| ^^^^^^^^^
|
= note: #[warn(safe_packed_borrows)] on by default
Expand Down Expand Up @@ -874,7 +874,7 @@ fn main() {
This will produce:

```text
warning: unused `std::result::Result` which must be used
warning: unused `std::result::Result` that must be used
--> src/main.rs:6:5
|
6 | returns_result();
Expand Down
8 changes: 7 additions & 1 deletion src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,17 @@ use raw_vec::RawVec;
/// assert_eq!(vec, [1, 2, 3, 4]);
/// ```
///
/// It can also initialize each element of a `Vec<T>` with a given value:
/// It can also initialize each element of a `Vec<T>` with a given value.
/// This may be more efficient than performing allocation and initialization
/// in separate steps, especially when initializing a vector of zeros:
///
/// ```
/// let vec = vec![0; 5];
/// assert_eq!(vec, [0, 0, 0, 0, 0]);
///
/// // The following is equivalent, but potentially slower:
/// let mut vec1 = Vec::with_capacity(5);
/// vec1.resize(5, 0);
/// ```
///
/// Use a `Vec<T>` as an efficient stack:
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
//! using it. The compiler will warn us about this kind of behavior:
//!
//! ```text
//! warning: unused result which must be used: iterator adaptors are lazy and
//! warning: unused result that must be used: iterator adaptors are lazy and
//! do nothing unless consumed
//! ```
//!
Expand Down
4 changes: 1 addition & 3 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,6 @@ impl<T> Option<T> {
/// # Examples
///
/// ```
/// #![feature(option_replace)]
///
/// let mut x = Some(2);
/// let old = x.replace(5);
/// assert_eq!(x, Some(5));
Expand All @@ -880,7 +878,7 @@ impl<T> Option<T> {
/// assert_eq!(old, None);
/// ```
#[inline]
#[unstable(feature = "option_replace", issue = "51998")]
#[stable(feature = "option_replace", since = "1.31.0")]
pub fn replace(&mut self, value: T) -> Option<T> {
mem::replace(self, Some(value))
}
Expand Down
1 change: 0 additions & 1 deletion src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#![feature(reverse_bits)]
#![feature(inner_deref)]
#![feature(slice_internals)]
#![feature(option_replace)]
#![feature(slice_partition_dedup)]
#![feature(copy_within)]

Expand Down
1 change: 0 additions & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#![feature(box_syntax)]
#![cfg_attr(unix, feature(libc))]
#![feature(nll)]
#![feature(option_replace)]
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(slice_sort_by_cached_key)]
Expand Down
27 changes: 17 additions & 10 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
}

let t = cx.tables.expr_ty(&expr);
let ty_warned = match t.sty {
ty::Tuple(ref tys) if tys.is_empty() => return,
ty::Never => return,
// FIXME(varkor): replace with `t.is_unit() || t.conservative_is_uninhabited()`.
let type_permits_no_use = match t.sty {
ty::Tuple(ref tys) if tys.is_empty() => true,
ty::Never => true,
ty::Adt(def, _) => {
if def.variants.is_empty() {
return;
true
} else {
check_must_use(cx, def.did, s.span, "")
}
check_must_use(cx, def.did, s.span, "")
},
}
_ => false,
};

Expand Down Expand Up @@ -95,7 +97,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
if let Some(def) = maybe_def {
let def_id = def.def_id();
fn_warned = check_must_use(cx, def_id, s.span, "return value of ");
} else if type_permits_no_use {
// We don't warn about unused unit or uninhabited types.
// (See https://github.com/rust-lang/rust/issues/43806 for details.)
return;
}

let must_use_op = match expr.node {
// Hardcoding operators here seemed more expedient than the
// refactoring that would be needed to look up the `#[must_use]`
Expand Down Expand Up @@ -135,18 +142,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {

if let Some(must_use_op) = must_use_op {
cx.span_lint(UNUSED_MUST_USE, expr.span,
&format!("unused {} which must be used", must_use_op));
&format!("unused {} that must be used", must_use_op));
op_warned = true;
}

if !(ty_warned || fn_warned || op_warned) {
if !(type_permits_no_use || fn_warned || op_warned) {
cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
}

fn check_must_use(cx: &LateContext, def_id: DefId, sp: Span, describe_path: &str) -> bool {
for attr in cx.tcx.get_attrs(def_id).iter() {
if attr.check_name("must_use") {
let msg = format!("unused {}`{}` which must be used",
let msg = format!("unused {}`{}` that must be used",
describe_path, cx.tcx.item_path_str(def_id));
let mut err = cx.struct_span_lint(UNUSED_MUST_USE, sp, &msg);
// check for #[must_use = "..."]
Expand Down Expand Up @@ -233,7 +240,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
.find(|&&(builtin, ty, _)| name == builtin && ty == AttributeType::CrateLevel)
.is_some();

// Has a plugin registered this attribute as one which must be used at
// Has a plugin registered this attribute as one that must be used at
// the crate level?
let plugin_crate = plugin_attributes.iter()
.find(|&&(ref x, t)| name == &**x && AttributeType::CrateLevel == t)
Expand Down
83 changes: 83 additions & 0 deletions src/librustc_mir/borrow_check/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,38 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
debug!("report_mutability_error: act={:?}, acted_on={:?}", act, acted_on);

match the_place_err {
// Suggest making an existing shared borrow in a struct definition a mutable borrow.
//
// This is applicable when we have a deref of a field access to a deref of a local -
// something like `*((*_1).0`. The local that we get will be a reference to the
// struct we've got a field access of (it must be a reference since there's a deref
// after the field access).
Place::Projection(box Projection {
base: Place::Projection(box Projection {
base: Place::Projection(box Projection {
base,
elem: ProjectionElem::Deref,
}),
elem: ProjectionElem::Field(field, _),
}),
elem: ProjectionElem::Deref,
}) => {
err.span_label(span, format!("cannot {ACT}", ACT = act));

if let Some((span, message)) = annotate_struct_field(
self.infcx.tcx,
base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx),
field,
) {
err.span_suggestion_with_applicability(
span,
"consider changing this to be mutable",
message,
Applicability::MaybeIncorrect,
);
}
},

// Suggest removing a `&mut` from the use of a mutable reference.
Place::Local(local)
if {
Expand Down Expand Up @@ -592,3 +624,54 @@ fn suggest_ampmut<'cx, 'gcx, 'tcx>(
fn is_closure_or_generator(ty: ty::Ty) -> bool {
ty.is_closure() || ty.is_generator()
}

/// Add a suggestion to a struct definition given a field access to a local.
/// This function expects the local to be a reference to a struct in order to produce a suggestion.
///
/// ```text
/// LL | s: &'a String
/// | ---------- use `&'a mut String` here to make mutable
/// ```
fn annotate_struct_field(
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
ty: ty::Ty<'tcx>,
field: &mir::Field,
) -> Option<(Span, String)> {
// Expect our local to be a reference to a struct of some kind.
if let ty::TyKind::Ref(_, ty, _) = ty.sty {
if let ty::TyKind::Adt(def, _) = ty.sty {
let field = def.all_fields().nth(field.index())?;
// Use the HIR types to construct the diagnostic message.
let node_id = tcx.hir.as_local_node_id(field.did)?;
let node = tcx.hir.find(node_id)?;
// Now we're dealing with the actual struct that we're going to suggest a change to,
// we can expect a field that is an immutable reference to a type.
if let hir::Node::Field(field) = node {
if let hir::TyKind::Rptr(lifetime, hir::MutTy {
mutbl: hir::Mutability::MutImmutable,
ref ty
}) = field.ty.node {
// Get the snippets in two parts - the named lifetime (if there is one) and
// type being referenced, that way we can reconstruct the snippet without loss
// of detail.
let type_snippet = tcx.sess.source_map().span_to_snippet(ty.span).ok()?;
let lifetime_snippet = if !lifetime.is_elided() {
format!("{} ", tcx.sess.source_map().span_to_snippet(lifetime.span).ok()?)
} else {
String::new()
};

return Some((
field.ty.span,
format!(
"&{}mut {}",
lifetime_snippet, &*type_snippet,
),
));
}
}
}
}

None
}
Loading