Skip to content

Commit ac841e7

Browse files
committed
Auto merge of #54859 - pietroalbini:rollup, r=pietroalbini
Rollup of 11 pull requests Successful merges: - #54078 (Expand the documentation for the `std::sync` module) - #54717 (Cleanup rustc/ty part 1) - #54781 (Add examples to `TyKind::FnDef` and `TyKind::FnPtr` docs) - #54787 (Only warn about unused `mut` in user-written code) - #54804 (add suggestion for inverted function parameters) - #54812 (Regression test for #32382.) - #54833 (make `Parser::parse_foreign_item()` return a foreign item or error) - #54834 (rustdoc: overflow:auto doesn't work nicely on small screens) - #54838 (Fix typo in src/libsyntax/parse/parser.rs) - #54851 (Fix a regression in 1.30 by reverting #53564) - #54853 (Remove unneccessary error from test, revealing NLL error.) Failed merges: r? @ghost
2 parents fddcd31 + 51334c9 commit ac841e7

31 files changed

+796
-503
lines changed

src/liballoc/collections/vec_deque.rs

+5-47
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
use core::cmp::Ordering;
2121
use core::fmt;
22-
use core::isize;
2322
use core::iter::{repeat, FromIterator, FusedIterator};
2423
use core::mem;
2524
use core::ops::Bound::{Excluded, Included, Unbounded};
@@ -203,33 +202,6 @@ impl<T> VecDeque<T> {
203202
len);
204203
}
205204

