diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-12-28 13:59:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-28 13:59:25 +0100 |
| commit | 98c61b673e807a3f704dcc7b2ad81ebf99f3d7c4 (patch) | |
| tree | c92ae3f0b1c2395bd56409e235aebd4a9e845252 /compiler | |
| parent | 9aaa61b2264ab0e34a9ad683ba63d0ee5b9d2a9f (diff) | |
| parent | e37d012a0629a20ea9a79efc8434d636f37487d9 (diff) | |
| download | rust-98c61b673e807a3f704dcc7b2ad81ebf99f3d7c4.tar.gz rust-98c61b673e807a3f704dcc7b2ad81ebf99f3d7c4.zip | |
Rollup merge of #92333 - compiler-errors:elided-lifetime-spans, r=cjgillot
Tighten span when suggesting lifetime on path This is kind of a hack. Really the issue here is that we want to suggest the segment's span if the path resolves to something defined outside of the macro, and the macro's span if it resolves to something defined within.. I'll look into seeing if we can do something like that. Fixes #92324 r? `@cjgillot`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/path.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/late/diagnostics.rs | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 78afc339748..46928a18465 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -277,7 +277,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // See rustc_resolve::late::lifetimes::LifetimeContext::add_missing_lifetime_specifiers_label let elided_lifetime_span = if generic_args.span.is_empty() { // If there are no brackets, use the identifier span. - path_span + // HACK: we use find_ancestor_inside to properly suggest elided spans in paths + // originating from macros, since the segment's span might be from a macro arg. + segment.ident.span.find_ancestor_inside(path_span).unwrap_or(path_span) } else if generic_args.is_empty() { // If there are brackets, but not generic arguments, then use the opening bracket generic_args.span.with_hi(generic_args.span.lo() + BytePos(1)) diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index e74a7a95650..4cd1b34bedc 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -2115,10 +2115,13 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { let spans_suggs: Vec<_> = formatters .into_iter() .zip(spans_with_counts.iter()) - .filter_map(|(fmt, (span, _))| { - if let Some(formatter) = fmt { Some((formatter, span)) } else { None } + .filter_map(|(formatter, (span, _))| { + if let Some(formatter) = formatter { + Some((*span, formatter(name))) + } else { + None + } }) - .map(|(formatter, span)| (*span, formatter(name))) .collect(); if spans_suggs.is_empty() { // If all the spans come from macros, we cannot extract snippets and then |
