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 11 pull requests #80781

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
274e299
Stablize slice::strip_prefix and strip_suffix, with SlicePattern
ijackson Oct 12, 2020
f51b681
Use existing slice_pattern feature for SlicePattern
ijackson Dec 12, 2020
beb293d
Drop pointless as_slice call.
ijackson Dec 27, 2020
03b4ea4
Mark SlicePattern trait uses as ?Sized
ijackson Dec 27, 2020
8b2e79d
Add test for slice as prefix/suffix pattern
ijackson Dec 27, 2020
9a240e4
Edit rustc_ast::tokenstream docs
pierwill Jan 3, 2021
b4a0ef0
fix issue 80559
max-heller Jan 3, 2021
e33a205
primitive disambiguator tests
max-heller Jan 4, 2021
fc3a405
still verify disambiguators for primitives
max-heller Jan 4, 2021
06b0900
half working
max-heller Jan 4, 2021
6f04133
fix incompatible disambiguator test
max-heller Jan 4, 2021
2bdbb0d
Document hackiness around primitive associated item disambiguators
max-heller Jan 5, 2021
aea9a4b
Remove bottom margin from crate version when the sidebar is collapsed.
arusahni Jan 5, 2021
e636805
rustdoc: Turn `next_def_id` comments into docs
camelid Jan 6, 2021
1a2ee0b
Update cargo
ehuss Jan 6, 2021
7428e2d
Apply suggestions from code review
camelid Jan 6, 2021
7bc22e9
Don't use to_string on Symbol
GuillaumeGomez Jan 6, 2021
fa4d8bc
Prefer enum Endian in rustc_target::Target
tesuji Jan 5, 2021
8ee804d
Change related spec files to use the new enum
tesuji Jan 5, 2021
3f74fbd
handle generic trait methods in coverage tests
andjo403 Jan 6, 2021
f03907b
Add pointing const identifier when emitting E0435
sasurau4 Dec 13, 2020
c9e7045
bless tests
sasurau4 Dec 13, 2020
c71348a
Refine E0435 description
sasurau4 Dec 26, 2020
f942c3c
Return EOF_CHAR constant instead of magic char.
Jan 7, 2021
bc751f2
Rollup merge of #77853 - ijackson:slice-strip-stab, r=Amanieu
Dylan-DPC Jan 7, 2021
72dfeff
Rollup merge of #80012 - sasurau4:feature/point-constant-identifier-E…
Dylan-DPC Jan 7, 2021
7a1c817
Rollup merge of #80659 - pierwill:edit-tokenstream, r=davidtwco
Dylan-DPC Jan 7, 2021
208710a
Rollup merge of #80660 - max-heller:issue-80559-fix, r=jyn514
Dylan-DPC Jan 7, 2021
69daa35
Rollup merge of #80709 - lzutao:target-enumerate, r=petrochenkov
Dylan-DPC Jan 7, 2021
9342728
Rollup merge of #80738 - arusahni:master, r=GuillaumeGomez
Dylan-DPC Jan 7, 2021
55c007a
Rollup merge of #80744 - camelid:next_def_id-docs, r=jyn514
Dylan-DPC Jan 7, 2021
cc1238f
Rollup merge of #80746 - ehuss:update-cargo, r=ehuss
Dylan-DPC Jan 7, 2021
9558447
Rollup merge of #80750 - GuillaumeGomez:cleanup-to_string, r=lzutao
Dylan-DPC Jan 7, 2021
38ccca7
Rollup merge of #80761 - andjo403:generic_coverage, r=wesleywiser
Dylan-DPC Jan 7, 2021
e4ecfea
Rollup merge of #80780 - lianghanzhen:master, r=petrochenkov
Dylan-DPC Jan 7, 2021
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
2 changes: 1 addition & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ checksum = "81a18687293a1546b67c246452202bbbf143d239cb43494cc163da14979082da"

