Skip to content

Commit 9208741

Browse files
committed
Fix ICE & bless the remaining tests
1 parent bdcb628 commit 9208741

File tree

7 files changed

+41
-11
lines changed

7 files changed

+41
-11
lines changed

compiler/rustc_resolve/src/late.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,9 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
702702

703703
/// We need some "real" `NodeId` to emit
704704
/// [`elided_named_lifetimes`](lint::builtin::ELIDED_NAMED_LIFETIMES).
705-
/// See comments in [`MissingLifetime::id_if_not_fake_or`].
705+
/// See comments in [`MissingLifetime::id_if_exists_in_source_or`].
706706
crate_node_id: NodeId,
707+
707708
/// Don't emit [`elided_named_lifetimes`](lint::builtin::ELIDED_NAMED_LIFETIMES)
708709
/// when we are in a type annotation for a `const` or `static`.
709710
/// ```rust
@@ -2072,7 +2073,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20722073
if self.warn_elided_static {
20732074
self.r.lint_buffer.buffer_lint(
20742075
lint::builtin::ELIDED_NAMED_LIFETIMES,
2075-
missing.id_if_not_fake_or(self.crate_node_id),
2076+
missing.id_if_exists_in_source_or(self.crate_node_id),
20762077
missing.span,
20772078
BuiltinLintDiag::ElidedIsStatic { elided },
20782079
);
@@ -2086,7 +2087,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20862087
// but `binder` sounds like a more appropriate place than the crate,
20872088
// and to convert `param` from `LocalDefId` to `NodeId`,
20882089
// we would have to do some additional work.
2089-
missing.id_if_not_fake_or(binder),
2090+
missing.id_if_exists_in_source_or(binder),
20902091
missing.span,
20912092
BuiltinLintDiag::ElidedIsParam { elided, param },
20922093
);

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ impl MissingLifetime {
117117
/// in a sense that they are temporary and not get preserved down the line,
118118
/// which means that the lints for those nodes will not get emitted.
119119
/// To combat this, we can try to use some other `NodeId`s as a fallback option.
120-
pub(super) fn id_if_not_fake_or(self, fallback: NodeId) -> NodeId {
120+
pub(super) fn id_if_exists_in_source_or(self, fallback: NodeId) -> NodeId {
121121
match self.kind {
122-
MissingLifetimeKind::Underscore
123-
| MissingLifetimeKind::Comma
124-
| MissingLifetimeKind::Brackets => self.id,
125-
MissingLifetimeKind::Ampersand => fallback,
122+
MissingLifetimeKind::Underscore => self.id,
123+
MissingLifetimeKind::Ampersand
124+
| MissingLifetimeKind::Brackets
125+
| MissingLifetimeKind::Comma => fallback,
126126
}
127127
}
128128
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: elided lifetime has a name
2+
--> $DIR/issue-71348.rs:18:68
3+
|
4+
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target
5+
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
6+
|
7+
= note: `#[warn(elided_named_lifetimes)]` on by default
8+
9+
warning: 1 warning emitted
10+

tests/ui/const-generics/type-dependent/issue-71348.min.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
warning: elided lifetime has a name
2+
--> $DIR/issue-71348.rs:18:68
3+
|
4+
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target
5+
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
6+
|
7+
= note: `#[warn(elided_named_lifetimes)]` on by default
8+
19
error: `&'static str` is forbidden as the type of a const generic parameter
210
--> $DIR/issue-71348.rs:10:24
311
|
@@ -30,5 +38,5 @@ help: add `#![feature(unsized_const_params)]` to the crate attributes to enable
3038
LL + #![feature(unsized_const_params)]
3139
|
3240

33-
error: aborting due to 2 previous errors
41+
error: aborting due to 2 previous errors; 1 warning emitted
3442

tests/ui/const-generics/type-dependent/issue-71348.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ trait Get<'a, const N: &'static str> {
1717
impl Foo {
1818
fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target
1919
//[min]~^ ERROR `&'static str` is forbidden as the type of a const generic parameter
20+
//~^^ WARNING elided lifetime has a name
2021
where
2122
Self: Get<'a, N>,
2223
{

tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
type Opaque2<T> = impl Sized;
44
type Opaque<'a, T> = Opaque2<T>;
5-
fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x }
5+
fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x } //~ WARNING elided lifetime has a name
66
//~^ ERROR: hidden type for `Opaque2<T>` captures lifetime that does not appear in bounds
77

88
fn main() {}

tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
warning: elided lifetime has a name
2+
--> $DIR/missing_lifetime_bound.rs:5:41
3+
|
4+
LL | fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x }
5+
| -- ^ this elided lifetime gets resolved as `'a`
6+
| |
7+
| lifetime `'a` declared here
8+
|
9+
= note: `#[warn(elided_named_lifetimes)]` on by default
10+
111
error[E0700]: hidden type for `Opaque2<T>` captures lifetime that does not appear in bounds
212
--> $DIR/missing_lifetime_bound.rs:5:47
313
|
@@ -9,6 +19,6 @@ LL | fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x }
919
| |
1020
| hidden type `&'a i32` captures the lifetime `'a` as defined here
1121

12-
error: aborting due to 1 previous error
22+
error: aborting due to 1 previous error; 1 warning emitted
1323

1424
For more information about this error, try `rustc --explain E0700`.

0 commit comments

Comments
 (0)