Skip to content

Commit 05f5a58

Browse files
committed
Auto merge of #145600 - jieyouxu:rollup-jw0bpnt, r=jieyouxu
Rollup of 15 pull requests Successful merges: - #145338 (actually provide the correct args to coroutine witnesses) - #145429 (Couple of codegen_fn_attrs improvements) - #145452 (Do not strip binaries in bootstrap everytime if they are unchanged) - #145464 (Stabilize `const_pathbuf_osstring_new` feature) - #145474 (Properly recover from parenthesized use-bounds (precise capturing lists) plus small cleanups) - #145486 (Fix `unicode_data.rs` mention message) - #145490 (Trace some basic I/O operations in bootstrap) - #145493 (remove `should_render` in `PrintAttribute` derive) - #145500 (Port must_use to the new target checking) - #145505 (Simplify span caches) - #145510 (Visit and print async_fut local for async drop.) - #145511 (Rust build fails on OpenBSD after using file_lock feature) - #145532 (resolve: debug for block module) - #145533 (Reorder `lto` options from most to least optimizing) - #145537 (Do not consider a `T: !Sized` candidate to satisfy a `T: !MetaSized` obligation.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 16ad385 + 4090d98 commit 05f5a58

File tree

59 files changed

+1092
-727
lines changed

Some content is hidden

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

59 files changed

+1092
-727
lines changed

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ attr_parsing_empty_attribute =
1212
1313
attr_parsing_invalid_target = `#[{$name}]` attribute cannot be used on {$target}
1414
.help = `#[{$name}]` can {$only}be applied to {$applied}
15+
.suggestion = remove the attribute
1516
attr_parsing_invalid_target_lint = `#[{$name}]` attribute cannot be used on {$target}
1617
.warn = {-attr_parsing_previously_accepted}
1718
.help = `#[{$name}]` can {$only}be applied to {$applied}
19+
.suggestion = remove the attribute
1820
1921
attr_parsing_empty_confusables =
2022
expected at least one confusable name

compiler/rustc_attr_parsing/src/attributes/must_use.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use rustc_errors::DiagArgValue;
22
use rustc_feature::{AttributeTemplate, template};
33
use rustc_hir::attrs::AttributeKind;
4+
use rustc_hir::{MethodKind, Target};
45
use rustc_span::{Symbol, sym};
56

67
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
7-
use crate::context::{ALL_TARGETS, AcceptContext, AllowedTargets, Stage};
8+
use crate::context::MaybeWarn::{Allow, Error};
9+
use crate::context::{AcceptContext, AllowedTargets, Stage};
810
use crate::parser::ArgParser;
911
use crate::session_diagnostics;
1012
pub(crate) struct MustUseParser;
@@ -13,7 +15,21 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
1315
const PATH: &[Symbol] = &[sym::must_use];
1416
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1517
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
16-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); //FIXME Still checked fully in `check_attr.rs`
18+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
19+
Allow(Target::Fn),
20+
Allow(Target::Enum),
21+
Allow(Target::Struct),
22+
Allow(Target::Union),
23+
Allow(Target::Method(MethodKind::Trait { body: false })),
24+
Allow(Target::Method(MethodKind::Trait { body: true })),
25+
Allow(Target::Method(MethodKind::Inherent)),
26+
Allow(Target::ForeignFn),
27+
// `impl Trait` in return position can trip
28+
// `unused_must_use` if `Trait` is marked as
29+
// `#[must_use]`
30+
Allow(Target::Trait),
31+
Error(Target::WherePredicate),
32+
]);
1733
const TEMPLATE: AttributeTemplate = template!(
1834
Word, NameValueStr: "reason",
1935
"https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"

compiler/rustc_attr_parsing/src/lints.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub fn emit_attribute_lint<L: LintEmitter>(lint: &AttributeLint<HirId>, lint_emi
5353
target: target.plural_name(),
5454
applied: applied.clone(),
5555
only,
56+
attr_span: *span,
5657
},
5758
),
5859
}

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,16 @@ pub(crate) struct InvalidTargetLint {
489489
pub target: &'static str,
490490
pub applied: String,
491491
pub only: &'static str,
492+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
493+
pub attr_span: Span,
492494
}
493495

