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
This commit is contained in:
bors 2023-11-17 00:03:54 +00:00
commit f2f526cafa
74 changed files with 193 additions and 28 deletions

View File

@ -15,7 +15,7 @@ standard library in the [Standard library developers Guide][std-dev-guide], comm
## About the [rustc-dev-guide]
The [rustc-dev-guide] is meant to help document how rustc the Rust compiler works,
as well as to help new contributors get involved in rustc development. It is recommend
as well as to help new contributors get involved in rustc development. It is recommended
to read and understand the [rustc-dev-guide] before making a contribution. This guide
talks about the different bots in the Rust ecosystem, the Rust development tools,
bootstrapping, the compiler architecture, source code representation, and more.

View File

@ -388,7 +388,8 @@ impl TokenKind {
match *self {
Comma => Some(vec![Dot, Lt, Semi]),
Semi => Some(vec![Colon, Comma]),
FatArrow => Some(vec![Eq, RArrow]),
Colon => Some(vec![Semi]),
FatArrow => Some(vec![Eq, RArrow, Ge, Gt]),
_ => None,
}
}

View File

@ -31,6 +31,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
self.annotate_alternative_method_deref(err, expr, error);
self.explain_self_literal(err, expr, expected, expr_ty);
// Use `||` to give these suggestions a precedence
let suggested = self.suggest_missing_parentheses(err, expr)
@ -1027,6 +1028,59 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return false;
}
fn explain_self_literal(
&self,
err: &mut Diagnostic,
expr: &hir::Expr<'tcx>,
expected: Ty<'tcx>,
found: Ty<'tcx>,
) {
match expr.peel_drop_temps().kind {
hir::ExprKind::Struct(
hir::QPath::Resolved(
None,
hir::Path { res: hir::def::Res::SelfTyAlias { alias_to, .. }, span, .. },
),
..,
)
| hir::ExprKind::Call(
hir::Expr {
kind:
hir::ExprKind::Path(hir::QPath::Resolved(
None,
hir::Path {
res: hir::def::Res::SelfTyAlias { alias_to, .. },
span,
..
},
)),
..
},
..,
) => {
if let Some(hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl(hir::Impl { self_ty, .. }),
..
})) = self.tcx.hir().get_if_local(*alias_to)
{
err.span_label(self_ty.span, "this is the type of the `Self` literal");
}
if let ty::Adt(e_def, e_args) = expected.kind()
&& let ty::Adt(f_def, _f_args) = found.kind()
&& e_def == f_def
{
err.span_suggestion_verbose(
*span,
"use the type name directly",
self.tcx.value_path_str_with_args(*alias_to, e_args),
Applicability::MaybeIncorrect,
);
}
}
_ => {}
}
}
fn note_wrong_return_ty_due_to_generic_arg(
&self,
err: &mut Diagnostic,

View File

@ -2278,9 +2278,8 @@ pub(crate) enum InvalidMutInPattern {
#[note(parse_note_mut_pattern_usage)]
NonIdent {
#[primary_span]
#[suggestion(code = "{pat}", applicability = "machine-applicable")]
#[suggestion(code = "", applicability = "machine-applicable")]
span: Span,
pat: String,
},
}

View File

@ -2904,15 +2904,16 @@ impl<'a> Parser<'a> {
"=>",
Applicability::MachineApplicable,
);
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 suppress the error here
err.delay_as_bug();
if matches!(
(&this.prev_token.kind, &this.token.kind),
(token::DotDotEq, token::Gt)
) {
// `error_inclusive_range_match_arrow` handles cases like `0..=> {}`,
// so we suppress the error here
err.delay_as_bug();
} else {
err.emit();
}
this.bump();
} else {
return Err(err);

View File

@ -830,8 +830,8 @@ impl<'a> Parser<'a> {
// https://github.com/rust-lang/rust/issues/72373
if self.prev_token.is_ident() && self.token.kind == token::DotDot {
let msg = format!(
"if you meant to bind the contents of \
the rest of the array pattern into `{}`, use `@`",
"if you meant to bind the contents of the rest of the array \
pattern into `{}`, use `@`",
pprust::token_to_string(&self.prev_token)
);
expect_err

View File

@ -638,13 +638,13 @@ impl<'a> Parser<'a> {
/// Error on `mut $pat` where `$pat` is not an ident.
fn ban_mut_general_pat(&self, lo: Span, pat: &Pat, changed_any_binding: bool) {
let span = lo.to(pat.span);
let pat = pprust::pat_to_string(&pat);
self.sess.emit_err(if changed_any_binding {
InvalidMutInPattern::NestedIdent { span, pat }
InvalidMutInPattern::NestedIdent {
span: lo.to(pat.span),
pat: pprust::pat_to_string(&pat),
}
} else {
InvalidMutInPattern::NonIdent { span, pat }
InvalidMutInPattern::NonIdent { span: lo.until(pat.span) }
});
}

View File

@ -887,7 +887,9 @@ impl Step for Rustc {
} else if let Some(path) = &builder.config.rust_profile_use {
if compiler.stage == 1 {
cargo.rustflag(&format!("-Cprofile-use={path}"));
cargo.rustflag("-Cllvm-args=-pgo-warn-missing-function");
if builder.is_verbose() {
cargo.rustflag("-Cllvm-args=-pgo-warn-missing-function");
}
true
} else {
false

View File

@ -2,7 +2,7 @@ error: `mut` must be followed by a named binding
--> $DIR/issue-32501.rs:7:9
|
LL | let mut _ = 0;
| ^^^^^ help: remove the `mut` prefix: `_`
| ^^^^ help: remove the `mut` prefix
|
= note: `mut` may be followed by `variable` and `variable @ pattern`

View File

@ -2,7 +2,7 @@ error: `mut` must be followed by a named binding
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:6:13
|
LL | let mut $eval = ();
| ^^^^^^^^^ help: remove the `mut` prefix: `does_not_exist!()`
| ^^^^ help: remove the `mut` prefix
...
LL | mac1! { does_not_exist!() }
| --------------------------- in this macro invocation
@ -25,7 +25,7 @@ error: `mut` must be followed by a named binding
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:13:13
|
LL | let mut $eval = ();
| ^^^ help: remove the `mut` prefix: `does_not_exist!()`
| ^^^ help: remove the `mut` prefix
...
LL | mac2! { does_not_exist!() }
| --------------------------- in this macro invocation

View File

@ -0,0 +1,7 @@
// run-rustfix
fn main() {
match 1 {
1 => {} //~ ERROR
_ => { let _: u16 = 2u16; } //~ ERROR
}
}

View File

@ -0,0 +1,7 @@
// run-rustfix
fn main() {
match 1 {
1 >= {} //~ ERROR
_ => { let _: u16 = 2u8; } //~ ERROR
}
}

View File

@ -0,0 +1,25 @@
error: expected one of `...`, `..=`, `..`, `=>`, `if`, or `|`, found `>=`
--> $DIR/recover-ge-as-fat-arrow.rs:4:11
|
LL | 1 >= {}
| ^^
| |
| expected one of `...`, `..=`, `..`, `=>`, `if`, or `|`
| help: use a fat arrow to start a match arm: `=>`
error[E0308]: mismatched types
--> $DIR/recover-ge-as-fat-arrow.rs:5:29
|
LL | _ => { let _: u16 = 2u8; }
| --- ^^^ expected `u16`, found `u8`
| |
| expected due to this
|
help: change the type of the numeric literal from `u8` to `u16`
|
LL | _ => { let _: u16 = 2u16; }
| ~~~
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.

View File

@ -2,7 +2,7 @@ error: `mut` must be followed by a named binding
--> $DIR/mut-patterns.rs:9:9
|
LL | let mut _ = 0;
| ^^^^^ help: remove the `mut` prefix: `_`
| ^^^^ help: remove the `mut` prefix
|
= note: `mut` may be followed by `variable` and `variable @ pattern`
@ -10,7 +10,7 @@ error: `mut` must be followed by a named binding
--> $DIR/mut-patterns.rs:10:9
|
LL | let mut (_, _) = (0, 0);
| ^^^^^^^^^^ help: remove the `mut` prefix: `(_, _)`
| ^^^^ help: remove the `mut` prefix
|
= note: `mut` may be followed by `variable` and `variable @ pattern`

View File

@ -0,0 +1,14 @@
fn main() {
let val = 42;
let x = match val {
(0 if true) => {
//~^ ERROR expected identifier, found keyword `if`
//~| ERROR expected one of `)`, `,`, `...`, `..=`, `..`, or `|`, found keyword `if`
//~| ERROR expected one of `)`, `,`, `@`, or `|`, found keyword `true`
//~| ERROR mismatched types
42u8
}
_ => 0u8,
};
let _y: u32 = x; //~ ERROR mismatched types
}

View File

@ -0,0 +1,49 @@
error: expected identifier, found keyword `if`
--> $DIR/recover-parens-around-match-arm-head.rs:4:12
|
LL | (0 if true) => {
| ^^ expected identifier, found keyword
error: expected one of `)`, `,`, `...`, `..=`, `..`, or `|`, found keyword `if`
--> $DIR/recover-parens-around-match-arm-head.rs:4:12
|
LL | (0 if true) => {
| -^^ expected one of `)`, `,`, `...`, `..=`, `..`, or `|`
| |
| help: missing `,`
error: expected one of `)`, `,`, `@`, or `|`, found keyword `true`
--> $DIR/recover-parens-around-match-arm-head.rs:4:15
|
LL | (0 if true) => {
| -^^^^ expected one of `)`, `,`, `@`, or `|`
| |
| help: missing `,`
error[E0308]: mismatched types
--> $DIR/recover-parens-around-match-arm-head.rs:4:9
|
LL | let x = match val {
| --- this expression has type `{integer}`
LL | (0 if true) => {
| ^^^^^^^^^^^ expected integer, found `(_, _, _)`
|
= note: expected type `{integer}`
found tuple `(_, _, _)`
error[E0308]: mismatched types
--> $DIR/recover-parens-around-match-arm-head.rs:13:19
|
LL | let _y: u32 = x;
| --- ^ expected `u32`, found `u8`
| |
| expected due to this
|
help: you can convert a `u8` to a `u32`
|
LL | let _y: u32 = x.into();
| +++++++
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0308`.

View File

@ -14,7 +14,7 @@ error: `mut` must be followed by a named binding
--> $DIR/self_type_keyword.rs:16:9
|
LL | mut Self => (),
| ^^^^^^^^ help: remove the `mut` prefix: `Self`
| ^^^^ help: remove the `mut` prefix
|
= note: `mut` may be followed by `variable` and `variable @ pattern`

View File

@ -24,7 +24,9 @@ error[E0308]: mismatched types
--> $DIR/struct-path-self-type-mismatch.rs:13:9
|
LL | impl<T> Foo<T> {
| - found type parameter
| - ------ this is the type of the `Self` literal
| |
| found type parameter
LL | fn new<U>(u: U) -> Foo<U> {
| - ------ expected `Foo<U>` because of return type
| |
@ -40,6 +42,10 @@ LL | | }
found struct `Foo<T>`
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
help: use the type name directly
|
LL | Foo::<U> {
| ~~~~~~~~
error: aborting due to 3 previous errors