Skip to content

Commit

Permalink
Auto merge of rust-lang#126262 - jieyouxu:rollup-g29lo3c, r=jieyouxu
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jun 11, 2024
2 parents 336e6ab + 36c884c commit 6a207f4
Show file tree
Hide file tree
Showing 46 changed files with 156 additions and 80 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_expand/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ expand_unsupported_key_value =
key-value macro attributes are not supported
expand_var_still_repeating =
variable '{$ident}' is still repeating at this depth
variable `{$ident}` is still repeating at this depth
expand_wrong_fragment_kind =
non-{$kind} macro in {$kind} position: {$name}
12 changes: 7 additions & 5 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ lint_macro_is_private = macro `{$ident}` is private
lint_macro_rule_never_used = rule #{$n} of macro `{$name}` is never used
lint_macro_use_deprecated =
deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
.help = remove it and import macros at use sites with a `use` item instead
lint_malformed_attribute = malformed lint attribute input
Expand All @@ -456,7 +457,7 @@ lint_map_unit_fn = `Iterator::map` call that discard the iterator's values
.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
.suggestion = you might have meant to use `Iterator::for_each`
lint_metavariable_still_repeating = variable '{$name}' is still repeating at this depth
lint_metavariable_still_repeating = variable `{$name}` is still repeating at this depth
lint_metavariable_wrong_operator = meta-variable repeats with different Kleene operator
Expand Down Expand Up @@ -635,8 +636,8 @@ lint_pattern_in_bodiless = patterns aren't allowed in functions without bodies
lint_pattern_in_foreign = patterns aren't allowed in foreign function declarations
.label = pattern not allowed in foreign function
lint_private_extern_crate_reexport =
extern crate `{$ident}` is private, and cannot be re-exported, consider declaring with `pub`
lint_private_extern_crate_reexport = extern crate `{$ident}` is private and cannot be re-exported
.suggestion = consider making the `extern crate` item publicly accessible
lint_proc_macro_derive_resolution_fallback = cannot find {$ns} `{$ident}` in this scope
.label = names from parent modules are not accessible without an explicit import
Expand Down Expand Up @@ -847,7 +848,8 @@ lint_unused_coroutine =
}{$post} that must be used
.note = coroutines are lazy and do nothing unless resumed
lint_unused_crate_dependency = external crate `{$extern_crate}` unused in `{$local_crate}`: remove the dependency or add `use {$extern_crate} as _;`
lint_unused_crate_dependency = extern crate `{$extern_crate}` is unused in crate `{$local_crate}`
.help = remove the dependency or add `use {$extern_crate} as _;` to the crate root
lint_unused_def = unused {$pre}`{$def}`{$post} that must be used
.suggestion = use `let _ = ...` to ignore the resulting value
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_lint/src/context/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
lints::MacroUseDeprecated.decorate_lint(diag);
}
BuiltinLintDiag::UnusedMacroUse => lints::UnusedMacroUse.decorate_lint(diag),
BuiltinLintDiag::PrivateExternCrateReexport(ident) => {
lints::PrivateExternCrateReexport { ident }.decorate_lint(diag);
BuiltinLintDiag::PrivateExternCrateReexport { source: ident, extern_crate_span } => {
lints::PrivateExternCrateReexport { ident, sugg: extern_crate_span.shrink_to_lo() }
.decorate_lint(diag);
}
BuiltinLintDiag::UnusedLabel => lints::UnusedLabel.decorate_lint(diag),
BuiltinLintDiag::MacroIsPrivate(ident) => {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2313,6 +2313,7 @@ pub mod unexpected_cfg_value {

#[derive(LintDiagnostic)]
#[diag(lint_macro_use_deprecated)]
#[help]
pub struct MacroUseDeprecated;

#[derive(LintDiagnostic)]
Expand All @@ -2323,6 +2324,8 @@ pub struct UnusedMacroUse;
#[diag(lint_private_extern_crate_reexport, code = E0365)]
pub struct PrivateExternCrateReexport {
pub ident: Ident,
#[suggestion(code = "pub ", style = "verbose", applicability = "maybe-incorrect")]
pub sugg: Span,
}

#[derive(LintDiagnostic)]
Expand Down Expand Up @@ -2416,6 +2419,7 @@ pub struct UnknownMacroVariable {

#[derive(LintDiagnostic)]
#[diag(lint_unused_crate_dependency)]
#[help]
pub struct UnusedCrateDependency {
pub extern_crate: Symbol,
pub local_crate: Symbol,
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,9 @@ declare_lint! {
/// This will produce:
///
/// ```text
/// error: external crate `regex` unused in `lint_example`: remove the dependency or add `use regex as _;`
/// error: extern crate `regex` is unused in crate `lint_example`
/// |
/// = help: remove the dependency or add `use regex as _;` to the crate root
/// note: the lint level is defined here
/// --> src/lib.rs:1:9
/// |
Expand Down Expand Up @@ -2160,8 +2161,7 @@ declare_lint! {
}

declare_lint! {
/// The `macro_use_extern_crate` lint detects the use of the
/// [`macro_use` attribute].
/// The `macro_use_extern_crate` lint detects the use of the [`macro_use` attribute].
///
/// ### Example
///
Expand All @@ -2179,12 +2179,13 @@ declare_lint! {
/// This will produce:
///
/// ```text
/// error: deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
/// error: applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
/// --> src/main.rs:3:1
/// |
/// 3 | #[macro_use]
/// | ^^^^^^^^^^^^
/// |
/// = help: remove it and import macros at use sites with a `use` item instead
/// note: the lint level is defined here
/// --> src/main.rs:1:9
/// |
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,10 @@ pub enum BuiltinLintDiag {
},
MacroUseDeprecated,
UnusedMacroUse,
PrivateExternCrateReexport(Ident),
PrivateExternCrateReexport {
source: Ident,
extern_crate_span: Span,
},
UnusedLabel,
MacroIsPrivate(Ident),
UnusedMacroDefinition(Symbol),
Expand Down
15 changes: 9 additions & 6 deletions compiler/rustc_passes/src/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,21 @@ impl<'tcx> ReachableContext<'tcx> {
}

hir::ItemKind::Const(_, _, init) => {
// Only things actually ending up in the final constant need to be reachable.
// Everything else is either already available as `mir_for_ctfe`, or can't be used
// by codegen anyway.
// Only things actually ending up in the final constant value are reachable
// for codegen. Everything else is only needed during const-eval, so even if
// const-eval happens in a downstream crate, all they need is
// `mir_for_ctfe`.
match self.tcx.const_eval_poly_to_alloc(item.owner_id.def_id.into()) {
Ok(alloc) => {
let alloc = self.tcx.global_alloc(alloc.alloc_id).unwrap_memory();
self.propagate_from_alloc(alloc);
}
// Reachable generic constants will be inlined into other crates
// unconditionally, so we need to make sure that their
// contents are also reachable.
// We can't figure out which value the constant will evaluate to. In
// lieu of that, we have to consider everything mentioned in the const
// initializer reachable, since it *may* end up in the final value.
Err(ErrorHandled::TooGeneric(_)) => self.visit_nested_body(init),
// If there was an error evaluating the const, nothing can be reachable
// via it, and anyway compilation will fail.
Err(ErrorHandled::Reported(..)) => {}
}
}
Expand Down
24 changes: 16 additions & 8 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,18 @@ struct UnresolvedImportError {

// Reexports of the form `pub use foo as bar;` where `foo` is `extern crate foo;`
// are permitted for backward-compatibility under a deprecation lint.
fn pub_use_of_private_extern_crate_hack(import: Import<'_>, binding: NameBinding<'_>) -> bool {
fn pub_use_of_private_extern_crate_hack(
import: Import<'_>,
binding: NameBinding<'_>,
) -> Option<NodeId> {
match (&import.kind, &binding.kind) {
(ImportKind::Single { .. }, NameBindingKind::Import { import: binding_import, .. }) => {
matches!(binding_import.kind, ImportKind::ExternCrate { .. })
&& import.expect_vis().is_public()
(ImportKind::Single { .. }, NameBindingKind::Import { import: binding_import, .. })
if let ImportKind::ExternCrate { id, .. } = binding_import.kind
&& import.expect_vis().is_public() =>
{
Some(id)
}
_ => false,
_ => None,
}
}

Expand All @@ -275,7 +280,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
pub(crate) fn import(&self, binding: NameBinding<'a>, import: Import<'a>) -> NameBinding<'a> {
let import_vis = import.expect_vis().to_def_id();
let vis = if binding.vis.is_at_least(import_vis, self.tcx)
|| pub_use_of_private_extern_crate_hack(import, binding)
|| pub_use_of_private_extern_crate_hack(import, binding).is_some()
{
import_vis
} else {
Expand Down Expand Up @@ -1253,12 +1258,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// All namespaces must be re-exported with extra visibility for an error to occur.
if !any_successful_reexport {
let (ns, binding) = reexport_error.unwrap();
if pub_use_of_private_extern_crate_hack(import, binding) {
if let Some(extern_crate_id) = pub_use_of_private_extern_crate_hack(import, binding) {
self.lint_buffer.buffer_lint(
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
import_id,
import.span,
BuiltinLintDiag::PrivateExternCrateReexport(ident),
BuiltinLintDiag::PrivateExternCrateReexport {
source: ident,
extern_crate_span: self.tcx.source_span(self.local_def_id(extern_crate_id)),
},
);
} else {
if ns == TypeNS {
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2041,8 +2041,11 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
ast::AssocItemKind::Fn(..) => AssocSuggestion::AssocFn { called },
ast::AssocItemKind::Type(..) => AssocSuggestion::AssocType,
ast::AssocItemKind::Delegation(..)
if self.r.delegation_fn_sigs[&self.r.local_def_id(assoc_item.id)]
.has_self =>
if self
.r
.delegation_fn_sigs
.get(&self.r.local_def_id(assoc_item.id))
.map_or(false, |sig| sig.has_self) =>
{
AssocSuggestion::MethodWithSelf { called }
}
Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/host-x86_64/x86_64-gnu-debug/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ENV RUST_CONFIGURE_ARGS \
# This job appears to be checking two separate things:
# - That we can build the compiler with `--enable-debug`
# (without necessarily testing the result).
# - That the tests with `//@ needs-matching-clang` pass, since they
# - That the tests with `//@ needs-force-clang-based-tests` pass, since they
# don't run by default unless RUSTBUILD_FORCE_CLANG_BASED_TESTS is set.
# - FIXME(https://github.com/rust-lang/rust/pull/126155#issuecomment-2156314273):
# Currently we only run the subset of tests with "clang" in their name.
Expand Down
2 changes: 1 addition & 1 deletion src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,9 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"needs-asm-support",
"needs-dlltool",
"needs-dynamic-linking",
"needs-force-clang-based-tests",
"needs-git-hash",
"needs-llvm-components",
"needs-matching-clang",
"needs-profiler-support",
"needs-relocation-model-pic",
"needs-run-enabled",
Expand Down
4 changes: 2 additions & 2 deletions src/tools/compiletest/src/header/needs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ pub(super) fn handle_needs(
ignore_reason: "ignored when profiler support is disabled",
},
Need {
name: "needs-matching-clang",
name: "needs-force-clang-based-tests",
condition: config.run_clang_based_tests_with.is_some(),
ignore_reason: "ignored when the used clang does not match the built LLVM",
ignore_reason: "ignored when RUSTBUILD_FORCE_CLANG_BASED_TESTS is not set",
},
Need {
name: "needs-xray",
Expand Down
12 changes: 6 additions & 6 deletions src/tools/run-make-support/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,38 +107,38 @@ impl CompletedProcess {

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

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

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

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

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

#[track_caller]
pub fn assert_exit_code(self, code: i32) -> Self {
pub fn assert_exit_code(&self, code: i32) -> &Self {
assert!(self.output.status.code() == Some(code));
self
}
Expand Down
6 changes: 0 additions & 6 deletions tests/crashes/124342.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/run-make/cross-lang-lto-clang/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# needs-matching-clang
# needs-force-clang-based-tests

# This test makes sure that cross-language inlining actually works by checking
# the generated machine code.
Expand Down
5 changes: 4 additions & 1 deletion tests/run-make/cross-lang-lto-pgo-smoketest/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# needs-matching-clang
# needs-force-clang-based-tests

# FIXME(#126180): This test doesn't actually run anywhere, because the only
# CI job that sets RUSTBUILD_FORCE_CLANG_BASED_TESTS runs very few tests.

# This test makes sure that cross-language inlining can be used in conjunction
# with profile-guided optimization. The test only tests that the whole workflow
Expand Down
5 changes: 4 additions & 1 deletion tests/run-make/cross-lang-lto-riscv-abi/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! Make sure that cross-language LTO works on riscv targets,
//! which requires extra `target-abi` metadata to be emitted.
//@ needs-matching-clang
//@ needs-force-clang-based-tests
//@ needs-llvm-components riscv

// FIXME(#126180): This test doesn't actually run anywhere, because the only
// CI job that sets RUSTBUILD_FORCE_CLANG_BASED_TESTS runs very few tests.

use run_make_support::{bin_name, clang, llvm_readobj, rustc};
use std::{
env,
Expand Down
5 changes: 4 additions & 1 deletion tests/run-make/issue-84395-lto-embed-bitcode/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# needs-matching-clang
# needs-force-clang-based-tests

# FIXME(#126180): This test doesn't actually run anywhere, because the only
# CI job that sets RUSTBUILD_FORCE_CLANG_BASED_TESTS runs very few tests.

# This test makes sure the embed bitcode in elf created with
# lto-embed-bitcode=optimized is valid llvm BC module.
Expand Down
5 changes: 4 additions & 1 deletion tests/run-make/wasm-override-linker/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# needs-matching-clang
# needs-force-clang-based-tests

# FIXME(#126180): This test doesn't actually run anywhere, because the only
# CI job that sets RUSTBUILD_FORCE_CLANG_BASED_TESTS runs very few tests.

include ../tools.mk

Expand Down
12 changes: 12 additions & 0 deletions tests/ui/delegation/ice-issue-124342.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![feature(fn_delegation)]
#![allow(incomplete_features)]

mod to_reuse {}

trait Trait {
reuse to_reuse::foo { foo }
//~^ ERROR cannot find function `foo` in module `to_reuse`
//~| ERROR cannot find value `foo` in this scope
}

fn main() {}
20 changes: 20 additions & 0 deletions tests/ui/delegation/ice-issue-124342.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0425]: cannot find function `foo` in module `to_reuse`
--> $DIR/ice-issue-124342.rs:7:21
|
LL | reuse to_reuse::foo { foo }
| ^^^ not found in `to_reuse`

error[E0425]: cannot find value `foo` in this scope
--> $DIR/ice-issue-124342.rs:7:27
|
LL | reuse to_reuse::foo { foo }
| ^^^
|
help: you might have meant to refer to the associated function
|
LL | reuse to_reuse::foo { Self::foo }
| ++++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.
2 changes: 1 addition & 1 deletion tests/ui/extern-flag/no-nounused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
//@ compile-flags: -Zunstable-options -Dunused-crate-dependencies
//@ edition:2018

fn main() { //~ ERROR external crate `somedep` unused in `no_nounused`
fn main() { //~ ERROR extern crate `somedep` is unused in crate `no_nounused`
}
Loading

0 comments on commit 6a207f4

Please sign in to comment.