Skip to content

Commit 41cbe3e

Browse files
committed
Auto merge of #133770 - GuillaumeGomez:rollup-l62iyyx, r=GuillaumeGomez
Rollup of 10 pull requests Successful merges: - #131713 (Stabilize `const_maybe_uninit_write`) - #133535 (show forbidden_lint_groups in future-compat reports) - #133610 (Move `Const::{from_anon_const,try_from_lit}` to hir_ty_lowering) - #133701 (Use c"lit" for CStrings without unwrap) - #133704 (fix ICE when promoted has layout size overflow) - #133705 (add "profiler" and "optimized-compiler-builtins" option coverage for ci-rustc) - #133710 (Reducing `target_feature` check-cfg merge conflicts) - #133732 (Fix `-Zdump-mir-dataflow`) - #133746 (Change `AttrArgs::Eq` to a struct variant) - #133763 (Fix `f16::midpoint` const feature gate) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 42b4b9c + 73f225a commit 41cbe3e

File tree

90 files changed

+1863
-418
lines changed

Some content is hidden

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

90 files changed

+1863
-418
lines changed

Diff for: compiler/rustc_ast/src/ast.rs

+36-15
Original file line numberDiff line numberDiff line change
@@ -1731,12 +1731,12 @@ pub enum AttrArgs {
17311731
/// Delimited arguments: `#[attr()/[]/{}]`.
17321732
Delimited(DelimArgs),
17331733
/// Arguments of a key-value attribute: `#[attr = "value"]`.
1734-
Eq(
1734+
Eq {
17351735
/// Span of the `=` token.
1736-
Span,
1737-
/// The "value".
1738-
AttrArgsEq,
1739-
),
1736+
eq_span: Span,
1737+
1738+
value: AttrArgsEq,
1739+
},
17401740
}
17411741

17421742
// The RHS of an `AttrArgs::Eq` starts out as an expression. Once macro
@@ -1748,15 +1748,39 @@ pub enum AttrArgsEq {
17481748
Hir(MetaItemLit),
17491749
}
17501750

1751+
impl AttrArgsEq {
1752+
pub fn span(&self) -> Span {
1753+
match self {
1754+
AttrArgsEq::Ast(p) => p.span,
1755+
AttrArgsEq::Hir(lit) => lit.span,
1756+
}
1757+
}
1758+
1759+
pub fn unwrap_ast(&self) -> &Expr {
1760+
match self {
1761+
AttrArgsEq::Ast(p) => p,
1762+
AttrArgsEq::Hir(lit) => {
1763+
unreachable!("in literal form when getting inner tokens: {lit:?}")
1764+
}
1765+
}
1766+
}
1767+
1768+
pub fn unwrap_ast_mut(&mut self) -> &mut P<Expr> {
1769+
match self {
1770+
AttrArgsEq::Ast(p) => p,
1771+
AttrArgsEq::Hir(lit) => {
1772+
unreachable!("in literal form when getting inner tokens: {lit:?}")
1773+
}
1774+
}
1775+
}
1776+
}
1777+
17511778
impl AttrArgs {
17521779
pub fn span(&self) -> Option<Span> {
17531780
match self {
17541781
AttrArgs::Empty => None,
17551782
AttrArgs::Delimited(args) => Some(args.dspan.entire()),
1756-
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => Some(eq_span.to(expr.span)),
1757-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
1758-
unreachable!("in literal form when getting span: {:?}", lit);
1759-
}
1783+
AttrArgs::Eq { eq_span, value } => Some(eq_span.to(value.span())),
17601784
}
17611785
}
17621786

