Skip to content

Commit 8396efe

Browse files
committed
Auto merge of rust-lang#117228 - matthiaskrgr:rollup-23zzepv, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#116905 (refactor(compiler/resolve): simplify some code) - rust-lang#117095 (Add way to differentiate argument locals from other locals in Stable MIR) - rust-lang#117143 (Avoid unbounded O(n^2) when parsing nested type args) - rust-lang#117194 (Minor improvements to `rustc_incremental`) - rust-lang#117202 (Revert "Remove TaKO8Ki from reviewers") - rust-lang#117207 (The value of `-Cinstrument-coverage=` doesn't need to be `Option`) - rust-lang#117214 (Quietly fail if an error has already occurred) - rust-lang#117221 (Rename type flag `HAS_TY_GENERATOR` to `HAS_TY_COROUTINE`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 698db85 + a461de7 commit 8396efe

File tree

104 files changed

+278
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+278
-82
lines changed

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_infer::infer::InferCtxt;
88
use rustc_middle::mir::ConstraintCategory;
99
use rustc_middle::traits::query::OutlivesBound;
1010
use rustc_middle::ty::{self, RegionVid, Ty};
11-
use rustc_span::{Span, DUMMY_SP};
11+
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
1212
use rustc_trait_selection::traits::query::type_op::{self, TypeOp};
1313
use std::rc::Rc;
1414
use type_op::TypeOpOutput;
@@ -318,7 +318,8 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
318318
.param_env
319319
.and(type_op::implied_outlives_bounds::ImpliedOutlivesBounds { ty })
320320
.fully_perform(self.infcx, DUMMY_SP)
321-
.unwrap_or_else(|_| bug!("failed to compute implied bounds {:?}", ty));
321+
.map_err(|_: ErrorGuaranteed| debug!("failed to compute implied bounds {:?}", ty))
322+
.ok()?;
322323
debug!(?bounds, ?constraints);
323324
self.add_outlives_bounds(bounds);
324325
constraints

compiler/rustc_incremental/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#![cfg_attr(not(bootstrap), doc(rust_logo))]
66
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
77
#![cfg_attr(not(bootstrap), allow(internal_features))]
8-
#![feature(never_type)]
98
#![recursion_limit = "256"]
109
#![deny(rustc::untranslatable_diagnostic)]
1110
#![deny(rustc::diagnostic_outside_of_impl)]
@@ -19,15 +18,11 @@ mod assert_dep_graph;
1918
mod errors;
2019
mod persist;
2120

22-
use assert_dep_graph::assert_dep_graph;
2321
pub use persist::copy_cgu_workproduct_to_incr_comp_cache_dir;
24-
pub use persist::delete_workproduct_files;
2522
pub use persist::finalize_session_directory;
26-
pub use persist::garbage_collect_session_directories;
2723
pub use persist::in_incr_comp_dir;
2824
pub use persist::in_incr_comp_dir_sess;
2925
pub use persist::load_query_result_cache;
30-
pub use persist::prepare_session_directory;
3126
pub use persist::save_dep_graph;
3227
pub use persist::save_work_product_index;
3328
pub use persist::setup_dep_graph;

compiler/rustc_incremental/src/persist/fs.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
//! ## Synchronization
5454
//!
5555
//! There is some synchronization needed in order for the compiler to be able to
56-
//! determine whether a given private session directory is not in used any more.
56+
//! determine whether a given private session directory is not in use any more.
5757
//! This is done by creating a lock file for each session directory and
5858
//! locking it while the directory is still being used. Since file locks have
5959
//! operating system support, we can rely on the lock being released if the
@@ -136,26 +136,29 @@ const QUERY_CACHE_FILENAME: &str = "query-cache.bin";
136136
const INT_ENCODE_BASE: usize = base_n::CASE_INSENSITIVE;
137137

