Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 14 pull requests #101295

Merged
merged 35 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4dded23
add `special_module_name` lint
ibraheemdev Mar 1, 2022
c08f460
tidy
ibraheemdev Apr 15, 2022
f479289
move dummy test module to auxiliary directory
ibraheemdev Jun 4, 2022
4fdf43f
`special_module_name`: ignore inline modules
ibraheemdev Jul 21, 2022
b9c47f6
Use getuid to check instead of USER env var in rustbuild
Samyak2 Aug 21, 2022
e136e02
bootstrap: Add llvm-has-rust-patches target option
tmandry Aug 27, 2022
73958fd
Ignore cargo target folder in src/bootstrap
tmandry Aug 27, 2022
de6a3ec
Make docs formulation more consistent for NonZero{int}
yjhn Aug 30, 2022
803e35a
Remove unneeded extra whitespace before where clause
GuillaumeGomez Aug 31, 2022
4304d1d
Update rustdoc tests
GuillaumeGomez Aug 31, 2022
b112bfe
Add rustdoc GUI test
GuillaumeGomez Aug 31, 2022
a928255
Fix bad target name in Walkthrough
diminishedprime Aug 31, 2022
037a911
rustdoc: remove unused `.docblock .impl-items` CSS
notriddle Aug 31, 2022
d8b572b
Tweaks to fuchsia doc walkthrough
andrewpollack Aug 31, 2022
a20318d
Update outdated comment about output capturing in print_to.
m-ou-se Sep 1, 2022
098725c
Fix filename of armv4t-none-eabi.md
QuinnPainter Sep 1, 2022
c9f4af6
Fix typo in comment
aDotInTheVoid Sep 1, 2022
fb14ad0
Correctly merge impl block cfg attributes with its parents
GuillaumeGomez Sep 1, 2022
68d0094
Add regression test for #101129
GuillaumeGomez Sep 1, 2022
78e9bea
do not suggest adding `move` to closure when `move` is already used
TaKO8Ki Sep 1, 2022
3107133
rustdoc: remove unneeded CSS `.content table td:first-child > a`
notriddle Sep 1, 2022
da1d738
Rollup merge of #94467 - ibraheemdev:master, r=pnkfelix
matthiaskrgr Sep 1, 2022
b05f97d
Rollup merge of #100852 - Samyak2:samyak/100459, r=Mark-Simulacrum
matthiaskrgr Sep 1, 2022
1c0561a
Rollup merge of #101072 - tmandry:llvm-is-vanilla, r=Mark-Simulacrum
matthiaskrgr Sep 1, 2022
36d0506
Rollup merge of #101190 - yjhn:patch-1, r=Mark-Simulacrum
matthiaskrgr Sep 1, 2022
21c8447
Rollup merge of #101245 - GuillaumeGomez:remove-unneeded-where-whites…
matthiaskrgr Sep 1, 2022
f6c7c4e
Rollup merge of #101251 - diminishedprime:patch-1, r=JohnTitor
matthiaskrgr Sep 1, 2022
418748f
Rollup merge of #101254 - rust-lang:notriddle/remove-even-more-css, r…
matthiaskrgr Sep 1, 2022
cbcea24
Rollup merge of #101256 - andrewpollack:fuchsia-docs-adding, r=tmandry
matthiaskrgr Sep 1, 2022
b36fd55
Rollup merge of #101270 - m-ou-se:update-comment, r=joshtriplett
matthiaskrgr Sep 1, 2022
754cb2a
Rollup merge of #101271 - QuinnPainter:patch-1, r=Dylan-DPC
matthiaskrgr Sep 1, 2022
e9df5dd
Rollup merge of #101274 - aDotInTheVoid:comment-typo, r=TaKO8Ki
matthiaskrgr Sep 1, 2022
8f8a5d2
Rollup merge of #101279 - GuillaumeGomez:doc_auto_cfg_nested_impl, r=…
matthiaskrgr Sep 1, 2022
1bafe0b
Rollup merge of #101285 - TaKO8Ki:do-not-suggest-adding-move-when-clo…
matthiaskrgr Sep 1, 2022
1c12ded
Rollup merge of #101292 - rust-lang:notriddle/rustdoc-table-first-chi…
matthiaskrgr Sep 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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