Skip to content

Commit e0ade8e

Browse files
authored
Unrolled build for rust-lang#125913
Rollup merge of rust-lang#125913 - fmease:early-lints-spruce-up-some-diags, r=Nadrieril Spruce up the diagnostics of some early lints Implement the various "*(note to myself) in a follow-up PR we should turn parts of this message into a subdiagnostic (help msg or even struct sugg)*" drive-by comments I left in rust-lang#124417 during my review. For context, before rust-lang#124417, only a few early lints touched/decorated/customized their diagnostic because the former API made it a bit awkward. Likely because of that, things that should've been subdiagnostics were just crammed into the primary message. This PR rectifies this.
2 parents 336e6ab + b2949ff commit e0ade8e

32 files changed

+83
-51
lines changed

compiler/rustc_expand/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ expand_unsupported_key_value =
157157
key-value macro attributes are not supported
158158
159159
expand_var_still_repeating =
160-
variable '{$ident}' is still repeating at this depth
160+
variable `{$ident}` is still repeating at this depth
161161
162162
expand_wrong_fragment_kind =
163163
non-{$kind} macro in {$kind} position: {$name}

compiler/rustc_lint/messages.ftl

+7-5
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,8 @@ lint_macro_is_private = macro `{$ident}` is private
445445
lint_macro_rule_never_used = rule #{$n} of macro `{$name}` is never used
446446
447447
lint_macro_use_deprecated =
448-
deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
448+
applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
449+
.help = remove it and import macros at use sites with a `use` item instead
449450
450451
lint_malformed_attribute = malformed lint attribute input
451452
@@ -456,7 +457,7 @@ lint_map_unit_fn = `Iterator::map` call that discard the iterator's values
456457
.map_label = after this call to map, the resulting iterator is `impl Iterator<Item = ()>`, which means the only information carried by the iterator is the number of items
457458
.suggestion = you might have meant to use `Iterator::for_each`
458459
459-
lint_metavariable_still_repeating = variable '{$name}' is still repeating at this depth
460+
lint_metavariable_still_repeating = variable `{$name}` is still repeating at this depth
460461
461462
lint_metavariable_wrong_operator = meta-variable repeats with different Kleene operator
462463
@@ -635,8 +636,8 @@ lint_pattern_in_bodiless = patterns aren't allowed in functions without bodies
635636
lint_pattern_in_foreign = patterns aren't allowed in foreign function declarations
636637
.label = pattern not allowed in foreign function
637638
638-
lint_private_extern_crate_reexport =
639-
extern crate `{$ident}` is private, and cannot be re-exported, consider declaring with `pub`
639+
lint_private_extern_crate_reexport = extern crate `{$ident}` is private and cannot be re-exported
640+
.suggestion = consider making the `extern crate` item publicly accessible
640641
641642
lint_proc_macro_derive_resolution_fallback = cannot find {$ns} `{$ident}` in this scope
642643
.label = names from parent modules are not accessible without an explicit import
@@ -847,7 +848,8 @@ lint_unused_coroutine =
847848
}{$post} that must be used
848849
.note = coroutines are lazy and do nothing unless resumed
849850
850-
lint_unused_crate_dependency = external crate `{$extern_crate}` unused in `{$local_crate}`: remove the dependency or add `use {$extern_crate} as _;`
851+
lint_unused_crate_dependency = extern crate `{$extern_crate}` is unused in crate `{$local_crate}`
852+
.help = remove the dependency or add `use {$extern_crate} as _;` to the crate root
851853
852854
lint_unused_def = unused {$pre}`{$def}`{$post} that must be used
853855
.suggestion = use `let _ = ...` to ignore the resulting value

