Skip to content

Commit f15d651

Browse files
committed
Auto merge of #52344 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 16 pull requests Successful merges: - #51962 (Provide llvm-strip in llvm-tools component) - #52003 (Implement `Option::replace` in the core library) - #52156 (Update std::ascii::ASCIIExt deprecation notes) - #52242 (NLL: Suggest `ref mut` and `&mut self`) - #52244 (Don't display default generic parameters in diagnostics that compare types) - #52290 (Deny bare trait objects in src/librustc_save_analysis) - #52293 (Deny bare trait objects in librustc_typeck) - #52299 (Deny bare trait objects in src/libserialize) - #52300 (Deny bare trait objects in librustc_target and libtest) - #52302 (Deny bare trait objects in the rest of rust) - #52310 (Backport 1.27.1 release notes to master) - #52314 (Fix ICE when using a pointer cast as array size) - #52315 (Resolve FIXME(#27942)) - #52316 (task: remove wrong comments about non-existent LocalWake trait) - #52322 (Update llvm-rebuild-trigger in light of LLVM 7 upgrade) - #52332 (dead-code lint: say "constructed", "called" for structs, functions) Failed merges: r? @ghost
2 parents bce32b5 + 9dff778 commit f15d651

File tree

85 files changed

+1076
-173
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1076
-173
lines changed

Diff for: RELEASES.md

+23
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,29 @@ Compatibility Notes
140140
[`{Any + Send + Sync}::downcast_ref`]: https://doc.rust-lang.org/std/any/trait.Any.html#method.downcast_ref-2
141141
[`{Any + Send + Sync}::is`]: https://doc.rust-lang.org/std/any/trait.Any.html#method.is-2
142142

143+
Version 1.27.1 (2018-07-10)
144+
===========================
145+
146+
Security Notes
147+
--------------
148+
149+
- rustdoc would execute plugins in the /tmp/rustdoc/plugins directory
150+
when running, which enabled executing code as some other user on a
151+
given machine. This release fixes that vulnerability; you can read
152+
more about this on the [blog][rustdoc-sec]. The associated CVE is [CVE-2018-1000622].
153+
154+
Thank you to Red Hat for responsibily disclosing this vulnerability to us.
155+
156+
Compatibility Notes
157+
-------------------
158+
159+
- The borrow checker was fixed to avoid an additional potential unsoundness when using
160+
match ergonomics: [#51415][51415], [#49534][49534].
161+
162+
[51415]: https://github.com/rust-lang/rust/issues/51415
163+
[49534]: https://github.com/rust-lang/rust/issues/49534
164+
[rustdoc-sec]: https://blog.rust-lang.org/2018/07/06/security-advisory-for-rustdoc.html
165+
[CVE-2018-1000622]: https://cve.mitre.org/cgi-bin/cvename.cgi?name=%20CVE-2018-1000622
143166

144167
Version 1.27.0 (2018-06-21)
145168
==========================

Diff for: src/bootstrap/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ const LLVM_TOOLS: &[&str] = &[
206206
"llvm-objcopy", // used to transform ELFs into binary format which flashing tools consume
207207
"llvm-objdump", // used to disassemble programs
208208
"llvm-profdata", // used to inspect and merge files generated by profiles
209-
"llvm-size", // prints the size of the linker sections of a program
209+
"llvm-size", // used to prints the size of the linker sections of a program
210+
"llvm-strip", // used to discard symbols from binary files to reduce their size
210211
];
211212

212213
/// A structure representing a Rust compiler.

Diff for: src/build_helper/lib.rs

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

11+
#![deny(bare_trait_objects)]
12+
1113
use std::fs::File;
1214
use std::path::{Path, PathBuf};
1315
use std::process::{Command, Stdio};

Diff for: src/liballoc_jemalloc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#![no_std]
1212
#![allow(unused_attributes)]
13+
#![deny(bare_trait_objects)]
1314
#![unstable(feature = "alloc_jemalloc",
1415
reason = "implementation detail of std, does not provide any public API",
1516
issue = "0")]

Diff for: src/liballoc_system/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#![no_std]
1212
#![allow(unused_attributes)]
13+
#![deny(bare_trait_objects)]
1314
#![unstable(feature = "alloc_system",
1415
reason = "this library is unlikely to be stabilized in its current \
1516
form or name",

