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 6 pull requests #121692

Closed
wants to merge 15 commits into from
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
63 changes: 41 additions & 22 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,21 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[

// Entry point:
gated!(unix_sigpipe, Normal, template!(Word, NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
ungated!(start, Normal, template!(Word), WarnFollowing),
ungated!(no_start, CrateLevel, template!(Word), WarnFollowing),
ungated!(no_main, CrateLevel, template!(Word), WarnFollowing),
ungated!(start, Normal, template!(Word), WarnFollowing, @only_local: true),
ungated!(no_start, CrateLevel, template!(Word), WarnFollowing, @only_local: true),
ungated!(no_main, CrateLevel, template!(Word), WarnFollowing, @only_local: true),

// Modules, prelude, and resolution:
ungated!(path, Normal, template!(NameValueStr: "file"), FutureWarnFollowing),
ungated!(no_std, CrateLevel, template!(Word), WarnFollowing),
ungated!(no_implicit_prelude, Normal, template!(Word), WarnFollowing),
ungated!(path, Normal, template!(NameValueStr: "file"), FutureWarnFollowing, @only_local: true),
ungated!(no_std, CrateLevel, template!(Word), WarnFollowing, @only_local: true),
ungated!(no_implicit_prelude, Normal, template!(Word), WarnFollowing, @only_local: true),
ungated!(non_exhaustive, Normal, template!(Word), WarnFollowing),

// Runtime
ungated!(
windows_subsystem, CrateLevel,
template!(NameValueStr: "windows|console"), FutureWarnFollowing
template!(NameValueStr: "windows|console"), FutureWarnFollowing,
@only_local: true
),
ungated!(panic_handler, Normal, template!(Word), WarnFollowing), // RFC 2070

Expand All @@ -416,13 +417,17 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
DuplicatesOk, @only_local: true,
),
ungated!(track_caller, Normal, template!(Word), WarnFollowing),
ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding),
ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding, @only_local: true),
gated!(
no_sanitize, Normal,
template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
experimental!(no_sanitize)
@only_local: true, experimental!(no_sanitize)
),
gated!(
coverage, Normal, template!(Word, List: "on|off"),
WarnFollowing, @only_local: true,
coverage_attribute, experimental!(coverage)
),
gated!(coverage, Normal, template!(Word, List: "on|off"), WarnFollowing, coverage_attribute, experimental!(coverage)),

