Skip to content

Commit 7531d2f

Browse files
committed
Auto merge of rust-lang#93021 - matthiaskrgr:rollup-o7z8zoe, r=matthiaskrgr
Rollup of 14 pull requests Successful merges: - rust-lang#92629 (Pick themes on settings page, not every page) - rust-lang#92640 (Fix ICEs related to `Deref<Target=[T; N]>` on newtypes) - rust-lang#92701 (Add some more attribute validation) - rust-lang#92803 (Hide mobile sidebar on some clicks) - rust-lang#92830 (Rustdoc style cleanups) - rust-lang#92866 ("Does exists" typos fix) - rust-lang#92870 (add `rustc_diagnostic_item` attribute to `AtomicBool` type) - rust-lang#92914 (htmldocck: Add support for `/text()` in ``@snapshot`)` - rust-lang#92923 (Abstract the pretty printer's ringbuffer to be infinitely sized) - rust-lang#92946 (Exclude llvm-libunwind from the self-contained set on s390x-musl targets) - rust-lang#92947 (rustdoc: Use `intersperse` in a `visit_path` function) - rust-lang#92997 (Add `~const` bound test for negative impls) - rust-lang#93004 (update codegen test for LLVM 14) - rust-lang#93016 (Stabilize vec_spare_capacity) Failed merges: - rust-lang#92924 (Delete pretty printer tracing) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e4ff903 + 83b1a94 commit 7531d2f

File tree

46 files changed

+687
-310
lines changed

Some content is hidden

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

46 files changed

+687
-310
lines changed

compiler/rustc_ast_pretty/src/pp.rs

+14-22
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
//! methods called `Printer::scan_*`, and the 'PRINT' process is the
133133
//! method called `Printer::print`.
134134
135+
mod ring;
136+
137+
use ring::RingBuffer;
135138
use std::borrow::Cow;
136139
use std::collections::VecDeque;
137140
use std::fmt;
@@ -190,8 +193,7 @@ impl fmt::Display for Token {
190193
}
191194
}
192195

