Merge pull request #6217 from compiler-errors/sync-from-rust-2024-06-24
subtree-push 2024-06-24
This commit is contained in:
commit
6093d48d15
@ -1,3 +1,3 @@
|
||||
[toolchain]
|
||||
channel = "nightly-2024-06-13"
|
||||
channel = "nightly-2024-06-25"
|
||||
components = ["llvm-tools", "rustc-dev"]
|
||||
|
@ -1994,7 +1994,6 @@ fn rewrite_static(
|
||||
static_parts: &StaticParts<'_>,
|
||||
offset: Indent,
|
||||
) -> Option<String> {
|
||||
println!("rewriting static");
|
||||
let colon = colon_spaces(context.config);
|
||||
let mut prefix = format!(
|
||||
"{}{}{}{} {}{}{}",
|
||||
|
@ -83,6 +83,7 @@ pub(crate) enum OverflowableItem<'a> {
|
||||
TuplePatField(&'a TuplePatField<'a>),
|
||||
Ty(&'a ast::Ty),
|
||||
Pat(&'a ast::Pat),
|
||||
PreciseCapturingArg(&'a ast::PreciseCapturingArg),
|
||||
}
|
||||
|
||||
impl<'a> Rewrite for OverflowableItem<'a> {
|
||||
@ -123,6 +124,7 @@ pub(crate) fn map<F, T>(&self, f: F) -> T
|
||||
OverflowableItem::TuplePatField(pat) => f(*pat),
|
||||
OverflowableItem::Ty(ty) => f(*ty),
|
||||
OverflowableItem::Pat(pat) => f(*pat),
|
||||
OverflowableItem::PreciseCapturingArg(arg) => f(*arg),
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,6 +139,9 @@ pub(crate) fn is_simple(&self) -> bool {
|
||||
matches!(meta_item.kind, ast::MetaItemKind::Word)
|
||||
}
|
||||
},
|
||||
// FIXME: Why don't we consider `SegmentParam` to be simple?
|
||||
// FIXME: If we also fix `SegmentParam`, then we should apply the same
|
||||
// heuristic to `PreciseCapturingArg`.
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -244,7 +249,15 @@ fn into_overflowable_item(&'a self) -> OverflowableItem<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl_into_overflowable_item_for_ast_node!(Expr, GenericParam, NestedMetaItem, FieldDef, Ty, Pat);
|
||||
impl_into_overflowable_item_for_ast_node!(
|
||||
Expr,
|
||||
GenericParam,
|
||||
NestedMetaItem,
|
||||
FieldDef,
|
||||
Ty,
|
||||
Pat,
|
||||
PreciseCapturingArg
|
||||
);
|
||||
impl_into_overflowable_item_for_rustfmt_types!([MacroArg], [SegmentParam, TuplePatField]);
|
||||
|
||||
pub(crate) fn into_overflowable_list<'a, T>(
|
||||
|
@ -67,7 +67,7 @@ fn parse_cfg_if_inner<'a>(
|
||||
Ok(None) => continue,
|
||||
Err(err) => {
|
||||
err.cancel();
|
||||
parser.psess.dcx.reset_err_count();
|
||||
parser.psess.dcx().reset_err_count();
|
||||
return Err(
|
||||
"Expected item inside cfg_if block, but failed to parse it as an item",
|
||||
);
|
||||
|
@ -16,8 +16,8 @@ macro_rules! parse_or {
|
||||
($method:ident $(,)* $($arg:expr),* $(,)*) => {
|
||||
match parser.$method($($arg,)*) {
|
||||
Ok(val) => {
|
||||
if parser.psess.dcx.has_errors().is_some() {
|
||||
parser.psess.dcx.reset_err_count();
|
||||
if parser.psess.dcx().has_errors().is_some() {
|
||||
parser.psess.dcx().reset_err_count();
|
||||
return None;
|
||||
} else {
|
||||
val
|
||||
@ -25,13 +25,12 @@ macro_rules! parse_or {
|
||||
}
|
||||
Err(err) => {
|
||||
err.cancel();
|
||||
parser.psess.dcx.reset_err_count();
|
||||
parser.psess.dcx().reset_err_count();
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while parser.token.kind != TokenKind::Eof {
|
||||
// Parse a `lazy_static!` item.
|
||||
let vis = parse_or!(parse_visibility, rustc_parse::parser::FollowedByType::No);
|
||||
|
@ -1,4 +1,4 @@
|
||||
use rustc_ast::token::{Delimiter, NonterminalKind, TokenKind};
|
||||
use rustc_ast::token::{Delimiter, NonterminalKind, NtExprKind::*, NtPatKind::*, TokenKind};
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{ast, ptr};
|
||||
use rustc_parse::parser::{ForceCollect, Parser, Recovery};
|
||||
@ -29,8 +29,8 @@ macro_rules! parse_macro_arg {
|
||||
if Parser::nonterminal_may_begin_with($nt_kind, &cloned_parser.token) {
|
||||
match $try_parse(&mut cloned_parser) {
|
||||
Ok(x) => {
|
||||
if parser.psess.dcx.has_errors().is_some() {
|
||||
parser.psess.dcx.reset_err_count();
|
||||
if parser.psess.dcx().has_errors().is_some() {
|
||||
parser.psess.dcx().reset_err_count();
|
||||
} else {
|
||||
// Parsing succeeded.
|
||||
*parser = cloned_parser;
|
||||
@ -39,7 +39,7 @@ macro_rules! parse_macro_arg {
|
||||
}
|
||||
Err(e) => {
|
||||
e.cancel();
|
||||
parser.psess.dcx.reset_err_count();
|
||||
parser.psess.dcx().reset_err_count();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -48,7 +48,7 @@ macro_rules! parse_macro_arg {
|
||||
|
||||
parse_macro_arg!(
|
||||
Expr,
|
||||
NonterminalKind::Expr,
|
||||
NonterminalKind::Expr(Expr),
|
||||
|parser: &mut Parser<'b>| parser.parse_expr(),
|
||||
|x: ptr::P<ast::Expr>| Some(x)
|
||||
);
|
||||
@ -60,7 +60,7 @@ macro_rules! parse_macro_arg {
|
||||
);
|
||||
parse_macro_arg!(
|
||||
Pat,
|
||||
NonterminalKind::PatParam { inferred: false },
|
||||
NonterminalKind::Pat(PatParam { inferred: false }),
|
||||
|parser: &mut Parser<'b>| parser.parse_pat_no_top_alt(None, None),
|
||||
|x: ptr::P<ast::Pat>| Some(x)
|
||||
);
|
||||
|
@ -210,7 +210,9 @@ pub(crate) fn set_silent_emitter(&mut self) {
|
||||
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
|
||||
false,
|
||||
);
|
||||
self.raw_psess.dcx.make_silent(fallback_bundle, None, false);
|
||||
self.raw_psess
|
||||
.dcx()
|
||||
.make_silent(fallback_bundle, None, false);
|
||||
}
|
||||
|
||||
pub(crate) fn span_to_filename(&self, span: Span) -> FileName {
|
||||
@ -286,11 +288,11 @@ pub(super) fn can_reset_errors(&self) -> bool {
|
||||
}
|
||||
|
||||
pub(super) fn has_errors(&self) -> bool {
|
||||
self.raw_psess.dcx.has_errors().is_some()
|
||||
self.raw_psess.dcx().has_errors().is_some()
|
||||
}
|
||||
|
||||
pub(super) fn reset_errors(&self) {
|
||||
self.raw_psess.dcx.reset_err_count();
|
||||
self.raw_psess.dcx().reset_err_count();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,6 +181,7 @@ fn span(&self) -> Span {
|
||||
match *self {
|
||||
ast::GenericBound::Trait(ref ptr, _) => ptr.span,
|
||||
ast::GenericBound::Outlives(ref l) => l.ident.span,
|
||||
ast::GenericBound::Use(_, span) => span,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -202,3 +203,12 @@ fn span(&self) -> Span {
|
||||
self.span()
|
||||
}
|
||||
}
|
||||
|
||||
impl Spanned for ast::PreciseCapturingArg {
|
||||
fn span(&self) -> Span {
|
||||
match self {
|
||||
ast::PreciseCapturingArg::Lifetime(lt) => lt.ident.span,
|
||||
ast::PreciseCapturingArg::Arg(path, _) => path.span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
29
src/types.rs
29
src/types.rs
@ -177,6 +177,17 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String>
|
||||
}
|
||||
}
|
||||
|
||||
impl Rewrite for ast::PreciseCapturingArg {
|
||||
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
|
||||
match self {
|
||||
ast::PreciseCapturingArg::Lifetime(lt) => lt.rewrite(context, shape),
|
||||
ast::PreciseCapturingArg::Arg(p, _) => {
|
||||
rewrite_path(context, PathContext::Type, &None, p, shape)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Rewrite for ast::AssocItemConstraint {
|
||||
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
|
||||
use ast::AssocItemConstraintKind::{Bound, Equality};
|
||||
@ -564,6 +575,9 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String>
|
||||
.map(|s| format!("{constness}{asyncness}{polarity}{s}"))
|
||||
.map(|s| if has_paren { format!("({})", s) } else { s })
|
||||
}
|
||||
ast::GenericBound::Use(ref args, span) => {
|
||||
overflow::rewrite_with_angle_brackets(context, "use", args.iter(), shape, span)
|
||||
}
|
||||
ast::GenericBound::Outlives(ref lifetime) => lifetime.rewrite(context, shape),
|
||||
}
|
||||
}
|
||||
@ -847,11 +861,7 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String>
|
||||
rewrite_macro(mac, None, context, shape, MacroPosition::Expression)
|
||||
}
|
||||
ast::TyKind::ImplicitSelf => Some(String::from("")),
|
||||
ast::TyKind::ImplTrait(_, ref it, ref captures) => {
|
||||
// FIXME(precise_capturing): Implement formatting.
|
||||
if captures.is_some() {
|
||||
return None;
|
||||
}
|
||||
ast::TyKind::ImplTrait(_, ref it) => {
|
||||
// Empty trait is not a parser error.
|
||||
if it.is_empty() {
|
||||
return Some("impl".to_owned());
|
||||
@ -935,7 +945,7 @@ fn rewrite_bare_fn(
|
||||
fn is_generic_bounds_in_order(generic_bounds: &[ast::GenericBound]) -> bool {
|
||||
let is_trait = |b: &ast::GenericBound| match b {
|
||||
ast::GenericBound::Outlives(..) => false,
|
||||
ast::GenericBound::Trait(..) => true,
|
||||
ast::GenericBound::Trait(..) | ast::GenericBound::Use(..) => true,
|
||||
};
|
||||
let is_lifetime = |b: &ast::GenericBound| !is_trait(b);
|
||||
let last_trait_index = generic_bounds.iter().rposition(is_trait);
|
||||
@ -969,7 +979,8 @@ fn join_bounds_inner(
|
||||
let generic_bounds_in_order = is_generic_bounds_in_order(items);
|
||||
let is_bound_extendable = |s: &str, b: &ast::GenericBound| match b {
|
||||
ast::GenericBound::Outlives(..) => true,
|
||||
ast::GenericBound::Trait(..) => last_line_extendable(s),
|
||||
// We treat `use<>` like a trait bound here.
|
||||
ast::GenericBound::Trait(..) | ast::GenericBound::Use(..) => last_line_extendable(s),
|
||||
};
|
||||
|
||||
// Whether a GenericBound item is a PathSegment segment that includes internal array
|
||||
@ -991,6 +1002,7 @@ fn join_bounds_inner(
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::GenericBound::Use(args, _) => args.len() > 1,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
@ -1114,8 +1126,7 @@ fn join_bounds_inner(
|
||||
|
||||
pub(crate) fn opaque_ty(ty: &Option<ptr::P<ast::Ty>>) -> Option<&ast::GenericBounds> {
|
||||
ty.as_ref().and_then(|t| match &t.kind {
|
||||
// FIXME(precise_capturing): Implement support here
|
||||
ast::TyKind::ImplTrait(_, bounds, _) => Some(bounds),
|
||||
ast::TyKind::ImplTrait(_, bounds) => Some(bounds),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
9
tests/source/precise-capturing.rs
Normal file
9
tests/source/precise-capturing.rs
Normal file
@ -0,0 +1,9 @@
|
||||
fn hello() -> impl
|
||||
use<'a> + Sized {}
|
||||
|
||||
fn all_three() -> impl Sized + use<'a> + 'a;
|
||||
|
||||
fn pathological() -> impl use<'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a,
|
||||
'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a,
|
||||
'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a,
|
||||
'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a> + Sized {}
|
55
tests/target/precise-capturing.rs
Normal file
55
tests/target/precise-capturing.rs
Normal file
@ -0,0 +1,55 @@
|
||||
fn hello() -> impl use<'a> + Sized {}
|
||||
|
||||
fn all_three() -> impl Sized + use<'a> + 'a;
|
||||
|
||||
fn pathological() -> impl use<
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
'a,
|
||||
> + Sized {
|
||||
}
|
Loading…
Reference in New Issue
Block a user