Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 15 pull requests #122008

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1f2db3d
Add an example to demonstrate how Rc::into_inner works
Takashiidobe Feb 17, 2024
cb8ce9d
time complexity for push
20jasper Feb 16, 2024
bb6dca0
time complexity for push_within_capacity
20jasper Feb 16, 2024
0a5d684
time complexity for pop
20jasper Feb 16, 2024
d2f825f
time complexity for insert
20jasper Feb 18, 2024
ef1a584
intradoc link for vec
20jasper Feb 18, 2024
a9cfeb3
fix typo in push documentation
20jasper Feb 18, 2024
bc52e5d
Fix error in push docs
20jasper Feb 18, 2024
261da5f
Clarify/add `must_use` message for Rc/Arc/Weak::into_raw.
zachs18 Feb 19, 2024
74151cb
Make push docs more vague
20jasper Feb 25, 2024
e0a726c
Adjust error yield/await lowering
compiler-errors Feb 27, 2024
91322f4
Limit the number of names and values in check-cfg diagnostics
Urgau Feb 16, 2024
f5f11e1
Add regression test
oli-obk Mar 1, 2024
c3954b3
Add a tidy check that checks whether the fluent slugs only appear once
mu001999 Mar 2, 2024
d88c7ff
Remove unused fluent messages
mu001999 Mar 2, 2024
dd0004a
Don't panic when waiting on poisoned queries
Zoxc Aug 16, 2023
a9a9798
Removing absolute path in proc-macro
sundeep-kokkonda Mar 4, 2024
8364a06
Merge the impl trait in assoc type collector into the opaque type col…
oli-obk Mar 4, 2024
4e03c51
hir_analysis: enums return `None` in `find_field`
davidtwco Mar 4, 2024
640e99c
Fix duplicated path in the "not found dylib" error
GuillaumeGomez Mar 4, 2024
5e6e140
Add regression ui test for duplicated path in dylib error
GuillaumeGomez Mar 4, 2024
2af01a2
Abort on arity mismatch
Nadrieril Mar 4, 2024
fb91610
Avoid using unnecessary queries when printing the query stack in panics
Zoxc Mar 4, 2024
86e88fc
interpret/cast: make more matches on FloatTy properly exhaustive
RalfJung Mar 4, 2024
681dc38
typo
RalfJung Mar 4, 2024
4dbd256
Explain use of display adapters
CAD97 Feb 14, 2024
215a4b6
doc wording improvements
CAD97 Mar 5, 2024
6e85695
Rollup merge of #121065 - CAD97:display-i18n, r=cuviper
jhpratt Mar 5, 2024
7fb3b5e
Rollup merge of #121202 - Urgau:check-cfg-limit-diagnostics, r=pnkfelix
jhpratt Mar 5, 2024
7852ee9
Rollup merge of #121213 - Takashiidobe:takashi/example-for-rc-into-in…
jhpratt Mar 5, 2024
1dcdfb3
Rollup merge of #121262 - 20jasper:add-vector-time-complexity, r=cuviper
jhpratt Mar 5, 2024
f5d4a5d
Rollup merge of #121287 - zachs18:rc-into-raw-must-use, r=cuviper
jhpratt Mar 5, 2024
b4245e1
Rollup merge of #121664 - compiler-errors:adjust-error-yield-lowering…
jhpratt Mar 5, 2024
c850191
Rollup merge of #121838 - oli-obk:impl_trait_in_assoc_tys_fix, r=comp…
jhpratt Mar 5, 2024
1938ec0
Rollup merge of #121860 - mu001999:master, r=Nilstrieb
jhpratt Mar 5, 2024
0a6b60b
Rollup merge of #121913 - Zoxc:query-fix, r=compiler-errors
jhpratt Mar 5, 2024
8698b24
Rollup merge of #121959 - sundeep-kokkonda:patch-2, r=davidtwco
jhpratt Mar 5, 2024
d03f11d
Rollup merge of #121975 - davidtwco:issue-121757, r=petrochenkov
jhpratt Mar 5, 2024
a6ef0cc
Rollup merge of #121978 - GuillaumeGomez:dylib-duplicated-path, r=bjorn3
jhpratt Mar 5, 2024
425caf7
Rollup merge of #121987 - Nadrieril:abort-on-arity-mismatch, r=compil…
jhpratt Mar 5, 2024
ac4eb31
Rollup merge of #121993 - Zoxc:query-stack-panic-queries, r=compiler-…
jhpratt Mar 5, 2024
4a65a53
Rollup merge of #121997 - RalfJung:cast-float-ty, r=compiler-errors
jhpratt Mar 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
Some(hir::CoroutineKind::Coroutine(_))
| Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _))
| None => {
return hir::ExprKind::Err(self.dcx().emit_err(AwaitOnlyInAsyncFnAndBlocks {
await_kw_span,
item_span: self.current_item,
}));
// Lower to a block `{ EXPR; <error> }` so that the awaited expr
// is not accidentally orphaned.
let stmt_id = self.next_id();
let expr_err = self.expr(
expr.span,
hir::ExprKind::Err(self.dcx().emit_err(AwaitOnlyInAsyncFnAndBlocks {
await_kw_span,
item_span: self.current_item,
})),
);
return hir::ExprKind::Block(
self.block_all(
expr.span,
arena_vec![self; hir::Stmt {
hir_id: stmt_id,
kind: hir::StmtKind::Semi(expr),
span: expr.span,
}],
Some(self.arena.alloc(expr_err)),
),
None,
);
}
};

