Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4e0f8c3

Browse files
Auto merge of #144952 - samueltardieu:rollup-74t6irz, r=<try>
Rollup of 11 pull requests try-job: test-various
2 parents 213d946 + 44030ec commit 4e0f8c3

File tree

56 files changed

+508
-314
lines changed

Some content is hidden

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

56 files changed

+508
-314
lines changed

‎compiler/rustc_attr_parsing/messages.ftl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ attr_parsing_ill_formed_attribute_input = {$num_suggestions ->
3232
*[other] valid forms for the attribute are {$suggestions}
3333
}
3434
35+
attr_parsing_invalid_macro_export_arguments = {$num_suggestions ->
36+
[1] attribute must be of the form {$suggestions}
37+
*[other] valid forms for the attribute are {$suggestions}
38+
}
39+
3540
attr_parsing_incorrect_repr_format_align_one_arg =
3641
incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
3742

‎compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
use rustc_errors::DiagArgValue;
22
use rustc_feature::{AttributeTemplate, template};
33
use rustc_hir::attrs::{AttributeKind, MacroUseArgs};
4+
use rustc_hir::lints::AttributeLintKind;
45
use rustc_span::{Span, Symbol, sym};
56
use thin_vec::ThinVec;
67

7-
use crate::attributes::{AcceptMapping, AttributeParser, NoArgsAttributeParser, OnDuplicate};
8+
use crate::attributes::{
9+
AcceptMapping, AttributeOrder, AttributeParser, NoArgsAttributeParser, OnDuplicate,
10+
SingleAttributeParser,
11+
};
812
use crate::context::{AcceptContext, FinalizeContext, Stage};
913
use crate::parser::ArgParser;
1014
use crate::session_diagnostics;
@@ -113,3 +117,58 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
113117
Some(AttributeKind::MacroUse { span: self.first_span?, arguments: self.state })
114118
}
115119
}
120+
121+
pub(crate) struct MacroExportParser;
122+
123+
impl<S: Stage> SingleAttributeParser<S> for crate::attributes::macro_attrs::MacroExportParser {
124+
const PATH: &[Symbol] = &[sym::macro_export];
125+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
126+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
127+
const TEMPLATE: AttributeTemplate = template!(Word, List: "local_inner_macros");
128+
129+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
130+
let suggestions =
131+
|| <Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "macro_export");
132+
let local_inner_macros = match args {
133+
ArgParser::NoArgs => false,
134+
ArgParser::List(list) => {
135+
let Some(l) = list.single() else {
136+
let span = cx.attr_span;
137+
cx.emit_lint(
138+
AttributeLintKind::InvalidMacroExportArguments {
139+
suggestions: suggestions(),
140+
},
141+
span,
142+
);
143+
return None;
144+
};
145+
match l.meta_item().and_then(|i| i.path().word_sym()) {
146+
Some(sym::local_inner_macros) => true,
147+
_ => {
148+
let span = cx.attr_span;
149+
cx.emit_lint(
150+
AttributeLintKind::InvalidMacroExportArguments {
151+
suggestions: suggestions(),
152+
},
153+
span,
154+
);
155+
return None;
156+
}
157+
}
158+
}
159+
ArgParser::NameValue(_) => {
160+
let span = cx.attr_span;
161+
let suggestions = suggestions();
162+
cx.emit_err(session_diagnostics::IllFormedAttributeInputLint {
163+
num_suggestions: suggestions.len(),
164+
suggestions: DiagArgValue::StrListSepByAnd(
165+
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
166+
),
167+
span,
168+
});
169+
return None;
170+
}
171+
};
172+
Some(AttributeKind::MacroExport { span: cx.attr_span, local_inner_macros })
173+
}
174+
}

‎compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::attributes::lint_helpers::{
3232
AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser,
3333
};
3434
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
35-
use crate::attributes::macro_attrs::{MacroEscapeParser, MacroUseParser};
35+
use crate::attributes::macro_attrs::{MacroEscapeParser, MacroExportParser,MacroUseParser};
3636
use crate::attributes::must_use::MustUseParser;
3737
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
3838
use crate::attributes::non_exhaustive::NonExhaustiveParser;
@@ -164,6 +164,7 @@ attribute_parsers!(
164164
Single<LinkNameParser>,
165165
Single<LinkOrdinalParser>,
166166
Single<LinkSectionParser>,
167+
Single<MacroExportParser>,
167168
Single<MustUseParser>,
168169
Single<OptimizeParser>,
169170
Single<PathAttributeParser>,

‎compiler/rustc_attr_parsing/src/lints.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,17 @@ pub fn emit_attribute_lint<L: LintEmitter>(lint: &AttributeLint<HirId>, lint_emi
3434
*first_span,
3535
session_diagnostics::EmptyAttributeList { attr_span: *first_span },
3636
),
37+
AttributeLintKind::InvalidMacroExportArguments { suggestions } => lint_emitter
38+
.emit_node_span_lint(
39+
rustc_session::lint::builtin::INVALID_MACRO_EXPORT_ARGUMENTS,
40+
*id,
41+
*span,
42+
session_diagnostics::IllFormedAttributeInput {
43+
num_suggestions: suggestions.len(),
44+
suggestions: DiagArgValue::StrListSepByAnd(
45+
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
46+
),
47+
},
48+
),
3749
}
3850
}