ungated!(
doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk
Expand All @@ -431,7 +436,8 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// Debugging
ungated!(
debugger_visualizer, Normal,
template!(List: r#"natvis_file = "...", gdb_script_file = "...""#), DuplicatesOk
template!(List: r#"natvis_file = "...", gdb_script_file = "...""#),
DuplicatesOk, @only_local: true
),

// ==========================================================================
Expand All @@ -455,26 +461,35 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
marker_trait_attr, experimental!(marker)
),
gated!(
thread_local, Normal, template!(Word), WarnFollowing,
thread_local, Normal, template!(Word), WarnFollowing, @only_local: true,
"`#[thread_local]` is an experimental feature, and does not currently handle destructors",
),
gated!(no_core, CrateLevel, template!(Word), WarnFollowing, experimental!(no_core)),
gated!(
no_core, CrateLevel, template!(Word), WarnFollowing,
@only_local: true, experimental!(no_core)
),
// RFC 2412
gated!(
optimize, Normal, template!(List: "size|speed"), ErrorPreceding, optimize_attribute,
experimental!(optimize),
optimize, Normal, template!(List: "size|speed"), ErrorPreceding,
@only_local: true, optimize_attribute, experimental!(optimize)
),

gated!(ffi_pure, Normal, template!(Word), WarnFollowing, experimental!(ffi_pure)),
gated!(ffi_const, Normal, template!(Word), WarnFollowing, experimental!(ffi_const)),
gated!(
ffi_pure, Normal, template!(Word), WarnFollowing,
@only_local: true, experimental!(ffi_pure)
),
gated!(
ffi_const, Normal, template!(Word), WarnFollowing,
@only_local: true, experimental!(ffi_const)
),
gated!(
register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), DuplicatesOk,
experimental!(register_tool),
@only_local: true, experimental!(register_tool),
),

gated!(
cmse_nonsecure_entry, Normal, template!(Word), WarnFollowing,
experimental!(cmse_nonsecure_entry)
@only_local: true, experimental!(cmse_nonsecure_entry)
),
// RFC 2632
gated!(
Expand All @@ -492,11 +507,14 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// `#[collapse_debuginfo]`
gated!(
collapse_debuginfo, Normal, template!(Word, List: "no|external|yes"), ErrorFollowing,
experimental!(collapse_debuginfo)
@only_local: true, experimental!(collapse_debuginfo)
),

// RFC 2397
gated!(do_not_recommend, Normal, template!(Word), WarnFollowing, experimental!(do_not_recommend)),
gated!(
do_not_recommend, Normal, template!(Word), WarnFollowing,
@only_local: true, experimental!(do_not_recommend)
),

// `#[cfi_encoding = ""]`
gated!(
Expand Down Expand Up @@ -528,7 +546,8 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),
ungated!(
rustc_default_body_unstable, Normal,
template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk
template!(List: r#"feature = "name", reason = "...", issue = "N""#),
DuplicatesOk, @only_local: true
),
gated!(
allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), DuplicatesOk,
Expand Down
83 changes: 1 addition & 82 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use crate::lints::{
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand, NonExistentDocKeyword,
QueryInstability, SpanUseEqCtxtDiag, TyQualified, TykindDiag, TykindKind, UntranslatableDiag,
UntranslatableDiagnosticTrivial,
};
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
use rustc_ast as ast;
Expand Down Expand Up @@ -361,15 +360,7 @@ declare_tool_lint! {
report_in_external_macro: true
}

declare_tool_lint! {
/// The `untranslatable_diagnostic_trivial` lint detects diagnostics created using only static strings.
pub rustc::UNTRANSLATABLE_DIAGNOSTIC_TRIVIAL,
Deny,
"prevent creation of diagnostics which cannot be translated, which use only static strings",
report_in_external_macro: true
}

declare_lint_pass!(Diagnostics => [ UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSIDE_OF_IMPL, UNTRANSLATABLE_DIAGNOSTIC_TRIVIAL ]);
declare_lint_pass!(Diagnostics => [UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSIDE_OF_IMPL]);

impl LateLintPass<'_> for Diagnostics {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
Expand Down Expand Up @@ -425,78 +416,6 @@ impl LateLintPass<'_> for Diagnostics {
}
}

impl EarlyLintPass for Diagnostics {
#[allow(unused_must_use)]
fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &ast::Stmt) {
// Looking for a straight chain of method calls from 'struct_span_err' to 'emit'.
let ast::StmtKind::Semi(expr) = &stmt.kind else {
return;
};
let ast::ExprKind::MethodCall(meth) = &expr.kind else {
return;
};
if meth.seg.ident.name != sym::emit || !meth.args.is_empty() {
return;
}
let mut segments = vec![];
let mut cur = &meth.receiver;
let fake = &[].into();
loop {
match &cur.kind {
ast::ExprKind::Call(func, args) => {
if let ast::ExprKind::Path(_, path) = &func.kind {
segments.push((path.segments.last().unwrap().ident.name, args))
}
break;
}
ast::ExprKind::MethodCall(method) => {
segments.push((method.seg.ident.name, &method.args));
cur = &method.receiver;
}
ast::ExprKind::MacCall(mac) => {
segments.push((mac.path.segments.last().unwrap().ident.name, fake));
break;
}
_ => {
break;
}
}
}
segments.reverse();
if segments.is_empty() {
return;
}
if segments[0].0.as_str() != "struct_span_err" {
return;
}
if !segments.iter().all(|(name, args)| {
let arg = match name.as_str() {
"struct_span_err" | "span_note" | "span_label" | "span_help" if args.len() == 2 => {
&args[1]
}
"note" | "help" if args.len() == 1 => &args[0],
_ => {
return false;
}
};
if let ast::ExprKind::Lit(lit) = arg.kind
&& let ast::token::LitKind::Str = lit.kind
{
true
} else {
false
}
}) {
return;
}
cx.emit_span_lint(
UNTRANSLATABLE_DIAGNOSTIC_TRIVIAL,
stmt.span,
UntranslatableDiagnosticTrivial,
);
}
}

