Skip to content

Commit

Permalink
Auto merge of rust-lang#124139 - cuviper:beta-next, r=cuviper
Browse files Browse the repository at this point in the history
[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
- disable two debuginfo tests under gdb 15 rust-lang#123963

r? cuviper
  • Loading branch information
bors committed Apr 19, 2024
2 parents 6fd1912 + c623345 commit 13ef05e
Show file tree
Hide file tree
Showing 28 changed files with 71 additions and 251 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,13 +1368,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let mut redundant_spans: Vec<_> = redundant_span.present_items().collect();
redundant_spans.sort();
redundant_spans.dedup();
/* FIXME(unused_imports): Add this back as a new lint
self.lint_buffer.buffer_lint_with_diagnostic(
UNUSED_IMPORTS,
id,
import.span,
format!("the item `{source}` is imported redundantly"),
BuiltinLintDiag::RedundantImport(redundant_spans, source),
);
*/
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ enum ImplTraitContext {

/// Used for tracking import use types which will be used for redundant import checking.
/// ### Used::Scope Example
/// ```rust,compile_fail
/// ```rust,ignore (redundant_imports)
/// #![deny(unused_imports)]
/// use std::mem::drop;
/// fn main() {
Expand Down
6 changes: 5 additions & 1 deletion library/proc_macro/src/bridge/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ fn maybe_install_panic_hook(force_show_panics: bool) {
BridgeState::NotConnected => true,
BridgeState::Connected(_) | BridgeState::InUse => force_show_panics,
});
if show {
// We normally report panics by catching unwinds and passing the payload from the
// unwind back to the compiler, but if the panic doesn't unwind we'll abort before
// the compiler has a chance to print an error. So we special-case PanicInfo where
// can_unwind is false.
if show || !info.can_unwind() {
prev(info)
}
}));
Expand Down
1 change: 1 addition & 0 deletions library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#![feature(maybe_uninit_write_slice)]
#![feature(negative_impls)]
#![feature(new_uninit)]
#![feature(panic_can_unwind)]
#![feature(restricted_std)]
#![feature(rustc_attrs)]
#![feature(min_specialization)]
Expand Down
19 changes: 8 additions & 11 deletions src/librustdoc/passes/lint/redundant_explicit_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_errors::SuggestionStyle;
use rustc_hir::def::{DefKind, DocLinkResMap, Namespace, Res};
use rustc_hir::HirId;
use rustc_lint_defs::Applicability;
use rustc_resolve::rustdoc::source_span_for_markdown_range;
use rustc_resolve::rustdoc::{prepare_to_doc_link_resolution, source_span_for_markdown_range};
use rustc_span::def_id::DefId;
use rustc_span::Symbol;

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

let doc = item.doc_value();
if doc.is_empty() {
return;
}

