Skip to content
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

Rollup of 15 pull requests #53765

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
931eb4c
Add one more example for Cow that shows how to keep Cow in a struct
kpp Aug 6, 2018
9a3a12e
Fix review notes
kpp Aug 15, 2018
34b65db
document effect of join on memory ordering
RalfJung Aug 15, 2018
5bfb785
Review fix
kpp Aug 15, 2018
b73843f
Force-inline `shallow_resolve` at its hottest call site.
nnethercote Aug 17, 2018
3995bff
Add another PartialEq example
GuillaumeGomez Aug 21, 2018
cccd2ce
cleanup: Add main functions to some UI tests
petrochenkov Aug 22, 2018
9395a02
Fix stabilisation version for macro_vis_matcher.
jkozlowski Aug 25, 2018
1f421d6
call span_suggestion with applicability
jcpst Aug 26, 2018
26f38c0
Do not suggest dereferencing in macro
estebank Aug 26, 2018
a2722f3
readd final newline
estebank Aug 27, 2018
4570ace
save-analysis: Differentiate foreign functions and statics.
emilio Aug 18, 2018
8486efa
fix a typo: taget_env -> target_env
oconnor663 Aug 27, 2018
1d79d8b
Fix source automatic scroll
GuillaumeGomez Aug 27, 2018
04b4c40
Fix invalid display of unstable messages
GuillaumeGomez Aug 27, 2018
f77ad5c
remove `let x = baz` which was obscuring the real error
nikomatsakis Aug 6, 2018
e6dcdee
expand keep-stage --help text
RalfJung Aug 28, 2018
31b63d0
split paragraph
RalfJung Aug 28, 2018
c0b4b6a
Update clippy submodule
oli-obk Aug 28, 2018
93f3f5b
Use FxHash{Map,Set} instead of the default Hash{Map,Set} everywhere i…
eddyb Aug 18, 2018
5b74d67
Rollup merge of #51760 - GuillaumeGomez:add-another-partialeq-example…
kennytm Aug 28, 2018
cbbfcc5
Rollup merge of #53113 - kpp:more_docs_for_cow, r=GuillaumeGomez
kennytm Aug 28, 2018
2744010
Rollup merge of #53129 - nikomatsakis:issue-51172-tweak-test, r=pnkfelix
kennytm Aug 28, 2018
105eb4e
Rollup merge of #53389 - RalfJung:thread-join, r=sfackler
kennytm Aug 28, 2018
7518d9d
Rollup merge of #53472 - eddyb:fx-pls, r=pnkfelix
kennytm Aug 28, 2018
b8594d9
Rollup merge of #53513 - nnethercote:inline-shallow_resolve, r=varkor
kennytm Aug 28, 2018
0ad879d
Rollup merge of #53622 - petrochenkov:nomain, r=oli-obk
kennytm Aug 28, 2018
13179e2
Rollup merge of #53655 - jcpst:with_applicability, r=estebank
kennytm Aug 28, 2018
8208ded
Rollup merge of #53702 - jkozlowski:correct_version_for_macro_vis_mat…
kennytm Aug 28, 2018
5e3cb12
Rollup merge of #53727 - estebank:incorrect-deref-suggestion, r=nikom…
kennytm Aug 28, 2018
07cb353
Rollup merge of #53732 - emilio:foreign-fn, r=nrc
kennytm Aug 28, 2018
dd2365c
Rollup merge of #53743 - oconnor663:target_env, r=kennytm
kennytm Aug 28, 2018
b993dd0
Rollup merge of #53747 - GuillaumeGomez:rustdoc-fixes, r=QuietMisdreavus
kennytm Aug 28, 2018
bca350b
Rollup merge of #53753 - RalfJung:keep-stage, r=nikomatsakis
kennytm Aug 28, 2018
bbe0a8e
Rollup merge of #53758 - oli-obk:clippy, r=kennytm
kennytm Aug 28, 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
2 changes: 0 additions & 2 deletions src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ dependencies = [
name = "clippy"
version = "0.0.212"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cargo_metadata 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clippy-mini-macro-test 0.2.0",
"clippy_lints 0.0.212",
Expand All @@ -303,7 +302,6 @@ dependencies = [
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-workspace-hack 1.0.0",
"rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`"
"stage to build (indicates compiler to use/test, e.g. stage 0 uses the \
bootstrap compiler, stage 1 the stage 0 rustc artifacts, etc.)",
"N");
opts.optmulti("", "keep-stage", "stage(s) to keep without recompiling", "N");
opts.optmulti("", "keep-stage", "stage(s) to keep without recompiling \
(pass multiple times to keep e.g. both stages 0 and 1)", "N");
opts.optopt("", "src", "path to the root of the rust checkout", "DIR");
opts.optopt("j", "jobs", "number of jobs to run in parallel", "JOBS");
opts.optflag("h", "help", "print this help message");
Expand Down
35 changes: 35 additions & 0 deletions src/liballoc/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,41 @@ impl<T> ToOwned for T
/// let mut input = Cow::from(vec![-1, 0, 1]);
/// abs_all(&mut input);
/// ```
///
/// Another example showing how to keep `Cow` in a struct:
///
/// ```
/// use std::borrow::{Cow, ToOwned};
///
/// struct Items<'a, X: 'a> where [X]: ToOwned<Owned=Vec<X>> {
/// values: Cow<'a, [X]>,
/// }
///
/// impl<'a, X: Clone + 'a> Items<'a, X> where [X]: ToOwned<Owned=Vec<X>> {
/// fn new(v: Cow<'a, [X]>) -> Self {
/// Items { values: v }
/// }
/// }
///
/// // Creates a container from borrowed values of a slice
/// let readonly = [1, 2];
/// let borrowed = Items::new((&readonly[..]).into());
/// match borrowed {
/// Items { values: Cow::Borrowed(b) } => println!("borrowed {:?}", b),
/// _ => panic!("expect borrowed value"),
/// }
///
/// let mut clone_on_write = borrowed;
/// // Mutates the data from slice into owned vec and pushes a new value on top
/// clone_on_write.values.to_mut().push(3);
/// println!("clone_on_write = {:?}", clone_on_write.values);
///
/// // The data was mutated. Let check it out.
/// match clone_on_write {
/// Items { values: Cow::Owned(_) } => println!("clone_on_write contains owned data"),
/// _ => panic!("expect owned data"),
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Cow<'a, B: ?Sized + 'a>
where B: ToOwned
Expand Down
85 changes: 84 additions & 1 deletion src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ use self::Ordering::*;
/// the same book if their ISBN matches, even if the formats differ:
///
/// ```
/// enum BookFormat { Paperback, Hardback, Ebook }
/// enum BookFormat {
/// Paperback,
/// Hardback,
/// Ebook,
/// }
///
/// struct Book {
/// isbn: i32,
/// format: BookFormat,
Expand All @@ -95,6 +100,84 @@ use self::Ordering::*;
/// assert!(b1 != b3);
/// ```
///
/// ## How can I compare two different types?
///
/// The type you can compare with is controlled by `PartialEq`'s type parameter.
/// For example, let's tweak our previous code a bit:
///
/// ```
/// enum BookFormat {
/// Paperback,
/// Hardback,
/// Ebook,
/// }
///
/// struct Book {
/// isbn: i32,
/// format: BookFormat,
/// }
///
/// impl PartialEq<BookFormat> for Book {
/// fn eq(&self, other: &BookFormat) -> bool {
/// match (&self.format, other) {
/// (BookFormat::Paperback, BookFormat::Paperback) => true,
/// (BookFormat::Hardback, BookFormat::Hardback) => true,
/// (BookFormat::Ebook, BookFormat::Ebook) => true,
/// (_, _) => false,
/// }
/// }
/// }
///
/// let b1 = Book { isbn: 3, format: BookFormat::Paperback };
///
/// assert!(b1 == BookFormat::Paperback);
/// assert!(b1 != BookFormat::Ebook);
/// ```
///
/// By changing `impl PartialEq for Book` to `impl PartialEq<BookFormat> for Book`,
/// we've changed what type we can use on the right side of the `==` operator.
/// This lets us use it in the `assert!` statements at the bottom.
///
/// You can also combine these implementations to let the `==` operator work with
/// two different types:
///
/// ```
/// enum BookFormat {
/// Paperback,
/// Hardback,
/// Ebook,
/// }
///
/// struct Book {
/// isbn: i32,
/// format: BookFormat,
/// }
///
/// impl PartialEq<BookFormat> for Book {
/// fn eq(&self, other: &BookFormat) -> bool {
/// match (&self.format, other) {
/// (&BookFormat::Paperback, &BookFormat::Paperback) => true,
/// (&BookFormat::Hardback, &BookFormat::Hardback) => true,
/// (&BookFormat::Ebook, &BookFormat::Ebook) => true,
/// (_, _) => false,
/// }
/// }
/// }
///
/// impl PartialEq for Book {
/// fn eq(&self, other: &Book) -> bool {
/// self.isbn == other.isbn
/// }
/// }
///
/// let b1 = Book { isbn: 3, format: BookFormat::Paperback };
/// let b2 = Book { isbn: 3, format: BookFormat::Ebook };
///
/// assert!(b1 == BookFormat::Paperback);
/// assert!(b1 != BookFormat::Ebook);
/// assert!(b1 == b2);
/// ```
///
/// # Examples
///
/// ```
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ use hir::GenericArg;
use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
ELIDED_LIFETIMES_IN_PATHS};
use middle::cstore::CrateStore;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::small_vec::OneVector;
use rustc_data_structures::thin_vec::ThinVec;
use session::Session;
use util::common::FN_OUTPUT_NAME;
use util::nodemap::{DefIdMap, NodeMap};