declare_tool_lint! {
/// The `bad_opt_access` lint detects accessing options by field instead of
/// the wrapper function.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ fn register_internals(store: &mut LintStore) {
store.register_lints(&TyTyKind::get_lints());
store.register_late_mod_pass(|_| Box::new(TyTyKind));
store.register_lints(&Diagnostics::get_lints());
store.register_early_pass(|| Box::new(Diagnostics));
store.register_late_mod_pass(|_| Box::new(Diagnostics));
store.register_lints(&BadOptAccess::get_lints());
store.register_late_mod_pass(|_| Box::new(BadOptAccess));
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,10 +923,6 @@ pub struct DiagOutOfImpl;
#[diag(lint_untranslatable_diag)]
pub struct UntranslatableDiag;

#[derive(LintDiagnostic)]
#[diag(lint_trivial_untranslatable_diag)]
pub struct UntranslatableDiagnosticTrivial;

#[derive(LintDiagnostic)]
#[diag(lint_bad_opt_access)]
pub struct BadOptAccessDiag<'a> {
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,10 +1294,20 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let mut path_segments = path_segments.clone();
path_segments.push(ast::PathSegment::from_ident(ident));

let alias_import = if let NameBindingKind::Import { import, .. } =
name_binding.kind
&& let ImportKind::ExternCrate { source: Some(_), .. } = import.kind
&& import.parent_scope.expansion == parent_scope.expansion
{
true
} else {
false
};

let is_extern_crate_that_also_appears_in_prelude =
name_binding.is_extern_crate() && lookup_ident.span.at_least_rust_2018();

if !is_extern_crate_that_also_appears_in_prelude {
if !is_extern_crate_that_also_appears_in_prelude || alias_import {
// add the module to the lookup
if seen_modules.insert(module.def_id()) {
if via_import { &mut worklist_via_import } else { &mut worklist }
Expand Down
4 changes: 3 additions & 1 deletion library/std/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pub use core::ffi::FromBytesUntilNulError;
pub use core::ffi::{CStr, FromBytesWithNulError};

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(inline)]
pub use self::os_str::{OsStr, OsString};

#[stable(feature = "core_ffi_c", since = "1.64.0")]
Expand All @@ -188,4 +189,5 @@ pub use core::ffi::c_void;
)]
pub use core::ffi::{VaList, VaListImpl};

mod os_str;
#[unstable(feature = "os_str_display", issue = "120048")]
pub mod os_str;
67 changes: 64 additions & 3 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! The [`OsStr`] and [`OsString`] types and associated utilities.

#[cfg(test)]
mod tests;

Expand Down Expand Up @@ -1147,6 +1149,32 @@ impl OsStr {
pub fn eq_ignore_ascii_case<S: AsRef<OsStr>>(&self, other: S) -> bool {
self.inner.eq_ignore_ascii_case(&other.as_ref().inner)
}

/// Returns an object that implements [`Display`] for safely printing an
/// [`OsStr`] that may contain non-Unicode data. This may perform lossy
/// conversion, depending on the platform. If you would like an
/// implementation which escapes the [`OsStr`] please use [`Debug`]
/// instead.
///
/// [`Display`]: fmt::Display
/// [`Debug`]: fmt::Debug
///
/// # Examples
///
/// ```
/// #![feature(os_str_display)]
/// use std::ffi::OsStr;
///
/// let s = OsStr::new("Hello, world!");
/// println!("{}", s.display());
/// ```
#[unstable(feature = "os_str_display", issue = "120048")]
#[must_use = "this does not display the `OsStr`; \
it returns an object that can be displayed"]
#[inline]
pub fn display(&self) -> Display<'_> {
Display { os_str: self }
}
}

#[stable(feature = "box_from_os_str", since = "1.17.0")]
Expand Down Expand Up @@ -1441,9 +1469,42 @@ impl fmt::Debug for OsStr {
}
}

impl OsStr {
pub(crate) fn display(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.inner, formatter)
/// Helper struct for safely printing an [`OsStr`] with [`format!`] and `{}`.
///
/// An [`OsStr`] might contain non-Unicode data. This `struct` implements the
/// [`Display`] trait in a way that mitigates that. It is created by the
/// [`display`](OsStr::display) method on [`OsStr`]. This may perform lossy
/// conversion, depending on the platform. If you would like an implementation
/// which escapes the [`OsStr`] please use [`Debug`] instead.
///
/// # Examples
///
/// ```
/// #![feature(os_str_display)]
/// use std::ffi::OsStr;
///
/// let s = OsStr::new("Hello, world!");
/// println!("{}", s.display());
/// ```
///
/// [`Display`]: fmt::Display
/// [`format!`]: crate::format
#[unstable(feature = "os_str_display", issue = "120048")]
pub struct Display<'a> {
os_str: &'a OsStr,
}

#[unstable(feature = "os_str_display", issue = "120048")]
impl fmt::Debug for Display<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.os_str, f)
}
}

#[unstable(feature = "os_str_display", issue = "120048")]
impl fmt::Display for Display<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.os_str.inner, f)
}
}

Expand Down
Loading
Loading