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 6 pull requests #96511

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
eb55cdc
use `ParseSess` instead of `Session` in `into_diagnostic`
pvdrz Apr 25, 2022
519dd8e
migrate ambiguous plus diagnostic
pvdrz Apr 25, 2022
d6da5fb
update lockfile
pvdrz Apr 25, 2022
5874b09
fix formatting
pvdrz Apr 25, 2022
530f4dc
remove old code
pvdrz Apr 25, 2022
2e261a8
add `struct_warn` method
pvdrz Apr 25, 2022
35b42cb
avoid `format!`
pvdrz Apr 26, 2022
6c3e793
move `AmbigousPlus` outside
pvdrz Apr 26, 2022
1e35bab
separate messages by a newline
pvdrz Apr 26, 2022
2a6a370
Add more diagnostic items
Serial-ATA Apr 26, 2022
a1e0cfa
Update ui test
Serial-ATA Apr 27, 2022
e7ae9eb
rename `sum_with_parens`
pvdrz Apr 27, 2022
332f326
Fixed grammatical error in example comment
user-simon Apr 27, 2022
2c94218
Recover suggestions to introduce named lifetime under NLL
marmeladema Apr 25, 2022
d9240d7
Ensure that `'_` and GAT yields errors
marmeladema Mar 25, 2022
2733ec1
rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`
petrochenkov Apr 26, 2022
9e97ba2
Rollup merge of #95312 - marmeladema:tests-for-issue-95305, r=jackh726
Dylan-DPC Apr 28, 2022
b9db253
Rollup merge of #96302 - Serial-ATA:more-diagnostic-items, r=manishearth
Dylan-DPC Apr 28, 2022
91bdc12
Rollup merge of #96405 - pvdrz:ambiguous-plus-diagnostic, r=davidtwco
Dylan-DPC Apr 28, 2022
c9fb0b4
Rollup merge of #96409 - marmeladema:fix-nll-introduce-named-lifetime…
Dylan-DPC Apr 28, 2022
d6905ce
Rollup merge of #96433 - petrochenkov:delim, r=nnethercote
Dylan-DPC Apr 28, 2022
1779024
Rollup merge of #96480 - user-simon:patch-1, r=Dylan-DPC
Dylan-DPC Apr 28, 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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4158,6 +4158,7 @@ dependencies = [
"rustc_errors",
"rustc_feature",
"rustc_lexer",
"rustc_macros",
"rustc_session",
"rustc_span",
"tracing",
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub use GenericArgs::*;
pub use UnsafeSource::*;

use crate::ptr::P;
use crate::token::{self, CommentKind, DelimToken, Token};
use crate::token::{self, CommentKind, Delimiter, Token};
use crate::tokenstream::{DelimSpan, LazyTokenStream, TokenStream, TokenTree};

use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
Expand Down Expand Up @@ -1542,7 +1542,7 @@ pub enum MacArgs {
}

impl MacArgs {
pub fn delim(&self) -> Option<DelimToken> {
pub fn delim(&self) -> Option<Delimiter> {
match self {
MacArgs::Delimited(_, delim, _) => Some(delim.to_token()),
MacArgs::Empty | MacArgs::Eq(..) => None,
Expand Down Expand Up @@ -1582,20 +1582,20 @@ pub enum MacDelimiter {
}

impl MacDelimiter {
pub fn to_token(self) -> DelimToken {
pub fn to_token(self) -> Delimiter {
match self {
MacDelimiter::Parenthesis => DelimToken::Paren,
MacDelimiter::Bracket => DelimToken::Bracket,
MacDelimiter::Brace => DelimToken::Brace,
MacDelimiter::Parenthesis => Delimiter::Parenthesis,
MacDelimiter::Bracket => Delimiter::Bracket,
MacDelimiter::Brace => Delimiter::Brace,
}
}

pub fn from_token(delim: DelimToken) -> Option<MacDelimiter> {
pub fn from_token(delim: Delimiter) -> Option<MacDelimiter> {
match delim {
token::Paren => Some(MacDelimiter::Parenthesis),
token::Bracket => Some(MacDelimiter::Bracket),
token::Brace => Some(MacDelimiter::Brace),
token::NoDelim => None,
Delimiter::Parenthesis => Some(MacDelimiter::Parenthesis),
Delimiter::Bracket => Some(MacDelimiter::Bracket),
Delimiter::Brace => Some(MacDelimiter::Brace),
Delimiter::Invisible => None,
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::ast::{AttrId, AttrItem, AttrKind, AttrStyle, Attribute};
use crate::ast::{Lit, LitKind};
use crate::ast::{MacArgs, MacDelimiter, MetaItem, MetaItemKind, NestedMetaItem};
use crate::ast::{Path, PathSegment};
use crate::token::{self, CommentKind, Token};
use crate::token::{self, CommentKind, Delimiter, Token};
use crate::tokenstream::{AttrAnnotatedTokenStream, AttrAnnotatedTokenTree};
use crate::tokenstream::{DelimSpan, Spacing, TokenTree, TreeAndSpacing};
use crate::tokenstream::{LazyTokenStream, TokenStream};
Expand Down Expand Up @@ -513,7 +513,7 @@ impl MetaItemKind {
vec![
TokenTree::Delimited(
DelimSpan::from_single(span),
token::Paren,
Delimiter::Parenthesis,
TokenStream::new(tokens),
)
.into(),
Expand All @@ -540,7 +540,7 @@ impl MetaItemKind {
tokens: &mut impl Iterator<Item = TokenTree>,
) -> Option<MetaItemKind> {
match tokens.next() {
Some(TokenTree::Delimited(_, token::NoDelim, inner_tokens)) => {
Some(TokenTree::Delimited(_, Delimiter::Invisible, inner_tokens)) => {
MetaItemKind::name_value_from_tokens(&mut inner_tokens.trees())
}
Some(TokenTree::Token(token)) => {
Expand All @@ -565,7 +565,7 @@ impl MetaItemKind {
tokens: &mut iter::Peekable<impl Iterator<Item = TokenTree>>,
) -> Option<MetaItemKind> {
match tokens.peek() {
Some(TokenTree::Delimited(_, token::Paren, inner_tokens)) => {
Some(TokenTree::Delimited(_, Delimiter::Parenthesis, inner_tokens)) => {
let inner_tokens = inner_tokens.clone();
tokens.next();
MetaItemKind::list_from_tokens(inner_tokens)
Expand Down Expand Up @@ -606,7 +606,7 @@ impl NestedMetaItem {
tokens.next();
return Some(NestedMetaItem::Literal(lit));
}
Some(TokenTree::Delimited(_, token::NoDelim, inner_tokens)) => {
Some(TokenTree::Delimited(_, Delimiter::Invisible, inner_tokens)) => {
let inner_tokens = inner_tokens.clone();
tokens.next();
return NestedMetaItem::from_tokens(&mut inner_tokens.into_trees().peekable());
Expand Down
43 changes: 25 additions & 18 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub use BinOpToken::*;
pub use DelimToken::*;
pub use LitKind::*;
pub use Nonterminal::*;
pub use TokenKind::*;
Expand Down Expand Up @@ -37,18 +36,26 @@ pub enum BinOpToken {
Shr,
}

/// A delimiter token.
#[derive(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Debug, Copy)]
#[derive(HashStable_Generic)]
pub enum DelimToken {
/// A round parenthesis (i.e., `(` or `)`).
Paren,
/// A square bracket (i.e., `[` or `]`).
Bracket,
/// A curly brace (i.e., `{` or `}`).
/// Describes how a sequence of token trees is delimited.
/// Cannot use `proc_macro::Delimiter` directly because this
/// structure should implement some additional traits.
/// The `None` variant is also renamed to `Invisible` to be
/// less confusing and better convey the semantics.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Encodable, Decodable, Hash, HashStable_Generic)]
pub enum Delimiter {
/// `( ... )`
Parenthesis,
/// `{ ... }`
Brace,
/// An empty delimiter.
NoDelim,
/// `[ ... ]`
Bracket,
/// `Ø ... Ø`
/// An invisible delimiter, that may, for example, appear around tokens coming from a
/// "macro variable" `$var`. It is important to preserve operator priorities in cases like
/// `$var * 3` where `$var` is `1 + 2`.
/// Invisible delimiters might not survive roundtrip of a token stream through a string.
Invisible,
}

#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
Expand Down Expand Up @@ -212,9 +219,9 @@ pub enum TokenKind {
/// Used by proc macros for representing lifetimes, not generated by lexer right now.
SingleQuote,
/// An opening delimiter (e.g., `{`).
OpenDelim(DelimToken),
OpenDelim(Delimiter),
/// A closing delimiter (e.g., `}`).
CloseDelim(DelimToken),
CloseDelim(Delimiter),

/* Literals */
Literal(Lit),
Expand Down Expand Up @@ -387,8 +394,8 @@ impl Token {
match self.uninterpolate().kind {
Ident(name, is_raw) =>
ident_can_begin_type(name, self.span, is_raw), // type name or keyword
OpenDelim(Paren) | // tuple
OpenDelim(Bracket) | // array
OpenDelim(Delimiter::Parenthesis) | // tuple
OpenDelim(Delimiter::Bracket) | // array
Not | // never
BinOp(Star) | // raw pointer
BinOp(And) | // reference
Expand All @@ -405,7 +412,7 @@ impl Token {
/// Returns `true` if the token can appear at the start of a const param.
pub fn can_begin_const_arg(&self) -> bool {
match self.kind {
OpenDelim(Brace) => true,
OpenDelim(Delimiter::Brace) => true,
Interpolated(ref nt) => matches!(**nt, NtExpr(..) | NtBlock(..) | NtLiteral(..)),
_ => self.can_begin_literal_maybe_minus(),
}
Expand All @@ -417,7 +424,7 @@ impl Token {
|| self.is_lifetime()
|| self.is_keyword(kw::For)
|| self == &Question
|| self == &OpenDelim(Paren)
|| self == &OpenDelim(Delimiter::Parenthesis)
}

/// Returns `true` if the token is any literal.
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking
//! ownership of the original.

use crate::token::{self, DelimToken, Token, TokenKind};
use crate::token::{self, Delimiter, Token, TokenKind};
use crate::AttrVec;

use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
Expand Down Expand Up @@ -42,7 +42,7 @@ pub enum TokenTree {
/// A single token.
Token(Token),
/// A delimited sequence of token trees.
Delimited(DelimSpan, DelimToken, TokenStream),
Delimited(DelimSpan, Delimiter, TokenStream),
}

#[derive(Copy, Clone)]
Expand All @@ -57,7 +57,7 @@ fn _dummy()
where
Token: Send + Sync,
DelimSpan: Send + Sync,
DelimToken: Send + Sync,
Delimiter: Send + Sync,
TokenStream: Send + Sync,
{
}
Expand Down Expand Up @@ -175,7 +175,7 @@ pub struct AttrAnnotatedTokenStream(pub Lrc<Vec<(AttrAnnotatedTokenTree, Spacing
#[derive(Clone, Debug, Encodable, Decodable)]
pub enum AttrAnnotatedTokenTree {
Token(Token),
Delimited(DelimSpan, DelimToken, AttrAnnotatedTokenStream),
Delimited(DelimSpan, Delimiter, AttrAnnotatedTokenStream),
/// Stores the attributes for an attribute target,
/// along with the tokens for that attribute target.
/// See `AttributesData` for more information
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)]

use rustc_ast::token::{self, Token};
use rustc_ast::token::{Delimiter, Token};
use rustc_ast::tokenstream::{CanSynthesizeMissingTokens, TokenStream, TokenTree};
use rustc_ast::visit;
use rustc_ast::{self as ast, *};
Expand Down Expand Up @@ -886,7 +886,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
match tokens.into_trees().next() {
Some(TokenTree::Token(token)) => token,
Some(TokenTree::Delimited(_, delim, tokens)) => {
if delim != token::NoDelim {
if delim != Delimiter::Invisible {
sess.diagnostic().delay_span_bug(
span,
"unexpected delimiter in key-value attribute's value",
Expand Down
28 changes: 15 additions & 13 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::pp::Breaks::{Consistent, Inconsistent};
use crate::pp::{self, Breaks};

use rustc_ast::ptr::P;
use rustc_ast::token::{self, BinOpToken, CommentKind, DelimToken, Nonterminal, Token, TokenKind};
use rustc_ast::token::{self, BinOpToken, CommentKind, Delimiter, Nonterminal, Token, TokenKind};
use rustc_ast::tokenstream::{TokenStream, TokenTree};
use rustc_ast::util::classify;
use rustc_ast::util::comments::{gather_comments, Comment, CommentStyle};
Expand Down Expand Up @@ -155,10 +155,10 @@ fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool {
}
match tt {
TokenTree::Token(token) => !matches!(token.kind, token::Comma | token::Not | token::Dot),
TokenTree::Delimited(_, DelimToken::Paren, _) => {
TokenTree::Delimited(_, Delimiter::Parenthesis, _) => {
!matches!(prev, TokenTree::Token(Token { kind: token::Ident(..), .. }))
}
TokenTree::Delimited(_, DelimToken::Bracket, _) => {
TokenTree::Delimited(_, Delimiter::Bracket, _) => {
!matches!(prev, TokenTree::Token(Token { kind: token::Pound, .. }))
}
TokenTree::Delimited(..) => true,
Expand Down Expand Up @@ -556,12 +556,12 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
header: Option<MacHeader<'_>>,
has_bang: bool,
ident: Option<Ident>,
delim: Option<DelimToken>,
delim: Option<Delimiter>,
tts: &TokenStream,
convert_dollar_crate: bool,
span: Span,
) {
if delim == Some(DelimToken::Brace) {
if delim == Some(Delimiter::Brace) {
self.cbox(INDENT_UNIT);
}
match header {
Expand All @@ -577,7 +577,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.print_ident(ident);
}
match delim {
Some(DelimToken::Brace) => {
Some(Delimiter::Brace) => {
if header.is_some() || has_bang || ident.is_some() {
self.nbsp();
}
Expand Down Expand Up @@ -758,13 +758,15 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
token::RArrow => "->".into(),
token::LArrow => "<-".into(),
token::FatArrow => "=>".into(),
token::OpenDelim(token::Paren) => "(".into(),
token::CloseDelim(token::Paren) => ")".into(),
token::OpenDelim(token::Bracket) => "[".into(),
token::CloseDelim(token::Bracket) => "]".into(),
token::OpenDelim(token::Brace) => "{".into(),
token::CloseDelim(token::Brace) => "}".into(),
token::OpenDelim(token::NoDelim) | token::CloseDelim(token::NoDelim) => "".into(),
token::OpenDelim(Delimiter::Parenthesis) => "(".into(),
token::CloseDelim(Delimiter::Parenthesis) => ")".into(),
token::OpenDelim(Delimiter::Bracket) => "[".into(),
token::CloseDelim(Delimiter::Bracket) => "]".into(),
token::OpenDelim(Delimiter::Brace) => "{".into(),
token::CloseDelim(Delimiter::Brace) => "}".into(),
token::OpenDelim(Delimiter::Invisible) | token::CloseDelim(Delimiter::Invisible) => {
"".into()
}
token::Pound => "#".into(),
token::Dollar => "$".into(),
token::Question => "?".into(),
Expand Down
35 changes: 34 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
use rustc_infer::infer::{
error_reporting::nice_region_error::{self, find_param_with_region, NiceRegionError},
error_reporting::nice_region_error::{
self, find_anon_type, find_param_with_region, suggest_adding_lifetime_params,
NiceRegionError,
},
error_reporting::unexpected_hidden_region_diagnostic,
NllRegionVariableOrigin, RelateParamBound,
};
Expand Down Expand Up @@ -630,6 +633,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}

self.add_static_impl_trait_suggestion(&mut diag, *fr, fr_name, *outlived_fr);
self.suggest_adding_lifetime_params(&mut diag, *fr, *outlived_fr);

diag
}
Expand Down Expand Up @@ -694,4 +698,33 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
);
}
}

fn suggest_adding_lifetime_params(
&self,
diag: &mut Diagnostic,
sub: RegionVid,
sup: RegionVid,
) {
let (Some(sub), Some(sup)) = (self.to_error_region(sub), self.to_error_region(sup)) else {
return
};

let Some((ty_sub, _)) = self
.infcx
.tcx
.is_suitable_region(sub)
.and_then(|anon_reg| find_anon_type(self.infcx.tcx, sub, &anon_reg.boundregion)) else {
return
};

let Some((ty_sup, _)) = self
.infcx
.tcx
.is_suitable_region(sup)
.and_then(|anon_reg| find_anon_type(self.infcx.tcx, sup, &anon_reg.boundregion)) else {
return
};

suggest_adding_lifetime_params(self.infcx.tcx, sub, ty_sup, ty_sub, diag);
}
}
Loading