206-
/// Copies all values from `src` to the back of `self`, wrapping around if needed.
207-
///
208-
/// # Safety
209-
///
210-
/// The capacity must be sufficient to hold self.len() + src.len() elements.
211-
/// If so, this function never panics.
212-
#[inline]
213-
unsafe fn copy_slice(&mut self, src: &[T]) {
214-
/// This is guaranteed by `RawVec`.
215-
debug_assert!(self.capacity() <= isize::MAX as usize);
216-
217-
let expected_new_len = self.len() + src.len();
218-
debug_assert!(self.capacity() >= expected_new_len);
219-
220-
let dst_high_ptr = self.ptr().add(self.head);
221-
let dst_high_len = self.cap() - self.head;
222-
223-
let split = cmp::min(src.len(), dst_high_len);
224-
let (src_high, src_low) = src.split_at(split);
225-
226-
ptr::copy_nonoverlapping(src_high.as_ptr(), dst_high_ptr, src_high.len());
227-
ptr::copy_nonoverlapping(src_low.as_ptr(), self.ptr(), src_low.len());
228-
229-
self.head = self.wrap_add(self.head, src.len());
230-
debug_assert!(self.len() == expected_new_len);
231-
}
232-
233205
/// Copies a potentially wrapping block of memory len long from src to dest.
234206
/// (abs(dst - src) + len) must be no larger than cap() (There must be at
235207
/// most one continuous overlapping region between src and dest).
@@ -1052,7 +1024,7 @@ impl<T> VecDeque<T> {
10521024
iter: Iter {
10531025
tail: drain_tail,
10541026
head: drain_head,
1055-
ring: unsafe { self.buffer_as_slice() },
1027+
ring: unsafe { self.buffer_as_mut_slice() },
10561028
},
10571029
}
10581030
}
@@ -1862,22 +1834,8 @@ impl<T> VecDeque<T> {
18621834
#[inline]
18631835
#[stable(feature = "append", since = "1.4.0")]
18641836
pub fn append(&mut self, other: &mut Self) {
1865-
unsafe {
1866-
// Guarantees there is space in `self` for `other`.
1867-
self.reserve(other.len());
1868-
1869-
{
1870-
let (src_high, src_low) = other.as_slices();
1871-
1872-
// This is only safe because copy_slice never panics when capacity is sufficient.
1873-
self.copy_slice(src_low);
1874-
self.copy_slice(src_high);
1875-
}
1876-
1877-
// Some values now exist in both `other` and `self` but are made inaccessible
1878-
// in`other`.
1879-
other.tail = other.head;
1880-
}
1837+
// naive impl
1838+
self.extend(other.drain(..));
18811839
}
18821840

18831841
/// Retains only the elements specified by the predicate.
@@ -2635,8 +2593,8 @@ impl<T> From<VecDeque<T>> for Vec<T> {
26352593
let mut right_offset = 0;
26362594
for i in left_edge..right_edge {
26372595
right_offset = (i - left_edge) % (cap - right_edge);
2638-
let src = right_edge + right_offset;
2639-
ptr::swap(buf.add(i), buf.add(src));
2596+
let src: isize = (right_edge + right_offset) as isize;
2597+
ptr::swap(buf.add(i), buf.offset(src));
26402598
}
26412599
let n_ops = right_edge - left_edge;
26422600
left_edge += n_ops;

src/librustc/hir/lowering.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -4132,16 +4132,16 @@ impl<'a> LoweringContext<'a> {
41324132
// expand <head>
41334133
let head = self.lower_expr(head);
41344134
let head_sp = head.span;
4135+
let desugared_span = self.allow_internal_unstable(
4136+
CompilerDesugaringKind::ForLoop,
4137+
head_sp,
4138+
);
41354139

41364140
let iter = self.str_to_ident("iter");
41374141

41384142
let next_ident = self.str_to_ident("__next");
4139-
let next_sp = self.allow_internal_unstable(
4140-
CompilerDesugaringKind::ForLoop,
4141-
head_sp,
4142-
);
41434143
let next_pat = self.pat_ident_binding_mode(
4144-
next_sp,
4144+
desugared_span,
41454145
next_ident,
41464146
hir::BindingAnnotation::Mutable,
41474147
);
@@ -4170,8 +4170,11 @@ impl<'a> LoweringContext<'a> {
41704170
};
41714171

41724172
// `mut iter`
4173-
let iter_pat =
4174-
self.pat_ident_binding_mode(head_sp, iter, hir::BindingAnnotation::Mutable);
4173+
let iter_pat = self.pat_ident_binding_mode(
4174+
desugared_span,
4175+
iter,
4176+
hir::BindingAnnotation::Mutable
4177+
);
41754178

41764179
// `match ::std::iter::Iterator::next(&mut iter) { ... }`
41774180
let match_expr = {
@@ -4200,8 +4203,12 @@ impl<'a> LoweringContext<'a> {
42004203
let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat.id));
42014204

42024205
// `let mut __next`
4203-
let next_let =
4204-
self.stmt_let_pat(head_sp, None, next_pat, hir::LocalSource::ForLoopDesugar);
4206+
let next_let = self.stmt_let_pat(
4207+
desugared_span,
4208+
None,
4209+
next_pat,
4210+
hir::LocalSource::ForLoopDesugar,
4211+
);
42054212

42064213
// `let <pat> = __next`
42074214
let pat = self.lower_pat(pat);

src/librustc/traits/error_reporting.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use ty::subst::Subst;
4646
use ty::SubtypePredicate;
4747
use util::nodemap::{FxHashMap, FxHashSet};
4848

49-
use syntax_pos::{DUMMY_SP, Span};
49+
use syntax_pos::{DUMMY_SP, Span, ExpnInfo, ExpnFormat};
5050

5151
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
5252
pub fn report_fulfillment_errors(&self,
@@ -68,18 +68,30 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
6868
}).collect();
6969

7070
for (index, error) in errors.iter().enumerate() {
71-
error_map.entry(error.obligation.cause.span).or_default().push(
71+
// We want to ignore desugarings here: spans are equivalent even
72+
// if one is the result of a desugaring and the other is not.
73+
let mut span = error.obligation.cause.span;
74+
if let Some(ExpnInfo {
75+
format: ExpnFormat::CompilerDesugaring(_),
76+
def_site: Some(def_span),
77+
..
78+
}) = span.ctxt().outer().expn_info() {
79+
span = def_span;
80+
}
81+
82+
error_map.entry(span).or_default().push(
7283
ErrorDescriptor {
7384
predicate: error.obligation.predicate.clone(),
7485
index: Some(index)
75-
});
86+
}
87+
);
7688

7789
self.reported_trait_errors.borrow_mut()
78-
.entry(error.obligation.cause.span).or_default()
90+
.entry(span).or_default()
7991
.push(error.obligation.predicate.clone());
8092
}
8193

82-
// We do this in 2 passes because we want to display errors in order, tho
94+
// We do this in 2 passes because we want to display errors in order, though
8395
// maybe it *is* better to sort errors by span or something.
8496
let mut is_suppressed = vec![false; errors.len()];
8597
for (_, error_set) in error_map.iter() {

src/librustc/ty/codec.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,19 @@ pub fn decode_predicates<'a, 'tcx, D>(decoder: &mut D)
178178
Ok(ty::GenericPredicates {
179179
parent: Decodable::decode(decoder)?,
180180
predicates: (0..decoder.read_usize()?).map(|_| {
181-
// Handle shorthands first, if we have an usize > 0x80.
182-
let predicate = if decoder.positioned_at_shorthand() {
183-
let pos = decoder.read_usize()?;
184-
assert!(pos >= SHORTHAND_OFFSET);
185-
let shorthand = pos - SHORTHAND_OFFSET;
186-
187-
decoder.with_position(shorthand, ty::Predicate::decode)
188-
} else {
189-
ty::Predicate::decode(decoder)
190-
}?;
191-
Ok((predicate, Decodable::decode(decoder)?))
192-
})
193-
.collect::<Result<Vec<_>, _>>()?,
181+
// Handle shorthands first, if we have an usize > 0x80.
182+
let predicate = if decoder.positioned_at_shorthand() {
183+
let pos = decoder.read_usize()?;
184+
assert!(pos >= SHORTHAND_OFFSET);
185+
let shorthand = pos - SHORTHAND_OFFSET;
186+
187+
decoder.with_position(shorthand, ty::Predicate::decode)
188+
} else {
189+
ty::Predicate::decode(decoder)
190+
}?;
191+
Ok((predicate, Decodable::decode(decoder)?))
192+
})
193+
.collect::<Result<Vec<_>, _>>()?,
194194
})
195195
}
196196

