Skip to content
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

Rollup of 10 pull requests #80281

Closed
wants to merge 38 commits into from
Closed
Changes from 3 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0698922
Deprecate compare_and_swap on all atomic types
faern Nov 20, 2020
7bd770c
Add documentation on migrating away from compare_and_swap
faern Nov 20, 2020
df2ef1d
Migrate standard library away from compare_and_swap
faern Nov 20, 2020
90e6eeb
Add doc aliases to compare_exchange[_weak]
faern Nov 22, 2020
ed7b244
Fix documentation typo
faern Nov 22, 2020
7a40b6d
Improve documentation on `success` and `failure` arguments
faern Nov 22, 2020
50b2ade
Revert the usage of compare_exchange_weak
faern Nov 22, 2020
3b8617b
Added [T; N]::zip()
usbalbin Nov 26, 2020
2f35fb1
Remove redundant tests
usbalbin Nov 27, 2020
06ca6bb
Add tests
Nadrieril Nov 22, 2020
d1a50ff
Rename the `overlapping_patterns` lint to `overlapping_range_endpoints`
Nadrieril Oct 22, 2020
c89d439
Be consistent about linting singletons
Nadrieril Oct 22, 2020
94ad5e1
Improve error message
Nadrieril Oct 22, 2020
5687c16
`overlapping_range_endpoints` does not belong in the `unused` lint group
Nadrieril Nov 22, 2020
0e0ae47
Add a new lint to rustdoc for invalid codeblocks
poliorcetics Dec 15, 2020
be2c8f2
Update zip for better codegen, see discussion
usbalbin Dec 16, 2020
baa5e47
Update doc comment
usbalbin Dec 16, 2020
8b37259
Added reference to tracking issue
usbalbin Dec 16, 2020
830ceaa
Remap instrument-coverage line numbers in doctests
Swatinem Dec 6, 2020
5b6c175
Tweak diagnostics
Nadrieril Dec 19, 2020
52b717f
Edit rustc_middle::lint::LintSource docs
pierwill Dec 19, 2020
4fffa74
docs: Edit rustc_middle::ty::query::on_disk_cache
pierwill Dec 19, 2020
41c4330
Make doc-test pass with the new rustdoc
poliorcetics Dec 19, 2020
c127530
Fix labels for 'Library Tracking Issue' template
camelid Dec 20, 2020
e614a72
Fix rustc-std-workspace-core documentation
GreenRecycleBin Dec 20, 2020
f9fa3fe
add an attribute to inner doctest fn
Swatinem Dec 20, 2020
087101e
make path normalization compatible with mac python2
Swatinem Dec 21, 2020
a272d62
Implemented a compiler diagnostic for move async mistake
diondokter Dec 18, 2020
a219cb7
Rollup merge of #78242 - Nadrieril:rename-overlapping_endpoints-lint,…
Dylan-DPC Dec 22, 2020
f373fe3
Rollup merge of #79261 - faern:deprecate-compare-and-swap, r=Amanieu
Dylan-DPC Dec 22, 2020
dae90aa
Rollup merge of #79451 - usbalbin:array_zip, r=m-ou-se
Dylan-DPC Dec 22, 2020
028b0cc
Rollup merge of #79762 - Swatinem:remap-doctest-coverage, r=Swatinem
Dylan-DPC Dec 22, 2020
c9e897a
Rollup merge of #79816 - poliorcetics:rustdoc-fail-on-deny, r=jyn514
Dylan-DPC Dec 22, 2020
c809da4
Rollup merge of #80160 - diondokter:move_async_fix, r=davidtwco
Dylan-DPC Dec 22, 2020
51338fa
Rollup merge of #80203 - pierwill:pierwill-rustcmiddle-lint, r=oli-obk
Dylan-DPC Dec 22, 2020
731c7ec
Rollup merge of #80204 - pierwill:pierwill-rustcmiddle-ondisk, r=varkor
Dylan-DPC Dec 22, 2020
f36d9ee
Rollup merge of #80219 - camelid:library_tracking_issue-labels, r=m-o…
Dylan-DPC Dec 22, 2020
cac7101
Rollup merge of #80222 - GreenRecycleBin:daniel/fix-rustc-std-workspa…
Dylan-DPC Dec 22, 2020
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
3 changes: 2 additions & 1 deletion compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_session::lint::builtin::{
BARE_TRAIT_OBJECTS, BROKEN_INTRA_DOC_LINKS, ELIDED_LIFETIMES_IN_PATHS,
EXPLICIT_OUTLIVES_REQUIREMENTS, INVALID_CODEBLOCK_ATTRIBUTES, INVALID_HTML_TAGS,
MISSING_DOC_CODE_EXAMPLES, NON_AUTOLINKS, PRIVATE_DOC_TESTS,
INVALID_RUST_CODEBLOCK, MISSING_DOC_CODE_EXAMPLES, NON_AUTOLINKS, PRIVATE_DOC_TESTS,
};
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::Span;
@@ -319,6 +319,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
BROKEN_INTRA_DOC_LINKS,
PRIVATE_INTRA_DOC_LINKS,
INVALID_CODEBLOCK_ATTRIBUTES,
INVALID_RUST_CODEBLOCK,
MISSING_DOC_CODE_EXAMPLES,
PRIVATE_DOC_TESTS,
INVALID_HTML_TAGS
13 changes: 13 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
@@ -1846,6 +1846,18 @@ declare_lint! {
"codeblock attribute looks a lot like a known one"
}

