Skip to content

Commit a07bc13

Browse files
committed
Auto merge of #114718 - compiler-errors:rollup-1am5rpn, r=compiler-errors
Rollup of 7 pull requests Successful merges: - #114599 (Add impl trait declarations to SMIR) - #114622 (rustc: Move `crate_types` and `stable_crate_id` from `Session` to `GlobalCtxt`) - #114662 (Unlock trailing where-clauses for lazy type aliases) - #114693 (Remove myself from the review rotation) - #114694 (make the provisional cache slightly less broken) - #114705 (Add spastorino to mailmap) - #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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ Philipp Matthias Schäfer <[email protected]>
458458
phosphorus <[email protected]>
459459
Pierre Krieger <[email protected]>
460460
461+
461462
Pradyumna Rahul <[email protected]>
462463
Przemysław Wesołek <[email protected]> Przemek Wesołek <[email protected]>
463464
@@ -495,6 +496,8 @@ Ryan Wiedemann <[email protected]>
495496
S Pradeep Kumar <[email protected]>
496497
Sam Radhakrishnan <[email protected]>
497498
Samuel Tardieu <[email protected]>
499+
Santiago Pastorino <[email protected]>
500+
Santiago Pastorino <[email protected]> <[email protected]>
498501
Scott McMurray <[email protected]>
499502
Scott Olson <[email protected]> Scott Olson <[email protected]>
500503
Sean Gillespie <[email protected]> swgillespie <[email protected]>

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 6 additions & 1 deletion
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

Lines changed: 55 additions & 44 deletions
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

Lines changed: 28 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)