@@ -267,7 +267,7 @@ pub fn decode_const<'a, 'tcx, D>(decoder: &mut D)
267267

268268
#[inline]
269269
pub fn decode_allocation<'a, 'tcx, D>(decoder: &mut D)
270-
-> Result<&'tcx Allocation, D::Error>
270+
-> Result<&'tcx Allocation, D::Error>
271271
where D: TyDecoder<'a, 'tcx>,
272272
'tcx: 'a,
273273
{

src/librustc/ty/context.rs

+20-24
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
190190
// types/regions in the global interner
191191
if local as *const _ as usize == global as *const _ as usize {
192192
bug!("Attempted to intern `{:?}` which contains \
193-
inference types/regions in the global type context",
194-
&ty_struct);
193+
inference types/regions in the global type context",
194+
&ty_struct);
195195
}
196196

197197
// Don't be &mut TyS.
@@ -272,9 +272,9 @@ fn validate_hir_id_for_typeck_tables(local_id_root: Option<DefId>,
272272

273273
bug!("node {} with HirId::owner {:?} cannot be placed in \
274274
TypeckTables with local_id_root {:?}",
275-
tcx.hir.node_to_string(node_id),
276-
DefId::local(hir_id.owner),
277-
local_id_root)
275+
tcx.hir.node_to_string(node_id),
276+
DefId::local(hir_id.owner),
277+
local_id_root)
278278
});
279279
}
280280
} else {
@@ -540,16 +540,13 @@ impl<'tcx> TypeckTables<'tcx> {
540540
}
541541

542542
pub fn node_id_to_type(&self, id: hir::HirId) -> Ty<'tcx> {
543-
match self.node_id_to_type_opt(id) {
544-
Some(ty) => ty,
545-
None => {
546-
bug!("node_id_to_type: no type for node `{}`",
547-
tls::with(|tcx| {
548-
let id = tcx.hir.hir_to_node_id(id);
549-
tcx.hir.node_to_string(id)
550-
}))
551-
}
552-
}
543+
self.node_id_to_type_opt(id).unwrap_or_else(||
544+
bug!("node_id_to_type: no type for node `{}`",
545+
tls::with(|tcx| {
546+
let id = tcx.hir.hir_to_node_id(id);
547+
tcx.hir.node_to_string(id)
548+
}))
549+
)
553550
}
554551

