Show note for type ascription interpreted as a constant pattern, not a new variable
Given the code ```rust pub fn main() { const y: i32 = 4; let y: i32 = 3; } ``` `y` in the let binding is actually interpreted as a constant pattern and is not a new variable, causing confusing diagnostics about refutable patterns in local binding. This commit extends the note for type ascription as a constant pattern to `AscribeUserType` patterns as well.
This commit is contained in:
parent
9eee230cd0
commit
55b4549602
3 changed files with 46 additions and 1 deletions
|
@ -443,7 +443,12 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
|
|||
let mut let_suggestion = None;
|
||||
let mut misc_suggestion = None;
|
||||
let mut interpreted_as_const = None;
|
||||
if let PatKind::Constant { .. } = pat.kind
|
||||
|
||||
if let PatKind::Constant { .. }
|
||||
| PatKind::AscribeUserType {
|
||||
subpattern: box Pat { kind: PatKind::Constant { .. }, .. },
|
||||
..
|
||||
} = pat.kind
|
||||
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(pat.span)
|
||||
{
|
||||
// If the pattern to match is an integer literal:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue