Skip to content

Commit b8cc4fa

Browse files
committed
Auto merge of rust-lang#126252 - matthiaskrgr:rollup-bt2r304, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - rust-lang#125913 (Spruce up the diagnostics of some early lints) - rust-lang#126140 (Rename `std::fs::try_exists` to `std::fs::exists` and stabilize fs_try_exists) - rust-lang#126234 (Delegation: fix ICE on late diagnostics) r? `@ghost` `@rustbot` modify labels: rollup
2 parents aec67e2 + 442c1c5 commit b8cc4fa

Some content is hidden

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

43 files changed

+135
-75
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 {

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
}

library/std/src/fs.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -2739,18 +2739,15 @@ impl AsInnerMut<fs_imp::DirBuilder> for DirBuilder {
27392739
/// # Examples
27402740
///
27412741
/// ```no_run
2742-
/// #![feature(fs_try_exists)]
27432742
/// use std::fs;
27442743
///
2745-
/// assert!(!fs::try_exists("does_not_exist.txt").expect("Can't check existence of file does_not_exist.txt"));
2746-
/// assert!(fs::try_exists("/root/secret_file.txt").is_err());
2744+
/// assert!(!fs::exists("does_not_exist.txt").expect("Can't check existence of file does_not_exist.txt"));
2745+
/// assert!(fs::exists("/root/secret_file.txt").is_err());
27472746
/// ```
27482747
///
27492748
/// [`Path::exists`]: crate::path::Path::exists
2750-
// FIXME: stabilization should modify documentation of `exists()` to recommend this method
2751-
// instead.
2752-
#[unstable(feature = "fs_try_exists", issue = "83186")]
2749+
#[stable(feature = "fs_try_exists", since = "CURRENT_RUSTC_VERSION")]
27532750
#[inline]
2754-
pub fn try_exists<P: AsRef<Path>>(path: P) -> io::Result<bool> {
2755-
fs_imp::try_exists(path.as_ref())
2751+
pub fn exists<P: AsRef<Path>>(path: P) -> io::Result<bool> {
2752+
fs_imp::exists(path.as_ref())
27562753
}

library/std/src/path.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2907,6 +2907,8 @@ impl Path {
29072907
/// prevent time-of-check to time-of-use (TOCTOU) bugs. You should only use it in scenarios
29082908
/// where those bugs are not an issue.
29092909
///
2910+
/// This is an alias for [`std::fs::exists`](crate::fs::exists).
2911+
///
29102912
/// # Examples
29112913
///
29122914
/// ```no_run
@@ -2919,7 +2921,7 @@ impl Path {
29192921
#[stable(feature = "path_try_exists", since = "1.63.0")]
29202922
#[inline]
29212923
pub fn try_exists(&self) -> io::Result<bool> {
2922-
fs::try_exists(self)
2924+
fs::exists(self)
29232925
}
29242926

29252927
/// Returns `true` if the path exists on disk and is pointing at a regular file.

library/std/src/sys/pal/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ use libc::{
101101
))]
102102
use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64};
103103

104-
pub use crate::sys_common::fs::try_exists;
104+
pub use crate::sys_common::fs::exists;
105105

106106
pub struct File(FileDesc);
107107

library/std/src/sys/pal/unix/thread.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ mod cgroups {
477477
//! output and we don't unescape
478478
use crate::borrow::Cow;
479479
use crate::ffi::OsString;
480-
use crate::fs::{try_exists, File};
480+
use crate::fs::{exists, File};
481481
use crate::io::Read;
482482
use crate::io::{BufRead, BufReader};
483483
use crate::os::unix::ffi::OsStringExt;
@@ -555,7 +555,7 @@ mod cgroups {
555555
path.push("cgroup.controllers");
556556

557557
// skip if we're not looking at cgroup2
558-
if matches!(try_exists(&path), Err(_) | Ok(false)) {
558+
if matches!(exists(&path), Err(_) | Ok(false)) {
559559
return usize::MAX;
560560
};
561561

@@ -612,7 +612,7 @@ mod cgroups {
612612
path.push(&group_path);
613613

614614
// skip if we guessed the mount incorrectly
615-
if matches!(try_exists(&path), Err(_) | Ok(false)) {
615+
if matches!(exists(&path), Err(_) | Ok(false)) {
616616
continue;
617617
}
618618

library/std/src/sys/pal/unsupported/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pub fn remove_dir_all(_path: &Path) -> io::Result<()> {
291291
unsupported()
292292
}
293293

294-
pub fn try_exists(_path: &Path) -> io::Result<bool> {
294+
pub fn exists(_path: &Path) -> io::Result<bool> {
295295
unsupported()
296296
}
297297

library/std/src/sys/pal/windows/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ pub fn junction_point(original: &Path, link: &Path) -> io::Result<()> {
15311531
}
15321532

15331533
// Try to see if a file exists but, unlike `exists`, report I/O errors.
1534-
pub fn try_exists(path: &Path) -> io::Result<bool> {
1534+
pub fn exists(path: &Path) -> io::Result<bool> {
15351535
// Open the file to ensure any symlinks are followed to their target.
15361536
let mut opts = OpenOptions::new();
15371537
// No read, write, etc access rights are needed.

library/std/src/sys_common/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn remove_dir_all_recursive(path: &Path) -> io::Result<()> {
4242
fs::remove_dir(path)
4343
}
4444

45-
pub fn try_exists(path: &Path) -> io::Result<bool> {
45+
pub fn exists(path: &Path) -> io::Result<bool> {
4646
match fs::metadata(path) {
4747
Ok(_) => Ok(true),
4848
Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(false),

tests/crashes/124342.rs

-6
This file was deleted.
+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
}

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
}

0 commit comments

Comments
 (0)