Skip to content

Commit e28ef22

Browse files
committed
Auto merge of #49875 - kennytm:rollup, r=kennytm
Rollup of 14 pull requests Successful merges: - #49525 (Use sort_by_cached_key where appropriate) - #49575 (Stabilize `Option::filter`.) - #49614 (in which the non-shorthand patterns lint keeps its own counsel in macros) - #49665 (Small nits to make couple of tests pass on mips targets.) - #49781 (add regression test for #16223 (NLL): use of collaterally moved value) - #49795 (Properly look for uninhabitedness of variants in niche-filling check) - #49809 (Stop emitting color codes on TERM=dumb) - #49856 (Do not uppercase-lint #[no_mangle] statics) - #49863 (fixed typo) - #49857 (Fix "fp" target feature for AArch64) - #49849 (Add --enable-debug flag to musl CI build script) - #49734 (proc_macro: Generalize `FromIterator` impl) - #49730 (Fix ICE with impl Trait) - #48270 (Replace `structurally_resolved_type` in casts check.) Failed merges:
2 parents ad610be + 9f6e5ae commit e28ef22

Some content is hidden

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

43 files changed

+243
-64
lines changed

src/bootstrap/compile.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,9 @@ pub fn stream_cargo(
11671167
cargo.arg("--message-format").arg("json")
11681168
.stdout(Stdio::piped());
11691169

1170-
if stderr_isatty() && build.ci_env == CiEnv::None {
1170+
if stderr_isatty() && build.ci_env == CiEnv::None &&
1171+
// if the terminal is reported as dumb, then we don't want to enable color for rustc
1172+
env::var_os("TERM").map(|t| t != *"dumb").unwrap_or(true) {
11711173
// since we pass message-format=json to cargo, we need to tell the rustc
11721174
// wrapper to give us colored output if necessary. This is because we
11731175
// only want Cargo's JSON output, not rustcs.

src/ci/docker/scripts/musl.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if [ ! -d $MUSL ]; then
4040
fi
4141

4242
cd $MUSL
43-
./configure --disable-shared --prefix=/musl-$TAG $@
43+
./configure --enable-optimize --enable-debug --disable-shared --prefix=/musl-$TAG $@
4444
if [ "$TAG" = "i586" -o "$TAG" = "i686" ]; then
4545
hide_output make -j$(nproc) AR=ar RANLIB=ranlib
4646
else

src/liballoc/slice.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,7 @@ impl<T> [T] {
14001400
let sz_usize = mem::size_of::<(K, usize)>();
14011401

14021402
let len = self.len();
1403+
if len < 2 { return }
14031404
if sz_u8 < sz_u16 && len <= ( u8::MAX as usize) { return sort_by_key!( u8, self, f) }
14041405
if sz_u16 < sz_u32 && len <= (u16::MAX as usize) { return sort_by_key!(u16, self, f) }
14051406
if sz_u32 < sz_usize && len <= (u32::MAX as usize) { return sort_by_key!(u32, self, f) }

src/libcore/option.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,6 @@ impl<T> Option<T> {
628628
/// # Examples
629629
///
630630
/// ```rust
631-
/// #![feature(option_filter)]
632-
///
633631
/// fn is_even(n: &i32) -> bool {
634632
/// n % 2 == 0
635633
/// }
@@ -639,7 +637,7 @@ impl<T> Option<T> {
639637
/// assert_eq!(Some(4).filter(is_even), Some(4));
640638
/// ```
641639
#[inline]
642-
#[unstable(feature = "option_filter", issue = "45860")]
640+
#[stable(feature = "option_filter", since = "1.27.0")]
643641
pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self {
644642
if let Some(x) = self {
645643
if predicate(&x) {

src/libproc_macro/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,16 @@ impl From<TokenTree> for TokenStream {
140140
#[unstable(feature = "proc_macro", issue = "38356")]
141141
impl iter::FromIterator<TokenTree> for TokenStream {
142142
fn from_iter<I: IntoIterator<Item = TokenTree>>(trees: I) -> Self {
143+
trees.into_iter().map(TokenStream::from).collect()
144+
}
145+
}
146+
147+
#[unstable(feature = "proc_macro", issue = "38356")]
148+
impl iter::FromIterator<TokenStream> for TokenStream {
149+
fn from_iter<I: IntoIterator<Item = TokenStream>>(streams: I) -> Self {
143150
let mut builder = tokenstream::TokenStreamBuilder::new();
144-
for tree in trees {
145-
builder.push(tree.to_internal());
151+
for stream in streams {
152+
builder.push(stream.0);
146153
}
147154
TokenStream(builder.build())
148155
}

src/librustc/infer/anon_types/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,14 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx>
533533
match r {
534534
// ignore bound regions that appear in the type (e.g., this
535535
// would ignore `'r` in a type like `for<'r> fn(&'r u32)`.
536-
ty::ReLateBound(..) => return r,
536+
ty::ReLateBound(..) |
537537

538538
// ignore `'static`, as that can appear anywhere
539-
ty::ReStatic => return r,
539+
ty::ReStatic |
540+
541+
// ignore `ReScope`, as that can appear anywhere
542+
// See `src/test/run-pass/issue-49556.rs` for example.
543+
ty::ReScope(..) => return r,
540544

541545
_ => { }
542546
}

src/librustc/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
181181
self.msg_span_from_early_bound_and_free_regions(region)
182182
},
183183
ty::ReStatic => ("the static lifetime".to_owned(), None),
184-
_ => bug!(),
184+
_ => bug!("{:?}", region),
185185
}
186186
}
187187

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#![feature(refcell_replace_swap)]
6161
#![feature(rustc_diagnostic_macros)]
6262
#![feature(slice_patterns)]
63+
#![feature(slice_sort_by_cached_key)]
6364
#![feature(specialization)]
6465
#![feature(unboxed_closures)]
6566
#![feature(trace_macros)]

src/librustc/middle/cstore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ pub fn used_crates(tcx: TyCtxt, prefer: LinkagePreference)
401401
.collect::<Vec<_>>();
402402
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE);
403403
Lrc::make_mut(&mut ordering).reverse();
404-
libs.sort_by_key(|&(a, _)| {
404+
libs.sort_by_cached_key(|&(a, _)| {
405405
ordering.iter().position(|x| *x == a)
406406
});
407407
libs

src/librustc/ty/cast.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use syntax::ast;
2020
pub enum IntTy {
2121
U(ast::UintTy),
2222
I,
23-
Ivar,
2423
CEnum,
2524
Bool,
2625
Char
@@ -64,7 +63,7 @@ impl<'tcx> CastTy<'tcx> {
6463
ty::TyBool => Some(CastTy::Int(IntTy::Bool)),
6564
ty::TyChar => Some(CastTy::Int(IntTy::Char)),
6665
ty::TyInt(_) => Some(CastTy::Int(IntTy::I)),
67-
ty::TyInfer(ty::InferTy::IntVar(_)) => Some(CastTy::Int(IntTy::Ivar)),
66+
ty::TyInfer(ty::InferTy::IntVar(_)) => Some(CastTy::Int(IntTy::I)),
6867
ty::TyInfer(ty::InferTy::FloatVar(_)) => Some(CastTy::Float),
6968
ty::TyUint(u) => Some(CastTy::Int(IntTy::U(u))),
7069
ty::TyFloat(_) => Some(CastTy::Float),

src/librustc/ty/layout.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1471,10 +1471,10 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
14711471

14721472
// Find one non-ZST variant.
14731473
'variants: for (v, fields) in variants.iter().enumerate() {
1474+
if fields.iter().any(|f| f.abi == Abi::Uninhabited) {
1475+
continue 'variants;
1476+
}
14741477
for f in fields {
1475-
if f.abi == Abi::Uninhabited {
1476-
continue 'variants;
1477-
}
14781478
if !f.is_zst() {
14791479
if dataful_variant.is_none() {
14801480
dataful_variant = Some(v);

src/librustc_driver/lib.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#![cfg_attr(unix, feature(libc))]
2323
#![feature(quote)]
2424
#![feature(rustc_diagnostic_macros)]
25+
#![feature(slice_sort_by_cached_key)]
2526
#![feature(set_stdio)]
2627
#![feature(rustc_stack_internals)]
2728

@@ -82,7 +83,6 @@ use rustc_trans_utils::trans_crate::TransCrate;
8283
use serialize::json::ToJson;
8384

8485
use std::any::Any;
85-
use std::cmp::Ordering::Equal;
8686
use std::cmp::max;
8787
use std::default::Default;
8888
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
@@ -1176,13 +1176,8 @@ Available lint options:
11761176

11771177
fn sort_lints(sess: &Session, lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> {
11781178
let mut lints: Vec<_> = lints.into_iter().map(|(x, _)| x).collect();
1179-
lints.sort_by(|x: &&Lint, y: &&Lint| {
1180-
match x.default_level(sess).cmp(&y.default_level(sess)) {
1181-
// The sort doesn't case-fold but it's doubtful we care.
1182-
Equal => x.name.cmp(y.name),
1183-
r => r,
1184-
}
1185-
});
1179+
// The sort doesn't case-fold but it's doubtful we care.
1180+
lints.sort_by_cached_key(|x: &&Lint| (x.default_level(sess), x.name));
11861181
lints
11871182
}
11881183

src/librustc_lint/bad_style.rs

+3
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
368368
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
369369
match it.node {
370370
hir::ItemStatic(..) => {
371+
if attr::find_by_name(&it.attrs, "no_mangle").is_some() {
372+
return;
373+
}
371374
NonUpperCaseGlobals::check_upper_case(cx, "static variable", it.name, it.span);
372375
}
373376
hir::ItemConst(..) => {

src/librustc_lint/builtin.rs

+6
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
173173
}
174174
if let PatKind::Binding(_, _, name, None) = fieldpat.node.pat.node {
175175
if name.node == fieldpat.node.name {
176+
if let Some(_) = fieldpat.span.ctxt().outer().expn_info() {
177+
// Don't lint if this is a macro expansion: macro authors
178+
// shouldn't have to worry about this kind of style issue
179+
// (Issue #49588)
180+
return;
181+
}
176182
let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS,
177183
fieldpat.span,
178184
&format!("the `{}:` in this pattern is redundant",

src/librustc_metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1414,15 +1414,15 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
14141414
let mut all_impls: Vec<_> = visitor.impls.into_iter().collect();
14151415

14161416
// Bring everything into deterministic order for hashing
1417-
all_impls.sort_unstable_by_key(|&(trait_def_id, _)| {
1417+
all_impls.sort_by_cached_key(|&(trait_def_id, _)| {
14181418
tcx.def_path_hash(trait_def_id)
14191419
});
14201420

14211421
let all_impls: Vec<_> = all_impls
14221422
.into_iter()
14231423
.map(|(trait_def_id, mut impls)| {
14241424
// Bring everything into deterministic order for hashing
1425-
impls.sort_unstable_by_key(|&def_index| {
1425+
impls.sort_by_cached_key(|&def_index| {
14261426
tcx.hir.definitions().def_path_hash(def_index)
14271427
});
14281428

src/librustc_metadata/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![feature(macro_lifetime_matcher)]
2121
#![feature(quote)]
2222
#![feature(rustc_diagnostic_macros)]
23+
#![feature(slice_sort_by_cached_key)]
2324
#![feature(specialization)]
2425
#![feature(rustc_private)]
2526

src/librustc_mir/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
1515
*/
1616

1717
#![feature(slice_patterns)]
18+
#![feature(slice_sort_by_cached_key)]
1819
#![feature(from_ref)]
1920
#![feature(box_patterns)]
2021
#![feature(box_syntax)]

src/librustc_mir/monomorphize/partitioning.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ use rustc::ty::{self, TyCtxt, InstanceDef};
112112
use rustc::ty::item_path::characteristic_def_id_of_type;
113113
use rustc::util::nodemap::{FxHashMap, FxHashSet};
114114
use std::collections::hash_map::Entry;
115+
use std::cmp;
115116
use syntax::ast::NodeId;
116117
use syntax::symbol::{Symbol, InternedString};
117118
use rustc::mir::mono::MonoItem;
118119
use monomorphize::item::{MonoItemExt, InstantiationMode};
119-
use core::usize;
120120

121121
pub use rustc::mir::mono::CodegenUnit;
122122

@@ -189,11 +189,9 @@ pub trait CodegenUnitExt<'tcx> {
189189
}, item.symbol_name(tcx))
190190
}
191191

192-
let items: Vec<_> = self.items().iter().map(|(&i, &l)| (i, l)).collect();
193-
let mut items : Vec<_> = items.iter()
194-
.map(|il| (il, item_sort_key(tcx, il.0))).collect();
195-
items.sort_by(|&(_, ref key1), &(_, ref key2)| key1.cmp(key2));
196-
items.into_iter().map(|(&item_linkage, _)| item_linkage).collect()
192+
let mut items: Vec<_> = self.items().iter().map(|(&i, &l)| (i, l)).collect();
193+
items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i));
194+
items
197195
}
198196
}
199197

@@ -509,7 +507,7 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
509507
// Merge the two smallest codegen units until the target size is reached.
510508
while codegen_units.len() > target_cgu_count {
511509
// Sort small cgus to the back
512-
codegen_units.sort_by_key(|cgu| usize::MAX - cgu.size_estimate());
510+
codegen_units.sort_by_cached_key(|cgu| cmp::Reverse(cgu.size_estimate()));
513511
let mut smallest = codegen_units.pop().unwrap();
514512
let second_smallest = codegen_units.last_mut().unwrap();
515513

src/librustc_resolve/lib.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
html_root_url = "https://doc.rust-lang.org/nightly/")]
1414

1515
#![feature(rustc_diagnostic_macros)]
16+
#![feature(slice_sort_by_cached_key)]
1617

1718
#[macro_use]
1819
extern crate log;
@@ -1149,13 +1150,9 @@ impl<'a> ModuleData<'a> {
11491150

11501151
fn for_each_child_stable<F: FnMut(Ident, Namespace, &'a NameBinding<'a>)>(&self, mut f: F) {
11511152
let resolutions = self.resolutions.borrow();
1152-
let mut resolutions = resolutions.iter().map(|(&(ident, ns), &resolution)| {
1153-
// Pre-compute keys for sorting
1154-
(ident.name.as_str(), ns, ident, resolution)
1155-
})
1156-
.collect::<Vec<_>>();
1157-
resolutions.sort_unstable_by_key(|&(str, ns, ..)| (str, ns));
1158-
for &(_, ns, ident, resolution) in resolutions.iter() {
1153+
let mut resolutions = resolutions.iter().collect::<Vec<_>>();
1154+
resolutions.sort_by_cached_key(|&(&(ident, ns), _)| (ident.name.as_str(), ns));
1155+
for &(&(ident, ns), &resolution) in resolutions.iter() {
11591156
resolution.borrow().binding.map(|binding| f(ident, ns, binding));
11601157
}
11611158
}
@@ -3340,7 +3337,9 @@ impl<'a> Resolver<'a> {
33403337
let is_mod = |def| match def { Def::Mod(..) => true, _ => false };
33413338
let mut candidates =
33423339
self.lookup_import_candidates(name, TypeNS, is_mod);
3343-
candidates.sort_by_key(|c| (c.path.segments.len(), c.path.to_string()));
3340+
candidates.sort_by_cached_key(|c| {
3341+
(c.path.segments.len(), c.path.to_string())
3342+
});
33443343
if let Some(candidate) = candidates.get(0) {
33453344
format!("Did you mean `{}`?", candidate.path)
33463345
} else {
@@ -3578,7 +3577,7 @@ impl<'a> Resolver<'a> {
35783577

35793578
let name = path[path.len() - 1].name;
35803579
// Make sure error reporting is deterministic.
3581-
names.sort_by_key(|name| name.as_str());
3580+
names.sort_by_cached_key(|name| name.as_str());
35823581
match find_best_match_for_name(names.iter(), &name.as_str(), None) {
35833582
Some(found) if found != name => Some(found),
35843583
_ => None,

src/librustc_trans/base.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ use std::ffi::CString;
8282
use std::str;
8383
use std::sync::Arc;
8484
use std::time::{Instant, Duration};
85-
use std::{i32, usize};
85+
use std::i32;
86+
use std::cmp;
8687
use std::sync::mpsc;
8788
use syntax_pos::Span;
8889
use syntax_pos::symbol::InternedString;
@@ -830,7 +831,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
830831
// a bit more efficiently.
831832
let codegen_units = {
832833
let mut codegen_units = codegen_units;
833-
codegen_units.sort_by_key(|cgu| usize::MAX - cgu.size_estimate());
834+
codegen_units.sort_by_cached_key(|cgu| cmp::Reverse(cgu.size_estimate()));
834835
codegen_units
835836
};
836837

src/librustc_trans/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#![feature(libc)]
2727
#![feature(quote)]
2828
#![feature(rustc_diagnostic_macros)]
29+
#![feature(slice_sort_by_cached_key)]
2930
#![feature(optin_builtin_traits)]
3031
#![feature(inclusive_range_fields)]
3132
#![feature(underscore_lifetimes)]

src/librustc_trans/llvm_util.rs

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub fn to_llvm_feature<'a>(sess: &Session, s: &'a str) -> &'a str {
134134
("x86", "pclmulqdq") => "pclmul",
135135
("x86", "rdrand") => "rdrnd",
136136
("x86", "bmi1") => "bmi",
137+
("aarch64", "fp") => "fp-armv8",
137138
("aarch64", "fp16") => "fullfp16",
138139
(_, s) => s,
139140
}

src/librustc_typeck/check/cast.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
486486
ty::TypeVariants::TyInfer(t) => {
487487
match t {
488488
ty::InferTy::IntVar(_) |
489-
ty::InferTy::FloatVar(_) |
490-
ty::InferTy::FreshIntTy(_) |
491-
ty::InferTy::FreshFloatTy(_) => {
492-
Err(CastError::NeedDeref)
493-
}
489+
ty::InferTy::FloatVar(_) => Err(CastError::NeedDeref),
494490
_ => Err(CastError::NeedViaPtr),
495491
}
496492
}

src/librustc_typeck/check/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
799799
.collect();
800800

801801
// sort them by the name so we have a stable result
802-
names.sort_by_key(|n| n.as_str());
802+
names.sort_by_cached_key(|n| n.as_str());
803803
names
804804
}
805805

src/librustc_typeck/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ This API is completely unstable and subject to change.
7676
#![feature(crate_visibility_modifier)]
7777
#![feature(from_ref)]
7878
#![feature(exhaustive_patterns)]
79-
#![feature(option_filter)]
8079
#![feature(quote)]
8180
#![feature(refcell_replace_swap)]
8281
#![feature(rustc_diagnostic_macros)]
8382
#![feature(slice_patterns)]
83+
#![feature(slice_sort_by_cached_key)]
8484
#![feature(dyn_trait)]
8585

8686
#[macro_use] extern crate log;

src/librustdoc/clean/auto_trait.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1437,9 +1437,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
14371437
// involved (impls rarely have more than a few bounds) means that it
14381438
// shouldn't matter in practice.
14391439
fn unstable_debug_sort<T: Debug>(&self, vec: &mut Vec<T>) {
1440-
vec.sort_unstable_by(|first, second| {
1441-
format!("{:?}", first).cmp(&format!("{:?}", second))
1442-
});
1440+
vec.sort_by_cached_key(|x| format!("{:?}", x))
14431441
}
14441442

14451443
fn is_fn_ty(&self, tcx: &TyCtxt, ty: &Type) -> bool {

src/librustdoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#![feature(box_syntax)]
2020
#![feature(fs_read_write)]
2121
#![feature(set_stdio)]
22+
#![feature(slice_sort_by_cached_key)]
2223
#![feature(test)]
2324
#![feature(unicode)]
2425
#![feature(vec_remove_item)]

0 commit comments

Comments
 (0)