193-
fn buf_str(buf: &[BufEntry], left: usize, right: usize, lim: usize) -> String {
194-
let n = buf.len();
196+
fn buf_str(buf: &RingBuffer<BufEntry>, left: usize, right: usize, lim: usize) -> String {
195197
let mut i = left;
196198
let mut l = lim;
197199
let mut s = String::from("[");
@@ -202,7 +204,6 @@ fn buf_str(buf: &[BufEntry], left: usize, right: usize, lim: usize) -> String {
202204
}
203205
s.push_str(&format!("{}={}", buf[i].size, &buf[i].token));
204206
i += 1;
205-
i %= n;
206207
}
207208
s.push(']');
208209
s
@@ -224,7 +225,6 @@ const SIZE_INFINITY: isize = 0xffff;
224225

225226
pub struct Printer {
226227
out: String,
227-
buf_max_len: usize,
228228
/// Width of lines we're constrained to
229229
margin: isize,
230230
/// Number of spaces left on line
@@ -234,7 +234,7 @@ pub struct Printer {
234234
/// Index of right side of input stream
235235
right: usize,
236236
/// Ring-buffer of tokens and calculated sizes
237-
buf: Vec<BufEntry>,
237+
buf: RingBuffer<BufEntry>,
238238
/// Running size of stream "...left"
239239
left_total: isize,
240240
/// Running size of stream "...right"
@@ -267,19 +267,16 @@ impl Default for BufEntry {
267267
impl Printer {
268268
pub fn new() -> Self {
269269
let linewidth = 78;
270-
// Yes 55, it makes the ring buffers big enough to never fall behind.
271-
let n: usize = 55 * linewidth;
272270
debug!("Printer::new {}", linewidth);
271+
let mut buf = RingBuffer::new();
272+
buf.advance_right();
273273
Printer {
274274
out: String::new(),
275-
buf_max_len: n,
276275
margin: linewidth as isize,
277276
space: linewidth as isize,
278277
left: 0,
279278
right: 0,
280-
// Initialize a single entry; advance_right() will extend it on demand
281-
// up to `buf_max_len` elements.
282-
buf: vec![BufEntry::default()],
279+
buf,
283280
left_total: 0,
284281
right_total: 0,
285282
scan_stack: VecDeque::new(),
@@ -308,8 +305,8 @@ impl Printer {
308305
if self.scan_stack.is_empty() {
309306
self.left_total = 1;
310307
self.right_total = 1;
311-
self.left = 0;
312-
self.right = 0;
308+
self.right = self.left;
309+
self.buf.truncate(1);
313310
} else {
314311
self.advance_right();
315312
}
@@ -332,8 +329,8 @@ impl Printer {
332329
if self.scan_stack.is_empty() {
333330
self.left_total = 1;
334331
self.right_total = 1;
335-
self.left = 0;
336-
self.right = 0;
332+
self.right = self.left;
333+
self.buf.truncate(1);
337334
} else {
338335
self.advance_right();
339336
}
@@ -400,12 +397,7 @@ impl Printer {
400397

401398
fn advance_right(&mut self) {
402399
self.right += 1;
403-
self.right %= self.buf_max_len;
404-
// Extend the buf if necessary.
405-
if self.right == self.buf.len() {
406-
self.buf.push(BufEntry::default());
407-
}
408-
assert_ne!(self.right, self.left);
400+
self.buf.advance_right();
409401
}
410402

411403
fn advance_left(&mut self) {
@@ -437,8 +429,8 @@ impl Printer {
437429
break;
438430
}
439431

432+
self.buf.advance_left();
440433
self.left += 1;
441-
self.left %= self.buf_max_len;
442434

443435
left_size = self.buf[self.left].size;
444436
}
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use std::collections::VecDeque;
2+
use std::ops::{Index, IndexMut};
3+
4+
/// A view onto a finite range of an infinitely long sequence of T.
5+
///
6+
/// The Ts are indexed 0..infinity. A RingBuffer begins as a view of elements
7+
/// 0..0 (i.e. nothing). The user of the RingBuffer advances its left and right
8+
/// position independently, although only in the positive direction, and only
9+
/// with left <= right at all times.
10+
///
11+
/// Holding a RingBuffer whose view is elements left..right gives the ability to
12+
/// use Index and IndexMut to access elements i in the infinitely long queue for
13+
/// which left <= i < right.
14+
pub struct RingBuffer<T> {
15+
data: VecDeque<T>,
16+
// Abstract index of data[0] in the infinitely sized queue.
17+
offset: usize,
18+
}
19+
20+
impl<T> RingBuffer<T> {
21+
pub fn new() -> Self {
22+
RingBuffer { data: VecDeque::new(), offset: 0 }
23+
}
24+
25+
pub fn advance_right(&mut self)
26+
where
27+
T: Default,
28+
{
29+
self.data.push_back(T::default());
30+
}
31+
32+
pub fn advance_left(&mut self) {
33+
self.data.pop_front().unwrap();
34+
self.offset += 1;
35+
}
36+
37+
pub fn truncate(&mut self, len: usize) {
38+
self.data.truncate(len);
39+
}
40+
}
41+
42+
impl<T> Index<usize> for RingBuffer<T> {
43+
type Output = T;
44+
fn index(&self, index: usize) -> &Self::Output {
45+
&self.data[index.checked_sub(self.offset).unwrap()]
46+
}
47+
}
48+
49+
impl<T> IndexMut<usize> for RingBuffer<T> {
50+
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
51+
&mut self.data[index.checked_sub(self.offset).unwrap()]
52+
}
53+
}

compiler/rustc_feature/src/builtin_attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
352352

353353
// Runtime
354354
ungated!(
355-
windows_subsystem, Normal,
355+
windows_subsystem, CrateLevel,
356356
template!(NameValueStr: "windows|console"), FutureWarnFollowing
357357
),
358358
ungated!(panic_handler, Normal, template!(Word), WarnFollowing), // RFC 2070
359359

360360
// Code generation:
361361
ungated!(inline, Normal, template!(Word, List: "always|never"), FutureWarnFollowing),
362362
ungated!(cold, Normal, template!(Word), WarnFollowing),
363-
ungated!(no_builtins, Normal, template!(Word), WarnFollowing),
363+
ungated!(no_builtins, CrateLevel, template!(Word), WarnFollowing),
364364
ungated!(target_feature, Normal, template!(List: r#"enable = "name""#), DuplicatesOk),
365365
ungated!(track_caller, Normal, template!(Word), WarnFollowing),
366366
gated!(

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
425425
// FIXME: perf problem described in #55921.
426426
ui = ty::UniverseIndex::ROOT;
427427
return self.canonicalize_const_var(
428-
CanonicalVarInfo { kind: CanonicalVarKind::Const(ui) },
428+
CanonicalVarInfo { kind: CanonicalVarKind::Const(ui, ct.ty) },
429429
ct,
430430
);
431431
}

compiler/rustc_infer/src/infer/canonical/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
137137
self.tcx.mk_region(ty::RePlaceholder(placeholder_mapped)).into()
138138
}
139139

140-
CanonicalVarKind::Const(ui) => self
140+
CanonicalVarKind::Const(ui, ty) => self
141141
.next_const_var_in_universe(
142-
self.next_ty_var_in_universe(
143-
TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span },
144-
universe_map(ui),
145-
),
142+
ty,
146143
ConstVariableOrigin { kind: ConstVariableOriginKind::MiscVariable, span },
147144
universe_map(ui),
148145
)

compiler/rustc_middle/src/infer/canonical.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
2424
use crate::infer::MemberConstraint;
2525
use crate::ty::subst::GenericArg;
26-
use crate::ty::{self, BoundVar, List, Region, TyCtxt};
26+
use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt};
2727
use rustc_index::vec::IndexVec;
2828
use rustc_macros::HashStable;
2929
use smallvec::SmallVec;
@@ -104,7 +104,7 @@ impl<'tcx> CanonicalVarInfo<'tcx> {
104104
CanonicalVarKind::PlaceholderTy(_) => false,
105105
CanonicalVarKind::Region(_) => true,
106106
CanonicalVarKind::PlaceholderRegion(..) => false,
107-
CanonicalVarKind::Const(_) => true,
107+
CanonicalVarKind::Const(..) => true,
108108
CanonicalVarKind::PlaceholderConst(_) => false,
109109
}
110110
}
@@ -130,7 +130,7 @@ pub enum CanonicalVarKind<'tcx> {
130130
PlaceholderRegion(ty::PlaceholderRegion),
131131

132132
/// Some kind of const inference variable.
133-
Const(ty::UniverseIndex),
133+
Const(ty::UniverseIndex, Ty<'tcx>),
134134

135135
/// A "placeholder" that represents "any const".
136136
PlaceholderConst(ty::PlaceholderConst<'tcx>),
@@ -147,7 +147,7 @@ impl<'tcx> CanonicalVarKind<'tcx> {
147147
CanonicalVarKind::PlaceholderTy(placeholder) => placeholder.universe,
148148
CanonicalVarKind::Region(ui) => ui,
149149
CanonicalVarKind::PlaceholderRegion(placeholder) => placeholder.universe,
150-
CanonicalVarKind::Const(ui) => ui,
150+
CanonicalVarKind::Const(ui, _) => ui,
151151
CanonicalVarKind::PlaceholderConst(placeholder) => placeholder.universe,
152152
}
153153
}

compiler/rustc_passes/src/check_attr.rs

+21
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl CheckAttrVisitor<'_> {
126126
// lint-only checks
127127
match attr.name_or_empty() {
128128
sym::cold => self.check_cold(hir_id, attr, span, target),
129+
sym::link => self.check_link(hir_id, attr, span, target),
129130
sym::link_name => self.check_link_name(hir_id, attr, span, target),
130131
sym::link_section => self.check_link_section(hir_id, attr, span, target),
131132
sym::no_mangle => self.check_no_mangle(hir_id, attr, span, target),
@@ -1157,6 +1158,26 @@ impl CheckAttrVisitor<'_> {
11571158
}
11581159
}
11591160

1161+
/// Checks if `#[link]` is applied to an item other than a foreign module.
1162+
fn check_link(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
1163+
match target {
1164+
Target::ForeignMod => {}
1165+
_ => {
1166+
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
1167+
let mut diag = lint.build("attribute should be applied to an `extern` block");
1168+
diag.warn(
1169+
"this was previously accepted by the compiler but is \
1170+
being phased out; it will become a hard error in \
1171+
a future release!",
1172+
);
1173+
1174+
diag.span_label(*span, "not an `extern` block");
1175+
diag.emit();
1176+
});
1177+
}
1178+
}
1179+
}
1180+
11601181
/// Checks if `#[link_name]` is applied to an item other than a foreign function or static.
11611182
fn check_link_name(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
11621183
match target {

compiler/rustc_traits/src/chalk/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ crate fn evaluate_goal<'tcx>(
8585
chalk_ir::VariableKind::Lifetime,
8686
chalk_ir::UniverseIndex { counter: ui.index() },
8787
),
88-
CanonicalVarKind::Const(_ui) => unimplemented!(),
88+
CanonicalVarKind::Const(_ui, _ty) => unimplemented!(),
8989
CanonicalVarKind::PlaceholderConst(_pc) => unimplemented!(),
9090
}),
9191
),
@@ -127,9 +127,9 @@ crate fn evaluate_goal<'tcx>(
127127
chalk_ir::VariableKind::Lifetime => CanonicalVarKind::Region(
128128
ty::UniverseIndex::from_usize(var.skip_kind().counter),
129129
),
130-
chalk_ir::VariableKind::Const(_) => CanonicalVarKind::Const(
131-
ty::UniverseIndex::from_usize(var.skip_kind().counter),
132-
),
130+
// FIXME(compiler-errors): We don't currently have a way of turning
131+
// a Chalk ty back into a rustc ty, right?
132+
chalk_ir::VariableKind::Const(_) => todo!(),
133133
};
134134
CanonicalVarInfo { kind }
135135
})

