Skip to content
Closed
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f920008
Improve proc macro attribute diagnostics
Jan 3, 2023
a8e3abd
Address feedback
Jan 8, 2023
2d82420
Teach parser to understand fake anonymous enum syntax
estebank Jan 15, 2023
c847a01
Emit fewer errors on patterns with possible type ascription
estebank Jan 17, 2023
12d18e4
Ensure macros are not affected
estebank Jan 17, 2023
8e43414
Fix proc macro tests
mejrs Jan 19, 2023
e1f630f
Add `OnceCell<T>: !Sync` impl for diagnostics
Noratrieb Jan 16, 2023
6d0c91f
Add `rustc_on_unimplemented` on `Sync` for cell types
Noratrieb Jan 16, 2023
d3cfe97
Custom MIR: Support binary and unary operations
tmiasko Jan 19, 2023
9806a9e
Print PID holding bootstrap build lock on Linux
clubby789 Jan 19, 2023
236f823
`sub_ptr()` is equivalent to `usize::try_from().unwrap_unchecked()`, …
ChayimFriedman2 Jan 23, 2023
e477cf9
Suggest coercion of `Result` using `?`
estebank Jan 8, 2023
d5a1609
review comment: use `fcx.infcx`
estebank Jan 8, 2023
ddd9a9f
Add call in `emit_type_mismatch_suggestions`
estebank Jan 8, 2023
fcf0ed9
Do not erase regions
estebank Jan 8, 2023
df81147
Ensure suggestion correctness
estebank Jan 8, 2023
62aff3b
tweak wording
estebank Jan 23, 2023
033047a
`new_outside_solver` -> `evaluate_root_goal`
lcnr Jan 23, 2023
bed3bb5
Don't resolve type var roots in point_at_expr_source_of_inferred_type
compiler-errors Jan 21, 2023
9f933b5
Hack to suppress bad labels in type mismatch inference deduction code
compiler-errors Jan 21, 2023
020cca8
review comment: Remove AST AnonTy
estebank Jan 23, 2023
91cb421
Rollup merge of #106407 - mejrs:attr_check, r=compiler-errors
matthiaskrgr Jan 23, 2023
3ebd120
Rollup merge of #106583 - estebank:suggest-result-coercion, r=compile…
matthiaskrgr Jan 23, 2023
f843609
Rollup merge of #106944 - Nilstrieb:there-once-was-a-diagnostic, r=Wa…
matthiaskrgr Jan 23, 2023
ffd5181
Rollup merge of #106960 - estebank:parse-anon-enums, r=cjgillot
matthiaskrgr Jan 23, 2023
00a8e59
Rollup merge of #107085 - tmiasko:custom-mir-operators, r=oli-obk
matthiaskrgr Jan 23, 2023
47b033e
Rollup merge of #107086 - clubby789:bootstrap-lock-pid-linux, r=alber…
matthiaskrgr Jan 23, 2023
4d65df0
Rollup merge of #107175 - compiler-errors:bad-types-in-vec-push, r=es…
matthiaskrgr Jan 23, 2023
d94d928
Rollup merge of #107223 - ChayimFriedman2:patch-5, r=WaffleLapkin
matthiaskrgr Jan 23, 2023
7c055af
Rollup merge of #107227 - lcnr:solver-new-external-api, r=compiler-er…
matthiaskrgr Jan 23, 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
@@ -400,8 +400,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(tuple_element_types) => {
walk_list!(visitor, visit_ty, tuple_element_types);
TyKind::Tup(tys) => {
walk_list!(visitor, visit_ty, tys);
}
TyKind::BareFn(function_declaration) => {
walk_list!(visitor, visit_generic_param, &function_declaration.generic_params);
21 changes: 21 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/passes.ftl
Original file line number Diff line number Diff line change
@@ -710,3 +710,24 @@ passes_ignored_derived_impls =
[one] trait {$trait_list}, but this is
*[other] traits {$trait_list}, but these are
} intentionally ignored during dead code analysis
passes_proc_macro_typeerror = mismatched {$kind} signature
.label = found {$found}, expected type `proc_macro::TokenStream`
.note = {$kind}s must have a signature of `{$expected_signature}`
passes_proc_macro_diff_arg_count = mismatched {$kind} signature
.label = found unexpected {$count ->
[one] argument
*[other] arguments
}
.note = {$kind}s must have a signature of `{$expected_signature}`
passes_proc_macro_missing_args = mismatched {$kind} signature
.label = {$kind} must have {$expected_input_count ->
[one] one argument
*[other] two arguments
} of type `proc_macro::TokenStream`
passes_proc_macro_invalid_abi = proc macro functions may not be `extern "{$abi}"`
passes_proc_macro_unsafe = proc macro functions may not be `unsafe`
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
@@ -1619,6 +1619,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
}
}
}