declare_lint! {
/// The `invalid_rust_codeblock` lint detects Rust code blocks in
/// documentation examples that are invalid (e.g. empty, not parsable as
/// Rust code). This is a `rustdoc` only lint, see the documentation in the
/// [rustdoc book].
///
/// [rustdoc book]: ../../../rustdoc/lints.html#invalid_rust_codeblock
pub INVALID_RUST_CODEBLOCK,
Warn,
"codeblock could not be parsed as valid Rust or is empty"
}

declare_lint! {
/// The `missing_crate_level_docs` lint detects if documentation is
/// missing at the crate root. This is a `rustdoc` only lint, see the
@@ -2846,6 +2858,7 @@ declare_lint_pass! {
BROKEN_INTRA_DOC_LINKS,
PRIVATE_INTRA_DOC_LINKS,
INVALID_CODEBLOCK_ATTRIBUTES,
INVALID_RUST_CODEBLOCK,
MISSING_CRATE_LEVEL_DOCS,
MISSING_DOC_CODE_EXAMPLES,
INVALID_HTML_TAGS,
1 change: 1 addition & 0 deletions compiler/rustc_trait_selection/src/opaque_types.rs
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ pub struct OpaqueTypeDecl<'tcx> {
/// type Foo = impl Baz;
/// fn bar() -> Foo {
/// // ^^^ This is the span we are looking for!
/// # }
/// ```
///
/// In cases where the fn returns `(impl Trait, impl Trait)` or
35 changes: 35 additions & 0 deletions src/doc/rustdoc/src/lints.md
Original file line number Diff line number Diff line change
@@ -285,6 +285,41 @@ warning: unclosed HTML tag `h1`
warning: 2 warnings emitted
```
## invalid_rust_codeblock

This lint **warns by default**. It detects Rust code blocks in documentation
examples that are invalid (e.g. empty, not parsable as Rust). For example:

```rust
/// Empty code block, with and without Rust:
///
/// ```rust
/// ```
///
/// Unclosed code block:
///
/// ```rust
fn main() {}
```

Which will give:

```text
warning: Rust code block is empty
--> src/lib.rs:3:5
|
3 | /// ```rust
| _____^
4 | | /// ```
| |_______^
warning: Rust code block is empty
--> src/lib.rs:8:5
|
8 | /// ```rust
| ^^^^^^^
```

## non_autolinks

2 changes: 2 additions & 0 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
@@ -308,6 +308,7 @@ crate fn create_config(
let private_doc_tests = rustc_lint::builtin::PRIVATE_DOC_TESTS.name;
let no_crate_level_docs = rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS.name;
let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name;
let invalid_rust_codeblock = rustc_lint::builtin::INVALID_RUST_CODEBLOCK.name;
let invalid_html_tags = rustc_lint::builtin::INVALID_HTML_TAGS.name;
let renamed_and_removed_lints = rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name;
let non_autolinks = rustc_lint::builtin::NON_AUTOLINKS.name;
@@ -323,6 +324,7 @@ crate fn create_config(
private_doc_tests.to_owned(),
no_crate_level_docs.to_owned(),
invalid_codeblock_attributes_name.to_owned(),
invalid_rust_codeblock.to_owned(),
invalid_html_tags.to_owned(),
renamed_and_removed_lints.to_owned(),
unknown_lints.to_owned(),
71 changes: 49 additions & 22 deletions src/librustdoc/passes/check_code_block_syntax.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use rustc_data_structures::sync::{Lock, Lrc};
use rustc_errors::{emitter::Emitter, Applicability, Diagnostic, Handler};
use rustc_middle::lint::LintDiagnosticBuilder;
use rustc_parse::parse_stream_from_source_str;
use rustc_session::lint;
use rustc_session::parse::ParseSess;
use rustc_span::source_map::{FilePathMapping, SourceMap};
use rustc_span::{FileName, InnerSpan};
@@ -47,51 +49,76 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
.unwrap_or(false);
let buffer = buffer.borrow();

if buffer.has_errors || is_empty {
let mut diag = if let Some(sp) =
super::source_span_for_markdown_range(self.cx, &dox, &code_block.range, &item.attrs)
{
let warning_message = if buffer.has_errors {
if !(buffer.has_errors || is_empty) {
// No errors in a non-empty program.
return;
}

let local_id = match item.def_id.as_local() {
Some(id) => id,
// We don't need to check the syntax for other crates so returning
// without doing anything should not be a problem.
None => return,
};

let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_id);
let mark_with_text = code_block.syntax.is_none() && code_block.is_fenced;

// The span and whether it is precise or not.
let (sp, precise_span) = match super::source_span_for_markdown_range(
self.cx,
&dox,
&code_block.range,
&item.attrs,
) {
Some(sp) => (sp, true),
None => (super::span_of_attrs(&item.attrs).unwrap_or(item.source.span()), false),
};

// lambda that will use the lint to start a new diagnostic and add
// a suggestion to it when needed.
let diag_builder = |lint: LintDiagnosticBuilder<'_>| {
let mut diag = if precise_span {
let msg = if buffer.has_errors {
"could not parse code block as Rust code"
} else {
"Rust code block is empty"
};

let mut diag = self.cx.sess().struct_span_warn(sp, warning_message);

if code_block.syntax.is_none() && code_block.is_fenced {
let sp = sp.from_inner(InnerSpan::new(0, 3));
let mut diag = lint.build(msg);
if mark_with_text {
diag.span_suggestion(
sp,
sp.from_inner(InnerSpan::new(0, 3)),
"mark blocks that do not contain Rust code as text",
String::from("```text"),
Applicability::MachineApplicable,
);
}

