Skip to content

Commit b61e694

Browse files
committed
Auto merge of #64883 - Centril:rollup-uehjt63, r=Centril
Rollup of 10 pull requests Successful merges: - #64131 (data_structures: Add deterministic FxHashMap and FxHashSet wrappers) - #64387 (Fix redundant semicolon lint interaction with proc macro attributes) - #64678 (added more context for duplicate lang item errors (fixes #60561)) - #64763 (Add E0734 and its long explanation) - #64793 (Fix format macro expansions spans to be macro-generated) - #64837 (Improve wording in documentation of MaybeUninit) - #64852 (Print ParamTy span when accessing a field (#52082)) - #64875 (Upgrade async/await to "used" keywords.) - #64876 (Fix typo in intrinsics op safety) - #64880 (Slice docs: fix typo) Failed merges: r? @ghost
2 parents 488381c + 4652671 commit b61e694

File tree

54 files changed

+620
-163
lines changed

Some content is hidden

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

54 files changed

+620
-163
lines changed

src/libcore/mem/maybe_uninit.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use crate::mem::ManuallyDrop;
55
///
66
/// # Initialization invariant
77
///
8-
/// The compiler, in general, assumes that variables are properly initialized
9-
/// at their respective type. For example, a variable of reference type must
10-
/// be aligned and non-NULL. This is an invariant that must *always* be upheld,
11-
/// even in unsafe code. As a consequence, zero-initializing a variable of reference
12-
/// type causes instantaneous [undefined behavior][ub], no matter whether that reference
13-
/// ever gets used to access memory:
8+
/// The compiler, in general, assumes that a variable is properly initialized
9+
/// according to the requirements of the variable's type. For example, a variable of
10+
/// reference type must be aligned and non-NULL. This is an invariant that must
11+
/// *always* be upheld, even in unsafe code. As a consequence, zero-initializing a
12+
/// variable of reference type causes instantaneous [undefined behavior][ub],
13+
/// no matter whether that reference ever gets used to access memory:
1414
///
1515
/// ```rust,no_run
1616
/// # #![allow(invalid_value)]

src/librustc/error_codes.rs

