diff --git a/Cargo.lock b/Cargo.lock index 4d216f26b6161..e37e8614af2cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3417,18 +3417,29 @@ version = "0.0.0" dependencies = [ "bitflags 2.4.2", "memchr", + "rustc_ast_ir", "rustc_data_structures", "rustc_index", "rustc_lexer", "rustc_macros", "rustc_serialize", "rustc_span", - "rustc_type_ir", "smallvec", "thin-vec", "tracing", ] +[[package]] +name = "rustc_ast_ir" +version = "0.0.0" +dependencies = [ + "rustc_data_structures", + "rustc_macros", + "rustc_serialize", + "rustc_span", + "smallvec", +] + [[package]] name = "rustc_ast_lowering" version = "0.0.0" @@ -4181,6 +4192,7 @@ dependencies = [ "rustc_apfloat", "rustc_arena", "rustc_ast", + "rustc_ast_ir", "rustc_attr", "rustc_data_structures", "rustc_error_messages", @@ -4661,6 +4673,7 @@ version = "0.0.0" dependencies = [ "bitflags 2.4.2", "derivative", + "rustc_ast_ir", "rustc_data_structures", "rustc_index", "rustc_macros", diff --git a/compiler/rustc_ast/Cargo.toml b/compiler/rustc_ast/Cargo.toml index 087f6a192b5c8..d33f9666b484c 100644 --- a/compiler/rustc_ast/Cargo.toml +++ b/compiler/rustc_ast/Cargo.toml @@ -8,14 +8,13 @@ edition = "2021" # tidy-alphabetical-start bitflags = "2.4.1" memchr = "=2.5.0" +rustc_ast_ir = { path = "../rustc_ast_ir" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_index = { path = "../rustc_index" } rustc_lexer = { path = "../rustc_lexer" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } -# For Mutability and Movability, which could be uplifted into a common crate. -rustc_type_ir = { path = "../rustc_type_ir" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } thin-vec = "0.2.12" tracing = "0.1" diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 8ba2f222fcfaa..4ae18b4cf4854 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -27,6 +27,7 @@ pub use UnsafeSource::*; use crate::ptr::P; use crate::token::{self, CommentKind, Delimiter}; use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream}; +pub use rustc_ast_ir::{Movability, Mutability}; use rustc_data_structures::packed::Pu128; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -35,7 +36,6 @@ use rustc_macros::HashStable_Generic; use rustc_span::source_map::{respan, Spanned}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP}; -pub use rustc_type_ir::{Movability, Mutability}; use std::fmt; use std::mem; use thin_vec::{thin_vec, ThinVec}; diff --git a/compiler/rustc_ast_ir/Cargo.toml b/compiler/rustc_ast_ir/Cargo.toml new file mode 100644 index 0000000000000..e761b7adad3fd --- /dev/null +++ b/compiler/rustc_ast_ir/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "rustc_ast_ir" +version = "0.0.0" +edition = "2021" + +[dependencies] +# tidy-alphabetical-start +rustc_data_structures = { path = "../rustc_data_structures", optional = true } +rustc_macros = { path = "../rustc_macros", optional = true } +rustc_serialize = { path = "../rustc_serialize", optional = true } +rustc_span = { path = "../rustc_span", optional = true } +smallvec = { version = "1.8.1" } +# tidy-alphabetical-end + +[features] +default = ["nightly"] +nightly = [ + "rustc_serialize", + "rustc_data_structures", + "rustc_macros", + "rustc_span", +] diff --git a/compiler/rustc_ast_ir/src/lib.rs b/compiler/rustc_ast_ir/src/lib.rs new file mode 100644 index 0000000000000..9fe1370921345 --- /dev/null +++ b/compiler/rustc_ast_ir/src/lib.rs @@ -0,0 +1,68 @@ +#![cfg_attr(feature = "nightly", feature(rustc_attrs))] +#![cfg_attr(feature = "nightly", allow(internal_features))] + +#[cfg(feature = "nightly")] +#[macro_use] +extern crate rustc_macros; + +/// The movability of a coroutine / closure literal: +/// whether a coroutine contains self-references, causing it to be `!Unpin`. +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] +#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))] +pub enum Movability { + /// May contain self-references, `!Unpin`. + Static, + /// Must not contain self-references, `Unpin`. + Movable, +} + +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] +#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))] +pub enum Mutability { + // N.B. Order is deliberate, so that Not < Mut + Not, + Mut, +} + +impl Mutability { + pub fn invert(self) -> Self { + match self { + Mutability::Mut => Mutability::Not, + Mutability::Not => Mutability::Mut, + } + } + + /// Returns `""` (empty string) or `"mut "` depending on the mutability. + pub fn prefix_str(self) -> &'static str { + match self { + Mutability::Mut => "mut ", + Mutability::Not => "", + } + } + + /// Returns `"&"` or `"&mut "` depending on the mutability. + pub fn ref_prefix_str(self) -> &'static str { + match self { + Mutability::Not => "&", + Mutability::Mut => "&mut ", + } + } + + /// Returns `""` (empty string) or `"mutably "` depending on the mutability. + pub fn mutably_str(self) -> &'static str { + match self { + Mutability::Not => "", + Mutability::Mut => "mutably ", + } + } + + /// Return `true` if self is mutable + pub fn is_mut(self) -> bool { + matches!(self, Self::Mut) + } + + /// Return `true` if self is **not** mutable + pub fn is_not(self) -> bool { + matches!(self, Self::Not) + } +} diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index 267f3acaaa5b2..434101ef6b695 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -11,11 +11,10 @@ use rustc_middle::mir::interpret::{ PointerKind, ResourceExhaustionInfo, UndefinedBehaviorInfo, UnsupportedOpInfo, ValidationErrorInfo, }; -use rustc_middle::ty::{self, Ty}; +use rustc_middle::ty::{self, Mutability, Ty}; use rustc_span::Span; use rustc_target::abi::call::AdjustForForeignAbiError; use rustc_target::abi::{Size, WrappingRange}; -use rustc_type_ir::Mutability; use crate::interpret::InternKind; diff --git a/compiler/rustc_const_eval/src/util/caller_location.rs b/compiler/rustc_const_eval/src/util/caller_location.rs index b8e15c485f58f..af9a4a4271d74 100644 --- a/compiler/rustc_const_eval/src/util/caller_location.rs +++ b/compiler/rustc_const_eval/src/util/caller_location.rs @@ -1,10 +1,9 @@ use rustc_hir::LangItem; use rustc_middle::mir; use rustc_middle::query::TyCtxtAt; -use rustc_middle::ty; use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::{self, Mutability}; use rustc_span::symbol::Symbol; -use rustc_type_ir::Mutability; use crate::const_eval::{mk_eval_cx_to_read_const_val, CanAccessMutGlobal, CompileTimeEvalContext}; use crate::interpret::*; diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 682363ed19d87..1fb061f911474 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -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 @@ -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 @@ -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 ), // ========================================================================== @@ -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!( @@ -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!( @@ -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, diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index b81ad8b194623..f538d6bcb9816 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -420,7 +420,9 @@ impl DefPathData { pub fn name(&self) -> DefPathDataName { use self::DefPathData::*; match *self { - TypeNs(name) if name == kw::Empty => DefPathDataName::Anon { namespace: sym::opaque }, + TypeNs(name) if name == kw::Empty => { + DefPathDataName::Anon { namespace: sym::synthetic } + } TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => { DefPathDataName::Named(name) } diff --git a/compiler/rustc_hir_analysis/src/check/errs.rs b/compiler/rustc_hir_analysis/src/check/errs.rs index 4a7ace274c5bb..c92320bc0fee8 100644 --- a/compiler/rustc_hir_analysis/src/check/errs.rs +++ b/compiler/rustc_hir_analysis/src/check/errs.rs @@ -1,9 +1,8 @@ use rustc_hir as hir; use rustc_hir_pretty::qpath_to_string; use rustc_lint_defs::builtin::STATIC_MUT_REFS; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{Mutability, TyCtxt}; use rustc_span::Span; -use rustc_type_ir::Mutability; use crate::errors; diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 8f4f028fc07f1..d07c9b10f1cbd 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -636,6 +636,20 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { { self.resolve_vars_if_possible(trait_pred) } + // Eagerly process alias-relate obligations in new trait solver, + // since these can be emitted in the process of solving trait goals, + // but we need to constrain vars before processing goals mentioning + // them. + Some(ty::PredicateKind::AliasRelate(..)) => { + let mut fulfill_cx = >::new(self); + fulfill_cx.register_predicate_obligation(self, obligation); + let errs = fulfill_cx.select_where_possible(self); + if !errs.is_empty() { + return Err(TypeError::Mismatch); + } + coercion.obligations.extend(fulfill_cx.pending_obligations()); + continue; + } _ => { coercion.obligations.push(obligation); continue; diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 596221a8455c5..a071fa488bc47 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -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; @@ -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<'_>) { @@ -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. diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index d5e5e0ec2245b..250c4adb948e2 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -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)); diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 80231d2e68ad9..c5ec887a570f8 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -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> { diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index 82e56c9cbe205..5a24a7ab0bd55 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -17,6 +17,7 @@ rustc-rayon-core = { version = "0.5.0", optional = true } rustc_apfloat = "0.2.0" rustc_arena = { path = "../rustc_arena" } rustc_ast = { path = "../rustc_ast" } +rustc_ast_ir = { path = "../rustc_ast_ir" } rustc_attr = { path = "../rustc_attr" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_error_messages = { path = "../rustc_error_messages" } # Used for intra-doc links diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index 125fac48df877..9cef4cf1ac6f2 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -4,6 +4,7 @@ use crate::error; use crate::mir::{ConstAlloc, ConstValue}; use crate::ty::{layout, tls, Ty, TyCtxt, ValTree}; +use rustc_ast_ir::Mutability; use rustc_data_structures::sync::Lock; use rustc_errors::{ DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg, @@ -12,7 +13,6 @@ use rustc_macros::HashStable; use rustc_session::CtfeBacktrace; use rustc_span::{def_id::DefId, Span, DUMMY_SP}; use rustc_target::abi::{call, Align, Size, VariantIdx, WrappingRange}; -use rustc_type_ir::Mutability; use std::borrow::Cow; use std::{any::Any, backtrace::Backtrace, fmt}; diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 30409e990e13c..eb63aa4260802 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -32,6 +32,7 @@ pub use generic_args::*; pub use generics::*; use rustc_ast as ast; use rustc_ast::node_id::NodeMap; +pub use rustc_ast_ir::{Movability, Mutability}; use rustc_attr as attr; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::intern::Interned; diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 1910841f2684e..87acca9e945a3 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -715,13 +715,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { p!(print_def_path(def_id, &[])); } ty::Alias(ty::Projection | ty::Inherent | ty::Weak, ref data) => { - if !(self.should_print_verbose() || with_no_queries()) - && self.tcx().is_impl_trait_in_trait(data.def_id) - { - return self.pretty_print_opaque_impl_type(data.def_id, data.args); - } else { - p!(print(data)) - } + p!(print(data)) } ty::Placeholder(placeholder) => match placeholder.bound.kind { ty::BoundTyKind::Anon => p!(write("{placeholder:?}")), @@ -3053,7 +3047,17 @@ define_print_and_forward_display! { if let DefKind::Impl { of_trait: false } = cx.tcx().def_kind(cx.tcx().parent(self.def_id)) { p!(pretty_print_inherent_projection(self)) } else { - p!(print_def_path(self.def_id, self.args)); + // If we're printing verbosely, or don't want to invoke queries + // (`is_impl_trait_in_trait`), then fall back to printing the def path. + // This is likely what you want if you're debugging the compiler anyways. + if !(cx.should_print_verbose() || with_no_queries()) + && cx.tcx().is_impl_trait_in_trait(self.def_id) + { + return cx.pretty_print_opaque_impl_type(self.def_id, self.args); + } else { + p!(print_def_path(self.def_id, self.args)); + } + } } diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 96025a26de7ae..eaf6dca457c6e 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -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 } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 5f9373dd81a58..4d8475bef54c8 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1690,6 +1690,7 @@ symbols! { suggestion, sym, sync, + synthetic, t32, target, target_abi, diff --git a/compiler/rustc_type_ir/Cargo.toml b/compiler/rustc_type_ir/Cargo.toml index 59966423f7fb7..79ff60802d28e 100644 --- a/compiler/rustc_type_ir/Cargo.toml +++ b/compiler/rustc_type_ir/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" # tidy-alphabetical-start bitflags = "2.4.1" derivative = "2.2.0" +rustc_ast_ir = { path = "../rustc_ast_ir" } rustc_data_structures = { path = "../rustc_data_structures", optional = true } rustc_index = { path = "../rustc_index", default-features = false } rustc_macros = { path = "../rustc_macros", optional = true } @@ -25,4 +26,5 @@ nightly = [ "rustc_span", "rustc_data_structures", "rustc_macros", + "rustc_ast_ir/nightly" ] diff --git a/compiler/rustc_type_ir/src/macros.rs b/compiler/rustc_type_ir/src/macros.rs index 82bb1bf291667..231546287d027 100644 --- a/compiler/rustc_type_ir/src/macros.rs +++ b/compiler/rustc_type_ir/src/macros.rs @@ -51,6 +51,6 @@ TrivialTypeTraversalImpls! { crate::DebruijnIndex, crate::AliasRelationDirection, crate::UniverseIndex, - crate::Mutability, - crate::Movability, + rustc_ast_ir::Mutability, + rustc_ast_ir::Movability, } diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 9f715a01d44fa..a4d67169bc75c 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -11,67 +11,7 @@ use crate::{DebruijnIndex, DebugWithInfcx, InferCtxtLike, WithInfcx}; use self::TyKind::*; -/// The movability of a coroutine / closure literal: -/// whether a coroutine contains self-references, causing it to be `!Unpin`. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] -#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))] -pub enum Movability { - /// May contain self-references, `!Unpin`. - Static, - /// Must not contain self-references, `Unpin`. - Movable, -} - -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] -#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))] -pub enum Mutability { - // N.B. Order is deliberate, so that Not < Mut - Not, - Mut, -} - -impl Mutability { - pub fn invert(self) -> Self { - match self { - Mutability::Mut => Mutability::Not, - Mutability::Not => Mutability::Mut, - } - } - - /// Returns `""` (empty string) or `"mut "` depending on the mutability. - pub fn prefix_str(self) -> &'static str { - match self { - Mutability::Mut => "mut ", - Mutability::Not => "", - } - } - - /// Returns `"&"` or `"&mut "` depending on the mutability. - pub fn ref_prefix_str(self) -> &'static str { - match self { - Mutability::Not => "&", - Mutability::Mut => "&mut ", - } - } - - /// Returns `""` (empty string) or `"mutably "` depending on the mutability. - pub fn mutably_str(self) -> &'static str { - match self { - Mutability::Not => "", - Mutability::Mut => "mutably ", - } - } - - /// Return `true` if self is mutable - pub fn is_mut(self) -> bool { - matches!(self, Self::Mut) - } - - /// Return `true` if self is **not** mutable - pub fn is_not(self) -> bool { - matches!(self, Self::Not) - } -} +use rustc_ast_ir::Mutability; /// Specifies how a trait object is represented. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] diff --git a/library/std/src/ffi/mod.rs b/library/std/src/ffi/mod.rs index 818571ddaaa16..f810611a02ecb 100644 --- a/library/std/src/ffi/mod.rs +++ b/library/std/src/ffi/mod.rs @@ -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")] @@ -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; diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index bbcbbc5284339..e44da8e637e98 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1,3 +1,5 @@ +//! The [`OsStr`] and [`OsString`] types and associated utilities. + #[cfg(test)] mod tests; @@ -1147,6 +1149,32 @@ impl OsStr { pub fn eq_ignore_ascii_case>(&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")] @@ -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) } } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 89fbd5c4c6454..56ea51226f9d5 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -84,7 +84,7 @@ use crate::rc::Rc; use crate::str::FromStr; use crate::sync::Arc; -use crate::ffi::{OsStr, OsString}; +use crate::ffi::{os_str, OsStr, OsString}; use crate::sys; use crate::sys::path::{is_sep_byte, is_verbatim_sep, parse_prefix, MAIN_SEP_STR}; @@ -2726,7 +2726,7 @@ impl Path { it returns an object that can be displayed"] #[inline] pub fn display(&self) -> Display<'_> { - Display { path: self } + Display { inner: self.inner.display() } } /// Queries the file system to get information about a file, directory, etc. @@ -3033,20 +3033,20 @@ impl fmt::Debug for Path { /// [`format!`]: crate::format #[stable(feature = "rust1", since = "1.0.0")] pub struct Display<'a> { - path: &'a Path, + inner: os_str::Display<'a>, } #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for Display<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(&self.path, f) + fmt::Debug::fmt(&self.inner, f) } } #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Display for Display<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.path.inner.display(f) + fmt::Display::fmt(&self.inner, f) } } diff --git a/library/std/src/sys/pal/unix/fs.rs b/library/std/src/sys/pal/unix/fs.rs index 086cdfe6e9434..422a99380cc59 100644 --- a/library/std/src/sys/pal/unix/fs.rs +++ b/library/std/src/sys/pal/unix/fs.rs @@ -576,7 +576,7 @@ impl FileAttr { Ok(SystemTime::new(ext.stx_btime.tv_sec, ext.stx_btime.tv_nsec as i64)) } else { Err(io::const_io_error!( - io::ErrorKind::Uncategorized, + io::ErrorKind::Unsupported, "creation time is not available for the filesystem", )) }; diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 973036a40982c..afd5eb42d019d 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -575,7 +575,7 @@ fn generate_macro_def_id_path( ExternalLocation::Local => { // `root_path` always end with a `/`. format!( - "{root_path}{crate_name}/{path}", + "{root_path}{path}", root_path = root_path.unwrap_or(""), path = path.iter().map(|p| p.as_str()).join("/") ) diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 1cdc792a819a8..aa5998876d9ab 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -136,6 +136,7 @@ fn can_merge(class1: Option, class2: Option, text: &str) -> bool { match (class1, class2) { (Some(c1), Some(c2)) => c1.is_equal_to(c2), (Some(Class::Ident(_)), None) | (None, Some(Class::Ident(_))) => true, + (Some(Class::Macro(_)), _) => false, (Some(_), None) | (None, Some(_)) => text.trim().is_empty(), (None, None) => true, } diff --git a/src/librustdoc/html/highlight/fixtures/sample.html b/src/librustdoc/html/highlight/fixtures/sample.html index aa735e81597c7..773afd5c2cc30 100644 --- a/src/librustdoc/html/highlight/fixtures/sample.html +++ b/src/librustdoc/html/highlight/fixtures/sample.html @@ -32,7 +32,7 @@ } } -macro_rules! bar { +macro_rules! bar { ($foo:tt) => {}; } diff --git a/src/tools/clippy/clippy_config/src/lib.rs b/src/tools/clippy/clippy_config/src/lib.rs index dab3119894a4d..3d5002f1780ae 100644 --- a/src/tools/clippy/clippy_config/src/lib.rs +++ b/src/tools/clippy/clippy_config/src/lib.rs @@ -6,7 +6,6 @@ clippy::missing_panics_doc, rustc::diagnostic_outside_of_impl, rustc::untranslatable_diagnostic, - rustc::untranslatable_diagnostic_trivial )] extern crate rustc_ast; diff --git a/tests/rustdoc-js-std/osstring-to-string.js b/tests/rustdoc-js-std/osstring-to-string.js index 17bb602a502af..3fdc0b9f24a3c 100644 --- a/tests/rustdoc-js-std/osstring-to-string.js +++ b/tests/rustdoc-js-std/osstring-to-string.js @@ -4,6 +4,6 @@ const EXPECTED = { 'query': 'OsString -> String', 'others': [ - { 'path': 'std::ffi::OsString', 'name': 'into_string' }, + { 'path': 'std::ffi::os_str::OsString', 'name': 'into_string' }, ] }; diff --git a/tests/rustdoc/auxiliary/jump-to-def-macro.rs b/tests/rustdoc/auxiliary/jump-to-def-macro.rs new file mode 100644 index 0000000000000..f442b9461e892 --- /dev/null +++ b/tests/rustdoc/auxiliary/jump-to-def-macro.rs @@ -0,0 +1,6 @@ +#[macro_export] +macro_rules! symbols { + ($name:ident = $value:expr) => { + pub const $name: isize = $value; + } +} diff --git a/tests/rustdoc/jump-to-def-macro.rs b/tests/rustdoc/jump-to-def-macro.rs new file mode 100644 index 0000000000000..e8e97a442dd10 --- /dev/null +++ b/tests/rustdoc/jump-to-def-macro.rs @@ -0,0 +1,15 @@ +//@ aux-build:jump-to-def-macro.rs +//@ build-aux-docs +//@ compile-flags: -Zunstable-options --generate-link-to-definition + +#![crate_name = "foo"] + +// @has 'src/foo/jump-to-def-macro.rs.html' + +#[macro_use] +extern crate jump_to_def_macro; + +// @has - '//a[@href="../../jump_to_def_macro/macro.symbols.html"]' 'symbols!' +symbols! { + A = 12 +} diff --git a/tests/rustdoc/source-code-highlight.rs b/tests/rustdoc/source-code-highlight.rs new file mode 100644 index 0000000000000..8d7c7782dc5b3 --- /dev/null +++ b/tests/rustdoc/source-code-highlight.rs @@ -0,0 +1,29 @@ +// We need this option to be enabled for the `foo` macro declaration to ensure +// that the link on the ident is not including whitespace characters. + +//@ compile-flags: -Zunstable-options --generate-link-to-definition +#![crate_name = "foo"] + +// @has 'src/foo/source-code-highlight.rs.html' + +// @hasraw - 'foo' +#[macro_export] +macro_rules! foo { + () => {} +} + +// @hasraw - 'foo!' +foo! {} + +// @hasraw - 'f' +#[rustfmt::skip] +pub fn f () {} +// @hasraw - 'Bar' +// @hasraw - 'Bar' +// @hasraw - 'u32' +#[rustfmt::skip] +pub struct Bar ( u32 ); +// @hasraw - 'Foo' +pub enum Foo { + A, +} diff --git a/tests/rustdoc/type-alias/primitive-local-link-121106.rs b/tests/rustdoc/type-alias/primitive-local-link-121106.rs new file mode 100644 index 0000000000000..c11d35d86464d --- /dev/null +++ b/tests/rustdoc/type-alias/primitive-local-link-121106.rs @@ -0,0 +1,19 @@ +#![crate_name = "foo"] + +#![feature(rustc_attrs)] + +// @has foo/primitive.i32.html '//h1' 'Primitive Type i32' +// @has foo/index.html '//a/@href' '../foo/index.html' +#[rustc_doc_primitive = "i32"] +mod i32 {} + +// @has foo/struct.Node.html '//a/@href' 'primitive.i32.html' +pub struct Node; + +impl Node { + pub fn edge(&self) -> i32 { 0 } +} + +// @!has foo/type.Alias.html '//a/@href' 'primitive.i32.html' +// @hasraw 'type.impl/foo/struct.Node.js' 'href=\"foo/primitive.i32.html\"' +pub type Alias = Node; diff --git a/tests/ui/attributes/unix_sigpipe/unix_sigpipe.rs b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-bare.rs similarity index 100% rename from tests/ui/attributes/unix_sigpipe/unix_sigpipe.rs rename to tests/ui/attributes/unix_sigpipe/unix_sigpipe-bare.rs diff --git a/tests/ui/attributes/unix_sigpipe/unix_sigpipe.stderr b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-bare.stderr similarity index 83% rename from tests/ui/attributes/unix_sigpipe/unix_sigpipe.stderr rename to tests/ui/attributes/unix_sigpipe/unix_sigpipe-bare.stderr index b18ec9abc3745..56218ed499ece 100644 --- a/tests/ui/attributes/unix_sigpipe/unix_sigpipe.stderr +++ b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-bare.stderr @@ -1,5 +1,5 @@ error: valid values for `#[unix_sigpipe = "..."]` are `inherit`, `sig_ign`, or `sig_dfl` - --> $DIR/unix_sigpipe.rs:3:1 + --> $DIR/unix_sigpipe-bare.rs:3:1 | LL | #[unix_sigpipe] | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-different-duplicates.rs b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-different-duplicates.rs new file mode 100644 index 0000000000000..294cb38526bd0 --- /dev/null +++ b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-different-duplicates.rs @@ -0,0 +1,5 @@ +#![feature(unix_sigpipe)] + +#[unix_sigpipe = "sig_ign"] +#[unix_sigpipe = "inherit"] //~ error: multiple `unix_sigpipe` attributes +fn main() {} diff --git a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-different-duplicates.stderr b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-different-duplicates.stderr new file mode 100644 index 0000000000000..c2a3b9f45f9ac --- /dev/null +++ b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-different-duplicates.stderr @@ -0,0 +1,14 @@ +error: multiple `unix_sigpipe` attributes + --> $DIR/unix_sigpipe-different-duplicates.rs:4:1 + | +LL | #[unix_sigpipe = "inherit"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/unix_sigpipe-different-duplicates.rs:3:1 + | +LL | #[unix_sigpipe = "sig_ign"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-duplicates.rs b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-duplicates.rs index 294cb38526bd0..eccb23021b6b8 100644 --- a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-duplicates.rs +++ b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-duplicates.rs @@ -1,5 +1,5 @@ #![feature(unix_sigpipe)] -#[unix_sigpipe = "sig_ign"] +#[unix_sigpipe = "inherit"] #[unix_sigpipe = "inherit"] //~ error: multiple `unix_sigpipe` attributes fn main() {} diff --git a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-duplicates.stderr b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-duplicates.stderr index 931aae96b0ff7..c86e54a1e532f 100644 --- a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-duplicates.stderr +++ b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-duplicates.stderr @@ -7,7 +7,7 @@ LL | #[unix_sigpipe = "inherit"] note: attribute also specified here --> $DIR/unix_sigpipe-duplicates.rs:3:1 | -LL | #[unix_sigpipe = "sig_ign"] +LL | #[unix_sigpipe = "inherit"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-not-used.rs b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-not-used.rs index 778e06cb3effe..b0044f5e91999 100644 --- a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-not-used.rs +++ b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-not-used.rs @@ -1,6 +1,9 @@ +//@ revisions: with_feature without_feature //@ run-pass //@ aux-build:sigpipe-utils.rs +#![cfg_attr(with_feature, feature(unix_sigpipe))] + fn main() { extern crate sigpipe_utils; diff --git a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-only-feature.rs b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-only-feature.rs deleted file mode 100644 index 6bbe4a8d0d688..0000000000000 --- a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-only-feature.rs +++ /dev/null @@ -1,13 +0,0 @@ -//@ run-pass -//@ aux-build:sigpipe-utils.rs - -#![feature(unix_sigpipe)] - -fn main() { - extern crate sigpipe_utils; - - // Only #![feature(unix_sigpipe)] is enabled, not #[unix_sigpipe = "..."]. - // This shall not change any behavior, so we still expect SIGPIPE to be - // ignored - sigpipe_utils::assert_sigpipe_handler(sigpipe_utils::SignalHandler::Ignore); -} diff --git a/tests/ui/attributes/unix_sigpipe/unix_sigpipe-error.rs b/tests/ui/attributes/unix_sigpipe/unix_sigpipe-sig_ign.rs similarity index 100% rename from tests/ui/attributes/unix_sigpipe/unix_sigpipe-error.rs rename to tests/ui/attributes/unix_sigpipe/unix_sigpipe-sig_ign.rs diff --git a/tests/ui/impl-trait/in-trait/async-and-ret-ref.rs b/tests/ui/impl-trait/in-trait/async-and-ret-ref.rs index e991b74a0f81a..e0a7aef2c5f44 100644 --- a/tests/ui/impl-trait/in-trait/async-and-ret-ref.rs +++ b/tests/ui/impl-trait/in-trait/async-and-ret-ref.rs @@ -5,7 +5,7 @@ trait T {} trait MyTrait { async fn foo() -> &'static impl T; - //~^ ERROR the associated type `::{opaque#0}` may not live long enough + //~^ ERROR the associated type `impl T` may not live long enough } fn main() {} diff --git a/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr b/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr index 15aa3cf54bbe5..19ffff9d3f2bd 100644 --- a/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr +++ b/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr @@ -1,10 +1,10 @@ -error[E0310]: the associated type `::{opaque#0}` may not live long enough +error[E0310]: the associated type `impl T` may not live long enough --> $DIR/async-and-ret-ref.rs:7:5 | LL | async fn foo() -> &'static impl T; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | - | the associated type `::{opaque#0}` must be valid for the static lifetime... + | the associated type `impl T` must be valid for the static lifetime... | ...so that the reference type `&'static impl T` does not outlive the data it points at error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr b/tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr index baee1b5db6e9c..fc3efb44ac76b 100644 --- a/tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr +++ b/tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr @@ -6,11 +6,11 @@ LL | fn bar() -> () {} | = help: the trait `std::fmt::Display` is not implemented for `()` = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead -note: required by a bound in `Foo::{opaque#0}` +note: required by a bound in `Foo::{synthetic#0}` --> $DIR/doesnt-satisfy.rs:2:22 | LL | fn bar() -> impl std::fmt::Display; - | ^^^^^^^^^^^^^^^^^ required by this bound in `Foo::{opaque#0}` + | ^^^^^^^^^^^^^^^^^ required by this bound in `Foo::{synthetic#0}` error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.rs b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.rs index a36799c3ebd46..ee9ecdda90289 100644 --- a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.rs +++ b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.rs @@ -9,7 +9,7 @@ trait Erased { impl Erased for T { fn f(&self) -> Box { Box::new(::f()) - //~^ ERROR the associated type `::{opaque#0}` may not live long enough + //~^ ERROR the associated type `impl Fn()` may not live long enough } } diff --git a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr index 5ec0ee38347aa..1f787c1842cf9 100644 --- a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr +++ b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr @@ -1,10 +1,10 @@ -error[E0310]: the associated type `::{opaque#0}` may not live long enough +error[E0310]: the associated type `impl Fn()` may not live long enough --> $DIR/missing-static-bound-from-impl.rs:11:9 | LL | Box::new(::f()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | - | the associated type `::{opaque#0}` must be valid for the static lifetime... + | the associated type `impl Fn()` must be valid for the static lifetime... | ...so that the type `impl Fn()` will meet its required lifetime bounds error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr b/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr index 638de01f91393..12725c3456fd5 100644 --- a/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr +++ b/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr @@ -5,11 +5,11 @@ LL | fn foo>(self) -> impl Foo { | ^^^^^^^^^^^^ the trait `Foo` is not implemented for `impl Foo` | = help: the trait `Foo` is implemented for `Bar` -note: required by a bound in `Foo::{opaque#0}` +note: required by a bound in `Foo::{synthetic#0}` --> $DIR/return-dont-satisfy-bounds.rs:2:30 | LL | fn foo(self) -> impl Foo; - | ^^^^^^ required by this bound in `Foo::{opaque#0}` + | ^^^^^^ required by this bound in `Foo::{synthetic#0}` error[E0276]: impl has stricter requirements than trait --> $DIR/return-dont-satisfy-bounds.rs:8:16 diff --git a/tests/ui/imports/auxiliary/import-alias-issue-121168-extern.rs b/tests/ui/imports/auxiliary/import-alias-issue-121168-extern.rs new file mode 100644 index 0000000000000..a665eb8eb96aa --- /dev/null +++ b/tests/ui/imports/auxiliary/import-alias-issue-121168-extern.rs @@ -0,0 +1 @@ +pub struct Foo(pub core::ptr::NonNull); diff --git a/tests/ui/imports/import-alias-issue-121168.edition2015.stderr b/tests/ui/imports/import-alias-issue-121168.edition2015.stderr new file mode 100644 index 0000000000000..47001fc1a5291 --- /dev/null +++ b/tests/ui/imports/import-alias-issue-121168.edition2015.stderr @@ -0,0 +1,14 @@ +error[E0412]: cannot find type `Foo` in this scope + --> $DIR/import-alias-issue-121168.rs:11:12 + | +LL | let _: Foo = todo!(); + | ^^^ not found in this scope + | +help: consider importing this struct + | +LL + use nice_crate_name::Foo; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/imports/import-alias-issue-121168.edition2018.stderr b/tests/ui/imports/import-alias-issue-121168.edition2018.stderr new file mode 100644 index 0000000000000..b61a0e3edd524 --- /dev/null +++ b/tests/ui/imports/import-alias-issue-121168.edition2018.stderr @@ -0,0 +1,16 @@ +error[E0412]: cannot find type `Foo` in this scope + --> $DIR/import-alias-issue-121168.rs:11:12 + | +LL | let _: Foo = todo!(); + | ^^^ not found in this scope + | +help: consider importing one of these items + | +LL + use crate::nice_crate_name::Foo; + | +LL + use import_alias_issue_121168_extern::Foo; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/imports/import-alias-issue-121168.edition2021.stderr b/tests/ui/imports/import-alias-issue-121168.edition2021.stderr new file mode 100644 index 0000000000000..b61a0e3edd524 --- /dev/null +++ b/tests/ui/imports/import-alias-issue-121168.edition2021.stderr @@ -0,0 +1,16 @@ +error[E0412]: cannot find type `Foo` in this scope + --> $DIR/import-alias-issue-121168.rs:11:12 + | +LL | let _: Foo = todo!(); + | ^^^ not found in this scope + | +help: consider importing one of these items + | +LL + use crate::nice_crate_name::Foo; + | +LL + use import_alias_issue_121168_extern::Foo; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/imports/import-alias-issue-121168.rs b/tests/ui/imports/import-alias-issue-121168.rs new file mode 100644 index 0000000000000..826a6765b0399 --- /dev/null +++ b/tests/ui/imports/import-alias-issue-121168.rs @@ -0,0 +1,14 @@ +//@ revisions: edition2015 edition2018 edition2021 +//@ [edition2015] edition:2015 +//@ [edition2018] edition:2018 +//@ [edition2021] edition:2021 +//@ compile-flags: --extern import_alias_issue_121168_extern +//@ aux-build: import-alias-issue-121168-extern.rs + +extern crate import_alias_issue_121168_extern as nice_crate_name; + +fn use_foo_from_another_crate_without_importing_it_first() { + let _: Foo = todo!(); //~ ERROR cannot find type `Foo` in this scope +} + +fn main() {} diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr index 3fbbfd0fd0dbf..b17700ec6325d 100644 --- a/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr +++ b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr @@ -4,11 +4,11 @@ error[E0277]: the trait bound `Something: Termination` is not satisfied LL | fn main() -> Something { | ^^^^^^^^^ the trait `Termination` is not implemented for `Something` | -note: required by a bound in `Main::{opaque#0}` +note: required by a bound in `Main::{synthetic#0}` --> $DIR/issue-103052-2.rs:5:27 | LL | fn main() -> impl std::process::Termination; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Main::{opaque#0}` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Main::{synthetic#0}` error: aborting due to 1 previous error diff --git a/tests/ui/sanitize/sanitizer-cfi-is-incompatible-with-saniziter-kcfi.aarch64.stderr b/tests/ui/sanitize/sanitizer-cfi-is-incompatible-with-sanitizer-kcfi.aarch64.stderr similarity index 100% rename from tests/ui/sanitize/sanitizer-cfi-is-incompatible-with-saniziter-kcfi.aarch64.stderr rename to tests/ui/sanitize/sanitizer-cfi-is-incompatible-with-sanitizer-kcfi.aarch64.stderr diff --git a/tests/ui/sanitize/sanitizer-cfi-is-incompatible-with-saniziter-kcfi.rs b/tests/ui/sanitize/sanitizer-cfi-is-incompatible-with-sanitizer-kcfi.rs similarity index 100% rename from tests/ui/sanitize/sanitizer-cfi-is-incompatible-with-saniziter-kcfi.rs rename to tests/ui/sanitize/sanitizer-cfi-is-incompatible-with-sanitizer-kcfi.rs diff --git a/tests/ui/sanitize/sanitizer-cfi-is-incompatible-with-saniziter-kcfi.x86_64.stderr b/tests/ui/sanitize/sanitizer-cfi-is-incompatible-with-sanitizer-kcfi.x86_64.stderr similarity index 100% rename from tests/ui/sanitize/sanitizer-cfi-is-incompatible-with-saniziter-kcfi.x86_64.stderr rename to tests/ui/sanitize/sanitizer-cfi-is-incompatible-with-sanitizer-kcfi.x86_64.stderr diff --git a/tests/ui/traits/next-solver/constrain-alias-goals-in-unsize.rs b/tests/ui/traits/next-solver/constrain-alias-goals-in-unsize.rs new file mode 100644 index 0000000000000..1656238bd6188 --- /dev/null +++ b/tests/ui/traits/next-solver/constrain-alias-goals-in-unsize.rs @@ -0,0 +1,18 @@ +//@ compile-flags: -Znext-solver +//@ check-pass + +use std::mem::ManuallyDrop; + +trait Foo {} + +struct Guard { + value: ManuallyDrop, +} + +impl Guard { + fn uwu(&self) { + let x: &dyn Foo = &*self.value; + } +} + +fn main() {}