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 7 pull requests #68739

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ is a bug or not, feel free to file a bug anyway.
**If you believe reporting your bug publicly represents a security risk to Rust users,
please follow our [instructions for reporting security vulnerabilities](https://www.rust-lang.org/policies/security)**.

If you're using the nightly channel, please check if the bug exists in the
latest toolchain before filing your bug. It might be fixed already.

If you have the chance, before reporting a bug, please [search existing
issues](https://github.com/rust-lang/rust/search?q=&type=Issues&utf8=%E2%9C%93),
as it's possible that someone else has already reported your error. This doesn't
Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ merge_derives = false
# by default we ignore everything in the repository
# tidy only checks files which are not ignored, each entry follows gitignore style
ignore = [
"build",

# tests for now are not formatted, as they are sometimes pretty-printing constrained
# (and generally rustfmt can move around comments in UI-testing incompatible ways)
"src/test",
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
//!
//! [`Box<T>`], casually referred to as a 'box', provides the simplest form of
//! heap allocation in Rust. Boxes provide ownership for this allocation, and
//! drop their contents when they go out of scope.
//! drop their contents when they go out of scope. Boxes also ensure that they
//! never allocate more than `isize::MAX` bytes.
//!
//! # Examples
//!
Expand Down
2 changes: 2 additions & 0 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! Vectors have `O(1)` indexing, amortized `O(1)` push (to the end) and
//! `O(1)` pop (from the end).
//!
//! Vectors ensure they never allocate more than `isize::MAX` bytes.
//!
//! # Examples
//!
//! You can explicitly create a [`Vec<T>`] with [`new`]:
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_data_structures/obligation_forest/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::obligation_forest::{ForestObligation, ObligationForest};
use graphviz as dot;
use std::env::var_os;
use std::fs::File;
use std::io::BufWriter;
use std::path::Path;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
Expand Down Expand Up @@ -31,7 +32,7 @@ impl<O: ForestObligation> ObligationForest<O> {

let file_path = dir.as_ref().join(format!("{:010}_{}.gv", counter, description));

let mut gv_file = File::create(file_path).unwrap();
let mut gv_file = BufWriter::new(File::create(file_path).unwrap());

dot::render(&self, &mut gv_file).unwrap();
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_incremental/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use syntax::ast;

use std::env;
use std::fs::{self, File};
use std::io::Write;
use std::io::{BufWriter, Write};

pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
tcx.dep_graph.with_ignore(|| {
Expand Down Expand Up @@ -235,7 +235,7 @@ fn dump_graph(tcx: TyCtxt<'_>) {
{
// dump a .txt file with just the edges:
let txt_path = format!("{}.txt", path);
let mut file = File::create(&txt_path).unwrap();
let mut file = BufWriter::new(File::create(&txt_path).unwrap());
for &(ref source, ref target) in &edges {
write!(file, "{:?} -> {:?}\n", source, target).unwrap();
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use tempfile::Builder as TempFileBuilder;
use std::any::Any;
use std::cell::RefCell;
use std::ffi::OsString;
use std::io::{self, Write};
use std::io::{self, BufWriter, Write};
use std::path::PathBuf;
use std::rc::Rc;
use std::{env, fs, iter, mem};
Expand Down Expand Up @@ -575,7 +575,7 @@ fn write_out_deps(
});
}

let mut file = fs::File::create(&deps_filename)?;
let mut file = BufWriter::new(fs::File::create(&deps_filename)?);
for path in out_filenames {
writeln!(file, "{}: {}\n", path.display(), files.join(" "))?;
}
Expand Down
34 changes: 27 additions & 7 deletions src/librustc_mir/borrow_check/facts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_index::vec::Idx;
use std::error::Error;
use std::fmt::Debug;
use std::fs::{self, File};
use std::io::Write;
use std::io::{BufWriter, Write};
use std::path::Path;

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -117,7 +117,7 @@ impl<'w> FactWriter<'w> {
T: FactRow,
{
let file = &self.dir.join(file_name);
let mut file = File::create(file)?;
let mut file = BufWriter::new(File::create(file)?);
for row in rows {
row.write(&mut file, self.location_table)?;
}
Expand All @@ -126,11 +126,19 @@ impl<'w> FactWriter<'w> {
}

trait FactRow {
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>>;
fn write(
&self,
out: &mut dyn Write,
location_table: &LocationTable,
) -> Result<(), Box<dyn Error>>;
}

impl FactRow for RegionVid {
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
fn write(
&self,
out: &mut dyn Write,
location_table: &LocationTable,
) -> Result<(), Box<dyn Error>> {
write_row(out, location_table, &[self])
}
}
Expand All @@ -140,7 +148,11 @@ where
A: FactCell,
B: FactCell,
{
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
fn write(
&self,
out: &mut dyn Write,
location_table: &LocationTable,
) -> Result<(), Box<dyn Error>> {
write_row(out, location_table, &[&self.0, &self.1])
}
}
Expand All @@ -151,7 +163,11 @@ where
B: FactCell,
C: FactCell,
{
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
fn write(
&self,
out: &mut dyn Write,
location_table: &LocationTable,
) -> Result<(), Box<dyn Error>> {
write_row(out, location_table, &[&self.0, &self.1, &self.2])
}
}
Expand All @@ -163,7 +179,11 @@ where
C: FactCell,
D: FactCell,
{
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
fn write(
&self,
out: &mut dyn Write,
location_table: &LocationTable,
) -> Result<(), Box<dyn Error>> {
write_row(out, location_table, &[&self.0, &self.1, &self.2, &self.3])
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/dump_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn on_mir_pass<'tcx>(

pub fn emit_mir(tcx: TyCtxt<'_>, outputs: &OutputFilenames) -> io::Result<()> {
let path = outputs.path(OutputType::Mir);
let mut f = File::create(&path)?;
let mut f = io::BufWriter::new(File::create(&path)?);
mir_util::write_mir_pretty(tcx, None, &mut f)?;
Ok(())
}
5 changes: 3 additions & 2 deletions src/librustc_mir/util/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use rustc_data_structures::work_queue::WorkQueue;
use rustc_index::bit_set::BitSet;
use rustc_index::vec::{Idx, IndexVec};
use std::fs;
use std::io::{self, Write};
use std::io::{self, BufWriter, Write};
use std::path::{Path, PathBuf};

pub type LiveVarSet = BitSet<Local>;
Expand Down Expand Up @@ -288,7 +288,8 @@ fn dump_matched_mir_node<'tcx>(
let item_id = tcx.hir().as_local_hir_id(source.def_id()).unwrap();
let file_name = format!("rustc.node{}{}-liveness.mir", item_id, pass_name);
file_path.push(&file_name);
let _ = fs::File::create(&file_path).and_then(|mut file| {
let _ = fs::File::create(&file_path).and_then(|file| {
let mut file = BufWriter::new(file);
writeln!(file, "// MIR local liveness analysis for `{}`", node_path)?;
writeln!(file, "// source = {:?}", source)?;
writeln!(file, "// pass_name = {}", pass_name)?;
Expand Down
27 changes: 11 additions & 16 deletions src/librustdoc/html/render/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ crate struct Cache {
/// found on that implementation.
pub impls: FxHashMap<DefId, Vec<Impl>>,

/// Maintains a mapping of local crate `NodeId`s to the fully qualified name
/// Maintains a mapping of local crate `DefId`s to the fully qualified name
/// and "short type description" of that node. This is used when generating
/// URLs when a type is being linked to. External paths are not located in
/// this map because the `External` type itself has all the information
Expand Down Expand Up @@ -358,6 +358,7 @@ impl DocFolder for Cache {
| clean::ForeignTypeItem
| clean::MacroItem(..)
| clean::ProcMacroItem(..)
| clean::VariantItem(..)
if !self.stripped_mod =>
{
// Re-exported items mean that the same id can show up twice
Expand All @@ -373,13 +374,6 @@ impl DocFolder for Cache {
}
self.add_aliases(&item);
}
// Link variants to their parent enum because pages aren't emitted
// for each variant.
clean::VariantItem(..) if !self.stripped_mod => {
let mut stack = self.stack.clone();
stack.pop();
self.paths.insert(item.def_id, (stack, ItemType::Enum));
}

clean::PrimitiveItem(..) => {
self.add_aliases(&item);
Expand All @@ -396,7 +390,8 @@ impl DocFolder for Cache {
| clean::EnumItem(..)
| clean::ForeignTypeItem
| clean::StructItem(..)
| clean::UnionItem(..) => {
| clean::UnionItem(..)
| clean::VariantItem(..) => {
self.parent_stack.push(item.def_id);
self.parent_is_trait_impl = false;
true
Expand Down Expand Up @@ -564,7 +559,7 @@ fn extern_location(

/// Builds the search index from the collected metadata
fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
let mut nodeid_to_pathid = FxHashMap::default();
let mut defid_to_pathid = FxHashMap::default();
let mut crate_items = Vec::with_capacity(cache.search_index.len());
let mut crate_paths = vec![];

Expand All @@ -586,21 +581,21 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
}
}

// Reduce `NodeId` in paths into smaller sequential numbers,
// Reduce `DefId` in paths into smaller sequential numbers,
// and prune the paths that do not appear in the index.
let mut lastpath = String::new();
let mut lastpathid = 0usize;

for item in search_index {
item.parent_idx = item.parent.map(|nodeid| {
if nodeid_to_pathid.contains_key(&nodeid) {
*nodeid_to_pathid.get(&nodeid).expect("no pathid")
item.parent_idx = item.parent.map(|defid| {
if defid_to_pathid.contains_key(&defid) {
*defid_to_pathid.get(&defid).expect("no pathid")
} else {
let pathid = lastpathid;
nodeid_to_pathid.insert(nodeid, pathid);
defid_to_pathid.insert(defid, pathid);
lastpathid += 1;

let &(ref fqp, short) = paths.get(&nodeid).unwrap();
let &(ref fqp, short) = paths.get(&defid).unwrap();
crate_paths.push((short, fqp.last().unwrap().clone()));
pathid
}
Expand Down
30 changes: 22 additions & 8 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1364,14 +1364,15 @@ function getSearchElement() {
var href;
var type = itemTypes[item.ty];
var name = item.name;
var path = item.path;

if (type === "mod") {
displayPath = item.path + "::";
href = rootPath + item.path.replace(/::/g, "/") + "/" +
displayPath = path + "::";
href = rootPath + path.replace(/::/g, "/") + "/" +
name + "/index.html";
} else if (type === "primitive" || type === "keyword") {
displayPath = "";
href = rootPath + item.path.replace(/::/g, "/") +
href = rootPath + path.replace(/::/g, "/") +
"/" + type + "." + name + ".html";
} else if (type === "externcrate") {
displayPath = "";
Expand All @@ -1380,14 +1381,27 @@ function getSearchElement() {
var myparent = item.parent;
var anchor = "#" + type + "." + name;
var parentType = itemTypes[myparent.ty];
var pageType = parentType;
var pageName = myparent.name;

if (parentType === "primitive") {
displayPath = myparent.name + "::";
} else if (type === "structfield" && parentType === "variant") {
// Structfields belonging to variants are special: the
// final path element is the enum name.
var splitPath = item.path.split("::");
var enumName = splitPath.pop();
path = splitPath.join("::");
displayPath = path + "::" + enumName + "::" + myparent.name + "::";
anchor = "#variant." + myparent.name + ".field." + name;
pageType = "enum";
pageName = enumName;
} else {
displayPath = item.path + "::" + myparent.name + "::";
displayPath = path + "::" + myparent.name + "::";
}
href = rootPath + item.path.replace(/::/g, "/") +
"/" + parentType +
"." + myparent.name +
href = rootPath + path.replace(/::/g, "/") +
"/" + pageType +
"." + pageName +
".html" + anchor;
} else {
displayPath = item.path + "::";
Expand Down Expand Up @@ -1668,7 +1682,7 @@ function getSearchElement() {
// (String) name]
var paths = rawSearchIndex[crate].p;

// convert `paths` into an object form
// convert `rawPaths` entries into object form
var len = paths.length;
for (i = 0; i < len; ++i) {
paths[i] = {ty: paths[i][0], name: paths[i][1]};
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1751,12 +1751,15 @@ impl<'a> State<'a> {
attrs: &[Attribute],
) {
self.print_path(path, true, 0);
self.nbsp();
self.s.word("{");
self.print_inner_attributes_inline(attrs);
self.commasep_cmnt(
Consistent,
&fields[..],
|s, field| {
s.print_outer_attributes(&field.attrs);
s.space_if_not_bol();
s.ibox(INDENT_UNIT);
if !field.is_shorthand {
s.print_ident(field.ident);
Expand All @@ -1769,6 +1772,7 @@ impl<'a> State<'a> {
);
match *wth {
Some(ref expr) => {
self.space_if_not_bol();
self.ibox(INDENT_UNIT);
if !fields.is_empty() {
self.s.word(",");
Expand Down
16 changes: 16 additions & 0 deletions src/test/pretty/issue-68710-field-attr-proc-mac-lost.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// pp-exact

fn main() { }

struct C {
field: u8,
}

#[allow()]
const C: C =
C {
#[cfg(debug_assertions)]
field: 0,

#[cfg(not (debug_assertions))]
field: 1,};
7 changes: 7 additions & 0 deletions src/test/rustdoc-js/struct-like-variant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const QUERY = 'name';

const EXPECTED = {
'others': [
{ 'path': 'struct_like_variant::Enum::Bar::name', 'name': 'l' },
],
};
5 changes: 5 additions & 0 deletions src/test/rustdoc-js/struct-like-variant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![crate_name = "struct_like_variant"]

pub enum Enum {
Bar { name: String }
}
Loading