Skip to content

Commit 92d7277

Browse files
committed
Auto merge of rust-lang#120112 - matthiaskrgr:rollup-48o3919, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#119582 (bootstrap: handle vendored sources when remapping crate paths) - rust-lang#119730 (docs: fix typos) - rust-lang#119828 (Improved collapse_debuginfo attribute, added command-line flag) - rust-lang#119869 (replace `track_errors` usages with bubbling up `ErrorGuaranteed`) - rust-lang#120037 (Remove `next_root_ty_var`) - rust-lang#120094 (tests/ui/asm/inline-syntax: adapt for LLVM 18) - rust-lang#120096 (Set RUSTC_BOOTSTRAP=1 consistently) - rust-lang#120101 (change `.unwrap()` to `?` on write where `fmt::Result` is returned) - rust-lang#120102 (Fix typo in munmap_partial.rs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 16fadb3 + 9c6795b commit 92d7277

Some content is hidden

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

61 files changed

+771
-255
lines changed

compiler/rustc_expand/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ expand_attributes_wrong_form =
1616
expand_cannot_be_name_of_macro =
1717
`{$trait_ident}` cannot be a name of {$macro_type} macro
1818
19+
expand_collapse_debuginfo_illegal =
20+
illegal value for attribute #[collapse_debuginfo(no|external|yes)]
21+
1922
expand_count_repetition_misplaced =
2023
`count` can not be placed inside the inner-most repetition
2124

compiler/rustc_expand/src/base.rs

+54-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![deny(rustc::untranslatable_diagnostic)]
22

3+
use crate::base::ast::NestedMetaItem;
34
use crate::errors;
45
use crate::expand::{self, AstFragment, Invocation};
56
use crate::module::DirOwnership;
@@ -19,6 +20,7 @@ use rustc_feature::Features;
1920
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
2021
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics, RegisteredTools};
2122
use rustc_parse::{parser, MACRO_ARGUMENTS};
23+
use rustc_session::config::CollapseMacroDebuginfo;
2224
use rustc_session::errors::report_lit_error;
2325
use rustc_session::{parse::ParseSess, Limit, Session};
2426
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
@@ -761,6 +763,55 @@ impl SyntaxExtension {
761763
}
762764
}
763765

