Skip to content

Commit 98fcb6c

Browse files
committed
Emit DOC_INCLUDE lint instead of a hard warning
1 parent 53c4de3 commit 98fcb6c

File tree

8 files changed

+95
-46
lines changed

8 files changed

+95
-46
lines changed

compiler/rustc_lint_defs/src/lib.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -448,17 +448,24 @@ macro_rules! declare_tool_lint {
448448
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
449449
$(, @future_incompatible = FutureIncompatibleInfo { $($field:ident : $val:expr),* $(,)* }; )?
450450
) => (
451-
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false}
451+
$crate::declare_tool_lint!{
452+
$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false
453+
$(, @future_incompatible = FutureIncompatibleInfo { $($field : $val),* };)?
454+
}
452455
);
453456
(
454457
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
455458
report_in_external_macro: $rep:expr
459+
$(, @future_incompatible = FutureIncompatibleInfo { $($field:ident : $val:expr),* $(,)* }; )?
456460
) => (
457-
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep}
461+
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep
462+
$(, @future_incompatible = FutureIncompatibleInfo { $($field:ident : $val:expr),* $(,)* }; )?
463+
}
458464
);
459465
(
460466
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
461467
$external:expr
468+
$(, @future_incompatible = FutureIncompatibleInfo { $($field:ident : $val:expr),* $(,)* }; )?
462469
) => (
463470
$(#[$attr])*
464471
$vis static $NAME: &$crate::Lint = &$crate::Lint {
@@ -467,10 +474,14 @@ macro_rules! declare_tool_lint {
467474
desc: $desc,
468475
edition_lint_opts: None,
469476
report_in_external_macro: $external,
470-
future_incompatible: None,
477+
$(future_incompatible: Some($crate::FutureIncompatibleInfo {
478+
$($field: $val,)*
479+
..$crate::FutureIncompatibleInfo::default_fields_for_macro()
480+
}),)?
471481
is_plugin: true,
472482
feature_gate: None,
473483
crate_level_only: false,
484+
..$crate::Lint::default_fields_for_macro()
474485
};
475486
);
476487
}

src/doc/rustdoc/src/lints.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,22 @@ error in a future release.
340340

341341
```rust
342342
#![feature(external_doc)]
343-
#[doc(include = "README.md")]
344-
pub fn foo() {}
343+
#![doc(include = "./external-doc.rs")]
344+
```
345+
346+
Which will give:
347+
348+
```text
349+
warning: `#[doc(include)]` is deprecated and will be removed in a future release
350+
--> external-doc.rs:2:1
351+
|
352+
2 | #![doc(include = "./external-doc.rs")]
353+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
354+
|
355+
= note: `#[warn(rustdoc::doc_include)]` on by default
356+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
357+
= note: for more information, see issue #44732 <https://github.com/rust-lang/rust/issues/44732>
358+
help: use `#![feature(extended_key_value_attributes)]` instead
359+
|
360+
2 | #![doc = include_str!("./external-doc.rs")]
345361
```

src/librustdoc/clean/inline.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHashSet;
77
use rustc_hir as hir;
88
use rustc_hir::def::{DefKind, Res};
99
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
10-
use rustc_hir::Mutability;
10+
use rustc_hir::{HirId, Mutability};
1111
use rustc_metadata::creader::LoadedMacro;
1212
use rustc_middle::ty::{self, TyCtxt};
1313
use rustc_mir::const_eval::is_min_const_fn;
@@ -122,7 +122,8 @@ crate fn try_inline(
122122
};
123123

124124
let target_attrs = load_attrs(cx, did);
125-
let attrs = box merge_attrs(cx, Some(parent_module), target_attrs, attrs_clone, did.is_local());
125+
let local_item = DocContext::as_local_hir_id(cx.tcx, did);
126+
let attrs = box merge_attrs(cx, Some(parent_module), target_attrs, attrs_clone, local_item);
126127

127128
cx.inlined.insert(did);
128129
let what_rustc_thinks = clean::Item::from_def_id_and_parts(did, Some(name), kind, cx);
@@ -290,22 +291,22 @@ fn merge_attrs(
290291
parent_module: Option<DefId>,
291292
old_attrs: Attrs<'_>,
292293
new_attrs: Option<Attrs<'_>>,
293-
local: bool,
294+
item: Option<HirId>,
294295
) -> clean::Attributes {
295296
// NOTE: If we have additional attributes (from a re-export),
296297
// always insert them first. This ensure that re-export
297298
// doc comments show up before the original doc comments
298299
// when we render them.
299300
if let Some(inner) = new_attrs {
300301
if let Some(new_id) = parent_module {
301-
Attributes::from_ast(cx.tcx, old_attrs, Some((inner, new_id)), local)
302+
Attributes::from_ast(cx.tcx, old_attrs, Some((inner, new_id)), item)
302303
} else {
303304
let mut both = inner.to_vec();
304305
both.extend_from_slice(old_attrs);
305-
clean_attrs(&both, local, cx)
306+
clean_attrs(&both, item, cx)
306307
}
307308
} else {
308-
clean_attrs(old_attrs, local, cx)
309+
clean_attrs(old_attrs, item, cx)
309310
}
310311
}
311312

@@ -416,8 +417,8 @@ crate fn build_impl(
416417

417418
debug!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id());
418419

419-
let attrs =
420-
box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs, did.is_local());
420+
let local_item = DocContext::as_local_hir_id(tcx, did);
421+
let attrs = box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs, local_item);
421422
debug!("merged_attrs={:?}", attrs);
422423

423424
ret.push(clean::Item::from_def_id_and_attrs_and_parts(

src/librustdoc/clean/mod.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1515
use rustc_hir as hir;
1616
use rustc_hir::def::{CtorKind, DefKind, Res};
1717
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
18+
use rustc_hir::HirId;
1819
use rustc_index::vec::{Idx, IndexVec};
1920
use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
2021
use rustc_middle::bug;
@@ -110,7 +111,7 @@ impl Clean<ExternalCrate> for CrateNum {
110111
if let Res::Def(DefKind::Mod, def_id) = res {
111112
// We already warned about any attributes on the module when cleaning it.
112113
// Don't warn a second time.
113-
let attrs = clean_attrs(cx.tcx.get_attrs(def_id), false, cx);
114+
let attrs = clean_attrs(cx.tcx.get_attrs(def_id), None, cx);
114115
let mut prim = None;
115116
for attr in attrs.lists(sym::doc) {
116117
if let Some(v) = attr.value_str() {
@@ -157,7 +158,7 @@ impl Clean<ExternalCrate> for CrateNum {
157158

158159
let mut as_keyword = |res: Res| {
159160
if let Res::Def(DefKind::Mod, def_id) = res {
160-
let attrs = clean_attrs(tcx.get_attrs(def_id), false, cx);
161+
let attrs = clean_attrs(tcx.get_attrs(def_id), None, cx);
161162
let mut keyword = None;
162163
for attr in attrs.lists(sym::doc) {
163164
if attr.has_name(sym::keyword) {
@@ -200,7 +201,7 @@ impl Clean<ExternalCrate> for CrateNum {
200201
name: tcx.crate_name(*self),
201202
src: krate_src,
202203
// The local crate was already cleaned, and all other crates are non-local.
203-
attrs: clean_attrs(tcx.get_attrs(root), false, cx),
204+
attrs: clean_attrs(tcx.get_attrs(root), None, cx),
204205
primitives,
205206
keywords,
206207
}
@@ -240,7 +241,11 @@ impl Clean<Item> for doctree::Module<'_> {
240241
}
241242
}
242243

243-
fn clean_attrs(attrs: &[ast::Attribute], local: bool, cx: &mut DocContext<'_>) -> Attributes {
244+
fn clean_attrs(
245+
attrs: &[ast::Attribute],
246+
local: Option<HirId>,
247+
cx: &mut DocContext<'_>,
248+
) -> Attributes {
244249
Attributes::from_ast(cx.tcx, attrs, None, local)
245250
}
246251

@@ -2125,7 +2130,7 @@ fn clean_extern_crate(
21252130
// FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason
21262131
vec![Item {
21272132
name: Some(name),
2128-
attrs: box clean_attrs(attrs, true, cx),
2133+
attrs: box clean_attrs(attrs, Some(krate.hir_id()), cx),
21292134
span: krate.span.clean(cx),
21302135
def_id: crate_def_id,
21312136
visibility: krate.vis.clean(cx),

src/librustdoc/clean/types.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_hir as hir;
2121
use rustc_hir::def::{CtorKind, Res};
2222
use rustc_hir::def_id::{CrateNum, DefId, DefIndex};
2323
use rustc_hir::lang_items::LangItem;
24+
use rustc_hir::HirId;
2425
use rustc_hir::{BodyId, Mutability};
2526
use rustc_index::vec::IndexVec;
2627
use rustc_middle::ty::{self, TyCtxt};
@@ -150,11 +151,12 @@ impl Item {
150151
kind: ItemKind,
151152
cx: &mut DocContext<'_>,
152153
) -> Item {
154+
let local_item = DocContext::as_local_hir_id(cx.tcx, def_id);
153155
Self::from_def_id_and_attrs_and_parts(
154156
def_id,
155157
name,
156158
kind,
157-
box clean_attrs(cx.tcx.get_attrs(def_id), def_id.is_local(), cx),
159+
box clean_attrs(cx.tcx.get_attrs(def_id), local_item, cx),
158160
cx,
159161
)
160162
}
@@ -742,7 +744,7 @@ impl Attributes {
742744
tcx: TyCtxt<'_>,
743745
attrs: &[ast::Attribute],
744746
additional_attrs: Option<(&[ast::Attribute], DefId)>,
745-
local: bool,
747+
item: Option<HirId>,
746748
) -> Attributes {
747749
let mut doc_strings: Vec<DocFragment> = vec![];
748750
let mut sp = None;
@@ -805,20 +807,21 @@ impl Attributes {
805807
}
806808
} else if let Some((filename, contents)) = Attributes::extract_include(&mi)
807809
{
808-
if local {
809-
let mut diag = handler
810-
.struct_span_warn(attr.span, "`doc(include)` is deprecated");
811-
diag.span_suggestion_verbose(
812-
attr.span,
813-
"use `#![feature(extended_key_value_attributes)]` instead",
814-
format!(
815-
"#{}[doc = include_str!(\"{}\")]",
816-
if attr.style == AttrStyle::Inner { "!" } else { "" },
817-
filename,
818-
),
819-
Applicability::MaybeIncorrect,
820-
);
821-
diag.emit();
810+
if let Some(hir_id) = item {
811+
tcx.struct_span_lint_hir(crate::lint::DOC_INCLUDE, hir_id, attr.span, |lint_builder| {
812+
let mut diag = lint_builder.build("`#[doc(include)]` is deprecated and will be removed in a future release");
813+
diag.span_suggestion_verbose(
814+
attr.span,
815+
"use `#![feature(extended_key_value_attributes)]` instead",
816+
format!(
817+
"#{}[doc = include_str!(\"{}\")]",
818+
if attr.style == AttrStyle::Inner { "!" } else { "" },
819+
filename,
820+
),
821+
Applicability::MaybeIncorrect,
822+
);
823+
diag.emit();
824+
});
822825
}
823826