compiler/rustc_lint/src/context/diagnostics.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
340340
lints::MacroUseDeprecated.decorate_lint(diag);
341341
}
342342
BuiltinLintDiag::UnusedMacroUse => lints::UnusedMacroUse.decorate_lint(diag),
343-
BuiltinLintDiag::PrivateExternCrateReexport(ident) => {
344-
lints::PrivateExternCrateReexport { ident }.decorate_lint(diag);
343+
BuiltinLintDiag::PrivateExternCrateReexport { source: ident, extern_crate_span } => {
344+
lints::PrivateExternCrateReexport { ident, sugg: extern_crate_span.shrink_to_lo() }
345+
.decorate_lint(diag);
345346
}
346347
BuiltinLintDiag::UnusedLabel => lints::UnusedLabel.decorate_lint(diag),
347348
BuiltinLintDiag::MacroIsPrivate(ident) => {

compiler/rustc_lint/src/lints.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,7 @@ pub mod unexpected_cfg_value {
23132313

23142314
#[derive(LintDiagnostic)]
23152315
#[diag(lint_macro_use_deprecated)]
2316+
#[help]
23162317
pub struct MacroUseDeprecated;
23172318

23182319
#[derive(LintDiagnostic)]
@@ -2323,6 +2324,8 @@ pub struct UnusedMacroUse;
23232324
#[diag(lint_private_extern_crate_reexport, code = E0365)]
23242325
pub struct PrivateExternCrateReexport {
23252326
pub ident: Ident,
2327+
#[suggestion(code = "pub ", style = "verbose", applicability = "maybe-incorrect")]
2328+
pub sugg: Span,
23262329
}
23272330

23282331
#[derive(LintDiagnostic)]
@@ -2416,6 +2419,7 @@ pub struct UnknownMacroVariable {
24162419

24172420
#[derive(LintDiagnostic)]
24182421
#[diag(lint_unused_crate_dependency)]
2422+
#[help]
24192423
pub struct UnusedCrateDependency {
24202424
pub extern_crate: Symbol,
24212425
pub local_crate: Symbol,

compiler/rustc_lint_defs/src/builtin.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,9 @@ declare_lint! {
511511
/// This will produce:
512512
///
513513
/// ```text
514-
/// error: external crate `regex` unused in `lint_example`: remove the dependency or add `use regex as _;`
514+
/// error: extern crate `regex` is unused in crate `lint_example`
515515
/// |
516+
/// = help: remove the dependency or add `use regex as _;` to the crate root
516517
/// note: the lint level is defined here
517518
/// --> src/lib.rs:1:9
518519
/// |
@@ -2160,8 +2161,7 @@ declare_lint! {
21602161
}
21612162

21622163
declare_lint! {
2163-
/// The `macro_use_extern_crate` lint detects the use of the
2164-
/// [`macro_use` attribute].
2164+
/// The `macro_use_extern_crate` lint detects the use of the [`macro_use` attribute].
21652165
///
21662166
/// ### Example
21672167
///
@@ -2179,12 +2179,13 @@ declare_lint! {
21792179
/// This will produce:
21802180
///
21812181
/// ```text
2182-
/// error: deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
2182+
/// error: applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
21832183
/// --> src/main.rs:3:1
21842184
/// |
21852185
/// 3 | #[macro_use]
21862186
/// | ^^^^^^^^^^^^
21872187
/// |
2188+
/// = help: remove it and import macros at use sites with a `use` item instead
21882189
/// note: the lint level is defined here
21892190
/// --> src/main.rs:1:9
21902191
/// |

compiler/rustc_lint_defs/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,10 @@ pub enum BuiltinLintDiag {
706706
},
707707
MacroUseDeprecated,
708708
UnusedMacroUse,
709-
PrivateExternCrateReexport(Ident),
709+
PrivateExternCrateReexport {
710+
source: Ident,
711+
extern_crate_span: Span,
712+
},
710713
UnusedLabel,
711714
MacroIsPrivate(Ident),
712715
UnusedMacroDefinition(Symbol),

compiler/rustc_resolve/src/imports.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,18 @@ struct UnresolvedImportError {
259259

260260
// Reexports of the form `pub use foo as bar;` where `foo` is `extern crate foo;`
261261
// are permitted for backward-compatibility under a deprecation lint.
262-
fn pub_use_of_private_extern_crate_hack(import: Import<'_>, binding: NameBinding<'_>) -> bool {
262+
fn pub_use_of_private_extern_crate_hack(
263+
import: Import<'_>,
264+
binding: NameBinding<'_>,
265+
) -> Option<NodeId> {
263266
match (&import.kind, &binding.kind) {
264-
(ImportKind::Single { .. }, NameBindingKind::Import { import: binding_import, .. }) => {
265-
matches!(binding_import.kind, ImportKind::ExternCrate { .. })
266-
&& import.expect_vis().is_public()
267+
(ImportKind::Single { .. }, NameBindingKind::Import { import: binding_import, .. })
268+
if let ImportKind::ExternCrate { id, .. } = binding_import.kind
269+
&& import.expect_vis().is_public() =>
270+
{
271+
Some(id)
267272
}
268-
_ => false,
273+
_ => None,
269274
}
270275
}
271276

@@ -275,7 +280,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
275280
pub(crate) fn import(&self, binding: NameBinding<'a>, import: Import<'a>) -> NameBinding<'a> {
276281
let import_vis = import.expect_vis().to_def_id();
277282
let vis = if binding.vis.is_at_least(import_vis, self.tcx)
278-
|| pub_use_of_private_extern_crate_hack(import, binding)
283+
|| pub_use_of_private_extern_crate_hack(import, binding).is_some()
279284
{
280285
import_vis
281286
} else {
@@ -1253,12 +1258,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12531258
// All namespaces must be re-exported with extra visibility for an error to occur.
12541259
if !any_successful_reexport {
12551260
let (ns, binding) = reexport_error.unwrap();
1256-
if pub_use_of_private_extern_crate_hack(import, binding) {
1261+
if let Some(extern_crate_id) = pub_use_of_private_extern_crate_hack(import, binding) {
12571262
self.lint_buffer.buffer_lint(
12581263
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
12591264
import_id,
12601265
import.span,
1261-
BuiltinLintDiag::PrivateExternCrateReexport(ident),
1266+
BuiltinLintDiag::PrivateExternCrateReexport {
1267+
source: ident,
1268+
extern_crate_span: self.tcx.source_span(self.local_def_id(extern_crate_id)),
1269+
},
12621270
);
12631271
} else {
12641272
if ns == TypeNS {

tests/ui/extern-flag/no-nounused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
//@ compile-flags: -Zunstable-options -Dunused-crate-dependencies
33
//@ edition:2018
44

5-
fn main() { //~ ERROR external crate `somedep` unused in `no_nounused`
5+
fn main() { //~ ERROR extern crate `somedep` is unused in crate `no_nounused`
66
}

tests/ui/extern-flag/no-nounused.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error: external crate `somedep` unused in `no_nounused`: remove the dependency or add `use somedep as _;`
1+
error: extern crate `somedep` is unused in crate `no_nounused`
22
--> $DIR/no-nounused.rs:5:1
33
|
44
LL | fn main() {
55
| ^
66
|
7+
= help: remove the dependency or add `use somedep as _;` to the crate root
78
= note: requested on the command line with `-D unused-crate-dependencies`
89

910
error: aborting due to 1 previous error

tests/ui/macros/issue-61053-missing-repetition.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
macro_rules! foo {
44
() => {};
55
($( $i:ident = $($j:ident),+ );*) => { $( $i = $j; )* };
6-
//~^ ERROR variable 'j' is still repeating
6+
//~^ ERROR variable `j` is still repeating
77
}
88

99
macro_rules! bar {
@@ -12,12 +12,12 @@ macro_rules! bar {
1212
macro_rules! nested {
1313
() => {};
1414
($( $i:ident = $($j:ident),+ );*) => { $( $i = $j; )* };
15-
//~^ ERROR variable 'j' is still repeating
15+
//~^ ERROR variable `j` is still repeating
1616
}
1717
};
1818
( $( $i:ident = $($j:ident),+ );* ) => {
1919
$(macro_rules! $i {
20-
() => { $j }; //~ ERROR variable 'j' is still repeating
20+
() => { $j }; //~ ERROR variable `j` is still repeating
2121
})*
2222
};
2323
}

tests/ui/macros/issue-61053-missing-repetition.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: variable 'j' is still repeating at this depth
1+
error: variable `j` is still repeating at this depth
22
--> $DIR/issue-61053-missing-repetition.rs:5:52
33
|
44
LL | ($( $i:ident = $($j:ident),+ );*) => { $( $i = $j; )* };
@@ -12,15 +12,15 @@ note: the lint level is defined here
1212
LL | #![deny(meta_variable_misuse)]
1313
| ^^^^^^^^^^^^^^^^^^^^
1414

15-
error: variable 'j' is still repeating at this depth
15+
error: variable `j` is still repeating at this depth
1616
--> $DIR/issue-61053-missing-repetition.rs:14:60
1717
|
1818
LL | ($( $i:ident = $($j:ident),+ );*) => { $( $i = $j; )* };
1919
| - ^^
2020
| |
2121
| expected repetition
2222

23-
error: variable 'j' is still repeating at this depth
23+
error: variable `j` is still repeating at this depth
2424
--> $DIR/issue-61053-missing-repetition.rs:20:21
2525
|
2626
LL | ( $( $i:ident = $($j:ident),+ );* ) => {

tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ macro_rules! no_curly__no_rhs_dollar__no_round {
3535
#[rustfmt::skip] // autoformatters can break a few of the error traces
3636
macro_rules! no_curly__rhs_dollar__round {
3737
( $( $i:ident ),* ) => { count($i) };
38-
//~^ ERROR variable 'i' is still repeating at this depth
38+
//~^ ERROR variable `i` is still repeating at this depth
3939
}
4040

4141
#[rustfmt::skip] // autoformatters can break a few of the error traces

tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ error: `count` can not be placed inside the inner-most repetition
208208
LL | ( $i:ident ) => { ${ count($i) } };
209209
| ^^^^^^^^^^^^^
210210

211-
error: variable 'i' is still repeating at this depth
211+
error: variable `i` is still repeating at this depth
212212
--> $DIR/syntax-errors.rs:37:36
213213
|
214214
LL | ( $( $i:ident ),* ) => { count($i) };

tests/ui/parser/macro/macro-repeat.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: variable 'v' is still repeating at this depth
1+
error: variable `v` is still repeating at this depth
22
--> $DIR/macro-repeat.rs:3:9
33
|
44
LL | $v
55
| ^^
66

7-
error: variable 'v' is still repeating at this depth
7+
error: variable `v` is still repeating at this depth
88
--> $DIR/macro-repeat.rs:3:9
99
|
1010
LL | $v

tests/ui/pub/pub-reexport-priv-extern-crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
extern crate core;
2-
pub use core as reexported_core; //~ ERROR `core` is private, and cannot be re-exported
2+
pub use core as reexported_core; //~ ERROR `core` is private and cannot be re-exported
33
//~^ WARN this was previously accepted
44

55
mod foo1 {

tests/ui/pub/pub-reexport-priv-extern-crate.stderr

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ note: the crate import `core` is defined here
2222
LL | extern crate core;
2323
| ^^^^^^^^^^^^^^^^^^
2424

25-
error[E0365]: extern crate `core` is private, and cannot be re-exported, consider declaring with `pub`
25+
error[E0365]: extern crate `core` is private and cannot be re-exported
2626
--> $DIR/pub-reexport-priv-extern-crate.rs:2:9
2727
|
2828
LL | pub use core as reexported_core;
@@ -31,6 +31,10 @@ LL | pub use core as reexported_core;
3131
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3232
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
3333
= note: `#[deny(pub_use_of_private_extern_crate)]` on by default
34+
help: consider making the `extern crate` item publicly accessible
35+
|
36+
LL | pub extern crate core;
37+
| +++
3438

3539
error: aborting due to 3 previous errors
3640

tests/ui/rust-2018/macro-use-warned-against.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#![warn(macro_use_extern_crate, unused)]
66

7-
#[macro_use] //~ WARN should be replaced at use sites with a `use` item
7+
#[macro_use] //~ WARN applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
88
extern crate macro_use_warned_against;
99
#[macro_use] //~ WARN unused `#[macro_use]`
1010
extern crate macro_use_warned_against2;

tests/ui/rust-2018/macro-use-warned-against.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
warning: deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
1+
warning: applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
22
--> $DIR/macro-use-warned-against.rs:7:1
33
|
44
LL | #[macro_use]
55
| ^^^^^^^^^^^^
66
|
7+
= help: remove it and import macros at use sites with a `use` item instead
78
note: the lint level is defined here
89
--> $DIR/macro-use-warned-against.rs:5:9
910
|

tests/ui/unused-crate-deps/deny-attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
//@ aux-crate:bar=bar.rs
55

66
#![deny(unused_crate_dependencies)]
7-
//~^ ERROR external crate `bar` unused in
7+
//~^ ERROR extern crate `bar` is unused in
88

99
fn main() {}

tests/ui/unused-crate-deps/deny-attr.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error: external crate `bar` unused in `deny_attr`: remove the dependency or add `use bar as _;`
1+
error: extern crate `bar` is unused in crate `deny_attr`
22
--> $DIR/deny-attr.rs:6:1
33
|
44
LL | #![deny(unused_crate_dependencies)]
55
| ^
66
|
7+
= help: remove the dependency or add `use bar as _;` to the crate root
78
note: the lint level is defined here
89
--> $DIR/deny-attr.rs:6:9
910
|

tests/ui/unused-crate-deps/deny-cmdline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
//@ aux-crate:bar=bar.rs
66

77
fn main() {}
8-
//~^ ERROR external crate `bar` unused in
8+
//~^ ERROR extern crate `bar` is unused in

tests/ui/unused-crate-deps/deny-cmdline.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error: external crate `bar` unused in `deny_cmdline`: remove the dependency or add `use bar as _;`
1+
error: extern crate `bar` is unused in crate `deny_cmdline`
22
--> $DIR/deny-cmdline.rs:7:1
33
|
44
LL | fn main() {}
55
| ^
66
|
7+
= help: remove the dependency or add `use bar as _;` to the crate root
78
= note: requested on the command line with `-D unused-crate-dependencies`
89

910
error: aborting due to 1 previous error

tests/ui/unused-crate-deps/libfib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//@ compile-flags:--crate-type lib -Wunused-crate-dependencies
66

77
pub fn fib(n: u32) -> Vec<u32> {
8-
//~^ WARNING external crate `bar` unused in
8+
//~^ WARNING extern crate `bar` is unused in
99
let mut prev = 0;
1010
let mut cur = 1;
1111
let mut v = vec![];

tests/ui/unused-crate-deps/libfib.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
warning: external crate `bar` unused in `libfib`: remove the dependency or add `use bar as _;`
1+
warning: extern crate `bar` is unused in crate `libfib`
22
--> $DIR/libfib.rs:7:1
33
|
44
LL | pub fn fib(n: u32) -> Vec<u32> {
55
| ^
66
|
7+
= help: remove the dependency or add `use bar as _;` to the crate root
78
= note: requested on the command line with `-W unused-crate-dependencies`
89

910
warning: 1 warning emitted

tests/ui/unused-crate-deps/unused-aliases.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//@ aux-crate:barbar=bar.rs
77

88
#![warn(unused_crate_dependencies)]
9-
//~^ WARNING external crate `barbar` unused in
9+
//~^ WARNING extern crate `barbar` is unused in
1010

1111
use bar as _;
1212

0 commit comments

Comments
 (0)