Skip to content

Commit 703dc9c

Browse files
committed
Auto merge of rust-lang#123416 - matthiaskrgr:rollup-j85wj05, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#123209 (Add section to sanitizer doc for `-Zexternal-clangrt`) - rust-lang#123342 (x.py test: remove no-op --skip flag) - rust-lang#123382 (Assert `FnDef` kind) - rust-lang#123386 (Set `CARGO` instead of `PATH` for Rust Clippy) - rust-lang#123393 (rustc_ast: Update `P<T>` docs to reflect mutable status.) - rust-lang#123394 (Postfix match fixes) - rust-lang#123412 (Output URLs of CI artifacts to GitHub summary) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ceab612 + 658c8f7 commit 703dc9c

File tree

20 files changed

+148
-69
lines changed

20 files changed

+148
-69
lines changed

Diff for: compiler/rustc_ast/src/ptr.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
//! The AST pointer.
22
//!
3-
//! Provides `P<T>`, a frozen owned smart pointer.
3+
//! Provides [`P<T>`][struct@P], an owned smart pointer.
44
//!
55
//! # Motivations and benefits
66
//!
77
//! * **Identity**: sharing AST nodes is problematic for the various analysis
88
//! passes (e.g., one may be able to bypass the borrow checker with a shared
99
//! `ExprKind::AddrOf` node taking a mutable borrow).
1010
//!
11-
//! * **Immutability**: `P<T>` disallows mutating its inner `T`, unlike `Box<T>`
12-
//! (unless it contains an `Unsafe` interior, but that may be denied later).
13-
//! This mainly prevents mistakes, but also enforces a kind of "purity".
14-
//!
1511
//! * **Efficiency**: folding can reuse allocation space for `P<T>` and `Vec<T>`,
1612
//! the latter even when the input and output types differ (as it would be the
1713
//! case with arenas or a GADT AST using type parameters to toggle features).
1814
//!
19-
//! * **Maintainability**: `P<T>` provides a fixed interface - `Deref`,
20-
//! `and_then` and `map` - which can remain fully functional even if the
21-
//! implementation changes (using a special thread-local heap, for example).
22-
//! Moreover, a switch to, e.g., `P<'a, T>` would be easy and mostly automated.
15+
//! * **Maintainability**: `P<T>` provides an interface, which can remain fully
16+
//! functional even if the implementation changes (using a special thread-local
17+
//! heap, for example). Moreover, a switch to, e.g., `P<'a, T>` would be easy
18+
//! and mostly automated.
2319
2420
use std::fmt::{self, Debug, Display};
2521
use std::ops::{Deref, DerefMut};
@@ -29,6 +25,8 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
2925

3026
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3127
/// An owned smart pointer.
28+
///
29+
/// See the [module level documentation][crate::ptr] for details.
3230
pub struct P<T: ?Sized> {
3331
ptr: Box<T>,
3432
}

Diff for: compiler/rustc_hir_analysis/src/collect/type_of.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
474474
VariantData::Unit(..) | VariantData::Struct { .. } => {
475475
tcx.type_of(tcx.hir().get_parent_item(hir_id)).instantiate_identity()
476476
}
477-
VariantData::Tuple(..) => {
477+
VariantData::Tuple(_, _, ctor) => {
478478
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
479-
Ty::new_fn_def(tcx, def_id.to_def_id(), args)
479+
Ty::new_fn_def(tcx, ctor.to_def_id(), args)
480480
}
481481
},
482482

Diff for: compiler/rustc_middle/src/thir.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
1212
use rustc_errors::{DiagArgValue, IntoDiagArg};
1313
use rustc_hir as hir;
1414
use rustc_hir::def_id::DefId;
15-
use rustc_hir::{BindingAnnotation, ByRef, RangeEnd};
15+
use rustc_hir::{BindingAnnotation, ByRef, MatchSource, RangeEnd};
1616
use rustc_index::newtype_index;
1717
use rustc_index::IndexVec;
1818
use rustc_middle::middle::region;
@@ -358,6 +358,7 @@ pub enum ExprKind<'tcx> {
358358
scrutinee: ExprId,
359359
scrutinee_hir_id: hir::HirId,
360360
arms: Box<[ArmId]>,
361+
match_source: MatchSource,
361362
},
362363
/// A block.
363364
Block {

Diff for: compiler/rustc_middle/src/ty/sty.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::ty::{
1111
};
1212
use crate::ty::{GenericArg, GenericArgs, GenericArgsRef};
1313
use crate::ty::{List, ParamEnv};
14-
use hir::def::DefKind;
14+
use hir::def::{CtorKind, DefKind};
1515
use rustc_data_structures::captures::Captures;
1616
use rustc_errors::{DiagArgValue, ErrorGuaranteed, IntoDiagArg, MultiSpan};
1717
use rustc_hir as hir;
@@ -1677,6 +1677,10 @@ impl<'tcx> Ty<'tcx> {
16771677
def_id: DefId,
16781678
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
16791679
) -> Ty<'tcx> {
1680+
debug_assert_matches!(
1681+
tcx.def_kind(def_id),
1682+
DefKind::AssocFn | DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn)
1683+
);
16801684
let args = tcx.check_and_mk_args(def_id, args);
16811685
Ty::new(tcx, FnDef(def_id, args))
16821686
}

Diff for: compiler/rustc_mir_build/src/errors.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,16 @@ pub enum UnusedUnsafeEnclosing {
456456

457457
pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'tcx, 'm> {
458458
pub cx: &'m RustcPatCtxt<'p, 'tcx>,
459-
pub expr_span: Span,
460-
pub span: Span,
459+
pub scrut_span: Span,
460+
pub braces_span: Option<Span>,
461461
pub ty: Ty<'tcx>,
462462
}
463463

464464
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> {
465465
fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'_, G> {
466466
let mut diag =
467467
Diag::new(dcx, level, fluent::mir_build_non_exhaustive_patterns_type_not_empty);
468-
diag.span(self.span);
468+
diag.span(self.scrut_span);
469469
diag.code(E0004);
470470
let peeled_ty = self.ty.peel_refs();
471471
diag.arg("ty", self.ty);
@@ -502,26 +502,19 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NonExhaustivePatternsTypeNo
502502
}
503503
}
504504

505-
let mut suggestion = None;
506505
let sm = self.cx.tcx.sess.source_map();
507-
if self.span.eq_ctxt(self.expr_span) {
506+
if let Some(braces_span) = self.braces_span {
508507
// Get the span for the empty match body `{}`.
509-
let (indentation, more) = if let Some(snippet) = sm.indentation_before(self.span) {
508+
let (indentation, more) = if let Some(snippet) = sm.indentation_before(self.scrut_span)
509+
{
510510
(format!("\n{snippet}"), " ")
511511
} else {
512512
(" ".to_string(), "")
513513
};
514-
suggestion = Some((
515-
self.span.shrink_to_hi().with_hi(self.expr_span.hi()),
516-
format!(" {{{indentation}{more}_ => todo!(),{indentation}}}",),
517-
));
518-
}
519-
520-
if let Some((span, sugg)) = suggestion {
521514
diag.span_suggestion_verbose(
522-
span,
515+
braces_span,
523516
fluent::mir_build_suggestion,
524-
sugg,
517+
format!(" {{{indentation}{more}_ => todo!(),{indentation}}}"),
525518
Applicability::HasPlaceholders,
526519
);
527520
} else {

Diff for: compiler/rustc_mir_build/src/thir/cx/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,11 @@ impl<'tcx> Cx<'tcx> {
716716
then: self.mirror_expr(then),
717717
else_opt: else_opt.map(|el| self.mirror_expr(el)),
718718
},
719-
hir::ExprKind::Match(discr, arms, _) => ExprKind::Match {
719+
hir::ExprKind::Match(discr, arms, match_source) => ExprKind::Match {
720720
scrutinee: self.mirror_expr(discr),
721721
scrutinee_hir_id: discr.hir_id,
722722
arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
723+
match_source,
723724
},
724725
hir::ExprKind::Loop(body, ..) => {
725726
let block_ty = self.typeck_results().node_type(body.hir_id);

Diff for: compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+41-16
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,8 @@ impl<'p, 'tcx> Visitor<'p, 'tcx> for MatchVisitor<'p, 'tcx> {
144144
});
145145
return;
146146
}
147-
ExprKind::Match { scrutinee, scrutinee_hir_id, box ref arms } => {
148-
let source = match ex.span.desugaring_kind() {
149-
Some(DesugaringKind::ForLoop) => hir::MatchSource::ForLoopDesugar,
150-
Some(DesugaringKind::QuestionMark) => {
151-
hir::MatchSource::TryDesugar(scrutinee_hir_id)
152-
}
153-
Some(DesugaringKind::Await) => hir::MatchSource::AwaitDesugar,
154-
_ => hir::MatchSource::Normal,
155-
};
156-
self.check_match(scrutinee, arms, source, ex.span);
147+
ExprKind::Match { scrutinee, scrutinee_hir_id: _, box ref arms, match_source } => {
148+
self.check_match(scrutinee, arms, match_source, ex.span);
157149
}
158150
ExprKind::Let { box ref pat, expr } => {
159151
self.check_let(pat, Some(expr), ex.span);
@@ -505,8 +497,41 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
505497
None,
506498
);
507499
} else {
500+
// span after scrutinee, or after `.match`. That is, the braces, arms,
501+
// and any whitespace preceding the braces.
502+
let braces_span = match source {
503+
hir::MatchSource::Normal => scrut
504+
.span
505+
.find_ancestor_in_same_ctxt(expr_span)
506+
.map(|scrut_span| scrut_span.shrink_to_hi().with_hi(expr_span.hi())),
507+
hir::MatchSource::Postfix => {
508+
// This is horrendous, and we should deal with it by just
509+
// stashing the span of the braces somewhere (like in the match source).
510+
scrut.span.find_ancestor_in_same_ctxt(expr_span).and_then(|scrut_span| {
511+
let sm = self.tcx.sess.source_map();
512+
let brace_span = sm.span_extend_to_next_char(scrut_span, '{', true);
513+
if sm.span_to_snippet(sm.next_point(brace_span)).as_deref() == Ok("{") {
514+
let sp = brace_span.shrink_to_hi().with_hi(expr_span.hi());
515+
// We also need to extend backwards for whitespace
516+
sm.span_extend_prev_while(sp, |c| c.is_whitespace()).ok()
517+
} else {
518+
None
519+
}
520+
})
521+
}
522+
hir::MatchSource::ForLoopDesugar
523+
| hir::MatchSource::TryDesugar(_)
524+
| hir::MatchSource::AwaitDesugar
525+
| hir::MatchSource::FormatArgs => None,
526+
};
508527
self.error = Err(report_non_exhaustive_match(
509-
&cx, self.thir, scrut.ty, scrut.span, witnesses, arms, expr_span,
528+
&cx,
529+
self.thir,
530+
scrut.ty,
531+
scrut.span,
532+
witnesses,
533+
arms,
534+
braces_span,
510535
));
511536
}
512537
}
@@ -929,7 +954,7 @@ fn report_non_exhaustive_match<'p, 'tcx>(
929954
sp: Span,
930955
witnesses: Vec<WitnessPat<'p, 'tcx>>,
931956
arms: &[ArmId],
932-
expr_span: Span,
957+
braces_span: Option<Span>,
933958
) -> ErrorGuaranteed {
934959
let is_empty_match = arms.is_empty();
935960
let non_empty_enum = match scrut_ty.kind() {
@@ -941,8 +966,8 @@ fn report_non_exhaustive_match<'p, 'tcx>(
941966
if is_empty_match && !non_empty_enum {
942967
return cx.tcx.dcx().emit_err(NonExhaustivePatternsTypeNotEmpty {
943968
cx,
944-
expr_span,
945-
span: sp,
969+
scrut_span: sp,
970+
braces_span,
946971
ty: scrut_ty,
947972
});
948973
}
@@ -1028,15 +1053,15 @@ fn report_non_exhaustive_match<'p, 'tcx>(
10281053
let mut suggestion = None;
10291054
let sm = cx.tcx.sess.source_map();
10301055
match arms {
1031-
[] if sp.eq_ctxt(expr_span) => {
1056+
[] if let Some(braces_span) = braces_span => {
10321057
// Get the span for the empty match body `{}`.
10331058
let (indentation, more) = if let Some(snippet) = sm.indentation_before(sp) {
10341059
(format!("\n{snippet}"), " ")
10351060
} else {
10361061
(" ".to_string(), "")
10371062
};
10381063
suggestion = Some((
1039-
sp.shrink_to_hi().with_hi(expr_span.hi()),
1064+
braces_span,
10401065
format!(" {{{indentation}{more}{suggested_arm},{indentation}}}",),
10411066
));
10421067
}

Diff for: compiler/rustc_parse/src/parser/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ impl<'a> Parser<'a> {
860860
ExprKind::MethodCall(_) => "a method call",
861861
ExprKind::Call(_, _) => "a function call",
862862
ExprKind::Await(_, _) => "`.await`",
863+
ExprKind::Match(_, _, MatchKind::Postfix) => "a postfix match",
863864
ExprKind::Err(_) => return Ok(with_postfix),
864865
_ => unreachable!("parse_dot_or_call_expr_with_ shouldn't produce this"),
865866
}

Diff for: src/bootstrap/src/core/builder.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -1194,20 +1194,11 @@ impl<'a> Builder<'a> {
11941194
}
11951195

11961196
pub fn cargo_clippy_cmd(&self, run_compiler: Compiler) -> Command {
1197-
let initial_sysroot_bin = self.initial_rustc.parent().unwrap();
1198-
// Set PATH to include the sysroot bin dir so clippy can find cargo.
1199-
// FIXME: once rust-clippy#11944 lands on beta, set `CARGO` directly instead.
1200-
let path = t!(env::join_paths(
1201-
// The sysroot comes first in PATH to avoid using rustup's cargo.
1202-
std::iter::once(PathBuf::from(initial_sysroot_bin))
1203-
.chain(env::split_paths(&t!(env::var("PATH"))))
1204-
));
1205-
12061197
if run_compiler.stage == 0 {
12071198
// `ensure(Clippy { stage: 0 })` *builds* clippy with stage0, it doesn't use the beta clippy.
12081199
let cargo_clippy = self.build.config.download_clippy();
12091200
let mut cmd = Command::new(cargo_clippy);
1210-
cmd.env("PATH", &path);
1201+
cmd.env("CARGO", &self.initial_cargo);
12111202
return cmd;
12121203
}
12131204

@@ -1227,7 +1218,7 @@ impl<'a> Builder<'a> {
12271218

12281219
let mut cmd = Command::new(cargo_clippy);
12291220
cmd.env(helpers::dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1230-
cmd.env("PATH", path);
1221+
cmd.env("CARGO", &self.initial_cargo);
12311222
cmd
12321223
}
12331224

Diff for: src/bootstrap/src/core/builder/tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ mod dist {
599599
pass: None,
600600
run: None,
601601
only_modified: false,
602-
skip: vec![],
603602
extra_checks: None,
604603
};
605604

@@ -664,7 +663,6 @@ mod dist {
664663
no_fail_fast: false,
665664
doc: true,
666665
no_doc: false,
667-
skip: vec![],
668666
bless: false,
669667
force_rerun: false,
670668
compare_mode: None,

Diff for: src/bootstrap/src/core/config/flags.rs

-3
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,6 @@ pub enum Subcommand {
339339
#[arg(long)]
340340
/// run all tests regardless of failure
341341
no_fail_fast: bool,
342-
#[arg(long, value_name = "SUBSTRING")]
343-
/// skips tests matching SUBSTRING, if supported by test tool. May be passed multiple times
344-
skip: Vec<PathBuf>,
345342
#[arg(long, value_name = "ARGS", allow_hyphen_values(true))]
346343
/// extra arguments to be passed for the test tool being used
347344
/// (e.g. libtest, compiletest or rustdoc)

Diff for: src/ci/scripts/upload-artifacts.sh

+14
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,17 @@ deploy_url="s3://${DEPLOY_BUCKET}/${deploy_dir}/$(ciCommit)"
4545

4646
retry aws s3 cp --storage-class INTELLIGENT_TIERING \
4747
--no-progress --recursive --acl public-read "${upload_dir}" "${deploy_url}"
48+
49+
access_url="https://ci-artifacts.rust-lang.org/${deploy_dir}/$(ciCommit)"
50+
51+
# Output URLs to the uploaded artifacts to GitHub summary (if it is available)
52+
# to make them easily accessible.
53+
if [ -n "${GITHUB_STEP_SUMMARY}" ]
54+
then
55+
echo "# CI artifacts" >> "${GITHUB_STEP_SUMMARY}"
56+
57+
for filename in "${upload_dir}"/*.xz; do
58+
filename=`basename "${filename}"`
59+
echo "- [${filename}](${access_url}/${filename})" >> "${GITHUB_STEP_SUMMARY}"
60+
done
61+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# `external-clangrt`
2+
3+
This option controls whether the compiler links in its own runtime library for
4+
[sanitizers](./sanitizer.md). Passing this flag makes the compiler *not* link
5+
its own library. For more information, see the section in the sanitizers doc on
6+
[working with other languages.](./sanitizer.md#working-with-other-languages)

Diff for: src/doc/unstable-book/src/compiler-flags/sanitizer.md

+15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ To enable a sanitizer compile with `-Zsanitizer=address`, `-Zsanitizer=cfi`,
4545
`-Zsanitizer=dataflow`,`-Zsanitizer=hwaddress`, `-Zsanitizer=leak`,
4646
`-Zsanitizer=memory`, `-Zsanitizer=memtag`, `-Zsanitizer=shadow-call-stack`, or
4747
`-Zsanitizer=thread`. You might also need the `--target` and `build-std` flags.
48+
If you're working with other languages that are also instrumented with sanitizers,
49+
you might need the `external-clangrt` flag. See the section on
50+
[working with other languages](#working-with-other-languages).
4851

4952
Example:
5053
```shell
@@ -853,6 +856,18 @@ functionality][build-std].
853856
854857
[build-std]: ../../cargo/reference/unstable.html#build-std
855858
859+
# Working with other languages
860+
861+
Sanitizers rely on compiler runtime libraries to function properly. Rust links
862+
in its own compiler runtime which might conflict with runtimes required by
863+
languages such as C++. Since Rust's runtime doesn't always contain the symbols
864+
required by C++ instrumented code, you might need to skip linking it so another
865+
runtime can be linked instead.
866+
867+
A separate unstable option `-Zexternal-clangrt` can be used to make rustc skip
868+
linking the compiler runtime for the sanitizer. This will require you to link
869+
in an external runtime, such as from clang instead.
870+
856871
# Build scripts and procedural macros
857872
858873
Use of sanitizers together with build scripts and procedural macros is

Diff for: src/etc/completions/x.py.fish

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ complete -c x.py -n "__fish_seen_subcommand_from doc" -l llvm-profile-generate -
261261
complete -c x.py -n "__fish_seen_subcommand_from doc" -l enable-bolt-settings -d 'Enable BOLT link flags'
262262
complete -c x.py -n "__fish_seen_subcommand_from doc" -l skip-stage0-validation -d 'Skip stage0 compiler validation'
263263
complete -c x.py -n "__fish_seen_subcommand_from doc" -s h -l help -d 'Print help (see more with \'--help\')'
264-
complete -c x.py -n "__fish_seen_subcommand_from test" -l skip -d 'skips tests matching SUBSTRING, if supported by test tool. May be passed multiple times' -r -F
265264
complete -c x.py -n "__fish_seen_subcommand_from test" -l test-args -d 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)' -r
266265
complete -c x.py -n "__fish_seen_subcommand_from test" -l rustc-args -d 'extra options to pass the compiler when running tests' -r
267266
complete -c x.py -n "__fish_seen_subcommand_from test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell)' -r
@@ -274,6 +273,7 @@ complete -c x.py -n "__fish_seen_subcommand_from test" -l build -d 'build target
274273
complete -c x.py -n "__fish_seen_subcommand_from test" -l host -d 'host targets to build' -r -f
275274
complete -c x.py -n "__fish_seen_subcommand_from test" -l target -d 'target targets to build' -r -f
276275
complete -c x.py -n "__fish_seen_subcommand_from test" -l exclude -d 'build paths to exclude' -r -F
276+
complete -c x.py -n "__fish_seen_subcommand_from test" -l skip -d 'build paths to skip' -r -F
277277
complete -c x.py -n "__fish_seen_subcommand_from test" -l rustc-error-format -r -f
278278
complete -c x.py -n "__fish_seen_subcommand_from test" -l on-fail -d 'command to run on failure' -r -f -a "(__fish_complete_command)"
279279
complete -c x.py -n "__fish_seen_subcommand_from test" -l stage -d 'stage to build (indicates compiler to use/test, e.g., stage 0 uses the bootstrap compiler, stage 1 the stage 0 rustc artifacts, etc.)' -r -f

0 commit comments

Comments
 (0)