Skip to content

Rollup of 6 pull requests #61105

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

Merged
merged 41 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1e3302d
Suggest dereferencing on assignment to mutable borrow
estebank May 22, 2019
f44b264
fix dangling reference in Vec::append
RalfJung May 23, 2019
3cbf586
tweak discriminant on non-nullary enum diagnostic
euclio May 22, 2019
6116f19
Box::into_unique: do the reborrow-to-raw *after* destroying the Box
RalfJung May 23, 2019
8d4e7fd
adjust comment
RalfJung May 23, 2019
4ba144d
Update associated_item_def_ids
Zoxc Nov 30, 2018
8c936e4
Update inherent_impls
Zoxc Nov 30, 2018
99f6221
Update borrowck
Zoxc Nov 30, 2018
95dfd82
Update upstream_monomorphizations and upstream_monomorphizations_for
Zoxc Nov 30, 2018
093940d
Update implementations_of_trait and all_trait_implementations
Zoxc Nov 30, 2018
529aed8
Update resolve_lifetimes, named_region_map, is_late_bound_map and obj…
Zoxc Nov 30, 2018
b1398a0
Update item_children
Zoxc Nov 30, 2018
28482db
Update used_trait_imports
Zoxc Nov 30, 2018
ba5d9c0
Optimize alloc_from_iter
Zoxc Apr 23, 2019
ae8975c
Update GenericPredicates queries
Zoxc Dec 1, 2018
e77096b
Remove subtle Default impl for Value
Zoxc Apr 5, 2019
4214565
Add a comment for arena_types!
Zoxc May 19, 2019
ad2b35b
Make ArenaField private
Zoxc May 19, 2019
5bcc80b
Update Cargo.lock
Zoxc May 19, 2019
9dcc60b
Update lint_levels
Zoxc Nov 30, 2018
10ef70b
Update stability_index, all_crate_nums and features_query
Zoxc Nov 30, 2018
5751fcc
Update all_traits
Zoxc Nov 30, 2018
fb57879
Update privacy_access_levels
Zoxc Dec 1, 2018
5f808f6
Update in_scope_traits_map
Zoxc Dec 1, 2018
9b648f7
Update upvars and module_exports
Zoxc Dec 1, 2018
46f2511
Update wasm_import_module_map and target_features_whitelist
Zoxc Dec 1, 2018
3f87975
Update get_lib_features, defined_lib_features, get_lang_items, define…
Zoxc Dec 1, 2018
2f74d90
Update visible_parent_map
Zoxc Dec 1, 2018
469831f
Update foreign_modules and dllimport_foreign_items
Zoxc Dec 1, 2018
a58999c
Update dylib_dependency_formats, extern_crate and reachable_non_generics
Zoxc Dec 1, 2018
d46e732
Update crate_variances and inferred_outlives_crate
Zoxc May 20, 2019
7fbbcfa
Add regression test for negative case
estebank May 23, 2019
49f01d8
Fix missing overflowing literal lint in for loop
varkor May 23, 2019
3e4cefe
Update unreachable loop patterns test
varkor May 23, 2019
12de24c
Add test for denying overflowing literal in loop
varkor May 23, 2019
e0e9c86
Rollup merge of #59545 - Zoxc:the-arena-3, r=eddyb,michaelwoerister
Centril May 23, 2019
b9459e7
Rollup merge of #61054 - estebank:mut-ref-reassign, r=zackmdavis
Centril May 23, 2019
26f3528
Rollup merge of #61056 - euclio:custom-discriminant-error, r=estebank
Centril May 23, 2019
ee97210
Rollup merge of #61082 - RalfJung:vec, r=alexcrichton
Centril May 23, 2019
3388028
Rollup merge of #61086 - RalfJung:box, r=alexcrichton
Centril May 23, 2019
92fda92
Rollup merge of #61098 - varkor:fix-overflowing-literal-in-loop, r=es…
Centril May 23, 2019
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,7 @@ dependencies = [
"rustc_errors 0.0.0",
"rustc_target 0.0.0",
"serialize 0.0.0",
"smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntax 0.0.0",
"syntax_ext 0.0.0",
Expand Down
11 changes: 6 additions & 5 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,16 @@ impl<T: ?Sized> Box<T> {
#[unstable(feature = "ptr_internals", issue = "0", reason = "use into_raw_non_null instead")]
#[inline]
#[doc(hidden)]
pub fn into_unique(mut b: Box<T>) -> Unique<T> {
pub fn into_unique(b: Box<T>) -> Unique<T> {
let mut unique = b.0;
mem::forget(b);
// Box is kind-of a library type, but recognized as a "unique pointer" by
// Stacked Borrows. This function here corresponds to "reborrowing to
// a raw pointer", but there is no actual reborrow here -- so
// without some care, the pointer we are returning here still carries
// the `Uniq` tag. We round-trip through a mutable reference to avoid that.
let unique = unsafe { b.0.as_mut() as *mut T };
mem::forget(b);
unsafe { Unique::new_unchecked(unique) }
// the tag of `b`, with `Unique` permission.
// We round-trip through a mutable reference to avoid that.
unsafe { Unique::new_unchecked(unique.as_mut() as *mut T) }
}

/// Consumes and leaks the `Box`, returning a mutable reference,
Expand Down
5 changes: 3 additions & 2 deletions src/liballoc/tests/vec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(not(miri))]

use std::borrow::Cow;
use std::mem::size_of;
use std::{usize, isize};
Expand Down Expand Up @@ -763,6 +761,7 @@ fn from_into_inner() {
it.next().unwrap();
let vec = it.collect::<Vec<_>>();
assert_eq!(vec, [2, 3]);
#[cfg(not(miri))] // Miri does not support comparing dangling pointers
assert!(ptr != vec.as_ptr());
}

Expand Down Expand Up @@ -971,6 +970,7 @@ fn test_reserve_exact() {
}

#[test]
#[cfg(not(miri))] // Miri does not support signalling OOM
fn test_try_reserve() {

// These are the interesting cases:
Expand Down Expand Up @@ -1073,6 +1073,7 @@ fn test_try_reserve() {
}

#[test]
#[cfg(not(miri))] // Miri does not support signalling OOM
fn test_try_reserve_exact() {

// This is exactly the same as test_try_reserve with the method changed.
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ impl<T> Vec<T> {
let count = (*other).len();
self.reserve(count);
let len = self.len();
ptr::copy_nonoverlapping(other as *const T, self.get_unchecked_mut(len), count);
ptr::copy_nonoverlapping(other as *const T, self.as_mut_ptr().add(len), count);
self.len += count;
}

Expand Down
29 changes: 24 additions & 5 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,31 @@ impl DroplessArena {
}
}

#[inline]
unsafe fn write_from_iter<T, I: Iterator<Item = T>>(
&self,
mut iter: I,
len: usize,
mem: *mut T,
) -> &mut [T] {
let mut i = 0;
// Use a manual loop since LLVM manages to optimize it better for
// slice iterators
loop {
let value = iter.next();
if i >= len || value.is_none() {
// We only return as many items as the iterator gave us, even
// though it was supposed to give us `len`
return slice::from_raw_parts_mut(mem, i);
}
ptr::write(mem.offset(i as isize), value.unwrap());
i += 1;
}
}

#[inline]
pub fn alloc_from_iter<T, I: IntoIterator<Item = T>>(&self, iter: I) -> &mut [T] {
let mut iter = iter.into_iter();
let iter = iter.into_iter();
assert!(mem::size_of::<T>() != 0);
assert!(!mem::needs_drop::<T>());

Expand All @@ -505,10 +527,7 @@ impl DroplessArena {
let size = len.checked_mul(mem::size_of::<T>()).unwrap();
let mem = self.alloc_raw(size, mem::align_of::<T>()) as *mut _ as *mut T;
unsafe {
for i in 0..len {
ptr::write(mem.offset(i as isize), iter.next().unwrap())
}
slice::from_raw_parts_mut(mem, len)
self.write_from_iter(iter, len, mem)
}
}
(_, _) => {
Expand Down
47 changes: 45 additions & 2 deletions src/librustc/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ use std::cell::RefCell;
use std::marker::PhantomData;
use smallvec::SmallVec;

/// This declares a list of types which can be allocated by `Arena`.
///
/// The `few` modifier will cause allocation to use the shared arena and recording the destructor.
/// This is faster and more memory efficient if there's only a few allocations of the type.
/// Leaving `few` out will cause the type to get its own dedicated `TypedArena` which is
/// faster and more memory efficient if there is lots of allocations.
///
/// Specifying the `decode` modifier will add decode impls for &T and &[T] where T is the type
/// listed. These impls will appear in the implement_ty_decoder! macro.
#[macro_export]
macro_rules! arena_types {
($macro:path, $args:tt, $tcx:lifetime) => (
Expand All @@ -14,7 +23,7 @@ macro_rules! arena_types {
rustc::hir::def_id::DefId,
rustc::ty::subst::SubstsRef<$tcx>
)>,
[few] mir_keys: rustc::util::nodemap::DefIdSet,
[few, decode] mir_keys: rustc::util::nodemap::DefIdSet,
[decode] specialization_graph: rustc::traits::specialization_graph::Graph,
[] region_scope_tree: rustc::middle::region::ScopeTree,
[] item_local_set: rustc::util::nodemap::ItemLocalSet,
Expand Down Expand Up @@ -58,6 +67,40 @@ macro_rules! arena_types {
rustc::infer::canonical::Canonical<'tcx,
rustc::infer::canonical::QueryResponse<'tcx, rustc::ty::Ty<'tcx>>
>,
[few] crate_inherent_impls: rustc::ty::CrateInherentImpls,
[decode] borrowck: rustc::middle::borrowck::BorrowCheckResult,
[few] upstream_monomorphizations:
rustc::util::nodemap::DefIdMap<
rustc_data_structures::fx::FxHashMap<
rustc::ty::subst::SubstsRef<'tcx>,
rustc::hir::def_id::CrateNum
>
>,
[few] resolve_lifetimes: rustc::middle::resolve_lifetime::ResolveLifetimes,
[decode] generic_predicates: rustc::ty::GenericPredicates<'tcx>,
[few] lint_levels: rustc::lint::LintLevelMap,
[few] stability_index: rustc::middle::stability::Index<'tcx>,
[few] features: syntax::feature_gate::Features,
[few] all_traits: Vec<rustc::hir::def_id::DefId>,
[few] privacy_access_levels: rustc::middle::privacy::AccessLevels,
[few] target_features_whitelist: rustc_data_structures::fx::FxHashMap<
String,
Option<syntax::symbol::Symbol>
>,
[few] wasm_import_module_map: rustc_data_structures::fx::FxHashMap<
rustc::hir::def_id::DefId,
String
>,
[few] get_lib_features: rustc::middle::lib_features::LibFeatures,
[few] defined_lib_features: rustc::middle::lang_items::LanguageItems,
[few] visible_parent_map: rustc::util::nodemap::DefIdMap<rustc::hir::def_id::DefId>,
[few] foreign_module: rustc::middle::cstore::ForeignModule,
[few] foreign_modules: Vec<rustc::middle::cstore::ForeignModule>,
[few] reachable_non_generics: rustc::util::nodemap::DefIdMap<
rustc::middle::exported_symbols::SymbolExportLevel
>,
[few] crate_variances: rustc::ty::CrateVariancesMap<'tcx>,
[few] inferred_outlives_crate: rustc::ty::CratePredicatesMap<'tcx>,
], $tcx);
)
}
Expand Down Expand Up @@ -119,7 +162,7 @@ pub trait ArenaAllocatable {}

impl<T: Copy> ArenaAllocatable for T {}

pub unsafe trait ArenaField<'tcx>: Sized {
unsafe trait ArenaField<'tcx>: Sized {
/// Returns a specific arena to allocate from.
/// If None is returned, the DropArena will be used.
fn arena<'a>(arena: &'a Arena<'tcx>) -> Option<&'a TypedArena<Self>>;
Expand Down
37 changes: 19 additions & 18 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
pub use self::Level::*;
pub use self::LintSource::*;

use rustc_data_structures::sync::{self, Lrc};
use rustc_data_structures::sync;

use crate::hir::def_id::{CrateNum, LOCAL_CRATE};
use crate::hir::intravisit;
Expand All @@ -35,7 +35,7 @@ use crate::util::nodemap::NodeMap;
use errors::{DiagnosticBuilder, DiagnosticId};
use std::{hash, ptr};
use syntax::ast;
use syntax::source_map::{MultiSpan, ExpnFormat};
use syntax::source_map::{MultiSpan, ExpnFormat, CompilerDesugaringKind};
use syntax::early_buffered_lints::BufferedEarlyLintId;
use syntax::edition::Edition;
use syntax::symbol::{Symbol, sym};
Expand Down Expand Up @@ -767,7 +767,7 @@ pub fn maybe_lint_level_root(tcx: TyCtxt<'_, '_, '_>, id: hir::HirId) -> bool {
}

fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)
-> Lrc<LintLevelMap>
-> &'tcx LintLevelMap
{
assert_eq!(cnum, LOCAL_CRATE);
let mut builder = LintLevelMapBuilder {
Expand All @@ -784,7 +784,7 @@ fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)
intravisit::walk_crate(&mut builder, krate);
builder.levels.pop(push);

Lrc::new(builder.levels.build_map())
tcx.arena.alloc(builder.levels.build_map())
}

struct LintLevelMapBuilder<'a, 'tcx: 'a> {
Expand Down Expand Up @@ -887,21 +887,22 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
};

match info.format {
ExpnFormat::MacroAttribute(..) => return true, // definitely a plugin
ExpnFormat::CompilerDesugaring(_) => return true, // well, it's "external"
ExpnFormat::MacroBang(..) => {} // check below
}

let def_site = match info.def_site {
Some(span) => span,
// no span for the def_site means it's an external macro
None => return true,
};
ExpnFormat::MacroAttribute(..) => true, // definitely a plugin
ExpnFormat::CompilerDesugaring(CompilerDesugaringKind::ForLoop) => false,
ExpnFormat::CompilerDesugaring(_) => true, // well, it's "external"
ExpnFormat::MacroBang(..) => {
let def_site = match info.def_site {
Some(span) => span,
// no span for the def_site means it's an external macro
None => return true,
};

match sess.source_map().span_to_snippet(def_site) {
Ok(code) => !code.starts_with("macro_rules"),
// no snippet = external macro or compiler-builtin expansion
Err(_) => true,
match sess.source_map().span_to_snippet(def_site) {
Ok(code) => !code.starts_with("macro_rules"),
// no snippet = external macro or compiler-builtin expansion
Err(_) => true,
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ pub fn used_crates(tcx: TyCtxt<'_, '_, '_>, prefer: LinkagePreference)
Some((cnum, path))
})
.collect::<Vec<_>>();
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE);
Lrc::make_mut(&mut ordering).reverse();
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE).to_owned();
ordering.reverse();
libs.sort_by_cached_key(|&(a, _)| {
ordering.iter().position(|x| *x == a)
});
Expand Down
23 changes: 9 additions & 14 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::rustc::lint;
use crate::session::Session;
use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet};
use errors::{Applicability, DiagnosticBuilder};
use rustc_data_structures::sync::Lrc;
use rustc_macros::HashStable;
use std::borrow::Cow;
use std::cell::Cell;
Expand Down Expand Up @@ -211,10 +210,10 @@ struct NamedRegionMap {
/// See [`NamedRegionMap`].
#[derive(Default)]
pub struct ResolveLifetimes {
defs: FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Region>>>,
late_bound: FxHashMap<LocalDefId, Lrc<FxHashSet<ItemLocalId>>>,
defs: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Region>>,
late_bound: FxHashMap<LocalDefId, FxHashSet<ItemLocalId>>,
object_lifetime_defaults:
FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>>,
}

impl_stable_hash_for!(struct crate::middle::resolve_lifetime::ResolveLifetimes {
Expand Down Expand Up @@ -347,23 +346,21 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {

named_region_map: |tcx, id| {
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
tcx.resolve_lifetimes(LOCAL_CRATE).defs.get(&id).cloned()
tcx.resolve_lifetimes(LOCAL_CRATE).defs.get(&id)
},

is_late_bound_map: |tcx, id| {
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
tcx.resolve_lifetimes(LOCAL_CRATE)
.late_bound
.get(&id)
.cloned()
},

object_lifetime_defaults_map: |tcx, id| {
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
tcx.resolve_lifetimes(LOCAL_CRATE)
.object_lifetime_defaults
.get(&id)
.cloned()
},

..*providers
Expand All @@ -379,7 +376,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
fn resolve_lifetimes<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
for_krate: CrateNum,
) -> Lrc<ResolveLifetimes> {
) -> &'tcx ResolveLifetimes {
assert_eq!(for_krate, LOCAL_CRATE);

let named_region_map = krate(tcx);
Expand All @@ -388,24 +385,22 @@ fn resolve_lifetimes<'tcx>(

for (hir_id, v) in named_region_map.defs {
let map = rl.defs.entry(hir_id.owner_local_def_id()).or_default();
Lrc::get_mut(map).unwrap().insert(hir_id.local_id, v);
map.insert(hir_id.local_id, v);
}
for hir_id in named_region_map.late_bound {
let map = rl.late_bound
.entry(hir_id.owner_local_def_id())
.or_default();
Lrc::get_mut(map).unwrap().insert(hir_id.local_id);
map.insert(hir_id.local_id);
}
for (hir_id, v) in named_region_map.object_lifetime_defaults {
let map = rl.object_lifetime_defaults
.entry(hir_id.owner_local_def_id())
.or_default();
Lrc::get_mut(map)
.unwrap()
.insert(hir_id.local_id, Lrc::new(v));
map.insert(hir_id.local_id, v);
}

Lrc::new(rl)
tcx.arena.alloc(rl)
}

fn krate<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> NamedRegionMap {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
remaining_lib_features.remove(&Symbol::intern("test"));

let check_features =
|remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &Vec<_>| {
|remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &[_]| {
for &(feature, since) in defined_features {
if let Some(since) = since {
if let Some(span) = remaining_lib_features.get(&feature) {
Expand All @@ -908,7 +908,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
if remaining_lib_features.is_empty() {
break;
}
check_features(&mut remaining_lib_features, &tcx.defined_lib_features(cnum));
check_features(&mut remaining_lib_features, tcx.defined_lib_features(cnum));
}
}

Expand Down
Loading