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 14 pull requests #93021

Merged
merged 34 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
59d4bae
Add validation for `link` attribute position.
ehuss Jan 9, 2022
b59e743
Mark windows_subsytem and no_builtins as crate-only attributes.
ehuss Jan 9, 2022
012910d
Canonicalize const variables correctly
compiler-errors Jan 7, 2022
9bf9fe0
Don't leak inference variables in array unsizing
compiler-errors Jan 7, 2022
7bf0cb7
Add new tests, fix up old tests
compiler-errors Jan 7, 2022
a7092f9
Typos fix
maxwase Jan 13, 2022
5431d5b
Add rustc_diagnostic_item attribute to AtomicBool
llogiq Jan 13, 2022
c4b994f
Pick themes on settings page, not every page
jsha Jan 6, 2022
04f0402
Add support for "always theme" in setting
jsha Jan 7, 2022
9c6d8ef
htmldocck: Add support for `/text()` in `@snapshot`
camelid Jan 15, 2022
1a37262
Exclude llvm-libunwind from the self-contained set on s390x-musl targ…
kaniini Jan 15, 2022
47de5b4
Remove `collect`
vacuus Jan 15, 2022
e6aef25
Add `~const` bound test for negative impls
lilasta Jan 17, 2022
853feb6
update codegen test for LLVM 14
Jan 17, 2022
e4607ff
update test assertion
Jan 17, 2022
43b9268
Rustdoc style cleanups
jsha Jan 12, 2022
b71f1fb
Hide mobile sidebar on some clicks
jsha Jan 12, 2022
7b5b3cf
Abstract the pretty printer's ringbuffer to be infinitely sized
dtolnay Jan 15, 2022
e012b9a
Stabilize vec_spare_capacity
Amanieu Jan 17, 2022
ae99e23
Add staged_api for tests
jsha Jan 15, 2022
d501ead
Rollup merge of #92629 - jsha:theme-picker-local-only-2, r=GuillaumeG…
matthiaskrgr Jan 18, 2022
cb5ecff
Rollup merge of #92640 - compiler-errors:array-deref-on-newtype, r=lcnr
matthiaskrgr Jan 18, 2022
804072f
Rollup merge of #92701 - ehuss:even-more-attr-validation, r=matthewja…
matthiaskrgr Jan 18, 2022
cc2339c
Rollup merge of #92803 - jsha:hide-sidebar, r=GuillaumeGomez
matthiaskrgr Jan 18, 2022
deee6f7
Rollup merge of #92830 - jsha:style-cleanups, r=GuillaumeGomez
matthiaskrgr Jan 18, 2022
ae8f39e
Rollup merge of #92866 - maxwase:does_exist_typo, r=Mark-Simulacrum
matthiaskrgr Jan 18, 2022
6a5663e
Rollup merge of #92870 - llogiq:atomic_bool_sym, r=Manishearth
matthiaskrgr Jan 18, 2022
be3d25b
Rollup merge of #92914 - camelid:snapshot-text, r=GuillaumeGomez
matthiaskrgr Jan 18, 2022
04b2073
Rollup merge of #92923 - dtolnay:ringbuffer, r=petrochenkov
matthiaskrgr Jan 18, 2022
b05be97
Rollup merge of #92946 - kaniini:chore/llvm-libunwind-s390x, r=Mark-S…
matthiaskrgr Jan 18, 2022
71e5bfe
Rollup merge of #92947 - vacuus:rustdoc-core-visit-path, r=camelid
matthiaskrgr Jan 18, 2022
baeff67
Rollup merge of #92997 - woppopo:test92114, r=Mark-Simulacrum
matthiaskrgr Jan 18, 2022
b8c544d
Rollup merge of #93004 - krasimirgg:threadlocal-llvm-up, r=nikic
matthiaskrgr Jan 18, 2022
83b1a94
Rollup merge of #93016 - Amanieu:vec_spare_capacity, r=Mark-Simulacrum
matthiaskrgr Jan 18, 2022
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
36 changes: 14 additions & 22 deletions compiler/rustc_ast_pretty/src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
//! methods called `Printer::scan_*`, and the 'PRINT' process is the
//! method called `Printer::print`.