use std::collections::{BTreeMap, HashSet};
use std::collections::BTreeMap;
use std::fmt::Debug;
use std::iter;
use std::mem;
Expand Down Expand Up @@ -1342,7 +1343,7 @@ impl<'a> LoweringContext<'a> {
exist_ty_id: NodeId,
collect_elided_lifetimes: bool,
currently_bound_lifetimes: Vec<hir::LifetimeName>,
already_defined_lifetimes: HashSet<hir::LifetimeName>,
already_defined_lifetimes: FxHashSet<hir::LifetimeName>,
output_lifetimes: Vec<hir::GenericArg>,
output_lifetime_params: Vec<hir::GenericParam>,
}
Expand Down Expand Up @@ -1476,7 +1477,7 @@ impl<'a> LoweringContext<'a> {
exist_ty_id,
collect_elided_lifetimes: true,
currently_bound_lifetimes: Vec::new(),
already_defined_lifetimes: HashSet::new(),
already_defined_lifetimes: FxHashSet::default(),
output_lifetimes: Vec::new(),
output_lifetime_params: Vec::new(),
};
Expand Down
10 changes: 9 additions & 1 deletion src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
self.resolve_type_vars_if_possible(t).to_string()
}

pub fn shallow_resolve(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
// We have this force-inlined variant of shallow_resolve() for the one
// callsite that is extremely hot. All other callsites use the normal
// variant.
#[inline(always)]
pub fn inlined_shallow_resolve(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
match typ.sty {
ty::Infer(ty::TyVar(v)) => {
// Not entirely obvious: if `typ` is a type variable,
Expand Down Expand Up @@ -1157,6 +1161,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}
}

pub fn shallow_resolve(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
self.inlined_shallow_resolve(typ)
}

pub fn resolve_type_vars_if_possible<T>(&self, value: &T) -> T
where T: TypeFoldable<'tcx>
{
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use session::config;
use middle::lang_items;

use rustc_data_structures::fx::FxHashSet;
use rustc_target::spec::PanicStrategy;
use syntax::ast;
use syntax::symbol::Symbol;
Expand All @@ -23,8 +24,6 @@ use hir::intravisit;
use hir;
use ty::TyCtxt;

use std::collections::HashSet;

macro_rules! weak_lang_items {
($($name:ident, $item:ident, $sym:ident;)*) => (

Expand Down Expand Up @@ -101,7 +100,7 @@ fn verify<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
return
}

let mut missing = HashSet::new();
let mut missing = FxHashSet::default();
for &cnum in tcx.crates().iter() {
for &item in tcx.missing_lang_items(cnum).iter() {
missing.insert(item);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ use std::collections::btree_map::Iter as BTreeMapIter;
use std::collections::btree_map::Keys as BTreeMapKeysIter;
use std::collections::btree_map::Values as BTreeMapValuesIter;

use rustc_data_structures::fx::FxHashSet;
use std::{fmt, str};
use std::hash::Hasher;
use std::collections::hash_map::DefaultHasher;
use std::collections::HashSet;
use std::iter::FromIterator;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -1373,7 +1373,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
let max_atomic_width = sess.target.target.max_atomic_width();
let atomic_cas = sess.target.target.options.atomic_cas;

let mut ret = HashSet::new();
let mut ret = FxHashSet::default();
// Target bindings.
ret.insert((Symbol::intern("target_os"), Some(Symbol::intern(os))));
if let Some(ref fam) = sess.target.target.options.target_family {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/session/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

pub use self::FileMatch::*;

use rustc_data_structures::fx::FxHashSet;
use std::borrow::Cow;
use std::collections::HashSet;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
Expand All @@ -40,7 +40,7 @@ impl<'a> FileSearch<'a> {
pub fn for_each_lib_search_path<F>(&self, mut f: F) where
F: FnMut(&Path, PathKind)
{
let mut visited_dirs = HashSet::new();
let mut visited_dirs = FxHashSet::default();

for (path, kind) in self.search_paths.iter(self.kind) {
f(path, kind);
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ use jobserver::Client;

use std;
use std::cell::{self, Cell, RefCell};
use std::collections::HashMap;
use std::env;
use std::fmt;
use std::io::Write;
Expand Down Expand Up @@ -122,7 +121,7 @@ pub struct Session {
/// Map from imported macro spans (which consist of
/// the localized span for the macro body) to the
/// macro name and definition span in the source crate.
pub imported_macro_spans: OneThread<RefCell<HashMap<Span, (String, Span)>>>,
pub imported_macro_spans: OneThread<RefCell<FxHashMap<Span, (String, Span)>>>,

incr_comp_session: OneThread<RefCell<IncrCompSession>>,

Expand Down Expand Up @@ -1129,7 +1128,7 @@ pub fn build_session_(
injected_allocator: Once::new(),
allocator_kind: Once::new(),
injected_panic_runtime: Once::new(),
imported_macro_spans: OneThread::new(RefCell::new(HashMap::new())),
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
self_profiling: Lock::new(SelfProfiler::new()),
profile_channel: Lock::new(None),
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
// doing more work yet
if !pending_obligation.stalled_on.is_empty() {
if pending_obligation.stalled_on.iter().all(|&ty| {
let resolved_ty = self.selcx.infcx().shallow_resolve(&ty);
// Use the force-inlined variant of shallow_resolve() because this code is hot.
let resolved_ty = self.selcx.infcx().inlined_shallow_resolve(&ty);
resolved_ty == ty // nothing changed here
}) {
debug!("process_predicate: pending obligation {:?} still stalled on {:?}",
Expand Down
11 changes: 6 additions & 5 deletions src/librustc/ty/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#![allow(warnings)]

use std::mem;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::{Lock, LockGuard, Lrc, Weak};
use rustc_data_structures::OnDrop;
use syntax_pos::Span;
Expand All @@ -21,7 +22,7 @@ use ty::context::TyCtxt;
use errors::Diagnostic;
use std::process;
use std::{fmt, ptr};
use std::collections::HashSet;

#[cfg(parallel_queries)]
use {
rayon_core,
Expand Down Expand Up @@ -282,7 +283,7 @@ where
fn cycle_check<'tcx>(query: Lrc<QueryJob<'tcx>>,
span: Span,
stack: &mut Vec<(Span, Lrc<QueryJob<'tcx>>)>,
visited: &mut HashSet<*const QueryJob<'tcx>>
visited: &mut FxHashSet<*const QueryJob<'tcx>>
) -> Option<Option<Waiter<'tcx>>> {
if visited.contains(&query.as_ptr()) {
return if let Some(p) = stack.iter().position(|q| q.1.as_ptr() == query.as_ptr()) {
Expand Down Expand Up @@ -321,7 +322,7 @@ fn cycle_check<'tcx>(query: Lrc<QueryJob<'tcx>>,
#[cfg(parallel_queries)]
fn connected_to_root<'tcx>(
query: Lrc<QueryJob<'tcx>>,
visited: &mut HashSet<*const QueryJob<'tcx>>
visited: &mut FxHashSet<*const QueryJob<'tcx>>
) -> bool {
// We already visited this or we're deliberately ignoring it
if visited.contains(&query.as_ptr()) {
Expand Down Expand Up @@ -357,7 +358,7 @@ fn remove_cycle<'tcx>(
wakelist: &mut Vec<Lrc<QueryWaiter<'tcx>>>,
tcx: TyCtxt<'_, 'tcx, '_>
) -> bool {
let mut visited = HashSet::new();
let mut visited = FxHashSet::default();
let mut stack = Vec::new();
// Look for a cycle starting with the last query in `jobs`
if let Some(waiter) = cycle_check(jobs.pop().unwrap(),
Expand Down Expand Up @@ -389,7 +390,7 @@ fn remove_cycle<'tcx>(
// connected to queries outside the cycle
let entry_points: Vec<Lrc<QueryJob<'tcx>>> = stack.iter().filter_map(|query| {
// Mark all the other queries in the cycle as already visited
let mut visited = HashSet::from_iter(stack.iter().filter_map(|q| {
let mut visited = FxHashSet::from_iter(stack.iter().filter_map(|q| {
if q.1.as_ptr() != query.1.as_ptr() {
Some(q.1.as_ptr())
} else {
Expand Down
Loading