Skip to content

Commit 7ad5f31

Browse files
committed
Make late_bound_lifetime_arguments a hard error.
1 parent f540a25 commit 7ad5f31

19 files changed

+221
-259
lines changed

compiler/rustc_hir_analysis/src/astconv/generics.rs

+16-23
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ use crate::astconv::{
66
use crate::errors::AssocTypeBindingNotAllowed;
77
use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs};
88
use rustc_ast::ast::ParamKindOrd;
9-
use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorGuaranteed, MultiSpan};
9+
use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorGuaranteed};
1010
use rustc_hir as hir;
1111
use rustc_hir::def::{DefKind, Res};
1212
use rustc_hir::def_id::DefId;
1313
use rustc_hir::GenericArg;
1414
use rustc_middle::ty::{
1515
self, subst, subst::SubstsRef, GenericParamDef, GenericParamDefKind, IsSuggestable, Ty, TyCtxt,
1616
};
17-
use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
1817
use rustc_span::{symbol::kw, Span};
1918
use smallvec::SmallVec;
2019

@@ -602,7 +601,6 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
602601
args: &hir::GenericArgs<'_>,
603602
position: GenericArgPosition,
604603
) -> ExplicitLateBound {
605-
let param_counts = def.own_counts();
606604
let infer_lifetimes = position != GenericArgPosition::Type && !args.has_lifetime_params();
607605

608606
if infer_lifetimes {
@@ -611,27 +609,22 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
611609

612610
if let Some(span_late) = def.has_late_bound_regions {
613611
let msg = "cannot specify lifetime arguments explicitly \
614-
if late bound lifetime parameters are present";
612+
if late bound lifetime parameters are present";
615613
let note = "the late bound lifetime parameter is introduced here";
616-
let span = args.args[0].span();
617-
618-
if position == GenericArgPosition::Value
619-
&& args.num_lifetime_params() != param_counts.lifetimes
620-
{
621-
let mut err = tcx.sess.struct_span_err(span, msg);
622-
err.span_note(span_late, note);
623-
err.emit();
624-
} else {
625-
let mut multispan = MultiSpan::from_span(span);
626-
multispan.push_span_label(span_late, note);
627-
tcx.struct_span_lint_hir(
628-
LATE_BOUND_LIFETIME_ARGUMENTS,
629-
args.args[0].hir_id(),
630-
multispan,
631-
msg,
632-
|lint| lint,
633-
);
634-
}
614+
let help = format!(
615+
"remove the explicit lifetime argument{}",
616+
rustc_errors::pluralize!(args.num_lifetime_params())
617+
);
618+
let spans: Vec<_> = args
619+
.args
620+
.iter()
621+
.filter_map(|arg| match arg {
622+
hir::GenericArg::Lifetime(l) => Some(l.ident.span),
623+
_ => None,
624+
})
625+
.collect();
626+
627+
tcx.sess.struct_span_err(spans, msg).span_note(span_late, note).help(help).emit();
635628

636629
ExplicitLateBound::Yes
637630
} else {

compiler/rustc_lint/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ fn register_builtins(store: &mut LintStore) {
504504
"converted into hard error, see issue #82523 \
505505
<https://github.com/rust-lang/rust/issues/82523> for more information",
506506
);
507+
store.register_removed(
508+
"late_bound_lifetime_arguments",
509+
"converted into hard error, see issue #42868 \
510+
<https://github.com/rust-lang/rust/issues/42868> for more information",
511+
);
507512
}
508513

509514
fn register_internals(store: &mut LintStore) {

compiler/rustc_lint_defs/src/builtin.rs

-42
Original file line numberDiff line numberDiff line change
@@ -1350,47 +1350,6 @@ declare_lint! {
13501350
};
13511351
}
13521352

1353-
declare_lint! {
1354-
/// The `late_bound_lifetime_arguments` lint detects generic lifetime
1355-
/// arguments in path segments with late bound lifetime parameters.
1356-
///
1357-
/// ### Example
1358-
///
1359-
/// ```rust
1360-
/// struct S;
1361-
///
1362-
/// impl S {
1363-
/// fn late(self, _: &u8, _: &u8) {}
1364-
/// }
1365-
///
1366-
/// fn main() {
1367-
/// S.late::<'static>(&0, &0);
1368-
/// }
1369-
/// ```
1370-
///
1371-
/// {{produces}}
1372-
///
1373-
/// ### Explanation
1374-
///
1375-
/// It is not clear how to provide arguments for early-bound lifetime
1376-
/// parameters if they are intermixed with late-bound parameters in the
1377-
/// same list. For now, providing any explicit arguments will trigger this
1378-
/// lint if late-bound parameters are present, so in the future a solution
1379-
/// can be adopted without hitting backward compatibility issues. This is
1380-
/// a [future-incompatible] lint to transition this to a hard error in the
1381-
/// future. See [issue #42868] for more details, along with a description
1382-
/// of the difference between early and late-bound parameters.
1383-
///
1384-
/// [issue #42868]: https://github.com/rust-lang/rust/issues/42868
1385-
/// [future-incompatible]: ../index.md#future-incompatible-lints
1386-
pub LATE_BOUND_LIFETIME_ARGUMENTS,
1387-
Warn,
1388-
"detects generic lifetime arguments in path segments with late bound lifetime parameters",
1389-
@future_incompatible = FutureIncompatibleInfo {
1390-
reference: "issue #42868 <https://github.com/rust-lang/rust/issues/42868>",
1391-
};
1392-
}
1393-
13941353
declare_lint! {
13951354
/// The `order_dependent_trait_objects` lint detects a trait coherency
13961355
/// violation that would allow creating two trait impls for the same
@@ -3266,7 +3225,6 @@ declare_lint_pass! {
32663225
CONST_ITEM_MUTATION,
32673226
PATTERNS_IN_FNS_WITHOUT_BODY,
32683227
MISSING_FRAGMENT_SPECIFIER,
3269-
LATE_BOUND_LIFETIME_ARGUMENTS,
32703228
ORDER_DEPENDENT_TRAIT_OBJECTS,
32713229
COHERENCE_LEAK_CHECK,
32723230
DEPRECATED,

tests/ui/const-generics/const-arg-in-const-arg.full.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ note: the late bound lifetime parameter is introduced here
99
|
1010
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
1111
| ^^
12+
= help: remove the explicit lifetime argument
1213

1314
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
1415
--> $DIR/const-arg-in-const-arg.rs:21:23
@@ -21,6 +22,7 @@ note: the late bound lifetime parameter is introduced here
2122
|
2223
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
2324
| ^^
25+
= help: remove the explicit lifetime argument
2426

2527
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
2628
--> $DIR/const-arg-in-const-arg.rs:41:24
@@ -33,6 +35,7 @@ note: the late bound lifetime parameter is introduced here
3335
|
3436
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
3537
| ^^
38+
= help: remove the explicit lifetime argument
3639

3740
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
3841
--> $DIR/const-arg-in-const-arg.rs:44:24
@@ -45,6 +48,7 @@ note: the late bound lifetime parameter is introduced here
4548
|
4649
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
4750
| ^^
51+
= help: remove the explicit lifetime argument
4852

4953
error: unconstrained generic constant
5054
--> $DIR/const-arg-in-const-arg.rs:13:12
@@ -105,6 +109,7 @@ note: the late bound lifetime parameter is introduced here
105109
|
106110
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
107111
| ^^
112+
= help: remove the explicit lifetime argument
108113

109114
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
110115
--> $DIR/const-arg-in-const-arg.rs:33:23
@@ -117,6 +122,7 @@ note: the late bound lifetime parameter is introduced here
117122
|
118123
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
119124
| ^^
125+
= help: remove the explicit lifetime argument
120126

121127
error: unconstrained generic constant
122128
--> $DIR/const-arg-in-const-arg.rs:47:19
@@ -145,6 +151,7 @@ note: the late bound lifetime parameter is introduced here
145151
|
146152
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
147153
| ^^
154+
= help: remove the explicit lifetime argument
148155

149156
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
150157
--> $DIR/const-arg-in-const-arg.rs:55:27
@@ -157,6 +164,7 @@ note: the late bound lifetime parameter is introduced here
157164
|
158165
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
159166
| ^^
167+
= help: remove the explicit lifetime argument
160168

161169
error: aborting due to 16 previous errors
162170

tests/ui/const-generics/const-arg-in-const-arg.min.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ note: the late bound lifetime parameter is introduced here
227227
|
228228
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
229229
| ^^
230+
= help: remove the explicit lifetime argument
230231

231232
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
232233
--> $DIR/const-arg-in-const-arg.rs:21:23
@@ -239,6 +240,7 @@ note: the late bound lifetime parameter is introduced here
239240
|
240241
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
241242
| ^^
243+
= help: remove the explicit lifetime argument
242244

243245
error[E0747]: unresolved item provided when a constant was expected
244246
--> $DIR/const-arg-in-const-arg.rs:38:24
@@ -262,6 +264,7 @@ note: the late bound lifetime parameter is introduced here
262264
|
263265
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
264266
| ^^
267+
= help: remove the explicit lifetime argument
265268

266269
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
267270
--> $DIR/const-arg-in-const-arg.rs:44:24
@@ -274,6 +277,7 @@ note: the late bound lifetime parameter is introduced here
274277
|
275278
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
276279
| ^^
280+
= help: remove the explicit lifetime argument
277281

278282
error: constant expression depends on a generic parameter
279283
--> $DIR/const-arg-in-const-arg.rs:25:17
@@ -305,6 +309,7 @@ note: the late bound lifetime parameter is introduced here
305309
|
306310
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
307311
| ^^
312+
= help: remove the explicit lifetime argument
308313

309314
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
310315
--> $DIR/const-arg-in-const-arg.rs:33:23
@@ -317,6 +322,7 @@ note: the late bound lifetime parameter is introduced here
317322
|
318323
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
319324
| ^^
325+
= help: remove the explicit lifetime argument
320326

321327
error[E0747]: unresolved item provided when a constant was expected
322328
--> $DIR/const-arg-in-const-arg.rs:49:27
@@ -340,6 +346,7 @@ note: the late bound lifetime parameter is introduced here
340346
|
341347
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
342348
| ^^
349+
= help: remove the explicit lifetime argument
343350

344351
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
345352
--> $DIR/const-arg-in-const-arg.rs:55:27
@@ -352,6 +359,7 @@ note: the late bound lifetime parameter is introduced here
352359
|
353360
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
354361
| ^^
362+
= help: remove the explicit lifetime argument
355363

356364
error: aborting due to 36 previous errors
357365

tests/ui/const-generics/issues/issue-83466.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ impl S {
99
}
1010
fn dont_crash<'a, U>() {
1111
S.func::<'a, 10_u32>()
12-
//~^ WARNING cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
13-
//~^^ WARNING this was previously accepted by
14-
//~^^^ ERROR constant provided when a type was expected [E0747]
12+
//~^ ERROR cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
13+
//~| ERROR constant provided when a type was expected [E0747]
1514
}
1615

1716
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
warning: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
1+
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
22
--> $DIR/issue-83466.rs:11:14
33
|
4-
LL | fn func<'a, U>(self) -> U {
5-
| -- the late bound lifetime parameter is introduced here
6-
...
74
LL | S.func::<'a, 10_u32>()
85
| ^^
96
|
10-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
11-
= note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
12-
= note: `#[warn(late_bound_lifetime_arguments)]` on by default
7+
note: the late bound lifetime parameter is introduced here
8+
--> $DIR/issue-83466.rs:6:13
9+
|
10+
LL | fn func<'a, U>(self) -> U {
11+
| ^^
12+
= help: remove the explicit lifetime argument
1313

1414
error[E0747]: constant provided when a type was expected
1515
--> $DIR/issue-83466.rs:11:18
1616
|
1717
LL | S.func::<'a, 10_u32>()
1818
| ^^^^^^
1919

20-
error: aborting due to previous error; 1 warning emitted
20+
error: aborting due to 2 previous errors
2121

2222
For more information about this error, try `rustc --explain E0747`.

tests/ui/issues/issue-60622.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ fn run_wild<T>(b: &Borked) {
1010
b.a::<'_, T>();
1111
//~^ ERROR cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
1212
//~| ERROR method takes 0 generic arguments but 1 generic argument
13-
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1413
}
1514

1615
fn main() {}

tests/ui/issues/issue-60622.stderr

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
22
--> $DIR/issue-60622.rs:10:11
33
|
4-
LL | fn a(&self) {}
5-
| - the late bound lifetime parameter is introduced here
6-
...
74
LL | b.a::<'_, T>();
85
| ^^
96
|
10-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
11-
= note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
12-
note: the lint level is defined here
13-
--> $DIR/issue-60622.rs:1:9
7+
note: the late bound lifetime parameter is introduced here
8+
--> $DIR/issue-60622.rs:6:10
149
|
15-
LL | #![deny(warnings)]
16-
| ^^^^^^^^
17-
= note: `#[deny(late_bound_lifetime_arguments)]` implied by `#[deny(warnings)]`
10+
LL | fn a(&self) {}
11+
| ^
12+
= help: remove the explicit lifetime argument
1813

1914
error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied
2015
--> $DIR/issue-60622.rs:10:7

tests/ui/issues/issue-72278.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// run-pass
2-
31
#![allow(unused)]
42

53
struct S;
@@ -12,8 +10,7 @@ impl S {
1210

1311
fn dont_crash<'a, U>() -> U {
1412
S.func::<'a, U>()
15-
//~^ WARN cannot specify lifetime arguments explicitly
16-
//~| WARN this was previously accepted
13+
//~^ ERROR cannot specify lifetime arguments explicitly
1714
}
1815

1916
fn main() {}

tests/ui/issues/issue-72278.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
warning: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
2-
--> $DIR/issue-72278.rs:14:14
1+
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
2+
--> $DIR/issue-72278.rs:12:14
33
|
4-
LL | fn func<'a, U>(&'a self) -> U {
5-
| -- the late bound lifetime parameter is introduced here
6-
...
74
LL | S.func::<'a, U>()
85
| ^^
96
|
10-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
11-
= note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
12-
= note: `#[warn(late_bound_lifetime_arguments)]` on by default
7+
note: the late bound lifetime parameter is introduced here
8+
--> $DIR/issue-72278.rs:6:13
9+
|
10+
LL | fn func<'a, U>(&'a self) -> U {
11+
| ^^
12+
= help: remove the explicit lifetime argument
1313

14-
warning: 1 warning emitted
14+
error: aborting due to previous error
1515

0 commit comments

Comments
 (0)