[[package]]
name = "cargo"
version = "0.51.0"
version = "0.52.0"
dependencies = [
"anyhow",
"atty",
Expand Down
33 changes: 17 additions & 16 deletions compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! # Token Streams
//!
//! `TokenStream`s represent syntactic objects before they are converted into ASTs.
//! A `TokenStream` is, roughly speaking, a sequence (eg stream) of `TokenTree`s,
//! which are themselves a single `Token` or a `Delimited` subsequence of tokens.
//! A `TokenStream` is, roughly speaking, a sequence of [`TokenTree`]s,
//! which are themselves a single [`Token`] or a `Delimited` subsequence of tokens.
//!
//! ## Ownership
//!
//! `TokenStream`s are persistent data structures constructed as ropes with reference
//! counted-children. In general, this means that calling an operation on a `TokenStream`
//! (such as `slice`) produces an entirely new `TokenStream` from the borrowed reference to
//! the original. This essentially coerces `TokenStream`s into 'views' of their subparts,
//! the original. This essentially coerces `TokenStream`s into "views" of their subparts,
//! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking
//! ownership of the original.

Expand All @@ -24,9 +24,9 @@ use smallvec::{smallvec, SmallVec};

use std::{fmt, iter, mem};

/// When the main rust parser encounters a syntax-extension invocation, it
/// parses the arguments to the invocation as a token-tree. This is a very
/// loose structure, such that all sorts of different AST-fragments can
/// When the main Rust parser encounters a syntax-extension invocation, it
/// parses the arguments to the invocation as a token tree. This is a very
/// loose structure, such that all sorts of different AST fragments can
/// be passed to syntax extensions using a uniform type.
///
/// If the syntax extension is an MBE macro, it will attempt to match its
Expand All @@ -38,9 +38,9 @@ use std::{fmt, iter, mem};
/// Nothing special happens to misnamed or misplaced `SubstNt`s.
#[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
pub enum TokenTree {
/// A single token
/// A single token.
Token(Token),
/// A delimited sequence of token trees
/// A delimited sequence of token trees.
Delimited(DelimSpan, DelimToken, TokenStream),
}

Expand All @@ -62,7 +62,7 @@ where
}

impl TokenTree {
/// Checks if this TokenTree is equal to the other, regardless of span information.
/// Checks if this `TokenTree` is equal to the other, regardless of span information.
pub fn eq_unspanned(&self, other: &TokenTree) -> bool {
match (self, other) {
(TokenTree::Token(token), TokenTree::Token(token2)) => token.kind == token2.kind,
Expand All @@ -73,7 +73,7 @@ impl TokenTree {
}
}

/// Retrieves the TokenTree's span.
/// Retrieves the `TokenTree`'s span.
pub fn span(&self) -> Span {
match self {
TokenTree::Token(token) => token.span,
Expand Down Expand Up @@ -140,7 +140,7 @@ impl CreateTokenStream for TokenStream {
}
}

/// A lazy version of `TokenStream`, which defers creation
/// A lazy version of [`TokenStream`], which defers creation
/// of an actual `TokenStream` until it is needed.
/// `Box` is here only to reduce the structure size.
#[derive(Clone)]
Expand Down Expand Up @@ -188,11 +188,12 @@ impl<CTX> HashStable<CTX> for LazyTokenStream {
}
}

/// A `TokenStream` is an abstract sequence of tokens, organized into `TokenTree`s.
/// A `TokenStream` is an abstract sequence of tokens, organized into [`TokenTree`]s.
///
/// The goal is for procedural macros to work with `TokenStream`s and `TokenTree`s
/// instead of a representation of the abstract syntax tree.
/// Today's `TokenTree`s can still contain AST via `token::Interpolated` for back-compat.
/// Today's `TokenTree`s can still contain AST via `token::Interpolated` for
/// backwards compatability.
#[derive(Clone, Debug, Default, Encodable, Decodable)]
pub struct TokenStream(pub(crate) Lrc<Vec<TreeAndSpacing>>);

Expand Down Expand Up @@ -429,7 +430,7 @@ impl TokenStreamBuilder {
}
}

/// By-reference iterator over a `TokenStream`.
/// By-reference iterator over a [`TokenStream`].
#[derive(Clone)]
pub struct CursorRef<'t> {
stream: &'t TokenStream,
Expand Down Expand Up @@ -457,8 +458,8 @@ impl<'t> Iterator for CursorRef<'t> {
}
}