Diff for: src/libarena/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#![cfg_attr(test, feature(test))]
3131

3232
#![allow(deprecated)]
33+
#![deny(bare_trait_objects)]
3334

3435
extern crate alloc;
3536
extern crate rustc_data_structures;

Diff for: src/libcore/option.rs

+27
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,33 @@ impl<T> Option<T> {
845845
pub fn take(&mut self) -> Option<T> {
846846
mem::replace(self, None)
847847
}
848+
849+
/// Replaces the actual value in the option by the value given in parameter,
850+
/// returning the old value if present,
851+
/// leaving a [`Some`] in its place without deinitializing either one.
852+
///
853+
/// [`Some`]: #variant.Some
854+
///
855+
/// # Examples
856+
///
857+
/// ```
858+
/// #![feature(option_replace)]
859+
///
860+
/// let mut x = Some(2);
861+
/// let old = x.replace(5);
862+
/// assert_eq!(x, Some(5));
863+
/// assert_eq!(old, Some(2));
864+
///
865+
/// let mut x = None;
866+
/// let old = x.replace(3);
867+
/// assert_eq!(x, Some(3));
868+
/// assert_eq!(old, None);
869+
/// ```
870+
#[inline]
871+
#[unstable(feature = "option_replace", issue = "51998")]
872+
pub fn replace(&mut self, value: T) -> Option<T> {
873+
mem::replace(self, Some(value))
874+
}
848875
}
849876

850877
impl<'a, T: Clone> Option<&'a T> {

Diff for: src/libcore/task/wake.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ impl LocalWaker {
113113
/// but you otherwise shouldn't call it directly.
114114
///
115115
/// If you're working with the standard library then it's recommended to
116-
/// use the `LocalWaker::from` function instead which works with the safe
117-
/// `Rc` type and the safe `LocalWake` trait.
116+
/// use the `local_waker_from_nonlocal` or `local_waker` to convert a `Waker`
117+
/// into a `LocalWaker`.
118118
///
119119
/// For this function to be used safely, it must be sound to call `inner.wake_local()`
120120
/// on the current thread.
@@ -197,9 +197,7 @@ impl Drop for LocalWaker {
197197
/// customization.
198198
///
199199
/// When using `std`, a default implementation of the `UnsafeWake` trait is provided for
200-
/// `Arc<T>` where `T: Wake` and `Rc<T>` where `T: LocalWake`.
201-
///
202-
/// Although the methods on `UnsafeWake` take pointers rather than references,
200+
/// `Arc<T>` where `T: Wake`.
203201
pub unsafe trait UnsafeWake: Send + Sync {
204202
/// Creates a clone of this `UnsafeWake` and stores it behind a `Waker`.
205203
///

Diff for: src/libcore/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#![feature(reverse_bits)]
4545
#![feature(iterator_find_map)]
4646
#![feature(slice_internals)]
47+
#![feature(option_replace)]
4748

4849
extern crate core;
4950
extern crate test;

Diff for: src/libcore/tests/option.rs

+15
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,18 @@ fn test_try() {
297297
}
298298
assert_eq!(try_option_err(), Err(NoneError));
299299
}
300+
301+
#[test]
302+
fn test_replace() {
303+
let mut x = Some(2);
304+
let old = x.replace(5);
305+
306+
assert_eq!(x, Some(5));
307+
assert_eq!(old, Some(2));
308+
309+
let mut x = None;
310+
let old = x.replace(3);
311+
312+
assert_eq!(x, Some(3));
313+
assert_eq!(old, None);
314+
}

Diff for: src/libfmt_macros/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
//! Parsing does not happen at runtime: structures of `std::fmt::rt` are
1515
//! generated instead.
1616
17+
#![deny(bare_trait_objects)]
18+
1719
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
1820
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
1921
html_root_url = "https://doc.rust-lang.org/nightly/",

Diff for: src/libgraphviz/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@
283283
//!
284284
//! * [DOT language](http://www.graphviz.org/doc/info/lang.html)
285285
286+
#![deny(bare_trait_objects)]
287+
286288
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
287289
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
288290
html_root_url = "https://doc.rust-lang.org/nightly/",

Diff for: src/libpanic_abort/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
2222
#![panic_runtime]
2323
#![allow(unused_features)]
24+
#![deny(bare_trait_objects)]
2425

2526
#![feature(core_intrinsics)]
2627
#![feature(libc)]

Diff for: src/libproc_macro/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//! See [the book](../book/first-edition/procedural-macros.html) for more.
2323
2424
#![stable(feature = "proc_macro_lib", since = "1.15.0")]
25+
#![deny(bare_trait_objects)]
2526
#![deny(missing_docs)]
2627
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2728
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",

Diff for: src/libprofiler_builtins/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
reason = "internal implementation detail of rustc right now",
1616
issue = "0")]
1717
#![allow(unused_features)]
18+
#![deny(bare_trait_objects)]
1819
#![feature(staged_api)]

Diff for: src/librustc/infer/error_reporting/mod.rs

+64-28
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePa
6060
use super::region_constraints::GenericKind;
6161
use super::lexical_region_resolve::RegionResolutionError;
6262

63-
use std::fmt;
63+
use std::{cmp, fmt};
6464
use hir;
6565
use hir::map as hir_map;
6666
use hir::def_id::DefId;
6767
use middle::region;
6868
use traits::{ObligationCause, ObligationCauseCode};
69-
use ty::{self, Region, Ty, TyCtxt, TypeFoldable, TypeVariants};
69+
use ty::{self, subst::Subst, Region, Ty, TyCtxt, TypeFoldable, TypeVariants};
7070
use ty::error::TypeError;
7171
use syntax::ast::DUMMY_NODE_ID;
7272
use syntax_pos::{Pos, Span};
@@ -193,32 +193,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
193193

194194
let scope = region.free_region_binding_scope(self);
195195
let node = self.hir.as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID);
196-
let unknown;
197196
let tag = match self.hir.find(node) {
198197
Some(hir_map::NodeBlock(_)) | Some(hir_map::NodeExpr(_)) => "body",
199198
Some(hir_map::NodeItem(it)) => Self::item_scope_tag(&it),
200199
Some(hir_map::NodeTraitItem(it)) => Self::trait_item_scope_tag(&it),
201200
Some(hir_map::NodeImplItem(it)) => Self::impl_item_scope_tag(&it),
202-
203-
// this really should not happen, but it does:
204-
// FIXME(#27942)
205-
Some(_) => {
206-
unknown = format!(
207-
"unexpected node ({}) for scope {:?}. \
208-
Please report a bug.",
209-
self.hir.node_to_string(node),
210-
scope
211-
);
212-
&unknown
213-
}
214-
None => {
215-
unknown = format!(
216-
"unknown node for scope {:?}. \
217-
Please report a bug.",
218-
scope
219-
);
220-
&unknown
221-
}
201+
_ => unreachable!()
222202
};
223203
let (prefix, span) = match *region {
224204
ty::ReEarlyBound(ref br) => {
@@ -672,6 +652,43 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
672652
}
673653
}
674654

