Skip to content

Commit 7e9a848

Browse files
committed
Small cleanup
* Add docstring to `Parser` field * Remove unnecessary `unwrap` * Remove unnecessary borrow * Fix indentation of some `teach`text output
1 parent db870ea commit 7e9a848

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

src/librustc_parse/parser/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ pub struct Parser<'a> {
104104
/// error.
105105
pub(super) unclosed_delims: Vec<UnmatchedBrace>,
106106
last_unexpected_token_span: Option<Span>,
107+
/// Span pointing at the `:` for the last type ascription the parser has seen, and whether it
108+
/// looked like it could have been a mistyped path or literal `Option:Some(42)`).
107109
pub last_type_ascription: Option<(Span, bool /* likely path typo */)>,
108110
/// If present, this `Parser` is not parsing Rust code but rather a macro call.
109111
subparser_name: Option<&'static str>,

src/librustc_resolve/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl<'a> PathSource<'a> {
226226
ValueNS => "method or associated constant",
227227
MacroNS => bug!("associated macro"),
228228
},
229-
PathSource::Expr(parent) => match &parent.as_ref().map(|p| &p.kind) {
229+
PathSource::Expr(parent) => match parent.as_ref().map(|p| &p.kind) {
230230
// "function" here means "anything callable" rather than `DefKind::Fn`,
231231
// this is not precise but usually more helpful than just "value".
232232
Some(ExprKind::Call(call_expr, _)) => match &call_expr.kind {

src/librustc_typeck/check/pat.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11141114
tcx.sess.struct_span_err(pat.span, "`..` cannot be used in union patterns").emit();
11151115
}
11161116
} else if !etc && !unmentioned_fields.is_empty() {
1117-
unmentioned_err = Some(self.error_unmentioned_fields(pat.span, &unmentioned_fields));
1117+
unmentioned_err = Some(self.error_unmentioned_fields(pat, &unmentioned_fields));
11181118
}
11191119
match (inexistent_fields_err, unmentioned_err) {
11201120
(Some(mut i), Some(mut u)) => {
@@ -1237,13 +1237,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12371237
if tcx.sess.teach(&err.get_code().unwrap()) {
12381238
err.note(
12391239
"This error indicates that a struct pattern attempted to \
1240-
extract a non-existent field from a struct. Struct fields \
1241-
are identified by the name used before the colon : so struct \
1242-
patterns should resemble the declaration of the struct type \
1243-
being matched.\n\n\
1244-
If you are using shorthand field patterns but want to refer \
1245-
to the struct field by a different name, you should rename \
1246-
it explicitly.",
1240+
extract a non-existent field from a struct. Struct fields \
1241+
are identified by the name used before the colon : so struct \
1242+
patterns should resemble the declaration of the struct type \
1243+
being matched.\n\n\
1244+
If you are using shorthand field patterns but want to refer \
1245+
to the struct field by a different name, you should rename \
1246+
it explicitly.",
12471247
);
12481248
}
12491249
err
@@ -1299,7 +1299,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12991299

13001300
fn error_unmentioned_fields(
13011301
&self,
1302-
span: Span,
1302+
pat: &Pat<'_>,
13031303
unmentioned_fields: &[Ident],
13041304
) -> DiagnosticBuilder<'tcx> {
13051305
let field_names = if unmentioned_fields.len() == 1 {
@@ -1312,23 +1312,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13121312
.join(", ");
13131313
format!("fields {}", fields)
13141314
};
1315-
let mut diag = struct_span_err!(
1315+
let mut err = struct_span_err!(
13161316
self.tcx.sess,
1317-
span,
1317+
pat.span,
13181318
E0027,
13191319
"pattern does not mention {}",
13201320
field_names
13211321
);
1322-
diag.span_label(span, format!("missing {}", field_names));
1323-
if self.tcx.sess.teach(&diag.get_code().unwrap()) {
1324-
diag.note(
1322+
err.span_label(pat.span, format!("missing {}", field_names));
1323+
if self.tcx.sess.teach(&err.get_code().unwrap()) {
1324+
err.note(
13251325
"This error indicates that a pattern for a struct fails to specify a \
1326-
sub-pattern for every one of the struct's fields. Ensure that each field \
1327-
from the struct's definition is mentioned in the pattern, or use `..` to \
1328-
ignore unwanted fields.",
1326+
sub-pattern for every one of the struct's fields. Ensure that each field \
1327+
from the struct's definition is mentioned in the pattern, or use `..` to \
1328+
ignore unwanted fields.",
13291329
);
13301330
}
1331-
diag
1331+
err
13321332
}
13331333

13341334
fn check_pat_box(

0 commit comments

Comments
 (0)