Skip to content

Commit 4e82f35

Browse files
committed
Auto merge of rust-lang#94333 - Dylan-DPC:rollup-7yxtywp, r=Dylan-DPC
Rollup of 9 pull requests Successful merges: - rust-lang#91795 (resolve/metadata: Stop encoding macros as reexports) - rust-lang#93714 (better ObligationCause for normalization errors in `can_type_implement_copy`) - rust-lang#94175 (Improve `--check-cfg` implementation) - rust-lang#94212 (Stop manually SIMDing in `swap_nonoverlapping`) - rust-lang#94242 (properly handle fat pointers to uninhabitable types) - rust-lang#94308 (Normalize main return type during mono item collection & codegen) - rust-lang#94315 (update auto trait lint for `PhantomData`) - rust-lang#94316 (Improve string literal unescaping) - rust-lang#94327 (Avoid emitting full macro body into JSON errors) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4b043fa + 3bd163f commit 4e82f35

File tree

66 files changed

+1078
-268
lines changed

Some content is hidden

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

66 files changed

+1078
-268
lines changed

compiler/rustc_ast/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![feature(min_specialization)]
1717
#![recursion_limit = "256"]
1818
#![feature(slice_internals)]
19+
#![feature(stmt_expr_attributes)]
1920

2021
#[macro_use]
2122
extern crate rustc_macros;

compiler/rustc_ast/src/util/literal.rs

