Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 18 additions & 9 deletions compiler/rustc_attr_parsing/src/attributes/crate_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ impl SingleAttributeParser for CrateNameParser {
const PATH: &[Symbol] = &[sym::crate_name];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
const STABILITY: AttributeStability = AttributeStability::Stable;

fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
Expand All @@ -31,7 +32,8 @@ impl CombineAttributeParser for CrateTypeParser {
const PATH: &[Symbol] = &[sym::crate_type];
type Item = CrateType;
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::CrateType(items);
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
const TEMPLATE: AttributeTemplate =
template!(NameValueStr: "crate type", "https://doc.rust-lang.org/reference/linkage.html");
const STABILITY: AttributeStability = AttributeStability::Stable;
Expand Down Expand Up @@ -74,7 +76,8 @@ impl SingleAttributeParser for RecursionLimitParser {
const PATH: &[Symbol] = &[sym::recursion_limit];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute");
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
const STABILITY: AttributeStability = AttributeStability::Stable;

fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
Expand Down Expand Up @@ -105,7 +108,8 @@ impl SingleAttributeParser for TypeLengthLimitParser {
const PATH: &[Symbol] = &[sym::type_length_limit];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
const STABILITY: AttributeStability = AttributeStability::Stable;

fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
Expand Down Expand Up @@ -147,7 +151,8 @@ pub(crate) struct NoStdParser;
impl NoArgsAttributeParser for NoStdParser {
const PATH: &[Symbol] = &[sym::no_std];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
const STABILITY: AttributeStability = AttributeStability::Stable;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoStd;
}
Expand All @@ -157,7 +162,8 @@ pub(crate) struct NoMainParser;
impl NoArgsAttributeParser for NoMainParser {
const PATH: &[Symbol] = &[sym::no_main];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
const STABILITY: AttributeStability = AttributeStability::Stable;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoMain;
}
Expand All @@ -176,7 +182,8 @@ pub(crate) struct WindowsSubsystemParser;
impl SingleAttributeParser for WindowsSubsystemParser {
const PATH: &[Symbol] = &[sym::windows_subsystem];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
const TEMPLATE: AttributeTemplate = template!(NameValueStr: ["windows", "console"], "https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute");
const STABILITY: AttributeStability = AttributeStability::Stable;

Expand Down Expand Up @@ -231,7 +238,8 @@ pub(crate) struct NoBuiltinsParser;
impl NoArgsAttributeParser for NoBuiltinsParser {
const PATH: &[Symbol] = &[sym::no_builtins];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
const STABILITY: AttributeStability = AttributeStability::Stable;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoBuiltins;
}
Expand Down Expand Up @@ -269,7 +277,8 @@ impl CombineAttributeParser for FeatureParser {
const PATH: &[Symbol] = &[sym::feature];
type Item = Ident;
const CONVERT: ConvertFn<Self::Item> = AttributeKind::Feature;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
const TEMPLATE: AttributeTemplate = template!(List: &["feature1, feature2, ..."]);
const STABILITY: AttributeStability = AttributeStability::Stable;

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_attr_parsing/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ pub(crate) struct InvalidAttrStyle {
pub crate_root_path: String,
#[help("the crate root is at `{$crate_root_path}`")]
pub show_crate_root_help: bool,
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
Expand Down
35 changes: 20 additions & 15 deletions compiler/rustc_attr_parsing/src/target_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ impl<'sess> AttributeParser<'sess> {
// For crate-level attributes we emit a specific set of lints to warn
// people about accidentally not using them on the crate.
if let &AllowedTargets::AllowList(&[Allow(Target::Crate)]) = allowed_targets {
Self::check_crate_level(cx);
Self::check_crate_level(cx, false);
return;
}
if let &AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]) = allowed_targets {
Self::check_crate_level(cx, true);
return;
}

Expand Down Expand Up @@ -181,7 +185,7 @@ impl<'sess> AttributeParser<'sess> {
}
}

pub(crate) fn check_crate_level(cx: &mut AcceptContext<'_, 'sess>) {
pub(crate) fn check_crate_level(cx: &mut AcceptContext<'_, 'sess>, warn: bool) {
if cx.target == Target::Crate {
return;
}
Expand All @@ -205,19 +209,20 @@ impl<'sess> AttributeParser<'sess> {
})
.unwrap_or_default();

let target = cx.target;
cx.emit_lint(
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
crate::errors::InvalidAttrStyle {
name,
is_used_as_inner,
target_span: (!is_used_as_inner).then_some(target_span),
target: target.name(),
crate_root_path,
show_crate_root_help,
},
attr_span,
);
let diag = crate::errors::InvalidAttrStyle {
name,
is_used_as_inner,
target_span: (!is_used_as_inner).then_some(target_span),
target: cx.target.name(),
crate_root_path,
show_crate_root_help,
span: attr_span,
};
if warn {
cx.emit_lint(rustc_session::lint::builtin::UNUSED_ATTRIBUTES, diag, attr_span);
} else {
cx.emit_err(diag);
}
}

// FIXME: Fix "Cannot determine resolution" error and remove built-in macros
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! where one region is named and the other is anonymous.

use rustc_errors::Diag;
use rustc_middle::ty;
use tracing::debug;

use crate::error_reporting::infer::nice_region_error::NiceRegionError;
Expand Down Expand Up @@ -72,16 +73,34 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
{
return None;
}
let orig_ty = anon_param_info.orig_param_ty;
// Don't suggest naming the outer lifetime when it already appears in the pointee
// (e.g. `&'a mut Buffer<'a>`); point at borrow splitting instead.
let suggestion_would_alias_lifetime =
if let ty::Ref(_, orig_inner_ty, ty::Mutability::Mut) = orig_ty.kind() {
self.tcx().any_free_region_meets(orig_inner_ty, |r| r == named)
} else {
false
};

let named = named.to_string();
let new_ty_span = if suggestion_would_alias_lifetime { None } else { Some(new_ty_span) };
let err = match param.pat.simple_ident() {
Some(simple_ident) => ExplicitLifetimeRequired::WithIdent {
span,
simple_ident,
named,
new_ty_span,
new_ty,
link_nomicon: suggestion_would_alias_lifetime,
},
None => ExplicitLifetimeRequired::WithParamType {
span,
named,
new_ty_span,
new_ty,
link_nomicon: suggestion_would_alias_lifetime,
},
None => ExplicitLifetimeRequired::WithParamType { span, named, new_ty_span, new_ty },
};
Some(self.tcx().sess.dcx().create_err(err))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct AnonymousParamInfo<'tcx> {
pub param: &'tcx hir::Param<'tcx>,
/// The type corresponding to the anonymous region parameter.
pub param_ty: Ty<'tcx>,
/// The original type before region replacement.
pub orig_param_ty: Ty<'tcx>,
/// The `ty::LateParamRegionKind` corresponding to the anonymous region.
pub kind: ty::LateParamRegionKind,
/// The `Span` of the parameter type.
Expand Down Expand Up @@ -94,7 +96,14 @@ pub fn find_param_with_region<'tcx>(
let ty_hir_id = fn_decl.inputs[index].hir_id;
let param_ty_span = tcx.hir_span(ty_hir_id);
let is_first = index == 0;
AnonymousParamInfo { param, param_ty: new_param_ty, param_ty_span, kind, is_first }
AnonymousParamInfo {
param,
param_ty: new_param_ty,
orig_param_ty: ty,
param_ty_span,
kind,
is_first,
}
})
})
}
Expand Down
14 changes: 12 additions & 2 deletions compiler/rustc_trait_selection/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,13 @@ pub(crate) enum ExplicitLifetimeRequired<'a> {
applicability = "unspecified",
style = "verbose"
)]
new_ty_span: Span,
new_ty_span: Option<Span>,
new_ty: Ty<'a>,
#[help(
"see <https://doc.rust-lang.org/nomicon/borrow-splitting.html> \
for more information about lifetime errors related to mutable references"
)]
link_nomicon: bool,
},
#[diag("explicit lifetime required in parameter type", code = E0621)]
WithParamType {
Expand All @@ -883,8 +888,13 @@ pub(crate) enum ExplicitLifetimeRequired<'a> {
applicability = "unspecified",
style = "verbose"
)]
new_ty_span: Span,
new_ty_span: Option<Span>,
new_ty: Ty<'a>,
#[help(
"see <https://doc.rust-lang.org/nomicon/borrow-splitting.html> \
for more information about lifetime errors related to mutable references"
)]
link_nomicon: bool,
},
}

Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
#![feature(str_internals)]
#![feature(sync_unsafe_cell)]
#![feature(temporary_niche_types)]
#![feature(thread_local_internals)]
#![feature(ub_checks)]
#![feature(uint_carryless_mul)]
#![feature(used_with_arg)]
Expand Down
47 changes: 47 additions & 0 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,26 @@ impl Command {
///
/// By default, stdin, stdout and stderr are inherited from the parent.
///
/// # Errors
///
/// This method returns an [`io::Error`] if the child process could not be
/// spawned. Common reasons include:
///
/// * the program could not be found (for example, it does not exist, or,
/// when given a bare name, it is not present in the `PATH`);
/// * the current process does not have permission to execute the program
/// (for example, the file is not marked executable, or execution is
/// denied by a security policy such as `seccomp`);
/// * the operating system could not create the new process because of
/// resource exhaustion (for example, a limit on the number of processes
/// was reached).
///
/// An error is only returned for failures that occur while the child is
/// being spawned. Once the child has started successfully, anything that
/// happens to it afterwards — including being terminated by a signal — is
/// reported through its [`ExitStatus`] rather than as an error from the
/// spawning method.
///
/// # Examples
///
/// ```no_run
Expand All @@ -1084,6 +1104,20 @@ impl Command {
/// attempt by the child process to read from the stdin stream will result
/// in the stream immediately closing.
///
/// # Errors
///
/// Like [`spawn`], this method returns an [`io::Error`] if the child
/// process could not be spawned; see [`spawn`] for the common reasons. It
/// may also return an error if reading the child's output or waiting on the
/// child fails.
///
/// Note that this method does **not** return an error if the child runs and
/// then exits unsuccessfully, or is terminated by a signal. In those cases
/// it still returns [`Ok`], and the outcome is reflected in the
/// [`ExitStatus`] stored in the returned [`Output`].
///
/// [`spawn`]: Command::spawn
///
/// # Examples
///
/// ```should_panic
Expand Down Expand Up @@ -1111,6 +1145,19 @@ impl Command {
///
/// By default, stdin, stdout and stderr are inherited from the parent.
///
/// # Errors
///
/// Like [`spawn`], this method returns an [`io::Error`] if the child
/// process could not be spawned; see [`spawn`] for the common reasons. It
/// may also return an error if waiting on the child fails.
///
/// Note that this method does **not** return an error if the child runs and
/// then exits unsuccessfully, or is terminated by a signal. In those cases
/// it still returns [`Ok`], and the outcome is reflected in the returned
/// [`ExitStatus`].
///
/// [`spawn`]: Command::spawn
///
/// # Examples
///
/// ```should_panic
Expand Down
9 changes: 9 additions & 0 deletions library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ pub use id::ThreadId;
pub use join_handle::JoinHandle;
pub(crate) use lifecycle::ThreadInit;
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(not(test))] // we use the realstd types instead, see below
pub use local::{AccessError, LocalKey};
#[stable(feature = "scoped_threads", since = "1.63.0")]
pub use scoped::{Scope, ScopedJoinHandle, scope};
Expand All @@ -210,10 +211,18 @@ pub use thread::Thread;
// Implementation details used by the thread_local!{} macro.
#[doc(hidden)]
#[unstable(feature = "thread_local_internals", issue = "none")]
#[cfg(not(test))] // we use the realstd types instead, see below
pub mod local_impl {
pub use super::local::thread_local_process_attrs;
pub use crate::sys::thread_local::*;
}
// Under cfg(test), avoid having two instances of the thread-local machinery.
// Things too easily get mixed up and then we end up with memory leaks because we're not calling
// all the right dtors.
#[cfg(test)]
pub use realstd::thread::local_impl;
#[cfg(test)]
pub use realstd::thread::{AccessError, LocalKey};

/// A specialized [`Result`] type for threads.
///
Expand Down
4 changes: 2 additions & 2 deletions src/doc/rustc/src/platform-support/arm-none-eabi.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ their own document.
### Tier 2 Target List

- Arm A-Profile Architectures
- [`armv7a-none-eabi`](armv7a-none-eabi.md)
- [`armv7a-none-eabi` and `armv7a-none-eabihf`](armv7a-none-eabi.md)
- [`thumbv7a-none-eabi` and `thumbv7a-none-eabihf`](armv7a-none-eabi.md)
- Arm R-Profile Architectures
- [`armv7r-none-eabi` and `armv7r-none-eabihf`](armv7r-none-eabi.md)
Expand All @@ -32,7 +32,7 @@ their own document.
### Tier 3 Target List

- Arm A-Profile Architectures
- [`armv7a-none-eabihf`](armv7a-none-eabi.md)
- None
- Arm R-Profile Architectures
- None
- Arm M-Profile Architectures
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/platform-support/nvptx64-nvidia-cuda.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ platform.
## Target maintainers

[@kjetilkjeka](https://github.com/kjetilkjeka)
[@kulst](https://github.com/kulst)

## Requirements

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/attributes/attr-on-mac-call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ fn main() {
//~| WARN previously accepted
unreachable!();
#[register_tool(xyz)]
//~^ WARN crate-level attribute should be an inner attribute
//~^ ERROR crate-level attribute should be an inner attribute
unreachable!();
}
Loading
Loading