Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 76f9fb4

Browse files
committedMar 5, 2024·
Auto merge of rust-lang#122008 - jhpratt:rollup-g08ehpt, r=jhpratt
Rollup of 15 pull requests Successful merges: - rust-lang#121065 (Add basic i18n guidance for `Display`) - rust-lang#121202 (Limit the number of names and values in check-cfg diagnostics) - rust-lang#121213 (Add an example to demonstrate how Rc::into_inner works) - rust-lang#121262 (Add vector time complexity) - rust-lang#121287 (Clarify/add `must_use` message for Rc/Arc/Weak::into_raw.) - rust-lang#121664 (Adjust error `yield`/`await` lowering) - rust-lang#121838 (Use the correct logic for nested impl trait in assoc types) - rust-lang#121860 (Add a tidy check that checks whether the fluent slugs only appear once) - rust-lang#121913 (Don't panic when waiting on poisoned queries) - rust-lang#121959 (Removing absolute path in proc-macro) - rust-lang#121975 (hir_analysis: enums return `None` in `find_field`) - rust-lang#121978 (Fix duplicated path in the "not found dylib" error) - rust-lang#121987 (pattern analysis: abort on arity mismatch) - rust-lang#121993 (Avoid using unnecessary queries when printing the query stack in panics) - rust-lang#121997 (interpret/cast: make more matches on FloatTy properly exhaustive) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2eeff46 + 4a65a53 commit 76f9fb4

File tree

35 files changed

+521
-218
lines changed

35 files changed

+521
-218
lines changed
 

‎compiler/rustc_ast_lowering/src/expr.rs

+43-9
Original file line numberDiff line numberDiff line change
@@ -760,10 +760,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
760760
Some(hir::CoroutineKind::Coroutine(_))
761761
| Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _))
762762
| None => {
763-
return hir::ExprKind::Err(self.dcx().emit_err(AwaitOnlyInAsyncFnAndBlocks {
764-
await_kw_span,
765-
item_span: self.current_item,
766-
}));
763+
// Lower to a block `{ EXPR; <error> }` so that the awaited expr
764+
// is not accidentally orphaned.
765+
let stmt_id = self.next_id();
766+
let expr_err = self.expr(
767+
expr.span,
768+
hir::ExprKind::Err(self.dcx().emit_err(AwaitOnlyInAsyncFnAndBlocks {
769+
await_kw_span,
770+
item_span: self.current_item,
771+
})),
772+
);
773+
return hir::ExprKind::Block(
774+
self.block_all(
775+
expr.span,
776+
arena_vec![self; hir::Stmt {
777+
hir_id: stmt_id,
778+
kind: hir::StmtKind::Semi(expr),
779+
span: expr.span,
780+
}],
781+
Some(self.arena.alloc(expr_err)),
782+
),
783+
None,
784+
);
767785
}
768786
};
769787

@@ -1496,12 +1514,31 @@ impl<'hir> LoweringContext<'_, 'hir> {
14961514
}
14971515

14981516
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
1517+
let yielded =
1518+
opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| self.expr_unit(span));
1519+
14991520
let is_async_gen = match self.coroutine_kind {
15001521
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)) => false,
15011522
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
15021523
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => {
1503-
return hir::ExprKind::Err(
1504-
self.dcx().emit_err(AsyncCoroutinesNotSupported { span }),
1524+
// Lower to a block `{ EXPR; <error> }` so that the awaited expr
1525+
// is not accidentally orphaned.
1526+
let stmt_id = self.next_id();
1527+
let expr_err = self.expr(
1528+
yielded.span,
1529+
hir::ExprKind::Err(self.dcx().emit_err(AsyncCoroutinesNotSupported { span })),
1530+
);
1531+
return hir::ExprKind::Block(
1532+
self.block_all(
1533+
yielded.span,
1534+
arena_vec![self; hir::Stmt {
1535+
hir_id: stmt_id,
1536+
kind: hir::StmtKind::Semi(yielded),
1537+
span: yielded.span,
1538+
}],
1539+
Some(self.arena.alloc(expr_err)),
1540+
),
1541+
None,
15051542
);
15061543
}
15071544
Some(hir::CoroutineKind::Coroutine(_)) => {
@@ -1531,9 +1568,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
15311568
}
15321569
};
15331570