824827
let line = doc_line;

src/librustdoc/doctest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ impl<'a, 'hir, 'tcx> HirCollector<'a, 'hir, 'tcx> {
10931093
nested: F,
10941094
) {
10951095
let attrs = self.tcx.hir().attrs(hir_id);
1096-
let mut attrs = Attributes::from_ast(self.tcx, attrs, None, true);
1096+
let mut attrs = Attributes::from_ast(self.tcx, attrs, None, Some(hir_id));
10971097
if let Some(ref cfg) = attrs.cfg {
10981098
if !cfg.matches(&self.sess.parse_sess, Some(&self.sess.features_untracked())) {
10991099
return;
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
// aux-build:doc-include-deprecated.rs
22
// check-pass
33
#![feature(external_doc)]
4-
#![doc(include = "auxiliary/docs.md")] //~ WARNING deprecated
4+
#![doc(include = "auxiliary/docs.md")]
5+
//~^ WARNING deprecated
6+
//~| WARNING hard error in a future release
57

68
extern crate inner;
79

810
pub use inner::HasDocInclude;
911

10-
#[doc(include = "auxiliary/docs.md")] //~ WARNING deprecated
12+
#[doc(include = "auxiliary/docs.md")]
13+
//~^ WARNING deprecated
14+
//~| WARNING hard error in a future release
1115
pub use inner::HasDocInclude as _;
1216

13-
#[doc(include = "auxiliary/docs.md")] //~ WARNING deprecated
17+
#[doc(include = "auxiliary/docs.md")]
18+
//~^ WARNING deprecated
19+
//~| WARNING hard error in a future release
1420
pub use inner::NoDocs;
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1-
warning: `doc(include)` is deprecated
2-
--> $DIR/doc-include-deprecated.rs:10:1
1+
warning: `#[doc(include)]` is deprecated and will be removed in a future release
2+
--> $DIR/doc-include-deprecated.rs:12:1
33
|
44
LL | #[doc(include = "auxiliary/docs.md")]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7+
= note: `#[warn(rustdoc::doc_include)]` on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #44732 <https://github.com/rust-lang/rust/issues/44732>
710
help: use `#![feature(extended_key_value_attributes)]` instead
811
|
912
LL | #[doc = include_str!("auxiliary/docs.md")]
10-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
|
1114

12-
warning: `doc(include)` is deprecated
13-
--> $DIR/doc-include-deprecated.rs:13:1
15+
warning: `#[doc(include)]` is deprecated and will be removed in a future release
16+
--> $DIR/doc-include-deprecated.rs:17:1
1417
|
1518
LL | #[doc(include = "auxiliary/docs.md")]
1619
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1720
|
21+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
22+
= note: for more information, see issue #44732 <https://github.com/rust-lang/rust/issues/44732>
1823
help: use `#![feature(extended_key_value_attributes)]` instead
1924
|
2025
LL | #[doc = include_str!("auxiliary/docs.md")]
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
|
2227

23-
warning: `doc(include)` is deprecated
28+
warning: `#[doc(include)]` is deprecated and will be removed in a future release
2429
--> $DIR/doc-include-deprecated.rs:4:1
2530
|
2631
LL | #![doc(include = "auxiliary/docs.md")]
2732
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2833
|
34+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
35+
= note: for more information, see issue #44732 <https://github.com/rust-lang/rust/issues/44732>
2936
help: use `#![feature(extended_key_value_attributes)]` instead
3037
|
3138
LL | #![doc = include_str!("auxiliary/docs.md")]
32-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39+
|
3340

3441
warning: 3 warnings emitted
3542

0 commit comments

Comments
 (0)