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 9 pull requests #107578

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a63f5dc
Remove confusing 'while checking' note from opaque future type mismat…
compiler-errors Jan 22, 2023
5209d6f
Remove hardcoded clang target: ios13 or ios14 for Mac Catalyst [fixed]
imWildCat Jan 27, 2023
72419ef
Recover _ as .. in field pattern
compiler-errors Jan 15, 2023
f1cb13e
Improve diagnostic for missing space in range pattern
clubby789 Jan 30, 2023
75e87d1
Fix syntax in `-Zunpretty-expanded` output for derived `PartialEq`.
nnethercote Jan 30, 2023
b96c899
Rename `rust_2015` => `is_rust_2015`
WaffleLapkin Feb 1, 2023
7f8bf60
Use `rust_2018` instead of `!is_rust_2015`
WaffleLapkin Feb 1, 2023
63f82db
Inline CSS background images directly into the CSS
GuillaumeGomez Jan 31, 2023
fb38578
Add proc-macro boilerplate to crt-static test
Feb 1, 2023
619de1b
Revert "Teach parser to understand fake anonymous enum syntax" and re…
compiler-errors Jan 30, 2023
250f530
Add a test
compiler-errors Jan 30, 2023
c8f7387
Rollup merge of #106919 - compiler-errors:underscore-typo-in-field-pa…
compiler-errors Feb 2, 2023
a6b171d
Rollup merge of #106925 - imWildCat:imWildCat/remove-hardcoded-ios-ma…
compiler-errors Feb 2, 2023
9d959ea
Rollup merge of #107201 - compiler-errors:confusing-async-fn-note, r=…
compiler-errors Feb 2, 2023
93e9dac
Rollup merge of #107478 - compiler-errors:anon-enum-tys-are-ambiguous…
compiler-errors Feb 2, 2023
191ee56
Rollup merge of #107488 - nnethercote:fix-PartialEq-syntax, r=RalfJung
compiler-errors Feb 2, 2023
beb3f5d
Rollup merge of #107493 - clubby789:range-fat-arrow-followup, r=estebank
compiler-errors Feb 2, 2023
8c835be
Rollup merge of #107531 - GuillaumeGomez:inline-images-in-css, r=notr…
compiler-errors Feb 2, 2023
abd02cc
Rollup merge of #107559 - WaffleLapkin:is_it_2015¿, r=davidtwco
compiler-errors Feb 2, 2023
e3c0499
Rollup merge of #107576 - P1n3appl3:master, r=tmandry
compiler-errors Feb 2, 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
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
walk_list!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Ref);
visitor.visit_ty(&mutable_type.ty)
}
TyKind::Tup(tys) => {
walk_list!(visitor, visit_ty, tys);
TyKind::Tup(tuple_element_types) => {
walk_list!(visitor, visit_ty, tuple_element_types);
}
TyKind::BareFn(function_declaration) => {
walk_list!(visitor, visit_generic_param, &function_declaration.generic_params);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub fn print_crate<'a>(

// Currently, in Rust 2018 we don't have `extern crate std;` at the crate
// root, so this is not needed, and actually breaks things.
if edition.rust_2015() {
if edition.is_rust_2015() {
// `#![no_std]`
let fake_attr = attr::mk_attr_word(g, ast::AttrStyle::Inner, sym::no_std, DUMMY_SP);
s.print_attribute(&fake_attr);
Expand Down
24 changes: 19 additions & 5 deletions compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,30 @@ pub fn expand_deriving_partial_eq(
cx.span_bug(field.span, "not exactly 2 arguments in `derive(PartialEq)`");
};

// We received `&T` arguments. Convert them to `T` by
// stripping `&` or adding `*`. This isn't necessary for
// type checking, but it results in much better error
// messages if something goes wrong.
// We received arguments of type `&T`. Convert them to type `T` by stripping
// any leading `&` or adding `*`. This isn't necessary for type checking, but
// it results in better error messages if something goes wrong.
//
// Note: for arguments that look like `&{ x }`, which occur with packed
// structs, this would cause expressions like `{ self.x } == { other.x }`,
// which isn't valid Rust syntax. This wouldn't break compilation because these
// AST nodes are constructed within the compiler. But it would mean that code
// printed by `-Zunpretty=expanded` (or `cargo expand`) would have invalid
// syntax, which would be suboptimal. So we wrap these in parens, giving
// `({ self.x }) == ({ other.x })`, which is valid syntax.
let convert = |expr: &P<Expr>| {
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) =
&expr.kind
{
inner.clone()
if let ExprKind::Block(..) = &inner.kind {
// `&{ x }` form: remove the `&`, add parens.
cx.expr_paren(field.span, inner.clone())
} else {
// `&x` form: remove the `&`.
inner.clone()
}
} else {
// No leading `&`: add a leading `*`.
cx.expr_deref(field.span, expr.clone())
}
};
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_error_messages/locales/en-US/parse.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ parse_inclusive_range_extra_equals = unexpected `=` after inclusive range
.suggestion_remove_eq = use `..=` instead
.note = inclusive ranges end with a single equals sign (`..=`)

parse_inclusive_range_match_arrow = unexpected `=>` after open range
.suggestion_add_space = add a space between the pattern and `=>`
parse_inclusive_range_match_arrow = unexpected `>` after inclusive range
.label = this is parsed as an inclusive range `..=`
.suggestion = add a space between the pattern and `=>`

parse_inclusive_range_no_end = inclusive range with no end
.suggestion_open_range = use `..` instead
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_expand/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ impl<'a> ExtCtxt<'a> {
self.expr(sp, ast::ExprKind::AddrOf(ast::BorrowKind::Ref, ast::Mutability::Not, e))
}

pub fn expr_paren(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
self.expr(sp, ast::ExprKind::Paren(e))
}

pub fn expr_call(
&self,
span: Span,
Expand Down
62 changes: 16 additions & 46 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use crate::traits::{

use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnosticArg};
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString, MultiSpan};
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId};
Expand Down Expand Up @@ -1470,51 +1470,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
for (key, values) in types.iter() {
let count = values.len();
let kind = key.descr();
let mut returned_async_output_error = false;
for &sp in values {
if sp.is_desugaring(DesugaringKind::Async) && !returned_async_output_error {
if [sp] != err.span.primary_spans() {
let mut span: MultiSpan = sp.into();
span.push_span_label(
sp,
format!(
"checked the `Output` of this `async fn`, {}{} {}{}",
if count > 1 { "one of the " } else { "" },
target,
kind,
pluralize!(count),
),
);
err.span_note(
span,
"while checking the return type of the `async fn`",
);
} else {
err.span_label(
sp,
format!(
"checked the `Output` of this `async fn`, {}{} {}{}",
if count > 1 { "one of the " } else { "" },
target,
kind,
pluralize!(count),
),
);
err.note("while checking the return type of the `async fn`");
}
returned_async_output_error = true;
} else {
err.span_label(
sp,
format!(
"{}{} {}{}",
if count == 1 { "the " } else { "one of the " },
target,
kind,
pluralize!(count),
),
);
}
err.span_label(
sp,
format!(
"{}{} {}{}",
if count == 1 { "the " } else { "one of the " },
target,
kind,
pluralize!(count),
),
);
}
}
}
Expand All @@ -1537,7 +1503,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// |
// = note: expected unit type `()`
// found closure `[closure@$DIR/issue-20862.rs:2:5: 2:14 x:_]`
if !self.ignore_span.overlaps(span) {
//
// Also ignore opaque `Future`s that come from async fns.
if !self.ignore_span.overlaps(span)
&& !span.is_desugaring(DesugaringKind::Async)
{
self.types.entry(kind).or_default().insert(span);
}
}
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,10 @@ pub(crate) struct InclusiveRangeExtraEquals {
#[diag(parse_inclusive_range_match_arrow)]
pub(crate) struct InclusiveRangeMatchArrow {
#[primary_span]
pub arrow: Span,
#[label]
pub span: Span,
#[suggestion(
suggestion_add_space,
style = "verbose",
code = " ",
applicability = "machine-applicable"
)]
#[suggestion(style = "verbose", code = " ", applicability = "machine-applicable")]
pub after_pat: Span,
}

