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 #86373

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4191853
Added the --temps-dir option.
Apr 4, 2021
c0e8578
Create temps_dir before it's needed.
Apr 4, 2021
abf9653
Emitted files go to the output dir.
Apr 4, 2021
e146192
Documentation.
Apr 4, 2021
9a60e47
Fix test.
Apr 4, 2021
857b19d
Added a regression test.
Apr 4, 2021
14f3ec2
Fix span calculation in format strings
FabianWolff Jun 7, 2021
7728476
Link reference in `dyn` keyword documentation
amorison Jun 8, 2021
3802d57
Mention the Borrow guarantee on the Hash implementations for Array an…
scottmcm Jun 8, 2021
78df1b8
Mention #79078 on compatibility notes of 1.52
JohnTitor Jun 15, 2021
c8a8a23
Do not emit invalid suggestions on multiple mutable borrow errors
JohnTitor Jun 16, 2021
280d193
Remove `projection_ty_from_predicates`
JohnTitor Jun 16, 2021
d828ead
Remove invalid suggestions for assoc consts on placeholder type error
JohnTitor Jun 16, 2021
fb06d9e
Move some typeck-related tests to the typeck dir
JohnTitor Jun 16, 2021
a2a006d
Add missing backslashes to prevent unwanted backlines in rustdoc HTML
GuillaumeGomez Jun 16, 2021
770e8cc
Typo correction: s/is/its
snoyberg Jun 16, 2021
2d097c1
Rollup merge of #83846 - torhovland:issue-10971, r=davidtwco
GuillaumeGomez Jun 16, 2021
a0839b4
Rollup merge of #86104 - FabianWolff:issue-86085, r=davidtwco
GuillaumeGomez Jun 16, 2021
bf53ee1
Rollup merge of #86140 - scottmcm:array-hash-facepalm, r=kennytm
GuillaumeGomez Jun 16, 2021
cb7fbfa
Rollup merge of #86141 - amorison:link-ref-in-doc-dyn-keyword, r=kennytm
GuillaumeGomez Jun 16, 2021
8d91f98
Rollup merge of #86339 - JohnTitor:note-derive-on-proc-macros, r=petr…
GuillaumeGomez Jun 16, 2021
cae088d
Rollup merge of #86343 - JohnTitor:issue-85581, r=estebank
GuillaumeGomez Jun 16, 2021
3f457a2
Rollup merge of #86353 - JohnTitor:remove-projection_ty_from_predicat…
GuillaumeGomez Jun 16, 2021
0f0eff9
Rollup merge of #86355 - JohnTitor:issue-82158, r=estebank
GuillaumeGomez Jun 16, 2021
bc14e69
Rollup merge of #86361 - GuillaumeGomez:missing-backslashes, r=jsha
GuillaumeGomez Jun 16, 2021
fb4fb21
Rollup merge of #86372 - snoyberg:patch-1, r=jonas-schievink
GuillaumeGomez Jun 16, 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
2 changes: 2 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ Compatibility Notes
- [Rustc now catches more cases of `pub_use_of_private_extern_crate`][80763]
- [Changes in how proc macros handle whitespace may lead to panics when used
with older `proc-macro-hack` versions. A `cargo update` should be sufficient to fix this in all cases.][84136]
- [Turn `#[derive]` into a regular macro attribute][79078]