Expand Down Expand Up @@ -1496,12 +1514,31 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
let yielded =
opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| self.expr_unit(span));

let is_async_gen = match self.coroutine_kind {
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)) => false,
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => {
return hir::ExprKind::Err(
self.dcx().emit_err(AsyncCoroutinesNotSupported { span }),
// Lower to a block `{ EXPR; <error> }` so that the awaited expr
// is not accidentally orphaned.
let stmt_id = self.next_id();
let expr_err = self.expr(
yielded.span,
hir::ExprKind::Err(self.dcx().emit_err(AsyncCoroutinesNotSupported { span })),
);
return hir::ExprKind::Block(
self.block_all(
yielded.span,
arena_vec![self; hir::Stmt {
hir_id: stmt_id,
kind: hir::StmtKind::Semi(yielded),
span: yielded.span,
}],
Some(self.arena.alloc(expr_err)),
),
None,
);
}
Some(hir::CoroutineKind::Coroutine(_)) => {
Expand Down Expand Up @@ -1531,9 +1568,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
};

let yielded =
opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| self.expr_unit(span));

if is_async_gen {
// `yield $expr` is transformed into `task_context = yield async_gen_ready($expr)`.
// This ensures that we store our resumed `ResumeContext` correctly, and also that
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ const_eval_intern_kind = {$kind ->
*[other] {""}
}

const_eval_invalid_align =
align has to be a power of 2

const_eval_invalid_align_details =
invalid align passed to `{$name}`: {$align} is {$err_kind ->
[not_power_of_two] not a power of 2
Expand Down
58 changes: 35 additions & 23 deletions compiler/rustc_const_eval/src/interpret/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
use rustc_type_ir::TyKind::*;

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

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

Float(FloatTy::F32) if signed => Scalar::from_f32(Single::from_i128(v as i128).value),
Float(FloatTy::F64) if signed => Scalar::from_f64(Double::from_i128(v as i128).value),
Float(FloatTy::F32) => Scalar::from_f32(Single::from_u128(v).value),
Float(FloatTy::F64) => Scalar::from_f64(Double::from_u128(v).value),

Char => {
// `u8` to `char` cast
Scalar::from_u32(u8::try_from(v).unwrap().into())
// signed int -> float
Float(fty) if signed => {
let v = v as i128;
match fty {
FloatTy::F16 => unimplemented!("f16_f128"),
FloatTy::F32 => Scalar::from_f32(Single::from_i128(v).value),
FloatTy::F64 => Scalar::from_f64(Double::from_i128(v).value),
FloatTy::F128 => unimplemented!("f16_f128"),
}
}
// unsigned int -> float
Float(fty) => match fty {
FloatTy::F16 => unimplemented!("f16_f128"),
FloatTy::F32 => Scalar::from_f32(Single::from_u128(v).value),
FloatTy::F64 => Scalar::from_f64(Double::from_u128(v).value),
FloatTy::F128 => unimplemented!("f16_f128"),
},

// u8 -> char
Char => Scalar::from_u32(u8::try_from(v).unwrap().into()),

// Casts to bool are not permitted by rustc, no need to handle them here.
_ => span_bug!(self.cur_span(), "invalid int to {} cast", cast_ty),
Expand Down Expand Up @@ -339,14 +352,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let v = f.to_i128(size.bits_usize()).value;
Scalar::from_int(v, size)
}
// float -> f32
Float(FloatTy::F32) => {
Scalar::from_f32(adjust_nan(self, f, f.convert(&mut false).value))
}
// float -> f64
Float(FloatTy::F64) => {
Scalar::from_f64(adjust_nan(self, f, f.convert(&mut false).value))
}
// float -> float
Float(fty) => match fty {
FloatTy::F16 => unimplemented!("f16_f128"),
FloatTy::F32 => Scalar::from_f32(adjust_nan(self, f, f.convert(&mut false).value)),
FloatTy::F64 => Scalar::from_f64(adjust_nan(self, f, f.convert(&mut false).value)),
FloatTy::F128 => unimplemented!("f16_f128"),
},
// That's it.
_ => span_bug!(self.cur_span(), "invalid float to {} cast", dest_ty),
}
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,12 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
}

