Skip to content

Commit f2f526c

Browse files
committed
Auto merge of #117996 - matthiaskrgr:rollup-sp48bl4, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #117892 (Detect more `=>` typos) - #117959 (Better handle type errors involving `Self` literals) - #117980 (fix: Update CONTRIBUTING.md recommend -> recommended) - #117982 (bootstrap: only show PGO warnings when verbose) - #117990 (Tweak error and move tests) Failed merges: - #117944 (some additional region refactorings) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a577704 + a5d7f8b commit f2f526c

File tree

74 files changed

+193
-28
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+193
-28
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion

compiler/rustc_ast/src/token.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ impl TokenKind {
388388
match *self {
389389
Comma => Some(vec![Dot, Lt, Semi]),
390390
Semi => Some(vec![Colon, Comma]),
391-
FatArrow => Some(vec![Eq, RArrow]),
391+
Colon => Some(vec![Semi]),
392+
FatArrow => Some(vec![Eq, RArrow, Ge, Gt]),
392393
_ => None,
393394
}
394395
}

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3131
}
3232

3333
self.annotate_alternative_method_deref(err, expr, error);
34+
self.explain_self_literal(err, expr, expected, expr_ty);
3435

3536
// Use `||` to give these suggestions a precedence
3637
let suggested = self.suggest_missing_parentheses(err, expr)
@@ -1027,6 +1028,59 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10271028
return false;
10281029
}
10291030

