Skip to content

Commit c65dcca

Browse files
committed
Auto merge of #143233 - dianqk:rollup-lcx3278, r=dianqk
Rollup of 14 pull requests Successful merges: - #142429 (`tests/ui`: A New Order [13/N]) - #142514 (Miri: handling of SNaN inputs in `f*::pow` operations) - #143066 (Use let chains in the new solver) - #143090 (Workaround for memory unsafety in third party DLLs) - #143118 (`tests/ui`: A New Order [15/N]) - #143159 (Do not freshen `ReError`) - #143168 (`tests/ui`: A New Order [16/N]) - #143176 (fix typos and improve clarity in documentation) - #143187 (Add my work email to mailmap) - #143190 (Use the `new` method for `BasicBlockData` and `Statement`) - #143195 (`tests/ui`: A New Order [17/N]) - #143196 (Port #[link_section] to the new attribute parsing infrastructure) - #143199 (Re-disable `tests/run-make/short-ice` on Windows MSVC again) - #143219 (Show auto trait and blanket impls for `!`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ad3b725 + c2904f7 commit c65dcca

File tree

125 files changed

+1361
-1066
lines changed

Some content is hidden

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

125 files changed

+1361
-1066
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ Xinye Tao <xy.tao@outlook.com>
690690
Xuefeng Wu <benewu@gmail.com> Xuefeng Wu <xfwu@thoughtworks.com>
691691
Xuefeng Wu <benewu@gmail.com> XuefengWu <benewu@gmail.com>
692692
York Xiang <bombless@126.com>
693+
Yotam Ofek <yotam.ofek@gmail.com> <yotamofek@microsoft.com>
693694
Youngsoo Son <ysson83@gmail.com> <ysoo.son@samsung.com>
694695
Youngsuk Kim <joseph942010@gmail.com>
695696
Yuki Okushi <jtitor@2k36.org>

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ pub enum AttributeKind {
256256
/// Represents `#[link_name]`.
257257
LinkName { name: Symbol, span: Span },
258258

259+
/// Represents [`#[link_section]`](https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute)
260+
LinkSection { name: Symbol, span: Span },
261+
259262
/// Represents `#[loop_match]`.
260263
LoopMatch(Span),
261264

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl AttributeKind {
2424
DocComment { .. } => Yes,
2525
ExportName { .. } => Yes,
2626
Inline(..) => No,
27+
LinkSection { .. } => No,
2728
MacroTransparency(..) => Yes,
2829
Repr(..) => No,
2930
Stability { .. } => Yes,

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ attr_parsing_non_ident_feature =
9999
100100
attr_parsing_null_on_export = `export_name` may not contain null characters
101101
102+
attr_parsing_null_on_link_section = `link_section` may not contain null characters
103+
102104
attr_parsing_repr_ident =
103105
meta item in `repr` must be an identifier
104106

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use rustc_attr_data_structures::AttributeKind;
2-
use rustc_attr_data_structures::AttributeKind::LinkName;
2+
use rustc_attr_data_structures::AttributeKind::{LinkName, LinkSection};
33
use rustc_feature::{AttributeTemplate, template};
44
use rustc_span::{Symbol, sym};
55

66
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
77
use crate::context::{AcceptContext, Stage};
88
use crate::parser::ArgParser;
9+
use crate::session_diagnostics::NullOnLinkSection;
910

1011
pub(crate) struct LinkNameParser;
1112

@@ -28,3 +29,31 @@ impl<S: Stage> SingleAttributeParser<S> for LinkNameParser {
2829
Some(LinkName { name, span: cx.attr_span })
2930
}
3031
}
32+
33+
pub(crate) struct LinkSectionParser;
34+
35+
impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
36+
const PATH: &[Symbol] = &[sym::link_section];
37+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
38+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
39+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
40+
41+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
42+
let Some(nv) = args.name_value() else {
43+
cx.expected_name_value(cx.attr_span, None);
44+
return None;
45+
};
46+
let Some(name) = nv.value_as_str() else {
47+
cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
48+
return None;
49+
};
50+
if name.as_str().contains('\0') {
51+
// `#[link_section = ...]` will be converted to a null-terminated string,
52+
// so it may not contain any null characters.
53+
cx.emit_err(NullOnLinkSection { span: cx.attr_span });
54+
return None;
55+
}
56+
57+
Some(LinkSection { name, span: cx.attr_span })
58+
}
59+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::attributes::codegen_attrs::{
2222
use crate::attributes::confusables::ConfusablesParser;
2323
use crate::attributes::deprecation::DeprecationParser;
2424
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
25-
use crate::attributes::link_attrs::LinkNameParser;
25+
use crate::attributes::link_attrs::{LinkNameParser, LinkSectionParser};
2626
use crate::attributes::lint_helpers::{AsPtrParser, PubTransparentParser};
2727
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
2828
use crate::attributes::must_use::MustUseParser;
@@ -123,6 +123,7 @@ attribute_parsers!(
123123
Single<ExportNameParser>,
124124
Single<InlineParser>,
125125
Single<LinkNameParser>,
126+
Single<LinkSectionParser>,
126127
Single<LoopMatchParser>,
127128
Single<MayDangleParser>,
128129
Single<MustUseParser>,

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,13 @@ pub(crate) struct NullOnExport {
452452
pub span: Span,
453453
}
454454

455+
#[derive(Diagnostic)]
456+
#[diag(attr_parsing_null_on_link_section, code = E0648)]
457+
pub(crate) struct NullOnLinkSection {
458+
#[primary_span]
459+
pub span: Span,
460+
}
461+
455462
#[derive(Diagnostic)]
456463
#[diag(attr_parsing_stability_outside_std, code = E0734)]
457464
pub(crate) struct StabilityOutsideStd {

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
124124
AttributeKind::Naked(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED,
125125
AttributeKind::Align { align, .. } => codegen_fn_attrs.alignment = Some(*align),
126126
AttributeKind::LinkName { name, .. } => codegen_fn_attrs.link_name = Some(*name),
127+
AttributeKind::LinkSection { name, .. } => {
128+
codegen_fn_attrs.link_section = Some(*name)
129+
}
127130
AttributeKind::NoMangle(attr_span) => {
128131
if tcx.opt_item_name(did.to_def_id()).is_some() {
129132
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
@@ -253,16 +256,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
253256
}
254257
}
255258
}
256-
sym::link_section => {
257-
if let Some(val) = attr.value_str() {
258-
if val.as_str().bytes().any(|b| b == 0) {
259-
let msg = format!("illegal null byte in link_section value: `{val}`");
260-
tcx.dcx().span_err(attr.span(), msg);
261-
} else {
262-
codegen_fn_attrs.link_section = Some(val);
263-
}
264-
}
265-
}
266259
sym::link_ordinal => {
267260
link_ordinal_span = Some(attr.span());
268261
if let ordinal @ Some(_) = check_link_ordinal(tcx, attr) {

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,15 @@ fn optimize_use_clone<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
354354

355355
let destination_block = target.unwrap();
356356

357-
bb.statements.push(mir::Statement {
358-
source_info: bb.terminator().source_info,
359-
kind: mir::StatementKind::Assign(Box::new((
357+
bb.statements.push(mir::Statement::new(
358+
bb.terminator().source_info,
359+
mir::StatementKind::Assign(Box::new((
360360
*destination,
361361
mir::Rvalue::Use(mir::Operand::Copy(
362362
arg_place.project_deeper(&[mir::ProjectionElem::Deref], tcx),
363363
)),
364364
))),
365-
});
365+
));
366366

367367
bb.terminator_mut().kind = mir::TerminatorKind::Goto { target: destination_block };
368368
}

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3055,7 +3055,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30553055
pub(crate) fn note_unmet_impls_on_type(
30563056
&self,
30573057
err: &mut Diag<'_>,
3058-
errors: Vec<FulfillmentError<'tcx>>,
3058+
errors: &[FulfillmentError<'tcx>],
30593059
suggest_derive: bool,
30603060
) {
30613061
let preds: Vec<_> = errors

compiler/rustc_hir_typeck/src/op.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
322322
lhs_expr.span,
323323
format!("cannot use `{}` on type `{}`", s, lhs_ty_str),
324324
);
325-
self.note_unmet_impls_on_type(&mut err, errors, false);
325+
self.note_unmet_impls_on_type(&mut err, &errors, false);
326326
(err, None)
327327
}
328328
Op::BinOp(bin_op) => {
@@ -382,7 +382,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
382382
err.span_label(rhs_expr.span, rhs_ty_str);
383383
}
384384
let suggest_derive = self.can_eq(self.param_env, lhs_ty, rhs_ty);
385-
self.note_unmet_impls_on_type(&mut err, errors, suggest_derive);
385+
self.note_unmet_impls_on_type(&mut err, &errors, suggest_derive);
386386
(err, output_def_id)
387387
}
388388
};
@@ -582,22 +582,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
582582
// concatenation (e.g., "Hello " + "World!"). This means
583583
// we don't want the note in the else clause to be emitted
584584
} else if lhs_ty.has_non_region_param() {
585-
// Look for a TraitPredicate in the Fulfillment errors,
586-
// and use it to generate a suggestion.
587-
//
588-
// Note that lookup_op_method must be called again but
589-
// with a specific rhs_ty instead of a placeholder so
590-
// the resulting predicate generates a more specific
591-
// suggestion for the user.
592-
let errors = self
593-
.lookup_op_method(
594-
(lhs_expr, lhs_ty),
595-
Some((rhs_expr, rhs_ty)),
596-
lang_item_for_binop(self.tcx, op),
597-
op.span(),
598-
expected,
599-
)
600-
.unwrap_err();
601585
if !errors.is_empty() {
602586
for error in errors {
603587
if let Some(trait_pred) =
@@ -946,7 +930,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
946930
ty::Str | ty::Never | ty::Char | ty::Tuple(_) | ty::Array(_, _) => {}
947931
ty::Ref(_, lty, _) if *lty.kind() == ty::Str => {}
948932
_ => {
949-
self.note_unmet_impls_on_type(&mut err, errors, true);
933+
self.note_unmet_impls_on_type(&mut err, &errors, true);
950934
}
951935
}
952936
}

compiler/rustc_infer/src/infer/freshen.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,16 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
110110

111111
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
112112
match r.kind() {
113-
ty::ReBound(..) => {
114-
// leave bound regions alone
115-
r
116-
}
113+
// Leave bound regions alone, since they affect selection via the leak check.
114+
ty::ReBound(..) => r,
115+
// Leave error regions alone, since they affect selection b/c of incompleteness.
116+
ty::ReError(_) => r,
117117

118118
ty::ReEarlyParam(..)
119119
| ty::ReLateParam(_)
120120
| ty::ReVar(_)
121121
| ty::RePlaceholder(..)
122122
| ty::ReStatic
123-
| ty::ReError(_)
124123
| ty::ReErased => self.cx().lifetimes.re_erased,
125124
}
126125
}

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,15 @@ pub struct BasicBlockData<'tcx> {
13591359

13601360
impl<'tcx> BasicBlockData<'tcx> {
13611361
pub fn new(terminator: Option<Terminator<'tcx>>, is_cleanup: bool) -> BasicBlockData<'tcx> {
1362-
BasicBlockData { statements: vec![], terminator, is_cleanup }
1362+
BasicBlockData::new_stmts(Vec::new(), terminator, is_cleanup)
1363+
}
1364+
1365+
pub fn new_stmts(
1366+
statements: Vec<Statement<'tcx>>,
1367+
terminator: Option<Terminator<'tcx>>,
1368+
is_cleanup: bool,
1369+
) -> BasicBlockData<'tcx> {
1370+
BasicBlockData { statements, terminator, is_cleanup }
13631371
}
13641372

13651373
/// Accessor for terminator.

compiler/rustc_middle/src/mir/statement.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ pub struct Statement<'tcx> {
1616
pub kind: StatementKind<'tcx>,
1717
}
1818

19-
impl Statement<'_> {
19+
impl<'tcx> Statement<'tcx> {
2020
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
2121
/// invalidating statement indices in `Location`s.
2222
pub fn make_nop(&mut self) {
2323
self.kind = StatementKind::Nop
2424
}
25+
26+
pub fn new(source_info: SourceInfo, kind: StatementKind<'tcx>) -> Self {
27+
Statement { source_info, kind }
28+
}
2529
}
2630

2731
impl<'tcx> StatementKind<'tcx> {

compiler/rustc_mir_build/src/builder/cfg.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'tcx> CFG<'tcx> {
4242
) {
4343
self.push(
4444
block,
45-
Statement { source_info, kind: StatementKind::Assign(Box::new((place, rvalue))) },
45+
Statement::new(source_info, StatementKind::Assign(Box::new((place, rvalue)))),
4646
);
4747
}
4848

@@ -88,7 +88,7 @@ impl<'tcx> CFG<'tcx> {
8888
place: Place<'tcx>,
8989
) {
9090
let kind = StatementKind::FakeRead(Box::new((cause, place)));
91-
let stmt = Statement { source_info, kind };
91+
let stmt = Statement::new(source_info, kind);
9292
self.push(block, stmt);
9393
}
9494

@@ -99,7 +99,7 @@ impl<'tcx> CFG<'tcx> {
9999
place: Place<'tcx>,
100100
) {
101101
let kind = StatementKind::PlaceMention(Box::new(place));
102-
let stmt = Statement { source_info, kind };
102+
let stmt = Statement::new(source_info, kind);
103103
self.push(block, stmt);
104104
}
105105

@@ -110,7 +110,7 @@ impl<'tcx> CFG<'tcx> {
110110
/// syntax (e.g. `continue` or `if !`) that would otherwise not appear in MIR.
111111
pub(crate) fn push_coverage_span_marker(&mut self, block: BasicBlock, source_info: SourceInfo) {
112112
let kind = StatementKind::Coverage(coverage::CoverageKind::SpanMarker);
113-
let stmt = Statement { source_info, kind };
113+
let stmt = Statement::new(source_info, kind);
114114
self.push(block, stmt);
115115
}
116116

compiler/rustc_mir_build/src/builder/coverageinfo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ impl BlockMarkerGen {
6161
block: BasicBlock,
6262
) -> BlockMarkerId {
6363
let id = self.next_block_marker_id();
64-
let marker_statement = mir::Statement {
64+
let marker_statement = mir::Statement::new(
6565
source_info,
66-
kind: mir::StatementKind::Coverage(CoverageKind::BlockMarker { id }),
67-
};
66+
mir::StatementKind::Coverage(CoverageKind::BlockMarker { id }),
67+
);
6868
cfg.push(block, marker_statement);
6969

7070
id

compiler/rustc_mir_build/src/builder/custom/parse.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,8 @@ impl<'a, 'tcx> ParseCtxt<'a, 'tcx> {
315315
let stmt = self.statement_as_expr(*stmt_id)?;
316316
let span = self.thir[stmt].span;
317317
let statement = self.parse_statement(stmt)?;
318-
data.statements.push(Statement {
319-
source_info: SourceInfo { span, scope: self.source_scope },
320-
kind: statement,
321-
});
318+
data.statements
319+
.push(Statement::new(SourceInfo { span, scope: self.source_scope }, statement));
322320
}
323321

324322
let Some(trailing) = block.expr else { return Err(self.expr_error(expr_id, "terminator")) };

compiler/rustc_mir_build/src/builder/expr/as_place.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,16 +489,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
489489
let place = place_builder.to_place(this);
490490
this.cfg.push(
491491
block,
492-
Statement {
493-
source_info: ty_source_info,
494-
kind: StatementKind::AscribeUserType(
492+
Statement::new(
493+
ty_source_info,
494+
StatementKind::AscribeUserType(
495495
Box::new((
496496
place,
497497
UserTypeProjection { base: annotation_index, projs: vec![] },
498498
)),
499499
Variance::Invariant,
500500
),
501-
},
501+
),
502502
);
503503
}
504504
block.and(place_builder)
@@ -518,16 +518,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
518518
});
519519
this.cfg.push(
520520
block,
521-
Statement {
522-
source_info: ty_source_info,
523-
kind: StatementKind::AscribeUserType(
521+
Statement::new(
522+
ty_source_info,
523+
StatementKind::AscribeUserType(
524524
Box::new((
525525
Place::from(temp),
526526
UserTypeProjection { base: annotation_index, projs: vec![] },
527527
)),
528528
Variance::Invariant,
529529
),
530-
},
530+
),
531531
);
532532
}
533533
block.and(PlaceBuilder::from(temp))

0 commit comments

Comments
 (0)