Skip to content

Commit 83fa02c

Browse files
committed
Auto merge of rust-lang#124139 - cuviper:beta-next, r=cuviper
[beta] backports - Silence `unused_imports` lint for redundant imports rust-lang#123744 - Call the panic hook for non-unwind panics in proc-macros rust-lang#123825 - rustdoc: check redundant explicit links with correct itemid rust-lang#123905 r? cuviper
2 parents 6fd1912 + 46515fd commit 83fa02c

26 files changed

+67
-251
lines changed

compiler/rustc_resolve/src/imports.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1368,13 +1368,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13681368
let mut redundant_spans: Vec<_> = redundant_span.present_items().collect();
13691369
redundant_spans.sort();
13701370
redundant_spans.dedup();
1371+
/* FIXME(unused_imports): Add this back as a new lint
13711372
self.lint_buffer.buffer_lint_with_diagnostic(
13721373
UNUSED_IMPORTS,
13731374
id,
13741375
import.span,
13751376
format!("the item `{source}` is imported redundantly"),
13761377
BuiltinLintDiag::RedundantImport(redundant_spans, source),
13771378
);
1379+
*/
13781380
return true;
13791381
}
13801382

compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ enum ImplTraitContext {
177177

178178
/// Used for tracking import use types which will be used for redundant import checking.
179179
/// ### Used::Scope Example
180-
/// ```rust,compile_fail
180+
/// ```rust,ignore (redundant_imports)
181181
/// #![deny(unused_imports)]
182182
/// use std::mem::drop;
183183
/// fn main() {

library/proc_macro/src/bridge/client.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ fn maybe_install_panic_hook(force_show_panics: bool) {
286286
BridgeState::NotConnected => true,
287287
BridgeState::Connected(_) | BridgeState::InUse => force_show_panics,
288288
});
289-
if show {
289+
// We normally report panics by catching unwinds and passing the payload from the
290+
// unwind back to the compiler, but if the panic doesn't unwind we'll abort before
291+
// the compiler has a chance to print an error. So we special-case PanicInfo where
292+
// can_unwind is false.
293+
if show || !info.can_unwind() {
290294
prev(info)
291295
}
292296
}));

library/proc_macro/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#![feature(maybe_uninit_write_slice)]
3131
#![feature(negative_impls)]
3232
#![feature(new_uninit)]
33+
#![feature(panic_can_unwind)]
3334
#![feature(restricted_std)]
3435
#![feature(rustc_attrs)]
3536
#![feature(min_specialization)]

src/librustdoc/passes/lint/redundant_explicit_links.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::SuggestionStyle;
66
use rustc_hir::def::{DefKind, DocLinkResMap, Namespace, Res};
77
use rustc_hir::HirId;
88
use rustc_lint_defs::Applicability;
9-
use rustc_resolve::rustdoc::source_span_for_markdown_range;
9+
use rustc_resolve::rustdoc::{prepare_to_doc_link_resolution, source_span_for_markdown_range};
1010
use rustc_span::def_id::DefId;
1111
use rustc_span::Symbol;
1212

@@ -29,16 +29,13 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
2929
return;
3030
};
3131

32-
let doc = item.doc_value();
33-
if doc.is_empty() {
34-
return;
35-
}
36-
37-
if let Some(item_id) = item.def_id() {
38-
check_redundant_explicit_link_for_did(cx, item, item_id, hir_id, &doc);
39-
}
40-
if let Some(item_id) = item.inline_stmt_id {
41-
check_redundant_explicit_link_for_did(cx, item, item_id, hir_id, &doc);
32+
let hunks = prepare_to_doc_link_resolution(&item.attrs.doc_strings);
33+
for (item_id, doc) in hunks {
34+
if let Some(item_id) = item_id.or(item.def_id())
35+
&& !doc.is_empty()
36+
{
37+
check_redundant_explicit_link_for_did(cx, item, item_id, hir_id, &doc);
38+
}
4239
}
4340
}
4441

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ check-pass
2+
#![deny(rustdoc::redundant_explicit_links)]
3+
4+
mod bar {
5+
/// [`Rc`](std::rc::Rc)
6+
pub enum Baz {}
7+
}
8+
9+
pub use bar::*;
10+
11+
use std::rc::Rc;
12+
13+
/// [`Rc::allocator`] [foo](std::rc::Rc)
14+
pub fn winit_runner() {}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ check-pass
12
//@ compile-flags: --extern aux_issue_121915 --edition 2015
23
//@ aux-build: aux-issue-121915.rs
34

