Skip to content

Commit 0577321

Browse files
committed
Auto merge of #3026 - rust-lang:rustup-2023-08-12, r=RalfJung
Automatic sync from rustc
2 parents 13acd4f + b122fa6 commit 0577321

File tree

195 files changed

+2664
-768
lines changed

Some content is hidden

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

195 files changed

+2664
-768
lines changed

.mailmap

+3
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

+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_builtin_macros/src/format.rs

+28-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast::ptr::P;
2-
use rustc_ast::token;
32
use rustc_ast::tokenstream::TokenStream;
3+
use rustc_ast::{token, StmtKind};
44
use rustc_ast::{
55
Expr, ExprKind, FormatAlignment, FormatArgPosition, FormatArgPositionKind, FormatArgs,
66
FormatArgsPiece, FormatArgument, FormatArgumentKind, FormatArguments, FormatCount,
@@ -163,25 +163,41 @@ fn make_format_args(
163163

164164
let MacroInput { fmtstr: efmt, mut args, is_direct_literal } = input;
165165

166-
let (fmt_str, fmt_style, fmt_span) = match expr_to_spanned_string(ecx, efmt, msg) {
166+
let (fmt_str, fmt_style, fmt_span) = match expr_to_spanned_string(ecx, efmt.clone(), msg) {
167167
Ok(mut fmt) if append_newline => {
168168
fmt.0 = Symbol::intern(&format!("{}\n", fmt.0));
169169
fmt
170170
}
171171
Ok(fmt) => fmt,
172172
Err(err) => {
173173
if let Some((mut err, suggested)) = err {
174-
let sugg_fmt = match args.explicit_args().len() {
175-
0 => "{}".to_string(),
176-
_ => format!("{}{{}}", "{} ".repeat(args.explicit_args().len())),
177-
};
178174
if !suggested {
179-
err.span_suggestion(
180-
unexpanded_fmt_span.shrink_to_lo(),
181-
"you might be missing a string literal to format with",
182-
format!("\"{sugg_fmt}\", "),
183-
Applicability::MaybeIncorrect,
184-
);
175+
if let ExprKind::Block(block, None) = &efmt.kind
176+
&& block.stmts.len() == 1
177+
&& let StmtKind::Expr(expr) = &block.stmts[0].kind
178+
&& let ExprKind::Path(None, path) = &expr.kind
179+
&& path.is_potential_trivial_const_arg()
180+
{
181+
err.multipart_suggestion(
182+
"quote your inlined format argument to use as string literal",
183+
vec![
184+
(unexpanded_fmt_span.shrink_to_hi(), "\"".to_string()),
185+
(unexpanded_fmt_span.shrink_to_lo(), "\"".to_string()),
186+
],
187+
Applicability::MaybeIncorrect,
188+
);
189+
} else {
190+
let sugg_fmt = match args.explicit_args().len() {
191+
0 => "{}".to_string(),
192+
_ => format!("{}{{}}", "{} ".repeat(args.explicit_args().len())),
193+
};
194+
err.span_suggestion(
195+
unexpanded_fmt_span.shrink_to_lo(),
196+
"you might be missing a string literal to format with",
197+
format!("\"{sugg_fmt}\", "),
198+
Applicability::MaybeIncorrect,
199+
);
200+
}
185201
}
186202
err.emit();
187203
}

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/coverageinfo/mapgen.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ use rustc_middle::bug;
1212
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1313
use rustc_middle::mir::coverage::CodeRegion;
1414
use rustc_middle::ty::TyCtxt;
15-
16-
use std::ffi::CString;
15+
use rustc_span::Symbol;
1716

1817
/// Generates and exports the Coverage Map.
1918
///
@@ -89,7 +88,10 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
8988

9089
// Encode all filenames referenced by counters/expressions in this module
9190
let filenames_buffer = llvm::build_byte_buffer(|filenames_buffer| {
92-
coverageinfo::write_filenames_section_to_buffer(&mapgen.filenames, filenames_buffer);
91+
coverageinfo::write_filenames_section_to_buffer(
92+
mapgen.filenames.iter().map(Symbol::as_str),
93+
filenames_buffer,
94+
);
9395
});
9496

9597
let filenames_size = filenames_buffer.len();
@@ -117,7 +119,7 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
117119
}
118120

119121
struct CoverageMapGenerator {
120-
filenames: FxIndexSet<CString>,
122+
filenames: FxIndexSet<Symbol>,
121123
}
122124

123125
impl CoverageMapGenerator {
@@ -128,11 +130,10 @@ impl CoverageMapGenerator {
128130
// Since rustc generates coverage maps with relative paths, the
129131
// compilation directory can be combined with the relative paths
130132
// to get absolute paths, if needed.
131-
let working_dir =
132-
tcx.sess.opts.working_dir.remapped_path_if_available().to_string_lossy().to_string();
133-
let c_filename =
134-
CString::new(working_dir).expect("null error converting filename to C string");
135-
filenames.insert(c_filename);
133+
let working_dir = Symbol::intern(
134+
&tcx.sess.opts.working_dir.remapped_path_if_available().to_string_lossy(),
135+
);
136+
filenames.insert(working_dir);
136137
Self { filenames }
137138
}
138139

@@ -170,10 +171,8 @@ impl CoverageMapGenerator {
170171
current_file_id += 1;
171172
}
172173
current_file_name = Some(file_name);
173-
let c_filename = CString::new(file_name.to_string())
174-
.expect("null error converting filename to C string");
175-
debug!(" file_id: {} = '{:?}'", current_file_id, c_filename);
176-
let (filenames_index, _) = self.filenames.insert_full(c_filename);
174+
debug!(" file_id: {} = '{:?}'", current_file_id, file_name);
175+
let (filenames_index, _) = self.filenames.insert_full(file_name);
177176
virtual_file_mapping.push(filenames_index as u32);
178177
}
179178
debug!("Adding counter {:?} to map for {:?}", counter, region);

0 commit comments

Comments
 (0)