Skip to content

Commit 10706d6

Browse files
committed
Auto merge of rust-lang#101295 - matthiaskrgr:rollup-046o38p, r=matthiaskrgr
Rollup of 14 pull requests Successful merges: - rust-lang#94467 (Add `special_module_name` lint) - rust-lang#100852 (Use `getuid` to check instead of `USER` env var in rustbuild) - rust-lang#101072 (bootstrap: Add llvm-has-rust-patches target option) - rust-lang#101190 (Make docs formulation more consistent for NonZero{int}) - rust-lang#101245 (Remove unneeded where whitespace) - rust-lang#101251 (Fix bad target name in Walkthrough) - rust-lang#101254 (rustdoc: remove unused `.docblock .impl-items` CSS) - rust-lang#101256 (Fixes/adjustments to Fuchsia doc walkthrough) - rust-lang#101270 (Update outdated comment about output capturing in print_to.) - rust-lang#101271 (Fix filename of armv4t-none-eabi.md) - rust-lang#101274 (Fix typo in comment) - rust-lang#101279 (Fix doc_auto_cfg for impl blocks in different modules with different `cfg`) - rust-lang#101285 (Do not suggest adding `move` to closure when `move` is already used) - rust-lang#101292 (rustdoc: remove unneeded CSS `.content table td:first-child > a`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2e35f95 + 1c12ded commit 10706d6

Some content is hidden

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

50 files changed

+412
-136
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ no_llvm_build
4646
/dist/
4747
/unicode-downloads
4848
/target
49+
/src/bootstrap/target
4950
/src/tools/x/target
5051
# Created by default with `src/ci/docker/run.sh`
5152
/obj/

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
902902
hir::ExprKind::MethodCall(.., args, _) => {
903903
// only the first closre parameter of the method. args[0] is MethodCall PathSegment
904904
for i in 1..args.len() {
905-
if let hir::ExprKind::Closure(..) = args[i].kind {
905+
if let hir::ExprKind::Closure(hir::Closure {
906+
capture_clause: hir::CaptureBy::Ref,
907+
..
908+
}) = args[i].kind
909+
{
906910
closure_span = Some(args[i].span.shrink_to_lo());
907911
break;
908912
}
@@ -911,7 +915,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
911915
hir::ExprKind::Block(blk, _) => {
912916
if let Some(ref expr) = blk.expr {
913917
// only when the block is a closure
914-
if let hir::ExprKind::Closure(..) = expr.kind {
918+
if let hir::ExprKind::Closure(hir::Closure {
919+
capture_clause: hir::CaptureBy::Ref,
920+
..
921+
}) = expr.kind
922+
{
915923
closure_span = Some(expr.span.shrink_to_lo());
916924
}
917925
}
@@ -921,7 +929,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
921929
if let Some(closure_span) = closure_span {
922930
diag.span_suggestion_verbose(
923931
closure_span,
924-
format!("consider adding 'move' keyword before the nested closure"),
932+
"consider adding 'move' keyword before the nested closure",
925933
"move ",
926934
Applicability::MaybeIncorrect,
927935
);

compiler/rustc_lint/src/builtin.rs

+78
Original file line numberDiff line numberDiff line change
@@ -3172,3 +3172,81 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
31723172
}
31733173
}
31743174
}
3175+
3176+
declare_lint! {
3177+
/// The `special_module_name` lint detects module
3178+
/// declarations for files that have a special meaning.
3179+
///
3180+
/// ### Example
3181+
///
3182+
/// ```rust,compile_fail
3183+
/// mod lib;
3184+
///
3185+
/// fn main() {
3186+
/// lib::run();
3187+
/// }
3188+
/// ```
3189+
///
3190+
/// {{produces}}
3191+
///
3192+
/// ### Explanation
3193+
///
3194+
/// Cargo recognizes `lib.rs` and `main.rs` as the root of a
3195+
/// library or binary crate, so declaring them as modules
3196+
/// will lead to miscompilation of the crate unless configured
3197+
/// explicitly.
3198+
///
3199+
/// To access a library from a binary target within the same crate,
3200+
/// use `your_crate_name::` as the path path instead of `lib::`:
3201+
///
3202+
/// ```rust,compile_fail
3203+
/// // bar/src/lib.rs
3204+
/// fn run() {
3205+
/// // ...
3206+
/// }
3207+
///
3208+
/// // bar/src/main.rs
3209+
/// fn main() {
3210+
/// bar::run();
3211+
/// }
3212+
/// ```
3213+
///
3214+
/// Binary targets cannot be used as libraries and so declaring
3215+
/// one as a module is not allowed.
3216+
pub SPECIAL_MODULE_NAME,
3217+
Warn,
3218+
"module declarations for files with a special meaning",
3219+
}
3220+
3221+
declare_lint_pass!(SpecialModuleName => [SPECIAL_MODULE_NAME]);
3222+
3223+
impl EarlyLintPass for SpecialModuleName {
3224+
fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &ast::Crate) {
3225+
for item in &krate.items {
3226+
if let ast::ItemKind::Mod(
3227+
_,
3228+
ast::ModKind::Unloaded | ast::ModKind::Loaded(_, ast::Inline::No, _),
3229+
) = item.kind
3230+
{
3231+
if item.attrs.iter().any(|a| a.has_name(sym::path)) {
3232+
continue;
3233+
}
3234+
3235+
match item.ident.name.as_str() {
3236+
"lib" => cx.struct_span_lint(SPECIAL_MODULE_NAME, item.span, |lint| {
3237+
lint.build("found module declaration for lib.rs")
3238+
.note("lib.rs is the root of this crate's library target")
3239+
.help("to refer to it from other targets, use the library's name as the path")
3240+
.emit()
3241+
}),
3242+
"main" => cx.struct_span_lint(SPECIAL_MODULE_NAME, item.span, |lint| {
3243+
lint.build("found module declaration for main.rs")
3244+
.note("a binary crate cannot be used as library")
3245+
.emit()
3246+
}),
3247+
_ => continue
3248+
}
3249+
}
3250+
}
3251+
}
3252+
}

compiler/rustc_lint/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ macro_rules! early_lint_passes {
133133
UnusedBraces: UnusedBraces,
134134
UnusedImportBraces: UnusedImportBraces,
135135
UnsafeCode: UnsafeCode,
136+
SpecialModuleName: SpecialModuleName,
136137
AnonymousParameters: AnonymousParameters,
137138
EllipsisInclusiveRangePatterns: EllipsisInclusiveRangePatterns::default(),
138139
NonCamelCaseTypes: NonCamelCaseTypes,

config.toml.example

+4
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ changelog-seen = 2
666666
# target.
667667
#llvm-config = <none> (path)
668668

669+
# Override detection of whether this is a Rust-patched LLVM. This would be used
670+
# in conjunction with either an llvm-config or build.submodules = false.
671+
#llvm-has-rust-patches = if llvm-config { false } else { true }
672+
669673
# Normally the build system can find LLVM's FileCheck utility, but if
670674
# not, you can specify an explicit file name for it.
671675
#llvm-filecheck = "/path/to/llvm-version/bin/FileCheck"

library/core/src/num/nonzero.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ macro_rules! nonzero_unsigned_operations {
309309
( $( $Ty: ident($Int: ident); )+ ) => {
310310
$(
311311
impl $Ty {
312-
/// Add an unsigned integer to a non-zero value.
313-
/// Check for overflow and return [`None`] on overflow
312+
/// Adds an unsigned integer to a non-zero value.
313+
/// Checks for overflow and returns [`None`] on overflow.
314314
/// As a consequence, the result cannot wrap to zero.
315315
///
316316
///
@@ -346,7 +346,7 @@ macro_rules! nonzero_unsigned_operations {
346346
}
347347
}
348348

349-
/// Add an unsigned integer to a non-zero value.
349+
/// Adds an unsigned integer to a non-zero value.
350350
#[doc = concat!("Return [`", stringify!($Int), "::MAX`] on overflow.")]
351351
///
352352
/// # Examples
@@ -377,7 +377,7 @@ macro_rules! nonzero_unsigned_operations {
377377
unsafe { $Ty::new_unchecked(self.get().saturating_add(other)) }
378378
}
379379

380-
/// Add an unsigned integer to a non-zero value,
380+
/// Adds an unsigned integer to a non-zero value,
381381
/// assuming overflow cannot occur.
382382
/// Overflow is unchecked, and it is undefined behaviour to overflow
383383
/// *even if the result would wrap to a non-zero value*.
@@ -409,7 +409,7 @@ macro_rules! nonzero_unsigned_operations {
409409
}
410410

411411
/// Returns the smallest power of two greater than or equal to n.
412-
/// Check for overflow and return [`None`]
412+
/// Checks for overflow and returns [`None`]
413413
/// if the next power of two is greater than the type’s maximum value.
414414
/// As a consequence, the result cannot wrap to zero.
415415
///
@@ -545,7 +545,7 @@ macro_rules! nonzero_signed_operations {
545545
}
546546

547547
/// Checked absolute value.
548-
/// Check for overflow and returns [`None`] if
548+
/// Checks for overflow and returns [`None`] if
549549
#[doc = concat!("`self == ", stringify!($Int), "::MIN`.")]
550550
/// The result cannot be zero.
551551
///
@@ -740,8 +740,8 @@ macro_rules! nonzero_unsigned_signed_operations {
740740
( $( $signedness:ident $Ty: ident($Int: ty); )+ ) => {
741741
$(
742742
impl $Ty {
743-
/// Multiply two non-zero integers together.
744-
/// Check for overflow and return [`None`] on overflow.
743+
/// Multiplies two non-zero integers together.
744+
/// Checks for overflow and returns [`None`] on overflow.
745745
/// As a consequence, the result cannot wrap to zero.
746746
///
747747
/// # Examples
@@ -777,7 +777,7 @@ macro_rules! nonzero_unsigned_signed_operations {
777777
}
778778
}
779779

780-
/// Multiply two non-zero integers together.
780+
/// Multiplies two non-zero integers together.
781781
#[doc = concat!("Return [`", stringify!($Int), "::MAX`] on overflow.")]
782782
///
783783
/// # Examples
@@ -809,7 +809,7 @@ macro_rules! nonzero_unsigned_signed_operations {
809809
unsafe { $Ty::new_unchecked(self.get().saturating_mul(other.get())) }
810810
}
811811

812-
/// Multiply two non-zero integers together,
812+
/// Multiplies two non-zero integers together,
813813
/// assuming overflow cannot occur.
814814
/// Overflow is unchecked, and it is undefined behaviour to overflow
815815
/// *even if the result would wrap to a non-zero value*.
@@ -849,8 +849,8 @@ macro_rules! nonzero_unsigned_signed_operations {
849849
unsafe { $Ty::new_unchecked(self.get().unchecked_mul(other.get())) }
850850
}
851851

852-
/// Raise non-zero value to an integer power.
853-
/// Check for overflow and return [`None`] on overflow.
852+
/// Raises non-zero value to an integer power.
853+
/// Checks for overflow and returns [`None`] on overflow.
854854
/// As a consequence, the result cannot wrap to zero.
855855
///
856856
/// # Examples

library/std/src/io/stdio.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -986,10 +986,10 @@ pub fn set_output_capture(sink: Option<LocalStream>) -> Option<LocalStream> {
986986
/// otherwise. `label` identifies the stream in a panic message.
987987
///
988988
/// This function is used to print error messages, so it takes extra
989-
/// care to avoid causing a panic when `local_s` is unusable.
990-
/// For instance, if the TLS key for the local stream is
991-
/// already destroyed, or if the local stream is locked by another
992-
/// thread, it will just fall back to the global stream.
989+
/// care to avoid causing a panic when `OUTPUT_CAPTURE` is unusable.
990+
/// For instance, if the TLS key for output capturing is already destroyed, or
991+
/// if the local stream is in use by another thread, it will just fall back to
992+
/// the global stream.
993993
///
994994
/// However, if the actual I/O causes an error, this function does panic.
995995
fn print_to<T>(args: fmt::Arguments<'_>, global_s: fn() -> T, label: &str)

src/bootstrap/bootstrap.py

+2
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,8 @@ def set_dist_environment(self, url):
793793

794794
def check_vendored_status(self):
795795
"""Check that vendoring is configured properly"""
796+
# keep this consistent with the equivalent check in rustbuild:
797+
# https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/lib.rs#L399-L405
796798
if 'SUDO_USER' in os.environ and not self.use_vendored_sources:
797799
if os.getuid() == 0:
798800
self.use_vendored_sources = True

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ impl PartialEq<&str> for TargetSelection {
388388
pub struct Target {
389389
/// Some(path to llvm-config) if using an external LLVM.
390390
pub llvm_config: Option<PathBuf>,
391+
pub llvm_has_rust_patches: Option<bool>,
391392
/// Some(path to FileCheck) if one was specified.
392393
pub llvm_filecheck: Option<PathBuf>,
393394
pub llvm_libunwind: Option<LlvmLibunwind>,
@@ -733,6 +734,7 @@ define_config! {
733734
default_linker: Option<PathBuf> = "default-linker",
734735
linker: Option<String> = "linker",
735736
llvm_config: Option<String> = "llvm-config",
737+
llvm_has_rust_patches: Option<bool> = "llvm-has-rust-patches",
736738
llvm_filecheck: Option<String> = "llvm-filecheck",
737739
llvm_libunwind: Option<String> = "llvm-libunwind",
738740
android_ndk: Option<String> = "android-ndk",
@@ -1109,6 +1111,7 @@ impl Config {
11091111
if let Some(ref s) = cfg.llvm_config {
11101112
target.llvm_config = Some(config.src.join(s));
11111113
}
1114+
target.llvm_has_rust_patches = cfg.llvm_has_rust_patches;
11121115
if let Some(ref s) = cfg.llvm_filecheck {
11131116
target.llvm_filecheck = Some(config.src.join(s));
11141117
}

src/bootstrap/lib.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ use std::path::{Path, PathBuf};
112112
use std::process::Command;
113113
use std::str;
114114

115+
use config::Target;
115116
use filetime::FileTime;
116117
use once_cell::sync::OnceCell;
117118

@@ -395,13 +396,18 @@ impl Build {
395396
let src = config.src.clone();
396397
let out = config.out.clone();
397398

399+
#[cfg(unix)]
400+
// keep this consistent with the equivalent check in x.py:
401+
// https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/bootstrap.py#L796-L797
398402
let is_sudo = match env::var_os("SUDO_USER") {
399-
Some(sudo_user) => match env::var_os("USER") {
400-
Some(user) => user != sudo_user,
401-
None => false,
402-
},
403+
Some(_sudo_user) => {
404+
let uid = unsafe { libc::getuid() };
405+
uid == 0
406+
}
403407
None => false,
404408
};
409+
#[cfg(not(unix))]
410+
let is_sudo = false;
405411

406412
let ignore_git = config.ignore_git;
407413
let rust_info = channel::GitInfo::new(ignore_git, &src);
@@ -834,12 +840,13 @@ impl Build {
834840
///
835841
/// If no custom `llvm-config` was specified then Rust's llvm will be used.
836842
fn is_rust_llvm(&self, target: TargetSelection) -> bool {
837-
if self.config.llvm_from_ci && target == self.config.build {
838-
return true;
839-
}
840-
841843
match self.config.target_config.get(&target) {
842-
Some(ref c) => c.llvm_config.is_none(),
844+
Some(Target { llvm_has_rust_patches: Some(patched), .. }) => *patched,
845+
Some(Target { llvm_config, .. }) => {
846+
// If the user set llvm-config we assume Rust is not patched,
847+
// but first check to see if it was configured by llvm-from-ci.
848+
(self.config.llvm_from_ci && target == self.config.build) || llvm_config.is_none()
849+
}
843850
None => true,
844851
}
845852
}

0 commit comments

Comments
 (0)