@@ -6,6 +7,6 @@ extern crate aux_issue_121915;
67
#[deny(unused_imports)]
78
fn main() {
89
use aux_issue_121915;
9-
//~^ ERROR the item `aux_issue_121915` is imported redundantly
10+
//FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly
1011
aux_issue_121915::item();
1112
}

tests/ui/imports/redundant-import-issue-121915-2015.stderr

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
//@ check-pass
12
//@ compile-flags: --extern aux_issue_121915 --edition 2018
23
//@ aux-build: aux-issue-121915.rs
34

45
#[deny(unused_imports)]
56
fn main() {
67
use aux_issue_121915;
7-
//~^ ERROR the item `aux_issue_121915` is imported redundantly
8+
//FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly
89
aux_issue_121915::item();
910
}

tests/ui/imports/redundant-import-issue-121915.stderr

-14
This file was deleted.

tests/ui/imports/suggest-remove-issue-121315.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
//@ compile-flags: --edition 2021
2+
23
#![deny(unused_imports)]
34
#![allow(dead_code)]
45

56
fn test0() {
67
// Test remove FlatUnused
78
use std::convert::TryFrom;
8-
//~^ ERROR the item `TryFrom` is imported redundantly
9+
//FIXME(unused_imports): ~^ ERROR the item `TryFrom` is imported redundantly
910
let _ = u32::try_from(5i32);
1011
}
1112