@@ -1766,10 +1790,7 @@ impl AttrArgs {
17661790
match self {
17671791
AttrArgs::Empty => TokenStream::default(),
17681792
AttrArgs::Delimited(args) => args.tokens.clone(),
1769-
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => TokenStream::from_ast(expr),
1770-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
1771-
unreachable!("in literal form when getting inner tokens: {:?}", lit)
1772-
}
1793+
AttrArgs::Eq { value, .. } => TokenStream::from_ast(value.unwrap_ast()),
17731794
}
17741795
}
17751796
}
@@ -1783,10 +1804,10 @@ where
17831804
match self {
17841805
AttrArgs::Empty => {}
17851806
AttrArgs::Delimited(args) => args.hash_stable(ctx, hasher),
1786-
AttrArgs::Eq(_eq_span, AttrArgsEq::Ast(expr)) => {
1807+
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => {
17871808
unreachable!("hash_stable {:?}", expr);
17881809
}
1789-
AttrArgs::Eq(eq_span, AttrArgsEq::Hir(lit)) => {
1810+
AttrArgs::Eq { eq_span, value: AttrArgsEq::Hir(lit) } => {
17901811
eq_span.hash_stable(ctx, hasher);
17911812
lit.hash_stable(ctx, hasher);
17921813
}

Diff for: compiler/rustc_ast/src/attr/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl AttrItem {
250250
AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => {
251251
MetaItemKind::list_from_tokens(args.tokens.clone())
252252
}
253-
AttrArgs::Delimited(_) | AttrArgs::Eq(..) | AttrArgs::Empty => None,
253+
AttrArgs::Delimited(_) | AttrArgs::Eq { .. } | AttrArgs::Empty => None,
254254
}
255255
}
256256

@@ -268,7 +268,7 @@ impl AttrItem {
268268
/// ```
269269
fn value_str(&self) -> Option<Symbol> {
270270
match &self.args {
271-
AttrArgs::Eq(_, args) => args.value_str(),
271+
AttrArgs::Eq { value, .. } => value.value_str(),
272272
AttrArgs::Delimited(_) | AttrArgs::Empty => None,
273273
}
274274
}
@@ -492,7 +492,7 @@ impl MetaItemKind {
492492
MetaItemKind::list_from_tokens(tokens.clone()).map(MetaItemKind::List)
493493
}
494494
AttrArgs::Delimited(..) => None,
495-
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => match expr.kind {
495+
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => match expr.kind {
496496
ExprKind::Lit(token_lit) => {
497497
// Turn failures to `None`, we'll get parse errors elsewhere.
498498
MetaItemLit::from_token_lit(token_lit, expr.span)
@@ -501,7 +501,9 @@ impl MetaItemKind {
501501
}
502502
_ => None,
503503
},
504-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => Some(MetaItemKind::NameValue(lit.clone())),
504+
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
505+
Some(MetaItemKind::NameValue(lit.clone()))
506+
}
505507
}
506508
}
507509
}
@@ -702,7 +704,7 @@ pub fn mk_attr_name_value_str(
702704
tokens: None,
703705
});
704706
let path = Path::from_ident(Ident::new(name, span));
705-
let args = AttrArgs::Eq(span, AttrArgsEq::Ast(expr));
707+
let args = AttrArgs::Eq { eq_span: span, value: AttrArgsEq::Ast(expr) };
706708
mk_attr(g, style, unsafety, path, args, span)
707709
}
708710

Diff for: compiler/rustc_ast/src/mut_visit.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,10 @@ fn visit_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
451451
match args {
452452
AttrArgs::Empty => {}
453453
AttrArgs::Delimited(args) => visit_delim_args(vis, args),
454-
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => {
455-
vis.visit_expr(expr);
454+
AttrArgs::Eq { eq_span, value } => {
455+
vis.visit_expr(value.unwrap_ast_mut());
456456
vis.visit_span(eq_span);
457457
}
458-
AttrArgs::Eq(_eq_span, AttrArgsEq::Hir(lit)) => {
459-
unreachable!("in literal form when visiting mac args eq: {:?}", lit)
460-
}
461458
}
462459
}
463460

