Skip to content

Commit a07bc13

Browse files
committed
Auto merge of rust-lang#114718 - compiler-errors:rollup-1am5rpn, r=compiler-errors
Rollup of 7 pull requests Successful merges: - rust-lang#114599 (Add impl trait declarations to SMIR) - rust-lang#114622 (rustc: Move `crate_types` and `stable_crate_id` from `Session` to `GlobalCtxt`) - rust-lang#114662 (Unlock trailing where-clauses for lazy type aliases) - rust-lang#114693 (Remove myself from the review rotation) - rust-lang#114694 (make the provisional cache slightly less broken) - rust-lang#114705 (Add spastorino to mailmap) - rust-lang#114712 (Fix a couple of bad comments) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e286f25 + 5f90689 commit a07bc13

File tree

76 files changed

+670
-252
lines changed

Some content is hidden

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

76 files changed

+670
-252
lines changed

.mailmap

+3
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ Philipp Matthias Schäfer <philipp.matthias.schaefer@posteo.de>
458458
phosphorus <steepout@qq.com>
459459
Pierre Krieger <pierre.krieger1708@gmail.com>
460460
pierwill <pierwill@users.noreply.github.com> <19642016+pierwill@users.noreply.github.com>
461+
Pietro Albini <pietro@pietroalbini.org> <pietro@pietroalbini.io> <pietro.albini@ferrous-systems.com>
461462
Pradyumna Rahul <prkinformed@gmail.com>
462463
Przemysław Wesołek <jest@go.art.pl> Przemek Wesołek <jest@go.art.pl>
463464
r00ster <r00ster91@protonmail.com>
@@ -495,6 +496,8 @@ Ryan Wiedemann <Ryan1729@gmail.com>
495496
S Pradeep Kumar <gohanpra@gmail.com>
496497
Sam Radhakrishnan <sk09idm@gmail.com>
497498
Samuel Tardieu <sam@rfc1149.net>
499+
Santiago Pastorino <spastorino@gmail.com>
500+
Santiago Pastorino <spastorino@gmail.com> <santiago@wyeworks.com>
498501
Scott McMurray <scottmcm@users.noreply.github.com>
499502
Scott Olson <scott@solson.me> Scott Olson <scott@scott-olson.org>
500503
Sean Gillespie <sean.william.g@gmail.com> swgillespie <sean.william.g@gmail.com>

compiler/rustc_ast_lowering/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
457457

458458
// Don't hash unless necessary, because it's expensive.
459459
let opt_hir_hash =
460-
if tcx.sess.needs_crate_hash() { Some(compute_hir_hash(tcx, &owners)) } else { None };
460+
if tcx.needs_crate_hash() { Some(compute_hir_hash(tcx, &owners)) } else { None };
461461
hir::Crate { owners, opt_hir_hash }
462462
}
463463

@@ -648,7 +648,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
648648
let bodies = SortedMap::from_presorted_elements(bodies);
649649

