diff options
| author | bors <bors@rust-lang.org> | 2024-10-06 11:43:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-10-06 11:43:07 +0000 |
| commit | 96d9d8aa7de9396fe22702ff6df33816ae4d01b6 (patch) | |
| tree | 3e6361197c5c3ad473e23a54991a6da0afdd2160 /compiler/rustc_resolve/src | |
| parent | 68301a6a968326bac8b85b04d5ef7e79cc042a00 (diff) | |
| parent | dd09e9c74240fe7537cd55ddffb19b8162756a91 (diff) | |
| download | rust-96d9d8aa7de9396fe22702ff6df33816ae4d01b6.tar.gz rust-96d9d8aa7de9396fe22702ff6df33816ae4d01b6.zip | |
Auto merge of #131320 - matthiaskrgr:rollup-tom15b3, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #129392 (Do not consider match/let/ref of place that evaluates to `!` to diverge, disallow coercions from them too) - #131279 (update "build/host" symlink comment) - #131312 (On function and method calls in patterns, link to the book) - #131315 (bootstrap: add `std_features` config) - #131316 (Fix typo in primitive_docs.rs) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/late/diagnostics.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 35d166e8b4a..fce5ec36c66 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -443,6 +443,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { self.suggest_bare_struct_literal(&mut err); self.suggest_changing_type_to_const_param(&mut err, res, source, span); + self.explain_functions_in_pattern(&mut err, res, source); if self.suggest_pattern_match_with_let(&mut err, source, span) { // Fallback label. @@ -1166,6 +1167,18 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { } } + fn explain_functions_in_pattern( + &mut self, + err: &mut Diag<'_>, + res: Option<Res>, + source: PathSource<'_>, + ) { + let PathSource::TupleStruct(_, _) = source else { return }; + let Some(Res::Def(DefKind::Fn, _)) = res else { return }; + err.primary_message("expected a pattern, found a function call"); + err.note("function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>"); + } + fn suggest_changing_type_to_const_param( &mut self, err: &mut Diag<'_>, |