Diff for: compiler/rustc_ast/src/visit.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1273,10 +1273,7 @@ pub fn walk_attr_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a AttrArgs) -
12731273
match args {
12741274
AttrArgs::Empty => {}
12751275
AttrArgs::Delimited(_args) => {}
1276-
AttrArgs::Eq(_eq_span, AttrArgsEq::Ast(expr)) => try_visit!(visitor.visit_expr(expr)),
1277-
AttrArgs::Eq(_eq_span, AttrArgsEq::Hir(lit)) => {
1278-
unreachable!("in literal form when walking mac args eq: {:?}", lit)
1279-
}
1276+
AttrArgs::Eq { value, .. } => try_visit!(visitor.visit_expr(value.unwrap_ast())),
12801277
}
12811278
V::Result::output()
12821279
}

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
889889
// This is an inert key-value attribute - it will never be visible to macros
890890
// after it gets lowered to HIR. Therefore, we can extract literals to handle
891891
// nonterminals in `#[doc]` (e.g. `#[doc = $e]`).
892-
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => {
892+
&AttrArgs::Eq { eq_span, ref value } => {
893+
let expr = value.unwrap_ast();
893894
// In valid code the value always ends up as a single literal. Otherwise, a dummy
894895
// literal suffices because the error is handled elsewhere.
895896
let lit = if let ExprKind::Lit(token_lit) = expr.kind
@@ -905,10 +906,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
905906
span: DUMMY_SP,
906907
}
907908
};
908-
AttrArgs::Eq(*eq_span, AttrArgsEq::Hir(lit))
909-
}
910-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
911-
unreachable!("in literal form when lowering mac args eq: {:?}", lit)
909+
AttrArgs::Eq { eq_span, value: AttrArgsEq::Hir(lit) }
912910
}
913911
}
914912
}

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,14 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
648648
AttrArgs::Empty => {
649649
self.print_path(&item.path, false, 0);
650650
}
651-
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => {
651+
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => {
652652
self.print_path(&item.path, false, 0);
653653
self.space();
654654
self.word_space("=");
655655
let token_str = self.expr_to_string(expr);
656656
self.word(token_str);
657657
}
658-
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
658+
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
659659
self.print_path(&item.path, false, 0);
660660
self.space();
661661
self.word_space("=");

Diff for: compiler/rustc_codegen_llvm/src/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn prepare_lto(
148148
// __llvm_profile_counter_bias is pulled in at link time by an undefined reference to
149149
// __llvm_profile_runtime, therefore we won't know until link time if this symbol
150150
// should have default visibility.
151-
symbols_below_threshold.push(CString::new("__llvm_profile_counter_bias").unwrap());
151+
symbols_below_threshold.push(c"__llvm_profile_counter_bias".to_owned());
152152
Ok((symbols_below_threshold, upstream_modules))
153153
}
154154

Diff for: compiler/rustc_codegen_llvm/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ fn get_pgo_sample_use_path(config: &ModuleConfig) -> Option<CString> {
509509
}
510510

511511
fn get_instr_profile_output_path(config: &ModuleConfig) -> Option<CString> {
512-
config.instrument_coverage.then(|| CString::new("default_%m_%p.profraw").unwrap())
512+
config.instrument_coverage.then(|| c"default_%m_%p.profraw".to_owned())
513513
}
514514

515515
pub(crate) unsafe fn llvm_optimize(

Diff for: compiler/rustc_const_eval/src/const_eval/error.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -139,29 +139,36 @@ where
139139
match error {
140140
// Don't emit a new diagnostic for these errors, they are already reported elsewhere or
141141
// should remain silent.
142+
err_inval!(AlreadyReported(info)) => ErrorHandled::Reported(info, span),
142143
err_inval!(Layout(LayoutError::Unknown(_))) | err_inval!(TooGeneric) => {
143144
ErrorHandled::TooGeneric(span)
144145
}
145-
err_inval!(AlreadyReported(guar)) => ErrorHandled::Reported(guar, span),
146146
err_inval!(Layout(LayoutError::ReferencesError(guar))) => {
147-
ErrorHandled::Reported(ReportedErrorInfo::tainted_by_errors(guar), span)
147+
// This can occur in infallible promoteds e.g. when a non-existent type or field is
148+
// encountered.
149+
ErrorHandled::Reported(ReportedErrorInfo::allowed_in_infallible(guar), span)
148150
}
149151
// Report remaining errors.
150152
_ => {
151153
let (our_span, frames) = get_span_and_frames();
152154
let span = span.substitute_dummy(our_span);
153155
let err = mk(span, frames);
154156
let mut err = tcx.dcx().create_err(err);
155-
let can_be_spurious = matches!(error, InterpErrorKind::ResourceExhaustion(_));
157+
// We allow invalid programs in infallible promoteds since invalid layouts can occur
158+
// anyway (e.g. due to size overflow). And we allow OOM as that can happen any time.
159+
let allowed_in_infallible = matches!(
160+
error,
161+
InterpErrorKind::ResourceExhaustion(_) | InterpErrorKind::InvalidProgram(_)
162+
);
156163

157164
let msg = error.diagnostic_message();
158165
error.add_args(&mut err);
159166

160167
// Use *our* span to label the interp error
161168
err.span_label(our_span, msg);
162169
let g = err.emit();
163-
let reported = if can_be_spurious {
164-
ReportedErrorInfo::spurious(g)
170+
let reported = if allowed_in_infallible {
171+
ReportedErrorInfo::allowed_in_infallible(g)
165172
} else {
166173
ReportedErrorInfo::from(g)
167174
};

Diff for: compiler/rustc_const_eval/src/interpret/eval_context.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
268268
};
269269
// do not continue if typeck errors occurred (can only occur in local crate)
270270
if let Some(err) = body.tainted_by_errors {
271-
throw_inval!(AlreadyReported(ReportedErrorInfo::tainted_by_errors(err)));
271+
throw_inval!(AlreadyReported(ReportedErrorInfo::from(err)));
272272
}
273273
interp_ok(body)
274274
}
@@ -585,13 +585,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
585585
match err {
586586
ErrorHandled::TooGeneric(..) => {},
587587
ErrorHandled::Reported(reported, span) => {
588-
if reported.is_tainted_by_errors() {
589-
// const-eval will return "tainted" errors if e.g. the layout cannot
590-
// be computed as the type references non-existing names.
591-
// See <https://github.com/rust-lang/rust/issues/124348>.
592-
} else if reported.can_be_spurious() {
588+
if reported.is_allowed_in_infallible() {
593589
// These errors can just sometimes happen, even when the expression
594-
// is nominally "infallible", e.g. when running out of memory.
590+
// is nominally "infallible", e.g. when running out of memory
591+
// or when some layout could not be computed.
595592
} else {
596593
// Looks like the const is not captured by `required_consts`, that's bad.
597594
span_bug!(span, "interpret const eval failure of {val:?} which is not in required_consts");

Diff for: compiler/rustc_error_codes/src/error_codes/E0060.md

+4-9
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,19 @@ unsafe { printf(); } // error!
1515
Using this declaration, it must be called with at least one argument, so
1616
simply calling `printf()` is invalid. But the following uses are allowed:
1717

18-
```
18+
```rust,edition2021
1919
# use std::os::raw::{c_char, c_int};
2020
# #[cfg_attr(all(windows, target_env = "msvc"),
2121
# link(name = "legacy_stdio_definitions",
2222
# kind = "static", modifiers = "-bundle"))]
2323
# extern "C" { fn printf(_: *const c_char, ...) -> c_int; }
2424
# fn main() {
2525
unsafe {
26-
use std::ffi::CString;
27-
28-
let fmt = CString::new("test\n").unwrap();
29-
printf(fmt.as_ptr());
26+
printf(c"test\n".as_ptr());
3027
31-
let fmt = CString::new("number = %d\n").unwrap();
32-
printf(fmt.as_ptr(), 3);
28+
printf(c"number = %d\n".as_ptr(), 3);
3329
34-
let fmt = CString::new("%d, %d\n").unwrap();
35-
printf(fmt.as_ptr(), 10, 5);
30+
printf(c"%d, %d\n".as_ptr(), 10, 5);
3631
}
3732
# }
3833
```

Diff for: compiler/rustc_expand/src/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
732732
_ => item.to_tokens(),
733733
};
734734
let attr_item = attr.unwrap_normal_item();
735-
if let AttrArgs::Eq(..) = attr_item.args {
735+
if let AttrArgs::Eq { .. } = attr_item.args {
736736
self.cx.dcx().emit_err(UnsupportedKeyValue { span });
737737
}
738738
let inner_tokens = attr_item.args.inner_tokens();

Diff for: compiler/rustc_hir_analysis/src/check/wfcheck.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_hir::lang_items::LangItem;
1313
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
1414
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
1515
use rustc_macros::LintDiagnostic;
16+
use rustc_middle::mir::interpret::ErrorHandled;
1617
use rustc_middle::query::Providers;
1718
use rustc_middle::ty::print::with_no_trimmed_paths;
1819
use rustc_middle::ty::trait_def::TraitSpecializationKind;
@@ -1170,19 +1171,13 @@ fn check_type_defn<'tcx>(
11701171

11711172
// Explicit `enum` discriminant values must const-evaluate successfully.
11721173
if let ty::VariantDiscr::Explicit(discr_def_id) = variant.discr {
1173-
let cause = traits::ObligationCause::new(
1174-
tcx.def_span(discr_def_id),
1175-
wfcx.body_def_id,
1176-
ObligationCauseCode::Misc,
1177-
);
1178-
wfcx.register_obligation(Obligation::new(
1179-
tcx,
1180-
cause,
1181-
wfcx.param_env,
1182-
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(
1183-
ty::Const::from_anon_const(tcx, discr_def_id.expect_local()),
1184-
))),
1185-
));
1174+
match tcx.const_eval_poly(discr_def_id) {
1175+
Ok(_) => {}
1176+
Err(ErrorHandled::Reported(..)) => {}
1177+
Err(ErrorHandled::TooGeneric(sp)) => {
1178+
span_bug!(sp, "enum variant discr was too generic to eval")
1179+
}
1180+
}
11861181
}
11871182
}
11881183

0 commit comments

Comments
 (0)