mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Auto merge of #153217 - JonathanBrouwer:rollup-iXVG70B, r=JonathanBrouwer
Rollup of 12 pull requests Successful merges: - rust-lang/rust#153211 (`rust-analyzer` subtree update) - rust-lang/rust#149027 (Improve cross-crate trait impl param mismatch suggestions ) - rust-lang/rust#152730 (add field representing types) - rust-lang/rust#153136 (Correctly handle `#[doc(alias = "...")]` attribute on inlined reexports) - rust-lang/rust#152165 (Normalize capture place `ty`s to prevent ICE) - rust-lang/rust#152615 (refactor 'valid for read/write' definition: exclude null) - rust-lang/rust#153109 (Fix LegacyKeyValueFormat report from docker build: aarch64-gnu-debug) - rust-lang/rust#153172 (Fix comment about placeholders) - rust-lang/rust#153187 (Fix ICE when macro-expanded extern crate shadows std) - rust-lang/rust#153190 (Don't allow subdiagnostic to use variables from their parent) - rust-lang/rust#153200 (Remove redundant clone) - rust-lang/rust#153216 (mark two polonius tests as known-bug)
This commit is contained in:
@@ -1016,7 +1016,6 @@ pub(crate) struct LeadingPlusNotSupported {
|
||||
pub(crate) struct ParenthesesWithStructFields {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub r#type: Path,
|
||||
#[subdiagnostic]
|
||||
pub braces_for_struct: BracesForStructLiteral,
|
||||
#[subdiagnostic]
|
||||
@@ -1029,6 +1028,7 @@ pub(crate) struct ParenthesesWithStructFields {
|
||||
applicability = "maybe-incorrect"
|
||||
)]
|
||||
pub(crate) struct BracesForStructLiteral {
|
||||
pub r#type: Path,
|
||||
#[suggestion_part(code = " {{ ")]
|
||||
pub first: Span,
|
||||
#[suggestion_part(code = " }}")]
|
||||
@@ -1041,6 +1041,7 @@ pub(crate) struct BracesForStructLiteral {
|
||||
applicability = "maybe-incorrect"
|
||||
)]
|
||||
pub(crate) struct NoFieldsForFnCall {
|
||||
pub r#type: Path,
|
||||
#[suggestion_part(code = "")]
|
||||
pub fields: Vec<Span>,
|
||||
}
|
||||
@@ -3176,6 +3177,7 @@ pub(crate) struct UnexpectedVertVertInPattern {
|
||||
pub(crate) struct TrailingVertSuggestion {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub token: Token,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
||||
@@ -118,16 +118,9 @@ pub fn new_parser_from_file<'a>(
|
||||
let msg = format!("couldn't read `{}`: {}", path.display(), e);
|
||||
let mut err = psess.dcx().struct_fatal(msg);
|
||||
if let Ok(contents) = std::fs::read(path)
|
||||
&& let Err(utf8err) = String::from_utf8(contents.clone())
|
||||
&& let Err(utf8err) = std::str::from_utf8(&contents)
|
||||
{
|
||||
utf8_error(
|
||||
sm,
|
||||
&path.display().to_string(),
|
||||
sp,
|
||||
&mut err,
|
||||
utf8err.utf8_error(),
|
||||
&contents,
|
||||
);
|
||||
utf8_error(sm, &path.display().to_string(), sp, &mut err, utf8err, &contents);
|
||||
}
|
||||
if let Some(sp) = sp {
|
||||
err.span(sp);
|
||||
|
||||
@@ -1140,7 +1140,7 @@ enum FloatComponent {
|
||||
/// Parse the field access used in offset_of, matched by `$(e:expr)+`.
|
||||
/// Currently returns a list of idents. However, it should be possible in
|
||||
/// future to also do array indices, which might be arbitrary expressions.
|
||||
fn parse_floating_field_access(&mut self) -> PResult<'a, Vec<Ident>> {
|
||||
pub(crate) fn parse_floating_field_access(&mut self) -> PResult<'a, Vec<Ident>> {
|
||||
let mut fields = Vec::new();
|
||||
let mut trailing_dot = None;
|
||||
|
||||
@@ -1309,12 +1309,13 @@ fn maybe_recover_struct_lit_bad_delims(
|
||||
self.dcx()
|
||||
.create_err(errors::ParenthesesWithStructFields {
|
||||
span,
|
||||
r#type: path,
|
||||
braces_for_struct: errors::BracesForStructLiteral {
|
||||
first: open_paren,
|
||||
second: close_paren,
|
||||
r#type: path.clone(),
|
||||
},
|
||||
no_fields_for_fn: errors::NoFieldsForFnCall {
|
||||
r#type: path,
|
||||
fields: fields
|
||||
.into_iter()
|
||||
.map(|field| field.span.until(field.expr.span))
|
||||
|
||||
@@ -364,6 +364,7 @@ fn recover_trailing_vert(&mut self, lo: Option<Span>) -> bool {
|
||||
start: lo,
|
||||
suggestion: TrailingVertSuggestion {
|
||||
span: self.prev_token.span.shrink_to_hi().with_hi(self.token.span.hi()),
|
||||
token: self.token,
|
||||
},
|
||||
token: self.token,
|
||||
note_double_vert: self.token.kind == token::OrOr,
|
||||
|
||||
@@ -329,6 +329,8 @@ fn parse_ty_common(
|
||||
self.parse_borrowed_pointee()?
|
||||
} else if self.eat_keyword_noexpect(kw::Typeof) {
|
||||
self.parse_typeof_ty(lo)?
|
||||
} else if self.is_builtin() {
|
||||
self.parse_builtin_ty()?
|
||||
} else if self.eat_keyword(exp!(Underscore)) {
|
||||
// A type to be inferred `_`
|
||||
TyKind::Infer
|
||||
@@ -802,6 +804,52 @@ fn parse_typeof_ty(&mut self, lo: Span) -> PResult<'a, TyKind> {
|
||||
Ok(TyKind::Err(guar))
|
||||
}
|
||||
|
||||
fn parse_builtin_ty(&mut self) -> PResult<'a, TyKind> {
|
||||
self.parse_builtin(|this, lo, ident| {
|
||||
Ok(match ident.name {
|
||||
sym::field_of => Some(this.parse_ty_field_of(lo)?),
|
||||
_ => None,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn parse_ty_field_of(&mut self, _lo: Span) -> PResult<'a, TyKind> {
|
||||
let container = self.parse_ty()?;
|
||||
self.expect(exp!(Comma))?;
|
||||
|
||||
let fields = self.parse_floating_field_access()?;
|
||||
let trailing_comma = self.eat_noexpect(&TokenKind::Comma);
|
||||
|
||||
if let Err(mut e) = self.expect_one_of(&[], &[exp!(CloseParen)]) {
|
||||
if trailing_comma {
|
||||
e.note("unexpected third argument to field_of");
|
||||
} else {
|
||||
e.note("field_of expects dot-separated field and variant names");
|
||||
}
|
||||
e.emit();
|
||||
}
|
||||
|
||||
// Eat tokens until the macro call ends.
|
||||
if self.may_recover() {
|
||||
while !self.token.kind.is_close_delim_or_eof() {
|
||||
self.bump();
|
||||
}
|
||||
}
|
||||
|
||||
match *fields {
|
||||
[] => Err(self.dcx().struct_span_err(
|
||||
self.token.span,
|
||||
"`field_of!` expects dot-separated field and variant names",
|
||||
)),
|
||||
[field] => Ok(TyKind::FieldOf(container, None, field)),
|
||||
[variant, field] => Ok(TyKind::FieldOf(container, Some(variant), field)),
|
||||
_ => Err(self.dcx().struct_span_err(
|
||||
fields.iter().map(|f| f.span).collect::<Vec<_>>(),
|
||||
"`field_of!` only supports a single field or a variant with a field",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses a function pointer type (`TyKind::FnPtr`).
|
||||
/// ```ignore (illustrative)
|
||||
/// [unsafe] [extern "ABI"] fn (S) -> T
|
||||
|
||||
Reference in New Issue
Block a user