138138
/// Returns the path to a session's dependency graph.
139-
pub fn dep_graph_path(sess: &Session) -> PathBuf {
139+
pub(crate) fn dep_graph_path(sess: &Session) -> PathBuf {
140140
in_incr_comp_dir_sess(sess, DEP_GRAPH_FILENAME)
141141
}
142+
142143
/// Returns the path to a session's staging dependency graph.
143144
///
144145
/// On the difference between dep-graph and staging dep-graph,
145146
/// see `build_dep_graph`.
146-
pub fn staging_dep_graph_path(sess: &Session) -> PathBuf {
147+
pub(crate) fn staging_dep_graph_path(sess: &Session) -> PathBuf {
147148
in_incr_comp_dir_sess(sess, STAGING_DEP_GRAPH_FILENAME)
148149
}
149-
pub fn work_products_path(sess: &Session) -> PathBuf {
150+
151+
pub(crate) fn work_products_path(sess: &Session) -> PathBuf {
150152
in_incr_comp_dir_sess(sess, WORK_PRODUCTS_FILENAME)
151153
}
154+
152155
/// Returns the path to a session's query cache.
153156
pub fn query_cache_path(sess: &Session) -> PathBuf {
154157
in_incr_comp_dir_sess(sess, QUERY_CACHE_FILENAME)
155158
}
156159

157160
/// Locks a given session directory.
158-
pub fn lock_file_path(session_dir: &Path) -> PathBuf {
161+
fn lock_file_path(session_dir: &Path) -> PathBuf {
159162
let crate_dir = session_dir.parent().unwrap();
160163

161164
let directory_name = session_dir.file_name().unwrap().to_string_lossy();
@@ -202,7 +205,7 @@ pub fn in_incr_comp_dir(incr_comp_session_dir: &Path, file_name: &str) -> PathBu
202205
/// The garbage collection will take care of it.
203206
///
204207
/// [`rustc_interface::queries::dep_graph`]: ../../rustc_interface/struct.Queries.html#structfield.dep_graph
205-
pub fn prepare_session_directory(
208+
pub(crate) fn prepare_session_directory(
206209
sess: &Session,
207210
crate_name: Symbol,
208211
stable_crate_id: StableCrateId,
@@ -373,7 +376,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
373376
let _ = garbage_collect_session_directories(sess);
374377
}
375378

376-
pub fn delete_all_session_dir_contents(sess: &Session) -> io::Result<()> {
379+
pub(crate) fn delete_all_session_dir_contents(sess: &Session) -> io::Result<()> {
377380
let sess_dir_iterator = sess.incr_comp_session_dir().read_dir()?;
378381
for entry in sess_dir_iterator {
379382
let entry = entry?;
@@ -621,7 +624,7 @@ fn is_old_enough_to_be_collected(timestamp: SystemTime) -> bool {
621624
}
622625

623626
/// Runs garbage collection for the current session.
624-
pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
627+
pub(crate) fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
625628
debug!("garbage_collect_session_directories() - begin");
626629

627630
let session_directory = sess.incr_comp_session_dir();

compiler/rustc_incremental/src/persist/load.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Code to save/load the dep-graph from files.
1+
//! Code to load the dep-graph from files.
22
33
use crate::errors;
44
use rustc_data_structures::memmap::Mmap;

compiler/rustc_incremental/src/persist/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ mod save;
1111
mod work_product;
1212

1313
pub use fs::finalize_session_directory;
14-
pub use fs::garbage_collect_session_directories;
1514
pub use fs::in_incr_comp_dir;
1615
pub use fs::in_incr_comp_dir_sess;
17-
pub use fs::prepare_session_directory;
1816
pub use load::load_query_result_cache;
1917
pub use load::setup_dep_graph;
2018
pub use load::LoadResult;
2119
pub use save::save_dep_graph;
2220
pub use save::save_work_product_index;
2321
pub use work_product::copy_cgu_workproduct_to_incr_comp_cache_dir;
24-
pub use work_product::delete_workproduct_files;

compiler/rustc_incremental/src/persist/save.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::assert_dep_graph::assert_dep_graph;
12
use crate::errors;
23
use rustc_data_structures::fx::FxIndexMap;
34
use rustc_data_structures::sync::join;
@@ -39,7 +40,7 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
3940
let dep_graph_path = dep_graph_path(sess);
4041
let staging_dep_graph_path = staging_dep_graph_path(sess);
4142

42-
sess.time("assert_dep_graph", || crate::assert_dep_graph(tcx));
43+
sess.time("assert_dep_graph", || assert_dep_graph(tcx));
4344
sess.time("check_dirty_clean", || dirty_clean::check_dirty_clean_annotations(tcx));
4445

4546
if sess.opts.unstable_opts.incremental_info {

compiler/rustc_incremental/src/persist/work_product.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use rustc_session::Session;
1111
use std::fs as std_fs;
1212
use std::path::Path;
1313

14-
/// Copies a CGU work product to the incremental compilation directory, so next compilation can find and reuse it.
14+
/// Copies a CGU work product to the incremental compilation directory, so next compilation can
15+
/// find and reuse it.
1516
pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
1617
sess: &Session,
1718
cgu_name: &str,
@@ -45,7 +46,7 @@ pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
4546
}
4647

4748
/// Removes files for a given work product.
48-
pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
49+
pub(crate) fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
4950
for (_, path) in work_product.saved_files.items().into_sorted_stable_ord() {
5051
let path = in_incr_comp_dir_sess(sess, path);
5152
if let Err(err) = std_fs::remove_file(&path) {

compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ fn test_codegen_options_tracking_hash() {
614614
tracked!(force_frame_pointers, Some(false));
615615
tracked!(force_unwind_tables, Some(true));
616616
tracked!(inline_threshold, Some(0xf007ba11));
617-
tracked!(instrument_coverage, Some(InstrumentCoverage::All));
617+
tracked!(instrument_coverage, InstrumentCoverage::All);
618618
tracked!(link_dead_code, Some(true));
619619
tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
620620
tracked!(llvm_args, vec![String::from("1"), String::from("2")]);

compiler/rustc_middle/src/ty/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl FlagComputation {
134134
if should_remove_further_specializable {
135135
self.flags -= TypeFlags::STILL_FURTHER_SPECIALIZABLE;
136136
}
137-
self.add_flags(TypeFlags::HAS_TY_GENERATOR);
137+
self.add_flags(TypeFlags::HAS_TY_COROUTINE);
138138
}
139139

140140
&ty::Closure(_, args) => {

compiler/rustc_middle/src/ty/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable<TyCtxt<'tcx>> {
4848
self.has_type_flags(TypeFlags::HAS_TY_OPAQUE)
4949
}
5050
fn has_coroutines(&self) -> bool {
51-
self.has_type_flags(TypeFlags::HAS_TY_GENERATOR)
51+
self.has_type_flags(TypeFlags::HAS_TY_COROUTINE)
5252
}
5353
fn references_error(&self) -> bool {
5454
self.has_type_flags(TypeFlags::HAS_ERROR)

compiler/rustc_parse/src/parser/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ pub struct Parser<'a> {
159159
/// appropriately.
160160
///
161161
/// See the comments in the `parse_path_segment` function for more details.
162-
unmatched_angle_bracket_count: u32,
163-
max_angle_bracket_count: u32,
162+
unmatched_angle_bracket_count: u16,
163+
max_angle_bracket_count: u16,
164+
angle_bracket_nesting: u16,
164165

165166
last_unexpected_token_span: Option<Span>,
166167
/// If present, this `Parser` is not parsing Rust code but rather a macro call.
@@ -394,6 +395,7 @@ impl<'a> Parser<'a> {
394395
break_last_token: false,
395396
unmatched_angle_bracket_count: 0,
396397
max_angle_bracket_count: 0,
398+
angle_bracket_nesting: 0,
397399
last_unexpected_token_span: None,
398400
subparser_name,
399401
capture_state: CaptureState {

compiler/rustc_parse/src/parser/path.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,24 @@ impl<'a> Parser<'a> {
487487
// Take a snapshot before attempting to parse - we can restore this later.
488488
let snapshot = is_first_invocation.then(|| self.clone());
489489

490+
self.angle_bracket_nesting += 1;
490491
debug!("parse_generic_args_with_leading_angle_bracket_recovery: (snapshotting)");
491492
match self.parse_angle_args(ty_generics) {
492-
Ok(args) => Ok(args),
493+
Ok(args) => {
494+
self.angle_bracket_nesting -= 1;
495+
Ok(args)
496+
}
497+
Err(mut e) if self.angle_bracket_nesting > 10 => {
498+
self.angle_bracket_nesting -= 1;
499+
// When encountering severely malformed code where there are several levels of
500+
// nested unclosed angle args (`f::<f::<f::<f::<...`), we avoid severe O(n^2)
501+
// behavior by bailing out earlier (#117080).
502+
e.emit();
503+
rustc_errors::FatalError.raise();
504+
}
493505
Err(e) if is_first_invocation && self.unmatched_angle_bracket_count > 0 => {
506+
self.angle_bracket_nesting -= 1;
507+
494508
// Swap `self` with our backup of the parser state before attempting to parse
495509
// generic arguments.
496510
let snapshot = mem::replace(self, snapshot.unwrap());
@@ -520,8 +534,8 @@ impl<'a> Parser<'a> {
520534
// Make a span over ${unmatched angle bracket count} characters.
521535
// This is safe because `all_angle_brackets` ensures that there are only `<`s,
522536
// i.e. no multibyte characters, in this range.
523-
let span =
524-
lo.with_hi(lo.lo() + BytePos(snapshot.unmatched_angle_bracket_count));
537+
let span = lo
538+
.with_hi(lo.lo() + BytePos(snapshot.unmatched_angle_bracket_count.into()));
525539
self.sess.emit_err(errors::UnmatchedAngle {
526540
span,
527541
plural: snapshot.unmatched_angle_bracket_count > 1,
@@ -531,7 +545,10 @@ impl<'a> Parser<'a> {
531545
self.parse_angle_args(ty_generics)
532546
}
533547
}
534-
Err(e) => Err(e),
548+
Err(e) => {
549+
self.angle_bracket_nesting -= 1;
550+
Err(e)
551+
}
535552
}
536553
}
537554

compiler/rustc_resolve/src/check_unused.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl Resolver<'_, '_> {
335335

336336
for unused in visitor.unused_imports.values() {
337337
let mut fixes = Vec::new();
338-
let mut spans = match calc_unused_spans(unused, unused.use_tree, unused.use_tree_id) {
338+
let spans = match calc_unused_spans(unused, unused.use_tree, unused.use_tree_id) {
339339
UnusedSpanResult::Used => continue,
340340
UnusedSpanResult::FlatUnused(span, remove) => {
341341
fixes.push((remove, String::new()));
@@ -353,20 +353,19 @@ impl Resolver<'_, '_> {
353353
}
354354
};
355355

356-
let len = spans.len();
357-
spans.sort();
358-
let ms = MultiSpan::from_spans(spans.clone());
359-
let mut span_snippets = spans
356+
let ms = MultiSpan::from_spans(spans);
357+
358+
let mut span_snippets = ms
359+
.primary_spans()
360360
.iter()
361-
.filter_map(|s| match tcx.sess.source_map().span_to_snippet(*s) {
362-
Ok(s) => Some(format!("`{s}`")),
363-
_ => None,
364-
})
361+
.filter_map(|span| tcx.sess.source_map().span_to_snippet(*span).ok())
362+
.map(|s| format!("`{s}`"))
365363
.collect::<Vec<String>>();
366364
span_snippets.sort();
365+
367366
let msg = format!(
368367
"unused import{}{}",
369-
pluralize!(len),
368+
pluralize!(ms.primary_spans().len()),
370369
if !span_snippets.is_empty() {
371370
format!(": {}", span_snippets.join(", "))
372371
} else {
@@ -376,7 +375,7 @@ impl Resolver<'_, '_> {
376375

377376
let fix_msg = if fixes.len() == 1 && fixes[0].0 == unused.item_span {
378377
"remove the whole `use` item"
379-
} else if spans.len() > 1 {
378+
} else if ms.primary_spans().len() > 1 {
380379
"remove the unused imports"
381380
} else {
382381
"remove the unused import"

compiler/rustc_session/src/config.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -2743,13 +2743,11 @@ pub fn build_session_options(
27432743
// This is what prevents them from being used on stable compilers.
27442744
match cg.instrument_coverage {
27452745
// Stable values:
2746-
Some(InstrumentCoverage::All | InstrumentCoverage::Off) | None => {}
2746+
InstrumentCoverage::All | InstrumentCoverage::Off => {}
27472747
// Unstable values:
2748-
Some(
2749-
InstrumentCoverage::Branch
2750-
| InstrumentCoverage::ExceptUnusedFunctions
2751-
| InstrumentCoverage::ExceptUnusedGenerics,
2752-
) => {
2748+
InstrumentCoverage::Branch
2749+
| InstrumentCoverage::ExceptUnusedFunctions
2750+
| InstrumentCoverage::ExceptUnusedGenerics => {
27532751
if !unstable_opts.unstable_options {
27542752
handler.early_error(
27552753
"`-C instrument-coverage=branch` and `-C instrument-coverage=except-*` \
@@ -2759,7 +2757,7 @@ pub fn build_session_options(
27592757
}
27602758
}
27612759

2762-
if cg.instrument_coverage.is_some() && cg.instrument_coverage != Some(InstrumentCoverage::Off) {
2760+
if cg.instrument_coverage != InstrumentCoverage::Off {
27632761
if cg.profile_generate.enabled() || cg.profile_use.is_some() {
27642762
handler.early_error(
27652763
"option `-C instrument-coverage` is not compatible with either `-C profile-use` \

compiler/rustc_session/src/options.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl CodegenOptions {
294294
// JUSTIFICATION: defn of the suggested wrapper fn
295295
#[allow(rustc::bad_opt_access)]
296296
pub fn instrument_coverage(&self) -> InstrumentCoverage {
297-
self.instrument_coverage.unwrap_or(InstrumentCoverage::Off)
297+
self.instrument_coverage
298298
}
299299
}
300300

@@ -913,23 +913,23 @@ mod parse {
913913
}
914914

915915
pub(crate) fn parse_instrument_coverage(
916-
slot: &mut Option<InstrumentCoverage>,
916+
slot: &mut InstrumentCoverage,
917917
v: Option<&str>,
918918
) -> bool {
919919
if v.is_some() {
920-
let mut bool_arg = None;
921-
if parse_opt_bool(&mut bool_arg, v) {
922-
*slot = bool_arg.unwrap().then_some(InstrumentCoverage::All);
920+
let mut bool_arg = false;
921+
if parse_bool(&mut bool_arg, v) {
922+
*slot = if bool_arg { InstrumentCoverage::All } else { InstrumentCoverage::Off };
923923
return true;
924924
}
925925
}
926926

927927
let Some(v) = v else {
928-
*slot = Some(InstrumentCoverage::All);
928+
*slot = InstrumentCoverage::All;
929929
return true;
930930
};
931931

932-
*slot = Some(match v {
932+
*slot = match v {
933933
"all" => InstrumentCoverage::All,
934934
"branch" => InstrumentCoverage::Branch,
935935
"except-unused-generics" | "except_unused_generics" => {
@@ -940,7 +940,7 @@ mod parse {
940940
}
941941
"off" | "no" | "n" | "false" | "0" => InstrumentCoverage::Off,
942942
_ => return false,
943-
});
943+
};
944944
true
945945
}
946946

@@ -1352,7 +1352,7 @@ options! {
13521352
inline_threshold: Option<u32> = (None, parse_opt_number, [TRACKED],
13531353
"set the threshold for inlining a function"),
13541354
#[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")]
1355-
instrument_coverage: Option<InstrumentCoverage> = (None, parse_instrument_coverage, [TRACKED],
1355+
instrument_coverage: InstrumentCoverage = (InstrumentCoverage::Off, parse_instrument_coverage, [TRACKED],
13561356
"instrument the generated code to support LLVM source-based code coverage \
13571357
reports (note, the compiler build config must include `profiler = true`); \
13581358
implies `-C symbol-mangling-version=v0`. Optional values are:

0 commit comments

Comments
 (0)