Skip to content

Commit 2c55902

Browse files
committed
add_elided_lifetime_in_path_suggestion -> rustc_session
1 parent e0403bc commit 2c55902

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

src/librustc/lint.rs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cmp;
33
use crate::ich::StableHashingContext;
44
use rustc_data_structures::fx::FxHashMap;
55
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
6-
use rustc_errors::{pluralize, Applicability, DiagnosticBuilder, DiagnosticId};
6+
use rustc_errors::{DiagnosticBuilder, DiagnosticId};
77
use rustc_hir::HirId;
88
use rustc_session::lint::{builtin, Level, Lint, LintId};
99
use rustc_session::{DiagnosticMessageId, Session};
@@ -350,45 +350,3 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
350350
ExpnKind::Macro(..) => true, // definitely a plugin
351351
}
352352
}
353-
354-
pub fn add_elided_lifetime_in_path_suggestion(
355-
sess: &Session,
356-
db: &mut DiagnosticBuilder<'_>,
357-
n: usize,
358-
path_span: Span,
359-
incl_angl_brckt: bool,
360-
insertion_span: Span,
361-
anon_lts: String,
362-
) {
363-
let (replace_span, suggestion) = if incl_angl_brckt {
364-
(insertion_span, anon_lts)
365-
} else {
366-
// When possible, prefer a suggestion that replaces the whole
367-
// `Path<T>` expression with `Path<'_, T>`, rather than inserting `'_, `
368-
// at a point (which makes for an ugly/confusing label)
369-
if let Ok(snippet) = sess.source_map().span_to_snippet(path_span) {
370-
// But our spans can get out of whack due to macros; if the place we think
371-
// we want to insert `'_` isn't even within the path expression's span, we
372-
// should bail out of making any suggestion rather than panicking on a
373-
// subtract-with-overflow or string-slice-out-out-bounds (!)
374-
// FIXME: can we do better?
375-
if insertion_span.lo().0 < path_span.lo().0 {
376-
return;
377-
}
378-
let insertion_index = (insertion_span.lo().0 - path_span.lo().0) as usize;
379-
if insertion_index > snippet.len() {
380-
return;
381-
}
382-
let (before, after) = snippet.split_at(insertion_index);
383-
(path_span, format!("{}{}{}", before, anon_lts, after))
384-
} else {
385-
(insertion_span, anon_lts)
386-
}
387-
};
388-
db.span_suggestion(
389-
replace_span,
390-
&format!("indicate the anonymous lifetime{}", pluralize!(n)),
391-
suggestion,
392-
Applicability::MachineApplicable,
393-
);
394-
}

src/librustc_ast_lowering/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
306306
E0726,
307307
"implicit elided lifetime not allowed here"
308308
);
309-
rustc::lint::add_elided_lifetime_in_path_suggestion(
309+
rustc_session::lint::add_elided_lifetime_in_path_suggestion(
310310
&self.sess,
311311
&mut err,
312312
expected_lifetimes,

src/librustc_lint/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use self::TargetLint::*;
1919
use crate::levels::LintLevelsBuilder;
2020
use crate::passes::{EarlyLintPassObject, LateLintPassObject};
2121
use rustc::hir::map::definitions::{DefPathData, DisambiguatedDefPathData};
22-
use rustc::lint::add_elided_lifetime_in_path_suggestion;
2322
use rustc::lint::LintDiagnosticBuilder;
2423
use rustc::middle::privacy::AccessLevels;
2524
use rustc::middle::stability;
@@ -32,7 +31,7 @@ use rustc_data_structures::sync;
3231
use rustc_errors::{struct_span_err, Applicability};
3332
use rustc_hir as hir;
3433
use rustc_hir::def_id::{CrateNum, DefId};
35-
use rustc_session::lint::BuiltinLintDiagnostics;
34+
use rustc_session::lint::{add_elided_lifetime_in_path_suggestion, BuiltinLintDiagnostics};
3635
use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintBuffer, LintId};
3736
use rustc_session::Session;
3837
use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP};

src/librustc_session/lint.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub use self::Level::*;
22
use rustc_ast::node_id::{NodeId, NodeMap};
33
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
4+
use rustc_errors::{pluralize, Applicability, DiagnosticBuilder};
45
use rustc_span::edition::Edition;
56
use rustc_span::{sym, symbol::Ident, MultiSpan, Span, Symbol};
67

@@ -367,3 +368,45 @@ macro_rules! declare_lint_pass {
367368
$crate::impl_lint_pass!($name => [$($lint),*]);
368369
};
369370
}
371+
372+
pub fn add_elided_lifetime_in_path_suggestion(
373+
sess: &crate::Session,
374+
db: &mut DiagnosticBuilder<'_>,
375+
n: usize,
376+
path_span: Span,
377+
incl_angl_brckt: bool,
378+
insertion_span: Span,
379+
anon_lts: String,
380+
) {
381+
let (replace_span, suggestion) = if incl_angl_brckt {
382+
(insertion_span, anon_lts)
383+
} else {
384+
// When possible, prefer a suggestion that replaces the whole
385+
// `Path<T>` expression with `Path<'_, T>`, rather than inserting `'_, `
386+
// at a point (which makes for an ugly/confusing label)
387+
if let Ok(snippet) = sess.source_map().span_to_snippet(path_span) {
388+
// But our spans can get out of whack due to macros; if the place we think
389+
// we want to insert `'_` isn't even within the path expression's span, we
390+
// should bail out of making any suggestion rather than panicking on a
391+
// subtract-with-overflow or string-slice-out-out-bounds (!)
392+
// FIXME: can we do better?
393+
if insertion_span.lo().0 < path_span.lo().0 {
394+
return;
395+
}
396+
let insertion_index = (insertion_span.lo().0 - path_span.lo().0) as usize;
397+
if insertion_index > snippet.len() {
398+
return;
399+
}
400+
let (before, after) = snippet.split_at(insertion_index);
401+
(path_span, format!("{}{}{}", before, anon_lts, after))
402+
} else {
403+
(insertion_span, anon_lts)
404+
}
405+
};
406+
db.span_suggestion(
407+
replace_span,
408+
&format!("indicate the anonymous lifetime{}", pluralize!(n)),
409+
suggestion,
410+
Applicability::MachineApplicable,
411+
);
412+
}

0 commit comments

Comments
 (0)