compiler/rustc_typeck/src/check/method/confirm.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
149149
// time writing the results into the various typeck results.
150150
let mut autoderef =
151151
self.autoderef_overloaded_span(self.span, unadjusted_self_ty, self.call_expr.span);
152-
let (_, n) = match autoderef.nth(pick.autoderefs) {
152+
let (ty, n) = match autoderef.nth(pick.autoderefs) {
153153
Some(n) => n,
154154
None => {
155155
return self.tcx.ty_error_with_message(
@@ -161,14 +161,15 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
161161
assert_eq!(n, pick.autoderefs);
162162

163163
let mut adjustments = self.adjust_steps(&autoderef);
164+
let mut target = self.structurally_resolved_type(autoderef.span(), ty);
164165

165-
let mut target =
166-
self.structurally_resolved_type(autoderef.span(), autoderef.final_ty(false));
167-
168-
match &pick.autoref_or_ptr_adjustment {
166+
match pick.autoref_or_ptr_adjustment {
169167
Some(probe::AutorefOrPtrAdjustment::Autoref { mutbl, unsize }) => {
170168
let region = self.next_region_var(infer::Autoref(self.span));
171-
target = self.tcx.mk_ref(region, ty::TypeAndMut { mutbl: *mutbl, ty: target });
169+
// Type we're wrapping in a reference, used later for unsizing
170+
let base_ty = target;
171+
172+
target = self.tcx.mk_ref(region, ty::TypeAndMut { mutbl, ty: target });
172173
let mutbl = match mutbl {
173174
hir::Mutability::Not => AutoBorrowMutability::Not,
174175
hir::Mutability::Mut => AutoBorrowMutability::Mut {
@@ -182,10 +183,18 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
182183
target,
183184
});
184185

185-
if let Some(unsize_target) = unsize {
186+
if unsize {
187+
let unsized_ty = if let ty::Array(elem_ty, _) = base_ty.kind() {
188+
self.tcx.mk_slice(elem_ty)
189+
} else {
190+
bug!(
191+
"AutorefOrPtrAdjustment's unsize flag should only be set for array ty, found {}",
192+
base_ty
193+
)
194+
};
186195
target = self
187196
.tcx
188-
.mk_ref(region, ty::TypeAndMut { mutbl: mutbl.into(), ty: unsize_target });
197+
.mk_ref(region, ty::TypeAndMut { mutbl: mutbl.into(), ty: unsized_ty });
189198
adjustments
190199
.push(Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target });
191200
}

0 commit comments

Comments
 (0)