+22-17
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,30 @@ impl LitKind {
5656
// new symbol because the string in the LitKind is different to the
5757
// string in the token.
5858
let s = symbol.as_str();
59-
let symbol =
60-
if s.contains(&['\\', '\r']) {
61-
let mut buf = String::with_capacity(s.len());
62-
let mut error = Ok(());
63-
unescape_literal(&s, Mode::Str, &mut |_, unescaped_char| {
64-
match unescaped_char {
65-
Ok(c) => buf.push(c),
66-
Err(err) => {
67-
if err.is_fatal() {
68-
error = Err(LitError::LexerError);
69-
}
59+
let symbol = if s.contains(&['\\', '\r']) {
60+
let mut buf = String::with_capacity(s.len());
61+
let mut error = Ok(());
62+
// Force-inlining here is aggressive but the closure is
63+
// called on every char in the string, so it can be
64+
// hot in programs with many long strings.
65+
unescape_literal(
66+
&s,
67+
Mode::Str,
68+
&mut #[inline(always)]
69+
|_, unescaped_char| match unescaped_char {
70+
Ok(c) => buf.push(c),
71+
Err(err) => {
72+
if err.is_fatal() {
73+
error = Err(LitError::LexerError);
7074
}
7175
}
72-
});
73-
error?;
74-
Symbol::intern(&buf)
75-
} else {
76-
symbol
77-
};
76+
},
77+
);
78+
error?;
79+
Symbol::intern(&buf)
80+
} else {
81+
symbol
82+
};
7883
LitKind::Str(symbol, ast::StrStyle::Cooked)
7984
}
8085
token::StrRaw(n) => {

compiler/rustc_ast_lowering/src/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
444444
),
445445
ItemKind::MacroDef(MacroDef { ref body, macro_rules }) => {
446446
let body = P(self.lower_mac_args(body));
447-
448-
hir::ItemKind::Macro(ast::MacroDef { body, macro_rules })
447+
let macro_kind = self.resolver.decl_macro_kind(self.resolver.local_def_id(id));
448+
hir::ItemKind::Macro(ast::MacroDef { body, macro_rules }, macro_kind)
449449
}
450450
ItemKind::MacCall(..) => {
451451
panic!("`TyMac` should have been expanded by now")

compiler/rustc_ast_lowering/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use rustc_session::lint::LintBuffer;
6161
use rustc_session::parse::feature_err;
6262
use rustc_session::utils::{FlattenNonterminals, NtToTokenstream};
6363
use rustc_session::Session;
64-
use rustc_span::hygiene::ExpnId;
64+
use rustc_span::hygiene::{ExpnId, MacroKind};
6565
use rustc_span::source_map::{respan, DesugaringKind};
6666
use rustc_span::symbol::{kw, sym, Ident, Symbol};
6767
use rustc_span::{Span, DUMMY_SP};
@@ -210,6 +210,8 @@ pub trait ResolverAstLowering {
210210
expn_id: ExpnId,
211211
span: Span,
212212
) -> LocalDefId;
213+
214+
fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind;
213215
}
214216

215217
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,

compiler/rustc_attr/src/builtin.rs

+25-16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_errors::{struct_span_err, Applicability};
88
use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
99
use rustc_macros::HashStable_Generic;
1010
use rustc_session::lint::builtin::UNEXPECTED_CFGS;
11+
use rustc_session::lint::BuiltinLintDiagnostics;
1112
use rustc_session::parse::{feature_err, ParseSess};
1213
use rustc_session::Session;
1314
use rustc_span::hygiene::Transparency;
@@ -461,29 +462,37 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
461462
true
462463
}
463464
MetaItemKind::NameValue(..) | MetaItemKind::Word => {
464-
let name = cfg.ident().expect("multi-segment cfg predicate").name;
465+
let ident = cfg.ident().expect("multi-segment cfg predicate");
466+
let name = ident.name;
465467
let value = cfg.value_str();
466-
if sess.check_config.names_checked && !sess.check_config.names_valid.contains(&name)
467-
{
468-
sess.buffer_lint(
469-
UNEXPECTED_CFGS,
470-
cfg.span,
471-
CRATE_NODE_ID,
472-
"unexpected `cfg` condition name",
473-
);
474-
}
475-
if let Some(val) = value {
476-
if sess.check_config.values_checked.contains(&name)
477-
&& !sess.check_config.values_valid.contains(&(name, val))
478-
{
479-
sess.buffer_lint(
468+
if let Some(names_valid) = &sess.check_config.names_valid {
469+
if !names_valid.contains(&name) {
470+
sess.buffer_lint_with_diagnostic(
480471
UNEXPECTED_CFGS,
481472
cfg.span,
482473
CRATE_NODE_ID,
483-
"unexpected `cfg` condition value",
474+
"unexpected `cfg` condition name",
475+
BuiltinLintDiagnostics::UnexpectedCfg(ident.span, name, None),
484476
);
485477
}
486478
}
479+
if let Some(value) = value {
480+
if let Some(values) = &sess.check_config.values_valid.get(&name) {
481+
if !values.contains(&value) {
482+
sess.buffer_lint_with_diagnostic(
483+
UNEXPECTED_CFGS,
484+
cfg.span,
485+
CRATE_NODE_ID,
486+
"unexpected `cfg` condition value",
487+
BuiltinLintDiagnostics::UnexpectedCfg(
488+
cfg.name_value_literal_span().unwrap(),
489+
name,
490+
Some(value),
491+
),
492+
);
493+
}
494+
}
495+
}
487496
sess.config.contains(&(name, value))
488497
}
489498
}

compiler/rustc_codegen_cranelift/src/main_shim.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ pub(crate) fn maybe_create_entry_wrapper(
5151
// late-bound regions, since late-bound
5252
// regions must appear in the argument
5353
// listing.
54-
let main_ret_ty = tcx.erase_regions(main_ret_ty.no_bound_vars().unwrap());
54+
let main_ret_ty = tcx.normalize_erasing_regions(
55+
ty::ParamEnv::reveal_all(),
56+
main_ret_ty.no_bound_vars().unwrap(),
57+
);
5558

5659
let cmain_sig = Signature {
5760
params: vec![

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,10 @@ fn pointer_or_reference_metadata<'ll, 'tcx>(
449449
// This is a thin pointer. Create a regular pointer type and give it the correct name.
450450
debug_assert_eq!(
451451
(thin_pointer_size, thin_pointer_align),
452-
cx.size_and_align_of(ptr_type)
452+
cx.size_and_align_of(ptr_type),
453+
"ptr_type={}, pointee_type={}",
454+
ptr_type,
455+
pointee_type,
453456
);
454457

455458
unsafe {

compiler/rustc_codegen_llvm/src/debuginfo/utils.rs

+16-17
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use super::namespace::item_namespace;
44
use super::CrateDebugContext;
55

66
use rustc_hir::def_id::DefId;
7-
use rustc_middle::ty::layout::LayoutOf;
7+
use rustc_middle::ty::layout::{HasParamEnv, LayoutOf};
88
use rustc_middle::ty::{self, DefIdTree, Ty};
9-
use rustc_target::abi::Variants;
9+
use tracing::trace;
1010

1111
use crate::common::CodegenCx;
1212
use crate::llvm;
@@ -63,38 +63,37 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>(
6363
cx: &CodegenCx<'ll, 'tcx>,
6464
pointee_ty: Ty<'tcx>,
6565
) -> Option<FatPtrKind> {
66-
let layout = cx.layout_of(pointee_ty);
66+
let pointee_tail_ty = cx.tcx.struct_tail_erasing_lifetimes(pointee_ty, cx.param_env());
67+
let layout = cx.layout_of(pointee_tail_ty);
68+
trace!(
69+
"fat_pointer_kind: {:?} has layout {:?} (is_unsized? {})",
70+
pointee_tail_ty,
71+
layout,
72+
layout.is_unsized()
73+
);
6774

6875
if !layout.is_unsized() {
6976
return None;
7077
}
7178

72-
match *pointee_ty.kind() {
79+
match *pointee_tail_ty.kind() {
7380
ty::Str | ty::Slice(_) => Some(FatPtrKind::Slice),
7481
ty::Dynamic(..) => Some(FatPtrKind::Dyn),
75-
ty::Adt(..) | ty::Tuple(..) if matches!(layout.variants, Variants::Single { .. }) => {
76-
let last_field_index = layout.fields.count() - 1;
77-
debug_assert!(
78-
(0..last_field_index)
79-
.all(|field_index| { !layout.field(cx, field_index).is_unsized() })
80-
);
81-
82-
let unsized_field = layout.field(cx, last_field_index);
83-
debug_assert!(unsized_field.is_unsized());
84-
fat_pointer_kind(cx, unsized_field.ty)
85-
}
8682
ty::Foreign(_) => {
8783
// Assert that pointers to foreign types really are thin:
8884
debug_assert_eq!(
89-
cx.size_of(cx.tcx.mk_imm_ptr(pointee_ty)),
85+
cx.size_of(cx.tcx.mk_imm_ptr(pointee_tail_ty)),
9086
cx.size_of(cx.tcx.mk_imm_ptr(cx.tcx.types.u8))
9187
);
9288
None
9389
}
9490
_ => {
9591
// For all other pointee types we should already have returned None
9692
// at the beginning of the function.
97-
panic!("fat_pointer_kind() - Encountered unexpected `pointee_ty`: {:?}", pointee_ty)
93+
panic!(
94+
"fat_pointer_kind() - Encountered unexpected `pointee_tail_ty`: {:?}",
95+
pointee_tail_ty
96+
)
9897
}
9998
}
10099
}

compiler/rustc_codegen_ssa/src/base.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,10 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
407407
// late-bound regions, since late-bound
408408
// regions must appear in the argument
409409
// listing.
410-
let main_ret_ty = cx.tcx().erase_regions(main_ret_ty.no_bound_vars().unwrap());
410+
let main_ret_ty = cx.tcx().normalize_erasing_regions(
411+
ty::ParamEnv::reveal_all(),
412+
main_ret_ty.no_bound_vars().unwrap(),
413+
);
411414

412415
let Some(llfn) = cx.declare_c_main(llfty) else {
413416
// FIXME: We should be smart and show a better diagnostic here.

compiler/rustc_errors/src/json.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,14 @@ impl DiagnosticSpan {
454454
let end = je.sm.lookup_char_pos(span.hi());
455455
let backtrace_step = backtrace.next().map(|bt| {
456456
let call_site = Self::from_span_full(bt.call_site, false, None, None, backtrace, je);
457-
let def_site_span =
458-
Self::from_span_full(bt.def_site, false, None, None, [].into_iter(), je);
457+
let def_site_span = Self::from_span_full(
458+
je.sm.guess_head_span(bt.def_site),
459+
false,
460+
None,
461+
None,
462+
[].into_iter(),
463+
je,
464+
);
459465
Box::new(DiagnosticSpanMacroExpansion {
460466
span: call_site,
461467
macro_decl_name: bt.kind.descr(),

compiler/rustc_hir/src/hir.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_data_structures::fx::FxHashMap;
1515
use rustc_data_structures::sorted_map::SortedMap;
1616
use rustc_index::vec::IndexVec;
1717
use rustc_macros::HashStable_Generic;
18+
use rustc_span::hygiene::MacroKind;
1819
use rustc_span::source_map::Spanned;
1920
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2021
use rustc_span::{def_id::LocalDefId, BytePos, MultiSpan, Span, DUMMY_SP};
@@ -2803,7 +2804,7 @@ pub enum ItemKind<'hir> {
28032804
/// A function declaration.
28042805
Fn(FnSig<'hir>, Generics<'hir>, BodyId),
28052806
/// A MBE macro definition (`macro_rules!` or `macro`).
2806-
Macro(ast::MacroDef),
2807+
Macro(ast::MacroDef, MacroKind),
28072808
/// A module.
28082809
Mod(Mod<'hir>),
28092810
/// An external module, e.g. `extern { .. }`.

compiler/rustc_hir/src/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
575575
item.span,
576576
item.hir_id(),
577577
),
578-
ItemKind::Macro(_) => {
578+
ItemKind::Macro(..) => {
579579
visitor.visit_id(item.hir_id());
580580
}
581581
ItemKind::Mod(ref module) => {

compiler/rustc_hir_pretty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ impl<'a> State<'a> {
570570
self.end(); // need to close a box
571571
self.ann.nested(self, Nested::Body(body));
572572
}
573-
hir::ItemKind::Macro(ref macro_def) => {
573+
hir::ItemKind::Macro(ref macro_def, _) => {
574574
self.print_mac_def(macro_def, &item.ident, item.span, |state| {
575575
state.print_visibility(&item.vis)
576576
});

compiler/rustc_interface/src/interface.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,12 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
169169
Ok(meta_item) if parser.token == token::Eof => {
170170
if let Some(args) = meta_item.meta_item_list() {
171171
if meta_item.has_name(sym::names) {
172-
cfg.names_checked = true;
172+
let names_valid =
173+
cfg.names_valid.get_or_insert_with(|| FxHashSet::default());
173174
for arg in args {
174175
if arg.is_word() && arg.ident().is_some() {
175176
let ident = arg.ident().expect("multi-segment cfg key");
176-
cfg.names_valid.insert(ident.name.to_string());
177+
names_valid.insert(ident.name.to_string());
177178
} else {
178179
error!("`names()` arguments must be simple identifers");
179180
}
@@ -183,13 +184,16 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
183184
if let Some((name, values)) = args.split_first() {
184185
if name.is_word() && name.ident().is_some() {
185186
let ident = name.ident().expect("multi-segment cfg key");
186-
cfg.values_checked.insert(ident.to_string());
187+
let ident_values = cfg
188+
.values_valid
189+
.entry(ident.name.to_string())
190+
.or_insert_with(|| FxHashSet::default());
191+
187192
for val in values {
188193
if let Some(LitKind::Str(s, _)) =
189194
val.literal().map(|lit| &lit.kind)
190195
{
191-
cfg.values_valid
192-
.insert((ident.to_string(), s.to_string()));
196+
ident_values.insert(s.to_string());
193197
} else {
194198
error!(
195199
"`values()` arguments must be string literals"
@@ -219,7 +223,9 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
219223
);
220224
}
221225

222-
cfg.names_valid.extend(cfg.values_checked.iter().cloned());
226+
if let Some(names_valid) = &mut cfg.names_valid {
227+
names_valid.extend(cfg.values_valid.keys().cloned());
228+
}
223229
cfg
224230
})
225231
}

0 commit comments

Comments
 (0)