fn find_field(tcx: TyCtxt<'_>, (def_id, ident): (DefId, Ident)) -> Option<FieldIdx> {
tcx.adt_def(def_id).non_enum_variant().fields.iter_enumerated().find_map(|(idx, field)| {
let adt = tcx.adt_def(def_id);
if adt.is_enum() {
return None;
}

adt.non_enum_variant().fields.iter_enumerated().find_map(|(idx, field)| {
if field.is_unnamed() {
let field_ty = tcx.type_of(field.did).instantiate_identity();
let adt_def = field_ty.ty_adt_def().expect("expect Adt for unnamed field");
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_infer/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,6 @@ infer_more_targeted = {$has_param_name ->

infer_msl_introduces_static = introduces a `'static` lifetime requirement
infer_msl_unmet_req = because this has an unmet lifetime requirement
infer_need_type_info_in_coroutine =
type inside {$coroutine_kind ->
[async_block] `async` block
[async_closure] `async` closure
[async_fn] `async fn` body
*[coroutine] coroutine
} must be known in this context


infer_nothing = {""}

Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,6 @@ lint_suspicious_double_ref_clone =
lint_suspicious_double_ref_deref =
using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type
lint_trivial_untranslatable_diag = diagnostic with static strings only
lint_ty_qualified = usage of qualified `ty::{$ty}`
.suggestion = try importing it and using it unqualified
Expand Down
71 changes: 51 additions & 20 deletions compiler/rustc_lint/src/context/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,43 @@ use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::BytePos;

const MAX_CHECK_CFG_NAMES_OR_VALUES: usize = 35;

fn check_cfg_expected_note(
sess: &Session,
possibilities: &[Symbol],
type_: &str,
name: Option<Symbol>,
suffix: &str,
) -> String {
use std::fmt::Write;

let n_possibilities = if sess.opts.unstable_opts.check_cfg_all_expected {
possibilities.len()
} else {
std::cmp::min(possibilities.len(), MAX_CHECK_CFG_NAMES_OR_VALUES)
};

let mut possibilities = possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>();
possibilities.sort();

let and_more = possibilities.len().saturating_sub(n_possibilities);
let possibilities = possibilities[..n_possibilities].join("`, `");

let mut note = String::with_capacity(50 + possibilities.len());

write!(&mut note, "expected {type_}").unwrap();
if let Some(name) = name {
write!(&mut note, " for `{name}`").unwrap();
}
write!(&mut note, " are: {suffix}`{possibilities}`").unwrap();
if and_more > 0 {
write!(&mut note, " and {and_more} more").unwrap();
}

note
}

pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: &mut Diag<'_, ()>) {
match diagnostic {
BuiltinLintDiagnostics::UnicodeTextFlow(span, content) => {
Expand Down Expand Up @@ -291,16 +328,13 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag:
}
}
if !possibilities.is_empty() {
let mut possibilities =
possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>();
possibilities.sort();
let possibilities = possibilities.join("`, `");

// The list of expected names can be long (even by default) and
// so the diagnostic produced can take a lot of space. To avoid
// cloging the user output we only want to print that diagnostic
// once.
diag.help_once(format!("expected names are: `{possibilities}`"));
diag.help_once(check_cfg_expected_note(
sess,
&possibilities,
"names",
None,
"",
));
}
}

Expand Down Expand Up @@ -343,16 +377,13 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag:
// Show the full list if all possible values for a given name, but don't do it
// for names as the possibilities could be very long
if !possibilities.is_empty() {
{
let mut possibilities =
possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>();
possibilities.sort();

let possibilities = possibilities.join("`, `");
let none = if have_none_possibility { "(none), " } else { "" };

diag.note(format!("expected values for `{name}` are: {none}`{possibilities}`"));
}
diag.note(check_cfg_expected_note(
sess,
&possibilities,
"values",
Some(name),
if have_none_possibility { "(none), " } else { "" },
));

if let Some((value, value_span)) = value {
// Suggest the most probable if we found one
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,13 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, S
Err(err) => {
// Only try to recover from this specific error.
if !matches!(err, libloading::Error::LoadLibraryExW { .. }) {
return Err(err.to_string());
let err = format_dlopen_err(&err);
// We include the path of the dylib in the error ourselves, so
// if it's in the error, we strip it.
if let Some(err) = err.strip_prefix(&format!(": {}", path.display())) {
return Err(err.to_string());
}
return Err(err);
}

last_error = Some(err);
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,6 @@ parse_invalid_identifier_with_leading_number = identifiers cannot start with a n

parse_invalid_interpolated_expression = invalid interpolated expression

parse_invalid_literal_suffix = suffixes on {$kind} literals are invalid
.label = invalid suffix `{$suffix}`

parse_invalid_literal_suffix_on_tuple_index = suffixes on a tuple index are invalid
.label = invalid suffix `{$suffix}`
.tuple_exception_line_1 = `{$suffix}` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
Expand Down Expand Up @@ -609,7 +606,6 @@ parse_nonterminal_expected_item_keyword = expected an item keyword
parse_nonterminal_expected_lifetime = expected a lifetime, found `{$token}`

parse_nonterminal_expected_statement = expected a statement
parse_not_supported = not supported

parse_note_edition_guide = for more on editions, read https://doc.rust-lang.org/edition-guide

Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,6 @@ passes_export_name =
attribute should be applied to a free function, impl method or static
.label = not a free function, impl method or static

passes_expr_not_allowed_in_context =
{$expr} is not allowed in a `{$context}`

passes_extern_main =
the `main` function cannot be declared in an `extern` block

Expand Down Expand Up @@ -405,8 +402,6 @@ passes_lang_item_on_incorrect_target =
`{$name}` language item must be applied to a {$expected_target}
.label = attribute should be applied to a {$expected_target}, not a {$actual_target}

passes_layout =
layout error: {$layout_error}
passes_layout_abi =
abi: {$abi}
passes_layout_align =
Expand Down
Loading
Loading