From 4b2e4e69dfbf75222ae547659e999cee05833de9 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 2 Mar 2021 09:42:32 -0500 Subject: [PATCH] Change error about unknown doc attributes to a warning This prevents breakage across the ecosystem, since the error was just introduced recently without first having a warning period. --- compiler/rustc_passes/src/check_attr.rs | 25 ++++++++++++++++--------- src/test/rustdoc-ui/doc-attr.rs | 10 ++++++++-- src/test/rustdoc-ui/doc-attr.stderr | 13 +++++++++++-- src/test/ui/attributes/doc-attr.rs | 10 ++++++++-- src/test/ui/attributes/doc-attr.stderr | 13 +++++++++++-- 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index afd1642bbd57c..39245ea77e52c 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -567,16 +567,23 @@ impl CheckAttrVisitor<'tcx> { .iter() .any(|m| i_meta.has_name(*m)) { - self.tcx - .sess - .struct_span_err( - meta.span(), - &format!( + self.tcx.struct_span_lint_hir( + UNUSED_ATTRIBUTES, + hir_id, + i_meta.span, + |lint| { + lint.build(&format!( "unknown `doc` attribute `{}`", - i_meta.name_or_empty(), - ), - ) - .emit(); + i_meta.name_or_empty() + )) + .warn( + "this was previously accepted by the compiler but is \ + being phased out; it will become a hard error in \ + a future release!", + ) + .emit(); + }, + ); return false; } } diff --git a/src/test/rustdoc-ui/doc-attr.rs b/src/test/rustdoc-ui/doc-attr.rs index 37c69a214b8ed..3519b5707b375 100644 --- a/src/test/rustdoc-ui/doc-attr.rs +++ b/src/test/rustdoc-ui/doc-attr.rs @@ -1,5 +1,11 @@ #![crate_type = "lib"] -#![doc(as_ptr)] //~ ERROR +#![deny(unused_attributes)] +//~^ NOTE lint level is defined here +#![doc(as_ptr)] +//~^ ERROR unknown `doc` attribute +//~| WARNING will become a hard error in a future release -#[doc(as_ptr)] //~ ERROR +#[doc(as_ptr)] +//~^ ERROR unknown `doc` attribute +//~| WARNING will become a hard error in a future release pub fn foo() {} diff --git a/src/test/rustdoc-ui/doc-attr.stderr b/src/test/rustdoc-ui/doc-attr.stderr index 17bc3d6a45a05..9666db2b10e01 100644 --- a/src/test/rustdoc-ui/doc-attr.stderr +++ b/src/test/rustdoc-ui/doc-attr.stderr @@ -1,14 +1,23 @@ error: unknown `doc` attribute `as_ptr` - --> $DIR/doc-attr.rs:4:7 + --> $DIR/doc-attr.rs:8:7 | LL | #[doc(as_ptr)] | ^^^^^^ + | +note: the lint level is defined here + --> $DIR/doc-attr.rs:2:9 + | +LL | #![deny(unused_attributes)] + | ^^^^^^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: unknown `doc` attribute `as_ptr` - --> $DIR/doc-attr.rs:2:8 + --> $DIR/doc-attr.rs:4:8 | LL | #![doc(as_ptr)] | ^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: aborting due to 2 previous errors diff --git a/src/test/ui/attributes/doc-attr.rs b/src/test/ui/attributes/doc-attr.rs index 37c69a214b8ed..3519b5707b375 100644 --- a/src/test/ui/attributes/doc-attr.rs +++ b/src/test/ui/attributes/doc-attr.rs @@ -1,5 +1,11 @@ #![crate_type = "lib"] -#![doc(as_ptr)] //~ ERROR +#![deny(unused_attributes)] +//~^ NOTE lint level is defined here +#![doc(as_ptr)] +//~^ ERROR unknown `doc` attribute +//~| WARNING will become a hard error in a future release -#[doc(as_ptr)] //~ ERROR +#[doc(as_ptr)] +//~^ ERROR unknown `doc` attribute +//~| WARNING will become a hard error in a future release pub fn foo() {} diff --git a/src/test/ui/attributes/doc-attr.stderr b/src/test/ui/attributes/doc-attr.stderr index 17bc3d6a45a05..9666db2b10e01 100644 --- a/src/test/ui/attributes/doc-attr.stderr +++ b/src/test/ui/attributes/doc-attr.stderr @@ -1,14 +1,23 @@ error: unknown `doc` attribute `as_ptr` - --> $DIR/doc-attr.rs:4:7 + --> $DIR/doc-attr.rs:8:7 | LL | #[doc(as_ptr)] | ^^^^^^ + | +note: the lint level is defined here + --> $DIR/doc-attr.rs:2:9 + | +LL | #![deny(unused_attributes)] + | ^^^^^^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: unknown `doc` attribute `as_ptr` - --> $DIR/doc-attr.rs:2:8 + --> $DIR/doc-attr.rs:4:8 | LL | #![doc(as_ptr)] | ^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: aborting due to 2 previous errors