Skip to content

Commit fc9f255

Browse files
committed
Report undeclared lifetimes on AST.
1 parent 4cfceea commit fc9f255

File tree

5 files changed

+837
-400
lines changed

5 files changed

+837
-400
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+6-19
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ enum ParenthesizedGenericArgs {
484484
/// an "elided" or "underscore" lifetime name. In the future, we probably want to move
485485
/// everything into HIR lowering.
486486
#[derive(Copy, Clone, Debug)]
487-
enum AnonymousLifetimeMode {
487+
pub enum AnonymousLifetimeMode {
488488
/// For **Modern** cases, create a new anonymous region parameter
489489
/// and reference that.
490490
///
@@ -2017,16 +2017,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20172017
});
20182018
let param_name = match lt.name {
20192019
hir::LifetimeName::Param(param_name) => param_name,
2020-
hir::LifetimeName::Implicit(_)
2021-
| hir::LifetimeName::Underscore
2022-
| hir::LifetimeName::Static => hir::ParamName::Plain(lt.name.ident()),
2020+
hir::LifetimeName::Implicit(_) | hir::LifetimeName::Underscore => {
2021+
hir::ParamName::Plain(lt.name.ident())
2022+
}
20232023
hir::LifetimeName::ImplicitObjectLifetimeDefault => {
20242024
self.sess.diagnostic().span_bug(
20252025
param.ident.span,
20262026
"object-lifetime-default should not occur here",
20272027
);
20282028
}
2029-
hir::LifetimeName::Error => ParamName::Error,
2029+
hir::LifetimeName::Static | hir::LifetimeName::Error => ParamName::Error,
20302030
};
20312031

20322032
let kind =
@@ -2404,20 +2404,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24042404
/// Report an error on illegal use of `'_` or a `&T` with no explicit lifetime;
24052405
/// return an "error lifetime".
24062406
fn new_error_lifetime(&mut self, id: Option<NodeId>, span: Span) -> hir::Lifetime {
2407-
let (id, msg, label) = match id {
2408-
Some(id) => (id, "`'_` cannot be used here", "`'_` is a reserved lifetime name"),
2409-
2410-
None => (
2411-
self.resolver.next_node_id(),
2412-
"`&` without an explicit lifetime name cannot be used here",
2413-
"explicit lifetime name needed here",
2414-
),
2415-
};
2416-
2417-
let mut err = struct_span_err!(self.sess, span, E0637, "{}", msg,);
2418-
err.span_label(span, label);
2419-
err.emit();
2420-
2407+
let id = id.unwrap_or_else(|| self.resolver.next_node_id());
24212408
self.new_named_lifetime(id, span, hir::LifetimeName::Error)
24222409
}
24232410

0 commit comments

Comments
 (0)