Skip to content

Commit 111e9bc

Browse files
committed
Auto merge of rust-lang#142878 - GuillaumeGomez:rollup-53dohob, r=GuillaumeGomez
Rollup of 10 pull requests Successful merges: - rust-lang#142458 (Merge unboxed trait object error suggestion into regular dyn incompat error) - rust-lang#142593 (Add a warning to LateContext::get_def_path) - rust-lang#142594 (Add DesugaringKind::FormatLiteral) - rust-lang#142740 (Clean-up `FnCtxt::is_destruct_assignment_desugaring`) - rust-lang#142780 (Port `#[must_use]` to new attribute parsing infrastructure) - rust-lang#142798 (Don't fail to parse a struct if a semicolon is used to separate fields) - rust-lang#142856 (Add a few inline directives in rustc_serialize.) - rust-lang#142868 (remove few allow(dead_code)) - rust-lang#142874 (cranelift: fix target feature name typo: "fxsr") - rust-lang#142877 (Document why tidy checks if `eslint` is installed via `npm`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c2ec753 + 8da1a62 commit 111e9bc

File tree

114 files changed

+594
-515
lines changed

Some content is hidden

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

114 files changed

+594
-515
lines changed

compiler/rustc_ast/src/format.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ pub struct FormatArgs {
5050
///
5151
/// Generally only useful for lints that care about the raw bytes the user wrote.
5252
pub uncooked_fmt_str: (LitKind, Symbol),
53+
/// Was the format literal written in the source?
54+
/// - `format!("boo")` => true,
55+
/// - `format!(concat!("b", "o", "o"))` => false,
56+
/// - `format!(include_str!("boo.txt"))` => false,
57+
///
58+
/// If it wasn't written in the source then we have to be careful with spans pointing into it
59+
/// and suggestions about rewriting it.
60+
pub is_source_literal: bool,
5361
}
5462

