Skip to content

Commit 4b2e4e6

Browse files
committed
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.
1 parent edeee91 commit 4b2e4e6

File tree

5 files changed

+54
-17
lines changed

5 files changed

+54
-17
lines changed

compiler/rustc_passes/src/check_attr.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -567,16 +567,23 @@ impl CheckAttrVisitor<'tcx> {
567567
.iter()
568568
.any(|m| i_meta.has_name(*m))
569569
{
570-
self.tcx
571-
.sess
572-
.struct_span_err(
573-
meta.span(),
574-
&format!(
570+
self.tcx.struct_span_lint_hir(
571+
UNUSED_ATTRIBUTES,
572+
hir_id,
573+
i_meta.span,
574+
|lint| {
575+
lint.build(&format!(
575576
"unknown `doc` attribute `{}`",
576-
i_meta.name_or_empty(),
577-
),
578-
)
579-
.emit();
577+
i_meta.name_or_empty()
578+
))
579+
.warn(
580+
"this was previously accepted by the compiler but is \
581+
being phased out; it will become a hard error in \
582+
a future release!",
583+
)
584+
.emit();
585+
},
586+
);
580587
return false;
581588
}
582589
}

src/test/rustdoc-ui/doc-attr.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#![crate_type = "lib"]
2-
#![doc(as_ptr)] //~ ERROR
2+
#![deny(unused_attributes)]
3+
//~^ NOTE lint level is defined here
4+
#![doc(as_ptr)]
5+
//~^ ERROR unknown `doc` attribute
6+
//~| WARNING will become a hard error in a future release
37

4-
#[doc(as_ptr)] //~ ERROR
8+
#[doc(as_ptr)]
9+
//~^ ERROR unknown `doc` attribute
10+
//~| WARNING will become a hard error in a future release
511
pub fn foo() {}

src/test/rustdoc-ui/doc-attr.stderr

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
error: unknown `doc` attribute `as_ptr`
2-
--> $DIR/doc-attr.rs:4:7
2+
--> $DIR/doc-attr.rs:8:7
33
|
44
LL | #[doc(as_ptr)]
55
| ^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/doc-attr.rs:2:9
9+
|
10+
LL | #![deny(unused_attributes)]
11+
| ^^^^^^^^^^^^^^^^^
12+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
613

714
error: unknown `doc` attribute `as_ptr`
8-
--> $DIR/doc-attr.rs:2:8
15+
--> $DIR/doc-attr.rs:4:8
916
|
1017
LL | #![doc(as_ptr)]
1118
| ^^^^^^
19+
|
20+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1221

1322
error: aborting due to 2 previous errors
1423

src/test/ui/attributes/doc-attr.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#![crate_type = "lib"]
2-
#![doc(as_ptr)] //~ ERROR
2+
#![deny(unused_attributes)]
3+
//~^ NOTE lint level is defined here
4+
#![doc(as_ptr)]
5+
//~^ ERROR unknown `doc` attribute
6+
//~| WARNING will become a hard error in a future release
37

4-
#[doc(as_ptr)] //~ ERROR
8+
#[doc(as_ptr)]
9+
//~^ ERROR unknown `doc` attribute
10+
//~| WARNING will become a hard error in a future release
511
pub fn foo() {}
+11-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
error: unknown `doc` attribute `as_ptr`
2-
--> $DIR/doc-attr.rs:4:7
2+
--> $DIR/doc-attr.rs:8:7
33
|
44
LL | #[doc(as_ptr)]
55
| ^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/doc-attr.rs:2:9
9+
|
10+
LL | #![deny(unused_attributes)]
11+
| ^^^^^^^^^^^^^^^^^
12+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
613

714
error: unknown `doc` attribute `as_ptr`
8-
--> $DIR/doc-attr.rs:2:8
15+
--> $DIR/doc-attr.rs:4:8
916
|
1017
LL | #![doc(as_ptr)]
1118
| ^^^^^^
19+
|
20+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1221

1322
error: aborting due to 2 previous errors
1423

0 commit comments

Comments
 (0)