Skip to content

Commit d3e1ccd

Browse files
committed
Auto merge of #149247 - jhpratt:rollup-mq8f5wo, r=jhpratt
Rollup of 3 pull requests Successful merges: - #149179 (Add regression test for 128705) - #149197 (validate usage of crate-level doc attributes) - #149232 (Add doc aliases "vector" and "list" to `Vec`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c23ed3e + b758cbd commit d3e1ccd

File tree

8 files changed

+157
-2
lines changed

8 files changed

+157
-2
lines changed

compiler/rustc_passes/messages.ftl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ passes_doc_alias_not_string_literal =
126126
passes_doc_alias_start_end =
127127
{$attr_str} cannot start or end with ' '
128128
129+
passes_doc_attr_expects_no_value =
130+
`doc({$attr_name})` does not accept a value
131+
.suggestion = use `doc({$attr_name})`
132+
133+
passes_doc_attr_expects_string =
134+
`doc({$attr_name})` expects a string value
135+
.suggestion = use `doc({$attr_name} = "...")`
136+
129137
passes_doc_attr_not_crate_level =
130138
`#![doc({$attr_name} = "...")]` isn't allowed as a crate-level attribute
131139

compiler/rustc_passes/src/check_attr.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,28 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11231123
true
11241124
}
11251125

1126+
fn check_doc_attr_string_value(&self, meta: &MetaItemInner, hir_id: HirId) {
1127+
if meta.value_str().is_none() {
1128+
self.tcx.emit_node_span_lint(
1129+
INVALID_DOC_ATTRIBUTES,
1130+
hir_id,
1131+
meta.span(),
1132+
errors::DocAttrExpectsString { attr_name: meta.name().unwrap() },
1133+
);
1134+
}
1135+
}
1136+
1137+
fn check_doc_attr_no_value(&self, meta: &MetaItemInner, hir_id: HirId) {
1138+
if !meta.is_word() {
1139+
self.tcx.emit_node_span_lint(
1140+
INVALID_DOC_ATTRIBUTES,
1141+
hir_id,
1142+
meta.span(),
1143+
errors::DocAttrExpectsNoValue { attr_name: meta.name().unwrap() },
1144+
);
1145+
}
1146+
}
1147+
11261148
/// Checks that `doc(test(...))` attribute contains only valid attributes and are at the right place.
11271149
fn check_test_attr(
11281150
&self,
@@ -1293,10 +1315,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12931315
| sym::html_logo_url
12941316
| sym::html_playground_url
12951317
| sym::issue_tracker_base_url
1296-
| sym::html_root_url
1297-
| sym::html_no_source,
1318+
| sym::html_root_url,
12981319
) => {
12991320
self.check_attr_crate_level(attr_span, style, meta, hir_id);
1321+
self.check_doc_attr_string_value(meta, hir_id);
1322+
}
1323+
1324+
Some(sym::html_no_source) => {
1325+
self.check_attr_crate_level(attr_span, style, meta, hir_id);
1326+
self.check_doc_attr_no_value(meta, hir_id);
13001327
}
13011328

