Skip to content

Commit 6ac86bb

Browse files
committed
Auto merge of #2991 - rust-lang:rustup-2023-07-26, r=RalfJung
Automatic sync from rustc
2 parents cba1df1 + 38665a1 commit 6ac86bb

File tree

351 files changed

+9259
-3364
lines changed

Some content is hidden

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

351 files changed

+9259
-3364
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,9 @@ dependencies = [
641641

642642
[[package]]
643643
name = "compiler_builtins"
644-
version = "0.1.95"
644+
version = "0.1.98"
645645
source = "registry+https://github.com/rust-lang/crates.io-index"
646-
checksum = "6866e0f3638013234db3c89ead7a14d278354338e7237257407500009012b23f"
646+
checksum = "dfbefa16407456e5cad1ad066c84dfcb980afe4437103a0007d1c2f136130210"
647647
dependencies = [
648648
"cc",
649649
"rustc-std-workspace-core",

compiler/rustc_abi/src/layout.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,9 @@ pub trait LayoutCalculator {
763763
let mut size = Size::ZERO;
764764
let only_variant = &variants[FIRST_VARIANT];
765765
for field in only_variant {
766-
assert!(field.0.is_sized());
766+
if field.0.is_unsized() {
767+
self.delay_bug("unsized field in union".to_string());
768+
}
767769

768770
align = align.max(field.align());
769771
max_repr_align = max_repr_align.max(field.max_repr_align());

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ impl FieldsShape {
11891189
}
11901190
FieldsShape::Array { stride, count } => {
11911191
let i = u64::try_from(i).unwrap();
1192-
assert!(i < count);
1192+
assert!(i < count, "tried to access field {} of array with {} fields", i, count);
11931193
stride * i
11941194
}
11951195
FieldsShape::Arbitrary { ref offsets, .. } => offsets[FieldIdx::from_usize(i)],
@@ -1345,7 +1345,6 @@ impl Abi {
13451345

13461346
/// Discard validity range information and allow undef.
13471347
pub fn to_union(&self) -> Self {
1348-
assert!(self.is_sized());
13491348
match *self {
13501349
Abi::Scalar(s) => Abi::Scalar(s.to_union()),
13511350
Abi::ScalarPair(s1, s2) => Abi::ScalarPair(s1.to_union(), s2.to_union()),

compiler/rustc_ast/src/util/comments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
6262
CommentKind::Block => {
6363
// Whatever happens, we skip the first line.
6464
let mut i = lines
65-
.get(0)
65+
.first()
6666
.map(|l| if l.trim_start().starts_with('*') { 0 } else { 1 })
6767
.unwrap_or(0);
6868
let mut j = lines.len();

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
286286
ExprKind::OffsetOf(container, fields) => hir::ExprKind::OffsetOf(
287287
self.lower_ty(
288288
container,
289-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::OffsetOf),
289+
&ImplTraitContext::Disallowed(ImplTraitPosition::OffsetOf),
290290
),
291291
self.arena.alloc_from_iter(fields.iter().map(|&ident| self.lower_ident(ident))),
292292
),

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,15 +697,15 @@ pub fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> St
697697
write!(template, "{n}").unwrap();
698698
if p.format_options != Default::default() || p.format_trait != FormatTrait::Display
699699
{
700-
template.push_str(":");
700+
template.push(':');
701701
}
702702
if let Some(fill) = p.format_options.fill {
703703
template.push(fill);
704704
}
705705
match p.format_options.alignment {
706-
Some(FormatAlignment::Left) => template.push_str("<"),
707-
Some(FormatAlignment::Right) => template.push_str(">"),
708-
Some(FormatAlignment::Center) => template.push_str("^"),
706+
Some(FormatAlignment::Left) => template.push('<'),
707+
Some(FormatAlignment::Right) => template.push('>'),
708+
Some(FormatAlignment::Center) => template.push('^'),
709709
None => {}
710710
}
711711
match p.format_options.sign {

compiler/rustc_borrowck/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,11 +2306,10 @@ mod error {
23062306

23072307
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorGuaranteed>) {
23082308
if let None = self.tainted_by_errors {
2309-
self.tainted_by_errors = Some(
2310-
self.tcx
2311-
.sess
2312-
.delay_span_bug(t.span.clone(), "diagnostic buffered but not emitted"),
2313-
)
2309+
self.tainted_by_errors = Some(self.tcx.sess.delay_span_bug(
2310+
t.span.clone_ignoring_labels(),
2311+
"diagnostic buffered but not emitted",
2312+
))
23142313
}
23152314
t.buffer(&mut self.buffered);
23162315
}

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ fn check_opaque_type_well_formed<'tcx>(
339339
// version.
340340
let errors = ocx.select_all_or_error();
341341

342-
// This is still required for many(half of the tests in ui/type-alias-impl-trait)
343-
// tests to pass
342+
// This is fishy, but we check it again in `check_opaque_meets_bounds`.
343+
// Remove once we can prepopulate with known hidden types.
344344
let _ = infcx.take_opaque_types();
345345

346346
if errors.is_empty() {

compiler/rustc_builtin_macros/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ builtin_macros_derive_path_args_value = traits in `#[derive(...)]` don't accept
109109
.suggestion = remove the value
110110
111111
builtin_macros_env_not_defined = environment variable `{$var}` not defined at compile time
112-
.cargo = Cargo sets build script variables at run time. Use `std::env::var("{$var}")` instead
113-
.other = use `std::env::var("{$var}")` to read the variable at run time
112+
.cargo = Cargo sets build script variables at run time. Use `std::env::var({$var_expr})` instead
113+
.custom = use `std::env::var({$var_expr})` to read the variable at run time
114114
115115
builtin_macros_env_takes_args = `env!()` takes 1 or 2 arguments
116116

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
401401
// should have errored above during parsing
402402
[] => unreachable!(),
403403
[(abi, _span)] => args.clobber_abis.push((*abi, full_span)),
404-
[abis @ ..] => {
404+
abis => {
405405
for (abi, span) in abis {
406406
args.clobber_abis.push((*abi, *span));
407407
}

compiler/rustc_builtin_macros/src/env.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55

66
use rustc_ast::tokenstream::TokenStream;
7-
use rustc_ast::{self as ast, GenericArg};
7+
use rustc_ast::{self as ast, AstDeref, GenericArg};
88
use rustc_expand::base::{self, *};
99
use rustc_span::symbol::{kw, sym, Ident, Symbol};
1010
use rustc_span::Span;
@@ -76,41 +76,46 @@ pub fn expand_env<'cx>(
7676
},
7777
};
7878

79-
let sp = cx.with_def_site_ctxt(sp);
79+
let span = cx.with_def_site_ctxt(sp);
8080
let value = env::var(var.as_str()).ok().as_deref().map(Symbol::intern);
8181
cx.sess.parse_sess.env_depinfo.borrow_mut().insert((var, value));
8282
let e = match value {
8383
None => {
84-
// Use the string literal in the code in the diagnostic to avoid confusing diagnostics,
85-
// e.g. when the literal contains escape sequences.
8684
let ast::ExprKind::Lit(ast::token::Lit {
87-
kind: ast::token::LitKind::Str,
88-
symbol: original_var,
85+
kind: ast::token::LitKind::Str | ast::token::LitKind::StrRaw(..),
86+
symbol,
8987
..
9088
}) = &var_expr.kind
9189
else {
9290
unreachable!("`expr_to_string` ensures this is a string lit")
9391
};
94-
cx.emit_err(errors::EnvNotDefined {
95-
span: sp,
96-
msg: custom_msg,
97-
var: *original_var,
98-
help: custom_msg.is_none().then(|| help_for_missing_env_var(var.as_str())),
99-
});
92+
93+
if let Some(msg_from_user) = custom_msg {
94+
cx.emit_err(errors::EnvNotDefinedWithUserMessage { span, msg_from_user });
95+
} else if is_cargo_env_var(var.as_str()) {
96+
cx.emit_err(errors::EnvNotDefined::CargoEnvVar {
97+
span,
98+
var: *symbol,
99+
var_expr: var_expr.ast_deref(),
100+
});
101+
} else {
102+
cx.emit_err(errors::EnvNotDefined::CustomEnvVar {
103+
span,
104+
var: *symbol,
105+
var_expr: var_expr.ast_deref(),
106+
});
107+
}
108+
100109
return DummyResult::any(sp);
101110
}
102111
Some(value) => cx.expr_str(sp, value),
103112
};
104113
MacEager::expr(e)
105114
}
106115

107-
fn help_for_missing_env_var(var: &str) -> errors::EnvNotDefinedHelp {
108-
if var.starts_with("CARGO_")
116+
/// Returns `true` if an environment variable from `env!` is one used by Cargo.
117+
fn is_cargo_env_var(var: &str) -> bool {
118+
var.starts_with("CARGO_")
109119
|| var.starts_with("DEP_")
110120
|| matches!(var, "OUT_DIR" | "OPT_LEVEL" | "PROFILE" | "HOST" | "TARGET")
111-
{
112-
errors::EnvNotDefinedHelp::CargoVar
113-
} else {
114-
errors::EnvNotDefinedHelp::Other
115-
}
116121
}

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -440,43 +440,43 @@ pub(crate) struct EnvTakesArgs {
440440
pub(crate) span: Span,
441441
}
442442

443-
//#[derive(Diagnostic)]
444-
//#[diag(builtin_macros_env_not_defined)]
445-
pub(crate) struct EnvNotDefined {
443+
pub(crate) struct EnvNotDefinedWithUserMessage {
446444
pub(crate) span: Span,
447-
pub(crate) msg: Option<Symbol>,
448-
pub(crate) var: Symbol,
449-
pub(crate) help: Option<EnvNotDefinedHelp>,
445+
pub(crate) msg_from_user: Symbol,
450446
}
451447

452-
// Hand-written implementation to support custom user messages
453-
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for EnvNotDefined {
448+
// Hand-written implementation to support custom user messages.
449+
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for EnvNotDefinedWithUserMessage {
454450
#[track_caller]
455451
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, G> {
456-
let mut diag = if let Some(msg) = self.msg {
457-
#[expect(
458-
rustc::untranslatable_diagnostic,
459-
reason = "cannot translate user-provided messages"
460-
)]
461-
handler.struct_diagnostic(msg.to_string())
462-
} else {
463-
handler.struct_diagnostic(crate::fluent_generated::builtin_macros_env_not_defined)
464-
};
465-
diag.set_arg("var", self.var);
452+
#[expect(
453+
rustc::untranslatable_diagnostic,
454+
reason = "cannot translate user-provided messages"
455+
)]
456+
let mut diag = handler.struct_diagnostic(self.msg_from_user.to_string());
466457
diag.set_span(self.span);
467-
if let Some(help) = self.help {
468-
diag.subdiagnostic(help);
469-
}
470458
diag
471459
}
472460
}
473461

474-
#[derive(Subdiagnostic)]
475-
pub(crate) enum EnvNotDefinedHelp {
462+
#[derive(Diagnostic)]
463+
pub(crate) enum EnvNotDefined<'a> {
464+
#[diag(builtin_macros_env_not_defined)]
476465
#[help(builtin_macros_cargo)]
477-
CargoVar,
478-
#[help(builtin_macros_other)]
479-
Other,
466+
CargoEnvVar {
467+
#[primary_span]
468+
span: Span,
469+
var: Symbol,
470+
var_expr: &'a rustc_ast::Expr,
471+
},
472+
#[diag(builtin_macros_env_not_defined)]
473+
#[help(builtin_macros_custom)]
474+
CustomEnvVar {
475+
#[primary_span]
476+
span: Span,
477+
var: Symbol,
478+
var_expr: &'a rustc_ast::Expr,
479+
},
480480
}
481481

482482
#[derive(Diagnostic)]

compiler/rustc_codegen_gcc/messages.ftl

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,6 @@
11
codegen_gcc_invalid_minimum_alignment =
22
invalid minimum global alignment: {$err}
33
4-
codegen_gcc_invalid_monomorphization_basic_integer =
5-
invalid monomorphization of `{$name}` intrinsic: expected basic integer type, found `{$ty}`
6-
7-
codegen_gcc_invalid_monomorphization_expected_signed_unsigned =
8-
invalid monomorphization of `{$name}` intrinsic: expected element type `{$elem_ty}` of vector type `{$vec_ty}` to be a signed or unsigned integer type
9-
10-
codegen_gcc_invalid_monomorphization_expected_simd =
11-
invalid monomorphization of `{$name}` intrinsic: expected SIMD {$expected_ty} type, found non-SIMD `{$found_ty}`
12-
13-
codegen_gcc_invalid_monomorphization_inserted_type =
14-
invalid monomorphization of `{$name}` intrinsic: expected inserted type `{$in_elem}` (element of input `{$in_ty}`), found `{$out_ty}`
15-
16-
codegen_gcc_invalid_monomorphization_invalid_bitmask =
17-
invalid monomorphization of `{$name}` intrinsic: invalid bitmask `{$ty}`, expected `u{$expected_int_bits}` or `[u8; {$expected_bytes}]`
18-
19-
codegen_gcc_invalid_monomorphization_invalid_float_vector =
20-
invalid monomorphization of `{$name}` intrinsic: unsupported element type `{$elem_ty}` of floating-point vector `{$vec_ty}`
21-
22-
codegen_gcc_invalid_monomorphization_mask_type =
23-
invalid monomorphization of `{$name}` intrinsic: mask element type is `{$ty}`, expected `i_`
24-
25-
codegen_gcc_invalid_monomorphization_mismatched_lengths =
26-
invalid monomorphization of `{$name}` intrinsic: mismatched lengths: mask length `{$m_len}` != other vector length `{$v_len}`
27-
28-
codegen_gcc_invalid_monomorphization_not_float =
29-
invalid monomorphization of `{$name}` intrinsic: `{$ty}` is not a floating-point type
30-
31-
codegen_gcc_invalid_monomorphization_return_element =
32-
invalid monomorphization of `{$name}` intrinsic: expected return element type `{$in_elem}` (element of input `{$in_ty}`), found `{$ret_ty}` with element type `{$out_ty}`
33-
34-
codegen_gcc_invalid_monomorphization_return_integer_type =
35-
invalid monomorphization of `{$name}` intrinsic: expected return type with integer elements, found `{$ret_ty}` with non-integer `{$out_ty}`
36-
37-
codegen_gcc_invalid_monomorphization_return_length =
38-
invalid monomorphization of `{$name}` intrinsic: expected return type of length {$in_len}, found `{$ret_ty}` with length {$out_len}
39-
40-
codegen_gcc_invalid_monomorphization_return_length_input_type =
41-
invalid monomorphization of `{$name}` intrinsic: expected return type with length {$in_len} (same as input type `{$in_ty}`), found `{$ret_ty}` with length {$out_len}
42-
43-
codegen_gcc_invalid_monomorphization_return_type =
44-
invalid monomorphization of `{$name}` intrinsic: expected return type `{$in_elem}` (element of input `{$in_ty}`), found `{$ret_ty}`
45-
46-
codegen_gcc_invalid_monomorphization_simd_shuffle =
47-
invalid monomorphization of `{$name}` intrinsic: simd_shuffle index must be an array of `u32`, got `{$ty}`
48-
49-
codegen_gcc_invalid_monomorphization_unrecognized =
50-
invalid monomorphization of `{$name}` intrinsic: unrecognized intrinsic `{$name}`
51-
52-
codegen_gcc_invalid_monomorphization_unsupported_cast =
53-
invalid monomorphization of `{$name}` intrinsic: unsupported cast from `{$in_ty}` with element `{$in_elem}` to `{$ret_ty}` with element `{$out_elem}`
54-
55-
codegen_gcc_invalid_monomorphization_unsupported_element =
56-
invalid monomorphization of `{$name}` intrinsic: unsupported {$name} from `{$in_ty}` with element `{$elem_ty}` to `{$ret_ty}`
57-
58-
codegen_gcc_invalid_monomorphization_unsupported_operation =
59-
invalid monomorphization of `{$name}` intrinsic: unsupported operation on `{$in_ty}` with element `{$in_elem}`
60-
614
codegen_gcc_lto_not_supported =
625
LTO is not supported. You may get a linker error.
636

0 commit comments

Comments
 (0)