1534-
let yielded =
1535-
opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| self.expr_unit(span));
1536-
15371571
if is_async_gen {
15381572
// `yield $expr` is transformed into `task_context = yield async_gen_ready($expr)`.
15391573
// This ensures that we store our resumed `ResumeContext` correctly, and also that

‎compiler/rustc_const_eval/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ const_eval_intern_kind = {$kind ->
146146
*[other] {""}
147147
}
148148
149-
const_eval_invalid_align =
150-
align has to be a power of 2
151-
152149
const_eval_invalid_align_details =
153150
invalid align passed to `{$name}`: {$align} is {$err_kind ->
154151
[not_power_of_two] not a power of 2

‎compiler/rustc_const_eval/src/interpret/cast.rs

+35-23
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
182182
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
183183
use rustc_type_ir::TyKind::*;
184184

185-
let val = match src.layout.ty.kind() {
186-
// Floating point
187-
Float(FloatTy::F32) => self.cast_from_float(src.to_scalar().to_f32()?, cast_to.ty),
188-
Float(FloatTy::F64) => self.cast_from_float(src.to_scalar().to_f64()?, cast_to.ty),
189-
_ => {
190-
bug!("Can't cast 'Float' type into {}", cast_to.ty);
191-
}
185+
let Float(fty) = src.layout.ty.kind() else {
186+
bug!("FloatToFloat/FloatToInt cast: source type {} is not a float type", src.layout.ty)
187+
};
188+
let val = match fty {
189+
FloatTy::F16 => unimplemented!("f16_f128"),
190+
FloatTy::F32 => self.cast_from_float(src.to_scalar().to_f32()?, cast_to.ty),
191+
FloatTy::F64 => self.cast_from_float(src.to_scalar().to_f64()?, cast_to.ty),
192+
FloatTy::F128 => unimplemented!("f16_f128"),
192193
};
193194
Ok(ImmTy::from_scalar(val, cast_to))
194195
}
@@ -275,6 +276,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
275276
trace!("cast_from_scalar: {}, {} -> {}", v, src_layout.ty, cast_ty);
276277

277278
Ok(match *cast_ty.kind() {
279+
// int -> int
278280
Int(_) | Uint(_) => {
279281
let size = match *cast_ty.kind() {
280282
Int(t) => Integer::from_int_ty(self, t).size(),
@@ -285,15 +287,26 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
285287
Scalar::from_uint(v, size)
286288
}
287289

288-
Float(FloatTy::F32) if signed => Scalar::from_f32(Single::from_i128(v as i128).value),
289-
Float(FloatTy::F64) if signed => Scalar::from_f64(Double::from_i128(v as i128).value),
290-
Float(FloatTy::F32) => Scalar::from_f32(Single::from_u128(v).value),
291-
Float(FloatTy::F64) => Scalar::from_f64(Double::from_u128(v).value),
292-
293-
Char => {
294-
// `u8` to `char` cast
295-
Scalar::from_u32(u8::try_from(v).unwrap().into())
290+
// signed int -> float
291+
Float(fty) if signed => {
292+
let v = v as i128;
293+
match fty {
294+
FloatTy::F16 => unimplemented!("f16_f128"),
295+
FloatTy::F32 => Scalar::from_f32(Single::from_i128(v).value),
296+
FloatTy::F64 => Scalar::from_f64(Double::from_i128(v).value),
297+
FloatTy::F128 => unimplemented!("f16_f128"),
298+
}
296299
}
300+
// unsigned int -> float
301+
Float(fty) => match fty {
302+
FloatTy::F16 => unimplemented!("f16_f128"),
303+
FloatTy::F32 => Scalar::from_f32(Single::from_u128(v).value),
304+
FloatTy::F64 => Scalar::from_f64(Double::from_u128(v).value),
305+
FloatTy::F128 => unimplemented!("f16_f128"),
306+
},
307+
308+
// u8 -> char
309+
Char => Scalar::from_u32(u8::try_from(v).unwrap().into()),
297310

298311
// Casts to bool are not permitted by rustc, no need to handle them here.
299312
_ => span_bug!(self.cur_span(), "invalid int to {} cast", cast_ty),
@@ -339,14 +352,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
339352
let v = f.to_i128(size.bits_usize()).value;
340353
Scalar::from_int(v, size)
341354
}
342-
// float -> f32
343-
Float(FloatTy::F32) => {
344-
Scalar::from_f32(adjust_nan(self, f, f.convert(&mut false).value))
345-
}
346-
// float -> f64
347-
Float(FloatTy::F64) => {
348-
Scalar::from_f64(adjust_nan(self, f, f.convert(&mut false).value))
349-
}
355+
// float -> float
356+
Float(fty) => match fty {
357+
FloatTy::F16 => unimplemented!("f16_f128"),
358+
FloatTy::F32 => Scalar::from_f32(adjust_nan(self, f, f.convert(&mut false).value)),
359+
FloatTy::F64 => Scalar::from_f64(adjust_nan(self, f, f.convert(&mut false).value)),
360+
FloatTy::F128 => unimplemented!("f16_f128"),
361+
},
350362
// That's it.
351363
_ => span_bug!(self.cur_span(), "invalid float to {} cast", dest_ty),
352364
}

‎compiler/rustc_hir_analysis/src/collect.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,12 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
791791
}
792792

793793
fn find_field(tcx: TyCtxt<'_>, (def_id, ident): (DefId, Ident)) -> Option<FieldIdx> {
794-
tcx.adt_def(def_id).non_enum_variant().fields.iter_enumerated().find_map(|(idx, field)| {
794+
let adt = tcx.adt_def(def_id);
795+
if adt.is_enum() {
796+
return None;
797+
}
798+
799+
adt.non_enum_variant().fields.iter_enumerated().find_map(|(idx, field)| {
795800
if field.is_unnamed() {
796801
let field_ty = tcx.type_of(field.did).instantiate_identity();
797802
let adt_def = field_ty.ty_adt_def().expect("expect Adt for unnamed field");

‎compiler/rustc_infer/messages.ftl

-8
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,6 @@ infer_more_targeted = {$has_param_name ->
181181
182182
infer_msl_introduces_static = introduces a `'static` lifetime requirement
183183
infer_msl_unmet_req = because this has an unmet lifetime requirement
184-
infer_need_type_info_in_coroutine =
185-
type inside {$coroutine_kind ->
186-
[async_block] `async` block
187-
[async_closure] `async` closure
188-
[async_fn] `async fn` body
189-
*[coroutine] coroutine
190-
} must be known in this context
191-
192184
193185
infer_nothing = {""}
194186

‎compiler/rustc_lint/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,6 @@ lint_suspicious_double_ref_clone =
562562
lint_suspicious_double_ref_deref =
563563
using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type
564564
565-
lint_trivial_untranslatable_diag = diagnostic with static strings only
566-
567565
lint_ty_qualified = usage of qualified `ty::{$ty}`
568566
.suggestion = try importing it and using it unqualified
569567

‎compiler/rustc_lint/src/context/diagnostics.rs

+51-20
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,43 @@ use rustc_span::edit_distance::find_best_match_for_name;
1212
use rustc_span::symbol::{sym, Symbol};
1313
use rustc_span::BytePos;
1414

15+
const MAX_CHECK_CFG_NAMES_OR_VALUES: usize = 35;
16+
17+
fn check_cfg_expected_note(
18+
sess: &Session,
19+
possibilities: &[Symbol],
20+
type_: &str,
21+
name: Option<Symbol>,
22+
suffix: &str,
23+
) -> String {
24+
use std::fmt::Write;
25+
26+
let n_possibilities = if sess.opts.unstable_opts.check_cfg_all_expected {
27+
possibilities.len()
28+
} else {
29+
std::cmp::min(possibilities.len(), MAX_CHECK_CFG_NAMES_OR_VALUES)
30+
};
31+
32+
let mut possibilities = possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>();
33+
possibilities.sort();
34+
35+
let and_more = possibilities.len().saturating_sub(n_possibilities);
36+
let possibilities = possibilities[..n_possibilities].join("`, `");
37+
38+
let mut note = String::with_capacity(50 + possibilities.len());
39+
40+
write!(&mut note, "expected {type_}").unwrap();
41+
if let Some(name) = name {
42+
write!(&mut note, " for `{name}`").unwrap();
43+
}
44+
write!(&mut note, " are: {suffix}`{possibilities}`").unwrap();
45+
if and_more > 0 {
46+
write!(&mut note, " and {and_more} more").unwrap();
47+
}
48+
49+
note
50+
}
51+
1552
pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: &mut Diag<'_, ()>) {
1653
match diagnostic {
1754
BuiltinLintDiagnostics::UnicodeTextFlow(span, content) => {
@@ -291,16 +328,13 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag:
291328
}
292329
}
293330
if !possibilities.is_empty() {
294-
let mut possibilities =
295-
possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>();
296-
possibilities.sort();
297-
let possibilities = possibilities.join("`, `");
298-
299-
// The list of expected names can be long (even by default) and
300-
// so the diagnostic produced can take a lot of space. To avoid
301-
// cloging the user output we only want to print that diagnostic
302-
// once.
303-
diag.help_once(format!("expected names are: `{possibilities}`"));
331+
diag.help_once(check_cfg_expected_note(
332+
sess,
333+
&possibilities,
334+
"names",
335+
None,
336+
"",
337+
));
304338
}
305339
}
306340

@@ -343,16 +377,13 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag:
343377
// Show the full list if all possible values for a given name, but don't do it
344378
// for names as the possibilities could be very long
345379
if !possibilities.is_empty() {
346-
{
347-
let mut possibilities =
348-
possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>();
349-
possibilities.sort();
350-
351-
let possibilities = possibilities.join("`, `");
352-
let none = if have_none_possibility { "(none), " } else { "" };
353-
354-
diag.note(format!("expected values for `{name}` are: {none}`{possibilities}`"));
355-
}
380+
diag.note(check_cfg_expected_note(
381+
sess,
382+
&possibilities,
383+
"values",
384+
Some(name),
385+
if have_none_possibility { "(none), " } else { "" },
386+
));
356387

357388
if let Some((value, value_span)) = value {
358389
// Suggest the most probable if we found one

‎compiler/rustc_metadata/src/creader.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,13 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, S
11321132
Err(err) => {
11331133
// Only try to recover from this specific error.
11341134
if !matches!(err, libloading::Error::LoadLibraryExW { .. }) {
1135-
return Err(err.to_string());
1135+
let err = format_dlopen_err(&err);
1136+
// We include the path of the dylib in the error ourselves, so
1137+
// if it's in the error, we strip it.
1138+
if let Some(err) = err.strip_prefix(&format!(": {}", path.display())) {
1139+
return Err(err.to_string());
1140+
}
1141+
return Err(err);
11361142
}
11371143

11381144
last_error = Some(err);

‎compiler/rustc_parse/messages.ftl

-4
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,6 @@ parse_invalid_identifier_with_leading_number = identifiers cannot start with a n
392392
393393
parse_invalid_interpolated_expression = invalid interpolated expression
394394
395-
parse_invalid_literal_suffix = suffixes on {$kind} literals are invalid
396-
.label = invalid suffix `{$suffix}`
397-
398395
parse_invalid_literal_suffix_on_tuple_index = suffixes on a tuple index are invalid
399396
.label = invalid suffix `{$suffix}`
400397
.tuple_exception_line_1 = `{$suffix}` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
@@ -609,7 +606,6 @@ parse_nonterminal_expected_item_keyword = expected an item keyword
609606
parse_nonterminal_expected_lifetime = expected a lifetime, found `{$token}`
610607
611608
parse_nonterminal_expected_statement = expected a statement
612-
parse_not_supported = not supported
613609
614610
parse_note_edition_guide = for more on editions, read https://doc.rust-lang.org/edition-guide
615611

‎compiler/rustc_passes/messages.ftl

-5
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,6 @@ passes_export_name =
302302
attribute should be applied to a free function, impl method or static
303303
.label = not a free function, impl method or static
304304
305-
passes_expr_not_allowed_in_context =
306-
{$expr} is not allowed in a `{$context}`
307-
308305
passes_extern_main =
309306
the `main` function cannot be declared in an `extern` block
310307
@@ -405,8 +402,6 @@ passes_lang_item_on_incorrect_target =
405402
`{$name}` language item must be applied to a {$expected_target}
406403
.label = attribute should be applied to a {$expected_target}, not a {$actual_target}
407404
408-
passes_layout =
409-
layout error: {$layout_error}
410405
passes_layout_abi =
411406
abi: {$abi}
412407
passes_layout_align =

0 commit comments

Comments
 (0)