650650
// Don't hash unless necessary, because it's expensive.
651-
let (opt_hash_including_bodies, attrs_hash) = if self.tcx.sess.needs_crate_hash() {
651+
let (opt_hash_including_bodies, attrs_hash) = if self.tcx.needs_crate_hash() {
652652
self.tcx.with_stable_hashing_context(|mut hcx| {
653653
let mut stable_hasher = StableHasher::new();
654654
hcx.with_hir_bodies(node.def_id(), &bodies, |hcx| {

compiler/rustc_ast_passes/messages.ftl

+6-1
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,10 @@ ast_passes_visibility_not_permitted =
239239
.individual_impl_items = place qualifiers on individual impl items instead
240240
.individual_foreign_items = place qualifiers on individual foreign items instead
241241
242-
ast_passes_where_after_type_alias = where clauses are not allowed after the type for type aliases
242+
ast_passes_where_clause_after_type_alias = where clauses are not allowed after the type for type aliases
243+
.note = see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
244+
.help = add `#![feature(lazy_type_alias)]` to the crate attributes to enable
245+
246+
ast_passes_where_clause_before_type_alias = where clauses are not allowed before the type for type aliases
243247
.note = see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
248+
.suggestion = move it to the end of the type declaration

compiler/rustc_ast_passes/src/ast_validation.rs

+55-44
Original file line numberDiff line numberDiff line change
@@ -136,40 +136,42 @@ impl<'a> AstValidator<'a> {
136136
}
137137
}
138138

139-
fn check_gat_where(
139+
fn check_type_alias_where_clause_location(
140140
&mut self,
141-
id: NodeId,
142-
before_predicates: &[WherePredicate],
143-
where_clauses: (ast::TyAliasWhereClause, ast::TyAliasWhereClause),
144-
) {
145-
if !before_predicates.is_empty() {
146-
let mut state = State::new();
147-
if !where_clauses.1.0 {
148-
state.space();
149-
state.word_space("where");
150-
} else {
141+
ty_alias: &TyAlias,
142+
) -> Result<(), errors::WhereClauseBeforeTypeAlias> {
143+
let before_predicates =
144+
ty_alias.generics.where_clause.predicates.split_at(ty_alias.where_predicates_split).0;
145+
146+
if ty_alias.ty.is_none() || before_predicates.is_empty() {
147+
return Ok(());
148+
}
149+
150+
let mut state = State::new();
151+
if !ty_alias.where_clauses.1.0 {
152+
state.space();
153+
state.word_space("where");
154+
} else {
155+
state.word_space(",");
156+
}
157+
let mut first = true;
158+
for p in before_predicates {
159+
if !first {
151160
state.word_space(",");
152161
}
153-
let mut first = true;
154-
for p in before_predicates.iter() {
155-
if !first {
156-
state.word_space(",");
157-
}
158-
first = false;
159-
state.print_where_predicate(p);
160-
}
161-
let suggestion = state.s.eof();
162-
self.lint_buffer.buffer_lint_with_diagnostic(
163-
DEPRECATED_WHERE_CLAUSE_LOCATION,
164-
id,
165-
where_clauses.0.1,
166-
fluent::ast_passes_deprecated_where_clause_location,
167-
BuiltinLintDiagnostics::DeprecatedWhereclauseLocation(
168-
where_clauses.1.1.shrink_to_hi(),
169-
suggestion,
170-
),
171-
);
162+
first = false;
163+
state.print_where_predicate(p);
172164
}
165+
166+
let span = ty_alias.where_clauses.0.1;
167+
Err(errors::WhereClauseBeforeTypeAlias {
168+
span,
169+
sugg: errors::WhereClauseBeforeTypeAliasSugg {
170+
left: span,
171+
snippet: state.s.eof(),
172+
right: ty_alias.where_clauses.1.1.shrink_to_hi(),
173+
},
174+
})
173175
}
174176

175177
fn with_impl_trait(&mut self, outer: Option<Span>, f: impl FnOnce(&mut Self)) {
@@ -1009,7 +1011,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10091011
replace_span: self.ending_semi_or_hi(item.span),
10101012
});
10111013
}
1012-
ItemKind::TyAlias(box TyAlias { defaultness, where_clauses, bounds, ty, .. }) => {
1014+
ItemKind::TyAlias(
1015+
ty_alias @ box TyAlias { defaultness, bounds, where_clauses, ty, .. },
1016+
) => {
10131017
self.check_defaultness(item.span, *defaultness);
10141018
if ty.is_none() {
10151019
self.session.emit_err(errors::TyAliasWithoutBody {
@@ -1018,9 +1022,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10181022
});
10191023
}
10201024
self.check_type_no_bounds(bounds, "this context");
1021-
if where_clauses.1.0 {
1022-
self.err_handler()
1023-
.emit_err(errors::WhereAfterTypeAlias { span: where_clauses.1.1 });
1025+
1026+
if self.session.features_untracked().lazy_type_alias {
1027+
if let Err(err) = self.check_type_alias_where_clause_location(ty_alias) {
1028+
self.err_handler().emit_err(err);
1029+
}
1030+
} else if where_clauses.1.0 {
1031+
self.err_handler().emit_err(errors::WhereClauseAfterTypeAlias {
1032+
span: where_clauses.1.1,
1033+
help: self.session.is_nightly_build().then_some(()),
1034+
});
10241035
}
10251036
}
10261037
_ => {}
@@ -1313,18 +1324,18 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13131324
}
13141325
}
13151326

1316-
if let AssocItemKind::Type(box TyAlias {
1317-
generics,
1318-
where_clauses,
1319-
where_predicates_split,
1320-
ty: Some(_),
1321-
..
1322-
}) = &item.kind
1327+
if let AssocItemKind::Type(ty_alias) = &item.kind
1328+
&& let Err(err) = self.check_type_alias_where_clause_location(ty_alias)
13231329
{
1324-
self.check_gat_where(
1330+
self.lint_buffer.buffer_lint_with_diagnostic(
1331+
DEPRECATED_WHERE_CLAUSE_LOCATION,
13251332
item.id,
1326-
generics.where_clause.predicates.split_at(*where_predicates_split).0,
1327-
*where_clauses,
1333+
err.span,
1334+
fluent::ast_passes_deprecated_where_clause_location,
1335+
BuiltinLintDiagnostics::DeprecatedWhereclauseLocation(
1336+
err.sugg.right,
1337+
err.sugg.snippet,
1338+
),
13281339
);
13291340
}
13301341

compiler/rustc_ast_passes/src/errors.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,37 @@ pub struct FieldlessUnion {
496496
}
497497

498498
#[derive(Diagnostic)]
499-
#[diag(ast_passes_where_after_type_alias)]
499+
#[diag(ast_passes_where_clause_after_type_alias)]
500500
#[note]
501-
pub struct WhereAfterTypeAlias {
501+
pub struct WhereClauseAfterTypeAlias {
502502
#[primary_span]
503503
pub span: Span,
504+
#[help]
505+
pub help: Option<()>,
506+
}
507+
508+
#[derive(Diagnostic)]
509+
#[diag(ast_passes_where_clause_before_type_alias)]
510+
#[note]
511+
pub struct WhereClauseBeforeTypeAlias {
512+
#[primary_span]
513+
pub span: Span,
514+
#[subdiagnostic]
515+
pub sugg: WhereClauseBeforeTypeAliasSugg,
516+
}
517+
518+
#[derive(Subdiagnostic)]
519+
#[multipart_suggestion(
520+
ast_passes_suggestion,
521+
applicability = "machine-applicable",
522+
style = "verbose"
523+
)]
524+
pub struct WhereClauseBeforeTypeAliasSugg {
525+
#[suggestion_part(code = "")]
526+
pub left: Span,
527+
pub snippet: String,
528+
#[suggestion_part(code = "{snippet}")]
529+
pub right: Span,
504530
}
505531

506532
#[derive(Diagnostic)]

compiler/rustc_codegen_cranelift/src/driver/jit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
9898
tcx.sess.fatal("JIT mode doesn't work with `cargo check`");
9999
}
100100

101-
if !tcx.sess.crate_types().contains(&rustc_session::config::CrateType::Executable) {
101+
if !tcx.crate_types().contains(&rustc_session::config::CrateType::Executable) {
102102
tcx.sess.fatal("can't jit non-executable crate");
103103
}
104104

compiler/rustc_codegen_llvm/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub unsafe fn create_module<'ll>(
209209
// PIE is potentially more effective than PIC, but can only be used in executables.
210210
// If all our outputs are executables, then we can relax PIC to PIE.
211211
if reloc_model == RelocModel::Pie
212-
|| sess.crate_types().iter().all(|ty| *ty == CrateType::Executable)
212+
|| tcx.crate_types().iter().all(|ty| *ty == CrateType::Executable)
213213
{
214214
llvm::LLVMRustSetModulePIELevel(llmod);
215215
}

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
9292
// each rlib could produce a different set of visualizers that would be embedded
9393
// in the `.debug_gdb_scripts` section. For that reason, we make sure that the
9494
// section is only emitted for leaf crates.
95-
let embed_visualizers = cx.sess().crate_types().iter().any(|&crate_type| match crate_type {
95+
let embed_visualizers = cx.tcx.crate_types().iter().any(|&crate_type| match crate_type {
9696
CrateType::Executable | CrateType::Dylib | CrateType::Cdylib | CrateType::Staticlib => {
9797
// These are crate types for which we will embed pretty printers since they
9898
// are treated as leaf crates.

compiler/rustc_codegen_llvm/src/mono_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl CodegenCx<'_, '_> {
111111
}
112112

113113
// Symbols from executables can't really be imported any further.
114-
let all_exe = self.tcx.sess.crate_types().iter().all(|ty| *ty == CrateType::Executable);
114+
let all_exe = self.tcx.crate_types().iter().all(|ty| *ty == CrateType::Executable);
115115
let is_declaration_for_linker =
116116
is_declaration || linkage == llvm::Linkage::AvailableExternallyLinkage;
117117
if all_exe && !is_declaration_for_linker {

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn link_binary<'a>(
6969
let _timer = sess.timer("link_binary");
7070
let output_metadata = sess.opts.output_types.contains_key(&OutputType::Metadata);
7171
let mut tempfiles_for_stdout_output: Vec<PathBuf> = Vec::new();
72-
for &crate_type in sess.crate_types().iter() {
72+
for &crate_type in &codegen_results.crate_info.crate_types {
7373
// Ignore executable crates if we have -Z no-codegen, as they will error.
7474
if (sess.opts.unstable_opts.no_codegen || !sess.opts.output_types.should_codegen())
7575
&& !output_metadata

compiler/rustc_codegen_ssa/src/back/linker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec<String> {
17031703
return Vec::new();
17041704
}
17051705

1706-
let stable_crate_id = tcx.sess.local_stable_crate_id();
1706+
let stable_crate_id = tcx.stable_crate_id(LOCAL_CRATE);
17071707
let proc_macro_decls_name = tcx.sess.generate_proc_macro_decls_symbol(stable_crate_id);
17081708
let metadata_symbol_name = exported_symbols::metadata_symbol_name(tcx);
17091709

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_session::config::{CrateType, OomStrategy};
1919
use rustc_target::spec::SanitizerSet;
2020

2121
pub fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
22-
crates_export_threshold(&tcx.sess.crate_types())
22+
crates_export_threshold(tcx.crate_types())
2323
}
2424

2525
fn crate_export_threshold(crate_type: CrateType) -> SymbolExportLevel {
@@ -290,8 +290,8 @@ fn exported_symbols_provider_local(
290290
}));
291291
}
292292

293-
if tcx.sess.crate_types().contains(&CrateType::Dylib)
294-
|| tcx.sess.crate_types().contains(&CrateType::ProcMacro)
293+
if tcx.crate_types().contains(&CrateType::Dylib)
294+
|| tcx.crate_types().contains(&CrateType::ProcMacro)
295295
{
296296
let symbol_name = metadata_symbol_name(tcx);
297297
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));

compiler/rustc_codegen_ssa/src/back/write.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub struct ModuleConfig {
123123
impl ModuleConfig {
124124
fn new(
125125
kind: ModuleKind,
126-
sess: &Session,
126+
tcx: TyCtxt<'_>,
127127
no_builtins: bool,
128128
is_compiler_builtins: bool,
129129
) -> ModuleConfig {
@@ -135,6 +135,7 @@ impl ModuleConfig {
135135
};
136136
}
137137

138+
let sess = tcx.sess;
138139
let opt_level_and_size = if_regular!(Some(sess.opts.optimize), None);
139140

140141
let save_temps = sess.opts.cg.save_temps;
@@ -166,7 +167,7 @@ impl ModuleConfig {
166167
// `#![no_builtins]` is assumed to not participate in LTO and
167168
// instead goes on to generate object code.
168169
EmitObj::Bitcode
169-
} else if need_bitcode_in_object(sess) {
170+
} else if need_bitcode_in_object(tcx) {
170171
EmitObj::ObjectCode(BitcodeSection::Full)
171172
} else {
172173
EmitObj::ObjectCode(BitcodeSection::None)
@@ -414,9 +415,10 @@ pub struct CompiledModules {
414415
pub allocator_module: Option<CompiledModule>,
415416
}
416417

417-
fn need_bitcode_in_object(sess: &Session) -> bool {
418+
fn need_bitcode_in_object(tcx: TyCtxt<'_>) -> bool {
419+
let sess = tcx.sess;
418420
let requested_for_rlib = sess.opts.cg.embed_bitcode
419-
&& sess.crate_types().contains(&CrateType::Rlib)
421+
&& tcx.crate_types().contains(&CrateType::Rlib)
420422
&& sess.opts.output_types.contains_key(&OutputType::Exe);
421423
let forced_by_target = sess.target.forces_embed_bitcode;
422424
requested_for_rlib || forced_by_target
@@ -450,11 +452,11 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
450452
let crate_info = CrateInfo::new(tcx, target_cpu);
451453

452454
let regular_config =
453-
ModuleConfig::new(ModuleKind::Regular, sess, no_builtins, is_compiler_builtins);
455+
ModuleConfig::new(ModuleKind::Regular, tcx, no_builtins, is_compiler_builtins);
454456
let metadata_config =
455-
ModuleConfig::new(ModuleKind::Metadata, sess, no_builtins, is_compiler_builtins);
457+
ModuleConfig::new(ModuleKind::Metadata, tcx, no_builtins, is_compiler_builtins);
456458
let allocator_config =
457-
ModuleConfig::new(ModuleKind::Allocator, sess, no_builtins, is_compiler_builtins);
459+
ModuleConfig::new(ModuleKind::Allocator, tcx, no_builtins, is_compiler_builtins);
458460

459461
let (shared_emitter, shared_emitter_main) = SharedEmitter::new();
460462
let (codegen_worker_send, codegen_worker_receive) = channel();
@@ -1092,7 +1094,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
10921094
};
10931095

10941096
let cgcx = CodegenContext::<B> {
1095-
crate_types: sess.crate_types().to_vec(),
1097+
crate_types: tcx.crate_types().to_vec(),
10961098
each_linked_rlib_for_lto,
10971099
lto: sess.lto(),
10981100
fewer_names: sess.fewer_names(),
@@ -2063,7 +2065,7 @@ fn msvc_imps_needed(tcx: TyCtxt<'_>) -> bool {
20632065
);
20642066

20652067
tcx.sess.target.is_like_windows &&
2066-
tcx.sess.crate_types().iter().any(|ct| *ct == CrateType::Rlib) &&
2068+
tcx.crate_types().iter().any(|ct| *ct == CrateType::Rlib) &&
20672069
// ThinLTO can't handle this workaround in all cases, so we don't
20682070
// emit the `__imp_` symbols. Instead we make them unnecessary by disallowing
20692071
// dynamic linking when linker plugin LTO is enabled.

0 commit comments

Comments
 (0)