1031+
fn explain_self_literal(
1032+
&self,
1033+
err: &mut Diagnostic,
1034+
expr: &hir::Expr<'tcx>,
1035+
expected: Ty<'tcx>,
1036+
found: Ty<'tcx>,
1037+
) {
1038+
match expr.peel_drop_temps().kind {
1039+
hir::ExprKind::Struct(
1040+
hir::QPath::Resolved(
1041+
None,
1042+
hir::Path { res: hir::def::Res::SelfTyAlias { alias_to, .. }, span, .. },
1043+
),
1044+
..,
1045+
)
1046+
| hir::ExprKind::Call(
1047+
hir::Expr {
1048+
kind:
1049+
hir::ExprKind::Path(hir::QPath::Resolved(
1050+
None,
1051+
hir::Path {
1052+
res: hir::def::Res::SelfTyAlias { alias_to, .. },
1053+
span,
1054+
..
1055+
},
1056+
)),
1057+
..
1058+
},
1059+
..,
1060+
) => {
1061+
if let Some(hir::Node::Item(hir::Item {
1062+
kind: hir::ItemKind::Impl(hir::Impl { self_ty, .. }),
1063+
..
1064+
})) = self.tcx.hir().get_if_local(*alias_to)
1065+
{
1066+
err.span_label(self_ty.span, "this is the type of the `Self` literal");
1067+
}
1068+
if let ty::Adt(e_def, e_args) = expected.kind()
1069+
&& let ty::Adt(f_def, _f_args) = found.kind()
1070+
&& e_def == f_def
1071+
{
1072+
err.span_suggestion_verbose(
1073+
*span,
1074+
"use the type name directly",
1075+
self.tcx.value_path_str_with_args(*alias_to, e_args),
1076+
Applicability::MaybeIncorrect,
1077+
);
1078+
}
1079+
}
1080+
_ => {}
1081+
}
1082+
}
1083+
10301084
fn note_wrong_return_ty_due_to_generic_arg(
10311085
&self,
10321086
err: &mut Diagnostic,

compiler/rustc_parse/src/errors.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,9 +2278,8 @@ pub(crate) enum InvalidMutInPattern {
22782278
#[note(parse_note_mut_pattern_usage)]
22792279
NonIdent {
22802280
#[primary_span]
2281-
#[suggestion(code = "{pat}", applicability = "machine-applicable")]
2281+
#[suggestion(code = "", applicability = "machine-applicable")]
22822282
span: Span,
2283-
pat: String,
22842283
},
22852284
}
22862285

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,15 +2904,16 @@ impl<'a> Parser<'a> {
29042904
"=>",
29052905
Applicability::MachineApplicable,
29062906
);
2907-
err.emit();
2908-
this.bump();
2909-
} else if matches!(
2910-
(&this.prev_token.kind, &this.token.kind),
2911-
(token::DotDotEq, token::Gt)
2912-
) {
2913-
// `error_inclusive_range_match_arrow` handles cases like `0..=> {}`,
2914-
// so we suppress the error here
2915-
err.delay_as_bug();
2907+
if matches!(
2908+
(&this.prev_token.kind, &this.token.kind),
2909+
(token::DotDotEq, token::Gt)
2910+
) {
2911+
// `error_inclusive_range_match_arrow` handles cases like `0..=> {}`,
2912+
// so we suppress the error here
2913+
err.delay_as_bug();
2914+
} else {
2915+
err.emit();
2916+
}
29162917
this.bump();
29172918
} else {
29182919
return Err(err);

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,8 @@ impl<'a> Parser<'a> {
830830
// https://github.com/rust-lang/rust/issues/72373
831831
if self.prev_token.is_ident() && self.token.kind == token::DotDot {
832832
let msg = format!(
833-
"if you meant to bind the contents of \
834-
the rest of the array pattern into `{}`, use `@`",
833+
"if you meant to bind the contents of the rest of the array \
834+
pattern into `{}`, use `@`",
835835
pprust::token_to_string(&self.prev_token)
836836
);
837837
expect_err

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,13 @@ impl<'a> Parser<'a> {
638638

639639
/// Error on `mut $pat` where `$pat` is not an ident.
640640
fn ban_mut_general_pat(&self, lo: Span, pat: &Pat, changed_any_binding: bool) {
641-
let span = lo.to(pat.span);
642-
let pat = pprust::pat_to_string(&pat);
643-
644641
self.sess.emit_err(if changed_any_binding {
645-
InvalidMutInPattern::NestedIdent { span, pat }
642+
InvalidMutInPattern::NestedIdent {
643+
span: lo.to(pat.span),
644+
pat: pprust::pat_to_string(&pat),
645+
}
646646
} else {
647-
InvalidMutInPattern::NonIdent { span, pat }
647+
InvalidMutInPattern::NonIdent { span: lo.until(pat.span) }
648648
});
649649
}
650650

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,9 @@ impl Step for Rustc {
887887
} else if let Some(path) = &builder.config.rust_profile_use {
888888
if compiler.stage == 1 {
889889
cargo.rustflag(&format!("-Cprofile-use={path}"));
890-
cargo.rustflag("-Cllvm-args=-pgo-warn-missing-function");
890+
if builder.is_verbose() {
891+
cargo.rustflag("-Cllvm-args=-pgo-warn-missing-function");
892+
}
891893
true
892894
} else {
893895
false

tests/ui/parser/issues/issue-32501.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `mut` must be followed by a named binding
22
--> $DIR/issue-32501.rs:7:9
33
|
44
LL | let mut _ = 0;
5-
| ^^^^^ help: remove the `mut` prefix: `_`
5+
| ^^^^ help: remove the `mut` prefix
66
|
77
= note: `mut` may be followed by `variable` and `variable @ pattern`
88

tests/ui/parser/issues/issue-65122-mac-invoc-in-mut-patterns.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `mut` must be followed by a named binding
22
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:6:13
33
|
44
LL | let mut $eval = ();
5-
| ^^^^^^^^^ help: remove the `mut` prefix: `does_not_exist!()`
5+
| ^^^^ help: remove the `mut` prefix
66
...
77
LL | mac1! { does_not_exist!() }
88
| --------------------------- in this macro invocation
@@ -25,7 +25,7 @@ error: `mut` must be followed by a named binding
2525
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:13:13
2626
|
2727
LL | let mut $eval = ();
28-
| ^^^ help: remove the `mut` prefix: `does_not_exist!()`
28+
| ^^^ help: remove the `mut` prefix
2929
...
3030
LL | mac2! { does_not_exist!() }
3131
| --------------------------- in this macro invocation

0 commit comments

Comments
 (0)