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 10 pull requests #64883

Merged
merged 26 commits into from
Sep 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
68d099a
Create new error code E0734 for stability attributes used outside of …
GuillaumeGomez Sep 25, 2019
0ec4513
Fix format macro expansions spans to be macro-generated
rinon Sep 25, 2019
0ebb044
Add long error explanation for E0734
GuillaumeGomez Sep 25, 2019
2e78683
Update ui tests
GuillaumeGomez Sep 25, 2019
ecfe92f
Don't check error_codes files for lints
GuillaumeGomez Sep 27, 2019
ac9aed5
getting more context for duplicate lang items (fixes #60561)
tomtau Sep 27, 2019
f922483
Print ParamTy span when accessing a field (#52082)
Baranowski Sep 26, 2019
d35f25c
Filter out stmts made for the redundant_semicolon lint when pretty-pr…
nathanwhit Sep 12, 2019
66c33c0
Add test for redundant_semicolon lint interaction with proc macro attrs
nathanwhit Sep 28, 2019
800bd3a
data_structures: Add deterministic FxHashMap and FxHashSet wrappers
inashivb Sep 3, 2019
fd505d7
Improve wording in documentation of MaybeUninit
nliberg Sep 27, 2019
f3744a1
Implement CRs
Baranowski Sep 28, 2019
9ad99c3
Refactor into ban_nonexisting_field method
Baranowski Sep 28, 2019
f6cecce
Upgrade async/await to "used" keywords.
ehuss Sep 28, 2019
c666bd5
Fix typo in intrinsics op safety
vertexclique Sep 28, 2019
e77dfa2
Slice docs: fix typo
llogiq Sep 28, 2019
b18d861
Rollup merge of #64131 - shivan1b:deterministic-fxhashmap, r=Mark-Sim…
Centril Sep 28, 2019
55a3ead
Rollup merge of #64387 - nathanwhit:redundant-semi-fix, r=varkor
Centril Sep 28, 2019
05881d0
Rollup merge of #64678 - tomtau:fix/no-std-error, r=matthewjasper
Centril Sep 28, 2019
01075d8
Rollup merge of #64763 - GuillaumeGomez:long-err-explanation-E0734, r…
Centril Sep 28, 2019
d9168e4
Rollup merge of #64793 - immunant:format_spans, r=matthewjasper
Centril Sep 28, 2019
69a3009
Rollup merge of #64837 - nliberg:patch-2, r=Centril
Centril Sep 28, 2019
6145757
Rollup merge of #64852 - Baranowski:param_note_52082, r=estebank
Centril Sep 28, 2019
787829d
Rollup merge of #64875 - ehuss:async-await-reserved, r=estebank
Centril Sep 28, 2019
1c2dd14
Rollup merge of #64876 - vertexclique:vcq/fix-fn-name-intrinsic-op-un…
Centril Sep 28, 2019
4652671
Rollup merge of #64880 - llogiq:slice-docs, r=Centril
Centril Sep 28, 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
12 changes: 6 additions & 6 deletions src/libcore/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use crate::mem::ManuallyDrop;
///
/// # Initialization invariant
///
/// The compiler, in general, assumes that variables are properly initialized
/// at their respective type. For example, a variable of reference type must
/// be aligned and non-NULL. This is an invariant that must *always* be upheld,
/// even in unsafe code. As a consequence, zero-initializing a variable of reference
/// type causes instantaneous [undefined behavior][ub], no matter whether that reference
/// ever gets used to access memory:
/// The compiler, in general, assumes that a variable is properly initialized
/// according to the requirements of the variable's type. For example, a variable of
/// reference type must be aligned and non-NULL. This is an invariant that must
/// *always* be upheld, even in unsafe code. As a consequence, zero-initializing a
/// variable of reference type causes instantaneous [undefined behavior][ub],
/// no matter whether that reference ever gets used to access memory:
///
/// ```rust,no_run
/// # #![allow(invalid_value)]
Expand Down
17 changes: 17 additions & 0 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,23 @@ Examples of erroneous code:
static X: u32 = 42;
```
"##,

E0734: r##"
A stability attribute has been used outside of the standard library.

Erroneous code examples:

```compile_fail,E0734
#[rustc_deprecated(since = "b", reason = "text")] // invalid
#[stable(feature = "a", since = "b")] // invalid
#[unstable(feature = "b", issue = "0")] // invalid
fn foo(){}
```

These attributes are meant to only be used by the standard library and are
rejected in your own crates.
"##,

;
// E0006, // merged with E0005
// E0101, // replaced with E0282
Expand Down
9 changes: 8 additions & 1 deletion src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,17 @@ pub struct ExternCrate {
/// used to select the extern with the shortest path
pub path_len: usize,

/// Crate that depends on this crate
pub dependency_of: CrateNum,
}

impl ExternCrate {
/// If true, then this crate is the crate named by the extern
/// crate referenced above. If false, then this crate is a dep
/// of the crate.
pub direct: bool,
pub fn is_direct(&self) -> bool {
self.dependency_of == LOCAL_CRATE
}
}

#[derive(Copy, Clone, Debug, HashStable)]
Expand Down
34 changes: 29 additions & 5 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::hir::def_id::DefId;
use crate::hir::check_attr::Target;
use crate::ty::{self, TyCtxt};
use crate::middle::weak_lang_items;
use crate::middle::cstore::ExternCrate;
use crate::util::nodemap::FxHashMap;

use syntax::ast;
Expand Down Expand Up @@ -182,16 +183,39 @@ impl LanguageItemCollector<'tcx> {
E0152,
"duplicate lang item found: `{}`.",
name),
None => self.tcx.sess.struct_err(&format!(
"duplicate lang item in crate `{}`: `{}`.",
self.tcx.crate_name(item_def_id.krate),
name)),
None => {
match self.tcx.extern_crate(item_def_id) {
Some(ExternCrate {dependency_of, ..}) => {
self.tcx.sess.struct_err(&format!(
"duplicate lang item in crate `{}` (which `{}` depends on): `{}`.",
self.tcx.crate_name(item_def_id.krate),
self.tcx.crate_name(*dependency_of),
name))
},
_ => {
self.tcx.sess.struct_err(&format!(
"duplicate lang item in crate `{}`: `{}`.",
self.tcx.crate_name(item_def_id.krate),
name))
}
}
},
};
if let Some(span) = self.tcx.hir().span_if_local(original_def_id) {
span_note!(&mut err, span, "first defined here.");
} else {
err.note(&format!("first defined in crate `{}`.",
match self.tcx.extern_crate(original_def_id) {
Some(ExternCrate {dependency_of, ..}) => {
err.note(&format!(
"first defined in crate `{}` (which `{}` depends on).",
self.tcx.crate_name(original_def_id.krate),
self.tcx.crate_name(*dependency_of)));
},
_ => {
err.note(&format!("first defined in crate `{}`.",
self.tcx.crate_name(original_def_id.krate)));
}
}
}
err.emit();
}
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
let name = attr.name_or_empty();
if [sym::unstable, sym::stable, sym::rustc_deprecated].contains(&name) {
attr::mark_used(attr);
self.tcx.sess.span_err(attr.span, "stability attributes may not be used \
outside of the standard library");
struct_span_err!(
self.tcx.sess,
attr.span,
E0734,
"stability attributes may not be used outside of the standard library",
).emit();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ pub trait PrettyPrinter<'tcx>:
match self.tcx().extern_crate(def_id) {
Some(&ExternCrate {
src: ExternCrateSource::Extern(def_id),
direct: true,
dependency_of: LOCAL_CRATE,
span,
..
}) => {
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_data_structures/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub mod box_region;
pub mod const_cstr;
pub mod flock;
pub mod fx;
pub mod stable_map;
pub mod graph;
pub mod indexed_vec;
pub mod jobserver;
Expand All @@ -84,6 +85,7 @@ pub mod small_c_str;
pub mod snapshot_map;
pub use ena::snapshot_vec;
pub mod sorted_map;
pub mod stable_set;
#[macro_use] pub mod stable_hasher;
pub mod sync;
pub mod sharded;
Expand Down
99 changes: 99 additions & 0 deletions src/librustc_data_structures/stable_map.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
pub use rustc_hash::FxHashMap;
use std::borrow::Borrow;
use std::collections::hash_map::Entry;
use std::fmt;
use std::hash::Hash;

/// A deterministic wrapper around FxHashMap that does not provide iteration support.
///
/// It supports insert, remove, get and get_mut functions from FxHashMap.
/// It also allows to convert hashmap to a sorted vector with the method `into_sorted_vector()`.
#[derive(Clone)]
pub struct StableMap<K, V> {
base: FxHashMap<K, V>,
}

impl<K, V> Default for StableMap<K, V>
where
K: Eq + Hash,
{
fn default() -> StableMap<K, V> {
StableMap::new()
}
}

impl<K, V> fmt::Debug for StableMap<K, V>
where
K: Eq + Hash + fmt::Debug,
V: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.base)
}
}

impl<K, V> PartialEq for StableMap<K, V>
where
K: Eq + Hash,
V: PartialEq,
{
fn eq(&self, other: &StableMap<K, V>) -> bool {
self.base == other.base
}
}

impl<K, V> Eq for StableMap<K, V>
where
K: Eq + Hash,
V: Eq,
{}

impl<K, V> StableMap<K, V>
where
K: Eq + Hash,
{
pub fn new() -> StableMap<K, V> {
StableMap { base: FxHashMap::default() }
}

pub fn into_sorted_vector(self) -> Vec<(K, V)>
where
K: Ord + Copy,
{
let mut vector = self.base.into_iter().collect::<Vec<_>>();
vector.sort_unstable_by_key(|pair| pair.0);
vector
}

pub fn entry(&mut self, k: K) -> Entry<'_, K, V> {
self.base.entry(k)
}

pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
where
K: Borrow<Q>,
Q: Hash + Eq,
{
self.base.get(k)
}

pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>
where
K: Borrow<Q>,
Q: Hash + Eq,
{
self.base.get_mut(k)
}

pub fn insert(&mut self, k: K, v: V) -> Option<V> {
self.base.insert(k, v)
}

pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>
where
K: Borrow<Q>,
Q: Hash + Eq,
{
self.base.remove(k)
}
}
77 changes: 77 additions & 0 deletions src/librustc_data_structures/stable_set.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
pub use rustc_hash::FxHashSet;
use std::borrow::Borrow;
use std::fmt;
use std::hash::Hash;

/// A deterministic wrapper around FxHashSet that does not provide iteration support.
///
/// It supports insert, remove, get functions from FxHashSet.
/// It also allows to convert hashset to a sorted vector with the method `into_sorted_vector()`.
#[derive(Clone)]
pub struct StableSet<T> {
base: FxHashSet<T>,
}

impl<T> Default for StableSet<T>
where
T: Eq + Hash,
{
fn default() -> StableSet<T> {
StableSet::new()
}
}

impl<T> fmt::Debug for StableSet<T>
where
T: Eq + Hash + fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.base)
}
}

impl<T> PartialEq<StableSet<T>> for StableSet<T>
where
T: Eq + Hash,
{
fn eq(&self, other: &StableSet<T>) -> bool {
self.base == other.base
}
}

impl<T> Eq for StableSet<T> where T: Eq + Hash {}

impl<T: Hash + Eq> StableSet<T> {
pub fn new() -> StableSet<T> {
StableSet { base: FxHashSet::default() }
}

pub fn into_sorted_vector(self) -> Vec<T>
where
T: Ord,
{
let mut vector = self.base.into_iter().collect::<Vec<_>>();
vector.sort_unstable();
vector
}

pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T>
where
T: Borrow<Q>,
Q: Hash + Eq,
{
self.base.get(value)
}

pub fn insert(&mut self, value: T) -> bool {
self.base.insert(value)
}

pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool
where
T: Borrow<Q>,
Q: Hash + Eq,
{
self.base.remove(value)
}
}
Loading