13021329
Some(sym::auto_cfg) => {

compiler/rustc_passes/src/errors.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ pub(crate) struct IncorrectDoNotRecommendLocation;
2424
#[diag(passes_incorrect_do_not_recommend_args)]
2525
pub(crate) struct DoNotRecommendDoesNotExpectArgs;
2626

27+
#[derive(LintDiagnostic)]
28+
#[diag(passes_doc_attr_expects_string)]
29+
pub(crate) struct DocAttrExpectsString {
30+
pub(crate) attr_name: Symbol,
31+
}
32+
33+
#[derive(LintDiagnostic)]
34+
#[diag(passes_doc_attr_expects_no_value)]
35+
pub(crate) struct DocAttrExpectsNoValue {
36+
pub(crate) attr_name: Symbol,
37+
}
38+
2739
#[derive(Diagnostic)]
2840
#[diag(passes_autodiff_attr)]
2941
pub(crate) struct AutoDiffAttr {

library/alloc/src/vec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ mod spec_extend;
433433
#[stable(feature = "rust1", since = "1.0.0")]
434434
#[rustc_diagnostic_item = "Vec"]
435435
#[rustc_insignificant_dtor]
436+
#[doc(alias = "list")]
437+
#[doc(alias = "vector")]
436438
pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
437439
buf: RawVec<T, A>,
438440
len: usize,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// regression test for https://github.com/rust-lang/rust/issues/149187
2+
3+
#![doc(html_favicon_url)] //~ ERROR: `doc(html_favicon_url)` expects a string value [invalid_doc_attributes]
4+
#![doc(html_logo_url)] //~ ERROR: `doc(html_logo_url)` expects a string value [invalid_doc_attributes]
5+
#![doc(html_playground_url)] //~ ERROR: `doc(html_playground_url)` expects a string value [invalid_doc_attributes]
6+
#![doc(issue_tracker_base_url)] //~ ERROR expects a string value
7+
#![doc(html_favicon_url = 1)] //~ ERROR expects a string value
8+
#![doc(html_logo_url = 2)] //~ ERROR expects a string value
9+
#![doc(html_playground_url = 3)] //~ ERROR expects a string value
10+
#![doc(issue_tracker_base_url = 4)] //~ ERROR expects a string value
11+
#![doc(html_no_source = "asdf")] //~ ERROR `doc(html_no_source)` does not accept a value [invalid_doc_attributes]
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
error: `doc(html_favicon_url)` expects a string value
2+
--> $DIR/bad-render-options.rs:3:8
3+
|
4+
LL | #![doc(html_favicon_url)]
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[deny(invalid_doc_attributes)]` on by default
8+
9+
error: `doc(html_logo_url)` expects a string value
10+
--> $DIR/bad-render-options.rs:4:8
11+
|
12+
LL | #![doc(html_logo_url)]
13+
| ^^^^^^^^^^^^^
14+
15+
error: `doc(html_playground_url)` expects a string value
16+
--> $DIR/bad-render-options.rs:5:8
17+
|
18+
LL | #![doc(html_playground_url)]
19+
| ^^^^^^^^^^^^^^^^^^^
20+
21+
error: `doc(issue_tracker_base_url)` expects a string value
22+
--> $DIR/bad-render-options.rs:6:8
23+
|
24+
LL | #![doc(issue_tracker_base_url)]
25+
| ^^^^^^^^^^^^^^^^^^^^^^
26+
27+
error: `doc(html_favicon_url)` expects a string value
28+
--> $DIR/bad-render-options.rs:7:8
29+
|
30+
LL | #![doc(html_favicon_url = 1)]
31+
| ^^^^^^^^^^^^^^^^^^^^
32+
33+
error: `doc(html_logo_url)` expects a string value
34+
--> $DIR/bad-render-options.rs:8:8
35+
|
36+
LL | #![doc(html_logo_url = 2)]
37+
| ^^^^^^^^^^^^^^^^^
38+
39+
error: `doc(html_playground_url)` expects a string value
40+
--> $DIR/bad-render-options.rs:9:8
41+
|
42+
LL | #![doc(html_playground_url = 3)]
43+
| ^^^^^^^^^^^^^^^^^^^^^^^
44+
45+
error: `doc(issue_tracker_base_url)` expects a string value
46+
--> $DIR/bad-render-options.rs:10:8
47+
|
48+
LL | #![doc(issue_tracker_base_url = 4)]
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
51+
error: `doc(html_no_source)` does not accept a value
52+
--> $DIR/bad-render-options.rs:11:8
53+
|
54+
LL | #![doc(html_no_source = "asdf")]
55+
| ^^^^^^^^^^^^^^^^^^^^^^^
56+
57+
error: aborting due to 9 previous errors
58+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Test that E0038 is not emitted twice for the same trait object coercion
2+
// regression test for issue <https://github.com/rust-lang/rust/issues/128705>
3+
4+
#![allow(dead_code)]
5+
6+
trait Tr {
7+
const N: usize;
8+
}
9+
10+
impl Tr for u8 {
11+
const N: usize = 1;
12+
}
13+
14+
fn main() {
15+
let x: &dyn Tr = &0_u8;
16+
//~^ ERROR E0038
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0038]: the trait `Tr` is not dyn compatible
2+
--> $DIR/no-duplicate-e0038.rs:15:17
3+
|
4+
LL | let x: &dyn Tr = &0_u8;
5+
| ^^ `Tr` is not dyn compatible
6+
|
7+
note: for a trait to be dyn compatible it needs to allow building a vtable
8+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
9+
--> $DIR/no-duplicate-e0038.rs:7:11
10+
|
11+
LL | trait Tr {
12+
| -- this trait is not dyn compatible...
13+
LL | const N: usize;
14+
| ^ ...because it contains this associated `const`
15+
= help: consider moving `N` to another trait
16+
= help: only type `u8` implements `Tr`; consider using it directly instead.
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0038`.

0 commit comments

Comments
 (0)