Skip to content

Rollup of 6 pull requests #107642

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

Merged
merged 19 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5fd4f5b
Add candidates for DiscriminantKind builtin
detrumi Jan 27, 2023
de50a86
Simplify discriminant_kind goal using new helper function
detrumi Feb 1, 2023
64f5293
Don't cause a cycle when formatting query description that references…
compiler-errors Feb 2, 2023
c3a71ed
Emit warnings on unused parens/braces in index expressions
PossiblyAShrub Jan 31, 2023
745d60c
Tweak misleading comment
compiler-errors Feb 2, 2023
af1d16e
Improve doc comment desugaring.
nnethercote Jan 31, 2023
b23f272
Make clear that `TokenTree::Token` shouldn't contain a delimiter.
nnethercote Feb 1, 2023
b5ecbbb
Remove `TokenCursorFrame`.
nnethercote Feb 1, 2023
a86fc72
Rename `Cursor`/`CursorRef` as `TokenTreeCursor`/`RefTokenTreeCursor`.
nnethercote Feb 1, 2023
f29000e
Use new helper inside probe
detrumi Feb 3, 2023
f874f67
Fix suggestion for coercing Option<&String> to Option<&str>
clubby789 Feb 3, 2023
9e1c600
Disallow impl autotrait for trait object
dtolnay Jan 19, 2023
4501d3a
Autotrait bounds on dyn-safe trait methods
dtolnay Jan 19, 2023
7221383
Rollup merge of #107082 - dtolnay:autotraits, r=lcnr
Dylan-DPC Feb 3, 2023
e1bf3a1
Rollup merge of #107427 - detrumi:builtin-impl-candidates, r=compiler…
Dylan-DPC Feb 3, 2023
d9db357
Rollup merge of #107539 - PossiblyAShrub:unused-parens-in-index, r=lcnr
Dylan-DPC Feb 3, 2023
815dc9c
Rollup merge of #107544 - nnethercote:improve-TokenCursor, r=petroche…
Dylan-DPC Feb 3, 2023
d6f0c51
Rollup merge of #107585 - compiler-errors:fndef-sig-cycle, r=oli-obk
Dylan-DPC Feb 3, 2023
c927027
Rollup merge of #107633 - clubby789:option-string-coerce-fix, r=Nilst…
Dylan-DPC Feb 3, 2023
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
42 changes: 27 additions & 15 deletions compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ use std::{fmt, iter};
/// 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. Should never be `OpenDelim` or `CloseDelim`, because
/// delimiters are implicitly represented by `Delimited`.
Token(Token, Spacing),
/// A delimited sequence of token trees.
Delimited(DelimSpan, Delimiter, TokenStream),
Expand Down Expand Up @@ -388,12 +389,12 @@ impl TokenStream {
self.0.len()
}

pub fn trees(&self) -> CursorRef<'_> {
CursorRef::new(self)
pub fn trees(&self) -> RefTokenTreeCursor<'_> {
RefTokenTreeCursor::new(self)
}

pub fn into_trees(self) -> Cursor {
Cursor::new(self)
pub fn into_trees(self) -> TokenTreeCursor {
TokenTreeCursor::new(self)
}

/// Compares two `TokenStream`s, checking equality without regarding span information.
Expand Down Expand Up @@ -551,24 +552,25 @@ impl TokenStream {
}
}

/// By-reference iterator over a [`TokenStream`].
/// By-reference iterator over a [`TokenStream`], that produces `&TokenTree`
/// items.
#[derive(Clone)]
pub struct CursorRef<'t> {
pub struct RefTokenTreeCursor<'t> {
stream: &'t TokenStream,
index: usize,
}