diag
} else {
// We couldn't calculate the span of the markdown block that had the error, so our
// diagnostics are going to be a bit lacking.
let mut diag = self.cx.sess().struct_span_warn(
super::span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
"doc comment contains an invalid Rust code block",
);

if code_block.syntax.is_none() && code_block.is_fenced {
let mut diag = lint.build("doc comment contains an invalid Rust code block");
if mark_with_text {
diag.help("mark blocks that do not contain Rust code as text: ```text");
}

diag
};

// FIXME(#67563): Provide more context for these errors by displaying the spans inline.
for message in buffer.messages.iter() {
diag.note(&message);
}

diag.emit();
}
};

// Finally build and emit the completed diagnostic.
// All points of divergence have been handled earlier so this can be
// done the same way whether the span is precise or not.
self.cx.tcx.struct_span_lint_hir(
lint::builtin::INVALID_RUST_CODEBLOCK,
hir_id,
sp,
diag_builder,
);
}
}

1 change: 1 addition & 0 deletions src/test/rustdoc-ui/invalid-syntax.stderr
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ LL | | /// \__________pkt->size___________/ \_result->size_/ \__pkt->si
LL | | /// ```
| |_______^
|
= note: `#[warn(invalid_rust_codeblock)]` on by default
= note: error from rustc: unknown start of token: \
= note: error from rustc: unknown start of token: \
= note: error from rustc: unknown start of token: \