‎compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
769769
}
770770
TerminatorKind::Call { func, args, .. }
771771
| TerminatorKind::TailCall { func, args, .. } => {
772-
let call_source = match term.kind {
773-
TerminatorKind::Call { call_source, .. } => call_source,
774-
TerminatorKind::TailCall { .. } => CallSource::Normal,
772+
let (call_source, destination, is_diverging) = match term.kind {
773+
TerminatorKind::Call { call_source, destination, target, .. } => {
774+
(call_source, destination, target.is_none())
775+
}
776+
TerminatorKind::TailCall { .. } => {
777+
(CallSource::Normal, RETURN_PLACE.into(), false)
778+
}
775779
_ => unreachable!(),
776780
};
777781

@@ -845,9 +849,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
845849
);
846850
}
847851

848-
if let TerminatorKind::Call { destination, target, .. } = term.kind {
849-
self.check_call_dest(term, &sig, destination, target, term_location);
850-
}
852+
self.check_call_dest(term, &sig, destination, is_diverging, term_location);
851853

852854
// The ordinary liveness rules will ensure that all
853855
// regions in the type of the callee are live here. We
@@ -1874,65 +1876,61 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18741876
term: &Terminator<'tcx>,
18751877
sig: &ty::FnSig<'tcx>,
18761878
destination: Place<'tcx>,
1877-
target:Option<BasicBlock>,
1879+
is_diverging:bool,
18781880
term_location: Location,
18791881
) {
18801882
let tcx = self.tcx();
1881-
match target {
1882-
Some(_) => {
1883-
let dest_ty = destination.ty(self.body, tcx).ty;
1884-
let dest_ty = self.normalize(dest_ty, term_location);
1885-
let category = match destination.as_local() {
1886-
Some(RETURN_PLACE) => {
1887-
if let DefiningTy::Const(def_id, _) | DefiningTy::InlineConst(def_id, _) =
1888-
self.universal_regions.defining_ty
1889-
{
1890-
if tcx.is_static(def_id) {
1891-
ConstraintCategory::UseAsStatic
1892-
} else {
1893-
ConstraintCategory::UseAsConst
1894-
}
1883+
if is_diverging {
1884+
// The signature in this call can reference region variables,
1885+
// so erase them before calling a query.
1886+
let output_ty = self.tcx().erase_regions(sig.output());
1887+
if !output_ty
1888+
.is_privately_uninhabited(self.tcx(), self.infcx.typing_env(self.infcx.param_env))
1889+
{
1890+
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
1891+
}
1892+
} else {
1893+
let dest_ty = destination.ty(self.body, tcx).ty;
1894+
let dest_ty = self.normalize(dest_ty, term_location);
1895+
let category = match destination.as_local() {
1896+
Some(RETURN_PLACE) => {
1897+
if let DefiningTy::Const(def_id, _) | DefiningTy::InlineConst(def_id, _) =
1898+
self.universal_regions.defining_ty
1899+
{
1900+
if tcx.is_static(def_id) {
1901+
ConstraintCategory::UseAsStatic
18951902
} else {
1896-
ConstraintCategory::Return(ReturnConstraint::Normal)
1903+
ConstraintCategory::UseAsConst
18971904
}
1905+
} else {
1906+
ConstraintCategory::Return(ReturnConstraint::Normal)
18981907
}
1899-
Some(l) if !self.body.local_decls[l].is_user_variable() => {
1900-
ConstraintCategory::Boring
1901-
}
1902-
// The return type of a call is interesting for diagnostics.
1903-
_ => ConstraintCategory::Assignment,
1904-
};
1905-
1906-
let locations = term_location.to_locations();
1907-
1908-
if let Err(terr) = self.sub_types(sig.output(), dest_ty, locations, category) {
1909-
span_mirbug!(
1910-
self,
1911-
term,
1912-
"call dest mismatch ({:?} <- {:?}): {:?}",
1913-
dest_ty,
1914-
sig.output(),
1915-
terr
1916-
);
19171908
}
1918-
1919-
// When `unsized_fn_params` is not enabled,
1920-
// this check is done at `check_local`.
1921-
if self.unsized_feature_enabled() {
1922-
let span = term.source_info.span;
1923-
self.ensure_place_sized(dest_ty, span);
1909+
Some(l) if !self.body.local_decls[l].is_user_variable() => {
1910+
ConstraintCategory::Boring
19241911
}
1912+
// The return type of a call is interesting for diagnostics.
1913+
_ => ConstraintCategory::Assignment,
1914+
};
1915+
1916+
let locations = term_location.to_locations();
1917+
1918+
if let Err(terr) = self.sub_types(sig.output(), dest_ty, locations, category) {
1919+
span_mirbug!(
1920+
self,
1921+
term,
1922+
"call dest mismatch ({:?} <- {:?}): {:?}",
1923+
dest_ty,
1924+
sig.output(),
1925+
terr
1926+
);
19251927
}
1926-
None => {
1927-
// The signature in this call can reference region variables,
1928-
// so erase them before calling a query.
1929-
let output_ty = self.tcx().erase_regions(sig.output());
1930-
if !output_ty.is_privately_uninhabited(
1931-
self.tcx(),
1932-
self.infcx.typing_env(self.infcx.param_env),
1933-
) {
1934-
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
1935-
}
1928+
1929+
// When `unsized_fn_params` is not enabled,
1930+
// this check is done at `check_local`.
1931+
if self.unsized_feature_enabled() {
1932+
let span = term.source_info.span;
1933+
self.ensure_place_sized(dest_ty, span);
19361934
}
19371935
}
19381936
}

‎compiler/rustc_const_eval/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// tidy-alphabetical-start
22
#![allow(internal_features)]
33
#![allow(rustc::diagnostic_outside_of_impl)]
4+
#![cfg_attr(bootstrap, feature(strict_overflow_ops))]
45
#![doc(rust_logo)]
56
#![feature(array_try_map)]
67
#![feature(assert_matches)]
@@ -10,7 +11,6 @@
1011
#![feature(never_type)]
1112
#![feature(rustdoc_internals)]
1213
#![feature(slice_ptr_get)]
13-
#![feature(strict_overflow_ops)]
1414
#![feature(trait_alias)]
1515
#![feature(try_blocks)]
1616
#![feature(unqualified_local_imports)]

‎compiler/rustc_expand/src/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,9 +910,9 @@ impl SyntaxExtension {
910910
let allow_internal_unsafe =
911911
ast::attr::find_by_name(attrs, sym::allow_internal_unsafe).is_some();
912912

913-
let local_inner_macros = ast::attr::find_by_name(attrs, sym::macro_export)
914-
.and_then(|macro_export| macro_export.meta_item_list())
915-
.is_some_and(|l| ast::attr::list_contains_name(&l, sym::local_inner_macros));
913+
let local_inner_macros =
914+
*find_attr!(attrs,AttributeKind::MacroExport{local_inner_macros: l, ..} => l)
915+
.unwrap_or(&false);
916916
let collapse_debuginfo = Self::get_collapse_debuginfo(sess, attrs, !is_local);
917917
tracing::debug!(?name, ?local_inner_macros, ?collapse_debuginfo, ?allow_internal_unsafe);
918918

‎compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ pub enum AttributeKind {
360360
/// Represents `#[macro_escape]`.
361361
MacroEscape(Span),
362362

363+
/// Represents [`#[macro_export]`](https://doc.rust-lang.org/reference/macros-by-example.html#r-macro.decl.scope.path).
364+
MacroExport { span: Span, local_inner_macros: bool },
365+
363366
/// Represents `#[rustc_macro_transparency]`.
364367
MacroTransparency(Transparency),
365368

‎compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl AttributeKind {
4646
LinkSection { .. } => Yes, // Needed for rustdoc
4747
LoopMatch(..) => No,
4848
MacroEscape(..) => No,
49+
MacroExport { .. } => Yes,
4950
MacroTransparency(..) => Yes,
5051
MacroUse { .. } => No,
5152
Marker(..) => No,

‎compiler/rustc_hir/src/lints.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,22 @@ pub struct AttributeLint<Id> {
3131

3232
#[derive(Clone, Debug, HashStable_Generic)]
3333
pub enum AttributeLintKind {
34-
UnusedDuplicate { this: Span, other: Span, warning: bool },
35-
IllFormedAttributeInput { suggestions: Vec<String> },
36-
EmptyAttribute { first_span: Span },
34+
UnusedDuplicate {
35+
this: Span,
36+
other: Span,
37+
warning: bool,
38+
},
39+
IllFormedAttributeInput {
40+
suggestions: Vec<String>,
41+
},
42+
EmptyAttribute {
43+
first_span: Span,
44+
},
45+
46+
/// Copy of `IllFormedAttributeInput`
47+
/// specifically for the `invalid_macro_export_arguments` lint until that is removed,
48+
/// see <https://github.com/rust-lang/rust/pull/143857#issuecomment-3079175663>
49+
InvalidMacroExportArguments {
50+
suggestions: Vec<String>,
51+
},
3752
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /