Skip to content

Remove attribute #[rustc_error] #139122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
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
6 changes: 3 additions & 3 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,9 +1087,9 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
WarnFollowing, EncodeCrossCrate::No
),
rustc_attr!(
TEST, rustc_error, Normal,
template!(Word, List: "delayed_bug_from_inside_query"),
WarnFollowingWordOnly, EncodeCrossCrate::Yes
TEST, rustc_delayed_bug_from_inside_query, Normal,
template!(Word),
WarnFollowing, EncodeCrossCrate::No
),
rustc_attr!(
TEST, rustc_dump_user_args, Normal, template!(Word),
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_interface/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,5 @@ interface_out_dir_error =
interface_proc_macro_crate_panic_abort =
building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic

interface_rustc_error_fatal =
fatal error triggered by #[rustc_error]

interface_rustc_error_unexpected_annotation =
unexpected annotation used with `#[rustc_error(...)]`!

interface_temps_dir_error =
failed to find or create the directory specified by `--temps-dir`
14 changes: 0 additions & 14 deletions compiler/rustc_interface/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,6 @@ pub struct TempsDirError;
#[diag(interface_out_dir_error)]
pub struct OutDirError;

#[derive(Diagnostic)]
#[diag(interface_rustc_error_fatal)]
pub struct RustcErrorFatal {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(interface_rustc_error_unexpected_annotation)]
pub struct RustcErrorUnexpectedAnnotation {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(interface_failed_writing_file)]
pub struct FailedWritingFile<'a> {
Expand Down
42 changes: 6 additions & 36 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,48 +1067,18 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
});
}

/// Check for the `#[rustc_error]` annotation, which forces an error in codegen. This is used
/// to write UI tests that actually test that compilation succeeds without reporting
/// an error.
fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) {
let Some((def_id, _)) = tcx.entry_fn(()) else { return };
for attr in tcx.get_attrs(def_id, sym::rustc_error) {
match attr.meta_item_list() {
// Check if there is a `#[rustc_error(delayed_bug_from_inside_query)]`.
Some(list)
if list.iter().any(|list_item| {
matches!(
list_item.ident().map(|i| i.name),
Some(sym::delayed_bug_from_inside_query)
)
}) =>
{
tcx.ensure_ok().trigger_delayed_bug(def_id);
}

// Bare `#[rustc_error]`.
None => {
tcx.dcx().emit_fatal(errors::RustcErrorFatal { span: tcx.def_span(def_id) });
}

// Some other attribute.
Some(_) => {
tcx.dcx().emit_warn(errors::RustcErrorUnexpectedAnnotation {
span: tcx.def_span(def_id),
});
}
}
}
}

