From 7719f534196c9fe5216161e313ad7624f1beadee Mon Sep 17 00:00:00 2001 From: "leonardo.yvens" Date: Fri, 16 Feb 2018 11:16:41 -0200 Subject: [PATCH 01/26] Replace `structurally_resolved_type` in casts check. The behaviour of `resolve_type_vars_if_possible` is simpler and infallible. --- src/librustc/ty/cast.rs | 3 +-- src/librustc_typeck/check/cast.rs | 10 +++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/librustc/ty/cast.rs b/src/librustc/ty/cast.rs index c118b7a4692e5..3ba79d91964ab 100644 --- a/src/librustc/ty/cast.rs +++ b/src/librustc/ty/cast.rs @@ -20,7 +20,6 @@ use syntax::ast; pub enum IntTy { U(ast::UintTy), I, - Ivar, CEnum, Bool, Char @@ -64,7 +63,7 @@ impl<'tcx> CastTy<'tcx> { ty::TyBool => Some(CastTy::Int(IntTy::Bool)), ty::TyChar => Some(CastTy::Int(IntTy::Char)), ty::TyInt(_) => Some(CastTy::Int(IntTy::I)), - ty::TyInfer(ty::InferTy::IntVar(_)) => Some(CastTy::Int(IntTy::Ivar)), + ty::TyInfer(ty::InferTy::IntVar(_)) => Some(CastTy::Int(IntTy::I)), ty::TyInfer(ty::InferTy::FloatVar(_)) => Some(CastTy::Float), ty::TyUint(u) => Some(CastTy::Int(IntTy::U(u))), ty::TyFloat(_) => Some(CastTy::Float), diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index e4bad8349ea2b..31f418df902be 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -389,8 +389,8 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { } pub fn check(mut self, fcx: &FnCtxt<'a, 'gcx, 'tcx>) { - self.expr_ty = fcx.structurally_resolved_type(self.span, self.expr_ty); - self.cast_ty = fcx.structurally_resolved_type(self.span, self.cast_ty); + self.expr_ty = fcx.resolve_type_vars_if_possible(&self.expr_ty); + self.cast_ty = fcx.resolve_type_vars_if_possible(&self.cast_ty); debug!("check_cast({}, {:?} as {:?})", self.expr.id, @@ -484,11 +484,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { ty::TypeVariants::TyInfer(t) => { match t { ty::InferTy::IntVar(_) | - ty::InferTy::FloatVar(_) | - ty::InferTy::FreshIntTy(_) | - ty::InferTy::FreshFloatTy(_) => { - Err(CastError::NeedDeref) - } + ty::InferTy::FloatVar(_) => Err(CastError::NeedDeref), _ => Err(CastError::NeedViaPtr), } } From 7353ef744e1ff4e8b511f77969eab316e8e06f5b Mon Sep 17 00:00:00 2001 From: "leonardo.yvens" Date: Sun, 18 Feb 2018 10:39:26 -0300 Subject: [PATCH 02/26] Replace `structurally_resolve_type` in unary expr check. `resolve_type_vars_with_obligations` is the same but doesn't error on unresolved type variables. In theory this could make more code compile because we don't error or could ommit an otherwise useful error. In practice I couldn't observe any effect. --- src/librustc_typeck/check/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 69879bbe85d6e..e5d3e84e840d2 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3639,7 +3639,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { needs); if !oprnd_t.references_error() { - oprnd_t = self.structurally_resolved_type(expr.span, oprnd_t); + oprnd_t = self.resolve_type_vars_with_obligations(&oprnd_t); match unop { hir::UnDeref => { if let Some(mt) = oprnd_t.builtin_deref(true) { From 0a5a5c3418c56546c574b7698d9158ef16aa174e Mon Sep 17 00:00:00 2001 From: "leonardo.yvens" Date: Thu, 22 Mar 2018 17:41:07 -0300 Subject: [PATCH 03/26] revert making casts atomic, test order dependency --- src/librustc_typeck/check/cast.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 2 +- src/test/run-pass/cast.rs | 5 +++++ src/test/ui/order-dependent-cast-inference.rs | 18 ++++++++++++++++++ .../ui/order-dependent-cast-inference.stderr | 13 +++++++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/order-dependent-cast-inference.rs create mode 100644 src/test/ui/order-dependent-cast-inference.stderr diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 31f418df902be..7ebacc92babf8 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -389,8 +389,8 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { } pub fn check(mut self, fcx: &FnCtxt<'a, 'gcx, 'tcx>) { - self.expr_ty = fcx.resolve_type_vars_if_possible(&self.expr_ty); - self.cast_ty = fcx.resolve_type_vars_if_possible(&self.cast_ty); + self.expr_ty = fcx.structurally_resolved_type(self.span, self.expr_ty); + self.cast_ty = fcx.structurally_resolved_type(self.span, self.cast_ty); debug!("check_cast({}, {:?} as {:?})", self.expr.id, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e5d3e84e840d2..69879bbe85d6e 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3639,7 +3639,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { needs); if !oprnd_t.references_error() { - oprnd_t = self.resolve_type_vars_with_obligations(&oprnd_t); + oprnd_t = self.structurally_resolved_type(expr.span, oprnd_t); match unop { hir::UnDeref => { if let Some(mt) = oprnd_t.builtin_deref(true) { diff --git a/src/test/run-pass/cast.rs b/src/test/run-pass/cast.rs index bb60626a4bf02..80fa5362a8be9 100644 --- a/src/test/run-pass/cast.rs +++ b/src/test/run-pass/cast.rs @@ -19,4 +19,9 @@ pub fn main() { assert_eq!(i as u8 as i8, 'Q' as u8 as i8); assert_eq!(0x51 as char, 'Q'); assert_eq!(0 as u32, false as u32); + + // Test that `_` is correctly inferred. + let x = &"hello"; + let mut y = x as *const _; + y = 0 as *const _; } diff --git a/src/test/ui/order-dependent-cast-inference.rs b/src/test/ui/order-dependent-cast-inference.rs new file mode 100644 index 0000000000000..afcd402343b25 --- /dev/null +++ b/src/test/ui/order-dependent-cast-inference.rs @@ -0,0 +1,18 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + // Tests case where inference fails due to the order in which casts are checked. + // Ideally this would compile, see #48270. + let x = &"hello"; + let mut y = 0 as *const _; + //~^ ERROR cannot cast to a pointer of an unknown kind + y = x as *const _; +} diff --git a/src/test/ui/order-dependent-cast-inference.stderr b/src/test/ui/order-dependent-cast-inference.stderr new file mode 100644 index 0000000000000..556acc87cffaf --- /dev/null +++ b/src/test/ui/order-dependent-cast-inference.stderr @@ -0,0 +1,13 @@ +error[E0641]: cannot cast to a pointer of an unknown kind + --> $DIR/order-dependent-cast-inference.rs:15:17 + | +LL | let mut y = 0 as *const _; + | ^^^^^-------- + | | + | help: consider giving more type information + | + = note: The type information given here is insufficient to check whether the pointer cast is valid + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0641`. From 5152a6f2852f5200665a591bbf59e7e827a68af4 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Sun, 1 Apr 2018 22:11:51 -0600 Subject: [PATCH 04/26] Stabilize `Option::filter`. Fixes #45860 --- src/libcore/option.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 61ef6798b2efb..002fe68ad9b4c 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -639,7 +639,7 @@ impl Option { /// assert_eq!(Some(4).filter(is_even), Some(4)); /// ``` #[inline] - #[unstable(feature = "option_filter", issue = "45860")] + #[stable(feature = "option_filter", since = "1.27.0")] pub fn filter bool>(self, predicate: P) -> Self { if let Some(x) = self { if predicate(&x) { From c7ac32a1c1b35cb2206d9f09549cf93ef8b31e76 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Thu, 5 Apr 2018 00:02:33 -0600 Subject: [PATCH 05/26] Remove uses of option_filter feature --- src/libcore/option.rs | 2 -- src/librustc_typeck/lib.rs | 1 - 2 files changed, 3 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 002fe68ad9b4c..0dfdabee03182 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -628,8 +628,6 @@ impl Option { /// # Examples /// /// ```rust - /// #![feature(option_filter)] - /// /// fn is_even(n: &i32) -> bool { /// n % 2 == 0 /// } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 44ecb32a0bf9b..b1431f44cda0e 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -81,7 +81,6 @@ This API is completely unstable and subject to change. #![feature(from_ref)] #![cfg_attr(stage0, feature(match_default_bindings))] #![feature(exhaustive_patterns)] -#![feature(option_filter)] #![feature(quote)] #![feature(refcell_replace_swap)] #![feature(rustc_diagnostic_macros)] From 20c499da0b9a2ea309ea94958e93dc55b3e225ae Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Fri, 6 Apr 2018 23:17:25 +0900 Subject: [PATCH 06/26] Fix ICE with impl Trait --- src/librustc/infer/anon_types/mod.rs | 8 ++++++-- src/test/run-pass/issue-49556.rs | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/test/run-pass/issue-49556.rs diff --git a/src/librustc/infer/anon_types/mod.rs b/src/librustc/infer/anon_types/mod.rs index eb5df697216a3..725ea9734abf4 100644 --- a/src/librustc/infer/anon_types/mod.rs +++ b/src/librustc/infer/anon_types/mod.rs @@ -533,10 +533,14 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx> match r { // ignore bound regions that appear in the type (e.g., this // would ignore `'r` in a type like `for<'r> fn(&'r u32)`. - ty::ReLateBound(..) => return r, + ty::ReLateBound(..) | // ignore `'static`, as that can appear anywhere - ty::ReStatic => return r, + ty::ReStatic | + + // ignore `ReScope`, as that can appear anywhere + // See `src/test/run-pass/issue-49556.rs` for example. + ty::ReScope(..) => return r, _ => { } } diff --git a/src/test/run-pass/issue-49556.rs b/src/test/run-pass/issue-49556.rs new file mode 100644 index 0000000000000..70ccee99f664d --- /dev/null +++ b/src/test/run-pass/issue-49556.rs @@ -0,0 +1,22 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn iter<'a>(data: &'a [usize]) -> impl Iterator + 'a { + data.iter() + .map( + |x| x // fn(&'a usize) -> &'(ReScope) usize + ) + .map( + |x| *x // fn(&'(ReScope) usize) -> usize + ) +} + +fn main() { +} From d985344b933f2ccc07602fdf86fda94bc3e643cf Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 6 Apr 2018 07:44:21 -0700 Subject: [PATCH 07/26] proc_macro: Generalize `FromIterator` impl While never intended to be stable we forgot that trait impls are insta-stable! This construction of `FromIterator` wasn't our first choice of how to stabilize the impl but our hands are tied at this point, so revert back to the original definition of `FromIterator` before #49597 Closes #49725 --- src/libproc_macro/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index 32697e46a08ac..836dc772f0fea 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -141,9 +141,16 @@ impl From for TokenStream { #[unstable(feature = "proc_macro", issue = "38356")] impl iter::FromIterator for TokenStream { fn from_iter>(trees: I) -> Self { + trees.into_iter().map(TokenStream::from).collect() + } +} + +#[unstable(feature = "proc_macro", issue = "38356")] +impl iter::FromIterator for TokenStream { + fn from_iter>(streams: I) -> Self { let mut builder = tokenstream::TokenStreamBuilder::new(); - for tree in trees { - builder.push(tree.to_internal()); + for stream in streams { + builder.push(stream.0); } TokenStream(builder.build()) } From b9e04e51db3495816271c0312eb1e172701957aa Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Sun, 8 Apr 2018 10:34:39 +0900 Subject: [PATCH 08/26] Print region in case of ICE --- src/librustc/infer/error_reporting/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 96c2309882108..8d314e251972d 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -181,7 +181,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.msg_span_from_early_bound_and_free_regions(region) }, ty::ReStatic => ("the static lifetime".to_owned(), None), - _ => bug!(), + _ => bug!("{:?}", region), } } From 5edfb53439e7da99a6a382d6507723f99755c7ce Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 2 Apr 2018 00:43:43 +0200 Subject: [PATCH 09/26] Properly look for uninhabitedness of variants in niche-filling check --- src/librustc/ty/layout.rs | 6 +++--- src/test/run-pass/type-sizes.rs | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 5f9c305d92f04..16d28ff4266ff 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -1471,10 +1471,10 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { // Find one non-ZST variant. 'variants: for (v, fields) in variants.iter().enumerate() { + if fields.iter().any(|f| f.abi == Abi::Uninhabited) { + continue 'variants; + } for f in fields { - if f.abi == Abi::Uninhabited { - continue 'variants; - } if !f.is_zst() { if dataful_variant.is_none() { dataful_variant = Some(v); diff --git a/src/test/run-pass/type-sizes.rs b/src/test/run-pass/type-sizes.rs index 2f50e63153ea4..0bb18d8729a97 100644 --- a/src/test/run-pass/type-sizes.rs +++ b/src/test/run-pass/type-sizes.rs @@ -42,6 +42,12 @@ enum ReorderedEnum { B(u8, u16, u8), } +enum NicheFilledEnumWithInhabitedVariant { + A(&'static ()), + B(&'static (), !), + C, +} + pub fn main() { assert_eq!(size_of::(), 1 as usize); assert_eq!(size_of::(), 4 as usize); @@ -67,4 +73,5 @@ pub fn main() { assert_eq!(size_of::(), 4 as usize); assert_eq!(size_of::(), 4); assert_eq!(size_of::(), 6); + assert_eq!(size_of::(), size_of::<&'static ()>()); } From eacfb330e65ad7f7a8b6bda4a0bafb09eb361396 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 30 Mar 2018 10:23:27 +0100 Subject: [PATCH 10/26] Convert sort_by_key to sort_by_cached_key --- src/librustc/lib.rs | 1 + src/librustc/middle/cstore.rs | 2 +- src/librustc_mir/lib.rs | 1 + src/librustc_mir/monomorphize/partitioning.rs | 2 +- src/librustc_resolve/lib.rs | 7 +++++-- src/librustc_trans/base.rs | 2 +- src/librustc_trans/lib.rs | 1 + src/librustc_typeck/check/method/probe.rs | 2 +- src/librustc_typeck/lib.rs | 1 + 9 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 7da664e6d0255..0b4c3be8b7814 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -61,6 +61,7 @@ #![feature(refcell_replace_swap)] #![feature(rustc_diagnostic_macros)] #![feature(slice_patterns)] +#![feature(slice_sort_by_cached_key)] #![feature(specialization)] #![feature(unboxed_closures)] #![feature(trace_macros)] diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index add9b621596b6..41334a37dbef6 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -401,7 +401,7 @@ pub fn used_crates(tcx: TyCtxt, prefer: LinkagePreference) .collect::>(); let mut ordering = tcx.postorder_cnums(LOCAL_CRATE); Lrc::make_mut(&mut ordering).reverse(); - libs.sort_by_key(|&(a, _)| { + libs.sort_by_cached_key(|&(a, _)| { ordering.iter().position(|x| *x == a) }); libs diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 8762e7550cded..2fe64f492dd8c 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -17,6 +17,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![deny(warnings)] #![feature(slice_patterns)] +#![feature(slice_sort_by_cached_key)] #![feature(from_ref)] #![feature(box_patterns)] #![feature(box_syntax)] diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index da4cb4ec78904..17d1156617da5 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -509,7 +509,7 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning< // Merge the two smallest codegen units until the target size is reached. while codegen_units.len() > target_cgu_count { // Sort small cgus to the back - codegen_units.sort_by_key(|cgu| usize::MAX - cgu.size_estimate()); + codegen_units.sort_by_cached_key(|cgu| usize::MAX - cgu.size_estimate()); let mut smallest = codegen_units.pop().unwrap(); let second_smallest = codegen_units.last_mut().unwrap(); diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 2bf17cd1317d4..c1a7f20feff96 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -14,6 +14,7 @@ #![deny(warnings)] #![feature(rustc_diagnostic_macros)] +#![feature(slice_sort_by_cached_key)] #[macro_use] extern crate log; @@ -3341,7 +3342,9 @@ impl<'a> Resolver<'a> { let is_mod = |def| match def { Def::Mod(..) => true, _ => false }; let mut candidates = self.lookup_import_candidates(name, TypeNS, is_mod); - candidates.sort_by_key(|c| (c.path.segments.len(), c.path.to_string())); + candidates.sort_by_cached_key(|c| { + (c.path.segments.len(), c.path.to_string()) + }); if let Some(candidate) = candidates.get(0) { format!("Did you mean `{}`?", candidate.path) } else { @@ -3579,7 +3582,7 @@ impl<'a> Resolver<'a> { let name = path[path.len() - 1].name; // Make sure error reporting is deterministic. - names.sort_by_key(|name| name.as_str()); + names.sort_by_cached_key(|name| name.as_str()); match find_best_match_for_name(names.iter(), &name.as_str(), None) { Some(found) if found != name => Some(found), _ => None, diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 0329264a3125f..3e60af6ef221a 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -830,7 +830,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // a bit more efficiently. let codegen_units = { let mut codegen_units = codegen_units; - codegen_units.sort_by_key(|cgu| usize::MAX - cgu.size_estimate()); + codegen_units.sort_by_cached_key(|cgu| usize::MAX - cgu.size_estimate()); codegen_units }; diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 344f959c1414c..73c676021ec36 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -27,6 +27,7 @@ #![feature(libc)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] +#![feature(slice_sort_by_cached_key)] #![feature(optin_builtin_traits)] #![feature(inclusive_range_fields)] #![feature(underscore_lifetimes)] diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index fa2022e8cc994..de5709566225c 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -799,7 +799,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { .collect(); // sort them by the name so we have a stable result - names.sort_by_key(|n| n.as_str()); + names.sort_by_cached_key(|n| n.as_str()); names } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 6f71db998bd41..2ead5e9d91306 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -82,6 +82,7 @@ This API is completely unstable and subject to change. #![feature(refcell_replace_swap)] #![feature(rustc_diagnostic_macros)] #![feature(slice_patterns)] +#![feature(slice_sort_by_cached_key)] #![feature(dyn_trait)] #[macro_use] extern crate log; From d3fe534fcf64f35be4285fcd0b04504b3713b628 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 30 Mar 2018 10:40:25 +0100 Subject: [PATCH 11/26] Convert sort_unstable_by_key to sort_by_cached_key --- src/librustc_metadata/encoder.rs | 4 ++-- src/librustc_metadata/lib.rs | 1 + src/librustc_resolve/lib.rs | 10 +++------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 1b208a512e2a4..e40a3057a95cf 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -1414,7 +1414,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { let mut all_impls: Vec<_> = visitor.impls.into_iter().collect(); // Bring everything into deterministic order for hashing - all_impls.sort_unstable_by_key(|&(trait_def_id, _)| { + all_impls.sort_by_cached_key(|&(trait_def_id, _)| { tcx.def_path_hash(trait_def_id) }); @@ -1422,7 +1422,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { .into_iter() .map(|(trait_def_id, mut impls)| { // Bring everything into deterministic order for hashing - impls.sort_unstable_by_key(|&def_index| { + impls.sort_by_cached_key(|&def_index| { tcx.hir.definitions().def_path_hash(def_index) }); diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs index e89b5a7fc1b4e..76a14cf44f2c2 100644 --- a/src/librustc_metadata/lib.rs +++ b/src/librustc_metadata/lib.rs @@ -21,6 +21,7 @@ #![feature(macro_lifetime_matcher)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] +#![feature(slice_sort_by_cached_key)] #![feature(specialization)] #![feature(rustc_private)] diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index c1a7f20feff96..9ca7d1a372b11 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1151,13 +1151,9 @@ impl<'a> ModuleData<'a> { fn for_each_child_stable)>(&self, mut f: F) { let resolutions = self.resolutions.borrow(); - let mut resolutions = resolutions.iter().map(|(&(ident, ns), &resolution)| { - // Pre-compute keys for sorting - (ident.name.as_str(), ns, ident, resolution) - }) - .collect::>(); - resolutions.sort_unstable_by_key(|&(str, ns, ..)| (str, ns)); - for &(_, ns, ident, resolution) in resolutions.iter() { + let mut resolutions = resolutions.iter().collect::>(); + resolutions.sort_by_cached_key(|&(&(ident, ns), _)| (ident.name.as_str(), ns)); + for &(&(ident, ns), &resolution) in resolutions.iter() { resolution.borrow().binding.map(|binding| f(ident, ns, binding)); } } From 5cd0504d10230ec82ad1a6447db590a77b0eadb7 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 30 Mar 2018 10:44:12 +0100 Subject: [PATCH 12/26] Convert sort_unstable_by to sort_by_cached_key --- src/librustdoc/clean/auto_trait.rs | 4 +--- src/librustdoc/lib.rs | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index a87e1df5efc2c..322527839e02e 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -1435,9 +1435,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // involved (impls rarely have more than a few bounds) means that it // shouldn't matter in practice. fn unstable_debug_sort(&self, vec: &mut Vec) { - vec.sort_unstable_by(|first, second| { - format!("{:?}", first).cmp(&format!("{:?}", second)) - }); + vec.sort_by_cached_key(|x| format!("{:?}", x)) } fn is_fn_ty(&self, tcx: &TyCtxt, ty: &Type) -> bool { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 42e87f88fd40d..e34cf6222cf83 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -20,6 +20,7 @@ #![feature(box_syntax)] #![feature(fs_read_write)] #![feature(set_stdio)] +#![feature(slice_sort_by_cached_key)] #![feature(test)] #![feature(unicode)] #![feature(vec_remove_item)] From 57eedbaaf8d2b789fbb3348589af0a43b98e40b8 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 30 Mar 2018 10:54:14 +0100 Subject: [PATCH 13/26] Convert sort_by to sort_by_cached_key --- src/librustc_driver/lib.rs | 11 +++-------- src/libsyntax/lib.rs | 1 + src/libsyntax/parse/parser.rs | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 6f88b0aecb6b6..ab710f2e9004d 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -23,6 +23,7 @@ #![cfg_attr(unix, feature(libc))] #![feature(quote)] #![feature(rustc_diagnostic_macros)] +#![feature(slice_sort_by_cached_key)] #![feature(set_stdio)] #![feature(rustc_stack_internals)] @@ -83,7 +84,6 @@ use rustc_trans_utils::trans_crate::TransCrate; use serialize::json::ToJson; use std::any::Any; -use std::cmp::Ordering::Equal; use std::cmp::max; use std::default::Default; use std::env::consts::{DLL_PREFIX, DLL_SUFFIX}; @@ -1177,13 +1177,8 @@ Available lint options: fn sort_lints(sess: &Session, lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> { let mut lints: Vec<_> = lints.into_iter().map(|(x, _)| x).collect(); - lints.sort_by(|x: &&Lint, y: &&Lint| { - match x.default_level(sess).cmp(&y.default_level(sess)) { - // The sort doesn't case-fold but it's doubtful we care. - Equal => x.name.cmp(y.name), - r => r, - } - }); + // The sort doesn't case-fold but it's doubtful we care. + lints.sort_by_cached_key(|x: &&Lint| (x.default_level(sess), x.name)); lints } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index c456dc45d2182..7774095e20421 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -22,6 +22,7 @@ #![feature(unicode)] #![feature(rustc_diagnostic_macros)] +#![feature(slice_sort_by_cached_key)] #![feature(non_exhaustive)] #![feature(const_atomic_usize_new)] #![feature(rustc_attrs)] diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e6da5bcaa3ae6..6ed7088d0521d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -689,7 +689,7 @@ impl<'a> Parser<'a> { .chain(inedible.iter().map(|x| TokenType::Token(x.clone()))) .chain(self.expected_tokens.iter().cloned()) .collect::>(); - expected.sort_by(|a, b| a.to_string().cmp(&b.to_string())); + expected.sort_by_cached_key(|x| x.to_string()); expected.dedup(); let expect = tokens_to_string(&expected[..]); let actual = self.this_token_to_string(); From 1aa61526a7acd4c3c2a1b2126b77502c818aa4bb Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 31 Mar 2018 21:40:46 +0100 Subject: [PATCH 14/26] Add trivial early return for sort_by_cached_key --- src/liballoc/slice.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 68f2313843c31..56c53fca62cb1 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -1400,6 +1400,7 @@ impl [T] { let sz_usize = mem::size_of::<(K, usize)>(); let len = self.len(); + if len < 2 { return } if sz_u8 < sz_u16 && len <= ( u8::MAX as usize) { return sort_by_key!( u8, self, f) } if sz_u16 < sz_u32 && len <= (u16::MAX as usize) { return sort_by_key!(u16, self, f) } if sz_u32 < sz_usize && len <= (u32::MAX as usize) { return sort_by_key!(u32, self, f) } From 2cc52f08b30642cf995fc39ceb5f3e4741a3dee3 Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 31 Mar 2018 21:42:35 +0100 Subject: [PATCH 15/26] Use cmp::Reverse instead of subtraction --- src/librustc_mir/monomorphize/partitioning.rs | 4 ++-- src/librustc_trans/base.rs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index 17d1156617da5..f914176864ae5 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -112,11 +112,11 @@ use rustc::ty::{self, TyCtxt, InstanceDef}; use rustc::ty::item_path::characteristic_def_id_of_type; use rustc::util::nodemap::{FxHashMap, FxHashSet}; use std::collections::hash_map::Entry; +use std::cmp; use syntax::ast::NodeId; use syntax::symbol::{Symbol, InternedString}; use rustc::mir::mono::MonoItem; use monomorphize::item::{MonoItemExt, InstantiationMode}; -use core::usize; pub use rustc::mir::mono::CodegenUnit; @@ -509,7 +509,7 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning< // Merge the two smallest codegen units until the target size is reached. while codegen_units.len() > target_cgu_count { // Sort small cgus to the back - codegen_units.sort_by_cached_key(|cgu| usize::MAX - cgu.size_estimate()); + codegen_units.sort_by_cached_key(|cgu| cmp::Reverse(cgu.size_estimate())); let mut smallest = codegen_units.pop().unwrap(); let second_smallest = codegen_units.last_mut().unwrap(); diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 3e60af6ef221a..09aba830d050d 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -82,7 +82,8 @@ use std::ffi::CString; use std::str; use std::sync::Arc; use std::time::{Instant, Duration}; -use std::{i32, usize}; +use std::i32; +use std::cmp; use std::sync::mpsc; use syntax_pos::Span; use syntax_pos::symbol::InternedString; @@ -830,7 +831,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // a bit more efficiently. let codegen_units = { let mut codegen_units = codegen_units; - codegen_units.sort_by_cached_key(|cgu| usize::MAX - cgu.size_estimate()); + codegen_units.sort_by_cached_key(|cgu| cmp::Reverse(cgu.size_estimate())); codegen_units }; From e7aa1397ea901e50cc3427d8db44c0b387253bba Mon Sep 17 00:00:00 2001 From: varkor Date: Sun, 1 Apr 2018 13:28:47 +0100 Subject: [PATCH 16/26] Use sort_by_cached_key for partitioning --- src/librustc_mir/monomorphize/partitioning.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index f914176864ae5..f29f86af4aba7 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -189,11 +189,9 @@ pub trait CodegenUnitExt<'tcx> { }, item.symbol_name(tcx)) } - let items: Vec<_> = self.items().iter().map(|(&i, &l)| (i, l)).collect(); - let mut items : Vec<_> = items.iter() - .map(|il| (il, item_sort_key(tcx, il.0))).collect(); - items.sort_by(|&(_, ref key1), &(_, ref key2)| key1.cmp(key2)); - items.into_iter().map(|(&item_linkage, _)| item_linkage).collect() + let mut items: Vec<_> = self.items().iter().map(|(&i, &l)| (i, l)).collect(); + items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i)); + items } } From a1d90a2a2a2d3ff6843d8fca17be4819dba9ab6b Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Mon, 2 Apr 2018 19:34:52 -0700 Subject: [PATCH 17/26] in which the non-shorthand patterns lint keeps its own counsel in macros In issue #49588, Michael Lamparski pointed out a scenario in which the non-shorthand-field-patterns lint could be triggered by a macro-expanded pattern, in a way which was direly unwieldy for the macro author to guard against and unreasonable to expect the macro user to take into account. We can avoid this by not linting patterns that come from macro-expansions. Although this entails accepting "false negatives" where the lint could genuinely improve macro-templated code, avoiding the reported "true-but-super-annoying positive" may be worth the trade? (Some precedent for these relative priorities exists as no. 47775 (5985b0b0).) Resolves #49588. --- src/librustc_lint/builtin.rs | 6 +++++ ...orthand-field-patterns-in-pattern-macro.rs | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/test/run-pass/issue-49588-non-shorthand-field-patterns-in-pattern-macro.rs diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 2cc6708bc034e..48e9cc498dceb 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -173,6 +173,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns { } if let PatKind::Binding(_, _, name, None) = fieldpat.node.pat.node { if name.node == fieldpat.node.name { + if let Some(_) = fieldpat.span.ctxt().outer().expn_info() { + // Don't lint if this is a macro expansion: macro authors + // shouldn't have to worry about this kind of style issue + // (Issue #49588) + return; + } let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span, &format!("the `{}:` in this pattern is redundant", diff --git a/src/test/run-pass/issue-49588-non-shorthand-field-patterns-in-pattern-macro.rs b/src/test/run-pass/issue-49588-non-shorthand-field-patterns-in-pattern-macro.rs new file mode 100644 index 0000000000000..51b2b5a4f7c0f --- /dev/null +++ b/src/test/run-pass/issue-49588-non-shorthand-field-patterns-in-pattern-macro.rs @@ -0,0 +1,24 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(non_shorthand_field_patterns)] + +pub struct Value { pub value: A } + +#[macro_export] +macro_rules! pat { + ($a:pat) => { + Value { value: $a } + }; +} + +fn main() { + let pat!(value) = Value { value: () }; +} From d326bebf919a84e1b130efb517deb7d0848603e3 Mon Sep 17 00:00:00 2001 From: Mark Simulacrum Date: Mon, 9 Apr 2018 11:39:18 -0600 Subject: [PATCH 18/26] Stop emitting color codes on TERM=dumb These terminals generally don't support color. Fixes #49191 --- src/bootstrap/compile.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 9cc18464fea09..b411b19bd53d2 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -1167,7 +1167,9 @@ pub fn stream_cargo( cargo.arg("--message-format").arg("json") .stdout(Stdio::piped()); - if stderr_isatty() && build.ci_env == CiEnv::None { + if stderr_isatty() && build.ci_env == CiEnv::None && + // if the terminal is reported as dumb, then we don't want to enable color for rustc + env::var_os("TERM").map(|t| t != *"dumb").unwrap_or(true) { // since we pass message-format=json to cargo, we need to tell the rustc // wrapper to give us colored output if necessary. This is because we // only want Cargo's JSON output, not rustcs. From f62c210d9012f45343bbe6148f897f77fbe50aa1 Mon Sep 17 00:00:00 2001 From: Hero Date: Mon, 9 Apr 2018 20:34:09 +0200 Subject: [PATCH 19/26] add regression test for issue #16223: fixed by NLL --- src/test/ui/nll/issue-16223.rs | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/test/ui/nll/issue-16223.rs diff --git a/src/test/ui/nll/issue-16223.rs b/src/test/ui/nll/issue-16223.rs new file mode 100644 index 0000000000000..64fc3df30b98c --- /dev/null +++ b/src/test/ui/nll/issue-16223.rs @@ -0,0 +1,63 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Regression test for #16223: without NLL the `if let` construct together with +// the nested box-structure of `Root` causes an unwanted collateral move. + +// The exact error prevented here is: +// +// error[E0382]: use of collaterally moved value: `(root.boxed.rhs as SomeVariant::B).0` +// --> src/main.rs:55:29 +// | +// 56 | lhs: SomeVariant::A(a), +// | - value moved here +// 57 | rhs: SomeVariant::B(b), +// | ^ value used here after move +// | +// = note: move occurs because the value has type `A`, which does not implement the `Copy` trait + +// must-compile-successfully + +#![feature(nll)] +#![feature(box_patterns)] + +struct Root { + boxed: Box, +} + +struct SetOfVariants { + lhs: SomeVariant, + rhs: SomeVariant, +} + +enum SomeVariant { + A(A), + B(B), +} + +struct A(String); +struct B(String); + +fn main() { + let root = Root { + boxed: Box::new(SetOfVariants { + lhs: SomeVariant::A(A(String::from("This is A"))), + rhs: SomeVariant::B(B(String::from("This is B"))), + }), + }; + if let box SetOfVariants { + lhs: SomeVariant::A(a), + rhs: SomeVariant::B(b), + } = root.boxed + { + println!("a = {}", a.0); + println!("b = {}", b.0); + } +} From dab317f04f33358ff265123db6a27e43f30e2a33 Mon Sep 17 00:00:00 2001 From: "dragan.mladjenovic" Date: Tue, 3 Apr 2018 16:40:05 +0200 Subject: [PATCH 20/26] Small nits to make couple of tests pass on mips targets. --- src/test/codegen/link_section.rs | 6 ++++++ src/test/ui/asm-out-assign-imm.rs | 1 + src/test/ui/target-feature-wrong.rs | 1 + 3 files changed, 8 insertions(+) diff --git a/src/test/codegen/link_section.rs b/src/test/codegen/link_section.rs index 9c56a316b341c..415ee6eb7eab8 100644 --- a/src/test/codegen/link_section.rs +++ b/src/test/codegen/link_section.rs @@ -15,8 +15,14 @@ // CHECK: @VAR1 = constant <{ [4 x i8] }> <{ [4 x i8] c"\01\00\00\00" }>, section ".test_one" #[no_mangle] #[link_section = ".test_one"] +#[cfg(target_endian = "little")] pub static VAR1: u32 = 1; +#[no_mangle] +#[link_section = ".test_one"] +#[cfg(target_endian = "big")] +pub static VAR1: u32 = 0x01000000; + pub enum E { A(u32), B(f32) diff --git a/src/test/ui/asm-out-assign-imm.rs b/src/test/ui/asm-out-assign-imm.rs index 49084e01a15db..055a169deda74 100644 --- a/src/test/ui/asm-out-assign-imm.rs +++ b/src/test/ui/asm-out-assign-imm.rs @@ -12,6 +12,7 @@ // ignore-emscripten // ignore-powerpc // ignore-sparc +// ignore-mips #![feature(asm)] diff --git a/src/test/ui/target-feature-wrong.rs b/src/test/ui/target-feature-wrong.rs index 56acbed47210a..080971f034746 100644 --- a/src/test/ui/target-feature-wrong.rs +++ b/src/test/ui/target-feature-wrong.rs @@ -12,6 +12,7 @@ // ignore-aarch64 // ignore-wasm // ignore-emscripten +// ignore-mips #![feature(target_feature)] From 1e5145db9fcfea306e3c38aeb6625a394c51a5cd Mon Sep 17 00:00:00 2001 From: "dragan.mladjenovic" Date: Thu, 5 Apr 2018 15:30:41 +0200 Subject: [PATCH 21/26] Update ui test references. --- src/test/ui/asm-out-assign-imm.stderr | 2 +- src/test/ui/target-feature-wrong.stderr | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/ui/asm-out-assign-imm.stderr b/src/test/ui/asm-out-assign-imm.stderr index 4ec758b97f2d8..d9fd4b26c3900 100644 --- a/src/test/ui/asm-out-assign-imm.stderr +++ b/src/test/ui/asm-out-assign-imm.stderr @@ -1,5 +1,5 @@ error[E0384]: cannot assign twice to immutable variable `x` - --> $DIR/asm-out-assign-imm.rs:29:9 + --> $DIR/asm-out-assign-imm.rs:30:9 | LL | x = 1; | ----- first assignment to `x` diff --git a/src/test/ui/target-feature-wrong.stderr b/src/test/ui/target-feature-wrong.stderr index 8773f8504cb01..fb3fb35531389 100644 --- a/src/test/ui/target-feature-wrong.stderr +++ b/src/test/ui/target-feature-wrong.stderr @@ -1,35 +1,35 @@ warning: #[target_feature = ".."] is deprecated and will eventually be removed, use #[target_feature(enable = "..")] instead - --> $DIR/target-feature-wrong.rs:18:1 + --> $DIR/target-feature-wrong.rs:19:1 | LL | #[target_feature = "+sse2"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the feature named `foo` is not valid for this target - --> $DIR/target-feature-wrong.rs:20:18 + --> $DIR/target-feature-wrong.rs:21:18 | LL | #[target_feature(enable = "foo")] | ^^^^^^^^^^^^^^ error: #[target_feature(..)] only accepts sub-keys of `enable` currently - --> $DIR/target-feature-wrong.rs:22:18 + --> $DIR/target-feature-wrong.rs:23:18 | LL | #[target_feature(bar)] | ^^^ error: #[target_feature(..)] only accepts sub-keys of `enable` currently - --> $DIR/target-feature-wrong.rs:24:18 + --> $DIR/target-feature-wrong.rs:25:18 | LL | #[target_feature(disable = "baz")] | ^^^^^^^^^^^^^^^ error: #[target_feature(..)] can only be applied to `unsafe` function - --> $DIR/target-feature-wrong.rs:28:1 + --> $DIR/target-feature-wrong.rs:29:1 | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: attribute should be applied to a function - --> $DIR/target-feature-wrong.rs:32:1 + --> $DIR/target-feature-wrong.rs:33:1 | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 0a94344fa795795de9eb864a75b3d999c2d6ea29 Mon Sep 17 00:00:00 2001 From: "dragan.mladjenovic" Date: Tue, 10 Apr 2018 10:19:58 +0200 Subject: [PATCH 22/26] Add ignores for powerpc and s390x to target-feature-wrong.rs and update references. --- src/test/ui/target-feature-wrong.rs | 2 ++ src/test/ui/target-feature-wrong.stderr | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/test/ui/target-feature-wrong.rs b/src/test/ui/target-feature-wrong.rs index 080971f034746..eb83ee724c785 100644 --- a/src/test/ui/target-feature-wrong.rs +++ b/src/test/ui/target-feature-wrong.rs @@ -13,6 +13,8 @@ // ignore-wasm // ignore-emscripten // ignore-mips +// ignore-powerpc +// ignore-s390x #![feature(target_feature)] diff --git a/src/test/ui/target-feature-wrong.stderr b/src/test/ui/target-feature-wrong.stderr index fb3fb35531389..b5e650eaf9ac4 100644 --- a/src/test/ui/target-feature-wrong.stderr +++ b/src/test/ui/target-feature-wrong.stderr @@ -1,35 +1,35 @@ warning: #[target_feature = ".."] is deprecated and will eventually be removed, use #[target_feature(enable = "..")] instead - --> $DIR/target-feature-wrong.rs:19:1 + --> $DIR/target-feature-wrong.rs:21:1 | LL | #[target_feature = "+sse2"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the feature named `foo` is not valid for this target - --> $DIR/target-feature-wrong.rs:21:18 + --> $DIR/target-feature-wrong.rs:23:18 | LL | #[target_feature(enable = "foo")] | ^^^^^^^^^^^^^^ error: #[target_feature(..)] only accepts sub-keys of `enable` currently - --> $DIR/target-feature-wrong.rs:23:18 + --> $DIR/target-feature-wrong.rs:25:18 | LL | #[target_feature(bar)] | ^^^ error: #[target_feature(..)] only accepts sub-keys of `enable` currently - --> $DIR/target-feature-wrong.rs:25:18 + --> $DIR/target-feature-wrong.rs:27:18 | LL | #[target_feature(disable = "baz")] | ^^^^^^^^^^^^^^^ error: #[target_feature(..)] can only be applied to `unsafe` function - --> $DIR/target-feature-wrong.rs:29:1 + --> $DIR/target-feature-wrong.rs:31:1 | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: attribute should be applied to a function - --> $DIR/target-feature-wrong.rs:33:1 + --> $DIR/target-feature-wrong.rs:35:1 | LL | #[target_feature(enable = "sse2")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +38,7 @@ LL | mod another {} | -------------- not a function error: cannot use #[inline(always)] with #[target_feature] - --> $DIR/target-feature-wrong.rs:36:1 + --> $DIR/target-feature-wrong.rs:39:1 | LL | #[inline(always)] | ^^^^^^^^^^^^^^^^^ From 18e95320986243696f31f4b596761eb35759dfe9 Mon Sep 17 00:00:00 2001 From: Alec Mocatta Date: Tue, 10 Apr 2018 18:44:47 +0100 Subject: [PATCH 23/26] Add --enable-debug flag to musl CI build script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Building for x86_64-unknown-linux-musl currently results in an executable lacking debug information for musl libc itself. If you request a backtrace in GDB while control flow is within musl – including sycalls made by musl – the result looks like: #0 0x0000000000434b46 in __cp_end () #1 0x0000000000432dbd in __syscall_cp_c () #2 0x0000000000000000 in ?? () i.e. not very helpful. Adding --enable-debug resolves this, and --enable-optimize re-enables optimisations which default to off given the previous flag. --- src/ci/docker/scripts/musl.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/scripts/musl.sh b/src/ci/docker/scripts/musl.sh index fb0bd06ce3099..f87ba8fe4e60e 100644 --- a/src/ci/docker/scripts/musl.sh +++ b/src/ci/docker/scripts/musl.sh @@ -40,7 +40,7 @@ if [ ! -d $MUSL ]; then fi cd $MUSL -./configure --disable-shared --prefix=/musl-$TAG $@ +./configure --enable-optimize --enable-debug --disable-shared --prefix=/musl-$TAG $@ if [ "$TAG" = "i586" -o "$TAG" = "i686" ]; then hide_output make -j$(nproc) AR=ar RANLIB=ranlib else From 6e0089ea7776eea84fb26690b590074710247146 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 10 Apr 2018 22:30:23 +0100 Subject: [PATCH 24/26] Do not uppercase-lint no_mangle statics --- src/librustc_lint/bad_style.rs | 3 +++ src/test/compile-fail/lint-non-uppercase-statics.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs index ad3760eed8019..463ec4796e8b6 100644 --- a/src/librustc_lint/bad_style.rs +++ b/src/librustc_lint/bad_style.rs @@ -368,6 +368,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { match it.node { hir::ItemStatic(..) => { + if attr::find_by_name(&it.attrs, "no_mangle").is_some() { + return; + } NonUpperCaseGlobals::check_upper_case(cx, "static variable", it.name, it.span); } hir::ItemConst(..) => { diff --git a/src/test/compile-fail/lint-non-uppercase-statics.rs b/src/test/compile-fail/lint-non-uppercase-statics.rs index 463a93612ca00..84cc24a00109f 100644 --- a/src/test/compile-fail/lint-non-uppercase-statics.rs +++ b/src/test/compile-fail/lint-non-uppercase-statics.rs @@ -16,4 +16,7 @@ static foo: isize = 1; //~ ERROR static variable `foo` should have an upper case static mut bar: isize = 1; //~^ ERROR static variable `bar` should have an upper case name such as `BAR` +#[no_mangle] +pub static extern_foo: isize = 1; // OK, because #[no_mangle] supersedes the warning + fn main() { } From 5e5374677a642994da2f5c12148abc5f104320e0 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Tue, 10 Apr 2018 22:34:15 +0100 Subject: [PATCH 25/26] Fix "fp" feature for AArch64 --- src/librustc_trans/llvm_util.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_trans/llvm_util.rs b/src/librustc_trans/llvm_util.rs index 1c8f09ce7b3f1..ad128516a3af3 100644 --- a/src/librustc_trans/llvm_util.rs +++ b/src/librustc_trans/llvm_util.rs @@ -134,6 +134,7 @@ pub fn to_llvm_feature<'a>(sess: &Session, s: &'a str) -> &'a str { ("x86", "pclmulqdq") => "pclmul", ("x86", "rdrand") => "rdrnd", ("x86", "bmi1") => "bmi", + ("aarch64", "fp") => "fp-armv8", ("aarch64", "fp16") => "fullfp16", (_, s) => s, } From a648267dff08b3243d16e6680f4831300806ce87 Mon Sep 17 00:00:00 2001 From: memoryleak47 Date: Wed, 11 Apr 2018 01:34:10 +0200 Subject: [PATCH 26/26] fixed typo --- src/tools/compiletest/src/header.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index e48f42705f16a..94a6353ad2431 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -595,7 +595,7 @@ impl Config { fn has_cfg_prefix(&self, line: &str, prefix: &str) -> bool { // returns whether this line contains this prefix or not. For prefix // "ignore", returns true if line says "ignore-x86_64", "ignore-arch", - // "ignore-andorid" etc. + // "ignore-android" etc. line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-') }