5563
/// A piece of a format template string.

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ macro_rules! common_visitor_and_walkers {
15661566

15671567
// FIXME: visit the template exhaustively.
15681568
pub fn walk_format_args<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, fmt: &$($lt)? $($mut)? FormatArgs) -> V::Result {
1569-
let FormatArgs { span, template: _, arguments, uncooked_fmt_str: _ } = fmt;
1569+
let FormatArgs { span, template: _, arguments, uncooked_fmt_str: _, is_source_literal: _ } = fmt;
15701570
let args = $(${ignore($mut)} arguments.all_args_mut())? $(${ignore($lt)} arguments.all_args())? ;
15711571
for FormatArgument { kind, expr } in args {
15721572
match kind {

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_ast::*;
44
use rustc_data_structures::fx::FxIndexMap;
55
use rustc_hir as hir;
66
use rustc_session::config::FmtDebug;
7-
use rustc_span::{Ident, Span, Symbol, sym};
7+
use rustc_span::{DesugaringKind, Ident, Span, Symbol, sym};
88

99
use super::LoweringContext;
1010

@@ -14,6 +14,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
1414
// format_args!() had any arguments _before_ flattening/inlining.
1515
let allow_const = fmt.arguments.all_args().is_empty();
1616
let mut fmt = Cow::Borrowed(fmt);
17+
18+
let sp = self.mark_span_with_reason(
19+
DesugaringKind::FormatLiteral { source: fmt.is_source_literal },
20+
sp,
21+
sp.ctxt().outer_expn_data().allow_internal_unstable,
22+
);
23+
1724
if self.tcx.sess.opts.unstable_opts.flatten_format_args {
1825
fmt = flatten_format_args(fmt);
1926
fmt = self.inline_literals(fmt);

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ pub enum AttributeKind {
237237
/// Represents [`#[may_dangle]`](https://std-dev-guide.rust-lang.org/tricky/may-dangle.html).
238238
MayDangle(Span),
239239

240+
/// Represents `#[must_use]`.
241+
MustUse {
242+
span: Span,
243+
/// must_use can optionally have a reason: `#[must_use = "reason this must be used"]`
244+
reason: Option<Symbol>,
245+
},
246+
240247
/// Represents `#[optimize(size|speed)]`
241248
Optimize(OptimizeAttr, Span),
242249

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub(crate) mod confusables;
3333
pub(crate) mod deprecation;
3434
pub(crate) mod inline;
3535
pub(crate) mod lint_helpers;
36+
pub(crate) mod must_use;
3637
pub(crate) mod repr;
3738
pub(crate) mod semantics;
3839
pub(crate) mod stability;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use rustc_attr_data_structures::AttributeKind;
2+
use rustc_errors::DiagArgValue;
3+
use rustc_feature::{AttributeTemplate, template};
4+
use rustc_span::{Symbol, sym};
5+
6+
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
7+
use crate::context::{AcceptContext, Stage};
8+
use crate::parser::ArgParser;
9+
use crate::session_diagnostics;
10+
11+
pub(crate) struct MustUseParser;
12+
13+
impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
14+
const PATH: &[Symbol] = &[sym::must_use];
15+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
16+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
17+
const TEMPLATE: AttributeTemplate = template!(Word, NameValueStr: "reason");
18+
19+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
20+
Some(AttributeKind::MustUse {
21+
span: cx.attr_span,
22+
reason: match args {
23+
ArgParser::NoArgs => None,
24+
ArgParser::NameValue(name_value) => name_value.value_as_str(),
25+
ArgParser::List(_) => {
26+
let suggestions =
27+
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "must_use");
28+
cx.emit_err(session_diagnostics::MustUseIllFormedAttributeInput {
29+
num_suggestions: suggestions.len(),
30+
suggestions: DiagArgValue::StrListSepByAnd(
31+
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
32+
),
33+
span: cx.attr_span,
34+
});
35+
return None;
36+
}
37+
},
38+
})
39+
}
40+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::attributes::confusables::ConfusablesParser;
2020
use crate::attributes::deprecation::DeprecationParser;
2121
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
2222
use crate::attributes::lint_helpers::{AsPtrParser, PubTransparentParser};
23+
use crate::attributes::must_use::MustUseParser;
2324
use crate::attributes::repr::{AlignParser, ReprParser};
2425
use crate::attributes::semantics::MayDangleParser;
2526
use crate::attributes::stability::{
@@ -112,6 +113,7 @@ attribute_parsers!(
112113
Single<DeprecationParser>,
113114
Single<InlineParser>,
114115
Single<MayDangleParser>,
116+
Single<MustUseParser>,
115117
Single<OptimizeParser>,
116118
Single<PubTransparentParser>,
117119
Single<RustcForceInlineParser>,

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,15 @@ pub(crate) struct IllFormedAttributeInput {
436436
pub suggestions: DiagArgValue,
437437
}
438438

439+
#[derive(Diagnostic)]
440+
#[diag(attr_parsing_ill_formed_attribute_input)]
441+
pub(crate) struct MustUseIllFormedAttributeInput {
442+
#[primary_span]
443+
pub span: Span,
444+
pub num_suggestions: usize,
445+
pub suggestions: DiagArgValue,
446+
}
447+
439448
#[derive(Diagnostic)]
440449
#[diag(attr_parsing_stability_outside_std, code = E0734)]
441450
pub(crate) struct StabilityOutsideStd {

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ fn make_format_args(
606606
template,
607607
arguments: args,
608608
uncooked_fmt_str,
609+
is_source_literal,
609610
}))
610611
}
611612

compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
184184
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
185185
let target_features = if sess.target.arch == "x86_64" && sess.target.os != "none" {
186186
// x86_64 mandates SSE2 support and rustc requires the x87 feature to be enabled
187-
vec![sym::fsxr, sym::sse, sym::sse2, Symbol::intern("x87")]
187+
vec![sym::fxsr, sym::sse, sym::sse2, Symbol::intern("x87")]
188188
} else if sess.target.arch == "aarch64" {
189189
match &*sess.target.os {
190190
"none" => vec![],

0 commit comments

Comments
 (0)