fn note_unreachable_loop_return(
&self,
err: &mut Diagnostic,
93 changes: 75 additions & 18 deletions compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
@@ -59,9 +59,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|| self.suggest_copied_or_cloned(err, expr, expr_ty, expected)
|| self.suggest_clone_for_ref(err, expr, expr_ty, expected)
|| self.suggest_into(err, expr, expr_ty, expected)
|| self.suggest_floating_point_literal(err, expr, expected);
|| self.suggest_floating_point_literal(err, expr, expected)
|| self.note_result_coercion(err, expr, expected, expr_ty);
if !suggested {
self.point_at_expr_source_of_inferred_type(err, expr, expr_ty, expected);
self.point_at_expr_source_of_inferred_type(err, expr, expr_ty, expected, expr.span);
}
}

@@ -222,6 +223,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr: &hir::Expr<'_>,
found: Ty<'tcx>,
expected: Ty<'tcx>,
mismatch_span: Span,
) -> bool {
let map = self.tcx.hir();

@@ -270,7 +272,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
lt_op: |_| self.tcx.lifetimes.re_erased,
ct_op: |c| c,
ty_op: |t| match *t.kind() {
ty::Infer(ty::TyVar(vid)) => self.tcx.mk_ty_infer(ty::TyVar(self.root_var(vid))),
ty::Infer(ty::TyVar(_)) => self.tcx.mk_ty_var(ty::TyVid::from_u32(0)),
ty::Infer(ty::IntVar(_)) => {
self.tcx.mk_ty_infer(ty::IntVar(ty::IntVid { index: 0 }))
}
@@ -281,7 +283,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
},
};
let mut prev = eraser.fold_ty(ty);
let mut prev_span = None;
let mut prev_span: Option<Span> = None;

for binding in expr_finder.uses {
// In every expression where the binding is referenced, we will look at that
@@ -333,13 +335,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// inferred in this method call.
let arg = &args[i];
let arg_ty = self.node_ty(arg.hir_id);
err.span_label(
arg.span,
&format!(
"this is of type `{arg_ty}`, which causes `{ident}` to be \
inferred as `{ty}`",
),
);
if !arg.span.overlaps(mismatch_span) {
err.span_label(
arg.span,
&format!(
"this is of type `{arg_ty}`, which causes `{ident}` to be \
inferred as `{ty}`",
),
);
}
param_args.insert(param_ty, (arg, arg_ty));
}
}
@@ -382,12 +386,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& self.can_eq(self.param_env, ty, found).is_ok()
{
// We only point at the first place where the found type was inferred.
if !segment.ident.span.overlaps(mismatch_span) {
err.span_label(
segment.ident.span,
with_forced_trimmed_paths!(format!(
"here the type of `{ident}` is inferred to be `{ty}`",
)),
);
);}
break;
} else if !param_args.is_empty() {
break;
@@ -406,12 +411,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// We use the *previous* span because if the type is known *here* it means
// it was *evaluated earlier*. We don't do this for method calls because we
// evaluate the method's self type eagerly, but not in any other case.
err.span_label(
span,
with_forced_trimmed_paths!(format!(
"here the type of `{ident}` is inferred to be `{ty}`",
)),
);
if !span.overlaps(mismatch_span) {
err.span_label(
span,
with_forced_trimmed_paths!(format!(
"here the type of `{ident}` is inferred to be `{ty}`",
)),
);
}
break;
}
prev = ty;
@@ -697,6 +704,56 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}