766+
fn collapse_debuginfo_by_name(sess: &Session, attr: &Attribute) -> CollapseMacroDebuginfo {
767+
use crate::errors::CollapseMacroDebuginfoIllegal;
768+
// #[collapse_debuginfo] without enum value (#[collapse_debuginfo(no/external/yes)])
769+
// considered as `yes`
770+
attr.meta_item_list().map_or(CollapseMacroDebuginfo::Yes, |l| {
771+
let [NestedMetaItem::MetaItem(item)] = &l[..] else {
772+
sess.dcx().emit_err(CollapseMacroDebuginfoIllegal { span: attr.span });
773+
return CollapseMacroDebuginfo::Unspecified;
774+
};
775+
if !item.is_word() {
776+
sess.dcx().emit_err(CollapseMacroDebuginfoIllegal { span: item.span });
777+
CollapseMacroDebuginfo::Unspecified
778+
} else {
779+
match item.name_or_empty() {
780+
sym::no => CollapseMacroDebuginfo::No,
781+
sym::external => CollapseMacroDebuginfo::External,
782+
sym::yes => CollapseMacroDebuginfo::Yes,
783+
_ => {
784+
sess.dcx().emit_err(CollapseMacroDebuginfoIllegal { span: item.span });
785+
CollapseMacroDebuginfo::Unspecified
786+
}
787+
}
788+
}
789+
})
790+
}
791+
792+
/// if-ext - if macro from different crate (related to callsite code)
793+
/// | cmd \ attr | no | (unspecified) | external | yes |
794+
/// | no | no | no | no | no |
795+
/// | (unspecified) | no | no | if-ext | yes |
796+
/// | external | no | if-ext | if-ext | yes |
797+
/// | yes | yes | yes | yes | yes |
798+
fn get_collapse_debuginfo(sess: &Session, attrs: &[ast::Attribute], is_local: bool) -> bool {
799+
let collapse_debuginfo_attr = attr::find_by_name(attrs, sym::collapse_debuginfo)
800+
.map(|v| Self::collapse_debuginfo_by_name(sess, v))
801+
.unwrap_or(CollapseMacroDebuginfo::Unspecified);
802+
let flag = sess.opts.unstable_opts.collapse_macro_debuginfo;
803+
let attr = collapse_debuginfo_attr;
804+
let ext = !is_local;
805+
#[rustfmt::skip]
806+
let collapse_table = [
807+
[false, false, false, false],
808+
[false, false, ext, true],
809+
[false, ext, ext, true],
810+
[true, true, true, true],
811+
];
812+
collapse_table[flag as usize][attr as usize]
813+
}
814+
764815
/// Constructs a syntax extension with the given properties
765816
/// and other properties converted from attributes.
766817
pub fn new(
@@ -772,6 +823,7 @@ impl SyntaxExtension {
772823
edition: Edition,
773824
name: Symbol,
774825
attrs: &[ast::Attribute],
826+
is_local: bool,
775827
) -> SyntaxExtension {
776828
let allow_internal_unstable =
777829
attr::allow_internal_unstable(sess, attrs).collect::<Vec<Symbol>>();
@@ -780,8 +832,8 @@ impl SyntaxExtension {
780832
let local_inner_macros = attr::find_by_name(attrs, sym::macro_export)
781833
.and_then(|macro_export| macro_export.meta_item_list())
782834
.is_some_and(|l| attr::list_contains_name(&l, sym::local_inner_macros));
783-
let collapse_debuginfo = attr::contains_name(attrs, sym::collapse_debuginfo);
784-
tracing::debug!(?local_inner_macros, ?collapse_debuginfo, ?allow_internal_unsafe);
835+
let collapse_debuginfo = Self::get_collapse_debuginfo(sess, attrs, is_local);
836+
tracing::debug!(?name, ?local_inner_macros, ?collapse_debuginfo, ?allow_internal_unsafe);
785837

786838
let (builtin_name, helper_attrs) = attr::find_by_name(attrs, sym::rustc_builtin_macro)
787839
.map(|attr| {

compiler/rustc_expand/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ pub(crate) struct ResolveRelativePath {
5858
pub path: String,
5959
}
6060

61+
#[derive(Diagnostic)]
62+
#[diag(expand_collapse_debuginfo_illegal)]
63+
pub(crate) struct CollapseMacroDebuginfoIllegal {
64+
#[primary_span]
65+
pub span: Span,
66+
}
67+
6168
#[derive(Diagnostic)]
6269
#[diag(expand_macro_const_stability)]
6370
pub(crate) struct MacroConstStability {

compiler/rustc_expand/src/mbe/macro_rules.rs

+1
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ pub fn compile_declarative_macro(
367367
edition,
368368
def.ident.name,
369369
&def.attrs,
370+
def.id != DUMMY_NODE_ID,
370371
)
371372
};
372373
let dummy_syn_ext = || (mk_syn_ext(Box::new(macro_rules_dummy_expander)), Vec::new());

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
469469

470470
// `#[collapse_debuginfo]`
471471
gated!(
472-
collapse_debuginfo, Normal, template!(Word), WarnFollowing,
472+
collapse_debuginfo, Normal, template!(Word, List: "no|external|yes"), ErrorFollowing,
473473
experimental!(collapse_debuginfo)
474474
),
475475

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
14461446
}
14471447

14481448
let candidates: Vec<_> = tcx
1449-
.inherent_impls(adt_did)
1449+
.inherent_impls(adt_did)?
14501450
.iter()
14511451
.filter_map(|&impl_| Some((impl_, self.lookup_assoc_ty_unchecked(name, block, impl_)?)))
14521452
.collect();

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

+48-31
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,41 @@ use rustc_hir::def_id::{DefId, LocalDefId};
1313
use rustc_middle::ty::fast_reject::{simplify_type, SimplifiedType, TreatParams};
1414
use rustc_middle::ty::{self, CrateInherentImpls, Ty, TyCtxt};
1515
use rustc_span::symbol::sym;
16+
use rustc_span::ErrorGuaranteed;
1617

1718
use crate::errors;
1819

1920
/// On-demand query: yields a map containing all types mapped to their inherent impls.
20-
pub fn crate_inherent_impls(tcx: TyCtxt<'_>, (): ()) -> CrateInherentImpls {
21+
pub fn crate_inherent_impls(
22+
tcx: TyCtxt<'_>,
23+
(): (),
24+
) -> Result<&'_ CrateInherentImpls, ErrorGuaranteed> {
2125
let mut collect = InherentCollect { tcx, impls_map: Default::default() };
26+
let mut res = Ok(());
2227
for id in tcx.hir().items() {
23-
collect.check_item(id);
28+
res = res.and(collect.check_item(id));
2429
}
25-
collect.impls_map
30+
res?;
31+
Ok(tcx.arena.alloc(collect.impls_map))
2632
}
2733

28-
pub fn crate_incoherent_impls(tcx: TyCtxt<'_>, simp: SimplifiedType) -> &[DefId] {
29-
let crate_map = tcx.crate_inherent_impls(());
30-
tcx.arena.alloc_from_iter(
34+
pub fn crate_incoherent_impls(
35+
tcx: TyCtxt<'_>,
36+
simp: SimplifiedType,
37+
) -> Result<&[DefId], ErrorGuaranteed> {
38+
let crate_map = tcx.crate_inherent_impls(())?;
39+
Ok(tcx.arena.alloc_from_iter(
3140
crate_map.incoherent_impls.get(&simp).unwrap_or(&Vec::new()).iter().map(|d| d.to_def_id()),
32-
)
41+
))
3342
}
3443

3544
/// On-demand query: yields a vector of the inherent impls for a specific type.
36-
pub fn inherent_impls(tcx: TyCtxt<'_>, ty_def_id: LocalDefId) -> &[DefId] {
37-
let crate_map = tcx.crate_inherent_impls(());
38-
match crate_map.inherent_impls.get(&ty_def_id) {
45+
pub fn inherent_impls(tcx: TyCtxt<'_>, ty_def_id: LocalDefId) -> Result<&[DefId], ErrorGuaranteed> {
46+
let crate_map = tcx.crate_inherent_impls(())?;
47+
Ok(match crate_map.inherent_impls.get(&ty_def_id) {
3948
Some(v) => &v[..],
4049
None => &[],
41-
}
50+
})
4251
}
4352

4453
struct InherentCollect<'tcx> {
@@ -47,33 +56,36 @@ struct InherentCollect<'tcx> {
4756
}
4857

4958
impl<'tcx> InherentCollect<'tcx> {
50-
fn check_def_id(&mut self, impl_def_id: LocalDefId, self_ty: Ty<'tcx>, ty_def_id: DefId) {
59+
fn check_def_id(
60+
&mut self,
61+
impl_def_id: LocalDefId,
62+
self_ty: Ty<'tcx>,
63+
ty_def_id: DefId,
64+
) -> Result<(), ErrorGuaranteed> {
5165
if let Some(ty_def_id) = ty_def_id.as_local() {
5266
// Add the implementation to the mapping from implementation to base
5367
// type def ID, if there is a base type for this implementation and
5468
// the implementation does not have any associated traits.
5569
let vec = self.impls_map.inherent_impls.entry(ty_def_id).or_default();
5670
vec.push(impl_def_id.to_def_id());
57-
return;
71+
return Ok(());
5872
}
5973

6074
if self.tcx.features().rustc_attrs {
6175
let items = self.tcx.associated_item_def_ids(impl_def_id);
6276

6377
if !self.tcx.has_attr(ty_def_id, sym::rustc_has_incoherent_inherent_impls) {
6478
let impl_span = self.tcx.def_span(impl_def_id);
65-
self.tcx.dcx().emit_err(errors::InherentTyOutside { span: impl_span });
66-
return;
79+
return Err(self.tcx.dcx().emit_err(errors::InherentTyOutside { span: impl_span }));
6780
}
6881

6982
for &impl_item in items {
7083
if !self.tcx.has_attr(impl_item, sym::rustc_allow_incoherent_impl) {
7184
let impl_span = self.tcx.def_span(impl_def_id);
72-
self.tcx.dcx().emit_err(errors::InherentTyOutsideRelevant {
85+
return Err(self.tcx.dcx().emit_err(errors::InherentTyOutsideRelevant {
7386
span: impl_span,
7487
help_span: self.tcx.def_span(impl_item),
75-
});
76-
return;
88+
}));
7789
}
7890
}
7991

@@ -82,24 +94,28 @@ impl<'tcx> InherentCollect<'tcx> {
8294
} else {
8395
bug!("unexpected self type: {:?}", self_ty);
8496
}
97+
Ok(())
8598
} else {
8699
let impl_span = self.tcx.def_span(impl_def_id);
87-
self.tcx.dcx().emit_err(errors::InherentTyOutsideNew { span: impl_span });
100+
Err(self.tcx.dcx().emit_err(errors::InherentTyOutsideNew { span: impl_span }))
88101
}
89102
}
90103

91-
fn check_primitive_impl(&mut self, impl_def_id: LocalDefId, ty: Ty<'tcx>) {
104+
fn check_primitive_impl(
105+
&mut self,
106+
impl_def_id: LocalDefId,
107+
ty: Ty<'tcx>,
108+
) -> Result<(), ErrorGuaranteed> {
92109
let items = self.tcx.associated_item_def_ids(impl_def_id);
93110
if !self.tcx.hir().rustc_coherence_is_core() {
94111
if self.tcx.features().rustc_attrs {
95112
for &impl_item in items {
96113
if !self.tcx.has_attr(impl_item, sym::rustc_allow_incoherent_impl) {
97114
let span = self.tcx.def_span(impl_def_id);
98-
self.tcx.dcx().emit_err(errors::InherentTyOutsidePrimitive {
115+
return Err(self.tcx.dcx().emit_err(errors::InherentTyOutsidePrimitive {
99116
span,
100117
help_span: self.tcx.def_span(impl_item),
101-
});
102-
return;
118+
}));
103119
}
104120
}
105121
} else {
@@ -108,8 +124,7 @@ impl<'tcx> InherentCollect<'tcx> {
108124
if let ty::Ref(_, subty, _) = ty.kind() {
109125
note = Some(errors::InherentPrimitiveTyNote { subty: *subty });
110126
}
111-
self.tcx.dcx().emit_err(errors::InherentPrimitiveTy { span, note });
112-
return;
127+
return Err(self.tcx.dcx().emit_err(errors::InherentPrimitiveTy { span, note }));
113128
}
114129
}
115130

@@ -118,11 +133,12 @@ impl<'tcx> InherentCollect<'tcx> {
118133
} else {
119134
bug!("unexpected primitive type: {:?}", ty);
120135
}
136+
Ok(())
121137
}
122138

123-
fn check_item(&mut self, id: hir::ItemId) {
139+
fn check_item(&mut self, id: hir::ItemId) -> Result<(), ErrorGuaranteed> {
124140
if !matches!(self.tcx.def_kind(id.owner_id), DefKind::Impl { of_trait: false }) {
125-
return;
141+
return Ok(());
126142
}
127143

128144
let id = id.owner_id.def_id;
@@ -132,10 +148,10 @@ impl<'tcx> InherentCollect<'tcx> {
132148
ty::Adt(def, _) => self.check_def_id(id, self_ty, def.did()),
133149
ty::Foreign(did) => self.check_def_id(id, self_ty, did),
134150
ty::Dynamic(data, ..) if data.principal_def_id().is_some() => {
135-
self.check_def_id(id, self_ty, data.principal_def_id().unwrap());
151+
self.check_def_id(id, self_ty, data.principal_def_id().unwrap())
136152
}
137153
ty::Dynamic(..) => {
138-
self.tcx.dcx().emit_err(errors::InherentDyn { span: item_span });
154+
Err(self.tcx.dcx().emit_err(errors::InherentDyn { span: item_span }))
139155
}
140156
ty::Bool
141157
| ty::Char
@@ -151,7 +167,7 @@ impl<'tcx> InherentCollect<'tcx> {
151167
| ty::FnPtr(_)
152168
| ty::Tuple(..) => self.check_primitive_impl(id, self_ty),
153169
ty::Alias(..) | ty::Param(_) => {
154-
self.tcx.dcx().emit_err(errors::InherentNominal { span: item_span });
170+
Err(self.tcx.dcx().emit_err(errors::InherentNominal { span: item_span }))
155171
}
156172
ty::FnDef(..)
157173
| ty::Closure(..)
@@ -162,7 +178,8 @@ impl<'tcx> InherentCollect<'tcx> {
162178
| ty::Infer(_) => {
163179
bug!("unexpected impl self type of impl: {:?} {:?}", id, self_ty);
164180
}
165-
ty::Error(_) => {}
181+
// We could bail out here, but that will silence other useful errors.
182+
ty::Error(_) => Ok(()),
166183
}
167184
}
168185
}

0 commit comments

Comments
 (0)