Skip to content

Rollup of 6 pull requests #82414

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

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a0f9d4b
Enable smart punctuation
camelid Sep 15, 2020
f1581ed
Test that code does not get smart-punctuated
camelid Feb 8, 2021
e4b83fc
Document smart punctuation
camelid Feb 8, 2021
0a34521
Fix `@has` checks "no closing quotation" error
camelid Feb 8, 2021
1b29b29
Update Markdown unit tests
camelid Feb 9, 2021
eeb5552
Remove query parameters when leaving search results
GuillaumeGomez Feb 17, 2021
343b673
Consider auto derefs before warning about write only fields
tmiasko Feb 19, 2021
a00eb7e
Add @is command to jsondocck
aDotInTheVoid Feb 20, 2021
cd5f603
Implement @set
aDotInTheVoid Feb 20, 2021
dd4b938
Implement using @set values
aDotInTheVoid Feb 20, 2021
a22d948
Apply suggestions from code review
aDotInTheVoid Feb 21, 2021
ba22a69
Extract string_to_value to its own function
aDotInTheVoid Feb 21, 2021
dd9ab16
disable atomic_max/min tests in Miri
RalfJung Feb 22, 2021
4c949a4
Simplify Error Handling.
aDotInTheVoid Feb 22, 2021
2145a87
Fix mir-cfg dumps
osa1 Feb 21, 2021
89e2f77
Rollup merge of #79423 - camelid:smart-punct, r=jyn514
GuillaumeGomez Feb 22, 2021
399431c
Rollup merge of #82234 - GuillaumeGomez:remove-query-param-on-esc, r=…
GuillaumeGomez Feb 22, 2021
b62f759
Rollup merge of #82297 - tmiasko:write-only, r=oli-obk
GuillaumeGomez Feb 22, 2021
6fedd91
Rollup merge of #82311 - aDotInTheVoid:jsondocck-improvements, r=jyn514
GuillaumeGomez Feb 22, 2021
98511dd
Rollup merge of #82362 - osa1:issue81918, r=oli-obk
GuillaumeGomez Feb 22, 2021
49fca26
Rollup merge of #82391 - RalfJung:miri-atomic-minmax, r=dtolnay
GuillaumeGomez Feb 22, 2021
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
23 changes: 18 additions & 5 deletions compiler/rustc_mir/src/util/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use gsgdt::GraphvizSettings;
use rustc_graphviz as dot;
use rustc_hir::def_id::DefId;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::{self, TyCtxt};
use std::fmt::Debug;
use std::io::{self, Write};

Expand All @@ -16,14 +16,27 @@ where
{
let def_ids = dump_mir_def_ids(tcx, single);

let use_subgraphs = def_ids.len() > 1;
let mirs =
def_ids
.iter()
.flat_map(|def_id| {
if tcx.is_const_fn_raw(*def_id) {
vec![tcx.optimized_mir(*def_id), tcx.mir_for_ctfe(*def_id)]
} else {
vec![tcx.instance_mir(ty::InstanceDef::Item(ty::WithOptConstParam::unknown(
*def_id,
)))]
}
})
.collect::<Vec<_>>();

let use_subgraphs = mirs.len() > 1;
if use_subgraphs {
writeln!(w, "digraph __crate__ {{")?;
}

for def_id in def_ids {
let body = &tcx.optimized_mir(def_id);
write_mir_fn_graphviz(tcx, body, use_subgraphs, w)?;
for mir in mirs {
write_mir_fn_graphviz(tcx, mir, use_subgraphs, w)?;
}

if use_subgraphs {
Expand Down
28 changes: 17 additions & 11 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ fn should_explore(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
)
}

fn base_expr<'a>(mut expr: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> {
loop {
match expr.kind {
hir::ExprKind::Field(base, ..) => expr = base,
_ => return expr,
}
}
}

struct MarkSymbolVisitor<'tcx> {
worklist: Vec<hir::HirId>,
tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -143,6 +134,22 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
}
}

fn handle_assign(&mut self, expr: &'tcx hir::Expr<'tcx>) {
if self
.typeck_results()
.expr_adjustments(expr)
.iter()
.any(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(_)))
{
self.visit_expr(expr);
} else if let hir::ExprKind::Field(base, ..) = expr.kind {
// Ignore write to field
self.handle_assign(base);
} else {
self.visit_expr(expr);
}
}

fn handle_field_pattern_match(
&mut self,
lhs: &hir::Pat<'_>,
Expand Down Expand Up @@ -272,8 +279,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
self.lookup_and_handle_method(expr.hir_id);
}
hir::ExprKind::Assign(ref left, ref right, ..) => {
// Ignore write to field
self.visit_expr(base_expr(left));
self.handle_assign(left);
self.visit_expr(right);
return;
}
Expand Down
4 changes: 4 additions & 0 deletions library/core/tests/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn uint_xor() {

#[test]
#[cfg(any(not(target_arch = "arm"), target_os = "linux"))] // Missing intrinsic in compiler-builtins
#[cfg_attr(miri, ignore)] // FIXME: Miri does not support atomic_min
fn uint_min() {
let x = AtomicUsize::new(0xf731);
assert_eq!(x.fetch_min(0x137f, SeqCst), 0xf731);
Expand All @@ -71,6 +72,7 @@ fn uint_min() {

#[test]
#[cfg(any(not(target_arch = "arm"), target_os = "linux"))] // Missing intrinsic in compiler-builtins
#[cfg_attr(miri, ignore)] // FIXME: Miri does not support atomic_max
fn uint_max() {
let x = AtomicUsize::new(0x137f);
assert_eq!(x.fetch_max(0xf731, SeqCst), 0x137f);
Expand Down Expand Up @@ -109,6 +111,7 @@ fn int_xor() {

#[test]
#[cfg(any(not(target_arch = "arm"), target_os = "linux"))] // Missing intrinsic in compiler-builtins
#[cfg_attr(miri, ignore)] // FIXME: Miri does not support atomic_min
fn int_min() {
let x = AtomicIsize::new(0xf731);
assert_eq!(x.fetch_min(0x137f, SeqCst), 0xf731);
Expand All @@ -119,6 +122,7 @@ fn int_min() {

#[test]
#[cfg(any(not(target_arch = "arm"), target_os = "linux"))] // Missing intrinsic in compiler-builtins
#[cfg_attr(miri, ignore)] // FIXME: Miri does not support atomic_max
fn int_max() {
let x = AtomicIsize::new(0x137f);
assert_eq!(x.fetch_max(0xf731, SeqCst), 0x137f);
Expand Down
26 changes: 21 additions & 5 deletions src/doc/rustdoc/src/how-to-write-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ what an item is, how it is used, and for what purpose it exists.
Let's see an example coming from the [standard library] by taking a look at the
[`std::env::args()`][env::args] function:

``````text
``````markdown
Returns the arguments which this program was started with (normally passed
via the command line).

Expand Down Expand Up @@ -135,7 +135,7 @@ for argument in env::args() {

Everything before the first empty line will be reused to describe the component
in searches and module overviews. For example, the function `std::env::args()`
above will be shown on the [`std::env`] module documentation. It is good
above will be shown on the [`std::env`] module documentation. It is good
practice to keep the summary to one line: concise writing is a goal of good
documentation.

Expand All @@ -153,9 +153,10 @@ and finally provides a code example.

## Markdown

`rustdoc` uses the [CommonMark markdown specification]. You might be
interested into taking a look at their website to see what's possible to do.
- [commonmark quick reference]
`rustdoc` uses the [CommonMark Markdown specification]. You might be
interested in taking a look at their website to see what's possible:

- [CommonMark quick reference]
- [current spec]

In addition to the standard CommonMark syntax, `rustdoc` supports several
Expand Down Expand Up @@ -240,6 +241,21 @@ This will render as

See the specification for the [task list extension] for more details.

### Smart punctuation

Some ASCII punctuation sequences will be automatically turned into fancy Unicode
characters:

| ASCII sequence | Unicode |
|----------------|---------|
| `--` | – |
| `---` | — |
| `...` | … |
| `"` | “ or ”, depending on context |
| `'` | ‘ or ’, depending on context |

So, no need to manually enter those Unicode characters!

[`backtrace`]: https://docs.rs/backtrace/0.3.50/backtrace/
[commonmark markdown specification]: https://commonmark.org/
[commonmark quick reference]: https://commonmark.org/help/
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ pub(crate) fn opts() -> Options {
| Options::ENABLE_FOOTNOTES
| Options::ENABLE_STRIKETHROUGH
| Options::ENABLE_TASKLISTS
| Options::ENABLE_SMART_PUNCTUATION
}

/// A subset of [`opts()`] used for rendering summaries.
pub(crate) fn summary_opts() -> Options {
Options::ENABLE_STRIKETHROUGH
Options::ENABLE_STRIKETHROUGH | Options::ENABLE_SMART_PUNCTUATION
}

/// When `to_string` is called, this struct will emit the HTML corresponding to
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/html/markdown/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ fn test_short_markdown_summary() {
t("Hard-break \nsummary", "Hard-break summary");
t("hello [Rust] :)\n\n[Rust]: https://www.rust-lang.org", "hello Rust :)");
t("hello [Rust](https://www.rust-lang.org \"Rust\") :)", "hello Rust :)");
t("code `let x = i32;` ...", "code <code>let x = i32;</code> ...");
t("type `Type<'static>` ...", "type <code>Type<'static></code> ...");
t("code `let x = i32;` ...", "code <code>let x = i32;</code> ");
t("type `Type<'static>` ...", "type <code>Type<'static></code> ");
t("# top header", "top header");
t("## header", "header");
t("first paragraph\n\nsecond paragraph", "first paragraph");
Expand All @@ -227,8 +227,8 @@ fn test_plain_text_summary() {
t("Hard-break \nsummary", "Hard-break summary");
t("hello [Rust] :)\n\n[Rust]: https://www.rust-lang.org", "hello Rust :)");
t("hello [Rust](https://www.rust-lang.org \"Rust\") :)", "hello Rust :)");
t("code `let x = i32;` ...", "code `let x = i32;` ...");
t("type `Type<'static>` ...", "type `Type<'static>` ...");
t("code `let x = i32;` ...", "code `let x = i32;` ");
t("type `Type<'static>` ...", "type `Type<'static>` ");
t("# top header", "top header");
t("# top header\n\nfollowed by some text", "top header");
t("## header", "header");
Expand All @@ -251,6 +251,6 @@ fn test_markdown_html_escape() {
}

t("`Struct<'a, T>`", "<p><code>Struct&lt;'a, T&gt;</code></p>\n");
t("Struct<'a, T>", "<p>Struct&lt;'a, T&gt;</p>\n");
t("Struct<'a, T>", "<p>Struct&lt;a, T&gt;</p>\n");
t("Struct<br>", "<p>Struct&lt;br&gt;</p>\n");
}
7 changes: 6 additions & 1 deletion src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function focusSearchBar() {
getSearchInput().focus();
}

// Removes the focus from the search bar
// Removes the focus from the search bar.
function defocusSearchBar() {
getSearchInput().blur();
}
Expand Down Expand Up @@ -220,6 +220,11 @@ function defocusSearchBar() {
addClass(search, "hidden");
removeClass(main, "hidden");
document.title = titleBeforeSearch;
// We also remove the query parameter from the URL.
if (browserSupportsHistoryApi()) {
history.replaceState("", window.currentCrate + " - Rust",
getNakedUrl() + window.location.hash);
}
}

// used for special search precedence
Expand Down
24 changes: 14 additions & 10 deletions src/test/rustdoc-json/nested.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
// edition:2018

// @has nested.json "$.index[*][?(@.name=='nested')].kind" \"module\"
// @has - "$.index[*][?(@.name=='nested')].inner.is_crate" true
// @is nested.json "$.index[*][?(@.name=='nested')].kind" \"module\"
// @is - "$.index[*][?(@.name=='nested')].inner.is_crate" true
// @count - "$.index[*][?(@.name=='nested')].inner.items[*]" 1

// @has nested.json "$.index[*][?(@.name=='l1')].kind" \"module\"
// @has - "$.index[*][?(@.name=='l1')].inner.is_crate" false
// @is nested.json "$.index[*][?(@.name=='l1')].kind" \"module\"
// @is - "$.index[*][?(@.name=='l1')].inner.is_crate" false
// @count - "$.index[*][?(@.name=='l1')].inner.items[*]" 2
pub mod l1 {

// @has nested.json "$.index[*][?(@.name=='l3')].kind" \"module\"
// @has - "$.index[*][?(@.name=='l3')].inner.is_crate" false
// @is nested.json "$.index[*][?(@.name=='l3')].kind" \"module\"
// @is - "$.index[*][?(@.name=='l3')].inner.is_crate" false
// @count - "$.index[*][?(@.name=='l3')].inner.items[*]" 1
// @set l3_id = - "$.index[*][?(@.name=='l3')].id"
// @has - "$.index[*][?(@.name=='l1')].inner.items[*]" $l3_id
pub mod l3 {

// @has nested.json "$.index[*][?(@.name=='L4')].kind" \"struct\"
// @has - "$.index[*][?(@.name=='L4')].inner.struct_type" \"unit\"
// @is nested.json "$.index[*][?(@.name=='L4')].kind" \"struct\"
// @is - "$.index[*][?(@.name=='L4')].inner.struct_type" \"unit\"
// @set l4_id = - "$.index[*][?(@.name=='L4')].id"
// @has - "$.index[*][?(@.name=='l3')].inner.items[*]" $l4_id
pub struct L4;
}
// @has nested.json "$.index[*][?(@.inner.span=='l3::L4')].kind" \"import\"
// @has - "$.index[*][?(@.inner.span=='l3::L4')].inner.glob" false
// @is nested.json "$.index[*][?(@.inner.span=='l3::L4')].kind" \"import\"
// @is - "$.index[*][?(@.inner.span=='l3::L4')].inner.glob" false
pub use l3::L4;
}
2 changes: 1 addition & 1 deletion src/test/rustdoc/inline_cross/add-docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ extern crate inner;


// @has add_docs/struct.MyStruct.html
// @has add_docs/struct.MyStruct.html "Doc comment from 'pub use', Doc comment from definition"
// @has add_docs/struct.MyStruct.html "Doc comment from pub use, Doc comment from definition"
/// Doc comment from 'pub use',
pub use inner::MyStruct;
30 changes: 30 additions & 0 deletions src/test/rustdoc/smart-punct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// ignore-tidy-linelength

#![crate_name = "foo"]

//! This is the "start" of the 'document'! How'd you know that "it's" the start?
//!
//! # Header with "smart punct'"
//!
//! [link with "smart punct'" -- yessiree!][]
//!
//! [link with "smart punct'" -- yessiree!]: https://www.rust-lang.org
//!
//! # Code should not be smart-punct'd
//!
//! `this inline code -- it shouldn't have "smart punct"`
//!
//! ```
//! let x = "don't smart-punct me -- please!";
//! ```
//!
//! ```text
//! I say "don't smart-punct me -- please!"
//! ```

// @has "foo/index.html" "//p" "This is the “start” of the ‘document’! How’d you know that “it’s” the start?"
// @has "foo/index.html" "//h1" "Header with “smart punct’”"
// @has "foo/index.html" '//a[@href="https://www.rust-lang.org"]' "link with “smart punct’” – yessiree!"
// @has "foo/index.html" '//code' "this inline code -- it shouldn't have \"smart punct\""
// @has "foo/index.html" '//pre' "let x = \"don't smart-punct me -- please!\";"
// @has "foo/index.html" '//pre' "I say \"don't smart-punct me -- please!\""
11 changes: 11 additions & 0 deletions src/test/ui/issues/issue-81918.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass
// dont-check-compiler-stdout
// compile-flags: -Z unpretty=mir-cfg

// This checks that unpretty=mir-cfg does not panic. See #81918.

const TAG: &'static str = "ABCD";

fn main() {
if TAG == "" {}
}
49 changes: 49 additions & 0 deletions src/test/ui/lint/dead-code/write-only-field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,53 @@ fn field_write(s: &mut S) {
fn main() {
let mut s = S { f: 0, sub: Sub { f: 0 } };
field_write(&mut s);

auto_deref();
nested_boxes();
}

fn auto_deref() {
struct E {
x: bool,
y: bool, //~ ERROR: field is never read
}

struct P<'a> {
e: &'a mut E
}

impl P<'_> {
fn f(&mut self) {
self.e.x = true;
self.e.y = true;
}
}

let mut e = E { x: false, y: false };
let mut p = P { e: &mut e };
p.f();
assert!(e.x);
}

fn nested_boxes() {
struct A {
b: Box<B>,
}

struct B {
c: Box<C>,
}

struct C {
u: u32, //~ ERROR: field is never read
v: u32, //~ ERROR: field is never read
}

let mut a = A {
b: Box::new(B {
c: Box::new(C { u: 0, v: 0 }),
}),
};
a.b.c.v = 10;
a.b.c = Box::new(C { u: 1, v: 2 });
}
Loading