impl<'t> CursorRef<'t> {
impl<'t> RefTokenTreeCursor<'t> {
fn new(stream: &'t TokenStream) -> Self {
CursorRef { stream, index: 0 }
RefTokenTreeCursor { stream, index: 0 }
}

pub fn look_ahead(&self, n: usize) -> Option<&TokenTree> {
self.stream.0.get(self.index + n)
}
}

impl<'t> Iterator for CursorRef<'t> {
impl<'t> Iterator for RefTokenTreeCursor<'t> {
type Item = &'t TokenTree;

fn next(&mut self) -> Option<&'t TokenTree> {
Expand All @@ -579,15 +581,16 @@ impl<'t> Iterator for CursorRef<'t> {
}
}

/// Owning by-value iterator over a [`TokenStream`].
/// Owning by-value iterator over a [`TokenStream`], that produces `TokenTree`
/// items.
// FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones.
#[derive(Clone)]
pub struct Cursor {
pub struct TokenTreeCursor {
pub stream: TokenStream,
index: usize,
}

impl Iterator for Cursor {
impl Iterator for TokenTreeCursor {
type Item = TokenTree;

fn next(&mut self) -> Option<TokenTree> {
Expand All @@ -598,9 +601,9 @@ impl Iterator for Cursor {
}
}

impl Cursor {
impl TokenTreeCursor {
fn new(stream: TokenStream) -> Self {
Cursor { stream, index: 0 }
TokenTreeCursor { stream, index: 0 }
}

#[inline]
Expand All @@ -614,6 +617,15 @@ impl Cursor {
pub fn look_ahead(&self, n: usize) -> Option<&TokenTree> {
self.stream.0.get(self.index + n)
}

// Replace the previously obtained token tree with `tts`, and rewind to
// just before them.
pub fn replace_prev_and_rewind(&mut self, tts: Vec<TokenTree>) {
assert!(self.index > 0);
self.index -= 1;
let stream = Lrc::make_mut(&mut self.stream.0);
stream.splice(self.index..self.index + 1, tts);
}
}

#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ cfg_if! {
pub auto trait Send {}
pub auto trait Sync {}

impl<T: ?Sized> Send for T {}
impl<T: ?Sized> Sync for T {}
impl<T> Send for T {}
impl<T> Sync for T {}

#[macro_export]
macro_rules! rustc_erase_owner {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/hir_typeck.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ hir_typeck_lang_start_incorrect_ret_ty = the return type of the `start` lang ite
hir_typeck_help_set_edition_cargo = set `edition = "{$edition}"` in `Cargo.toml`
hir_typeck_help_set_edition_standalone = pass `--edition {$edition}` to `rustc`
hir_typeck_note_edition_guide = for more on editions, read https://doc.rust-lang.org/edition-guide

hir_typeck_convert_to_str = try converting the passed type into a `&str`
12 changes: 6 additions & 6 deletions compiler/rustc_expand/src/mbe/metavar_expr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_ast::token::{self, Delimiter};
use rustc_ast::tokenstream::{CursorRef, TokenStream, TokenTree};
use rustc_ast::tokenstream::{RefTokenTreeCursor, TokenStream, TokenTree};
use rustc_ast::{LitIntType, LitKind};
use rustc_ast_pretty::pprust;
use rustc_errors::{Applicability, PResult};
Expand Down Expand Up @@ -72,7 +72,7 @@ impl MetaVarExpr {

// Checks if there are any remaining tokens. For example, `${ignore(ident ... a b c ...)}`
fn check_trailing_token<'sess>(
iter: &mut CursorRef<'_>,
iter: &mut RefTokenTreeCursor<'_>,
sess: &'sess ParseSess,
) -> PResult<'sess, ()> {
if let Some(tt) = iter.next() {
Expand All @@ -88,7 +88,7 @@ fn check_trailing_token<'sess>(

/// Parse a meta-variable `count` expression: `count(ident[, depth])`
fn parse_count<'sess>(
iter: &mut CursorRef<'_>,
iter: &mut RefTokenTreeCursor<'_>,
sess: &'sess ParseSess,
span: Span,
) -> PResult<'sess, MetaVarExpr> {
Expand All @@ -99,7 +99,7 @@ fn parse_count<'sess>(

/// Parses the depth used by index(depth) and length(depth).
fn parse_depth<'sess>(
iter: &mut CursorRef<'_>,
iter: &mut RefTokenTreeCursor<'_>,
sess: &'sess ParseSess,
span: Span,
) -> PResult<'sess, usize> {
Expand All @@ -126,7 +126,7 @@ fn parse_depth<'sess>(

/// Parses an generic ident
fn parse_ident<'sess>(
iter: &mut CursorRef<'_>,
iter: &mut RefTokenTreeCursor<'_>,
sess: &'sess ParseSess,
span: Span,
) -> PResult<'sess, Ident> {
Expand All @@ -152,7 +152,7 @@ fn parse_ident<'sess>(

/// Tries to move the iterator forward returning `true` if there is a comma. If not, then the
/// iterator is not modified and the result is `false`.
fn try_eat_comma(iter: &mut CursorRef<'_>) -> bool {
fn try_eat_comma(iter: &mut RefTokenTreeCursor<'_>) -> bool {
if let Some(TokenTree::Token(token::Token { kind: token::Comma, .. }, _)) = iter.look_ahead(0) {
let _ = iter.next();
return true;
Expand Down
Loading