Expand Down
52 changes: 13 additions & 39 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,7 @@ impl<'a> Parser<'a> {

/// Some special error handling for the "top-level" patterns in a match arm,
/// `for` loop, `let`, &c. (in contrast to subpatterns within such).
pub(crate) fn maybe_recover_colon_colon_in_pat_typo_or_anon_enum(
pub(crate) fn maybe_recover_colon_colon_in_pat_typo(
&mut self,
mut first_pat: P<Pat>,
expected: Expected,
Expand All @@ -2405,41 +2405,26 @@ impl<'a> Parser<'a> {
if !matches!(first_pat.kind, PatKind::Ident(_, _, None) | PatKind::Path(..))
|| !self.look_ahead(1, |token| token.is_ident() && !token.is_reserved_ident())
{
let mut snapshot_type = self.create_snapshot_for_diagnostic();
snapshot_type.bump(); // `:`
match snapshot_type.parse_ty() {
Err(inner_err) => {
inner_err.cancel();
}
Ok(ty) => {
let Err(mut err) = self.expected_one_of_not_found(&[], &[]) else {
return first_pat;
};
err.span_label(ty.span, "specifying the type of a pattern isn't supported");
self.restore_snapshot(snapshot_type);
let span = first_pat.span.to(ty.span);
first_pat = self.mk_pat(span, PatKind::Wild);
err.emit();
}
}
return first_pat;
}
// The pattern looks like it might be a path with a `::` -> `:` typo:
// `match foo { bar:baz => {} }`
let colon_span = self.token.span;
let span = self.token.span;
// We only emit "unexpected `:`" error here if we can successfully parse the
// whole pattern correctly in that case.
let mut snapshot_pat = self.create_snapshot_for_diagnostic();
let mut snapshot_type = self.create_snapshot_for_diagnostic();
let snapshot = self.create_snapshot_for_diagnostic();

// Create error for "unexpected `:`".
match self.expected_one_of_not_found(&[], &[]) {
Err(mut err) => {
snapshot_pat.bump(); // Skip the `:`.
snapshot_type.bump(); // Skip the `:`.
match snapshot_pat.parse_pat_no_top_alt(expected) {
self.bump(); // Skip the `:`.
match self.parse_pat_no_top_alt(expected) {
Err(inner_err) => {
// Carry on as if we had not done anything, callers will emit a
// reasonable error.
inner_err.cancel();
err.cancel();
self.restore_snapshot(snapshot);
}
Ok(mut pat) => {
// We've parsed the rest of the pattern.
Expand Down Expand Up @@ -2503,33 +2488,22 @@ impl<'a> Parser<'a> {
_ => {}
}
if show_sugg {
err.span_suggestion_verbose(
colon_span.until(self.look_ahead(1, |t| t.span)),
err.span_suggestion(
span,
"maybe write a path separator here",
"::",
Applicability::MaybeIncorrect,
);
} else {
first_pat = self.mk_pat(new_span, PatKind::Wild);
}
self.restore_snapshot(snapshot_pat);
err.emit();
}
}
match snapshot_type.parse_ty() {
Err(inner_err) => {
inner_err.cancel();
}
Ok(ty) => {
err.span_label(ty.span, "specifying the type of a pattern isn't supported");
self.restore_snapshot(snapshot_type);
let new_span = first_pat.span.to(ty.span);
first_pat = self.mk_pat(new_span, PatKind::Wild);
}
}
err.emit();
}
_ => {
// Carry on as if we had not done anything. This should be unreachable.
self.restore_snapshot(snapshot);
}
};
first_pat
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,14 @@ impl<'a> Parser<'a> {
);
err.emit();
this.bump();
} else if matches!(
(&this.prev_token.kind, &this.token.kind),
(token::DotDotEq, token::Gt)
) {
// `error_inclusive_range_match_arrow` handles cases like `0..=> {}`,
// so we supress the error here
err.delay_as_bug();
this.bump();
} else {
return Err(err);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2442,7 +2442,7 @@ impl<'a> Parser<'a> {

/// We are parsing `async fn`. If we are on Rust 2015, emit an error.
fn ban_async_in_2015(&self, span: Span) {
if span.rust_2015() {
if span.is_rust_2015() {
let diag = self.diagnostic();
struct_span_err!(diag, span, E0670, "`async fn` is not permitted in Rust 2015")
.span_label(span, "to use `async fn`, switch to Rust 2018 or later")
Expand Down
44 changes: 25 additions & 19 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ impl<'a> Parser<'a> {

// Check if the user wrote `foo:bar` instead of `foo::bar`.
if ra == RecoverColon::Yes {
first_pat =
self.maybe_recover_colon_colon_in_pat_typo_or_anon_enum(first_pat, expected);
first_pat = self.maybe_recover_colon_colon_in_pat_typo(first_pat, expected);
}

if let Some(leading_vert_span) = leading_vert_span {
Expand Down Expand Up @@ -777,7 +776,7 @@ impl<'a> Parser<'a> {
self.error_inclusive_range_with_extra_equals(span_with_eq);
}
token::Gt if no_space => {
self.error_inclusive_range_match_arrow(span);
self.error_inclusive_range_match_arrow(span, tok.span);
}
_ => self.error_inclusive_range_with_no_end(span),
}
Expand All @@ -787,9 +786,9 @@ impl<'a> Parser<'a> {
self.sess.emit_err(InclusiveRangeExtraEquals { span });
}

fn error_inclusive_range_match_arrow(&self, span: Span) {
fn error_inclusive_range_match_arrow(&self, span: Span, arrow: Span) {
let after_pat = span.with_hi(span.hi() - rustc_span::BytePos(1)).shrink_to_hi();
self.sess.emit_err(InclusiveRangeMatchArrow { span, after_pat });
self.sess.emit_err(InclusiveRangeMatchArrow { span, arrow, after_pat });
}

fn error_inclusive_range_with_no_end(&self, span: Span) {
Expand Down Expand Up @@ -1013,12 +1012,15 @@ impl<'a> Parser<'a> {
}
ate_comma = false;

if self.check(&token::DotDot) || self.token == token::DotDotDot {
if self.check(&token::DotDot)
|| self.check_noexpect(&token::DotDotDot)
|| self.check_keyword(kw::Underscore)
{
etc = true;
let mut etc_sp = self.token.span;

self.recover_one_fewer_dotdot();
self.bump(); // `..` || `...`
self.recover_bad_dot_dot();
self.bump(); // `..` || `...` || `_`

if self.token == token::CloseDelim(Delimiter::Brace) {
etc_span = Some(etc_sp);
Expand Down Expand Up @@ -1111,21 +1113,25 @@ impl<'a> Parser<'a> {
Ok((fields, etc))
}

/// Recover on `...` as if it were `..` to avoid further errors.
/// Recover on `...` or `_` as if it were `..` to avoid further errors.
/// See issue #46718.
fn recover_one_fewer_dotdot(&self) {
if self.token != token::DotDotDot {
fn recover_bad_dot_dot(&self) {
if self.token == token::DotDot {
return;
}

self.struct_span_err(self.token.span, "expected field pattern, found `...`")
.span_suggestion(
self.token.span,
"to omit remaining fields, use one fewer `.`",
"..",
Applicability::MachineApplicable,
)
.emit();
let token_str = pprust::token_to_string(&self.token);
self.struct_span_err(
self.token.span,
format!("expected field pattern, found `{token_str}`"),
)
.span_suggestion_verbose(
self.token.span,
"to omit remaining fields, use `..`",
"..",
Applicability::MachineApplicable,
)
.emit();
}

fn parse_pat_field(&mut self, lo: Span, attrs: AttrVec) -> PResult<'a, PatField> {
Expand Down
Loading