if let Some(item_id) = item.def_id() {
check_redundant_explicit_link_for_did(cx, item, item_id, hir_id, &doc);
}
if let Some(item_id) = item.inline_stmt_id {
check_redundant_explicit_link_for_did(cx, item, item_id, hir_id, &doc);
let hunks = prepare_to_doc_link_resolution(&item.attrs.doc_strings);
for (item_id, doc) in hunks {
if let Some(item_id) = item_id.or(item.def_id())
&& !doc.is_empty()
{
check_redundant_explicit_link_for_did(cx, item, item_id, hir_id, &doc);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/debuginfo/include_string.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ min-lldb-version: 310
//@ ignore-gdb-version: 15.0 - 99.0
// ^ test temporarily disabled as it fails under gdb 15

//@ compile-flags:-g
// gdb-command:run
Expand Down
2 changes: 2 additions & 0 deletions tests/debuginfo/vec-slices.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ min-lldb-version: 310
//@ ignore-gdb-version: 15.0 - 99.0
// ^ test temporarily disabled as it fails under gdb 15

//@ compile-flags:-g

Expand Down
14 changes: 14 additions & 0 deletions tests/rustdoc-ui/redundant-explicit-links-123677.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ check-pass
#![deny(rustdoc::redundant_explicit_links)]

mod bar {
/// [`Rc`](std::rc::Rc)
pub enum Baz {}
}

pub use bar::*;

use std::rc::Rc;

/// [`Rc::allocator`] [foo](std::rc::Rc)
pub fn winit_runner() {}
3 changes: 2 additions & 1 deletion tests/ui/imports/redundant-import-issue-121915-2015.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ check-pass
//@ compile-flags: --extern aux_issue_121915 --edition 2015
//@ aux-build: aux-issue-121915.rs

Expand All @@ -6,6 +7,6 @@ extern crate aux_issue_121915;
#[deny(unused_imports)]
fn main() {
use aux_issue_121915;
//~^ ERROR the item `aux_issue_121915` is imported redundantly
//FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly
aux_issue_121915::item();
}
17 changes: 0 additions & 17 deletions tests/ui/imports/redundant-import-issue-121915-2015.stderr

This file was deleted.

3 changes: 2 additions & 1 deletion tests/ui/imports/redundant-import-issue-121915.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//@ check-pass
//@ compile-flags: --extern aux_issue_121915 --edition 2018
//@ aux-build: aux-issue-121915.rs

#[deny(unused_imports)]
fn main() {
use aux_issue_121915;
//~^ ERROR the item `aux_issue_121915` is imported redundantly
//FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly
aux_issue_121915::item();
}
14 changes: 0 additions & 14 deletions tests/ui/imports/redundant-import-issue-121915.stderr

This file was deleted.

9 changes: 5 additions & 4 deletions tests/ui/imports/suggest-remove-issue-121315.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
//@ compile-flags: --edition 2021

#![deny(unused_imports)]
#![allow(dead_code)]

fn test0() {
// Test remove FlatUnused
use std::convert::TryFrom;
//~^ ERROR the item `TryFrom` is imported redundantly
//FIXME(unused_imports): ~^ ERROR the item `TryFrom` is imported redundantly
let _ = u32::try_from(5i32);
}

fn test1() {
// FIXME(yukang) Test remove NestedFullUnused
use std::convert::{TryFrom, TryInto};
//~^ ERROR the item `TryFrom` is imported redundantly
//~| ERROR the item `TryInto` is imported redundantly
//FIXME(unused_imports): ~^ ERROR the item `TryFrom` is imported redundantly
//FIXME(unused_imports): ~| ERROR the item `TryInto` is imported redundantly

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

let _a: u32 = (5u8).into();
}
Expand Down
50 changes: 7 additions & 43 deletions tests/ui/imports/suggest-remove-issue-121315.stderr
Original file line number Diff line number Diff line change
@@ -1,56 +1,20 @@
error: the item `TryFrom` is imported redundantly
--> $DIR/suggest-remove-issue-121315.rs:7:9
|
LL | use std::convert::TryFrom;
| ^^^^^^^^^^^^^^^^^^^^^
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
= note: the item `TryFrom` is already defined here
|
note: the lint level is defined here
--> $DIR/suggest-remove-issue-121315.rs:2:9
|
LL | #![deny(unused_imports)]
| ^^^^^^^^^^^^^^

error: the item `TryFrom` is imported redundantly
--> $DIR/suggest-remove-issue-121315.rs:14:24
|
LL | use std::convert::{TryFrom, TryInto};
| ^^^^^^^
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
= note: the item `TryFrom` is already defined here

error: the item `TryInto` is imported redundantly
--> $DIR/suggest-remove-issue-121315.rs:14:33
|
LL | use std::convert::{TryFrom, TryInto};
| ^^^^^^^
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
= note: the item `TryInto` is already defined here

error: unused import: `AsMut`
--> $DIR/suggest-remove-issue-121315.rs:24:24
--> $DIR/suggest-remove-issue-121315.rs:25:24
|
LL | use std::convert::{AsMut, Into};
| ^^^^^

error: the item `Into` is imported redundantly
--> $DIR/suggest-remove-issue-121315.rs:24:31
|
LL | use std::convert::{AsMut, Into};
| ^^^^
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
note: the lint level is defined here
--> $DIR/suggest-remove-issue-121315.rs:3:9
|
= note: the item `Into` is already defined here
LL | #![deny(unused_imports)]
| ^^^^^^^^^^^^^^

error: unused import: `From`
--> $DIR/suggest-remove-issue-121315.rs:33:24
--> $DIR/suggest-remove-issue-121315.rs:34:24
|
LL | use std::convert::{From, Infallible};
| ^^^^

error: aborting due to 6 previous errors
error: aborting due to 2 previous errors

3 changes: 2 additions & 1 deletion tests/ui/lint/unused/issue-59896.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//@ check-pass
#![deny(unused_imports)]

struct S;

fn main() {
use S; //~ ERROR the item `S` is imported redundantly
use S; //FIXME(unused_imports): ~ ERROR the item `S` is imported redundantly

let _s = S;
}
17 changes: 0 additions & 17 deletions tests/ui/lint/unused/issue-59896.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/lint/use-redundant/use-redundant-glob-parent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod bar {
use bar::*;

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

Expand Down
17 changes: 0 additions & 17 deletions tests/ui/lint/use-redundant/use-redundant-glob-parent.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/lint/use-redundant/use-redundant-glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod bar {

pub fn warning() -> bar::Foo {
use bar::*;
use bar::Foo; //~ WARNING imported redundantly
use bar::Foo; //FIXME(unused_imports): ~ WARNING imported redundantly
Foo(Bar('a'))
}

Expand Down
16 changes: 0 additions & 16 deletions tests/ui/lint/use-redundant/use-redundant-glob.stderr

This file was deleted.

3 changes: 2 additions & 1 deletion tests/ui/lint/use-redundant/use-redundant-issue-71450.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ mod foo {
fn main() {

{
use std::string::String; //~ WARNING the item `String` is imported redundantly
use std::string::String;
//FIXME(unused_imports): ~^ WARNING the item `String` is imported redundantly
// 'String' from 'std::string::String'.
let s = String::new();
println!("{}", s);
Expand Down
17 changes: 0 additions & 17 deletions tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr

This file was deleted.

12 changes: 8 additions & 4 deletions tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
#![warn(unused_imports)]


use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly
use std::option::Option::None; //~ WARNING the item `None` is imported redundantly
use std::option::Option::Some;
//FIXME(unused_imports): ~^ WARNING the item `Some` is imported redundantly
use std::option::Option::None;
//FIXME(unused_imports): ~ WARNING the item `None` is imported redundantly

use std::result::Result::Ok;//~ WARNING the item `Ok` is imported redundantly
use std::result::Result::Err;//~ WARNING the item `Err` is imported redundantly
use std::result::Result::Ok;
//FIXME(unused_imports): ~^ WARNING the item `Ok` is imported redundantly
use std::result::Result::Err;
//FIXME(unused_imports): ~^ WARNING the item `Err` is imported redundantly
use std::convert::{TryFrom, TryInto};

fn main() {
Expand Down
Loading

0 comments on commit 13ef05e

Please sign in to comment.