/// Owning by-value iterator over a `TokenStream`.
/// FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones.
/// Owning by-value iterator over a [`TokenStream`].
// FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones.
#[derive(Clone)]
pub struct Cursor {
pub stream: TokenStream,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/va_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_codegen_ssa::{
};
use rustc_middle::ty::layout::HasTyCtxt;
use rustc_middle::ty::Ty;
use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size};
use rustc_target::abi::{Align, Endian, HasDataLayout, LayoutOf, Size};

fn round_pointer_up_to_alignment(
bx: &mut Builder<'a, 'll, 'tcx>,
Expand Down Expand Up @@ -52,7 +52,7 @@ fn emit_direct_ptr_va_arg(
let next = bx.inbounds_gep(addr, &[full_direct_size]);
bx.store(next, va_list_addr, bx.tcx().data_layout.pointer_align.abi);

if size.bytes() < slot_size.bytes() && &*bx.tcx().sess.target.endian == "big" {
if size.bytes() < slot_size.bytes() && bx.tcx().sess.target.endian == Endian::Big {
let adjusted_size = bx.cx().const_i32((slot_size.bytes() - size.bytes()) as i32);
let adjusted = bx.inbounds_gep(addr, &[adjusted_size]);
(bx.bitcast(adjusted, bx.cx().type_ptr_to(llty)), addr_align)
Expand Down Expand Up @@ -105,7 +105,7 @@ fn emit_aapcs_va_arg(
let mut end = bx.build_sibling_block("va_arg.end");
let zero = bx.const_i32(0);
let offset_align = Align::from_bytes(4).unwrap();
assert!(&*bx.tcx().sess.target.endian == "little");
assert_eq!(bx.tcx().sess.target.endian, Endian::Little);

let gr_type = target_ty.is_any_ptr() || target_ty.is_integral();
let (reg_off, reg_top_index, slot_size) = if gr_type {
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0435.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ let foo = 42;
let a: [u8; foo]; // error: attempt to use a non-constant value in a constant
```

'constant' means 'a compile-time value'.

More details can be found in the [Variables and Mutability] section of the book.

[Variables and Mutability]: https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#differences-between-variables-and-constants

To fix this error, please replace the value with a constant. Example:

```
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lexer/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<'a> Cursor<'a> {

#[cfg(not(debug_assertions))]
{
'\0'
EOF_CHAR
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl CheckAttrVisitor<'tcx> {
return false;
}
let item_name = self.tcx.hir().name(hir_id);
if item_name.to_string() == doc_alias {
if &*item_name.as_str() == doc_alias {
self.tcx
.sess
.struct_span_err(
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,19 @@ impl<'a> Resolver<'a> {
err.help("use the `|| { ... }` closure form instead");
err
}
ResolutionError::AttemptToUseNonConstantValueInConstant => {
ResolutionError::AttemptToUseNonConstantValueInConstant(ident, sugg) => {
let mut err = struct_span_err!(
self.session,
span,
E0435,
"attempt to use a non-constant value in a constant"
);
err.span_suggestion(
ident.span,
&sugg,
"".to_string(),
Applicability::MaybeIncorrect,
);
err.span_label(span, "non-constant value");
err
}
Expand Down
38 changes: 28 additions & 10 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ crate enum HasGenericParams {
No,
}

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
crate enum ConstantItemKind {
Const,
Static,
}

/// The rib kind restricts certain accesses,
/// e.g. to a `Res::Local` of an outer item.
#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -119,7 +125,7 @@ crate enum RibKind<'a> {
///
/// The `bool` indicates if this constant may reference generic parameters
/// and is used to only allow generic parameters to be used in trivial constant expressions.
ConstantItemRibKind(bool),
ConstantItemRibKind(bool, Option<(Ident, ConstantItemKind)>),

/// We passed through a module.
ModuleRibKind(Module<'a>),
Expand All @@ -145,7 +151,7 @@ impl RibKind<'_> {
NormalRibKind
| ClosureOrAsyncRibKind
| FnItemRibKind
| ConstantItemRibKind(_)
| ConstantItemRibKind(..)
| ModuleRibKind(_)
| MacroDefinition(_)
| ConstParamTyRibKind => false,
Expand Down Expand Up @@ -634,7 +640,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
// Note that we might not be inside of an repeat expression here,
// but considering that `IsRepeatExpr` is only relevant for
// non-trivial constants this is doesn't matter.
self.with_constant_rib(IsRepeatExpr::No, true, |this| {
self.with_constant_rib(IsRepeatExpr::No, true, None, |this| {
this.smart_resolve_path(
ty.id,
qself.as_ref(),
Expand Down Expand Up @@ -843,7 +849,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
| ClosureOrAsyncRibKind
| FnItemRibKind
| ItemRibKind(..)
| ConstantItemRibKind(_)
| ConstantItemRibKind(..)
| ModuleRibKind(..)
| ForwardTyParamBanRibKind
| ConstParamTyRibKind => {
Expand Down Expand Up @@ -970,6 +976,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
this.with_constant_rib(
IsRepeatExpr::No,
true,
None,
|this| this.visit_expr(expr),
);
}
Expand Down Expand Up @@ -1012,11 +1019,19 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
self.with_item_rib(HasGenericParams::No, |this| {
this.visit_ty(ty);
if let Some(expr) = expr {
let constant_item_kind = match item.kind {
ItemKind::Const(..) => ConstantItemKind::Const,
ItemKind::Static(..) => ConstantItemKind::Static,
_ => unreachable!(),
};
// We already forbid generic params because of the above item rib,
// so it doesn't matter whether this is a trivial constant.
this.with_constant_rib(IsRepeatExpr::No, true, |this| {
this.visit_expr(expr)
});
this.with_constant_rib(
IsRepeatExpr::No,
true,
Some((item.ident, constant_item_kind)),
|this| this.visit_expr(expr),
);
}
});
}
Expand Down Expand Up @@ -1118,15 +1133,16 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
&mut self,
is_repeat: IsRepeatExpr,
is_trivial: bool,
item: Option<(Ident, ConstantItemKind)>,
f: impl FnOnce(&mut Self),
) {
debug!("with_constant_rib: is_repeat={:?} is_trivial={}", is_repeat, is_trivial);
self.with_rib(ValueNS, ConstantItemRibKind(is_trivial), |this| {
self.with_rib(ValueNS, ConstantItemRibKind(is_trivial, item), |this| {
this.with_rib(
TypeNS,
ConstantItemRibKind(is_repeat == IsRepeatExpr::Yes || is_trivial),
ConstantItemRibKind(is_repeat == IsRepeatExpr::Yes || is_trivial, item),
|this| {
this.with_label_rib(ConstantItemRibKind(is_trivial), f);
this.with_label_rib(ConstantItemRibKind(is_trivial, item), f);
},
)
});
Expand Down Expand Up @@ -1266,6 +1282,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
this.with_constant_rib(
IsRepeatExpr::No,
true,
None,
|this| {
visit::walk_assoc_item(
this,
Expand Down Expand Up @@ -2200,6 +2217,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
self.with_constant_rib(
is_repeat,
constant.value.is_potential_trivial_const_param(),
None,
|this| {
visit::walk_anon_const(this, constant);
},
Expand Down
Loading