Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/eii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ pub(crate) fn check_externally_implementable_items<'tcx>(tcx: TyCtxt<'tcx>, ():
decl_crate_name: tcx.crate_name(decl_crate),
// FIXME: shouldn't call `item_name`
name: decl.name.name,
kind: tcx.def_kind(decl.foreign_item).descr(decl.foreign_item),
span: decl.name.span,
help: (),
});
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,12 +1209,13 @@ pub(crate) struct EiiWithTrackCaller {
}

#[derive(Diagnostic)]
#[diag("`#[{$name}]` required, but not found")]
#[diag("`#[{$name}]` {$kind} required, but not found")]
pub(crate) struct EiiWithoutImpl {
#[primary_span]
#[label("expected because `#[{$name}]` was declared here in crate `{$decl_crate_name}`")]
pub span: Span,
pub name: Symbol,
pub kind: &'static str,

pub current_crate_name: Symbol,
pub decl_crate_name: Symbol,
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,10 @@ impl Resolver<'_, '_> {
&& !tcx.is_panic_runtime(cnum)
&& !tcx.has_global_allocator(cnum)
&& !tcx.has_panic_handler(cnum)
&& tcx.externally_implementable_items(cnum).is_empty()
&& tcx
.externally_implementable_items(cnum)
.values()
.all(|(_, defs)| defs.is_empty())
}) {
maybe_unused_extern_crates.insert(id, import.span);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/eii/auxiliary/unused_extern_crate_decl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@ no-prefer-dynamic
#![crate_type = "rlib"]
#![feature(extern_item_impls)]

#[eii(eii1)]
pub fn decl1(x: u64);
9 changes: 9 additions & 0 deletions tests/ui/eii/auxiliary/unused_extern_crate_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ no-prefer-dynamic
//@ aux-build:unused_extern_crate_decl.rs
#![crate_type = "rlib"]
#![feature(extern_item_impls)]

extern crate unused_extern_crate_decl;

#[unused_extern_crate_decl::eii1]
fn impl1(x: u64) {}
2 changes: 1 addition & 1 deletion tests/ui/eii/dylib_needs_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#![crate_type = "dylib"]
#![feature(extern_item_impls)]

#[eii(eii1)] //~ ERROR `#[eii1]` required, but not found
#[eii(eii1)] //~ ERROR `#[eii1]` function required, but not found
fn decl1(x: u64);
2 changes: 1 addition & 1 deletion tests/ui/eii/dylib_needs_impl.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: `#[eii1]` required, but not found
error: `#[eii1]` function required, but not found
--> $DIR/dylib_needs_impl.rs:6:7
|
LL | #[eii(eii1)]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/eii/privacy2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
extern crate other_crate_privacy2 as codegen;

// has a span but in the other crate
//~? ERROR `#[eii2]` required, but not found
//~? ERROR `#[eii3]` required, but not found
//~? ERROR `#[eii2]` function required, but not found
//~? ERROR `#[eii3]` function required, but not found

#[codegen::eii1]
fn eii1_impl(x: u64) {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/eii/privacy2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ note: the function `decl1` is defined here
LL | fn decl1(x: u64);
| ^^^^^^^^^^^^^^^^^

error: `#[eii2]` required, but not found
error: `#[eii2]` function required, but not found

@jdonszelmann jdonszelmann Jun 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a similar test for statics? To show their analogous error message?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed the test to the wrong branch 🤦

--> $DIR/auxiliary/other_crate_privacy2.rs:9:7
|
LL | #[eii(eii2)]
| ^^^^ expected because `#[eii2]` was declared here in crate `other_crate_privacy2`
|
= help: expected at least one implementation in crate `privacy2` or any of its dependencies

error: `#[eii3]` required, but not found
error: `#[eii3]` function required, but not found
--> $DIR/auxiliary/other_crate_privacy2.rs:13:11
|
LL | #[eii(eii3)]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/eii/shadow_builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![feature(extern_item_impls)]

#[eii(inline)]
//~^ ERROR `#[inline]` required, but not found
//~^ ERROR `#[inline]` function required, but not found
fn test(x: u64);

#[inline]
Expand All @@ -14,4 +14,4 @@ fn test_impl(x: u64) {
println!("{x:?}")
}

fn main() { }
fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/eii/shadow_builtin.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LL | #[eii(inline)]
| ^^^^^^^^^^^^^^
= help: use `crate::inline` to refer to this attribute macro unambiguously

error: `#[inline]` required, but not found
error: `#[inline]` function required, but not found
--> $DIR/shadow_builtin.rs:7:7
|
LL | #[eii(inline)]
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/eii/unused_extern_crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ aux-build:unused_extern_crate_decl.rs
//@ aux-build:unused_extern_crate_impl.rs
// Tests that dependencies that contain an EII decl without any EII impl are
// still considered unused.
#![feature(extern_item_impls)]
#![deny(unused_extern_crates)]

extern crate unused_extern_crate_decl; //~ ERROR unused extern crate
extern crate unused_extern_crate_impl;

fn main() {}
19 changes: 19 additions & 0 deletions tests/ui/eii/unused_extern_crate.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error: unused extern crate
--> $DIR/unused_extern_crate.rs:8:1
|
LL | extern crate unused_extern_crate_decl;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused
|
note: the lint level is defined here
--> $DIR/unused_extern_crate.rs:6:9
|
LL | #![deny(unused_extern_crates)]
| ^^^^^^^^^^^^^^^^^^^^
help: remove the unused `extern crate`
|
LL - extern crate unused_extern_crate_decl;
LL +
|

error: aborting due to 1 previous error

Loading