pub(crate) fn note_result_coercion(
&self,
err: &mut Diagnostic,
expr: &hir::Expr<'tcx>,
expected: Ty<'tcx>,
found: Ty<'tcx>,
) -> bool {
let ty::Adt(e, substs_e) = expected.kind() else { return false; };
let ty::Adt(f, substs_f) = found.kind() else { return false; };
if e.did() != f.did() {
return false;
}
if Some(e.did()) != self.tcx.get_diagnostic_item(sym::Result) {
return false;
}
let map = self.tcx.hir();
if let Some(hir::Node::Expr(expr)) = map.find_parent(expr.hir_id)
&& let hir::ExprKind::Ret(_) = expr.kind
{
// `return foo;`
} else if map.get_return_block(expr.hir_id).is_some() {
// Function's tail expression.
} else {
return false;
}
let e = substs_e.type_at(1);
let f = substs_f.type_at(1);
if self
.infcx
.type_implements_trait(
self.tcx.get_diagnostic_item(sym::Into).unwrap(),
[f, e],
self.param_env,
)
.must_apply_modulo_regions()
{
err.multipart_suggestion(
"use `?` to coerce and return an appropriate `Err`, and wrap the resulting value \
in `Ok` so the expression remains of type `Result`",
vec![
(expr.span.shrink_to_lo(), "Ok(".to_string()),
(expr.span.shrink_to_hi(), "?)".to_string()),
],
Applicability::MaybeIncorrect,
);
return true;
}
false
}

/// If the expected type is an enum (Issue #55250) with any variants whose
/// sole field is of the found type, suggest such variants. (Issue #42764)
fn suggest_compatible_variants(
8 changes: 7 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
@@ -808,7 +808,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
kind: TypeVariableOriginKind::MiscVariable,
span: full_call_span,
});
self.point_at_expr_source_of_inferred_type(&mut err, rcvr, expected, callee_ty);
self.point_at_expr_source_of_inferred_type(
&mut err,
rcvr,
expected,
callee_ty,
provided_arg_span,
);
}
// Call out where the function is defined
self.label_fn_like(
Original file line number Diff line number Diff line change
@@ -147,6 +147,12 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
ExprKind::AddressOf { mutability, arg } => Ok(
Rvalue::AddressOf(*mutability, self.parse_place(*arg)?)
),
ExprKind::Binary { op, lhs, rhs } => Ok(
Rvalue::BinaryOp(*op, Box::new((self.parse_operand(*lhs)?, self.parse_operand(*rhs)?)))
),
ExprKind::Unary { op, arg } => Ok(
Rvalue::UnaryOp(*op, self.parse_operand(*arg)?)
),
_ => self.parse_operand(expr_id).map(Rvalue::Use),
)
}
52 changes: 39 additions & 13 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -2372,7 +2372,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(
pub(crate) fn maybe_recover_colon_colon_in_pat_typo_or_anon_enum(
&mut self,
mut first_pat: P<Pat>,
expected: Expected,
@@ -2383,26 +2383,41 @@ 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 span = self.token.span;
let colon_span = self.token.span;
// We only emit "unexpected `:`" error here if we can successfully parse the
// whole pattern correctly in that case.
let snapshot = self.create_snapshot_for_diagnostic();
let mut snapshot_pat = self.create_snapshot_for_diagnostic();
let mut snapshot_type = self.create_snapshot_for_diagnostic();

// Create error for "unexpected `:`".
match self.expected_one_of_not_found(&[], &[]) {
Err(mut err) => {
self.bump(); // Skip the `:`.
match self.parse_pat_no_top_alt(expected) {
snapshot_pat.bump(); // Skip the `:`.
snapshot_type.bump(); // Skip the `:`.
match snapshot_pat.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.
@@ -2466,22 +2481,33 @@ impl<'a> Parser<'a> {
_ => {}
}
if show_sugg {
err.span_suggestion(
span,
err.span_suggestion_verbose(
colon_span.until(self.look_ahead(1, |t| t.span)),
"maybe write a path separator here",
"::",
Applicability::MaybeIncorrect,
);
} else {
first_pat = self.mk_pat(new_span, PatKind::Wild);
}
err.emit();
self.restore_snapshot(snapshot_pat);
}
}
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
3 changes: 2 additions & 1 deletion compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
@@ -116,7 +116,8 @@ 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(first_pat, expected);
first_pat =
self.maybe_recover_colon_colon_in_pat_typo_or_anon_enum(first_pat, expected);
}

if let Some(leading_vert_span) = leading_vert_span {
Loading