Skip to content

Commit 6a207f4

Browse files
committed
Auto merge of rust-lang#126262 - jieyouxu:rollup-g29lo3c, r=jieyouxu
Rollup of 5 pull requests Successful merges: - rust-lang#125913 (Spruce up the diagnostics of some early lints) - rust-lang#126234 (Delegation: fix ICE on late diagnostics) - rust-lang#126253 (Simplify assert matchers in `run-make-support`) - rust-lang#126257 (Rename `needs-matching-clang` to `needs-force-clang-based-tests`) - rust-lang#126259 (reachable computation: clarify comments around consts) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 336e6ab + 36c884c commit 6a207f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+156
-80
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_passes/src/reachable.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,21 @@ impl<'tcx> ReachableContext<'tcx> {
207207
}
208208

209209
hir::ItemKind::Const(_, _, init) => {
210-
// Only things actually ending up in the final constant need to be reachable.
211-
// Everything else is either already available as `mir_for_ctfe`, or can't be used
212-
// by codegen anyway.
210+
// Only things actually ending up in the final constant value are reachable
211+
// for codegen. Everything else is only needed during const-eval, so even if
212+
// const-eval happens in a downstream crate, all they need is
213+
// `mir_for_ctfe`.
213214
match self.tcx.const_eval_poly_to_alloc(item.owner_id.def_id.into()) {
214215
Ok(alloc) => {
215216
let alloc = self.tcx.global_alloc(alloc.alloc_id).unwrap_memory();
216217
self.propagate_from_alloc(alloc);
217218
}
218-
// Reachable generic constants will be inlined into other crates
219-
// unconditionally, so we need to make sure that their
220-
// contents are also reachable.
219+
// We can't figure out which value the constant will evaluate to. In
220+
// lieu of that, we have to consider everything mentioned in the const
221+
// initializer reachable, since it *may* end up in the final value.
221222
Err(ErrorHandled::TooGeneric(_)) => self.visit_nested_body(init),
223+
// If there was an error evaluating the const, nothing can be reachable
224+
// via it, and anyway compilation will fail.
222225
Err(ErrorHandled::Reported(..)) => {}
223226
}
224227
}

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 {

compiler/rustc_resolve/src/late/diagnostics.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2041,8 +2041,11 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
20412041
ast::AssocItemKind::Fn(..) => AssocSuggestion::AssocFn { called },
20422042
ast::AssocItemKind::Type(..) => AssocSuggestion::AssocType,
20432043
ast::AssocItemKind::Delegation(..)
2044-
if self.r.delegation_fn_sigs[&self.r.local_def_id(assoc_item.id)]
2045-
.has_self =>
2044+
if self
2045+
.r
2046+
.delegation_fn_sigs
2047+
.get(&self.r.local_def_id(assoc_item.id))
2048+
.map_or(false, |sig| sig.has_self) =>
20462049
{
20472050
AssocSuggestion::MethodWithSelf { called }
20482051
}

src/ci/docker/host-x86_64/x86_64-gnu-debug/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ENV RUST_CONFIGURE_ARGS \
4747
# This job appears to be checking two separate things:
4848
# - That we can build the compiler with `--enable-debug`
4949
# (without necessarily testing the result).
50-
# - That the tests with `//@ needs-matching-clang` pass, since they
50+
# - That the tests with `//@ needs-force-clang-based-tests` pass, since they
5151
# don't run by default unless RUSTBUILD_FORCE_CLANG_BASED_TESTS is set.
5252
# - FIXME(https://github.com./rust-lang/rust/pull/126155#issuecomment-2156314273):
5353
# Currently we only run the subset of tests with "clang" in their name.

src/tools/compiletest/src/header.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,9 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
854854
"needs-asm-support",
855855
"needs-dlltool",
856856
"needs-dynamic-linking",
857+
"needs-force-clang-based-tests",
857858
"needs-git-hash",
858859
"needs-llvm-components",
859-
"needs-matching-clang",
860860
"needs-profiler-support",
861861
"needs-relocation-model-pic",
862862
"needs-run-enabled",

src/tools/compiletest/src/header/needs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ pub(super) fn handle_needs(
100100
ignore_reason: "ignored when profiler support is disabled",
101101
},
102102
Need {
103-
name: "needs-matching-clang",
103+
name: "needs-force-clang-based-tests",
104104
condition: config.run_clang_based_tests_with.is_some(),
105-
ignore_reason: "ignored when the used clang does not match the built LLVM",
105+
ignore_reason: "ignored when RUSTBUILD_FORCE_CLANG_BASED_TESTS is not set",
106106
},
107107
Need {
108108
name: "needs-xray",

src/tools/run-make-support/src/command.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,38 +107,38 @@ impl CompletedProcess {
107107

108108
/// Checks that trimmed `stdout` matches trimmed `content`.
109109
#[track_caller]
110-
pub fn assert_stdout_equals<S: AsRef<str>>(self, content: S) -> Self {
110+
pub fn assert_stdout_equals<S: AsRef<str>>(&self, content: S) -> &Self {
111111
assert_eq!(self.stdout_utf8().trim(), content.as_ref().trim());
112112
self
113113
}
114114

115115
#[track_caller]
116-
pub fn assert_stdout_not_contains<S: AsRef<str>>(self, needle: S) -> Self {
116+
pub fn assert_stdout_not_contains<S: AsRef<str>>(&self, needle: S) -> &Self {
117117
assert_not_contains(&self.stdout_utf8(), needle.as_ref());
118118
self
119119
}
120120

121121
/// Checks that trimmed `stderr` matches trimmed `content`.
122122
#[track_caller]
123-
pub fn assert_stderr_equals<S: AsRef<str>>(self, content: S) -> Self {
123+
pub fn assert_stderr_equals<S: AsRef<str>>(&self, content: S) -> &Self {
124124
assert_eq!(self.stderr_utf8().trim(), content.as_ref().trim());
125125
self
126126
}
127127

128128
#[track_caller]
129-
pub fn assert_stderr_contains<S: AsRef<str>>(self, needle: S) -> Self {
129+
pub fn assert_stderr_contains<S: AsRef<str>>(&self, needle: S) -> &Self {
130130
assert!(self.stderr_utf8().contains(needle.as_ref()));
131131
self
132132
}
133133

134134
#[track_caller]
135-
pub fn assert_stderr_not_contains<S: AsRef<str>>(self, needle: S) -> Self {
135+
pub fn assert_stderr_not_contains<S: AsRef<str>>(&self, needle: S) -> &Self {
136136
assert_not_contains(&self.stdout_utf8(), needle.as_ref());
137137
self
138138
}
139139

140140
#[track_caller]
141-
pub fn assert_exit_code(self, code: i32) -> Self {
141+
pub fn assert_exit_code(&self, code: i32) -> &Self {
142142
assert!(self.output.status.code() == Some(code));
143143
self
144144
}

tests/crashes/124342.rs

-6
This file was deleted.

tests/run-make/cross-lang-lto-clang/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# needs-matching-clang
1+
# needs-force-clang-based-tests
22

33
# This test makes sure that cross-language inlining actually works by checking
44
# the generated machine code.

tests/run-make/cross-lang-lto-pgo-smoketest/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# needs-matching-clang
1+
# needs-force-clang-based-tests
2+
3+
# FIXME(#126180): This test doesn't actually run anywhere, because the only
4+
# CI job that sets RUSTBUILD_FORCE_CLANG_BASED_TESTS runs very few tests.
25

36
# This test makes sure that cross-language inlining can be used in conjunction
47
# with profile-guided optimization. The test only tests that the whole workflow

tests/run-make/cross-lang-lto-riscv-abi/rmake.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
//! Make sure that cross-language LTO works on riscv targets,
22
//! which requires extra `target-abi` metadata to be emitted.
3-
//@ needs-matching-clang
3+
//@ needs-force-clang-based-tests
44
//@ needs-llvm-components riscv
55

6+
// FIXME(#126180): This test doesn't actually run anywhere, because the only
7+
// CI job that sets RUSTBUILD_FORCE_CLANG_BASED_TESTS runs very few tests.
8+
69
use run_make_support::{bin_name, clang, llvm_readobj, rustc};
710
use std::{
811
env,

tests/run-make/issue-84395-lto-embed-bitcode/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# needs-matching-clang
1+
# needs-force-clang-based-tests
2+
3+
# FIXME(#126180): This test doesn't actually run anywhere, because the only
4+
# CI job that sets RUSTBUILD_FORCE_CLANG_BASED_TESTS runs very few tests.
25

36
# This test makes sure the embed bitcode in elf created with
47
# lto-embed-bitcode=optimized is valid llvm BC module.

tests/run-make/wasm-override-linker/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# needs-matching-clang
1+
# needs-force-clang-based-tests
2+
3+
# FIXME(#126180): This test doesn't actually run anywhere, because the only
4+
# CI job that sets RUSTBUILD_FORCE_CLANG_BASED_TESTS runs very few tests.
25

36
include ../tools.mk
47

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(fn_delegation)]
2+
#![allow(incomplete_features)]
3+
4+
mod to_reuse {}
5+
6+
trait Trait {
7+
reuse to_reuse::foo { foo }
8+
//~^ ERROR cannot find function `foo` in module `to_reuse`
9+
//~| ERROR cannot find value `foo` in this scope
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0425]: cannot find function `foo` in module `to_reuse`
2+
--> $DIR/ice-issue-124342.rs:7:21
3+
|
4+
LL | reuse to_reuse::foo { foo }
5+
| ^^^ not found in `to_reuse`
6+
7+
error[E0425]: cannot find value `foo` in this scope
8+
--> $DIR/ice-issue-124342.rs:7:27
9+
|
10+
LL | reuse to_reuse::foo { foo }
11+
| ^^^
12+
|
13+
help: you might have meant to refer to the associated function
14+
|
15+
LL | reuse to_reuse::foo { Self::foo }
16+
| ++++++
17+
18+
error: aborting due to 2 previous errors
19+
20+
For more information about this error, try `rustc --explain E0425`.

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
}

0 commit comments

Comments
 (0)