494496
#[derive(Diagnostic)]
495497
#[help]
496498
#[diag(attr_parsing_invalid_target)]
497499
pub(crate) struct InvalidTarget {
498500
#[primary_span]
501+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
499502
pub span: Span,
500503
pub name: Symbol,
501504
pub target: &'static str,

compiler/rustc_builtin_macros/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
99
#![doc(rust_logo)]
1010
#![feature(assert_matches)]
11-
#![feature(autodiff)]
1211
#![feature(box_patterns)]
1312
#![feature(decl_macro)]
1413
#![feature(if_let_guard)]

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
497497
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "wasm-import-module", module));
498498

499499
let name =
500-
codegen_fn_attrs.link_name.unwrap_or_else(|| cx.tcx.item_name(instance.def_id()));
500+
codegen_fn_attrs.symbol_name.unwrap_or_else(|| cx.tcx.item_name(instance.def_id()));
501501
let name = name.as_str();
502502
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "wasm-import-name", name));
503503
}

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
858858
instance: Instance<'tcx>,
859859
) -> bool {
860860
fn is_llvm_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
861-
if let Some(name) = tcx.codegen_fn_attrs(def_id).link_name {
861+
if let Some(name) = tcx.codegen_fn_attrs(def_id).symbol_name {
862862
name.as_str().starts_with("llvm.")
863863
} else {
864864
false

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
66
use rustc_hir::attrs::{AttributeKind, InlineAttr, InstructionSetAttr, UsedBy};
77
use rustc_hir::def::DefKind;
88
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
9-
use rustc_hir::weak_lang_items::WEAK_LANG_ITEMS;
109
use rustc_hir::{self as hir, Attribute, LangItem, find_attr, lang_items};
1110
use rustc_middle::middle::codegen_fn_attrs::{
1211
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry,
@@ -156,15 +155,21 @@ fn process_builtin_attrs(
156155
match p {
157156
AttributeKind::Cold(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD,
158157
AttributeKind::ExportName { name, .. } => {
159-
codegen_fn_attrs.export_name = Some(*name)
158+
codegen_fn_attrs.symbol_name = Some(*name)
160159
}
161160
AttributeKind::Inline(inline, span) => {
162161
codegen_fn_attrs.inline = *inline;
163162
interesting_spans.inline = Some(*span);
164163
}
165164
AttributeKind::Naked(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED,
166165
AttributeKind::Align { align, .. } => codegen_fn_attrs.alignment = Some(*align),
167-
AttributeKind::LinkName { name, .. } => codegen_fn_attrs.link_name = Some(*name),
166+
AttributeKind::LinkName { name, .. } => {
167+
// FIXME Remove check for foreign functions once #[link_name] on non-foreign
168+
// functions is a hard error
169+
if tcx.is_foreign_item(did) {
170+
codegen_fn_attrs.symbol_name = Some(*name);
171+
}
172+
}
168173
AttributeKind::LinkOrdinal { ordinal, span } => {
169174
codegen_fn_attrs.link_ordinal = Some(*ordinal);
170175
interesting_spans.link_ordinal = Some(*span);
@@ -382,7 +387,7 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
382387
// * `#[rustc_std_internal_symbol]` mangles the symbol name in a special way
383388
// both for exports and imports through foreign items. This is handled further,
384389
// during symbol mangling logic.
385-
} else if codegen_fn_attrs.link_name.is_some() {
390+
} else if codegen_fn_attrs.symbol_name.is_some() {
386391
// * This can be overridden with the `#[link_name]` attribute
387392
} else {
388393
// NOTE: there's one more exception that we cannot apply here. On wasm,
@@ -437,7 +442,7 @@ fn check_result(
437442
}
438443

439444
// error when specifying link_name together with link_ordinal
440-
if let Some(_) = codegen_fn_attrs.link_name
445+
if let Some(_) = codegen_fn_attrs.symbol_name
441446
&& let Some(_) = codegen_fn_attrs.link_ordinal
442447
{
443448
let msg = "cannot use `#[link_name]` with `#[link_ordinal]`";
@@ -484,14 +489,11 @@ fn handle_lang_items(
484489
// strippable by the linker.
485490
//
486491
// Additionally weak lang items have predetermined symbol names.
487-
if let Some(lang_item) = lang_item {
488-
if WEAK_LANG_ITEMS.contains(&lang_item) {
489-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
490-
}
491-
if let Some(link_name) = lang_item.link_name() {
492-
codegen_fn_attrs.export_name = Some(link_name);
493-
codegen_fn_attrs.link_name = Some(link_name);
494-
}
492+
if let Some(lang_item) = lang_item
493+
&& let Some(link_name) = lang_item.link_name()
494+
{
495+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
496+
codegen_fn_attrs.symbol_name = Some(link_name);
495497
}
496498

497499
// error when using no_mangle on a lang item item

compiler/rustc_lint/src/foreign_modules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl ClashingExternDeclarations {
179179
/// symbol's name.
180180
fn name_of_extern_decl(tcx: TyCtxt<'_>, fi: hir::OwnerId) -> SymbolName {
181181
if let Some((overridden_link_name, overridden_link_name_span)) =
182-
tcx.codegen_fn_attrs(fi).link_name.map(|overridden_link_name| {
182+
tcx.codegen_fn_attrs(fi).symbol_name.map(|overridden_link_name| {
183183
// FIXME: Instead of searching through the attributes again to get span
184184
// information, we could have codegen_fn_attrs also give span information back for
185185
// where the attribute was defined. However, until this is found to be a

compiler/rustc_macros/src/print_attribute.rs

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use syn::spanned::Spanned;
44
use syn::{Data, Fields, Ident};
55
use synstructure::Structure;
66

7-
fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, TokenStream) {
7+
fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream) {
88
let string_name = name.to_string();
99
let mut disps = vec![quote! {let mut __printed_anything = false;}];
1010

@@ -43,7 +43,6 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
4343
#(#disps)*
4444
__p.word("}");
4545
},
46-
quote! { true },
4746
)
4847
}
4948
Fields::Unnamed(fields_unnamed) => {
@@ -76,10 +75,9 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
7675
#(#disps)*
7776
__p.pclose();
7877
},
79-
quote! { true },
8078
)
8179
}
82-
Fields::Unit => (quote! {}, quote! { __p.word(#string_name) }, quote! { true }),
80+
Fields::Unit => (quote! {}, quote! { __p.word(#string_name) }),
8381
}
8482
}
8583

@@ -89,51 +87,33 @@ pub(crate) fn print_attribute(input: Structure<'_>) -> TokenStream {
8987
};
9088

9189
// Must be applied to an enum type.
92-
let (code, printed) = match &input.ast().data {
90+
let code = match &input.ast().data {
9391
Data::Enum(e) => {
94-
let (arms, printed) = e
92+
let arms = e
9593
.variants
9694
.iter()
9795
.map(|x| {
9896
let ident = &x.ident;
99-
let (pat, code, printed) = print_fields(ident, &x.fields);
97+
let (pat, code) = print_fields(ident, &x.fields);
10098

101-
(
102-
quote! {
103-
Self::#ident #pat => {#code}
104-
},
105-
quote! {
106-
Self::#ident #pat => {#printed}
107-
},
108-
)
99+
quote! {
100+
Self::#ident #pat => {#code}
101+
}
109102
})
110-
.unzip::<_, _, Vec<_>, Vec<_>>();
103+
.collect::<Vec<_>>();
111104

112-
(
113-
quote! {
114-
match self {
115-
#(#arms)*
116-
}
117-
},
118-
quote! {
119-
match self {
120-
#(#printed)*
121-
}
122-
},
123-
)
105+
quote! {
106+
match self {
107+
#(#arms)*
108+
}
109+
}
124110
}
125111
Data::Struct(s) => {
126-
let (pat, code, printed) = print_fields(&input.ast().ident, &s.fields);
127-
(
128-
quote! {
129-
let Self #pat = self;
130-
#code
131-
},
132-
quote! {
133-
let Self #pat = self;
134-
#printed
135-
},
136-
)
112+
let (pat, code) = print_fields(&input.ast().ident, &s.fields);
113+
quote! {
114+
let Self #pat = self;
115+
#code
116+
}
137117
}
138118
Data::Union(u) => {
139119
return span_error(u.union_token.span(), "can't derive PrintAttribute on unions");
@@ -144,7 +124,7 @@ pub(crate) fn print_attribute(input: Structure<'_>) -> TokenStream {
144124
input.gen_impl(quote! {
145125
#[allow(unused)]
146126
gen impl PrintAttribute for @Self {
147-
fn should_render(&self) -> bool { #printed }
127+
fn should_render(&self) -> bool { true }
148128
fn print_attribute(&self, __p: &mut rustc_ast_pretty::pp::Printer) { #code }
149129
}
150130
})

0 commit comments

Comments
 (0)