1213
fn test1() {
1314
// FIXME(yukang) Test remove NestedFullUnused
1415
use std::convert::{TryFrom, TryInto};
15-
//~^ ERROR the item `TryFrom` is imported redundantly
16-
//~| ERROR the item `TryInto` is imported redundantly
16+
//FIXME(unused_imports): ~^ ERROR the item `TryFrom` is imported redundantly
17+
//FIXME(unused_imports): ~| ERROR the item `TryInto` is imported redundantly
1718

1819
let _ = u32::try_from(5i32);
1920
let _a: i32 = u32::try_into(5u32).unwrap();
@@ -23,7 +24,7 @@ fn test2() {
2324
// FIXME(yukang): Test remove both redundant and unused
2425
use std::convert::{AsMut, Into};
2526
//~^ ERROR unused import: `AsMut`
26-
//~| ERROR the item `Into` is imported redundantly
27+
//FIXME(unused_imports): ~| ERROR the item `Into` is imported redundantly
2728

2829
let _a: u32 = (5u8).into();
2930
}
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,20 @@
1-
error: the item `TryFrom` is imported redundantly
2-
--> $DIR/suggest-remove-issue-121315.rs:7:9
3-
|
4-
LL | use std::convert::TryFrom;
5-
| ^^^^^^^^^^^^^^^^^^^^^
6-
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
7-
|
8-
= note: the item `TryFrom` is already defined here
9-
|
10-
note: the lint level is defined here
11-
--> $DIR/suggest-remove-issue-121315.rs:2:9
12-
|
13-
LL | #![deny(unused_imports)]
14-
| ^^^^^^^^^^^^^^
15-
16-
error: the item `TryFrom` is imported redundantly
17-
--> $DIR/suggest-remove-issue-121315.rs:14:24
18-
|
19-
LL | use std::convert::{TryFrom, TryInto};
20-
| ^^^^^^^
21-
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
22-
|
23-
= note: the item `TryFrom` is already defined here
24-
25-
error: the item `TryInto` is imported redundantly
26-
--> $DIR/suggest-remove-issue-121315.rs:14:33
27-
|
28-
LL | use std::convert::{TryFrom, TryInto};
29-
| ^^^^^^^
30-
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
31-
|
32-
= note: the item `TryInto` is already defined here
33-
341
error: unused import: `AsMut`
35-
--> $DIR/suggest-remove-issue-121315.rs:24:24
2+
--> $DIR/suggest-remove-issue-121315.rs:25:24
363
|
374
LL | use std::convert::{AsMut, Into};
385
| ^^^^^
39-
40-
error: the item `Into` is imported redundantly
41-
--> $DIR/suggest-remove-issue-121315.rs:24:31
426
|
43-
LL | use std::convert::{AsMut, Into};
44-
| ^^^^
45-
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
7+
note: the lint level is defined here
8+
--> $DIR/suggest-remove-issue-121315.rs:3:9
469
|
47-
= note: the item `Into` is already defined here
10+
LL | #![deny(unused_imports)]
11+
| ^^^^^^^^^^^^^^
4812

4913
error: unused import: `From`
50-
--> $DIR/suggest-remove-issue-121315.rs:33:24
14+
--> $DIR/suggest-remove-issue-121315.rs:34:24
5115
|
5216
LL | use std::convert::{From, Infallible};
5317
| ^^^^
5418

55-
error: aborting due to 6 previous errors
19+
error: aborting due to 2 previous errors
5620

tests/ui/lint/unused/issue-59896.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
//@ check-pass
12
#![deny(unused_imports)]
23

34
struct S;
45

56
fn main() {
6-
use S; //~ ERROR the item `S` is imported redundantly
7+
use S; //FIXME(unused_imports): ~ ERROR the item `S` is imported redundantly
78

89
let _s = S;
910
}

tests/ui/lint/unused/issue-59896.stderr

-17
This file was deleted.

tests/ui/lint/use-redundant/use-redundant-glob-parent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub mod bar {
99
use bar::*;
1010

1111
pub fn warning() -> Foo {
12-
use bar::Foo; //~ WARNING imported redundantly
12+
use bar::Foo; //FIXME(unused_imports): ~ WARNING imported redundantly
1313
Foo(Bar('a'))
1414
}
1515

tests/ui/lint/use-redundant/use-redundant-glob-parent.stderr

-17
This file was deleted.

tests/ui/lint/use-redundant/use-redundant-glob.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub mod bar {
88

99
pub fn warning() -> bar::Foo {
1010
use bar::*;
11-
use bar::Foo; //~ WARNING imported redundantly
11+
use bar::Foo; //FIXME(unused_imports): ~ WARNING imported redundantly
1212
Foo(Bar('a'))
1313
}
1414

tests/ui/lint/use-redundant/use-redundant-glob.stderr

-16
This file was deleted.

tests/ui/lint/use-redundant/use-redundant-issue-71450.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ mod foo {
2323
fn main() {
2424

2525
{
26-
use std::string::String; //~ WARNING the item `String` is imported redundantly
26+
use std::string::String;
27+
//FIXME(unused_imports): ~^ WARNING the item `String` is imported redundantly
2728
// 'String' from 'std::string::String'.
2829
let s = String::new();
2930
println!("{}", s);

tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr

-17
This file was deleted.

tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
#![warn(unused_imports)]
33

44

5-
use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly
6-
use std::option::Option::None; //~ WARNING the item `None` is imported redundantly
5+
use std::option::Option::Some;
6+
//FIXME(unused_imports): ~^ WARNING the item `Some` is imported redundantly
7+
use std::option::Option::None;
8+
//FIXME(unused_imports): ~ WARNING the item `None` is imported redundantly
79

8-
use std::result::Result::Ok;//~ WARNING the item `Ok` is imported redundantly
9-
use std::result::Result::Err;//~ WARNING the item `Err` is imported redundantly
10+
use std::result::Result::Ok;
11+
//FIXME(unused_imports): ~^ WARNING the item `Ok` is imported redundantly
12+
use std::result::Result::Err;
13+
//FIXME(unused_imports): ~^ WARNING the item `Err` is imported redundantly
1014
use std::convert::{TryFrom, TryInto};
1115

1216
fn main() {

0 commit comments

Comments
 (0)