Skip to content

Commit 72b6a91

Browse files
authored
Rollup merge of #91764 - cjgillot:elide-anyway, r=jackh726
Do not ICE when suggesting elided lifetimes on non-existent spans. Fixes #91763 r? `@jackh726`
2 parents 6c66d34 + 989d1de commit 72b6a91

File tree

6 files changed

+78
-21
lines changed

6 files changed

+78
-21
lines changed

compiler/rustc_lint/src/context.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ use ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
2222
use rustc_ast as ast;
2323
use rustc_data_structures::fx::FxHashMap;
2424
use rustc_data_structures::sync;
25-
use rustc_errors::{
26-
add_elided_lifetime_in_path_suggestion, struct_span_err, Applicability, SuggestionStyle,
27-
};
25+
use rustc_errors::{struct_span_err, Applicability, SuggestionStyle};
2826
use rustc_hir as hir;
2927
use rustc_hir::def::Res;
3028
use rustc_hir::def_id::{CrateNum, DefId};
@@ -670,23 +668,6 @@ pub trait LintContext: Sized {
670668
) => {
671669
db.span_note(span_def, "the macro is defined here");
672670
}
673-
BuiltinLintDiagnostics::ElidedLifetimesInPaths(
674-
n,
675-
path_span,
676-
incl_angl_brckt,
677-
insertion_span,
678-
anon_lts,
679-
) => {
680-
add_elided_lifetime_in_path_suggestion(
681-
sess.source_map(),
682-
&mut db,
683-
n,
684-
path_span,
685-
incl_angl_brckt,
686-
insertion_span,
687-
anon_lts,
688-
);
689-
}
690671
BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => {
691672
db.span_suggestion(span, &note, sugg, Applicability::MaybeIncorrect);
692673
}

compiler/rustc_lint_defs/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ pub enum BuiltinLintDiagnostics {
289289
AbsPathWithModule(Span),
290290
ProcMacroDeriveResolutionFallback(Span),
291291
MacroExpandedMacroExportsAccessedByAbsolutePaths(Span),
292-
ElidedLifetimesInPaths(usize, Span, bool, Span, String),
293292
UnknownCrateTypes(Span, String, String),
294293
UnusedImports(String, Vec<(Span, String)>),
295294
RedundantImport(Vec<(Span, bool)>, Ident),

compiler/rustc_resolve/src/late/diagnostics.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2115,6 +2115,11 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
21152115
})
21162116
.map(|(formatter, span)| (*span, formatter(name)))
21172117
.collect();
2118+
if spans_suggs.is_empty() {
2119+
// If all the spans come from macros, we cannot extract snippets and then
2120+
// `formatters` only contains None and `spans_suggs` is empty.
2121+
return;
2122+
}
21182123
err.multipart_suggestion_verbose(
21192124
&format!(
21202125
"consider using the `{}` lifetime",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
//#![feature(proc_macro_diagnostic, proc_macro_span, proc_macro_def_site)]
7+
8+
extern crate proc_macro;
9+
10+
use proc_macro::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
11+
use std::iter::FromIterator;
12+
13+
#[proc_macro_attribute]
14+
pub fn repro(_args: TokenStream, input: TokenStream) -> TokenStream {
15+
let call_site = Span::call_site();
16+
let span = input.into_iter().nth(8).unwrap().span();
17+
18+
//fn f(_: &::std::fmt::Formatter) {}
19+
TokenStream::from_iter([
20+
TokenTree::Ident(Ident::new("fn", call_site)),
21+
TokenTree::Ident(Ident::new("f", call_site)),
22+
TokenTree::Group(Group::new(
23+
Delimiter::Parenthesis,
24+
TokenStream::from_iter([
25+
TokenTree::Ident(Ident::new("_", call_site)),
26+
TokenTree::Punct(punct(':', Spacing::Alone, call_site)),
27+
TokenTree::Punct(punct('&', Spacing::Alone, call_site)),
28+
TokenTree::Punct(punct(':', Spacing::Joint, span)),
29+
TokenTree::Punct(punct(':', Spacing::Alone, span)),
30+
TokenTree::Ident(Ident::new("std", span)),
31+
TokenTree::Punct(punct(':', Spacing::Joint, span)),
32+
TokenTree::Punct(punct(':', Spacing::Alone, span)),
33+
TokenTree::Ident(Ident::new("fmt", span)),
34+
TokenTree::Punct(punct(':', Spacing::Joint, span)),
35+
TokenTree::Punct(punct(':', Spacing::Alone, span)),
36+
TokenTree::Ident(Ident::new("Formatter", span)),
37+
]),
38+
)),
39+
TokenTree::Group(Group::new(Delimiter::Brace, TokenStream::new())),
40+
])
41+
}
42+
43+
fn punct(ch: char, spacing: Spacing, span: Span) -> Punct {
44+
let mut punct = Punct::new(ch, spacing);
45+
punct.set_span(span);
46+
punct
47+
}

src/test/ui/lifetimes/issue-91763.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// aux-build:issue-91763-aux.rs
2+
3+
#![deny(elided_lifetimes_in_paths)]
4+
5+
extern crate issue_91763_aux;
6+
7+
#[issue_91763_aux::repro]
8+
fn f() -> Ptr<Thing>;
9+
//~^ ERROR hidden lifetime parameters in types are deprecated
10+
11+
fn main() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: hidden lifetime parameters in types are deprecated
2+
--> $DIR/issue-91763.rs:8:20
3+
|
4+
LL | fn f() -> Ptr<Thing>;
5+
| ^ expected named lifetime parameter
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-91763.rs:3:9
9+
|
10+
LL | #![deny(elided_lifetimes_in_paths)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)