/// Runs the codegen backend, after which the AST and analysis can
/// be discarded.
pub(crate) fn start_codegen<'tcx>(
codegen_backend: &dyn CodegenBackend,
tcx: TyCtxt<'tcx>,
) -> Box<dyn Any> {
// Hook for UI tests.
check_for_rustc_errors_attr(tcx);
// Hook for tests.
if let Some((def_id, _)) = tcx.entry_fn(())
&& tcx.has_attr(def_id, sym::rustc_delayed_bug_from_inside_query)
{
tcx.ensure_ok().trigger_delayed_bug(def_id);
}

// Don't run this test assertions when not doing codegen. Compiletest tries to build
// build-fail tests in check mode first and expects it to not give an error in that case.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/util/bug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>(
pub fn trigger_delayed_bug(tcx: TyCtxt<'_>, key: rustc_hir::def_id::DefId) {
tcx.dcx().span_delayed_bug(
tcx.def_span(key),
"delayed bug triggered by #[rustc_error(delayed_bug_from_inside_query)]",
"delayed bug triggered by #[rustc_delayed_bug_from_inside_query]",
);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,7 @@ symbols! {
rustc_deallocator,
rustc_def_path,
rustc_default_body_unstable,
rustc_delayed_bug_from_inside_query,
rustc_deny_explicit_impl,
rustc_deprecated_safe_2024,
rustc_diagnostic_item,
Expand All @@ -1787,7 +1788,6 @@ symbols! {
rustc_dump_user_args,
rustc_dump_vtable,
rustc_effective_visibility,
rustc_error,
rustc_evaluate_where_clauses,
rustc_expected_cgu_reuse,
rustc_force_inline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,6 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ..."), WarnFollowing),
rustc_attr!(TEST, rustc_abi, Normal, template!(List: "field1, field2, ..."), WarnFollowing),
rustc_attr!(TEST, rustc_regions, Normal, template!(Word), WarnFollowing),
rustc_attr!(
Copy link
Member

@compiler-errors compiler-errors Mar 30, 2025

Choose a reason for hiding this comment

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

Doesn't the rust-analyzer team deal with these attrs themselves? I don't think we typically tweak this lint ourselves from within the rust-lang/rust repo when modifying internal attrs.

Maybe someone like @Veykril would know?

Copy link
Member

@lnicola lnicola Mar 30, 2025

Choose a reason for hiding this comment

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

It's fine. We auto-generate some files, but not that one IIUC. The concern behind that rustbot check is to avoid conflicts on subtree syncs, but it's not a problem in this case and almost nobody follows up with a r-a PR anyway.

It's fine to leave it out too, since it shouldn't harm.

TEST, rustc_error, Normal,
template!(Word, List: "delayed_bug_from_inside_query"), WarnFollowingWordOnly
),
rustc_attr!(TEST, rustc_dump_user_args, Normal, template!(Word), WarnFollowing),
rustc_attr!(TEST, rustc_evaluate_where_clauses, Normal, template!(Word), WarnFollowing),
rustc_attr!(
Expand Down
4 changes: 2 additions & 2 deletions tests/incremental/delayed_span_bug.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//@ revisions: cfail1 cfail2
//@ should-ice
//@ error-pattern: delayed bug triggered by #[rustc_error(delayed_bug_from_inside_query)]
//@ error-pattern: delayed bug triggered by #[rustc_delayed_bug_from_inside_query]

#![feature(rustc_attrs)]

#[rustc_error(delayed_bug_from_inside_query)]
#[rustc_delayed_bug_from_inside_query]
fn main() {}

This file was deleted.

5 changes: 2 additions & 3 deletions tests/ui/associated-types/bound-lifetime-constrained.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ revisions: func object clause ok
//@[ok] check-pass

#![allow(dead_code)]
#![feature(rustc_attrs)]

trait Foo<'a> {
type Item;
Expand Down Expand Up @@ -44,5 +44,4 @@ fn clause2<T>() where T: for<'a> Fn() -> <() as Foo<'a>>::Item {
//[clause]~^ ERROR `Output` references lifetime `'a`
}

#[rustc_error]
fn main() { } //[ok]~ ERROR fatal error triggered by #[rustc_error]
fn main() { }

This file was deleted.

5 changes: 2 additions & 3 deletions tests/ui/associated-types/bound-lifetime-in-binding-only.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ revisions: angle paren ok elision
//@[ok] check-pass

#![allow(dead_code)]
#![feature(rustc_attrs)]
#![feature(unboxed_closures)]

trait Foo {
Expand Down Expand Up @@ -67,5 +67,4 @@ fn ok2<T: for<'a,'b> Fn<(&'b Parameterized<'a>,), Output=&'a i32>>() {
fn ok3<T>() where for<'a> Parameterized<'a>: Foo<Item=&'a i32> {
}

#[rustc_error]
fn main() { } //[ok]~ ERROR fatal error triggered by #[rustc_error]
fn main() { }

This file was deleted.

5 changes: 2 additions & 3 deletions tests/ui/associated-types/bound-lifetime-in-return-only.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ revisions: sig local structure ok elision
//@[ok] check-pass

#![allow(dead_code)]
#![feature(rustc_attrs)]
#![feature(unboxed_closures)]

trait Foo {
Expand Down Expand Up @@ -45,5 +45,4 @@ fn ok1(_: &dyn for<'a> Fn(&Parameterized<'a>) -> &'a i32) {
fn ok2(_: &dyn for<'a,'b> Fn<(&'b Parameterized<'a>,), Output=&'a i32>) {
}

#[rustc_error]
fn main() { } //[ok]~ ERROR fatal error triggered by #[rustc_error]
fn main() { }
3 changes: 1 addition & 2 deletions tests/ui/borrowck/borrowck-report-with-custom-diagnostic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(rustc_attrs)]
#![allow(dead_code)]
fn main() { #![rustc_error] // rust-lang/rust#49855
fn main() {
// Original borrow ends at end of function
let mut x = 1;
let y = &mut x;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-report-with-custom-diagnostic.rs:8:13
--> $DIR/borrowck-report-with-custom-diagnostic.rs:7:13
|
LL | let y = &mut x;
| ------ mutable borrow occurs here
Expand All @@ -11,7 +11,7 @@ LL | y.use_mut();
| - mutable borrow later used here

error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-report-with-custom-diagnostic.rs:21:21
--> $DIR/borrowck-report-with-custom-diagnostic.rs:20:21
|
LL | let y = &x;
| -- immutable borrow occurs here
Expand All @@ -23,7 +23,7 @@ LL | y.use_ref();
| - immutable borrow later used here

error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-report-with-custom-diagnostic.rs:36:17
--> $DIR/borrowck-report-with-custom-diagnostic.rs:35:17
|
LL | let y = &mut x;
| ------ first mutable borrow occurs here
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/borrowck/mut-borrow-outside-loop.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ensure borrowck messages are correct outside special case
#![feature(rustc_attrs)]
fn main() { #![rustc_error] // rust-lang/rust#49855

fn main() {
let mut void = ();

let first = &mut void;
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/codemap_tests/issue-11715.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(rustc_attrs)]
fn main() { #![rustc_error] // rust-lang/rust#49855
fn main() {
let mut x = "foo";
let y = &mut x;
let z = &mut x; //~ ERROR cannot borrow
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/codemap_tests/issue-11715.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/issue-11715.rs:5:13
--> $DIR/issue-11715.rs:4:13
|
LL | let y = &mut x;
| ------ first mutable borrow occurs here
Expand Down
5 changes: 2 additions & 3 deletions tests/ui/consts/async-block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

//@ edition:2018
//@ revisions: with_feature without_feature
//@[with_feature] check-pass

#![feature(rustc_attrs)]
#![cfg_attr(with_feature, feature(const_async_blocks))]

use std::future::Future;
Expand All @@ -15,5 +15,4 @@ const _: i32 = { core::mem::ManuallyDrop::new(async { 0 }); 4 };
static _FUT: &(dyn Future<Output = ()> + Sync) = &async {};
//[without_feature]~^ `async` block

#[rustc_error]
fn main() {} //[with_feature]~ fatal error triggered by #[rustc_error]
fn main() {}
8 changes: 0 additions & 8 deletions tests/ui/consts/async-block.with_feature.stderr

This file was deleted.

10 changes: 6 additions & 4 deletions tests/ui/diagnostic-flags/allow-non-lint-warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
//! - Original impl PR: <https://github.com/rust-lang/rust/pull/21248>.
//! - RFC 507 "Release channels":
//! <https://github.com/rust-lang/rfcs/blob/c017755b9bfa0421570d92ba38082302e0f3ad4f/text/0507-release-channels.md>.
#![feature(rustc_attrs)]

//@ revisions: without_flag with_flag

//@ check-pass
//@ compile-flags: -Zunleash-the-miri-inside-of-you
//@[with_flag] compile-flags: -Awarnings

//@ check-pass
fn non_constant() {}
const fn constant() { non_constant() }

#[rustc_error(warn)]
fn main() {}
//[without_flag]~^ WARN unexpected annotation used with `#[rustc_error(...)]`!

//[without_flag]~? WARN skipping const checks
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
warning: unexpected annotation used with `#[rustc_error(...)]`!
--> $DIR/allow-non-lint-warnings.rs:25:1
warning: skipping const checks
|
LL | fn main() {}
| ^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/allow-non-lint-warnings.rs:24:23
|
LL | const fn constant() { non_constant() }
| ^^^^^^^^^^^^^^

warning: 1 warning emitted

1 change: 0 additions & 1 deletion tests/ui/feature-gates/feature-gate-rustc-attrs-1.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Test that `#[rustc_*]` attributes are gated by `rustc_attrs` feature gate.

#[rustc_variance] //~ ERROR the `#[rustc_variance]` attribute is just used for rustc unit tests and will never be stable
#[rustc_error] //~ ERROR the `#[rustc_error]` attribute is just used for rustc unit tests and will never be stable
#[rustc_nonnull_optimization_guaranteed] //~ ERROR the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to document guaranteed niche optimizations in libcore and libstd and will never be stable

fn main() {}
13 changes: 2 additions & 11 deletions tests/ui/feature-gates/feature-gate-rustc-attrs-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,16 @@ LL | #[rustc_variance]
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: the `#[rustc_error]` attribute is just used for rustc unit tests and will never be stable
--> $DIR/feature-gate-rustc-attrs-1.rs:4:1
|
LL | #[rustc_error]
| ^^^^^^^^^^^^^^
|
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to document guaranteed niche optimizations in libcore and libstd and will never be stable
(note that the compiler does not even check whether the type indeed is being non-null-optimized; it is your responsibility to ensure that the attribute is only used on types that are optimized)
--> $DIR/feature-gate-rustc-attrs-1.rs:5:1
--> $DIR/feature-gate-rustc-attrs-1.rs:4:1
|
LL | #[rustc_nonnull_optimization_guaranteed]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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

For more information about this error, try `rustc --explain E0658`.
5 changes: 2 additions & 3 deletions tests/ui/mir/issue-75053.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ check-pass
//@ compile-flags: -Z mir-opt-level=3

#![feature(type_alias_impl_trait, rustc_attrs)]
#![feature(type_alias_impl_trait)]

use std::marker::PhantomData;

Expand Down Expand Up @@ -43,8 +44,6 @@ impl<T: MyFrom<Phantom2<DummyT<U>>>, U> MyIndex<Phantom1<T>> for Scope<U> {
}
}

#[rustc_error]
fn main() {
//~^ ERROR
let _pos: Phantom1<DummyT<()>> = Scope::new().my_index();
}
Loading
Loading