mod ring;

use ring::RingBuffer;
use std::borrow::Cow;
use std::collections::VecDeque;
use std::fmt;
Expand Down Expand Up @@ -190,8 +193,7 @@ impl fmt::Display for Token {
}
}

fn buf_str(buf: &[BufEntry], left: usize, right: usize, lim: usize) -> String {
let n = buf.len();
fn buf_str(buf: &RingBuffer<BufEntry>, left: usize, right: usize, lim: usize) -> String {
let mut i = left;
let mut l = lim;
let mut s = String::from("[");
Expand All @@ -202,7 +204,6 @@ fn buf_str(buf: &[BufEntry], left: usize, right: usize, lim: usize) -> String {
}
s.push_str(&format!("{}={}", buf[i].size, &buf[i].token));
i += 1;
i %= n;
}
s.push(']');
s
Expand All @@ -224,7 +225,6 @@ const SIZE_INFINITY: isize = 0xffff;

pub struct Printer {
out: String,
buf_max_len: usize,
/// Width of lines we're constrained to
margin: isize,
/// Number of spaces left on line
Expand All @@ -234,7 +234,7 @@ pub struct Printer {
/// Index of right side of input stream
right: usize,
/// Ring-buffer of tokens and calculated sizes
buf: Vec<BufEntry>,
buf: RingBuffer<BufEntry>,
/// Running size of stream "...left"
left_total: isize,
/// Running size of stream "...right"
Expand Down Expand Up @@ -267,19 +267,16 @@ impl Default for BufEntry {
impl Printer {
pub fn new() -> Self {
let linewidth = 78;
// Yes 55, it makes the ring buffers big enough to never fall behind.
let n: usize = 55 * linewidth;
debug!("Printer::new {}", linewidth);
let mut buf = RingBuffer::new();
buf.advance_right();
Printer {
out: String::new(),
buf_max_len: n,
margin: linewidth as isize,
space: linewidth as isize,
left: 0,
right: 0,
// Initialize a single entry; advance_right() will extend it on demand
// up to `buf_max_len` elements.
buf: vec![BufEntry::default()],
buf,
left_total: 0,
right_total: 0,
scan_stack: VecDeque::new(),
Expand Down Expand Up @@ -308,8 +305,8 @@ impl Printer {
if self.scan_stack.is_empty() {
self.left_total = 1;
self.right_total = 1;
self.left = 0;
self.right = 0;
self.right = self.left;
self.buf.truncate(1);
} else {
self.advance_right();
}
Expand All @@ -332,8 +329,8 @@ impl Printer {
if self.scan_stack.is_empty() {
self.left_total = 1;
self.right_total = 1;
self.left = 0;
self.right = 0;
self.right = self.left;
self.buf.truncate(1);
} else {
self.advance_right();
}
Expand Down Expand Up @@ -400,12 +397,7 @@ impl Printer {

fn advance_right(&mut self) {
self.right += 1;
self.right %= self.buf_max_len;
// Extend the buf if necessary.
if self.right == self.buf.len() {
self.buf.push(BufEntry::default());
}
assert_ne!(self.right, self.left);
self.buf.advance_right();
}

fn advance_left(&mut self) {
Expand Down Expand Up @@ -437,8 +429,8 @@ impl Printer {
break;
}

self.buf.advance_left();
self.left += 1;
self.left %= self.buf_max_len;

left_size = self.buf[self.left].size;
}
Expand Down
53 changes: 53 additions & 0 deletions compiler/rustc_ast_pretty/src/pp/ring.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::collections::VecDeque;
use std::ops::{Index, IndexMut};

/// A view onto a finite range of an infinitely long sequence of T.
///
/// The Ts are indexed 0..infinity. A RingBuffer begins as a view of elements
/// 0..0 (i.e. nothing). The user of the RingBuffer advances its left and right
/// position independently, although only in the positive direction, and only
/// with left <= right at all times.
///
/// Holding a RingBuffer whose view is elements left..right gives the ability to
/// use Index and IndexMut to access elements i in the infinitely long queue for
/// which left <= i < right.
pub struct RingBuffer<T> {
data: VecDeque<T>,
// Abstract index of data[0] in the infinitely sized queue.
offset: usize,
}

impl<T> RingBuffer<T> {
pub fn new() -> Self {
RingBuffer { data: VecDeque::new(), offset: 0 }
}

pub fn advance_right(&mut self)
where
T: Default,
{
self.data.push_back(T::default());
}

pub fn advance_left(&mut self) {
self.data.pop_front().unwrap();
self.offset += 1;
}

pub fn truncate(&mut self, len: usize) {
self.data.truncate(len);
}
}

impl<T> Index<usize> for RingBuffer<T> {
type Output = T;
fn index(&self, index: usize) -> &Self::Output {
&self.data[index.checked_sub(self.offset).unwrap()]
}
}

impl<T> IndexMut<usize> for RingBuffer<T> {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
&mut self.data[index.checked_sub(self.offset).unwrap()]
}
}
4 changes: 2 additions & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,15 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[

// Runtime
ungated!(
windows_subsystem, Normal,
windows_subsystem, CrateLevel,
template!(NameValueStr: "windows|console"), FutureWarnFollowing
),
ungated!(panic_handler, Normal, template!(Word), WarnFollowing), // RFC 2070

// Code generation:
ungated!(inline, Normal, template!(Word, List: "always|never"), FutureWarnFollowing),
ungated!(cold, Normal, template!(Word), WarnFollowing),
ungated!(no_builtins, Normal, template!(Word), WarnFollowing),
ungated!(no_builtins, CrateLevel, template!(Word), WarnFollowing),
ungated!(target_feature, Normal, template!(List: r#"enable = "name""#), DuplicatesOk),
ungated!(track_caller, Normal, template!(Word), WarnFollowing),
gated!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
// FIXME: perf problem described in #55921.
ui = ty::UniverseIndex::ROOT;
return self.canonicalize_const_var(
CanonicalVarInfo { kind: CanonicalVarKind::Const(ui) },
CanonicalVarInfo { kind: CanonicalVarKind::Const(ui, ct.ty) },
ct,
);
}
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_infer/src/infer/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
self.tcx.mk_region(ty::RePlaceholder(placeholder_mapped)).into()
}

CanonicalVarKind::Const(ui) => self
CanonicalVarKind::Const(ui, ty) => self
.next_const_var_in_universe(
self.next_ty_var_in_universe(
TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span },
universe_map(ui),
),
ty,
ConstVariableOrigin { kind: ConstVariableOriginKind::MiscVariable, span },
universe_map(ui),
)
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/infer/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

use crate::infer::MemberConstraint;
use crate::ty::subst::GenericArg;
use crate::ty::{self, BoundVar, List, Region, TyCtxt};
use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt};
use rustc_index::vec::IndexVec;
use rustc_macros::HashStable;
use smallvec::SmallVec;
Expand Down Expand Up @@ -104,7 +104,7 @@ impl<'tcx> CanonicalVarInfo<'tcx> {
CanonicalVarKind::PlaceholderTy(_) => false,
CanonicalVarKind::Region(_) => true,
CanonicalVarKind::PlaceholderRegion(..) => false,
CanonicalVarKind::Const(_) => true,
CanonicalVarKind::Const(..) => true,
CanonicalVarKind::PlaceholderConst(_) => false,
}
}
Expand All @@ -130,7 +130,7 @@ pub enum CanonicalVarKind<'tcx> {
PlaceholderRegion(ty::PlaceholderRegion),

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

/// A "placeholder" that represents "any const".
PlaceholderConst(ty::PlaceholderConst<'tcx>),
Expand All @@ -147,7 +147,7 @@ impl<'tcx> CanonicalVarKind<'tcx> {
CanonicalVarKind::PlaceholderTy(placeholder) => placeholder.universe,
CanonicalVarKind::Region(ui) => ui,
CanonicalVarKind::PlaceholderRegion(placeholder) => placeholder.universe,
CanonicalVarKind::Const(ui) => ui,
CanonicalVarKind::Const(ui, _) => ui,
CanonicalVarKind::PlaceholderConst(placeholder) => placeholder.universe,
}
}
Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl CheckAttrVisitor<'_> {
// lint-only checks
match attr.name_or_empty() {
sym::cold => self.check_cold(hir_id, attr, span, target),
sym::link => self.check_link(hir_id, attr, span, target),
sym::link_name => self.check_link_name(hir_id, attr, span, target),
sym::link_section => self.check_link_section(hir_id, attr, span, target),
sym::no_mangle => self.check_no_mangle(hir_id, attr, span, target),
Expand Down Expand Up @@ -1157,6 +1158,26 @@ impl CheckAttrVisitor<'_> {
}
}

/// Checks if `#[link]` is applied to an item other than a foreign module.
fn check_link(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
match target {
Target::ForeignMod => {}
_ => {
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
let mut diag = lint.build("attribute should be applied to an `extern` block");
diag.warn(
"this was previously accepted by the compiler but is \
being phased out; it will become a hard error in \
a future release!",
);

diag.span_label(*span, "not an `extern` block");
diag.emit();
});
}
}
}

/// Checks if `#[link_name]` is applied to an item other than a foreign function or static.
fn check_link_name(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
match target {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_traits/src/chalk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ crate fn evaluate_goal<'tcx>(
chalk_ir::VariableKind::Lifetime,
chalk_ir::UniverseIndex { counter: ui.index() },
),
CanonicalVarKind::Const(_ui) => unimplemented!(),
CanonicalVarKind::Const(_ui, _ty) => unimplemented!(),
CanonicalVarKind::PlaceholderConst(_pc) => unimplemented!(),
}),
),
Expand Down Expand Up @@ -127,9 +127,9 @@ crate fn evaluate_goal<'tcx>(
chalk_ir::VariableKind::Lifetime => CanonicalVarKind::Region(
ty::UniverseIndex::from_usize(var.skip_kind().counter),
),
chalk_ir::VariableKind::Const(_) => CanonicalVarKind::Const(
ty::UniverseIndex::from_usize(var.skip_kind().counter),
),
// FIXME(compiler-errors): We don't currently have a way of turning
// a Chalk ty back into a rustc ty, right?
chalk_ir::VariableKind::Const(_) => todo!(),
};
CanonicalVarInfo { kind }
})
Expand Down
25 changes: 17 additions & 8 deletions compiler/rustc_typeck/src/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// time writing the results into the various typeck results.
let mut autoderef =
self.autoderef_overloaded_span(self.span, unadjusted_self_ty, self.call_expr.span);
let (_, n) = match autoderef.nth(pick.autoderefs) {
let (ty, n) = match autoderef.nth(pick.autoderefs) {
Some(n) => n,
None => {
return self.tcx.ty_error_with_message(
Expand All @@ -161,14 +161,15 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
assert_eq!(n, pick.autoderefs);

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

let mut target =
self.structurally_resolved_type(autoderef.span(), autoderef.final_ty(false));

match &pick.autoref_or_ptr_adjustment {
match pick.autoref_or_ptr_adjustment {
Some(probe::AutorefOrPtrAdjustment::Autoref { mutbl, unsize }) => {
let region = self.next_region_var(infer::Autoref(self.span));
target = self.tcx.mk_ref(region, ty::TypeAndMut { mutbl: *mutbl, ty: target });
// Type we're wrapping in a reference, used later for unsizing
let base_ty = target;

target = self.tcx.mk_ref(region, ty::TypeAndMut { mutbl, ty: target });
let mutbl = match mutbl {
hir::Mutability::Not => AutoBorrowMutability::Not,
hir::Mutability::Mut => AutoBorrowMutability::Mut {
Expand All @@ -182,10 +183,18 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
target,
});

if let Some(unsize_target) = unsize {
if unsize {
let unsized_ty = if let ty::Array(elem_ty, _) = base_ty.kind() {
self.tcx.mk_slice(elem_ty)
} else {
bug!(
"AutorefOrPtrAdjustment's unsize flag should only be set for array ty, found {}",
base_ty
)
};
target = self
.tcx
.mk_ref(region, ty::TypeAndMut { mutbl: mutbl.into(), ty: unsize_target });
.mk_ref(region, ty::TypeAndMut { mutbl: mutbl.into(), ty: unsized_ty });
adjustments
.push(Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target });
}
Expand Down
Loading