555552
pub fn node_id_to_type_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {
@@ -686,7 +683,7 @@ impl<'tcx> TypeckTables<'tcx> {
686683
}
687684

688685
pub fn pat_adjustments_mut(&mut self)
689-
-> LocalTableInContextMut<'_, Vec<Ty<'tcx>>> {
686+
-> LocalTableInContextMut<'_, Vec<Ty<'tcx>>> {
690687
LocalTableInContextMut {
691688
local_id_root: self.local_id_root,
692689
data: &mut self.pat_adjustments,
@@ -1199,8 +1196,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11991196
let hir_id = hir.node_to_hir_id(k);
12001197
let map = trait_map.entry(hir_id.owner).or_default();
12011198
Lrc::get_mut(map).unwrap()
1202-
.insert(hir_id.local_id,
1203-
Lrc::new(StableVec::new(v)));
1199+
.insert(hir_id.local_id,
1200+
Lrc::new(StableVec::new(v)));
12041201
}
12051202

12061203
let gcx = &GlobalCtxt {
@@ -2188,7 +2185,6 @@ macro_rules! sty_debug_print {
21882185
};
21892186
$(let mut $variant = total;)*
21902187

2191-
21922188
for &Interned(t) in tcx.interners.type_.borrow().iter() {
21932189
let variant = match t.sty {
21942190
ty::Bool | ty::Char | ty::Int(..) | ty::Uint(..) |
@@ -2207,7 +2203,7 @@ macro_rules! sty_debug_print {
22072203
}
22082204
println!("Ty interner total ty region both");
22092205
$(println!(" {:18}: {uses:6} {usespc:4.1}%, \
2210-
{ty:4.1}% {region:5.1}% {both:4.1}%",
2206+
{ty:4.1}% {region:5.1}% {both:4.1}%",
22112207
stringify!($variant),
22122208
uses = $variant.total,
22132209
usespc = $variant.total as f64 * 100.0 / total.total as f64,
@@ -2216,7 +2212,7 @@ macro_rules! sty_debug_print {
22162212
both = $variant.both_infer as f64 * 100.0 / total.total as f64);
22172213
)*
22182214
println!(" total {uses:6} \
2219-
{ty:4.1}% {region:5.1}% {both:4.1}%",
2215+
{ty:4.1}% {region:5.1}% {both:4.1}%",
22202216
uses = total.total,
22212217
ty = total.ty_infer as f64 * 100.0 / total.total as f64,
22222218
region = total.region_infer as f64 * 100.0 / total.total as f64,
@@ -2653,7 +2649,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26532649
}
26542650

26552651
pub fn mk_closure(self, closure_id: DefId, closure_substs: ClosureSubsts<'tcx>)
2656-
-> Ty<'tcx> {
2652+
-> Ty<'tcx> {
26572653
self.mk_ty(Closure(closure_id, closure_substs))
26582654
}
26592655

@@ -2686,8 +2682,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26862682
}
26872683

26882684
pub fn mk_ty_param(self,
2689-
index: u32,
2690-
name: InternedString) -> Ty<'tcx> {
2685+
index: u32,
2686+
name: InternedString) -> Ty<'tcx> {
26912687
self.mk_ty(Param(ParamTy { idx: index, name: name }))
26922688
}
26932689

0 commit comments

Comments
 (0)