Use span_label
as it looks better when we show pattern missing binding in order
This commit is contained in:
parent
8c8e8d35bc
commit
733fd03f0f
3 changed files with 10 additions and 39 deletions
|
@ -1129,7 +1129,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||
) {
|
||||
let [segment] = path else { return };
|
||||
let None = following_seg else { return };
|
||||
'outer: for rib in self.ribs[ValueNS].iter().rev() {
|
||||
for rib in self.ribs[ValueNS].iter().rev() {
|
||||
for (def_id, spans) in &rib.patterns_with_skipped_bindings {
|
||||
if let Some(fields) = self.r.field_idents(*def_id) {
|
||||
for field in fields {
|
||||
|
@ -1141,23 +1141,14 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||
spans.iter().map(|(s, _)| *s).collect::<Vec<_>>().into();
|
||||
err.span_note(
|
||||
multispan,
|
||||
"this pattern had a recovered parse error which likely \
|
||||
lost the expected fields",
|
||||
"this pattern had a recovered parse error which likely lost \
|
||||
the expected fields",
|
||||
);
|
||||
err.downgrade_to_delayed_bug();
|
||||
}
|
||||
let mut multispan: MultiSpan = spans
|
||||
.iter()
|
||||
.filter(|(_, had_error)| had_error.is_ok())
|
||||
.map(|(sp, _)| *sp)
|
||||
.collect::<Vec<_>>()
|
||||
.into();
|
||||
let def_span = self.r.def_span(*def_id);
|
||||
let ty = self.r.tcx.item_name(*def_id);
|
||||
multispan.push_span_label(def_span, String::new());
|
||||
multispan.push_span_label(field.span, "defined here".to_string());
|
||||
for (span, _) in spans.iter().filter(|(_, had_err)| had_err.is_ok()) {
|
||||
multispan.push_span_label(
|
||||
for (span, _) in spans {
|
||||
err.span_label(
|
||||
*span,
|
||||
format!(
|
||||
"this pattern doesn't include `{field}`, which is \
|
||||
|
@ -1165,14 +1156,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||
),
|
||||
);
|
||||
}
|
||||
err.span_note(
|
||||
multispan,
|
||||
format!(
|
||||
"`{ty}` has a field `{field}` which could have been included \
|
||||
in this pattern, but it wasn't",
|
||||
),
|
||||
);
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
struct Website {
|
||||
url: String,
|
||||
title: Option<String> ,//~ NOTE defined here
|
||||
title: Option<String>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -14,8 +14,7 @@ fn main() {
|
|||
println!("[{}]({})", title, url); // we hide the errors for `title` and `url`
|
||||
}
|
||||
|
||||
if let Website { url, .. } = website { //~ NOTE `Website` has a field `title`
|
||||
//~^ NOTE this pattern
|
||||
if let Website { url, .. } = website { //~ NOTE this pattern
|
||||
println!("[{}]({})", title, url); //~ ERROR cannot find value `title` in this scope
|
||||
//~^ NOTE not found in this scope
|
||||
}
|
||||
|
|
|
@ -7,23 +7,12 @@ LL | if let Website { url, Some(title) } = website {
|
|||
| while parsing the fields for this pattern
|
||||
|
||||
error[E0425]: cannot find value `title` in this scope
|
||||
--> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:19:30
|
||||
--> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:18:30
|
||||
|
|
||||
LL | if let Website { url, .. } = website {
|
||||
| ------------------- this pattern doesn't include `title`, which is available in `Website`
|
||||
LL | println!("[{}]({})", title, url);
|
||||
| ^^^^^ not found in this scope
|
||||
|
|
||||
note: `Website` has a field `title` which could have been included in this pattern, but it wasn't
|
||||
--> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:17:12
|
||||
|
|
||||
LL | / struct Website {
|
||||
LL | | url: String,
|
||||
LL | | title: Option<String> ,
|
||||
| | ----- defined here
|
||||
LL | | }
|
||||
| |_-
|
||||
...
|
||||
LL | if let Website { url, .. } = website {
|
||||
| ^^^^^^^^^^^^^^^^^^^ this pattern doesn't include `title`, which is available in `Website`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue