Skip to content

Commit

Permalink
Auto merge of rust-lang#101295 - matthiaskrgr:rollup-046o38p, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed Sep 1, 2022
2 parents 2e35f95 + 1c12ded commit 10706d6
Show file tree
Hide file tree
Showing 50 changed files with 412 additions and 136 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ no_llvm_build
/dist/
/unicode-downloads
/target
/src/bootstrap/target
/src/tools/x/target
# Created by default with `src/ci/docker/run.sh`
/obj/
Expand Down
14 changes: 11 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
hir::ExprKind::MethodCall(.., args, _) => {
// only the first closre parameter of the method. args[0] is MethodCall PathSegment
for i in 1..args.len() {
if let hir::ExprKind::Closure(..) = args[i].kind {
if let hir::ExprKind::Closure(hir::Closure {
capture_clause: hir::CaptureBy::Ref,
..
}) = args[i].kind
{
closure_span = Some(args[i].span.shrink_to_lo());
break;
}
Expand All @@ -911,7 +915,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
hir::ExprKind::Block(blk, _) => {
if let Some(ref expr) = blk.expr {
// only when the block is a closure
if let hir::ExprKind::Closure(..) = expr.kind {
if let hir::ExprKind::Closure(hir::Closure {
capture_clause: hir::CaptureBy::Ref,
..
}) = expr.kind
{
closure_span = Some(expr.span.shrink_to_lo());
}
}
Expand All @@ -921,7 +929,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if let Some(closure_span) = closure_span {
diag.span_suggestion_verbose(
closure_span,
format!("consider adding 'move' keyword before the nested closure"),
"consider adding 'move' keyword before the nested closure",
"move ",
Applicability::MaybeIncorrect,
);
Expand Down
78 changes: 78 additions & 0 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3172,3 +3172,81 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
}
}
}

declare_lint! {
/// The `special_module_name` lint detects module
/// declarations for files that have a special meaning.
///
/// ### Example
///
/// ```rust,compile_fail
/// mod lib;
///
/// fn main() {
/// lib::run();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Cargo recognizes `lib.rs` and `main.rs` as the root of a
/// library or binary crate, so declaring them as modules
/// will lead to miscompilation of the crate unless configured
/// explicitly.
///
/// To access a library from a binary target within the same crate,
/// use `your_crate_name::` as the path path instead of `lib::`:
///
/// ```rust,compile_fail
/// // bar/src/lib.rs
/// fn run() {
/// // ...
/// }
///
/// // bar/src/main.rs
/// fn main() {
/// bar::run();
/// }
/// ```
///
/// Binary targets cannot be used as libraries and so declaring
/// one as a module is not allowed.
pub SPECIAL_MODULE_NAME,
Warn,
"module declarations for files with a special meaning",
}

declare_lint_pass!(SpecialModuleName => [SPECIAL_MODULE_NAME]);

impl EarlyLintPass for SpecialModuleName {
fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &ast::Crate) {
for item in &krate.items {
if let ast::ItemKind::Mod(
_,
ast::ModKind::Unloaded | ast::ModKind::Loaded(_, ast::Inline::No, _),
) = item.kind
{
if item.attrs.iter().any(|a| a.has_name(sym::path)) {
continue;
}

match item.ident.name.as_str() {
"lib" => cx.struct_span_lint(SPECIAL_MODULE_NAME, item.span, |lint| {
lint.build("found module declaration for lib.rs")
.note("lib.rs is the root of this crate's library target")
.help("to refer to it from other targets, use the library's name as the path")
.emit()
}),
"main" => cx.struct_span_lint(SPECIAL_MODULE_NAME, item.span, |lint| {
lint.build("found module declaration for main.rs")
.note("a binary crate cannot be used as library")
.emit()
}),
_ => continue
}
}
}
}
}
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ macro_rules! early_lint_passes {
UnusedBraces: UnusedBraces,
UnusedImportBraces: UnusedImportBraces,
UnsafeCode: UnsafeCode,
SpecialModuleName: SpecialModuleName,
AnonymousParameters: AnonymousParameters,
EllipsisInclusiveRangePatterns: EllipsisInclusiveRangePatterns::default(),
NonCamelCaseTypes: NonCamelCaseTypes,
Expand Down
4 changes: 4 additions & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ changelog-seen = 2
# target.
#llvm-config = <none> (path)

# Override detection of whether this is a Rust-patched LLVM. This would be used
# in conjunction with either an llvm-config or build.submodules = false.
#llvm-has-rust-patches = if llvm-config { false } else { true }

# Normally the build system can find LLVM's FileCheck utility, but if
# not, you can specify an explicit file name for it.
#llvm-filecheck = "/path/to/llvm-version/bin/FileCheck"
Expand Down
24 changes: 12 additions & 12 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ macro_rules! nonzero_unsigned_operations {
( $( $Ty: ident($Int: ident); )+ ) => {
$(
impl $Ty {
/// Add an unsigned integer to a non-zero value.
/// Check for overflow and return [`None`] on overflow
/// Adds an unsigned integer to a non-zero value.
/// Checks for overflow and returns [`None`] on overflow.
/// As a consequence, the result cannot wrap to zero.
///
///
Expand Down Expand Up @@ -346,7 +346,7 @@ macro_rules! nonzero_unsigned_operations {
}
}

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

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

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

/// Checked absolute value.
/// Check for overflow and returns [`None`] if
/// Checks for overflow and returns [`None`] if
#[doc = concat!("`self == ", stringify!($Int), "::MIN`.")]
/// The result cannot be zero.
///
Expand Down Expand Up @@ -740,8 +740,8 @@ macro_rules! nonzero_unsigned_signed_operations {
( $( $signedness:ident $Ty: ident($Int: ty); )+ ) => {
$(
impl $Ty {
/// Multiply two non-zero integers together.
/// Check for overflow and return [`None`] on overflow.
/// Multiplies two non-zero integers together.
/// Checks for overflow and returns [`None`] on overflow.
/// As a consequence, the result cannot wrap to zero.
///
/// # Examples
Expand Down Expand Up @@ -777,7 +777,7 @@ macro_rules! nonzero_unsigned_signed_operations {
}
}

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

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

/// Raise non-zero value to an integer power.
/// Check for overflow and return [`None`] on overflow.
/// Raises non-zero value to an integer power.
/// Checks for overflow and returns [`None`] on overflow.
/// As a consequence, the result cannot wrap to zero.
///
/// # Examples
Expand Down
8 changes: 4 additions & 4 deletions library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,10 +986,10 @@ pub fn set_output_capture(sink: Option<LocalStream>) -> Option<LocalStream> {
/// otherwise. `label` identifies the stream in a panic message.
///
/// This function is used to print error messages, so it takes extra
/// care to avoid causing a panic when `local_s` is unusable.
/// For instance, if the TLS key for the local stream is
/// already destroyed, or if the local stream is locked by another
/// thread, it will just fall back to the global stream.
/// care to avoid causing a panic when `OUTPUT_CAPTURE` is unusable.
/// For instance, if the TLS key for output capturing is already destroyed, or
/// if the local stream is in use by another thread, it will just fall back to
/// the global stream.
///
/// However, if the actual I/O causes an error, this function does panic.
fn print_to<T>(args: fmt::Arguments<'_>, global_s: fn() -> T, label: &str)
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,8 @@ def set_dist_environment(self, url):

def check_vendored_status(self):
"""Check that vendoring is configured properly"""
# keep this consistent with the equivalent check in rustbuild:
# https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/lib.rs#L399-L405
if 'SUDO_USER' in os.environ and not self.use_vendored_sources:
if os.getuid() == 0:
self.use_vendored_sources = True
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ impl PartialEq<&str> for TargetSelection {
pub struct Target {
/// Some(path to llvm-config) if using an external LLVM.
pub llvm_config: Option<PathBuf>,
pub llvm_has_rust_patches: Option<bool>,
/// Some(path to FileCheck) if one was specified.
pub llvm_filecheck: Option<PathBuf>,
pub llvm_libunwind: Option<LlvmLibunwind>,
Expand Down Expand Up @@ -733,6 +734,7 @@ define_config! {
default_linker: Option<PathBuf> = "default-linker",
linker: Option<String> = "linker",
llvm_config: Option<String> = "llvm-config",
llvm_has_rust_patches: Option<bool> = "llvm-has-rust-patches",
llvm_filecheck: Option<String> = "llvm-filecheck",
llvm_libunwind: Option<String> = "llvm-libunwind",
android_ndk: Option<String> = "android-ndk",
Expand Down Expand Up @@ -1109,6 +1111,7 @@ impl Config {
if let Some(ref s) = cfg.llvm_config {
target.llvm_config = Some(config.src.join(s));
}
target.llvm_has_rust_patches = cfg.llvm_has_rust_patches;
if let Some(ref s) = cfg.llvm_filecheck {
target.llvm_filecheck = Some(config.src.join(s));
}
Expand Down
25 changes: 16 additions & 9 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use std::str;

use config::Target;
use filetime::FileTime;
use once_cell::sync::OnceCell;

Expand Down Expand Up @@ -395,13 +396,18 @@ impl Build {
let src = config.src.clone();
let out = config.out.clone();

#[cfg(unix)]
// keep this consistent with the equivalent check in x.py:
// https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/bootstrap.py#L796-L797
let is_sudo = match env::var_os("SUDO_USER") {
Some(sudo_user) => match env::var_os("USER") {
Some(user) => user != sudo_user,
None => false,
},
Some(_sudo_user) => {
let uid = unsafe { libc::getuid() };
uid == 0
}
None => false,
};
#[cfg(not(unix))]
let is_sudo = false;

let ignore_git = config.ignore_git;
let rust_info = channel::GitInfo::new(ignore_git, &src);
Expand Down Expand Up @@ -834,12 +840,13 @@ impl Build {
///
/// If no custom `llvm-config` was specified then Rust's llvm will be used.
fn is_rust_llvm(&self, target: TargetSelection) -> bool {
if self.config.llvm_from_ci && target == self.config.build {
return true;
}

match self.config.target_config.get(&target) {
Some(ref c) => c.llvm_config.is_none(),
Some(Target { llvm_has_rust_patches: Some(patched), .. }) => *patched,
Some(Target { llvm_config, .. }) => {
// If the user set llvm-config we assume Rust is not patched,
// but first check to see if it was configured by llvm-from-ci.
(self.config.llvm_from_ci && target == self.config.build) || llvm_config.is_none()
}
None => true,
}
}
Expand Down
Loading

0 comments on commit 10706d6

Please sign in to comment.