655+
/// For generic types with parameters with defaults, remove the parameters corresponding to
656+
/// the defaults. This repeats a lot of the logic found in `PrintContext::parameterized`.
657+
fn strip_generic_default_params(
658+
&self,
659+
def_id: DefId,
660+
substs: &ty::subst::Substs<'tcx>
661+
) -> &'tcx ty::subst::Substs<'tcx> {
662+
let generics = self.tcx.generics_of(def_id);
663+
let mut num_supplied_defaults = 0;
664+
let mut type_params = generics.params.iter().rev().filter_map(|param| match param.kind {
665+
ty::GenericParamDefKind::Lifetime => None,
666+
ty::GenericParamDefKind::Type { has_default, .. } => {
667+
Some((param.def_id, has_default))
668+
}
669+
}).peekable();
670+
let has_default = {
671+
let has_default = type_params.peek().map(|(_, has_default)| has_default);
672+
*has_default.unwrap_or(&false)
673+
};
674+
if has_default {
675+
let types = substs.types().rev();
676+
for ((def_id, has_default), actual) in type_params.zip(types) {
677+
if !has_default {
678+
break;
679+
}
680+
if self.tcx.type_of(def_id).subst(self.tcx, substs) != actual {
681+
break;
682+
}
683+
num_supplied_defaults += 1;
684+
}
685+
}
686+
let len = generics.params.len();
687+
let mut generics = generics.clone();
688+
generics.params.truncate(len - num_supplied_defaults);
689+
substs.truncate_to(self.tcx, &generics)
690+
}
691+
675692
/// Compare two given types, eliding parts that are the same between them and highlighting
676693
/// relevant differences, and return two representation of those types for highlighted printing.
677694
fn cmp(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) -> (DiagnosticStyledString, DiagnosticStyledString) {
@@ -713,6 +730,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
713730

714731
match (&t1.sty, &t2.sty) {
715732
(&ty::TyAdt(def1, sub1), &ty::TyAdt(def2, sub2)) => {
733+
let sub_no_defaults_1 = self.strip_generic_default_params(def1.did, sub1);
734+
let sub_no_defaults_2 = self.strip_generic_default_params(def2.did, sub2);
716735
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
717736
let path1 = self.tcx.item_path_str(def1.did.clone());
718737
let path2 = self.tcx.item_path_str(def2.did.clone());
@@ -728,8 +747,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
728747
values.0.push_normal(path1);
729748
values.1.push_normal(path2);
730749

750+
// Avoid printing out default generic parameters that are common to both
751+
// types.
752+
let len1 = sub_no_defaults_1.len();
753+
let len2 = sub_no_defaults_2.len();
754+
let common_len = cmp::min(len1, len2);
755+
let remainder1: Vec<_> = sub1.types().skip(common_len).collect();
756+
let remainder2: Vec<_> = sub2.types().skip(common_len).collect();
757+
let common_default_params =
758+
remainder1.iter().rev().zip(remainder2.iter().rev())
759+
.filter(|(a, b)| a == b).count();
760+
let len = sub1.len() - common_default_params;
761+
731762
// Only draw `<...>` if there're lifetime/type arguments.
732-
let len = sub1.len();
733763
if len > 0 {
734764
values.0.push_normal("<");
735765
values.1.push_normal("<");
@@ -774,7 +804,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
774804
// ^ elided type as this type argument was the same in both sides
775805
let type_arguments = sub1.types().zip(sub2.types());
776806
let regions_len = sub1.regions().collect::<Vec<_>>().len();
777-
for (i, (ta1, ta2)) in type_arguments.enumerate() {
807+
for (i, (ta1, ta2)) in type_arguments.take(len).enumerate() {
778808
let i = i + regions_len;
779809
if ta1 == ta2 {
780810
values.0.push_normal("_");
@@ -804,7 +834,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
804834
&mut values.0,
805835
&mut values.1,
806836
path1.clone(),
807-
sub1,
837+
sub_no_defaults_1,
808838
path2.clone(),
809839
&t2,
810840
).is_some()
@@ -816,8 +846,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
816846
// Bar<Qux>
817847
// Foo<Bar<Qux>>
818848
// ------- this type argument is exactly the same as the other type
819-
if self.cmp_type_arg(&mut values.1, &mut values.0, path2, sub2, path1, &t1)
820-
.is_some()
849+
if self.cmp_type_arg(
850+
&mut values.1,
851+
&mut values.0,
852+
path2,
853+
sub_no_defaults_2,
854+
path1,
855+
&t1,
856+
).is_some()
821857
{
822858
return values;
823859
}

Diff for: src/librustc/middle/dead.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,17 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
567567
hir::ItemImpl(..) => self.tcx.sess.codemap().def_span(item.span),
568568
_ => item.span,
569569
};
570+
let participle = match item.node {
571+
hir::ItemFn(..) => "called",
572+
hir::ItemStruct(..) => "constructed",
573+
_ => "used"
574+
};
570575
self.warn_dead_code(
571576
item.id,
572577
span,
573578
item.name,
574579
item.node.descriptive_variant(),
575-
"used",
580+
participle,
576581
);
577582
} else {
578583
// Only continue if we didn't warn
@@ -622,7 +627,8 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
622627
hir::ImplItemKind::Method(_, body_id) => {
623628
if !self.symbol_is_live(impl_item.id, None) {
624629
let span = self.tcx.sess.codemap().def_span(impl_item.span);
625-
self.warn_dead_code(impl_item.id, span, impl_item.ident.name, "method", "used");
630+
self.warn_dead_code(impl_item.id, span, impl_item.ident.name,
631+
"method", "called");
626632
}
627633
self.visit_nested_body(body_id)
628634
}

0 commit comments

Comments
 (0)