+17
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,23 @@ Examples of erroneous code:
22172217
static X: u32 = 42;
22182218
```
22192219
"##,
2220+
2221+
E0734: r##"
2222+
A stability attribute has been used outside of the standard library.
2223+
2224+
Erroneous code examples:
2225+
2226+
```compile_fail,E0734
2227+
#[rustc_deprecated(since = "b", reason = "text")] // invalid
2228+
#[stable(feature = "a", since = "b")] // invalid
2229+
#[unstable(feature = "b", issue = "0")] // invalid
2230+
fn foo(){}
2231+
```
2232+
2233+
These attributes are meant to only be used by the standard library and are
2234+
rejected in your own crates.
2235+
"##,
2236+
22202237
;
22212238
// E0006, // merged with E0005
22222239
// E0101, // replaced with E0282

src/librustc/middle/cstore.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,17 @@ pub struct ExternCrate {
126126
/// used to select the extern with the shortest path
127127
pub path_len: usize,
128128

129+
/// Crate that depends on this crate
130+
pub dependency_of: CrateNum,
131+
}
132+
133+
impl ExternCrate {
129134
/// If true, then this crate is the crate named by the extern
130135
/// crate referenced above. If false, then this crate is a dep
131136
/// of the crate.
132-
pub direct: bool,
137+
pub fn is_direct(&self) -> bool {
138+
self.dependency_of == LOCAL_CRATE
139+
}
133140
}
134141

135142
#[derive(Copy, Clone, Debug, HashStable)]

src/librustc/middle/lang_items.rs

+29-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::hir::def_id::DefId;
1313
use crate::hir::check_attr::Target;
1414
use crate::ty::{self, TyCtxt};
1515
use crate::middle::weak_lang_items;
16+
use crate::middle::cstore::ExternCrate;
1617
use crate::util::nodemap::FxHashMap;
1718

1819
use syntax::ast;
@@ -182,16 +183,39 @@ impl LanguageItemCollector<'tcx> {
182183
E0152,
183184
"duplicate lang item found: `{}`.",
184185
name),
185-
None => self.tcx.sess.struct_err(&format!(
186-
"duplicate lang item in crate `{}`: `{}`.",
187-
self.tcx.crate_name(item_def_id.krate),
188-
name)),
186+
None => {
187+
match self.tcx.extern_crate(item_def_id) {
188+
Some(ExternCrate {dependency_of, ..}) => {
189+
self.tcx.sess.struct_err(&format!(
190+
"duplicate lang item in crate `{}` (which `{}` depends on): `{}`.",
191+
self.tcx.crate_name(item_def_id.krate),
192+
self.tcx.crate_name(*dependency_of),
193+
name))
194+
},
195+
_ => {
196+
self.tcx.sess.struct_err(&format!(
197+
"duplicate lang item in crate `{}`: `{}`.",
198+
self.tcx.crate_name(item_def_id.krate),
199+
name))
200+
}
201+
}
202+
},
189203
};
190204
if let Some(span) = self.tcx.hir().span_if_local(original_def_id) {
191205
span_note!(&mut err, span, "first defined here.");
192206
} else {
193-
err.note(&format!("first defined in crate `{}`.",
207+
match self.tcx.extern_crate(original_def_id) {
208+
Some(ExternCrate {dependency_of, ..}) => {
209+
err.note(&format!(
210+
"first defined in crate `{}` (which `{}` depends on).",
211+
self.tcx.crate_name(original_def_id.krate),
212+
self.tcx.crate_name(*dependency_of)));
213+
},
214+
_ => {
215+
err.note(&format!("first defined in crate `{}`.",
194216
self.tcx.crate_name(original_def_id.krate)));
217+
}
218+
}
195219
}
196220
err.emit();
197221
}

src/librustc/middle/stability.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,12 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
199199
let name = attr.name_or_empty();
200200
if [sym::unstable, sym::stable, sym::rustc_deprecated].contains(&name) {
201201
attr::mark_used(attr);
202-
self.tcx.sess.span_err(attr.span, "stability attributes may not be used \
203-
outside of the standard library");
202+
struct_span_err!(
203+
self.tcx.sess,
204+
attr.span,
205+
E0734,
206+
"stability attributes may not be used outside of the standard library",
207+
).emit();
204208
}
205209
}
206210

src/librustc/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub trait PrettyPrinter<'tcx>:
278278
match self.tcx().extern_crate(def_id) {
279279
Some(&ExternCrate {
280280
src: ExternCrateSource::Extern(def_id),
281-
direct: true,
281+
dependency_of: LOCAL_CRATE,
282282
span,
283283
..
284284
}) => {

src/librustc_data_structures/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub mod box_region;
7373
pub mod const_cstr;
7474
pub mod flock;
7575
pub mod fx;
76+
pub mod stable_map;
7677
pub mod graph;
7778
pub mod indexed_vec;
7879
pub mod jobserver;
@@ -84,6 +85,7 @@ pub mod small_c_str;
8485
pub mod snapshot_map;
8586
pub use ena::snapshot_vec;
8687
pub mod sorted_map;
88+
pub mod stable_set;
8789
#[macro_use] pub mod stable_hasher;
8890
pub mod sync;
8991
pub mod sharded;
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
pub use rustc_hash::FxHashMap;
2+
use std::borrow::Borrow;
3+
use std::collections::hash_map::Entry;
4+
use std::fmt;
5+
use std::hash::Hash;
6+
7+
/// A deterministic wrapper around FxHashMap that does not provide iteration support.
8+
///
9+
/// It supports insert, remove, get and get_mut functions from FxHashMap.
10+
/// It also allows to convert hashmap to a sorted vector with the method `into_sorted_vector()`.
11+
#[derive(Clone)]
12+
pub struct StableMap<K, V> {
13+
base: FxHashMap<K, V>,
14+
}
15+
16+
impl<K, V> Default for StableMap<K, V>
17+
where
18+
K: Eq + Hash,
19+
{
20+
fn default() -> StableMap<K, V> {
21+
StableMap::new()
22+
}
23+
}
24+
25+
impl<K, V> fmt::Debug for StableMap<K, V>
26+
where
27+
K: Eq + Hash + fmt::Debug,
28+
V: fmt::Debug,
29+
{
30+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31+
write!(f, "{:?}", self.base)
32+
}
33+
}
34+
35+
impl<K, V> PartialEq for StableMap<K, V>
36+
where
37+
K: Eq + Hash,
38+
V: PartialEq,
39+
{
40+
fn eq(&self, other: &StableMap<K, V>) -> bool {
41+
self.base == other.base
42+
}
43+
}
44+
45+
impl<K, V> Eq for StableMap<K, V>
46+
where
47+
K: Eq + Hash,
48+
V: Eq,
49+
{}
50+
51+
impl<K, V> StableMap<K, V>
52+
where
53+
K: Eq + Hash,
54+
{
55+
pub fn new() -> StableMap<K, V> {
56+
StableMap { base: FxHashMap::default() }
57+
}
58+
59+
pub fn into_sorted_vector(self) -> Vec<(K, V)>
60+
where
61+
K: Ord + Copy,
62+
{
63+
let mut vector = self.base.into_iter().collect::<Vec<_>>();
64+
vector.sort_unstable_by_key(|pair| pair.0);
65+
vector
66+
}
67+
68+
pub fn entry(&mut self, k: K) -> Entry<'_, K, V> {
69+
self.base.entry(k)
70+
}
71+
72+
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
73+
where
74+
K: Borrow<Q>,
75+
Q: Hash + Eq,
76+
{
77+
self.base.get(k)
78+
}
79+
80+
pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>
81+
where
82+
K: Borrow<Q>,
83+
Q: Hash + Eq,
84+
{
85+
self.base.get_mut(k)
86+
}
87+
88+
pub fn insert(&mut self, k: K, v: V) -> Option<V> {
89+
self.base.insert(k, v)
90+
}
91+
92+
pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>
93+
where
94+
K: Borrow<Q>,
95+
Q: Hash + Eq,
96+
{
97+
self.base.remove(k)
98+
}
99+
}
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
pub use rustc_hash::FxHashSet;
2+
use std::borrow::Borrow;
3+
use std::fmt;
4+
use std::hash::Hash;
5+
6+
/// A deterministic wrapper around FxHashSet that does not provide iteration support.
7+
///
8+
/// It supports insert, remove, get functions from FxHashSet.
9+
/// It also allows to convert hashset to a sorted vector with the method `into_sorted_vector()`.
10+
#[derive(Clone)]
11+
pub struct StableSet<T> {
12+
base: FxHashSet<T>,
13+
}
14+
15+
impl<T> Default for StableSet<T>
16+
where
17+
T: Eq + Hash,
18+
{
19+
fn default() -> StableSet<T> {
20+
StableSet::new()
21+
}
22+
}
23+
24+
impl<T> fmt::Debug for StableSet<T>
25+
where
26+
T: Eq + Hash + fmt::Debug,
27+
{
28+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29+
write!(f, "{:?}", self.base)
30+
}
31+
}
32+
33+
impl<T> PartialEq<StableSet<T>> for StableSet<T>
34+
where
35+
T: Eq + Hash,
36+
{
37+
fn eq(&self, other: &StableSet<T>) -> bool {
38+
self.base == other.base
39+
}
40+
}
41+
42+
impl<T> Eq for StableSet<T> where T: Eq + Hash {}
43+
44+
impl<T: Hash + Eq> StableSet<T> {
45+
pub fn new() -> StableSet<T> {
46+
StableSet { base: FxHashSet::default() }
47+
}
48+
49+
pub fn into_sorted_vector(self) -> Vec<T>
50+
where
51+
T: Ord,
52+
{
53+
let mut vector = self.base.into_iter().collect::<Vec<_>>();
54+
vector.sort_unstable();
55+
vector
56+
}
57+
58+
pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T>
59+
where
60+
T: Borrow<Q>,
61+
Q: Hash + Eq,
62+
{
63+
self.base.get(value)
64+
}
65+
66+
pub fn insert(&mut self, value: T) -> bool {
67+
self.base.insert(value)
68+
}
69+
70+
pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool
71+
where
72+
T: Borrow<Q>,
73+
Q: Hash + Eq,
74+
{
75+
self.base.remove(value)
76+
}
77+
}

0 commit comments

Comments
 (0)