[84136]: https://github.com/rust-lang/rust/issues/84136
[80763]: https://github.com/rust-lang/rust/pull/80763
Expand All @@ -332,6 +333,7 @@ Compatibility Notes
[78429]: https://github.com/rust-lang/rust/pull/78429
[82733]: https://github.com/rust-lang/rust/pull/82733
[82594]: https://github.com/rust-lang/rust/pull/82594
[79078]: https://github.com/rust-lang/rust/pull/79078
[cargo/9181]: https://github.com/rust-lang/cargo/pull/9181
[`char::MAX`]: https://doc.rust-lang.org/std/primitive.char.html#associatedconstant.MAX
[`char::REPLACEMENT_CHARACTER`]: https://doc.rust-lang.org/std/primitive.char.html#associatedconstant.REPLACEMENT_CHARACTER
Expand Down
15 changes: 14 additions & 1 deletion compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ pub fn expand_preparsed_format_args(

let msg = "format argument must be a string literal";
let fmt_sp = efmt.span;
let efmt_kind_is_lit: bool = matches!(efmt.kind, ast::ExprKind::Lit(_));
let (fmt_str, fmt_style, fmt_span) = match expr_to_spanned_string(ecx, efmt, msg) {
Ok(mut fmt) if append_newline => {
fmt.0 = Symbol::intern(&format!("{}\n", fmt.0));
Expand Down Expand Up @@ -989,7 +990,19 @@ pub fn expand_preparsed_format_args(

if !parser.errors.is_empty() {
let err = parser.errors.remove(0);
let sp = fmt_span.from_inner(err.span);
let sp = if efmt_kind_is_lit {
fmt_span.from_inner(err.span)
} else {
// The format string could be another macro invocation, e.g.:
// format!(concat!("abc", "{}"), 4);
// However, `err.span` is an inner span relative to the *result* of
// the macro invocation, which is why we would get a nonsensical
// result calling `fmt_span.from_inner(err.span)` as above, and
// might even end up inside a multibyte character (issue #86085).
// Therefore, we conservatively report the error for the entire
// argument span here.
fmt_span
};
let mut e = ecx.struct_span_err(sp, &format!("invalid format string: {}", err.description));
e.span_label(sp, err.label + " in format string");
if let Some(note) = err.note {
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,15 @@ fn run_compiler(

let cfg = interface::parse_cfgspecs(matches.opt_strs("cfg"));
let (odir, ofile) = make_output(&matches);
let temps_dir = make_temps_dir(&matches);
let mut config = interface::Config {
opts: sopts,
crate_cfg: cfg,
input: Input::File(PathBuf::new()),
input_path: None,
output_file: ofile,
output_dir: odir,
temps_dir,
file_loader,
diagnostic_output,
stderr: None,
Expand Down Expand Up @@ -268,6 +270,7 @@ fn run_compiler(
None,
&compiler.output_dir(),
&compiler.output_file(),
&compiler.temps_dir(),
);

if should_stop == Compilation::Stop {
Expand Down Expand Up @@ -296,6 +299,7 @@ fn run_compiler(
Some(compiler.input()),
compiler.output_dir(),
compiler.output_file(),
compiler.temps_dir(),
)
.and_then(|| {
RustcDefaultCalls::list_metadata(
Expand Down Expand Up @@ -461,6 +465,11 @@ fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<PathBuf>)
(odir, ofile)
}

// Extract temporary directory from matches.
fn make_temps_dir(matches: &getopts::Matches) -> Option<PathBuf> {
matches.opt_str("temps-dir").map(|o| PathBuf::from(&o))
}

// Extract input (string or file and optional path) from matches.
fn make_input(
error_format: ErrorOutputType,
Expand Down Expand Up @@ -650,6 +659,7 @@ impl RustcDefaultCalls {
input: Option<&Input>,
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>,
temps_dir: &Option<PathBuf>,
) -> Compilation {
use rustc_session::config::PrintRequest::*;
// PrintRequest::NativeStaticLibs is special - printed during linking
Expand Down Expand Up @@ -691,7 +701,7 @@ impl RustcDefaultCalls {
});
let attrs = attrs.as_ref().unwrap();
let t_outputs = rustc_interface::util::build_output_filenames(
input, odir, ofile, attrs, sess,
input, odir, ofile, temps_dir, attrs, sess,
);
let id = rustc_session::output::find_crate_name(sess, attrs, input);
if *req == PrintRequest::CrateName {
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct Compiler {
pub(crate) input_path: Option<PathBuf>,
pub(crate) output_dir: Option<PathBuf>,
pub(crate) output_file: Option<PathBuf>,
pub(crate) temps_dir: Option<PathBuf>,
pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>,
pub(crate) override_queries:
Option<fn(&Session, &mut ty::query::Providers, &mut ty::query::Providers)>,
Expand All @@ -56,6 +57,9 @@ impl Compiler {
pub fn output_file(&self) -> &Option<PathBuf> {
&self.output_file
}
pub fn temps_dir(&self) -> &Option<PathBuf> {
&self.temps_dir
}
pub fn register_lints(&self) -> &Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>> {
&self.register_lints
}
Expand All @@ -68,6 +72,7 @@ impl Compiler {
&self.input,
&self.output_dir,
&self.output_file,
&self.temps_dir,
&attrs,
&sess,
)
Expand Down Expand Up @@ -134,6 +139,7 @@ pub struct Config {
pub input_path: Option<PathBuf>,
pub output_dir: Option<PathBuf>,
pub output_file: Option<PathBuf>,
pub temps_dir: Option<PathBuf>,
pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
pub diagnostic_output: DiagnosticOutput,

Expand Down Expand Up @@ -195,6 +201,7 @@ pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R
input_path: config.input_path,
output_dir: config.output_dir,
output_file: config.output_file,
temps_dir: config.temps_dir,
register_lints: config.register_lints,
override_queries: config.override_queries,
};
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ pub fn prepare_outputs(
&compiler.input,
&compiler.output_dir,
&compiler.output_file,
&compiler.temps_dir,
&krate.attrs,
sess,
);
Expand Down Expand Up @@ -739,6 +740,13 @@ pub fn prepare_outputs(
}
}

if let Some(ref dir) = compiler.temps_dir {
if fs::create_dir_all(dir).is_err() {
sess.err("failed to find or create the directory specified by `--temps-dir`");
return Err(ErrorReported);
}
}

write_out_deps(sess, boxed_resolver, &outputs, &output_paths);

let only_dep_info = sess.opts.output_types.contains_key(&OutputType::DepInfo)
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ pub fn build_output_filenames(
input: &Input,
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>,
temps_dir: &Option<PathBuf>,
attrs: &[ast::Attribute],
sess: &Session,
) -> OutputFilenames {
Expand All @@ -658,6 +659,7 @@ pub fn build_output_filenames(
dirpath,
stem,
None,
temps_dir.clone(),
sess.opts.cg.extra_filename.clone(),
sess.opts.output_types.clone(),
)
Expand Down Expand Up @@ -686,6 +688,7 @@ pub fn build_output_filenames(
out_file.parent().unwrap_or_else(|| Path::new("")).to_path_buf(),
out_file.file_stem().unwrap_or_default().to_str().unwrap().to_string(),
ofile,
temps_dir.clone(),
sess.opts.cg.extra_filename.clone(),
sess.opts.output_types.clone(),
)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
// required that their size stay the same, but we don't want to change
// it inadvertently. This assert just ensures we're aware of any change.
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
static_assert_size!(DepNode, 18);
static_assert_size!(DepNode, 17);

#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
static_assert_size!(DepNode, 24);
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ rustc_queries! {
desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
}

query projection_ty_from_predicates(key: (DefId, DefId)) -> Option<ty::ProjectionTy<'tcx>> {
desc { |tcx| "finding projection type inside predicates of `{}`", tcx.def_path_str(key.0) }
}

query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLib>> {
desc { "looking up the native libraries of a linked crate" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
Some(borrow_span),
None,
);
err.buffer(&mut self.errors_buffer);
}
Expand Down Expand Up @@ -498,6 +499,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
None,
None,
);
err
}
Expand Down Expand Up @@ -718,6 +720,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
first_borrow_desc,
None,
Some((issued_span, span)),
);

err
Expand Down Expand Up @@ -1076,6 +1079,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
None,
None,
);
}
} else {
Expand All @@ -1093,6 +1097,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
None,
None,
);
}

Expand Down Expand Up @@ -1158,6 +1163,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
None,
None,
);

err.buffer(&mut self.errors_buffer);
Expand Down Expand Up @@ -1236,6 +1242,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
None,
None,
);

let within = if borrow_spans.for_generator() { " by generator" } else { "" };
Expand Down Expand Up @@ -1614,6 +1621,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
None,
None,
);

self.explain_deref_coercion(loan, &mut err);
Expand Down
26 changes: 18 additions & 8 deletions compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl BorrowExplanation {
err: &mut DiagnosticBuilder<'_>,
borrow_desc: &str,
borrow_span: Option<Span>,
multiple_borrow_span: Option<(Span, Span)>,
) {
match *self {
BorrowExplanation::UsedLater(later_use_kind, var_or_use_span, path_span) => {
Expand Down Expand Up @@ -192,14 +193,23 @@ impl BorrowExplanation {

if let Some(info) = &local_decl.is_block_tail {
if info.tail_result_is_ignored {
err.span_suggestion_verbose(
info.span.shrink_to_hi(),
"consider adding semicolon after the expression so its \
temporaries are dropped sooner, before the local variables \
declared by the block are dropped",
";".to_string(),
Applicability::MaybeIncorrect,
);
// #85581: If the first mutable borrow's scope contains
// the second borrow, this suggestion isn't helpful.
if !multiple_borrow_span
.map(|(old, new)| {
old.to(info.span.shrink_to_hi()).contains(new)
})
.unwrap_or(false)
{
err.span_suggestion_verbose(
info.span.shrink_to_hi(),
"consider adding semicolon after the expression so its \
temporaries are dropped sooner, before the local variables \
declared by the block are dropped",
";".to_string(),
Applicability::MaybeIncorrect,
);
}
} else {
err.note(
"the temporary is part of an expression at the end of a \
Expand Down
23 changes: 20 additions & 3 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ pub struct OutputFilenames {
pub out_directory: PathBuf,
filestem: String,
pub single_output_file: Option<PathBuf>,
pub temps_directory: Option<PathBuf>,
pub outputs: OutputTypes,
}

Expand All @@ -577,12 +578,14 @@ impl OutputFilenames {
out_directory: PathBuf,
out_filestem: String,
single_output_file: Option<PathBuf>,
temps_directory: Option<PathBuf>,
extra: String,
outputs: OutputTypes,
) -> Self {
OutputFilenames {
out_directory,
single_output_file,
temps_directory,
outputs,
filestem: format!("{}{}", out_filestem, extra),
}
Expand All @@ -593,7 +596,14 @@ impl OutputFilenames {
.get(&flavor)
.and_then(|p| p.to_owned())
.or_else(|| self.single_output_file.clone())
.unwrap_or_else(|| self.temp_path(flavor, None))
.unwrap_or_else(|| self.output_path(flavor))
}

/// Gets the output path where a compilation artifact of the given type
/// should be placed on disk.
pub fn output_path(&self, flavor: OutputType) -> PathBuf {
let extension = flavor.extension();
self.with_directory_and_extension(&self.out_directory, &extension)
}

/// Gets the path where a compilation artifact of the given type for the
Expand Down Expand Up @@ -628,11 +638,17 @@ impl OutputFilenames {
extension.push_str(ext);
}

self.with_extension(&extension)
let temps_directory = self.temps_directory.as_ref().unwrap_or(&self.out_directory);

self.with_directory_and_extension(&temps_directory, &extension)
}

pub fn with_extension(&self, extension: &str) -> PathBuf {
let mut path = self.out_directory.join(&self.filestem);
self.with_directory_and_extension(&self.out_directory, extension)
}

fn with_directory_and_extension(&self, directory: &PathBuf, extension: &str) -> PathBuf {
let mut path = directory.join(&self.filestem);
path.set_extension(extension);
path
}
Expand Down Expand Up @@ -1072,6 +1088,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
in <dir>",
"DIR",
),
opt::opt_s("", "temps-dir", "Write temporary output files to <dir>", "DIR"),
opt::opt_s(
"",
"explain",
Expand Down
Loading