Do not lower generic lifetime params when AST resolution emitted an error.
This commit is contained in:
parent
a265c49b25
commit
c75409d5e4
@ -1917,14 +1917,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
fn lower_generic_param(&mut self, param: &GenericParam) -> hir::GenericParam<'hir> {
|
||||
let (name, kind) = match param.kind {
|
||||
GenericParamKind::Lifetime => {
|
||||
let param_name = if param.ident.name == kw::StaticLifetime
|
||||
|| param.ident.name == kw::UnderscoreLifetime
|
||||
{
|
||||
ParamName::Error
|
||||
} else {
|
||||
let ident = self.lower_ident(param.ident);
|
||||
ParamName::Plain(ident)
|
||||
};
|
||||
// AST resolution emitted an error on those parameters, so we lower them using
|
||||
// `ParamName::Error`.
|
||||
let param_name =
|
||||
if let Some(LifetimeRes::Error) = self.resolver.get_lifetime_res(param.id) {
|
||||
ParamName::Error
|
||||
} else {
|
||||
let ident = self.lower_ident(param.ident);
|
||||
ParamName::Plain(ident)
|
||||
};
|
||||
let kind =
|
||||
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
|
||||
|
||||
@ -1949,10 +1950,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
)
|
||||
}
|
||||
};
|
||||
let name = match name {
|
||||
hir::ParamName::Plain(ident) => hir::ParamName::Plain(self.lower_ident(ident)),
|
||||
name => name,
|
||||
};
|
||||
|
||||
let hir_id = self.lower_node_id(param.id);
|
||||
self.lower_attrs(hir_id, ¶m.attrs);
|
||||
|
@ -1939,6 +1939,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
param.ident,
|
||||
orig_is_param,
|
||||
);
|
||||
// Record lifetime res, so lowering knows there is something fishy.
|
||||
self.record_lifetime_res(param.id, LifetimeRes::Error);
|
||||
continue;
|
||||
}
|
||||
Entry::Vacant(entry) => {
|
||||
entry.insert(true);
|
||||
@ -1966,6 +1969,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
)
|
||||
.span_label(param.ident.span, "`'_` is a reserved lifetime name")
|
||||
.emit();
|
||||
// Record lifetime res, so lowering knows there is something fishy.
|
||||
self.record_lifetime_res(param.id, LifetimeRes::Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1979,6 +1984,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
)
|
||||
.span_label(param.ident.span, "'static is a reserved lifetime name")
|
||||
.emit();
|
||||
// Record lifetime res, so lowering knows there is something fishy.
|
||||
self.record_lifetime_res(param.id, LifetimeRes::Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
struct Foo<'a, 'a> {
|
||||
//~^ ERROR lifetime name `'a` declared twice
|
||||
//~| ERROR parameter `'a` is never used [E0392]
|
||||
x: &'a isize,
|
||||
}
|
||||
|
||||
|
@ -6,15 +6,6 @@ LL | struct Foo<'a, 'a> {
|
||||
| |
|
||||
| first declared here
|
||||
|
||||
error[E0392]: parameter `'a` is never used
|
||||
--> $DIR/regions-name-duplicated.rs:1:12
|
||||
|
|
||||
LL | struct Foo<'a, 'a> {
|
||||
| ^^ unused parameter
|
||||
|
|
||||
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`
|
||||
error: aborting due to previous error
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0263, E0392.
|
||||
For more information about an error, try `rustc --explain E0263`.
|
||||
For more information about this error, try `rustc --explain E0263`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user