diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 26d98ec13cc2b..e3b8af5e8c4db 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1044,7 +1044,7 @@ fn visibility_di_flags<'ll, 'tcx>( match visibility { Visibility::Public => DIFlags::FlagPublic, // Private fields have a restricted visibility of the module containing the type. - Visibility::Restricted(did) if did == parent_did => DIFlags::FlagPrivate, + Visibility::Restricted(did) if did.to_def_id() == parent_did => DIFlags::FlagPrivate, // `pub(crate)`/`pub(super)` visibilities are any other restricted visibility. Visibility::Restricted(..) => DIFlags::FlagProtected, } diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 3cf39a68aa3bb..3d8b4616f37fd 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -24,7 +24,7 @@ use rustc_parse::MACRO_ARGUMENTS; use rustc_parse::parser::Parser; use rustc_session::Session; use rustc_session::parse::ParseSess; -use rustc_span::def_id::{CrateNum, DefId, LocalDefId}; +use rustc_span::def_id::{CrateNum, DefId, LocalDefId, ModId}; use rustc_span::edition::Edition; use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind}; use rustc_span::source_map::SourceMap; @@ -274,11 +274,7 @@ impl<'cx> MacroExpanderResult<'cx> { arm_span: Span, macro_ident: Ident, ) -> Self { - // Emit the SEMICOLON_IN_EXPRESSIONS_FROM_MACROS deprecation lint. - let is_local = true; - - let parser = - ParserAnyMacro::from_tts(cx, tts, site_span, arm_span, is_local, macro_ident, &[], &[]); + let parser = ParserAnyMacro::from_tts(cx, tts, site_span, arm_span, macro_ident, &[], &[]); ExpandResult::Ready(Box::new(parser)) } } @@ -998,7 +994,7 @@ impl SyntaxExtension { descr: Symbol, kind: MacroKind, macro_def_id: Option, - parent_module: Option, + parent_module: Option, ) -> ExpnData { ExpnData::new( ExpnKind::Macro(kind, descr), diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index cc4e08e2877b6..0fced30420ebd 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -55,8 +55,6 @@ pub(crate) struct ParserAnyMacro<'a, 'b> { lint_node_id: NodeId, is_trailing_mac: bool, arm_span: Span, - /// Whether or not this macro is defined in the current crate - is_local: bool, bindings: &'b [MacroRule], matched_rule_bindings: &'b [MatcherLoc], } @@ -73,7 +71,6 @@ impl<'a, 'b> ParserAnyMacro<'a, 'b> { lint_node_id, arm_span, is_trailing_mac, - is_local, bindings, matched_rule_bindings, } = *self; @@ -99,14 +96,12 @@ impl<'a, 'b> ParserAnyMacro<'a, 'b> { // `macro_rules! m { () => { panic!(); } }` isn't parsed by `.parse_expr()`, // but `m!()` is allowed in expression positions (cf. issue #34706). if kind == AstFragmentKind::Expr && parser.token == token::Semi { - if is_local { - parser.psess.buffer_lint( - SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, - parser.token.span, - lint_node_id, - diagnostics::TrailingMacro { is_trailing: is_trailing_mac, name: macro_ident }, - ); - } + parser.psess.buffer_lint( + SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, + parser.token.span, + lint_node_id, + diagnostics::TrailingMacro { is_trailing: is_trailing_mac, name: macro_ident }, + ); parser.bump(); } @@ -122,7 +117,6 @@ impl<'a, 'b> ParserAnyMacro<'a, 'b> { tts: TokenStream, site_span: Span, arm_span: Span, - is_local: bool, macro_ident: Ident, // bindings and lhs is for diagnostics bindings: &'b [MacroRule], @@ -139,7 +133,6 @@ impl<'a, 'b> ParserAnyMacro<'a, 'b> { lint_node_id: cx.current_expansion.lint_node_id, is_trailing_mac: cx.current_expansion.is_trailing_mac, arm_span, - is_local, bindings, matched_rule_bindings, } @@ -471,13 +464,12 @@ fn expand_macro<'cx, 'a: 'cx>( trace_macros_note(&mut cx.expansions, sp, msg); } - let is_local = is_defined_in_current_crate(node_id); - if is_local { + if is_defined_in_current_crate(node_id) { cx.resolver.record_macro_rule_usage(node_id, rule_index); } // Let the context choose how to interpret the result. Weird, but useful for X-macros. - Box::new(ParserAnyMacro::from_tts(cx, tts, sp, arm_span, is_local, name, rules, lhs)) + Box::new(ParserAnyMacro::from_tts(cx, tts, sp, arm_span, name, rules, lhs)) } Err(CanRetry::No(guar)) => { debug!("Will not retry matching as an error was emitted already"); diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 5cdf7e920949b..96e89a8d8cdb6 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -342,7 +342,7 @@ pub trait Visitor<'v>: Sized { fn visit_pat_expr(&mut self, expr: &'v PatExpr<'v>) -> Self::Result { walk_pat_expr(self, expr) } - fn visit_lit(&mut self, _hir_id: HirId, _lit: Lit, _negated: bool) -> Self::Result { + fn visit_lit(&mut self, _hir_id: HirId, _lit: Lit, _is_negated_pat: bool) -> Self::Result { Self::Result::output() } fn visit_anon_const(&mut self, c: &'v AnonConst) -> Self::Result { diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index 074196b0f959e..70ab2cc44e0c6 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -12,6 +12,7 @@ use rustc_middle::ty::{ TypeVisitableExt, TypeVisitor, TypingMode, Unnormalized, }; use rustc_span::Span; +use rustc_span::def_id::ModId; use rustc_trait_selection::regions::InferCtxtRegionExt; use rustc_trait_selection::traits::{ObligationCtxt, elaborate, normalize_param_env_or_error}; @@ -380,7 +381,7 @@ fn report_mismatched_rpitit_signature<'tcx>( ); } -fn type_visibility<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> { +fn type_visibility<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> { match *ty.kind() { ty::Ref(_, ty, _) => type_visibility(tcx, ty), ty::Adt(def, args) => { diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 5778a0f932374..29c0786e66f93 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -45,6 +45,7 @@ use rustc_middle::ty::{ use rustc_middle::{bug, span_bug}; use rustc_session::diagnostics::feature_err; use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS; +use rustc_span::def_id::ModId; use rustc_span::{DUMMY_SP, Ident, Span, kw, sym}; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::{self, FulfillmentError}; @@ -116,7 +117,7 @@ pub enum RegionInferReason<'a> { pub struct InherentAssocCandidate { pub impl_: DefId, pub assoc_item: DefId, - pub scope: DefId, + pub scope: ModId, } pub struct ResolvedStructPath<'tcx> { @@ -1806,7 +1807,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ident: Ident, assoc_tag: ty::AssocTag, scope: DefId, - ) -> Option<(ty::AssocItem, /*scope*/ DefId)> { + ) -> Option<(ty::AssocItem, /*scope*/ ModId)> { let tcx = self.tcx(); let (ident, def_scope) = tcx.adjust_ident_and_get_scope(ident, scope, self.item_def_id()); @@ -1826,7 +1827,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { &self, item_def_id: DefId, ident: Ident, - scope: DefId, + scope: ModId, block: HirId, span: Span, ) { diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index ea0f8f22ab187..c34005d2ea7f5 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1192,7 +1192,7 @@ impl UnreachablePub { && let parent_parent = cx .tcx .parent_module_from_def_id(cx.tcx.parent_module_from_def_id(def_id).into()) - && *restricted_did == parent_parent.to_local_def_id() + && *restricted_did == parent_parent && !restricted_did.to_def_id().is_crate_root() { "pub(super)" diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index c17fe6f2e510f..b8eb4910df248 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -8,7 +8,7 @@ use std::cell::Cell; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::sync::par_join; -use rustc_hir::def_id::{LocalDefId, LocalModDefId}; +use rustc_hir::def_id::{LocalDefId, LocalModId}; use rustc_hir::{self as hir, AmbigArg, HirId, intravisit as hir_visit}; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, TyCtxt}; @@ -151,8 +151,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas hir_visit::walk_pat(self, p); } - fn visit_lit(&mut self, hir_id: HirId, lit: hir::Lit, negated: bool) { - lint_callback!(self, check_lit, hir_id, lit, negated); + fn visit_lit(&mut self, hir_id: HirId, lit: hir::Lit, is_negated_pat: bool) { + lint_callback!(self, check_lit, hir_id, lit, is_negated_pat); } fn visit_expr_field(&mut self, field: &'tcx hir::ExprField<'tcx>) { @@ -335,7 +335,7 @@ crate::late_lint_methods!(impl_late_lint_pass, []); pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>( tcx: TyCtxt<'tcx>, - module_def_id: LocalModDefId, + mod_id: LocalModId, builtin_lints: T, ) { let context = LateContext { @@ -344,7 +344,7 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>( cached_typeck_results: Cell::new(None), param_env: ty::ParamEnv::empty(), effective_visibilities: tcx.effective_visibilities(()), - last_node_with_lint_attrs: tcx.local_def_id_to_hir_id(module_def_id), + last_node_with_lint_attrs: tcx.local_def_id_to_hir_id(mod_id), generics: None, only_module: true, }; @@ -363,26 +363,26 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>( let builtin_lints_must_run = is_lint_pass_required(skippable_lints, &builtin_lints.get_lints()); if passes.is_empty() { if builtin_lints_must_run { - late_lint_mod_inner(tcx, module_def_id, context, builtin_lints); + late_lint_mod_inner(tcx, mod_id, context, builtin_lints); } } else { if builtin_lints_must_run { passes.push(Box::new(builtin_lints) as Box>); } let pass = RuntimeCombinedLateLintPass { passes }; - late_lint_mod_inner(tcx, module_def_id, context, pass); + late_lint_mod_inner(tcx, mod_id, context, pass); } } fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>( tcx: TyCtxt<'tcx>, - module_def_id: LocalModDefId, + mod_id: LocalModId, context: LateContext<'tcx>, pass: T, ) { let mut cx = LateContextAndPass { context, pass }; - let (module, _span, hir_id) = tcx.hir_get_module(module_def_id); + let (module, _span, hir_id) = tcx.hir_get_module(mod_id); cx.with_lint_attrs(hir_id, |cx| { // There is no module lint that will have the crate itself as an item, so check it here. diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index eaf9360cc3358..5271217593e62 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -121,7 +121,7 @@ use redundant_semicolon::*; use reference_casting::*; use runtime_symbols::*; use rustc_data_structures::unord::UnordSet; -use rustc_hir::def_id::LocalModDefId; +use rustc_hir::def_id::LocalModId; use rustc_middle::query::Providers; use rustc_middle::ty::TyCtxt; use shadowed_into_iter::ShadowedIntoIter; @@ -154,8 +154,8 @@ pub fn provide(providers: &mut Providers) { *providers = Providers { lint_mod, ..*providers }; } -fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { - late_lint_mod(tcx, module_def_id, BuiltinCombinedLateLintModPass::new()); +fn lint_mod(tcx: TyCtxt<'_>, mod_id: LocalModId) { + late_lint_mod(tcx, mod_id, BuiltinCombinedLateLintModPass::new()); } early_lint_methods!( diff --git a/compiler/rustc_lint/src/passes.rs b/compiler/rustc_lint/src/passes.rs index 12cf58907566d..a1133a9a6ec29 100644 --- a/compiler/rustc_lint/src/passes.rs +++ b/compiler/rustc_lint/src/passes.rs @@ -21,7 +21,7 @@ macro_rules! late_lint_methods { fn check_stmt(a: &'tcx rustc_hir::Stmt<'tcx>); fn check_arm(a: &'tcx rustc_hir::Arm<'tcx>); fn check_pat(a: &'tcx rustc_hir::Pat<'tcx>); - fn check_lit(hir_id: rustc_hir::HirId, a: rustc_hir::Lit, negated: bool); + fn check_lit(hir_id: rustc_hir::HirId, a: rustc_hir::Lit, is_negated_pat: bool); fn check_expr(a: &'tcx rustc_hir::Expr<'tcx>); fn check_expr_post(a: &'tcx rustc_hir::Expr<'tcx>); fn check_ty(a: &'tcx rustc_hir::Ty<'tcx, rustc_hir::AmbigArg>); diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 58599db734c49..083d2e4ee0499 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -194,10 +194,15 @@ declare_lint! { #[derive(Copy, Clone, Default)] pub(crate) struct TypeLimits { - /// Id of the last visited negated expression - negated_expr_id: Option, - /// Span of the last visited negated expression - negated_expr_span: Option, + last_visited_negation: Option, +} + +#[derive(Copy, Clone)] +struct NegationInfo { + /// A negation expression (a `rustc_hir::ExprKind::Unary`) + negation_span: Span, + /// The operand of the negation expression. + negated_id: hir::HirId, } impl_lint_pass!(TypeLimits => [ @@ -210,7 +215,7 @@ impl_lint_pass!(TypeLimits => [ impl TypeLimits { pub(crate) fn new() -> TypeLimits { - TypeLimits { negated_expr_id: None, negated_expr_span: None } + TypeLimits { last_visited_negation: None } } } @@ -539,22 +544,32 @@ fn lint_fn_pointer<'tcx>( } impl<'tcx> LateLintPass<'tcx> for TypeLimits { - fn check_lit(&mut self, cx: &LateContext<'tcx>, hir_id: HirId, lit: hir::Lit, negated: bool) { - if negated { - self.negated_expr_id = Some(hir_id); - self.negated_expr_span = Some(lit.span); - } - lint_literal(cx, self, hir_id, lit.span, &lit, negated); + fn check_lit( + &mut self, + cx: &LateContext<'tcx>, + hir_id: HirId, + lit: hir::Lit, + is_negated_pat: bool, + ) { + let surrounding_negation = if is_negated_pat { + // In this case, lit.span refers to a `rustc_hir::hir::PatExprKind::Lit`, + // which includes the minus sign in front. + Some(lit.span) + } else if let Some(negation_info) = self.last_visited_negation + && negation_info.negated_id == hir_id + { + Some(negation_info.negation_span) + } else { + None + }; + lint_literal(cx, hir_id, lit.span, &lit, surrounding_negation); } fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx hir::Expr<'tcx>) { match e.kind { hir::ExprKind::Unary(hir::UnOp::Neg, expr) => { - // Propagate negation, if the negation itself isn't negated - if self.negated_expr_id != Some(e.hir_id) { - self.negated_expr_id = Some(expr.hir_id); - self.negated_expr_span = Some(e.span); - } + self.last_visited_negation = + Some(NegationInfo { negation_span: e.span, negated_id: expr.hir_id }); } hir::ExprKind::Binary(binop, ref l, ref r) => { if is_comparison(binop.node) { diff --git a/compiler/rustc_lint/src/types/literal.rs b/compiler/rustc_lint/src/types/literal.rs index 45d79fec75ae9..bed26ee6f3d25 100644 --- a/compiler/rustc_lint/src/types/literal.rs +++ b/compiler/rustc_lint/src/types/literal.rs @@ -17,7 +17,7 @@ use crate::lints::{ OverflowingBinHexSub, OverflowingInt, OverflowingIntHelp, OverflowingLiteral, OverflowingUInt, RangeEndpointOutOfRange, SurrogateCharCast, TooLargeCharCast, UseInclusiveRange, }; -use crate::types::{OVERFLOWING_LITERALS, TypeLimits}; +use crate::types::OVERFLOWING_LITERALS; /// Attempts to special-case the overflowing literal lint when it occurs as a range endpoint (`expr..MAX+1`). /// Returns `true` iff the lint was emitted. @@ -260,17 +260,17 @@ fn literal_to_i128(val: u128, negative: bool) -> Option { fn lint_int_literal<'tcx>( cx: &LateContext<'tcx>, - type_limits: &TypeLimits, hir_id: HirId, span: Span, lit: &hir::Lit, t: ty::IntTy, v: u128, + surrounding_negation: Option, ) { let int_type = t.normalize(cx.sess().target.pointer_width); let (min, max) = int_ty_range(int_type); let max = max as u128; - let negative = type_limits.negated_expr_id == Some(hir_id); + let negative = surrounding_negation.is_some(); // Detect literal value out of range [min, max] inclusive // avoiding use of -min to prevent overflow/panic @@ -294,7 +294,7 @@ fn lint_int_literal<'tcx>( return; } - let span = if negative { type_limits.negated_expr_span.unwrap() } else { span }; + let span = surrounding_negation.unwrap_or(span); let lit = cx .sess() .source_map() @@ -400,23 +400,22 @@ fn float_is_infinite(v: Symbol) -> Option { pub(crate) fn lint_literal<'tcx>( cx: &LateContext<'tcx>, - type_limits: &TypeLimits, hir_id: HirId, span: Span, lit: &hir::Lit, - negated: bool, + surrounding_negation: Option, ) { match *cx.typeck_results().node_type(hir_id).kind() { ty::Int(t) => { match lit.node { ast::LitKind::Int(v, ast::LitIntType::Signed(_) | ast::LitIntType::Unsuffixed) => { - lint_int_literal(cx, type_limits, hir_id, span, lit, t, v.get()) + lint_int_literal(cx, hir_id, span, lit, t, v.get(), surrounding_negation) } _ => bug!(), }; } ty::Uint(t) => { - assert!(!negated); + assert!(surrounding_negation.is_none()); lint_uint_literal(cx, hir_id, span, lit, t) } ty::Float(t) => { diff --git a/compiler/rustc_lint/src/unused/must_use.rs b/compiler/rustc_lint/src/unused/must_use.rs index c7177f1829bbd..e72335c80d505 100644 --- a/compiler/rustc_lint/src/unused/must_use.rs +++ b/compiler/rustc_lint/src/unused/must_use.rs @@ -143,7 +143,7 @@ pub fn is_ty_must_use<'tcx>( return IsTyMustUse::Trivial; } - let parent_mod_did = cx.tcx.parent_module(expr.hir_id).to_def_id(); + let parent_mod_did = cx.tcx.parent_module(expr.hir_id); let is_uninhabited = |t: Ty<'tcx>| !t.is_inhabited_from(cx.tcx, parent_mod_did, cx.typing_env()); diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index bed2be51a3468..5719d6610b6bc 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -32,6 +32,7 @@ use rustc_serialize::{Decodable, Decoder}; use rustc_session::config::TargetModifier; use rustc_session::config::mitigation_coverage::DeniedPartialMitigation; use rustc_session::cstore::{CrateSource, ExternCrate}; +use rustc_span::def_id::ModId; use rustc_span::hygiene::HygieneDecodeContext; use rustc_span::{ BlobDecoder, BytePos, ByteSymbol, DUMMY_SP, Pos, RemapPathScopeComponents, SpanData, @@ -1173,14 +1174,14 @@ impl CrateMetadata { ) } - fn get_visibility(&self, tcx: TyCtxt<'_>, id: DefIndex) -> Visibility { + fn get_visibility(&self, tcx: TyCtxt<'_>, id: DefIndex) -> Visibility { self.root .tables .visibility .get(self, id) .unwrap_or_else(|| self.missing("visibility", id)) .decode((self, tcx)) - .map_id(|index| self.local_def_id(index)) + .map_id(|index| ModId::new_unchecked(self.local_def_id(index))) } fn get_safety(&self, id: DefIndex) -> Safety { diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 798709d69d76e..69f7540c08e83 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -19,6 +19,7 @@ use rustc_middle::util::Providers; use rustc_serialize::Decoder; use rustc_session::StableCrateId; use rustc_session::cstore::{CrateStore, ExternCrate}; +use rustc_span::def_id::ModId; use rustc_span::hygiene::ExpnId; use rustc_span::{Span, Symbol, kw}; @@ -191,6 +192,13 @@ impl IntoArgs for DefId { } } +impl IntoArgs for ModId { + type Other = (); + fn into_args(self) -> (DefId, ()) { + (self.to_def_id(), ()) + } +} + impl IntoArgs for CrateNum { type Other = (); fn into_args(self) -> (DefId, ()) { diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index cd5e343e08d1a..90ee009facacd 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -28,6 +28,7 @@ use rustc_middle::{bug, span_bug}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque}; use rustc_session::config::mitigation_coverage::DeniedPartialMitigation; use rustc_session::config::{CrateType, OptLevel, TargetModifier}; +use rustc_span::def_id::CRATE_MOD_ID; use rustc_span::hygiene::HygieneEncodeContext; use rustc_span::{ ByteSymbol, ExternalSource, FileName, SourceFile, SpanData, SpanEncoder, StableSourceFileId, @@ -1455,8 +1456,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id)); } if should_encode_visibility(def_kind) { - let vis = - self.tcx.local_visibility(local_id).map_id(|def_id| def_id.local_def_index); + let vis = self + .tcx + .local_visibility(local_id) + .map_id(|mod_id| mod_id.to_local_def_id().local_def_index); record!(self.tables.visibility[def_id] <- vis); } if should_encode_stability(def_kind) { @@ -1979,16 +1982,18 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { self.tables.def_kind.set_some(LOCAL_CRATE.as_def_id().index, DefKind::Mod); record!(self.tables.def_span[LOCAL_CRATE.as_def_id()] <- tcx.def_span(LOCAL_CRATE.as_def_id())); self.encode_attrs(LOCAL_CRATE.as_def_id().expect_local()); - let vis = tcx.local_visibility(CRATE_DEF_ID).map_id(|def_id| def_id.local_def_index); + let vis = tcx + .local_visibility(CRATE_DEF_ID) + .map_id(|mod_id| mod_id.to_local_def_id().local_def_index); record!(self.tables.visibility[LOCAL_CRATE.as_def_id()] <- vis); if let Some(stability) = stability { record!(self.tables.lookup_stability[LOCAL_CRATE.as_def_id()] <- stability); } self.encode_deprecation(LOCAL_CRATE.as_def_id()); - if let Some(res_map) = tcx.resolutions(()).doc_link_resolutions.get(&CRATE_DEF_ID) { + if let Some(res_map) = tcx.resolutions(()).doc_link_resolutions.get(&CRATE_MOD_ID) { record!(self.tables.doc_link_resolutions[LOCAL_CRATE.as_def_id()] <- res_map); } - if let Some(traits) = tcx.resolutions(()).doc_link_traits_in_scope.get(&CRATE_DEF_ID) { + if let Some(traits) = tcx.resolutions(()).doc_link_traits_in_scope.get(&CRATE_MOD_ID) { record_array!(self.tables.doc_link_traits_in_scope[LOCAL_CRATE.as_def_id()] <- traits); } diff --git a/compiler/rustc_middle/src/dep_graph/dep_node_key.rs b/compiler/rustc_middle/src/dep_graph/dep_node_key.rs index 618b061442d43..870864da2714b 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node_key.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node_key.rs @@ -2,7 +2,7 @@ use std::fmt::Debug; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hash::{StableHash, StableHasher}; -use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId, ModDefId}; +use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModId, ModId}; use rustc_hir::definitions::DefPathHash; use rustc_hir::{HirId, ItemLocalId, OwnerId}; @@ -194,7 +194,7 @@ impl<'tcx> DepNodeKey<'tcx> for HirId { } } -impl<'tcx> DepNodeKey<'tcx> for ModDefId { +impl<'tcx> DepNodeKey<'tcx> for ModId { #[inline(always)] fn key_fingerprint_style() -> KeyFingerprintStyle { KeyFingerprintStyle::DefPathHash @@ -207,11 +207,11 @@ impl<'tcx> DepNodeKey<'tcx> for ModDefId { #[inline(always)] fn try_recover_key(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option { - DefId::try_recover_key(tcx, dep_node).map(ModDefId::new_unchecked) + DefId::try_recover_key(tcx, dep_node).map(ModId::new_unchecked) } } -impl<'tcx> DepNodeKey<'tcx> for LocalModDefId { +impl<'tcx> DepNodeKey<'tcx> for LocalModId { #[inline(always)] fn key_fingerprint_style() -> KeyFingerprintStyle { KeyFingerprintStyle::DefPathHash @@ -224,6 +224,6 @@ impl<'tcx> DepNodeKey<'tcx> for LocalModDefId { #[inline(always)] fn try_recover_key(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option { - LocalDefId::try_recover_key(tcx, dep_node).map(LocalModDefId::new_unchecked) + LocalDefId::try_recover_key(tcx, dep_node).map(LocalModId::new_unchecked) } } diff --git a/compiler/rustc_middle/src/hir/map.rs b/compiler/rustc_middle/src/hir/map.rs index 82c0503d5468b..c01d9e98e9b9c 100644 --- a/compiler/rustc_middle/src/hir/map.rs +++ b/compiler/rustc_middle/src/hir/map.rs @@ -10,13 +10,13 @@ use rustc_data_structures::steal::Steal; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::{DynSend, DynSync, par_for_each_in, try_par_for_each_in}; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId, LocalModDefId}; +use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId, LocalModId}; use rustc_hir::definitions::{DefKey, DefPath, DefPathHash}; use rustc_hir::intravisit::Visitor; use rustc_hir::lints::DelayedLints; use rustc_hir::*; use rustc_hir_pretty as pprust_hir; -use rustc_span::def_id::StableCrateId; +use rustc_span::def_id::{CRATE_MOD_ID, StableCrateId}; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, with_metavar_spans}; use crate::hir::{ModuleItems, ProjectedMaybeOwner, nested_filter}; @@ -207,7 +207,7 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] - pub fn hir_module_free_items(self, module: LocalModDefId) -> impl Iterator { + pub fn hir_module_free_items(self, module: LocalModId) -> impl Iterator { self.hir_module_items(module).free_items() } @@ -412,7 +412,7 @@ impl<'tcx> TyCtxt<'tcx> { find_attr!(self.hir_krate_attrs(), RustcCoherenceIsCore) } - pub fn hir_get_module(self, module: LocalModDefId) -> (&'tcx Mod<'tcx>, Span, HirId) { + pub fn hir_get_module(self, module: LocalModId) -> (&'tcx Mod<'tcx>, Span, HirId) { let hir_id = HirId::make_owner(module.to_local_def_id()); match self.hir_owner_node(hir_id.owner) { OwnerNode::Item(&Item { span, kind: ItemKind::Mod(_, m), .. }) => (m, span, hir_id), @@ -426,7 +426,7 @@ impl<'tcx> TyCtxt<'tcx> { where V: Visitor<'tcx>, { - let (top_mod, span, hir_id) = self.hir_get_module(LocalModDefId::CRATE_DEF_ID); + let (top_mod, span, hir_id) = self.hir_get_module(CRATE_MOD_ID); visitor.visit_mod(top_mod, span, hir_id) } @@ -477,11 +477,7 @@ impl<'tcx> TyCtxt<'tcx> { /// This method is the equivalent of `visit_all_item_likes_in_crate` but restricted to /// item-likes in a single module. - pub fn hir_visit_item_likes_in_module( - self, - module: LocalModDefId, - visitor: &mut V, - ) -> V::Result + pub fn hir_visit_item_likes_in_module(self, module: LocalModId, visitor: &mut V) -> V::Result where V: Visitor<'tcx>, { @@ -501,30 +497,26 @@ impl<'tcx> TyCtxt<'tcx> { V::Result::output() } - pub fn hir_for_each_module(self, mut f: impl FnMut(LocalModDefId)) { + pub fn hir_for_each_module(self, mut f: impl FnMut(LocalModId)) { let crate_items = self.hir_crate_items(()); - for module in crate_items.submodules.iter() { - f(LocalModDefId::new_unchecked(module.def_id)) + for &module in crate_items.submodules.iter() { + f(module) } } #[inline] - pub fn par_hir_for_each_module(self, f: impl Fn(LocalModDefId) + DynSend + DynSync) { + pub fn par_hir_for_each_module(self, f: impl Fn(LocalModId) + DynSend + DynSync) { let crate_items = self.hir_crate_items(()); - par_for_each_in(&crate_items.submodules[..], |module| { - f(LocalModDefId::new_unchecked(module.def_id)) - }) + par_for_each_in(&crate_items.submodules[..], |&&module| f(module)); } #[inline] pub fn try_par_hir_for_each_module( self, - f: impl Fn(LocalModDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync, + f: impl Fn(LocalModId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync, ) -> Result<(), ErrorGuaranteed> { let crate_items = self.hir_crate_items(()); - try_par_for_each_in(&crate_items.submodules[..], |module| { - f(LocalModDefId::new_unchecked(module.def_id)) - }) + try_par_for_each_in(&crate_items.submodules[..], |&&module| f(module)) } /// Returns an iterator for the nodes in the ancestor tree of the `current_id` @@ -1261,7 +1253,7 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> { upstream_crates } -pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> ModuleItems { +pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModId) -> ModuleItems { let mut collector = ItemCollector::new(tcx, false); let (hir_mod, span, hir_id) = tcx.hir_get_module(module_id); @@ -1302,7 +1294,7 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems { // A "crate collector" and "module collector" start at a // module item (the former starts at the crate root) but only // the former needs to collect it. ItemCollector does not do this for us. - collector.submodules.push(CRATE_OWNER_ID); + collector.submodules.push(CRATE_MOD_ID); tcx.hir_walk_toplevel_module(&mut collector); let ItemCollector { @@ -1341,7 +1333,7 @@ struct ItemCollector<'tcx> { // (see ). crate_collector: bool, tcx: TyCtxt<'tcx>, - submodules: Vec = vec![], + submodules: Vec = vec![], items: Vec = vec![], trait_items: Vec = vec![], impl_items: Vec = vec![], @@ -1390,7 +1382,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> { // Items that are modules are handled here instead of in visit_mod. if let ItemKind::Mod(_, module) = &item.kind { - self.submodules.push(item.owner_id); + self.submodules.push(LocalModId::new_unchecked(item.owner_id.def_id)); // A module collector does not recurse inside nested modules. if self.crate_collector { intravisit::walk_mod(self, module); diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index e0c1482af72ba..13bda2991fa92 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -12,7 +12,7 @@ use rustc_data_structures::stable_hash::{StableHash, StableHasher}; use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in}; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap, LocalModDefId}; +use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap, LocalModId}; use rustc_hir::lints::DelayedLints; use rustc_hir::*; use rustc_macros::{Decodable, Encodable, StableHash}; @@ -28,7 +28,7 @@ pub struct ModuleItems { /// Whether this represents the whole crate, in which case we need to add `CRATE_OWNER_ID` to /// the iterators if we want to account for the crate root. add_root: bool, - submodules: Box<[OwnerId]>, + submodules: Box<[LocalModId]>, free_items: Box<[ItemId]>, trait_items: Box<[TraitItemId]>, impl_items: Box<[ImplItemId]>, @@ -146,22 +146,22 @@ impl ModuleItems { } impl<'tcx> TyCtxt<'tcx> { - pub fn parent_module(self, id: HirId) -> LocalModDefId { + pub fn parent_module(self, id: HirId) -> LocalModId { if !id.is_owner() && self.def_kind(id.owner) == DefKind::Mod { - LocalModDefId::new_unchecked(id.owner.def_id) + LocalModId::new_unchecked(id.owner.def_id) } else { self.parent_module_from_def_id(id.owner.def_id) } } - pub fn parent_module_from_def_id(self, mut id: LocalDefId) -> LocalModDefId { + pub fn parent_module_from_def_id(self, mut id: LocalDefId) -> LocalModId { while let Some(parent) = self.opt_local_parent(id) { id = parent; if self.def_kind(id) == DefKind::Mod { break; } } - LocalModDefId::new_unchecked(id) + LocalModId::new_unchecked(id) } /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`). diff --git a/compiler/rustc_middle/src/metadata.rs b/compiler/rustc_middle/src/metadata.rs index 1365d2e19b75f..0c9b44a93a20e 100644 --- a/compiler/rustc_middle/src/metadata.rs +++ b/compiler/rustc_middle/src/metadata.rs @@ -1,7 +1,7 @@ use rustc_hir::def::Res; use rustc_macros::{StableHash, TyDecodable, TyEncodable}; use rustc_span::Ident; -use rustc_span::def_id::DefId; +use rustc_span::def_id::{DefId, ModId}; use smallvec::SmallVec; use crate::ty; @@ -39,7 +39,7 @@ pub struct ModChild { /// Local variables cannot be exported, so this `Res` doesn't need the ID parameter. pub res: Res, /// Visibility of the item. - pub vis: ty::Visibility, + pub vis: ty::Visibility, /// Reexport chain linking this module child to its original reexported item. /// Empty if the module child is a proper item. pub reexport_chain: SmallVec<[Reexport; 2]>, diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index 05eb8727bafbd..86eca36eac084 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -64,7 +64,7 @@ use rustc_errors::{ErrorGuaranteed, catch_fatal_errors}; use rustc_hir as hir; use rustc_hir::attrs::{EiiDecl, EiiImpl, StrippedCfgItem}; use rustc_hir::def::{DefKind, DocLinkResMap}; -use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdSet, LocalModDefId}; +use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdSet, LocalModId}; use rustc_hir::lang_items::{LangItem, LanguageItems}; use rustc_hir::{ItemLocalId, PreciseCapturingArgKind}; use rustc_index::IndexVec; @@ -76,7 +76,7 @@ use rustc_session::cstore::{ CrateDepKind, CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib, }; use rustc_session::lint::StableLintExpectationId; -use rustc_span::def_id::LOCAL_CRATE; +use rustc_span::def_id::{LOCAL_CRATE, ModId}; use rustc_span::{DUMMY_SP, LocalExpnId, Span, Spanned, Symbol}; use rustc_target::spec::PanicStrategy; @@ -236,7 +236,7 @@ rustc_queries! { /// /// This can be conveniently accessed by `tcx.hir_visit_item_likes_in_module`. /// Avoid calling this query directly. - query hir_module_items(key: LocalModDefId) -> &'tcx rustc_middle::hir::ModuleItems { + query hir_module_items(key: LocalModId) -> &'tcx rustc_middle::hir::ModuleItems { arena_cache desc { "getting HIR module items in `{}`", tcx.def_path_str(key) } cache_on_disk @@ -1156,7 +1156,7 @@ rustc_queries! { } /// Performs lint checking for the module. - query lint_mod(key: LocalModDefId) { + query lint_mod(key: LocalModId) { desc { "linting {}", describe_as_module(key, tcx) } } @@ -1165,16 +1165,16 @@ rustc_queries! { } /// Checks the attributes in the module. - query check_mod_attrs(key: LocalModDefId) { + query check_mod_attrs(key: LocalModId) { desc { "checking attributes in {}", describe_as_module(key, tcx) } } /// Checks for uses of unstable APIs in the module. - query check_mod_unstable_api_usage(key: LocalModDefId) { + query check_mod_unstable_api_usage(key: LocalModId) { desc { "checking for unstable API usage in {}", describe_as_module(key, tcx) } } - query check_mod_privacy(key: LocalModDefId) { + query check_mod_privacy(key: LocalModId) { desc { "checking privacy in {}", describe_as_module(key.to_local_def_id(), tcx) } } @@ -1189,7 +1189,7 @@ rustc_queries! { desc { "finding live symbols in crate" } } - query check_mod_deathness(key: LocalModDefId) { + query check_mod_deathness(key: LocalModId) { desc { "checking deathness of variables in {}", describe_as_module(key, tcx) } } @@ -1380,7 +1380,7 @@ rustc_queries! { eval_always desc { "checking effective visibilities" } } - query check_private_in_public(module_def_id: LocalModDefId) { + query check_private_in_public(module_def_id: LocalModId) { desc { "checking for private elements in public interfaces for {}", describe_as_module(module_def_id, tcx) @@ -2164,7 +2164,7 @@ rustc_queries! { /// ``` /// /// In here, if you call `visibility` on `T`, it'll panic. - query visibility(def_id: DefId) -> ty::Visibility { + query visibility(def_id: DefId) -> ty::Visibility { desc { "computing visibility of `{}`", tcx.def_path_str(def_id) } separate_provide_extern feedable @@ -2692,13 +2692,13 @@ rustc_queries! { separate_provide_extern } - query doc_link_resolutions(def_id: DefId) -> &'tcx DocLinkResMap { + query doc_link_resolutions(def_id: ModId) -> &'tcx DocLinkResMap { eval_always desc { "resolutions for documentation links for a module" } separate_provide_extern } - query doc_link_traits_in_scope(def_id: DefId) -> &'tcx [DefId] { + query doc_link_traits_in_scope(def_id: ModId) -> &'tcx [DefId] { eval_always desc { "traits in scope for documentation links for a module" } separate_provide_extern diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index a5fb77ced7656..827ae5a8edbdf 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -13,6 +13,7 @@ use std::mem::MaybeUninit; use rustc_ast::tokenstream::TokenStream; use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{DynSend, DynSync}; +use rustc_span::def_id::ModId; use rustc_span::{ErrorGuaranteed, Spanned}; use crate::mono::{MonoItem, NormalizationErrorInMono}; @@ -246,7 +247,7 @@ impl_erasable_for_types_with_no_type_params! { rustc_middle::ty::ParamEnv<'_>, rustc_middle::ty::SymbolName<'_>, rustc_middle::ty::TypingEnv<'_>, - rustc_middle::ty::Visibility, + rustc_middle::ty::Visibility, rustc_middle::ty::inhabitedness::InhabitedPredicate<'_>, rustc_session::Limits, rustc_session::config::OptLevel, diff --git a/compiler/rustc_middle/src/query/into_query_key.rs b/compiler/rustc_middle/src/query/into_query_key.rs index 04bbfd5c3a8ab..6428a9e98e7fd 100644 --- a/compiler/rustc_middle/src/query/into_query_key.rs +++ b/compiler/rustc_middle/src/query/into_query_key.rs @@ -1,5 +1,5 @@ use rustc_hir::OwnerId; -use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId, ModDefId}; +use rustc_hir::def_id::{DefId, LocalDefId, LocalModId, ModId}; /// Argument-conversion trait used by some queries and other `TyCtxt` methods. /// @@ -48,21 +48,21 @@ impl IntoQueryKey for OwnerId { } } -impl IntoQueryKey for ModDefId { +impl IntoQueryKey for ModId { #[inline(always)] fn into_query_key(self) -> DefId { self.to_def_id() } } -impl IntoQueryKey for LocalModDefId { +impl IntoQueryKey for LocalModId { #[inline(always)] fn into_query_key(self) -> DefId { self.to_def_id() } } -impl IntoQueryKey for LocalModDefId { +impl IntoQueryKey for LocalModId { #[inline(always)] fn into_query_key(self) -> LocalDefId { self.into() diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index 772caa0b9f505..225618689647d 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -7,8 +7,9 @@ use std::hash::Hash; use rustc_ast::tokenstream::TokenStream; use rustc_data_structures::sso::SsoHashSet; use rustc_data_structures::stable_hash::StableHash; -use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId}; +use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModId}; use rustc_hir::hir_id::OwnerId; +use rustc_span::def_id::ModId; use rustc_span::{DUMMY_SP, Ident, LocalExpnId, Span, Symbol}; use crate::dep_graph::DepNodeIndex; @@ -157,7 +158,25 @@ impl QueryKey for DefId { } } -impl QueryKey for LocalModDefId { +impl QueryKey for ModId { + type LocalQueryKey = LocalModId; + + fn default_span(&self, tcx: TyCtxt<'_>) -> Span { + tcx.def_span(self.to_def_id()) + } + + #[inline(always)] + fn key_as_def_id(&self) -> Option { + Some(self.to_def_id()) + } + + #[inline(always)] + fn as_local_key(&self) -> Option { + self.as_local() + } +} + +impl QueryKey for LocalModId { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(*self) } diff --git a/compiler/rustc_middle/src/ty/assoc.rs b/compiler/rustc_middle/src/ty/assoc.rs index 2c59e66c6f470..85c94d0b598e6 100644 --- a/compiler/rustc_middle/src/ty/assoc.rs +++ b/compiler/rustc_middle/src/ty/assoc.rs @@ -3,6 +3,7 @@ use rustc_hir as hir; use rustc_hir::def::{DefKind, Namespace}; use rustc_hir::def_id::DefId; use rustc_macros::{Decodable, Encodable, StableHash}; +use rustc_span::def_id::ModId; use rustc_span::{ErrorGuaranteed, Ident, Symbol}; use super::{TyCtxt, Visibility}; @@ -82,7 +83,7 @@ impl AssocItem { } #[inline] - pub fn visibility(&self, tcx: TyCtxt<'_>) -> Visibility { + pub fn visibility(&self, tcx: TyCtxt<'_>) -> Visibility { tcx.visibility(self.def_id) } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 17f0098070c5c..146662676acc0 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -620,7 +620,7 @@ impl<'tcx> TyCtxt<'tcx> { other => bug!("{key:?} is not an assoc item of a trait impl: {other:?}"), } } - TyCtxtFeed { tcx: self, key }.visibility(vis.to_def_id()) + TyCtxtFeed { tcx: self, key }.visibility(vis.to_mod_id()) } } @@ -1324,8 +1324,8 @@ impl<'tcx> TyCtxt<'tcx> { // Visibilities for opaque types are meaningless, but still provided // so that all items have visibilities. if matches!(def_kind, DefKind::Closure | DefKind::OpaqueTy) { - let parent_mod = self.parent_module_from_def_id(def_id).to_def_id(); - feed.visibility(ty::Visibility::Restricted(parent_mod)); + let parent_mod = self.parent_module_from_def_id(def_id); + feed.visibility(ty::Visibility::Restricted(parent_mod.to_mod_id())); } feed diff --git a/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs b/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs index 03a6163b33ade..6cd188349ef22 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs @@ -1,8 +1,9 @@ use rustc_macros::StableHash; +use rustc_span::def_id::{LocalModId, ModId}; use smallvec::SmallVec; use tracing::instrument; -use crate::ty::{self, DefId, OpaqueTypeKey, Ty, TyCtxt, TypingEnv, Unnormalized}; +use crate::ty::{self, OpaqueTypeKey, Ty, TyCtxt, TypingEnv, Unnormalized}; /// Represents whether some type is inhabited in a given context. /// Examples of uninhabited types are `!`, `enum Void {}`, or a struct @@ -20,7 +21,7 @@ pub enum InhabitedPredicate<'tcx> { ConstIsZero(ty::Const<'tcx>), /// Uninhabited if within a certain module. This occurs when an uninhabited /// type has restricted visibility. - NotInModule(DefId), + NotInModule(ModId), /// Inhabited if some generic type is inhabited. /// These are replaced by calling [`Self::instantiate`]. GenericType(Ty<'tcx>), @@ -38,7 +39,7 @@ impl<'tcx> InhabitedPredicate<'tcx> { self, tcx: TyCtxt<'tcx>, typing_env: TypingEnv<'tcx>, - module_def_id: DefId, + module_def_id: LocalModId, ) -> bool { self.apply_revealing_opaque(tcx, typing_env, module_def_id, &|_| None) } @@ -49,7 +50,7 @@ impl<'tcx> InhabitedPredicate<'tcx> { self, tcx: TyCtxt<'tcx>, typing_env: TypingEnv<'tcx>, - module_def_id: DefId, + module_def_id: LocalModId, reveal_opaque: &impl Fn(OpaqueTypeKey<'tcx>) -> Option>, ) -> bool { let Ok(result) = self.apply_inner::( @@ -83,7 +84,7 @@ impl<'tcx> InhabitedPredicate<'tcx> { tcx: TyCtxt<'tcx>, typing_env: TypingEnv<'tcx>, eval_stack: &mut SmallVec<[Ty<'tcx>; 1]>, // for cycle detection - in_module: &impl Fn(DefId) -> Result, + in_module: &impl Fn(ModId) -> Result, reveal_opaque: &impl Fn(OpaqueTypeKey<'tcx>) -> Option>, ) -> Result { match self { diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs index 55b359866bb97..12c13ad74cb24 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs @@ -43,6 +43,7 @@ //! This code should only compile in modules where the uninhabitedness of `Foo` //! is visible. +use rustc_span::def_id::LocalModId; use rustc_type_ir::TyKind::*; use tracing::instrument; @@ -184,7 +185,7 @@ impl<'tcx> Ty<'tcx> { pub fn is_inhabited_from( self, tcx: TyCtxt<'tcx>, - module: DefId, + module: LocalModId, typing_env: ty::TypingEnv<'tcx>, ) -> bool { self.inhabited_predicate(tcx).apply(tcx, typing_env, module) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 4c14858101bf1..d90a709ffcd41 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -50,6 +50,7 @@ use rustc_macros::{ use rustc_serialize::{Decodable, Encodable}; use rustc_session::config::OptLevel; pub use rustc_session::lint::RegisteredTools; +use rustc_span::def_id::{LocalModId, ModId}; use rustc_span::hygiene::MacroKind; use rustc_span::{DUMMY_SP, ExpnId, ExpnKind, Ident, Span, Symbol}; use rustc_target::callconv::FnAbi; @@ -199,8 +200,8 @@ pub struct ResolverGlobalCtxt { /// Mapping from ident span to path span for paths that don't exist as written, but that /// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`. pub confused_type_with_std_module: FxIndexMap, - pub doc_link_resolutions: FxIndexMap, - pub doc_link_traits_in_scope: FxIndexMap>, + pub doc_link_resolutions: FxIndexMap, + pub doc_link_traits_in_scope: FxIndexMap>, pub all_macro_rules: UnordSet, pub stripped_cfg_items: Vec, // Information about delegations which is used when handling recursive delegations @@ -311,7 +312,7 @@ impl Asyncness { } #[derive(Clone, Debug, PartialEq, Eq, Copy, Hash, Encodable, BlobDecodable, StableHash)] -pub enum Visibility { +pub enum Visibility { /// Visible everywhere (including in other crates). Public, /// Visible only in the given crate-local module. @@ -324,7 +325,7 @@ impl Visibility { ty::Visibility::Restricted(restricted_id) => { if restricted_id.is_top_level_module() { "pub(crate)".to_string() - } else if restricted_id == tcx.parent_module_from_def_id(def_id).to_local_def_id() { + } else if restricted_id == tcx.parent_module_from_def_id(def_id) { "pub(self)".to_string() } else { format!( @@ -403,9 +404,13 @@ impl TyCtxt<'_> { } } - pub fn is_descendant_of(self, descendant: DefId, ancestor: DefId) -> bool { + pub fn is_descendant_of( + self, + descendant: impl Into, + ancestor: impl Into, + ) -> bool { matches!( - self.def_id_partial_cmp(descendant, ancestor), + self.def_id_partial_cmp(descendant.into(), ancestor.into()), Some(Ordering::Less | Ordering::Equal) ) } @@ -424,17 +429,19 @@ impl Visibility { } } -impl> Visibility { - pub fn to_def_id(self) -> Visibility { - self.map_id(Into::into) +impl Visibility { + pub fn to_mod_id(self) -> Visibility { + self.map_id(LocalModId::to_mod_id) } +} +impl> Visibility { /// Returns `true` if an item with this visibility is accessible from the given module. pub fn is_accessible_from(self, module: impl Into, tcx: TyCtxt<'_>) -> bool { match self { // Public items are visible everywhere. Visibility::Public => true, - Visibility::Restricted(id) => tcx.is_descendant_of(module.into(), id.into()), + Visibility::Restricted(id) => tcx.is_descendant_of(module, id), } } @@ -473,7 +480,7 @@ impl + Debug + Copy> Visibility { } } -impl Visibility { +impl Visibility { pub fn expect_local(self) -> Visibility { self.map_id(|id| id.expect_local()) } @@ -482,7 +489,7 @@ impl Visibility { pub fn is_visible_locally(self) -> bool { match self { Visibility::Public => true, - Visibility::Restricted(def_id) => def_id.is_local(), + Visibility::Restricted(mod_id) => mod_id.is_local(), } } } @@ -1464,7 +1471,7 @@ pub enum VariantDiscr { pub struct FieldDef { pub did: DefId, pub name: Symbol, - pub vis: Visibility, + pub vis: Visibility, pub safety: hir::Safety, pub value: Option, } @@ -2160,12 +2167,12 @@ impl<'tcx> TyCtxt<'tcx> { mut ident: Ident, scope: DefId, item_id: LocalDefId, - ) -> (Ident, DefId) { + ) -> (Ident, ModId) { let scope = ident .span .normalize_to_macros_2_0_and_adjust(self.expn_that_defined(scope)) .and_then(|actual_expansion| actual_expansion.expn_data().parent_module) - .unwrap_or_else(|| self.parent_module_from_def_id(item_id).to_def_id()); + .unwrap_or_else(|| self.parent_module_from_def_id(item_id).to_mod_id()); (ident, scope) } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 69def782bb67b..67d6f4682361f 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -11,7 +11,7 @@ use rustc_data_structures::unord::UnordMap; use rustc_hir as hir; use rustc_hir::LangItem; use rustc_hir::def::{self, CtorKind, DefKind, Namespace}; -use rustc_hir::def_id::{DefIdMap, DefIdSet, LOCAL_CRATE, ModDefId}; +use rustc_hir::def_id::{DefIdMap, DefIdSet, LOCAL_CRATE, ModId}; use rustc_hir::definitions::{DefKey, DefPathDataName}; use rustc_hir::limit::Limit; use rustc_macros::{Lift, extension}; @@ -385,8 +385,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { && Some(*visible_parent) != actual_parent { this.tcx() - // FIXME(typed_def_id): Further propagate ModDefId - .module_children(ModDefId::new_unchecked(*visible_parent)) + .module_children(ModId::new_unchecked(*visible_parent)) .iter() .filter(|child| child.res.opt_def_id() == Some(def_id)) .find(|child| child.vis.is_public() && child.ident.name != kw::Underscore) @@ -612,8 +611,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { // that's public and whose identifier isn't `_`. let reexport = self .tcx() - // FIXME(typed_def_id): Further propagate ModDefId - .module_children(ModDefId::new_unchecked(visible_parent)) + .module_children(ModId::new_unchecked(visible_parent)) .iter() .filter(|child| child.res.opt_def_id() == Some(def_id)) .find(|child| child.vis.is_public() && child.ident.name != kw::Underscore) diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 49bac6a130231..7e087f6e1646f 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -250,6 +250,7 @@ TrivialTypeTraversalImpls! { rustc_span::Ident, rustc_span::Span, rustc_span::Symbol, + rustc_span::def_id::ModId, rustc_target::asm::InlineAsmRegOrRegClass, // tidy-alphabetical-end } diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs index fee9cd80161e5..29e9d1243f0ca 100644 --- a/compiler/rustc_middle/src/ty/trait_def.rs +++ b/compiler/rustc_middle/src/ty/trait_def.rs @@ -140,7 +140,7 @@ impl ImplRestrictionKind { if restricted_to.krate == rustc_hir::def_id::LOCAL_CRATE { with_crate_prefix!(with_no_trimmed_paths!(tcx.def_path_str(restricted_to))) } else { - tcx.def_path_str(restricted_to.krate.as_mod_def_id()) + tcx.def_path_str(restricted_to.krate.as_mod_id()) } } } diff --git a/compiler/rustc_mir_build/src/builder/scope.rs b/compiler/rustc_mir_build/src/builder/scope.rs index 932e4af130459..a5707e0177c63 100644 --- a/compiler/rustc_mir_build/src/builder/scope.rs +++ b/compiler/rustc_mir_build/src/builder/scope.rs @@ -967,7 +967,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let cx = RustcPatCtxt { tcx: self.tcx, typeck_results, - module: self.tcx.parent_module(self.hir_id).to_def_id(), + module: self.tcx.parent_module(self.hir_id), typing_env: ty::TypingEnv::post_typeck_until_borrowck_for_mir_build( self.tcx, self.def_id, diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 57a71467f6f01..41806547932cd 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -385,7 +385,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> { tcx: self.tcx, typeck_results: self.typeck_results, typing_env: self.typing_env, - module: self.tcx.parent_module(self.hir_source).to_def_id(), + module: self.tcx.parent_module(self.hir_source), dropless_arena: self.dropless_arena, match_lint_level: self.hir_source, whole_match_span, diff --git a/compiler/rustc_mir_transform/src/lint_and_remove_uninhabited.rs b/compiler/rustc_mir_transform/src/lint_and_remove_uninhabited.rs index b359077753fd6..7d902c0149c95 100644 --- a/compiler/rustc_mir_transform/src/lint_and_remove_uninhabited.rs +++ b/compiler/rustc_mir_transform/src/lint_and_remove_uninhabited.rs @@ -14,7 +14,7 @@ impl<'tcx> crate::MirPass<'tcx> for LintAndRemoveUninhabited { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let def_id = body.source.def_id().expect_local(); tracing::debug!(?def_id); - let parent_module = tcx.parent_module_from_def_id(def_id).to_def_id(); + let parent_module = tcx.parent_module_from_def_id(def_id); let typing_env = body.typing_env(tcx); // check if the function's return type is inhabited diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index afc716284391b..3139c8746b95a 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -21,7 +21,7 @@ use rustc_hir::attrs::{ OptimizeAttr, ReprAttr, }; use rustc_hir::def::DefKind; -use rustc_hir::def_id::LocalModDefId; +use rustc_hir::def_id::LocalModId; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{ self as hir, Attribute, CRATE_HIR_ID, Constness, FnSig, ForeignItem, GenericParam, @@ -1801,7 +1801,7 @@ fn check_non_exported_macro_for_invalid_attrs(tcx: TyCtxt<'_>, item: &Item<'_>) } } -fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { +fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalModId) { let check_attr_visitor = &mut CheckAttrVisitor { tcx, abort: Cell::new(false) }; tcx.hir_visit_item_likes_in_module(module_def_id, check_attr_visitor); if module_def_id.to_local_def_id().is_top_level_module() { diff --git a/compiler/rustc_passes/src/check_export.rs b/compiler/rustc_passes/src/check_export.rs index a1b204152387c..411aad0717959 100644 --- a/compiler/rustc_passes/src/check_export.rs +++ b/compiler/rustc_passes/src/check_export.rs @@ -56,7 +56,7 @@ impl<'tcx> ExportableItemCollector<'tcx> { if has_attr && !is_pub { let vis = visibilities.effective_vis(def_id).cloned().unwrap_or_else(|| { EffectiveVisibility::from_vis(Visibility::Restricted( - self.tcx.parent_module_from_def_id(def_id).to_local_def_id(), + self.tcx.parent_module_from_def_id(def_id), )) }); let vis = vis.at_level(Level::Direct); diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 221aca2ec0c95..dd5247823231d 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -12,7 +12,7 @@ use rustc_abi::FieldIdx; use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_errors::{ErrorGuaranteed, MultiSpan}; use rustc_hir::def::{CtorOf, DefKind, Res}; -use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId}; +use rustc_hir::def_id::{DefId, LocalDefId, LocalModId}; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{self as hir, ForeignItemId, ItemId, Node, PatKind, QPath, find_attr}; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; @@ -1325,7 +1325,7 @@ impl<'tcx> DeadVisitor<'tcx> { } } -fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) { +fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModId) { let Ok(DeadCodeLivenessSummary { pre_deferred_seeding, final_result }) = tcx.live_symbols_and_ignored_derived_traits(()).as_ref() else { @@ -1367,7 +1367,7 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) { fn lint_dead_codes<'tcx>( tcx: TyCtxt<'tcx>, target_lint: &'static Lint, - module: LocalModDefId, + module: LocalModId, live_symbols: &'tcx LocalDefIdSet, ignored_derived_traits: &'tcx LocalDefIdMap>, free_items: impl Iterator, diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index bf5a1dc2ec4b8..86e3e57b34bf0 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -9,7 +9,7 @@ use rustc_data_structures::unord::{ExtendUnord, UnordMap, UnordSet}; use rustc_feature::{EnabledLangFeature, EnabledLibFeature, UNSTABLE_LANG_FEATURES}; use rustc_hir::attrs::{AttributeKind, DeprecatedSince}; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId, LocalModDefId}; +use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId, LocalModId}; use rustc_hir::intravisit::{self, Visitor, VisitorExt}; use rustc_hir::{ self as hir, AmbigArg, ConstStability, Constness, DefaultBodyStability, FieldDef, HirId, Item, @@ -520,21 +520,21 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> { /// Cross-references the feature names of unstable APIs with enabled /// features and possibly prints errors. -fn check_mod_unstable_api_usage(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { - tcx.hir_visit_item_likes_in_module(module_def_id, &mut Checker { tcx }); +fn check_mod_unstable_api_usage(tcx: TyCtxt<'_>, mod_id: LocalModId) { + tcx.hir_visit_item_likes_in_module(mod_id, &mut Checker { tcx }); let is_staged_api = tcx.sess.opts.unstable_opts.force_unstable_if_unmarked || tcx.features().staged_api(); if is_staged_api { let effective_visibilities = &tcx.effective_visibilities(()); let mut missing = MissingStabilityAnnotations { tcx, effective_visibilities }; - if module_def_id.is_top_level_module() { + if mod_id.is_top_level_module() { missing.check_missing_stability(CRATE_DEF_ID); } - tcx.hir_visit_item_likes_in_module(module_def_id, &mut missing); + tcx.hir_visit_item_likes_in_module(mod_id, &mut missing); } - if module_def_id.is_top_level_module() { + if mod_id.is_top_level_module() { check_unused_or_stable_features(tcx) } } diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index 14fd5f8e9a2dc..c3b3d14848982 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -5,7 +5,6 @@ use std::iter::once; use rustc_abi::{FIRST_VARIANT, FieldIdx, Integer, VariantIdx}; use rustc_arena::DroplessArena; use rustc_hir::HirId; -use rustc_hir::def_id::DefId; use rustc_index::{Idx, IndexVec}; use rustc_middle::middle::stability::EvalResult; use rustc_middle::thir::{self, Pat, PatKind, PatRange, PatRangeBoundary}; @@ -15,6 +14,7 @@ use rustc_middle::ty::{ }; use rustc_middle::{bug, span_bug}; use rustc_session::lint; +use rustc_span::def_id::LocalModId; use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span}; use crate::constructor::Constructor::*; @@ -84,7 +84,7 @@ pub struct RustcPatCtxt<'p, 'tcx: 'p> { /// inhabited can depend on whether it was defined in the current module or /// not. E.g., `struct Foo { _private: ! }` cannot be seen to be empty /// outside its module and should not be matchable with an empty match statement. - pub module: DefId, + pub module: LocalModId, pub typing_env: ty::TypingEnv<'tcx>, /// To allocate the result of `self.ctor_sub_tys()` pub dropless_arena: &'p DroplessArena, diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 46d6445711175..29ee27bc102f9 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -21,7 +21,7 @@ use rustc_data_structures::indexmap::IndexSet; use rustc_data_structures::intern::Interned; use rustc_errors::{MultiSpan, listify}; use rustc_hir::def::{CtorOf, DefKind, Res}; -use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId}; +use rustc_hir::def_id::{DefId, LocalDefId, LocalModId}; use rustc_hir::intravisit::{self, InferKind, Visitor}; use rustc_hir::{self as hir, AmbigArg, ForeignItemId, ItemId, OwnerId, PatKind, find_attr}; use rustc_middle::middle::privacy::{EffectiveVisibilities, EffectiveVisibility, Level}; @@ -405,9 +405,8 @@ impl VisibilityLike for EffectiveVisibility { ) -> Self { let effective_vis = find.effective_visibilities.effective_vis(def_id).copied().unwrap_or_else(|| { - let private_vis = ty::Visibility::Restricted( - find.tcx.parent_module_from_def_id(def_id).to_local_def_id(), - ); + let private_vis = + ty::Visibility::Restricted(find.tcx.parent_module_from_def_id(def_id)); EffectiveVisibility::from_vis(private_vis) }); @@ -517,7 +516,6 @@ impl<'tcx> EmbargoVisitor<'tcx> { max_vis: Option, level: Level, ) -> bool { - // FIXME(typed_def_id): Make `Visibility::Restricted` use a `LocalModDefId` by default. let private_vis = ty::Visibility::Restricted(self.tcx.parent_module_from_def_id(def_id).into()); if max_vis != Some(private_vis) { @@ -1128,14 +1126,14 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> { /// Checks are performed on "semantic" types regardless of names and their hygiene. struct TypePrivacyVisitor<'tcx> { tcx: TyCtxt<'tcx>, - module_def_id: LocalModDefId, + mod_id: LocalModId, maybe_typeck_results: Option<&'tcx ty::TypeckResults<'tcx>>, span: Span, } impl<'tcx> TypePrivacyVisitor<'tcx> { fn item_is_accessible(&self, did: DefId) -> bool { - self.tcx.visibility(did).is_accessible_from(self.module_def_id, self.tcx) + self.tcx.visibility(did).is_accessible_from(self.mod_id, self.tcx) } // Take node-id of an expression or pattern and check its type for privacy. @@ -1434,12 +1432,10 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> { if self.hard_error && self.required_visibility.greater_than(vis, self.tcx) { let vis_descr = match vis { ty::Visibility::Public => "public", - ty::Visibility::Restricted(vis_def_id) => { - if vis_def_id - == self.tcx.parent_module_from_def_id(local_def_id).to_local_def_id() - { + ty::Visibility::Restricted(vis_mod_id) => { + if vis_mod_id == self.tcx.parent_module_from_def_id(local_def_id) { "private" - } else if vis_def_id.is_top_level_module() { + } else if vis_mod_id.is_top_level_module() { "crate-private" } else { "restricted" @@ -1746,17 +1742,17 @@ pub fn provide(providers: &mut Providers) { }; } -fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { +fn check_mod_privacy(tcx: TyCtxt<'_>, mod_id: LocalModId) { // Check privacy of names not checked in previous compilation stages. let mut visitor = NamePrivacyVisitor { tcx, maybe_typeck_results: None }; - tcx.hir_visit_item_likes_in_module(module_def_id, &mut visitor); + tcx.hir_visit_item_likes_in_module(mod_id, &mut visitor); // Check privacy of explicitly written types and traits as well as // inferred types of expressions and patterns. - let span = tcx.def_span(module_def_id); - let mut visitor = TypePrivacyVisitor { tcx, module_def_id, maybe_typeck_results: None, span }; + let span = tcx.def_span(mod_id); + let mut visitor = TypePrivacyVisitor { tcx, mod_id, maybe_typeck_results: None, span }; - let module = tcx.hir_module_items(module_def_id); + let module = tcx.hir_module_items(mod_id); for def_id in module.definitions() { let _ = rustc_ty_utils::sig_types::walk_types(tcx, def_id, &mut visitor); @@ -1881,12 +1877,12 @@ fn effective_visibilities(tcx: TyCtxt<'_>, (): ()) -> &EffectiveVisibilities { tcx.arena.alloc(visitor.effective_visibilities) } -fn check_private_in_public(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { +fn check_private_in_public(tcx: TyCtxt<'_>, mod_id: LocalModId) { let effective_visibilities = tcx.effective_visibilities(()); // Check for private types in public interfaces. let checker = PrivateItemsInPublicInterfacesChecker { tcx, effective_visibilities }; - let crate_items = tcx.hir_module_items(module_def_id); + let crate_items = tcx.hir_module_items(mod_id); let _ = crate_items.par_items(|id| Ok(checker.check_item(id))); let _ = crate_items.par_foreign_items(|id| Ok(checker.check_foreign_item(id))); } diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 3f4c260a496af..98c7af88550dc 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -19,12 +19,13 @@ use rustc_expand::base::{ResolverExpand, SyntaxExtension, SyntaxExtensionKind}; use rustc_hir::Attribute; use rustc_hir::attrs::{AttributeKind, MacroUseArgs}; use rustc_hir::def::{self, *}; -use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId}; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_index::bit_set::DenseBitSet; use rustc_metadata::creader::LoadedMacro; use rustc_middle::metadata::{ModChild, Reexport}; use rustc_middle::ty::{TyCtxtFeed, Visibility}; use rustc_middle::{bug, span_bug}; +use rustc_span::def_id::{CRATE_MOD_ID, ModId}; use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind}; use rustc_span::{Ident, Span, Symbol, kw, sym}; use thin_vec::ThinVec; @@ -71,7 +72,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { expn_id: LocalExpnId, ) { let decl = - self.arenas.new_def_decl(res, vis.to_def_id(), span, expn_id, Some(parent.to_module())); + self.arenas.new_def_decl(res, vis.to_mod_id(), span, expn_id, Some(parent.to_module())); let ident = IdentKey::new(orig_ident); self.plant_decl_into_local_module(ident, orig_ident.span, ns, decl); } @@ -274,7 +275,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { Ok(Visibility::Public) } _ => { - let vis = Visibility::Restricted(res.def_id()); + let vis = + Visibility::Restricted(ModId::new_unchecked(res.def_id())); if self.is_accessible_from(vis, parent_scope.module) { if finalize { self.record_partial_res(id, PartialRes::new(res)); @@ -904,7 +906,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { let mut ctor_vis = if vis.is_public() && ast::attr::contains_name(&item.attrs, sym::non_exhaustive) { - Visibility::Restricted(CRATE_DEF_ID) + Visibility::Restricted(CRATE_MOD_ID) } else { vis }; @@ -922,7 +924,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { if ctor_vis.greater_than(field_vis, self.r.tcx) { ctor_vis = field_vis; } - field_visibilities.push(field_vis.to_def_id()); + field_visibilities.push(field_vis.to_mod_id()); } // If this is a unit or tuple-like struct, register the constructor. let feed = self.create_def( @@ -940,7 +942,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { self.insert_field_visibilities_local(ctor_def_id.to_def_id(), vdata.fields()); let ctor = - StructCtor { res: ctor_res, vis: ctor_vis.to_def_id(), field_visibilities }; + StructCtor { res: ctor_res, vis: ctor_vis.to_mod_id(), field_visibilities }; self.r.struct_ctors.insert(local_def_id, ctor); } self.r.struct_generics.insert(local_def_id, generics.clone()); @@ -1154,7 +1156,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { root_span: span, span, module_path: Vec::new(), - vis: Visibility::Restricted(CRATE_DEF_ID), + vis: Visibility::Restricted(CRATE_MOD_ID), vis_span: item.vis.span, on_unknown_attr: OnUnknownData::from_attrs(this.r, &item.attrs), }) @@ -1310,11 +1312,11 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { let vis = if is_macro_export { Visibility::Public } else { - Visibility::Restricted(CRATE_DEF_ID) + Visibility::Restricted(CRATE_MOD_ID) }; let decl = self.r.arenas.new_def_decl( res, - vis.to_def_id(), + vis.to_mod_id(), span, expansion, Some(parent_scope.module), @@ -1516,7 +1518,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { // If the variant is marked as non_exhaustive then lower the visibility to within the crate. let ctor_vis = if vis.is_public() && ast::attr::contains_name(&variant.attrs, sym::non_exhaustive) { - Visibility::Restricted(CRATE_DEF_ID) + Visibility::Restricted(CRATE_MOD_ID) } else { vis }; diff --git a/compiler/rustc_resolve/src/diagnostics/impls.rs b/compiler/rustc_resolve/src/diagnostics/impls.rs index b6d278c26e61d..8c3c758f2be69 100644 --- a/compiler/rustc_resolve/src/diagnostics/impls.rs +++ b/compiler/rustc_resolve/src/diagnostics/impls.rs @@ -32,6 +32,7 @@ use rustc_session::lint::builtin::{ AMBIGUOUS_PANIC_IMPORTS, MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS, }; use rustc_session::utils::was_invoked_from_cargo; +use rustc_span::def_id::ModId; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::edition::Edition; use rustc_span::hygiene::MacroKind; @@ -68,8 +69,8 @@ pub(crate) type LabelSuggestion = (Ident, bool); #[derive(Clone)] pub(crate) struct StructCtor { pub res: Res, - pub vis: Visibility, - pub field_visibilities: Vec>, + pub vis: Visibility, + pub field_visibilities: Vec>, } impl StructCtor { @@ -1991,7 +1992,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } return; } - if Some(parent_nearest) == scope.opt_def_id() { + if Some(parent_nearest.to_def_id()) == scope.opt_def_id() { err.subdiagnostic(MacroDefinedLater { span: unused_ident.span }); err.subdiagnostic(MacroSuggMovePosition { span: ident.span, ident }); return; diff --git a/compiler/rustc_resolve/src/effective_visibilities.rs b/compiler/rustc_resolve/src/effective_visibilities.rs index 8f051cf02d41c..90927492195b0 100644 --- a/compiler/rustc_resolve/src/effective_visibilities.rs +++ b/compiler/rustc_resolve/src/effective_visibilities.rs @@ -7,6 +7,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId}; use rustc_middle::middle::privacy::{EffectiveVisibilities, EffectiveVisibility, Level}; use rustc_middle::ty::Visibility; +use rustc_span::def_id::{CRATE_MOD_ID, LocalModId}; use rustc_span::sym; use tracing::info; @@ -55,7 +56,7 @@ pub(crate) struct EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> { impl Resolver<'_, '_> { fn private_vis_decl(&self, decl: Decl<'_>) -> Visibility { Visibility::Restricted( - decl.parent_module.map_or(CRATE_DEF_ID, |m| m.nearest_parent_mod().expect_local()), + decl.parent_module.map_or(CRATE_MOD_ID, |m| m.nearest_parent_mod().expect_local()), ) } @@ -65,8 +66,8 @@ impl Resolver<'_, '_> { .get_nearest_non_block_module(def_id.to_def_id()) .nearest_parent_mod() .expect_local(); - if normal_mod_id == def_id { - Visibility::Restricted(self.tcx.local_parent(def_id)) + if normal_mod_id.to_local_def_id() == def_id { + Visibility::Restricted(LocalModId::new_unchecked(self.tcx.local_parent(def_id))) } else { Visibility::Restricted(normal_mod_id) } @@ -85,7 +86,7 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> { r, def_effective_visibilities: Default::default(), import_effective_visibilities: Default::default(), - current_private_vis: Visibility::Restricted(CRATE_DEF_ID), + current_private_vis: Visibility::Restricted(CRATE_MOD_ID), macro_reachable: Default::default(), changed: true, }; @@ -242,7 +243,7 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> { fn update_macro(&mut self, def_id: LocalDefId, inherited_effective_vis: EffectiveVisibility) { let max_vis = Some(self.r.tcx.local_visibility(def_id)); let priv_vis = if def_id == CRATE_DEF_ID { - Visibility::Restricted(CRATE_DEF_ID) + Visibility::Restricted(CRATE_MOD_ID) } else { self.r.private_vis_def(def_id) }; @@ -364,8 +365,10 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> ), ast::ItemKind::Mod(..) => { - let prev_private_vis = - mem::replace(&mut self.current_private_vis, Visibility::Restricted(def_id)); + let prev_private_vis = mem::replace( + &mut self.current_private_vis, + Visibility::Restricted(LocalModId::new_unchecked(def_id)), + ); self.set_bindings_effective_visibilities(def_id); visit::walk_item(self, item); self.current_private_vis = prev_private_vis; diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 134aec3d0c7d2..26418dff45a5c 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -1831,7 +1831,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ) -> PathResult<'ra> { let mut module = None; let mut module_had_parse_errors = !self.mods_with_parse_errors.is_empty() - && self.mods_with_parse_errors.contains(&parent_scope.module.nearest_parent_mod()); + && self + .mods_with_parse_errors + .contains(&parent_scope.module.nearest_parent_mod().to_def_id()); let mut allow_super = true; let mut second_binding = None; diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index d3b1d06b870a9..25f7e28b6738c 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -473,7 +473,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { kind: DeclKind::Import { source_decl: decl, import }, ambiguity: CmCell::new(None), span: import.span, - initial_vis: vis.to_def_id(), + initial_vis: vis.to_mod_id(), ambiguity_vis_max: CmCell::new(None), ambiguity_vis_min: CmCell::new(None), expansion: import.parent_scope.expansion, @@ -1646,7 +1646,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ns: Namespace, ) -> Option { let crate_private_reexport = match decl.vis() { - Visibility::Restricted(def_id) if def_id.is_top_level_module() => true, + Visibility::Restricted(mod_id) if mod_id.is_top_level_module() => true, _ => false, }; diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 13576c24e6c08..40cad4241e5a3 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -71,6 +71,7 @@ use rustc_middle::ty::{ use rustc_middle::{bug, span_bug}; use rustc_session::config::CrateType; use rustc_session::lint::builtin::PRIVATE_MACRO_USE; +use rustc_span::def_id::{LocalModId, ModId}; use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency}; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; use smallvec::{SmallVec, smallvec}; @@ -706,7 +707,7 @@ impl<'ra> ModuleData<'ra> { expansion: ExpnId, span: Span, no_implicit_prelude: bool, - vis: Visibility, + vis: Visibility, arenas: &'ra ResolverArenas<'ra>, ) -> Self { let is_foreign = !kind.is_local(); @@ -840,11 +841,11 @@ impl<'ra> Module<'ra> { } } - /// The [`DefId`] of the nearest `mod` item ancestor (which may be this module). + /// The [`ModId`] of the nearest `mod` item ancestor (which may be this module). /// This may be the crate root. - fn nearest_parent_mod(self) -> DefId { + fn nearest_parent_mod(self) -> ModId { match self.kind { - ModuleKind::Def(DefKind::Mod, def_id, _, _) => def_id, + ModuleKind::Def(DefKind::Mod, def_id, _, _) => ModId::new_unchecked(def_id), _ => self.parent.expect("non-root module without parent").nearest_parent_mod(), } } @@ -894,7 +895,7 @@ impl<'ra> LocalModule<'ra> { fn new( parent: Option>, kind: ModuleKind, - vis: Visibility, + vis: Visibility, expn_id: ExpnId, span: Span, no_implicit_prelude: bool, @@ -916,7 +917,7 @@ impl<'ra> ExternModule<'ra> { fn new( parent: Option>, kind: ModuleKind, - vis: Visibility, + vis: Visibility, expn_id: ExpnId, span: Span, no_implicit_prelude: bool, @@ -980,7 +981,7 @@ struct DeclData<'ra> { ambiguity: CmCell, bool /*warning*/)>>, expansion: LocalExpnId, span: Span, - initial_vis: Visibility, + initial_vis: Visibility, /// If the declaration refers to an ambiguous glob set, then this is the most visible /// declaration from the set, if its visibility is different from `initial_vis`. ambiguity_vis_max: CmCell>>, @@ -1099,12 +1100,12 @@ struct AmbiguityError<'ra> { } impl<'ra> DeclData<'ra> { - fn vis(&self) -> Visibility { + fn vis(&self) -> Visibility { // Select the maximum visibility if there are multiple ambiguous glob imports. self.ambiguity_vis_max.get().map(|d| d.vis()).unwrap_or_else(|| self.initial_vis) } - fn min_vis(&self) -> Visibility { + fn min_vis(&self) -> Visibility { // Select the minimum visibility if there are multiple ambiguous glob imports. self.ambiguity_vis_min.get().map(|d| d.vis()).unwrap_or_else(|| self.initial_vis) } @@ -1490,8 +1491,8 @@ pub struct Resolver<'ra, 'tcx> { effective_visibilities: EffectiveVisibilities, macro_reachable_adts: FxIndexMap>, - doc_link_resolutions: FxIndexMap, - doc_link_traits_in_scope: FxIndexMap>, + doc_link_resolutions: FxIndexMap, + doc_link_traits_in_scope: FxIndexMap>, all_macro_rules: UnordSet = Default::default(), /// Invocation ids of all glob delegations. @@ -1539,7 +1540,7 @@ impl<'ra> ResolverArenas<'ra> { fn new_def_decl( &'ra self, res: Res, - vis: Visibility, + vis: Visibility, span: Span, expansion: LocalExpnId, parent_module: Option>, @@ -1924,7 +1925,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } fn feed_visibility(&mut self, feed: TyCtxtFeed<'tcx, LocalDefId>, vis: Visibility) { - feed.visibility(vis.to_def_id()); + feed.visibility(vis.to_mod_id()); self.visibilities_for_hashing.push((feed.def_id(), vis)); } @@ -2359,10 +2360,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } fn resolve_self(&self, ctxt: &mut SyntaxContext, module: Module<'ra>) -> Module<'ra> { - let mut module = self.expect_module(module.nearest_parent_mod()); + let mut module = self.expect_module(module.nearest_parent_mod().to_def_id()); while module.span.ctxt().normalize_to_macros_2_0() != *ctxt { let parent = module.parent.unwrap_or_else(|| self.expn_def_scope(ctxt.remove_mark())); - module = self.expect_module(parent.nearest_parent_mod()); + module = self.expect_module(parent.nearest_parent_mod().to_def_id()); } module } @@ -2749,7 +2750,7 @@ enum Stage { #[derive(Copy, Clone, Debug)] struct ImportSummary { vis: Visibility, - nearest_parent_mod: LocalDefId, + nearest_parent_mod: LocalModId, is_single: bool, priv_macro_use: bool, span: Span, diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index a1e293af69433..f2c26caa58aab 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -28,6 +28,7 @@ use rustc_session::lint::builtin::{ LEGACY_DERIVE_HELPERS, OUT_OF_SCOPE_MACRO_CALLS, UNKNOWN_DIAGNOSTIC_ATTRIBUTES, UNUSED_MACRO_RULES, UNUSED_MACROS, }; +use rustc_span::def_id::ModId; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::edition::Edition; use rustc_span::hygiene::{self, AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind}; @@ -214,8 +215,8 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> { features: &[Symbol], parent_module_id: Option, ) -> LocalExpnId { - let parent_module = - parent_module_id.map(|module_id| self.owner_def_id(module_id).to_def_id()); + let parent_module = parent_module_id + .map(|module_id| ModId::new_unchecked(self.owner_def_id(module_id).to_def_id())); let expn_id = self.tcx.with_stable_hashing_context(|hcx| { LocalExpnId::fresh( ExpnData::allow_unstable( @@ -230,8 +231,9 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> { ) }); - let parent_scope = parent_module - .map_or(self.empty_module, |def_id| self.expect_module(def_id).expect_local()); + let parent_scope = parent_module.map_or(self.empty_module, |mod_id| { + self.expect_module(mod_id.to_def_id()).expect_local() + }); self.ast_transform_scopes.insert(expn_id, parent_scope); expn_id @@ -1179,7 +1181,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { && kinds.contains(MacroKinds::BANG) // And the `macro_rules` is defined inside the attribute's module, // so it cannot be in scope unless imported. - && self.tcx.is_descendant_of(def_id, mod_def_id.to_def_id()) + && self.tcx.is_descendant_of(def_id, mod_def_id) { // Try to resolve our ident ignoring `macro_rules` scopes. // If such resolution is successful and gives the same result diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 0ea7da4f2ab87..43a0d18cde435 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -40,8 +40,8 @@ impl CrateNum { } #[inline] - pub fn as_mod_def_id(self) -> ModDefId { - ModDefId::new_unchecked(DefId { krate: self, index: CRATE_DEF_INDEX }) + pub fn as_mod_id(self) -> ModId { + ModId::new_unchecked(DefId { krate: self, index: CRATE_DEF_INDEX }) } } @@ -377,6 +377,7 @@ impl !Ord for LocalDefId {} impl !PartialOrd for LocalDefId {} pub const CRATE_DEF_ID: LocalDefId = LocalDefId { local_def_index: CRATE_DEF_INDEX }; +pub const CRATE_MOD_ID: LocalModId = LocalModId::new_unchecked(CRATE_DEF_ID); impl Idx for LocalDefId { #[inline] @@ -465,102 +466,98 @@ impl ToStableHashKey for LocalDefId { } } -macro_rules! typed_def_id { - ($Name:ident, $LocalName:ident) => { - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, StableHash)] - pub struct $Name(DefId); +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, StableHash)] +pub struct ModId(DefId); - impl $Name { - #[inline] - pub const fn new_unchecked(def_id: DefId) -> Self { - Self(def_id) - } +impl ModId { + #[inline] + pub const fn new_unchecked(def_id: DefId) -> Self { + Self(def_id) + } - #[inline] - pub fn to_def_id(self) -> DefId { - self.into() - } + #[inline] + pub fn to_def_id(self) -> DefId { + self.into() + } - #[inline] - pub fn is_local(self) -> bool { - self.0.is_local() - } + #[inline] + pub fn is_local(self) -> bool { + self.0.is_local() + } - #[inline] - pub fn as_local(self) -> Option<$LocalName> { - self.0.as_local().map($LocalName::new_unchecked) - } - } + #[inline] + pub fn as_local(self) -> Option { + self.0.as_local().map(LocalModId::new_unchecked) + } - impl From<$LocalName> for $Name { - #[inline] - fn from(local: $LocalName) -> Self { - Self(local.0.to_def_id()) - } - } + pub fn expect_local(self) -> LocalModId { + LocalModId::new_unchecked(self.0.expect_local()) + } - impl From<$Name> for DefId { - #[inline] - fn from(typed: $Name) -> Self { - typed.0 - } - } + pub fn is_crate_root(self) -> bool { + self.0.is_crate_root() + } + + pub fn is_top_level_module(self) -> bool { + self.0.is_top_level_module() + } +} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, StableHash)] - pub struct $LocalName(LocalDefId); +impl From for ModId { + #[inline] + fn from(local: LocalModId) -> Self { + Self(local.0.to_def_id()) + } +} - impl !Ord for $LocalName {} - impl !PartialOrd for $LocalName {} +impl From for DefId { + #[inline] + fn from(typed: ModId) -> Self { + typed.0 + } +} - impl $LocalName { - #[inline] - pub const fn new_unchecked(def_id: LocalDefId) -> Self { - Self(def_id) - } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, StableHash)] +pub struct LocalModId(LocalDefId); - #[inline] - pub fn to_def_id(self) -> DefId { - self.0.into() - } +impl !Ord for LocalModId {} +impl !PartialOrd for LocalModId {} - #[inline] - pub fn to_local_def_id(self) -> LocalDefId { - self.0 - } - } +impl LocalModId { + #[inline] + pub const fn new_unchecked(def_id: LocalDefId) -> Self { + Self(def_id) + } - impl From<$LocalName> for LocalDefId { - #[inline] - fn from(typed: $LocalName) -> Self { - typed.0 - } - } + pub fn is_top_level_module(self) -> bool { + self.0.is_top_level_module() + } - impl From<$LocalName> for DefId { - #[inline] - fn from(typed: $LocalName) -> Self { - typed.0.into() - } - } - }; -} + #[inline] + pub fn to_def_id(self) -> DefId { + self.0.into() + } -// N.B.: when adding new typed `DefId`s update the corresponding trait impls in -// `rustc_middle::dep_graph::dep_node_key` for `DepNodeKey`. -typed_def_id! { ModDefId, LocalModDefId } + pub fn to_mod_id(self) -> ModId { + ModId::new_unchecked(self.0.to_def_id()) + } -impl LocalModDefId { - pub const CRATE_DEF_ID: Self = Self::new_unchecked(CRATE_DEF_ID); + #[inline] + pub fn to_local_def_id(self) -> LocalDefId { + self.0 + } } -impl ModDefId { - pub fn is_top_level_module(self) -> bool { - self.0.is_top_level_module() +impl From for LocalDefId { + #[inline] + fn from(typed: LocalModId) -> Self { + typed.0 } } -impl LocalModDefId { - pub fn is_top_level_module(self) -> bool { - self.0.is_top_level_module() +impl From for DefId { + #[inline] + fn from(typed: LocalModId) -> Self { + typed.0.into() } } diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index 1cdce5cd04567..67c4da3e56a57 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -41,7 +41,7 @@ use rustc_macros::{Decodable, Encodable, StableHash}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use tracing::{debug, trace}; -use crate::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, StableCrateId}; +use crate::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, ModId, StableCrateId}; use crate::edition::Edition; use crate::source_map::SourceMap; use crate::symbol::{Symbol, kw, sym}; @@ -1012,7 +1012,7 @@ pub struct ExpnData { /// if this `ExpnData` corresponds to a macro invocation pub macro_def_id: Option, /// The normal module (`mod`) in which the expanded macro was defined. - pub parent_module: Option, + pub parent_module: Option, /// Suppresses the `unsafe_code` lint for code produced by this macro. pub(crate) allow_internal_unsafe: bool, /// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`) for this macro. @@ -1037,7 +1037,7 @@ impl ExpnData { allow_internal_unstable: Option>, edition: Edition, macro_def_id: Option, - parent_module: Option, + parent_module: Option, allow_internal_unsafe: bool, local_inner_macros: bool, collapse_debuginfo: bool, @@ -1066,7 +1066,7 @@ impl ExpnData { call_site: Span, edition: Edition, macro_def_id: Option, - parent_module: Option, + parent_module: Option, ) -> ExpnData { ExpnData { kind, @@ -1091,7 +1091,7 @@ impl ExpnData { edition: Edition, allow_internal_unstable: Arc<[Symbol]>, macro_def_id: Option, - parent_module: Option, + parent_module: Option, ) -> ExpnData { ExpnData { allow_internal_unstable: Some(allow_internal_unstable), diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs index 7e706a9838306..e104cc04310be 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs @@ -833,7 +833,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { None => generic_param_scope, }, }; - match self.tcx.is_descendant_of(type_scope.into(), lifetime_scope.into()) { + match self.tcx.is_descendant_of(type_scope, lifetime_scope) { true => type_scope, false => lifetime_scope, } diff --git a/library/core/src/attribute_docs.rs b/library/core/src/attribute_docs.rs index 8591e866f482b..22fa75b1bd963 100644 --- a/library/core/src/attribute_docs.rs +++ b/library/core/src/attribute_docs.rs @@ -445,3 +445,64 @@ mod no_std_attribute {} /// /// [the `inline` attribute]: ../reference/attributes/codegen.html#the-inline-attribute mod inline_attribute {} + +#[doc(attribute = "cold")] +// +/// Hint to the compiler that a function is unlikely to be called. +/// +/// Marking a function `#[cold]` tells the compiler that calls to it are rare, so it can +/// optimize for the common case where the function is not called. It is only a hint: the +/// compiler may ignore it, and it does not change the function's behavior. +/// +/// It is typically used on functions that handle uncommon cases, such as error or panic paths: +/// +/// ```rust +/// # #![allow(dead_code)] +/// fn check(value: i32) { +/// if value < 0 { +/// report_error("value must be non-negative"); +/// } +/// // ... the common case continues here ... +/// } +/// +/// #[cold] +/// fn report_error(message: &str) { +/// eprintln!("error: {message}"); +/// } +/// ``` +/// +/// For more information, see the Reference on [the `cold` attribute]. +/// +/// [the `cold` attribute]: ../reference/attributes/codegen.html#the-cold-attribute +mod cold_attribute {} + +#[doc(attribute = "track_caller")] +// +/// Make a function report the location of its caller instead of its own. +/// +/// When a function panics, the panic message normally points at the line inside that function +/// where the panic happened. `#[track_caller]` changes that: it lets the function see the +/// [`Location`] it was called from, so the panic (and any direct use of [`Location::caller`]) +/// points at the call site instead. The standard library uses this on methods like +/// [`Option::unwrap`], so a failed `unwrap` blames the line that called it rather than a line +/// inside the standard library. +/// +/// ```rust,should_panic +/// #[track_caller] +/// fn assert_even(n: i32) { +/// assert!(n % 2 == 0, "{n} is not even"); +/// } +/// +/// // The panic blames this line, not the `assert!` inside `assert_even`. +/// assert_even(3); +/// ``` +/// +/// The attribute applies to functions with the default `"Rust"` ABI, other than `fn main`. +/// +/// For more information, see the Reference on [the `track_caller` attribute]. +/// +/// [`Location`]: panic::Location +/// [`Location::caller`]: panic::Location::caller +/// [`Option::unwrap`]: Option::unwrap +/// [the `track_caller` attribute]: ../reference/attributes/codegen.html#the-track_caller-attribute +mod track_caller_attribute {} diff --git a/library/core/src/bool.rs b/library/core/src/bool.rs index 10ef8e3b33b53..7a2823baaae0f 100644 --- a/library/core/src/bool.rs +++ b/library/core/src/bool.rs @@ -129,4 +129,32 @@ impl bool { ) -> Result<(), E> { if self { Ok(()) } else { Err(f()) } } + + /// Toggles `self` in-place. + /// + /// - If `self` is [`true`], sets `self` to [`false`]. + /// - If `self` is [`false`], sets `self` to [`true`]. + /// + /// Equivalent to `value = !value`. + /// + /// # Examples + /// + /// ``` + /// #![feature(bool_toggle)] + /// let mut boolean = false; + /// + /// boolean.toggle(); + /// assert_eq!(boolean, true); + /// + /// boolean.toggle(); + /// assert_eq!(boolean, false); + /// ``` + /// + /// [`true`]: ../std/keyword.true.html + /// [`false`]: ../std/keyword.false.html + #[unstable(feature = "bool_toggle", issue = "159298")] + #[inline] + pub const fn toggle(&mut self) { + *self = !*self; + } } diff --git a/library/std_detect/src/detect/macros.rs b/library/std_detect/src/detect/macros.rs index 17140e15653d2..43f59e22c3a9b 100644 --- a/library/std_detect/src/detect/macros.rs +++ b/library/std_detect/src/detect/macros.rs @@ -75,7 +75,7 @@ macro_rules! features { }; )* ($t:tt,) => { - $crate::$macro_name!($t); + $crate::$macro_name!($t) }; ($t:tt) => { compile_error!( diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index d4cdc7781fed5..46b8683137c60 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::thin_vec::{ThinVec, thin_vec}; use rustc_hir::def::{DefKind, MacroKinds, Res}; -use rustc_hir::def_id::{DefId, DefIdSet, LocalDefId, LocalModDefId}; +use rustc_hir::def_id::{DefId, DefIdSet, LocalDefId, LocalModId}; use rustc_hir::{self as hir, Mutability, find_attr}; use rustc_metadata::creader::{CStore, LoadedMacro}; use rustc_middle::ty::fast_reject::SimplifiedType; @@ -181,7 +181,7 @@ pub(crate) fn try_inline( pub(crate) fn try_inline_glob( cx: &mut DocContext<'_>, res: Res, - current_mod: LocalModDefId, + current_mod: LocalModId, visited: &mut DefIdSet, inlined_names: &mut FxHashSet<(ItemType, Symbol)>, import: &hir::Item<'_>, diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 620951bb4974b..3034ce5fb318c 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -25,7 +25,7 @@ use rustc_resolve::rustdoc::{ DocFragment, add_doc_fragment, attrs_to_doc_fragments, inner_docs, span_of_fragments, }; use rustc_session::Session; -use rustc_span::def_id::CRATE_DEF_ID; +use rustc_span::def_id::{CRATE_DEF_ID, ModId}; use rustc_span::hygiene::MacroKind; use rustc_span::symbol::{Symbol, kw, sym}; use rustc_span::{DUMMY_SP, FileName, Ident, Loc, RemapPathScopeComponents}; @@ -871,7 +871,7 @@ impl Item { /// Returns the visibility of the current item. If the visibility is "inherited", then `None` /// is returned. - pub(crate) fn visibility(&self, tcx: TyCtxt<'_>) -> Option> { + pub(crate) fn visibility(&self, tcx: TyCtxt<'_>) -> Option> { let def_id = match self.item_id { // Anything but DefId *shouldn't* matter, but return a reasonable value anyway. ItemId::Auto { .. } | ItemId::Blanket { .. } => return None, diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index f77e201805a2b..9290555f2ef39 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -16,6 +16,7 @@ use rustc_hir::find_attr; use rustc_metadata::rendered_const; use rustc_middle::mir; use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, TyCtxt, TypeVisitableExt}; +use rustc_span::def_id::ModId; use rustc_span::symbol::{Symbol, kw, sym}; use tracing::{debug, warn}; @@ -556,17 +557,17 @@ where } /// Find the nearest parent module of a [`DefId`]. -pub(crate) fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option { +pub(crate) fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option { if def_id.is_top_level_module() { // The crate root has no parent. Use it as the root instead. - Some(def_id) + Some(ModId::new_unchecked(def_id)) } else { let mut current = def_id; // The immediate parent might not always be a module. // Find the first parent which is. while let Some(parent) = tcx.opt_parent(current) { if tcx.def_kind(parent) == DefKind::Mod { - return Some(parent); + return Some(ModId::new_unchecked(parent)); } current = parent; } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 8c225da583bf2..4b9bf8bbd3a07 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -1421,29 +1421,29 @@ pub(crate) fn visibility_print_with_space(item: &clean::Item, cx: &Context<'_>) match vis { ty::Visibility::Public => f.write_str("pub ")?, - ty::Visibility::Restricted(vis_did) => { + ty::Visibility::Restricted(vis_mod_id) => { // FIXME(camelid): This may not work correctly if `item_did` is a module. // However, rustdoc currently never displays a module's // visibility, so it shouldn't matter. let parent_module = find_nearest_parent_module(cx.tcx(), item.item_id.expect_def_id()); - if vis_did.is_crate_root() { + if vis_mod_id.is_crate_root() { f.write_str("pub(crate) ")?; - } else if parent_module == Some(vis_did) { + } else if parent_module == Some(vis_mod_id) { // `pub(in foo)` where `foo` is the parent module // is the same as no visibility modifier; do nothing } else if parent_module - .and_then(|parent| find_nearest_parent_module(cx.tcx(), parent)) - == Some(vis_did) + .and_then(|parent| find_nearest_parent_module(cx.tcx(), parent.to_def_id())) + == Some(vis_mod_id) { f.write_str("pub(super) ")?; } else { - let path = cx.tcx().def_path(vis_did); + let path = cx.tcx().def_path(vis_mod_id.to_def_id()); debug!("path={path:?}"); // modified from `resolved_path()` to work with `DefPathData` let last_name = path.data.last().unwrap().data.get_opt_name().unwrap(); - let anchor = print_anchor(vis_did, last_name, cx); + let anchor = print_anchor(vis_mod_id.to_def_id(), last_name, cx); f.write_str("pub(in ")?; for seg in &path.data[..path.data.len() - 1] { diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 740a69d3c6b7a..470ac0c8a5c86 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -16,6 +16,7 @@ use rustc_hir::{HeaderSafety, Safety, find_attr}; use rustc_metadata::rendered_const; use rustc_middle::ty::TyCtxt; use rustc_middle::{bug, ty}; +use rustc_span::def_id::ModId; use rustc_span::{Pos, Symbol, kw, sym}; use rustdoc_json_types::*; @@ -207,15 +208,15 @@ impl FromClean for Option { } } -impl FromClean>> for Visibility { - fn from_clean(v: &Option>, renderer: &JsonRenderer<'_>) -> Self { - match v { +impl FromClean>> for Visibility { + fn from_clean(v: &Option>, renderer: &JsonRenderer<'_>) -> Self { + match *v { None => Visibility::Default, Some(ty::Visibility::Public) => Visibility::Public, - Some(ty::Visibility::Restricted(did)) if did.is_crate_root() => Visibility::Crate, - Some(ty::Visibility::Restricted(did)) => Visibility::Restricted { - parent: renderer.id_from_item_default((*did).into()), - path: renderer.tcx.def_path(*did).to_string_no_crate_verbose(), + Some(ty::Visibility::Restricted(mod_id)) if mod_id.is_crate_root() => Visibility::Crate, + Some(ty::Visibility::Restricted(mod_id)) => Visibility::Restricted { + parent: renderer.id_from_item_default(ItemId::DefId(mod_id.to_def_id())), + path: renderer.tcx.def_path(mod_id.to_def_id()).to_string_no_crate_verbose(), }, } } diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 02423c4b9391b..ce191aaf445d5 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -26,6 +26,7 @@ use rustc_resolve::rustdoc::{ use rustc_session::config::CrateType; use rustc_session::lint::Lint; use rustc_span::BytePos; +use rustc_span::def_id::ModId; use rustc_span::symbol::{Ident, Symbol, sym}; use smallvec::{SmallVec, smallvec}; use tracing::{debug, info, instrument, trace}; @@ -170,7 +171,7 @@ struct UnresolvedPath<'a> { /// Item on which the link is resolved, used for resolving `Self`. item_id: DefId, /// The scope the link was resolved in. - module_id: DefId, + module_id: ModId, /// If part of the link resolved, this has the `Res`. /// /// In `[std::io::Error::x]`, `std::io::Error` would be a partial resolution. @@ -208,7 +209,7 @@ pub(crate) enum UrlFragment { #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub(crate) struct ResolutionInfo { item_id: DefId, - module_id: DefId, + module_id: ModId, dis: Option, path_str: Box, extra_fragment: Option, @@ -286,7 +287,7 @@ impl<'tcx> LinkCollector<'_, 'tcx> { &self, path_str: &'path str, item_id: DefId, - module_id: DefId, + module_id: ModId, ) -> Result<(Res, DefId), UnresolvedPath<'path>> { let tcx = self.cx.tcx; let no_res = || UnresolvedPath { @@ -355,7 +356,7 @@ impl<'tcx> LinkCollector<'_, 'tcx> { path_str: &str, ns: Namespace, item_id: DefId, - module_id: DefId, + module_id: ModId, ) -> Option { if let res @ Some(..) = resolve_self_ty(self.cx.tcx, path_str, ns, item_id) { return res; @@ -392,7 +393,7 @@ impl<'tcx> LinkCollector<'_, 'tcx> { ns: Namespace, disambiguator: Option, item_id: DefId, - module_id: DefId, + module_id: ModId, ) -> Result)>, UnresolvedPath<'path>> { let tcx = self.cx.tcx; @@ -604,7 +605,7 @@ fn resolve_associated_item<'tcx>( item_name: Symbol, ns: Namespace, disambiguator: Option, - module_id: DefId, + module_id: ModId, ) -> Vec<(Res, DefId)> { let item_ident = Ident::with_dummy_span(item_name); @@ -665,7 +666,7 @@ fn resolve_assoc_on_primitive<'tcx>( prim: PrimitiveType, ns: Namespace, item_ident: Ident, - module_id: DefId, + module_id: ModId, ) -> Vec<(Res, DefId)> { let root_res = Res::Primitive(prim); let items = resolve_primitive_inherent_assoc_item(tcx, prim, ns, item_ident); @@ -690,7 +691,7 @@ fn resolve_assoc_on_adt<'tcx>( item_ident: Ident, ns: Namespace, disambiguator: Option, - module_id: DefId, + module_id: ModId, ) -> Vec<(Res, DefId)> { debug!("looking for associated item named {item_ident} for item {adt_def_id:?}"); let root_res = Res::from_def_id(tcx, adt_def_id); @@ -735,7 +736,7 @@ fn resolve_assoc_on_simple_type<'tcx>( ty_def_id: DefId, item_ident: Ident, ns: Namespace, - module_id: DefId, + module_id: ModId, ) -> Vec<(Res, DefId)> { let root_res = Res::from_def_id(tcx, ty_def_id); // Checks if item_name belongs to `impl SomeItem` @@ -781,7 +782,7 @@ fn resolve_structfield<'tcx>(adt_def: ty::AdtDef<'tcx>, item_name: Symbol) -> Op /// `::source`. fn resolve_associated_trait_item<'tcx>( ty: Ty<'tcx>, - module: DefId, + module: ModId, item_ident: Ident, ns: Namespace, tcx: TyCtxt<'tcx>, @@ -841,7 +842,7 @@ fn trait_assoc_to_impl_assoc_item<'tcx>( fn trait_impls_for<'tcx>( tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, - module: DefId, + module: ModId, ) -> FxIndexSet<(DefId, DefId)> { let mut impls = FxIndexSet::default(); @@ -1097,7 +1098,7 @@ impl LinkCollector<'_, '_> { return; } let module_id = match tcx.def_kind(item_id) { - DefKind::Mod if item.inner_docs(tcx) => item_id, + DefKind::Mod if item.inner_docs(tcx) => ModId::new_unchecked(item_id), _ => find_nearest_parent_module(tcx, item_id).unwrap(), }; for md_link in preprocessed_markdown_links(&doc) { @@ -1180,7 +1181,7 @@ impl LinkCollector<'_, '_> { dox: &str, item: &Item, item_id: DefId, - module_id: DefId, + module_id: ModId, PreprocessedMarkdownLink(pp_link, ori_link): &PreprocessedMarkdownLink, ) -> Option { trace!("considering link '{}'", ori_link.link); @@ -2112,7 +2113,7 @@ fn resolution_failure( } let last_found_module = match *partial_res { - Some(Res::Def(DefKind::Mod, id)) => Some(id), + Some(Res::Def(DefKind::Mod, id)) => Some(ModId::new_unchecked(id)), None => Some(module_id), _ => None, }; diff --git a/src/librustdoc/passes/lint/redundant_explicit_links.rs b/src/librustdoc/passes/lint/redundant_explicit_links.rs index cd7b7caac69ad..22a79ecf6a53e 100644 --- a/src/librustdoc/passes/lint/redundant_explicit_links.rs +++ b/src/librustdoc/passes/lint/redundant_explicit_links.rs @@ -9,7 +9,7 @@ use rustc_resolve::rustdoc::pulldown_cmark::{ BrokenLink, BrokenLinkCallback, CowStr, Event, LinkType, OffsetIter, Parser, Tag, }; use rustc_resolve::rustdoc::{prepare_to_doc_link_resolution, source_span_for_markdown_range}; -use rustc_span::def_id::DefId; +use rustc_span::def_id::{DefId, ModId}; use rustc_span::{Span, Symbol}; use crate::clean::Item; @@ -58,7 +58,7 @@ fn check_redundant_explicit_link_for_did( } let module_id = match cx.tcx.def_kind(did) { - DefKind::Mod if item.inner_docs(cx.tcx) => did, + DefKind::Mod if item.inner_docs(cx.tcx) => ModId::new_unchecked(did), _ => find_nearest_parent_module(cx.tcx, did).unwrap(), }; diff --git a/src/tools/clippy/clippy_lints/src/approx_const.rs b/src/tools/clippy/clippy_lints/src/approx_const.rs index 2ea921e5d4614..b7b9befd10b0b 100644 --- a/src/tools/clippy/clippy_lints/src/approx_const.rs +++ b/src/tools/clippy/clippy_lints/src/approx_const.rs @@ -75,7 +75,7 @@ impl ApproxConstant { } impl LateLintPass<'_> for ApproxConstant { - fn check_lit(&mut self, cx: &LateContext<'_>, _hir_id: HirId, lit: Lit, _negated: bool) { + fn check_lit(&mut self, cx: &LateContext<'_>, _hir_id: HirId, lit: Lit, _is_negated_pat: bool) { match lit.node { LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty { FloatTy::F16 => self.check_known_consts(cx, lit.span, s, "f16"), diff --git a/src/tools/clippy/clippy_lints/src/error_impl_error.rs b/src/tools/clippy/clippy_lints/src/error_impl_error.rs index 4b9e3cee011c6..4b7aaa34d1ad8 100644 --- a/src/tools/clippy/clippy_lints/src/error_impl_error.rs +++ b/src/tools/clippy/clippy_lints/src/error_impl_error.rs @@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for ErrorImplError { /// which aren't reexported fn is_visible_outside_module(cx: &LateContext<'_>, def_id: LocalDefId) -> bool { !matches!( - cx.tcx.visibility(def_id), - Visibility::Restricted(mod_def_id) if cx.tcx.parent_module_from_def_id(def_id).to_def_id() == mod_def_id + cx.tcx.local_visibility(def_id), + Visibility::Restricted(mod_def_id) if cx.tcx.parent_module_from_def_id(def_id) == mod_def_id ) } diff --git a/src/tools/clippy/clippy_lints/src/infallible_try_from.rs b/src/tools/clippy/clippy_lints/src/infallible_try_from.rs index b7cbe667b3346..7472ec0a2106b 100644 --- a/src/tools/clippy/clippy_lints/src/infallible_try_from.rs +++ b/src/tools/clippy/clippy_lints/src/infallible_try_from.rs @@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleTryFrom { .filter_by_name_unhygienic_and_kind(sym::Error, AssocTag::Type) { let ii_ty = cx.tcx.type_of(ii.def_id).instantiate_identity().skip_norm_wip(); - if !ii_ty.is_inhabited_from(cx.tcx, ii.def_id, cx.typing_env()) { + if !ii_ty.is_inhabited_from(cx.tcx, cx.tcx.parent_module_from_def_id(ii.def_id.expect_local()), cx.typing_env()) { let mut span = MultiSpan::from_span(cx.tcx.def_span(item.owner_id.to_def_id())); let ii_ty_span = cx .tcx diff --git a/src/tools/clippy/clippy_lints/src/inherent_impl.rs b/src/tools/clippy/clippy_lints/src/inherent_impl.rs index 257a165ba8315..7475897852177 100644 --- a/src/tools/clippy/clippy_lints/src/inherent_impl.rs +++ b/src/tools/clippy/clippy_lints/src/inherent_impl.rs @@ -3,7 +3,7 @@ use clippy_config::types::InherentImplLintScope; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{fulfill_or_allowed, is_cfg_test, is_in_cfg_test}; use rustc_data_structures::fx::FxHashMap; -use rustc_hir::def_id::{LocalDefId, LocalModDefId}; +use rustc_hir::def_id::{LocalDefId, LocalModId}; use rustc_hir::{Item, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; @@ -63,7 +63,7 @@ impl MultipleInherentImpl { #[derive(Hash, Eq, PartialEq, Clone)] enum Criterion { - Module(LocalModDefId), + Module(LocalModId), File(FileName), Crate, } diff --git a/src/tools/clippy/clippy_lints/src/redundant_pub_crate.rs b/src/tools/clippy/clippy_lints/src/redundant_pub_crate.rs index c7f7b47403376..8abb5159f90e6 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_pub_crate.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_pub_crate.rs @@ -5,7 +5,7 @@ use rustc_hir::{Item, ItemKind, UseKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::impl_lint_pass; -use rustc_span::def_id::CRATE_DEF_ID; +use rustc_span::def_id::CRATE_MOD_ID; declare_clippy_lint! { /// ### What it does @@ -44,7 +44,7 @@ pub struct RedundantPubCrate { impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { - if cx.tcx.visibility(item.owner_id.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()) + if cx.tcx.local_visibility(item.owner_id.def_id) == ty::Visibility::Restricted(CRATE_MOD_ID) && !cx.effective_visibilities.is_exported(item.owner_id.def_id) && self.is_exported.last() == Some(&false) && !is_ignorable_export(item) diff --git a/src/tools/clippy/clippy_lints/src/unused_trait_names.rs b/src/tools/clippy/clippy_lints/src/unused_trait_names.rs index be41bdd380204..e09018284434f 100644 --- a/src/tools/clippy/clippy_lints/src/unused_trait_names.rs +++ b/src/tools/clippy/clippy_lints/src/unused_trait_names.rs @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedTraitNames { && cx.tcx.resolutions(()).maybe_unused_trait_imports.contains(&item.owner_id.def_id) // Only check this import if it is visible to its module only (no pub, pub(crate), ...) && let module = cx.tcx.parent_module_from_def_id(item.owner_id.def_id) - && cx.tcx.visibility(item.owner_id.def_id) == Visibility::Restricted(module.to_def_id()) + && cx.tcx.local_visibility(item.owner_id.def_id) == Visibility::Restricted(module) && let Some(last_segment) = path.segments.last() && let Some(snip) = snippet_opt(cx, last_segment.ident.span) && self.msrv.meets(cx, msrvs::UNDERSCORE_IMPORTS) diff --git a/src/tools/clippy/clippy_lints/src/wildcard_imports.rs b/src/tools/clippy/clippy_lints/src/wildcard_imports.rs index 22c46527b5c6c..19ab3789232cd 100644 --- a/src/tools/clippy/clippy_lints/src/wildcard_imports.rs +++ b/src/tools/clippy/clippy_lints/src/wildcard_imports.rs @@ -123,7 +123,7 @@ impl LateLintPass<'_> for WildcardImports { } let module = cx.tcx.parent_module_from_def_id(item.owner_id.def_id); - if cx.tcx.visibility(item.owner_id.def_id) != ty::Visibility::Restricted(module.to_def_id()) + if cx.tcx.local_visibility(item.owner_id.def_id) != ty::Visibility::Restricted(module) && !self.warn_on_all { return; diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 56a5e80df2df8..2be96a6f08973 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -88,7 +88,7 @@ use rustc_data_structures::unhash::UnindexMap; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::attrs::CfgEntry; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId}; +use rustc_hir::def_id::{DefId, LocalDefId, LocalModId}; use rustc_hir::definitions::{DefPath, DefPathData}; use rustc_hir::hir_id::{HirIdMap, HirIdSet}; use rustc_hir::intravisit::{Visitor, walk_expr}; @@ -2348,11 +2348,11 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool { false } -static TEST_ITEM_NAMES_CACHE: OnceLock>>> = OnceLock::new(); +static TEST_ITEM_NAMES_CACHE: OnceLock>>> = OnceLock::new(); /// Returns the names of the test items in the given module. /// The names are sorted using the default `Symbol` ordering. -fn test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId) -> Vec { +fn test_item_names(tcx: TyCtxt<'_>, module: LocalModId) -> Vec { let cache = TEST_ITEM_NAMES_CACHE.get_or_init(|| Mutex::new(FxHashMap::default())); let mut map = cache.lock().unwrap(); match map.entry(module) { diff --git a/tests/codegen-llvm/array-equality.rs b/tests/codegen-llvm/array-equality.rs index 385b7d7803594..706caebdcb6d4 100644 --- a/tests/codegen-llvm/array-equality.rs +++ b/tests/codegen-llvm/array-equality.rs @@ -1,5 +1,5 @@ //@ revisions: llvm-current llvm-next -//@[llvm-current] ignore-llvm-version: 23-99 +//@[llvm-current] ignore-llvm-version: 23 - 99 //@[llvm-next] min-llvm-version: 23 //@ compile-flags: -Copt-level=3 -Z merge-functions=disabled //@ only-x86_64 diff --git a/tests/codegen-llvm/issues/rem-match-unreachable.rs b/tests/codegen-llvm/issues/rem-match-unreachable.rs new file mode 100644 index 0000000000000..cd4f0579f0a4a --- /dev/null +++ b/tests/codegen-llvm/issues/rem-match-unreachable.rs @@ -0,0 +1,32 @@ +// Matching every possible result of `x % 5` should not keep unreachable +// fallback panic code. + +//@ compile-flags: -Copt-level=3 +//@ only-64bit + +#![crate_type = "lib"] + +unsafe extern "C" { + fn rem_arm0(x: usize) -> usize; + fn rem_arm1(x: usize) -> usize; + fn rem_arm2(x: usize) -> usize; + fn rem_arm3(x: usize) -> usize; + fn rem_arm4(x: usize) -> usize; +} + +// CHECK-LABEL: @rem_match_unreachable +// CHECK-NOT: core::panicking::panic +// CHECK-NOT: entered unreachable code +#[no_mangle] +pub fn rem_match_unreachable(x: usize) -> usize { + unsafe { + match x % 5 { + 0 => rem_arm0(x), + 1 => rem_arm1(x), + 2 => rem_arm2(x), + 3 => rem_arm3(x), + 4 => rem_arm4(x), + _ => unreachable!(), + } + } +} diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155125.stderr b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155125.stderr index 6675831bddc86..30aad09279447 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155125.stderr +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155125.stderr @@ -1,5 +1,5 @@ error[E0428]: the name `foo` is defined multiple times - --> $DIR/hir-crate-items-before-lowering-ices.rs:12:17 + --> $DIR/hir-crate-items-before-lowering-ices.rs:13:17 | LL | fn foo() {} | -------- previous definition of the value `foo` here @@ -9,7 +9,7 @@ LL | reuse foo; = note: `foo` must be defined only once in the value namespace of this block error: complex const arguments must be placed inside of a `const` block - --> $DIR/hir-crate-items-before-lowering-ices.rs:10:37 + --> $DIR/hir-crate-items-before-lowering-ices.rs:11:37 | LL | core::direct_const_arg!({ | _____________________________________^ diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155127.stderr b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155127.stderr index 350bf5df3256a..228d5fb299203 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155127.stderr +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155127.stderr @@ -1,5 +1,5 @@ error: `#[deprecated]` attribute cannot be used on delegations - --> $DIR/hir-crate-items-before-lowering-ices.rs:26:9 + --> $DIR/hir-crate-items-before-lowering-ices.rs:27:9 | LL | #[deprecated] | ^^^^^^^^^^^^^ diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155128.stderr b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155128.stderr index 80ecb2ec0fca5..674035c79f019 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155128.stderr +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155128.stderr @@ -1,5 +1,5 @@ error: delegation's target expression is specified for function with no params - --> $DIR/hir-crate-items-before-lowering-ices.rs:36:18 + --> $DIR/hir-crate-items-before-lowering-ices.rs:37:18 | LL | reuse a as b { | __________________^ @@ -10,7 +10,7 @@ LL | | } | |_____^ error[E0061]: this function takes 0 arguments but 1 argument was supplied - --> $DIR/hir-crate-items-before-lowering-ices.rs:36:11 + --> $DIR/hir-crate-items-before-lowering-ices.rs:37:11 | LL | reuse a as b { | ___________^______- @@ -21,7 +21,7 @@ LL | | } | |_____- unexpected argument of type `fn() {foo::<_>}` | note: function defined here - --> $DIR/hir-crate-items-before-lowering-ices.rs:34:8 + --> $DIR/hir-crate-items-before-lowering-ices.rs:35:8 | LL | fn a() {} | ^ diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155164.stderr b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155164.stderr index 6164dabe74bff..b44a3c4174540 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155164.stderr +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155164.stderr @@ -1,5 +1,5 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/hir-crate-items-before-lowering-ices.rs:47:37 + --> $DIR/hir-crate-items-before-lowering-ices.rs:48:37 | LL | core::direct_const_arg!({ | _____________________________________^ diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155202.stderr b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155202.stderr index 28f045ca69442..5012905807597 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155202.stderr +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155202.stderr @@ -1,16 +1,18 @@ -error[E0425]: cannot find value `async` in this scope - --> $DIR/hir-crate-items-before-lowering-ices.rs:66:13 +error: function cannot return without recursing + --> $DIR/hir-crate-items-before-lowering-ices.rs:67:22 | -LL | async || {}; - | ^^^^^ not found in this scope - -error[E0308]: mismatched types - --> $DIR/hir-crate-items-before-lowering-ices.rs:66:22 +LL | reuse Trait::bar { + | ^^^ + | | + | cannot return without recursing + | recursive call site + | + = help: a `loop` may express intention better if this is on purpose +note: the lint level is defined here + --> $DIR/hir-crate-items-before-lowering-ices.rs:61:8 | -LL | async || {}; - | ^^ expected `bool`, found `()` +LL | #[deny(unconditional_recursion)] + | ^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0308, E0425. -For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.rs b/tests/ui/delegation/hir-crate-items-before-lowering-ices.rs index 07f5a1ad1712f..aaf84514eb784 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.rs +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.rs @@ -1,4 +1,5 @@ //@ revisions: ice_155125 ice_155127 ice_155128 ice_155164 ice_155202 +//@[ice_155202] edition: 2024 #![feature(min_generic_const_args, fn_delegation)] @@ -57,14 +58,14 @@ mod ice_155164 { } #[cfg(ice_155202)] +#[deny(unconditional_recursion)] mod ice_155202 { trait Trait { fn bar(self); } impl Trait for () { - reuse Trait::bar { - async || {}; //[ice_155202]~ ERROR: mismatched types - //[ice_155202]~^ ERROR: cannot find value `async` in this scope + reuse Trait::bar { //[ice_155202]~ ERROR: cannot return without recursing + async || {}; } } } diff --git a/tests/ui/lint/lint-type-overflow2.rs b/tests/ui/lint/lint-type-overflow2.rs index d3ff02aeb722f..622208b33cb08 100644 --- a/tests/ui/lint/lint-type-overflow2.rs +++ b/tests/ui/lint/lint-type-overflow2.rs @@ -5,9 +5,6 @@ #![deny(overflowing_literals)] fn main() { - let x2: i8 = --128; //~ ERROR literal out of range for `i8` - //~| WARN use of a double negation - let x = -65520.0_f16; //~ ERROR literal out of range for `f16` let x = 65520.0_f16; //~ ERROR literal out of range for `f16` let x = -3.40282357e+38_f32; //~ ERROR literal out of range for `f32` diff --git a/tests/ui/lint/lint-type-overflow2.stderr b/tests/ui/lint/lint-type-overflow2.stderr index c045d243753e4..f8c0c6d4ef3a1 100644 --- a/tests/ui/lint/lint-type-overflow2.stderr +++ b/tests/ui/lint/lint-type-overflow2.stderr @@ -1,25 +1,10 @@ -warning: use of a double negation - --> $DIR/lint-type-overflow2.rs:8:18 - | -LL | let x2: i8 = --128; - | ^^^^^ - | - = note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages - = note: use `-= 1` if you meant to decrement the value - = note: `#[warn(double_negations)]` on by default -help: add parentheses for clarity - | -LL | let x2: i8 = -(-128); - | + + - -error: literal out of range for `i8` - --> $DIR/lint-type-overflow2.rs:8:20 +error: literal out of range for `f16` + --> $DIR/lint-type-overflow2.rs:8:14 | -LL | let x2: i8 = --128; - | ^^^ +LL | let x = -65520.0_f16; + | ^^^^^^^^^^^ | - = note: the literal `128` does not fit into the type `i8` whose range is `-128..=127` - = help: consider using the type `u8` instead + = note: the literal `65520.0_f16` does not fit into the type `f16` and will be converted to `f16::INFINITY` note: the lint level is defined here --> $DIR/lint-type-overflow2.rs:5:9 | @@ -27,15 +12,7 @@ LL | #![deny(overflowing_literals)] | ^^^^^^^^^^^^^^^^^^^^ error: literal out of range for `f16` - --> $DIR/lint-type-overflow2.rs:11:14 - | -LL | let x = -65520.0_f16; - | ^^^^^^^^^^^ - | - = note: the literal `65520.0_f16` does not fit into the type `f16` and will be converted to `f16::INFINITY` - -error: literal out of range for `f16` - --> $DIR/lint-type-overflow2.rs:12:14 + --> $DIR/lint-type-overflow2.rs:9:14 | LL | let x = 65520.0_f16; | ^^^^^^^^^^^ @@ -43,7 +20,7 @@ LL | let x = 65520.0_f16; = note: the literal `65520.0_f16` does not fit into the type `f16` and will be converted to `f16::INFINITY` error: literal out of range for `f32` - --> $DIR/lint-type-overflow2.rs:13:14 + --> $DIR/lint-type-overflow2.rs:10:14 | LL | let x = -3.40282357e+38_f32; | ^^^^^^^^^^^^^^^^^^ @@ -51,7 +28,7 @@ LL | let x = -3.40282357e+38_f32; = note: the literal `3.40282357e+38_f32` does not fit into the type `f32` and will be converted to `f32::INFINITY` error: literal out of range for `f32` - --> $DIR/lint-type-overflow2.rs:14:14 + --> $DIR/lint-type-overflow2.rs:11:14 | LL | let x = 3.40282357e+38_f32; | ^^^^^^^^^^^^^^^^^^ @@ -59,7 +36,7 @@ LL | let x = 3.40282357e+38_f32; = note: the literal `3.40282357e+38_f32` does not fit into the type `f32` and will be converted to `f32::INFINITY` error: literal out of range for `f64` - --> $DIR/lint-type-overflow2.rs:15:14 + --> $DIR/lint-type-overflow2.rs:12:14 | LL | let x = -1.7976931348623159e+308_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +44,7 @@ LL | let x = -1.7976931348623159e+308_f64; = note: the literal `1.7976931348623159e+308_f64` does not fit into the type `f64` and will be converted to `f64::INFINITY` error: literal out of range for `f64` - --> $DIR/lint-type-overflow2.rs:16:14 + --> $DIR/lint-type-overflow2.rs:13:14 | LL | let x = 1.7976931348623159e+308_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -75,7 +52,7 @@ LL | let x = 1.7976931348623159e+308_f64; = note: the literal `1.7976931348623159e+308_f64` does not fit into the type `f64` and will be converted to `f64::INFINITY` error: literal out of range for `f128` - --> $DIR/lint-type-overflow2.rs:17:14 + --> $DIR/lint-type-overflow2.rs:14:14 | LL | let x = -1.1897314953572317650857593266280075e+4932_f128; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -83,12 +60,12 @@ LL | let x = -1.1897314953572317650857593266280075e+4932_f128; = note: the literal `1.1897314953572317650857593266280075e+4932_f128` does not fit into the type `f128` and will be converted to `f128::INFINITY` error: literal out of range for `f128` - --> $DIR/lint-type-overflow2.rs:18:14 + --> $DIR/lint-type-overflow2.rs:15:14 | LL | let x = 1.1897314953572317650857593266280075e+4932_f128; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the literal `1.1897314953572317650857593266280075e+4932_f128` does not fit into the type `f128` and will be converted to `f128::INFINITY` -error: aborting due to 9 previous errors; 1 warning emitted +error: aborting due to 8 previous errors diff --git a/tests/ui/lint/lint-type-overflow3.rs b/tests/ui/lint/lint-type-overflow3.rs new file mode 100644 index 0000000000000..d51f94fae696c --- /dev/null +++ b/tests/ui/lint/lint-type-overflow3.rs @@ -0,0 +1,21 @@ +//@ compile-flags: --emit link +// The above flags (which are passed in `cargo build`) are required for +// the `arithmetic_overflow` lint to function. + +#![deny(overflowing_literals, arithmetic_overflow)] + +fn main() { + let x: i8 = 128; + //~^ ERROR literal out of range for `i8` + let x: i8 = -128; + let x: i8 = --128; //~ WARN use of a double negation + //~^ ERROR this arithmetic operation will overflow + let x: i8 = ---128; //~ WARN use of a double negation + //~^ ERROR this arithmetic operation will overflow + let x: i8 = ----128; //~ WARN use of a double negation + //~^ ERROR this arithmetic operation will overflow + let x: i8 = -----128; //~ WARN use of a double negation + //~^ ERROR this arithmetic operation will overflow + let x: i8 = ------128; //~ WARN use of a double negation + //~^ ERROR this arithmetic operation will overflow +} diff --git a/tests/ui/lint/lint-type-overflow3.stderr b/tests/ui/lint/lint-type-overflow3.stderr new file mode 100644 index 0000000000000..3dc7fbec1eebf --- /dev/null +++ b/tests/ui/lint/lint-type-overflow3.stderr @@ -0,0 +1,118 @@ +warning: use of a double negation + --> $DIR/lint-type-overflow3.rs:11:17 + | +LL | let x: i8 = --128; + | ^^^^^ + | + = note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages + = note: use `-= 1` if you meant to decrement the value + = note: `#[warn(double_negations)]` on by default +help: add parentheses for clarity + | +LL | let x: i8 = -(-128); + | + + + +warning: use of a double negation + --> $DIR/lint-type-overflow3.rs:13:18 + | +LL | let x: i8 = ---128; + | ^^^^^ + | + = note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages + = note: use `-= 1` if you meant to decrement the value +help: add parentheses for clarity + | +LL | let x: i8 = --(-128); + | + + + +warning: use of a double negation + --> $DIR/lint-type-overflow3.rs:15:19 + | +LL | let x: i8 = ----128; + | ^^^^^ + | + = note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages + = note: use `-= 1` if you meant to decrement the value +help: add parentheses for clarity + | +LL | let x: i8 = ---(-128); + | + + + +warning: use of a double negation + --> $DIR/lint-type-overflow3.rs:17:20 + | +LL | let x: i8 = -----128; + | ^^^^^ + | + = note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages + = note: use `-= 1` if you meant to decrement the value +help: add parentheses for clarity + | +LL | let x: i8 = ----(-128); + | + + + +warning: use of a double negation + --> $DIR/lint-type-overflow3.rs:19:21 + | +LL | let x: i8 = ------128; + | ^^^^^ + | + = note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages + = note: use `-= 1` if you meant to decrement the value +help: add parentheses for clarity + | +LL | let x: i8 = -----(-128); + | + + + +error: this arithmetic operation will overflow + --> $DIR/lint-type-overflow3.rs:11:17 + | +LL | let x: i8 = --128; + | ^^^^^ attempt to negate `i8::MIN`, which would overflow + | +note: the lint level is defined here + --> $DIR/lint-type-overflow3.rs:5:31 + | +LL | #![deny(overflowing_literals, arithmetic_overflow)] + | ^^^^^^^^^^^^^^^^^^^ + +error: this arithmetic operation will overflow + --> $DIR/lint-type-overflow3.rs:13:18 + | +LL | let x: i8 = ---128; + | ^^^^^ attempt to negate `i8::MIN`, which would overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-type-overflow3.rs:15:19 + | +LL | let x: i8 = ----128; + | ^^^^^ attempt to negate `i8::MIN`, which would overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-type-overflow3.rs:17:20 + | +LL | let x: i8 = -----128; + | ^^^^^ attempt to negate `i8::MIN`, which would overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-type-overflow3.rs:19:21 + | +LL | let x: i8 = ------128; + | ^^^^^ attempt to negate `i8::MIN`, which would overflow + +error: literal out of range for `i8` + --> $DIR/lint-type-overflow3.rs:8:17 + | +LL | let x: i8 = 128; + | ^^^ + | + = note: the literal `128` does not fit into the type `i8` whose range is `-128..=127` + = help: consider using the type `u8` instead +note: the lint level is defined here + --> $DIR/lint-type-overflow3.rs:5:9 + | +LL | #![deny(overflowing_literals, arithmetic_overflow)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 6 previous errors; 5 warnings emitted + diff --git a/tests/ui/lint/semicolon-in-expressions-from-macros/foreign-crate.rs b/tests/ui/lint/semicolon-in-expressions-from-macros/foreign-crate.rs index 6dd9d3d4dee2a..a0fc12470def0 100644 --- a/tests/ui/lint/semicolon-in-expressions-from-macros/foreign-crate.rs +++ b/tests/ui/lint/semicolon-in-expressions-from-macros/foreign-crate.rs @@ -1,9 +1,10 @@ //@ aux-build:foreign-crate.rs -//@ check-pass extern crate foreign_crate; -// Test that we do not lint for a macro in a foreign crate +// Test that we fail with a macro in a foreign crate fn main() { let _ = foreign_crate::my_macro!(); + //~^ ERROR trailing semicolon in macro used in expression position + //~| WARN this was previously accepted } diff --git a/tests/ui/lint/semicolon-in-expressions-from-macros/foreign-crate.stderr b/tests/ui/lint/semicolon-in-expressions-from-macros/foreign-crate.stderr new file mode 100644 index 0000000000000..c68de5e4b6d5c --- /dev/null +++ b/tests/ui/lint/semicolon-in-expressions-from-macros/foreign-crate.stderr @@ -0,0 +1,25 @@ +error: trailing semicolon in macro used in expression position + --> $DIR/foreign-crate.rs:7:13 + | +LL | let _ = foreign_crate::my_macro!(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #79813 + = note: `#[deny(semicolon_in_expressions_from_macros)]` (part of `#[deny(future_incompatible)]`) on by default + = note: this error originates in the macro `foreign_crate::my_macro` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 1 previous error + +Future incompatibility report: Future breakage diagnostic: +error: trailing semicolon in macro used in expression position + --> $DIR/foreign-crate.rs:7:13 + | +LL | let _ = foreign_crate::my_macro!(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #79813 + = note: `#[deny(semicolon_in_expressions_from_macros)]` (part of `#[deny(future_incompatible)]`) on by default + = note: this error originates in the macro `foreign_crate::my_macro` (in Nightly builds, run with -Z macro-backtrace for more info) + diff --git a/tests/ui/macros/auxiliary/semicolon-in-exprs.rs b/tests/ui/macros/auxiliary/semicolon-in-exprs.rs deleted file mode 100644 index 87a1c1786c1e4..0000000000000 --- a/tests/ui/macros/auxiliary/semicolon-in-exprs.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[macro_export] -macro_rules! outer { - ($inner:ident) => { $inner![1, 2, 3]; }; -} diff --git a/tests/ui/macros/semicolon-in-exprs.rs b/tests/ui/macros/semicolon-in-exprs.rs deleted file mode 100644 index 1d6c9d895f067..0000000000000 --- a/tests/ui/macros/semicolon-in-exprs.rs +++ /dev/null @@ -1,15 +0,0 @@ -//! Regression test for https://github.com/rust-lang/rust/issues/156084. -//! This test can probably be removed again once -//! `semicolon_in_expressions_from_macros` is a hard error. -//@ check-pass -//@ aux-build:semicolon-in-exprs.rs -//@ edition: 2021 - -extern crate semicolon_in_exprs; - -macro_rules! inner { - [$($x:expr),*] => { [$($x),*] }; -} -fn main() { - let _v: Vec = semicolon_in_exprs::outer!(inner).into_iter().collect(); -} diff --git a/tests/ui/thir-print/thir-tree-field-expr-index.stdout b/tests/ui/thir-print/thir-tree-field-expr-index.stdout index 5bf97a1852904..f1ab57a4545eb 100644 --- a/tests/ui/thir-print/thir-tree-field-expr-index.stdout +++ b/tests/ui/thir-print/thir-tree-field-expr-index.stdout @@ -85,7 +85,7 @@ body: adt_def: AdtDef { did: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S) - variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }], tainted: None, flags: }] + variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }], tainted: None, flags: }] flags: IS_STRUCT repr: ReprOptions { int: None, align: None, pack: None, flags: , scalable: None, field_shuffle_seed: 7076349371981215213 } } @@ -230,7 +230,7 @@ body: adt_def: AdtDef { did: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S) - variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }], tainted: None, flags: }] + variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }], tainted: None, flags: }] flags: IS_STRUCT repr: ReprOptions { int: None, align: None, pack: None, flags: , scalable: None, field_shuffle_seed: 7076349371981215213 } } @@ -317,7 +317,7 @@ body: adt_def: AdtDef { did: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S) - variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }], tainted: None, flags: }] + variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }], tainted: None, flags: }] flags: IS_STRUCT repr: ReprOptions { int: None, align: None, pack: None, flags: , scalable: None, field_shuffle_seed: 7076349371981215213 } } @@ -404,7 +404,7 @@ body: adt_def: AdtDef { did: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S) - variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }], tainted: None, flags: }] + variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }], tainted: None, flags: }] flags: IS_STRUCT repr: ReprOptions { int: None, align: None, pack: None, flags: , scalable: None, field_shuffle_seed: 7076349371981215213 } } @@ -491,7 +491,7 @@ body: adt_def: AdtDef { did: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S) - variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }], tainted: None, flags: }] + variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }], tainted: None, flags: }] flags: IS_STRUCT repr: ReprOptions { int: None, align: None, pack: None, flags: , scalable: None, field_shuffle_seed: 7076349371981215213 } } @@ -578,7 +578,7 @@ body: adt_def: AdtDef { did: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S) - variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }], tainted: None, flags: }] + variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }], tainted: None, flags: }] flags: IS_STRUCT repr: ReprOptions { int: None, align: None, pack: None, flags: , scalable: None, field_shuffle_seed: 7076349371981215213 } } @@ -665,7 +665,7 @@ body: adt_def: AdtDef { did: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S) - variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }], tainted: None, flags: }] + variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }], tainted: None, flags: }] flags: IS_STRUCT repr: ReprOptions { int: None, align: None, pack: None, flags: , scalable: None, field_shuffle_seed: 7076349371981215213 } } @@ -773,7 +773,7 @@ body: adt_def: AdtDef { did: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S) - variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(DefId(0:0 ~ thir_tree_field_expr_index[5059])), safety: Safe, value: None }], tainted: None, flags: }] + variants: [VariantDef { def_id: DefId(0:3 ~ thir_tree_field_expr_index[5059]::S), ctor: None, name: "S", discr: Relative(0), fields: [FieldDef { did: DefId(0:4 ~ thir_tree_field_expr_index[5059]::S::a), name: "a", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:5 ~ thir_tree_field_expr_index[5059]::S::b), name: "b", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:6 ~ thir_tree_field_expr_index[5059]::S::c), name: "c", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:7 ~ thir_tree_field_expr_index[5059]::S::d), name: "d", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }, FieldDef { did: DefId(0:8 ~ thir_tree_field_expr_index[5059]::S::e), name: "e", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_field_expr_index[5059]))), safety: Safe, value: None }], tainted: None, flags: }] flags: IS_STRUCT repr: ReprOptions { int: None, align: None, pack: None, flags: , scalable: None, field_shuffle_seed: 7076349371981215213 } } diff --git a/tests/ui/thir-print/thir-tree-match.stdout b/tests/ui/thir-print/thir-tree-match.stdout index 33baafeb48b26..3ef5c3dfce6e5 100644 --- a/tests/ui/thir-print/thir-tree-match.stdout +++ b/tests/ui/thir-print/thir-tree-match.stdout @@ -93,7 +93,7 @@ body: adt_def: AdtDef { did: DefId(0:10 ~ thir_tree_match[fcf8]::Foo) - variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(DefId(0:0 ~ thir_tree_match[fcf8])), safety: Safe, value: None }], tainted: None, flags: }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], tainted: None, flags: }] + variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_match[fcf8]))), safety: Safe, value: None }], tainted: None, flags: }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], tainted: None, flags: }] flags: IS_ENUM repr: ReprOptions { int: None, align: None, pack: None, flags: , scalable: None, field_shuffle_seed: 13397682652773712997 } } @@ -157,7 +157,7 @@ body: adt_def: AdtDef { did: DefId(0:10 ~ thir_tree_match[fcf8]::Foo) - variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(DefId(0:0 ~ thir_tree_match[fcf8])), safety: Safe, value: None }], tainted: None, flags: }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], tainted: None, flags: }] + variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_match[fcf8]))), safety: Safe, value: None }], tainted: None, flags: }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], tainted: None, flags: }] flags: IS_ENUM repr: ReprOptions { int: None, align: None, pack: None, flags: , scalable: None, field_shuffle_seed: 13397682652773712997 } } @@ -210,7 +210,7 @@ body: adt_def: AdtDef { did: DefId(0:10 ~ thir_tree_match[fcf8]::Foo) - variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(DefId(0:0 ~ thir_tree_match[fcf8])), safety: Safe, value: None }], tainted: None, flags: }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], tainted: None, flags: }] + variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(ModId(DefId(0:0 ~ thir_tree_match[fcf8]))), safety: Safe, value: None }], tainted: None, flags: }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], tainted: None, flags: }] flags: IS_ENUM repr: ReprOptions { int: None, align: None, pack: None, flags: , scalable: None, field_shuffle_seed: 13397682652773712997 } } diff --git a/tests/ui/type-alias-impl-trait/tait-normalize.rs b/tests/ui/type-alias-impl-trait/tait-normalize.rs index a34d167bcc391..f90520d3c5cd1 100644 --- a/tests/ui/type-alias-impl-trait/tait-normalize.rs +++ b/tests/ui/type-alias-impl-trait/tait-normalize.rs @@ -2,6 +2,9 @@ //@ [next] compile-flags: -Znext-solver //@ check-pass +// this fails in edition 2021; see tests/crashes/119786-1.rs +//@ edition: 2015..2018 + #![feature(type_alias_impl_trait)] fn enum_upvar() { diff --git a/tests/ui/use/use-self-at-end.e2015.stderr b/tests/ui/use/use-self-at-end.e2015.stderr index a0f834bda1052..d77045b45941b 100644 --- a/tests/ui/use/use-self-at-end.e2015.stderr +++ b/tests/ui/use/use-self-at-end.e2015.stderr @@ -1,5 +1,5 @@ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:14:24 + --> $DIR/use-self-at-end.rs:15:24 | LL | pub use crate::self; | ^^^^ @@ -10,7 +10,7 @@ LL | pub use crate::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:16:25 + --> $DIR/use-self-at-end.rs:17:25 | LL | pub use crate::{self}; | ^^^^ @@ -21,7 +21,7 @@ LL | pub use crate::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:20:17 + --> $DIR/use-self-at-end.rs:21:17 | LL | pub use self; | ^^^^ @@ -32,7 +32,7 @@ LL | pub use self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:22:18 + --> $DIR/use-self-at-end.rs:23:18 | LL | pub use {self}; | ^^^^ @@ -43,7 +43,7 @@ LL | pub use {self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:26:23 + --> $DIR/use-self-at-end.rs:27:23 | LL | pub use self::self; | ^^^^ @@ -54,7 +54,7 @@ LL | pub use self::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:29:24 + --> $DIR/use-self-at-end.rs:30:24 | LL | pub use self::{self}; | ^^^^ @@ -65,7 +65,7 @@ LL | pub use self::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:33:24 + --> $DIR/use-self-at-end.rs:34:24 | LL | pub use super::self; | ^^^^ @@ -76,7 +76,7 @@ LL | pub use super::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:36:25 + --> $DIR/use-self-at-end.rs:37:25 | LL | pub use super::{self}; | ^^^^ @@ -87,7 +87,7 @@ LL | pub use super::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:48:19 + --> $DIR/use-self-at-end.rs:50:19 | LL | pub use ::self; | ^^^^ @@ -98,7 +98,7 @@ LL | pub use ::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:52:20 + --> $DIR/use-self-at-end.rs:56:20 | LL | pub use ::{self}; | ^^^^ @@ -109,31 +109,31 @@ LL | pub use ::{self as name}; | +++++++ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:57:20 + --> $DIR/use-self-at-end.rs:63:20 | LL | pub use z::self::self; | ^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:58:20 + --> $DIR/use-self-at-end.rs:64:20 | LL | pub use z::self::self as z1; | ^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:59:21 + --> $DIR/use-self-at-end.rs:65:21 | LL | pub use z::{self::{self}}; | ^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:60:21 + --> $DIR/use-self-at-end.rs:66:21 | LL | pub use z::{self::{self as z2}}; | ^^^^ error[E0252]: the name `x` is defined multiple times - --> $DIR/use-self-at-end.rs:42:28 + --> $DIR/use-self-at-end.rs:43:28 | LL | pub use crate::x::self; | -------------- previous import of the module `x` here @@ -147,7 +147,7 @@ LL | pub use crate::x::{self}; = note: `x` must be defined only once in the type namespace of this module error[E0252]: the name `Enum` is defined multiple times - --> $DIR/use-self-at-end.rs:71:31 + --> $DIR/use-self-at-end.rs:77:31 | LL | pub use super::Enum::self; | ----------------- previous import of the type `Enum` here @@ -161,7 +161,7 @@ LL | pub use super::Enum::{self}; = note: `Enum` must be defined only once in the type namespace of this module error[E0252]: the name `Trait` is defined multiple times - --> $DIR/use-self-at-end.rs:79:32 + --> $DIR/use-self-at-end.rs:88:32 | LL | pub use super::Trait::self; | ------------------ previous import of the trait `Trait` here @@ -175,103 +175,103 @@ LL | pub use super::Trait::{self}; = note: `Trait` must be defined only once in the type namespace of this module error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:63:24 + --> $DIR/use-self-at-end.rs:69:24 | LL | pub use super::Struct::self; | ^^^^^^ `Struct` is a struct, not a module error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:64:24 + --> $DIR/use-self-at-end.rs:70:24 | LL | pub use super::Struct::self as Struct1; | ^^^^^^ `Struct` is a struct, not a module error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:65:24 + --> $DIR/use-self-at-end.rs:71:24 | LL | pub use super::Struct::{self}; | ^^^^^^ `Struct` is a struct, not a module error[E0433]: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:83:24 + --> $DIR/use-self-at-end.rs:92:24 | LL | pub use super::self::y::z; | ^^^^ can only be used in path start position or last position error[E0433]: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:84:24 + --> $DIR/use-self-at-end.rs:93:24 | LL | pub use super::self::y::z as z3; | ^^^^ can only be used in path start position or last position error[E0433]: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:85:24 + --> $DIR/use-self-at-end.rs:94:24 | LL | pub use super::self::y::{z}; | ^^^^ can only be used in path start position or last position error[E0433]: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:86:24 + --> $DIR/use-self-at-end.rs:95:24 | LL | pub use super::self::y::{z as z4}; | ^^^^ can only be used in path start position or last position error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:66:24 + --> $DIR/use-self-at-end.rs:72:24 | LL | pub use super::Struct::{self as Struct2}; | ^^^^^^ `Struct` is a struct, not a module error[E0433]: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:56:21 + --> $DIR/use-self-at-end.rs:62:21 | LL | type G = z::self::self; | ^^^^ can only be used in path start position or last position error[E0433]: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:82:25 + --> $DIR/use-self-at-end.rs:91:25 | LL | type K = super::self::y::z; | ^^^^ can only be used in path start position or last position error[E0573]: expected type, found module `crate::self` - --> $DIR/use-self-at-end.rs:13:18 + --> $DIR/use-self-at-end.rs:14:18 | LL | type A = crate::self; | ^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self` - --> $DIR/use-self-at-end.rs:19:18 + --> $DIR/use-self-at-end.rs:20:18 | LL | type B = self; | ^^^^ not a type error[E0573]: expected type, found module `self::self` - --> $DIR/use-self-at-end.rs:25:18 + --> $DIR/use-self-at-end.rs:26:18 | LL | type C = self::self; | ^^^^^^^^^^ not a type error[E0573]: expected type, found module `super::self` - --> $DIR/use-self-at-end.rs:32:18 + --> $DIR/use-self-at-end.rs:33:18 | LL | type D = super::self; | ^^^^^^^^^^^ not a type error[E0573]: expected type, found module `crate::x::self` - --> $DIR/use-self-at-end.rs:39:18 + --> $DIR/use-self-at-end.rs:40:18 | LL | type E = crate::x::self; | ^^^^^^^^^^^^^^ not a type error[E0573]: expected type, found module `::self` - --> $DIR/use-self-at-end.rs:45:18 + --> $DIR/use-self-at-end.rs:46:18 | LL | type F = ::self; | ^^^^^^ not a type error[E0223]: ambiguous associated type - --> $DIR/use-self-at-end.rs:62:18 + --> $DIR/use-self-at-end.rs:68:18 | LL | type H = super::Struct::self; | ^^^^^^^^^^^^^^^^^^^ @@ -283,7 +283,7 @@ LL + type H = ::self; | warning: trait objects without an explicit `dyn` are deprecated - --> $DIR/use-self-at-end.rs:74:18 + --> $DIR/use-self-at-end.rs:80:18 | LL | type J = super::Trait::self; | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/use/use-self-at-end.e2018.stderr b/tests/ui/use/use-self-at-end.e2018.stderr index 6d82c061d9247..65cba69dd4cdc 100644 --- a/tests/ui/use/use-self-at-end.e2018.stderr +++ b/tests/ui/use/use-self-at-end.e2018.stderr @@ -1,5 +1,5 @@ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:14:24 + --> $DIR/use-self-at-end.rs:15:24 | LL | pub use crate::self; | ^^^^ @@ -10,7 +10,7 @@ LL | pub use crate::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:16:25 + --> $DIR/use-self-at-end.rs:17:25 | LL | pub use crate::{self}; | ^^^^ @@ -21,7 +21,7 @@ LL | pub use crate::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:20:17 + --> $DIR/use-self-at-end.rs:21:17 | LL | pub use self; | ^^^^ @@ -32,7 +32,7 @@ LL | pub use self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:22:18 + --> $DIR/use-self-at-end.rs:23:18 | LL | pub use {self}; | ^^^^ @@ -43,7 +43,7 @@ LL | pub use {self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:26:23 + --> $DIR/use-self-at-end.rs:27:23 | LL | pub use self::self; | ^^^^ @@ -54,7 +54,7 @@ LL | pub use self::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:29:24 + --> $DIR/use-self-at-end.rs:30:24 | LL | pub use self::{self}; | ^^^^ @@ -65,7 +65,7 @@ LL | pub use self::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:33:24 + --> $DIR/use-self-at-end.rs:34:24 | LL | pub use super::self; | ^^^^ @@ -76,7 +76,7 @@ LL | pub use super::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:36:25 + --> $DIR/use-self-at-end.rs:37:25 | LL | pub use super::{self}; | ^^^^ @@ -87,55 +87,55 @@ LL | pub use super::{self as name}; | +++++++ error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:48:17 + --> $DIR/use-self-at-end.rs:50:17 | LL | pub use ::self; | ^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:51:17 + --> $DIR/use-self-at-end.rs:54:17 | LL | pub use ::self as crate4; | ^^^^^^^^^^^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:52:20 + --> $DIR/use-self-at-end.rs:56:20 | LL | pub use ::{self}; | ^^^^ error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:54:20 + --> $DIR/use-self-at-end.rs:59:20 | LL | pub use ::{self as crate5}; | ^^^^^^^^^^^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:57:20 + --> $DIR/use-self-at-end.rs:63:20 | LL | pub use z::self::self; | ^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:58:20 + --> $DIR/use-self-at-end.rs:64:20 | LL | pub use z::self::self as z1; | ^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:59:21 + --> $DIR/use-self-at-end.rs:65:21 | LL | pub use z::{self::{self}}; | ^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:60:21 + --> $DIR/use-self-at-end.rs:66:21 | LL | pub use z::{self::{self as z2}}; | ^^^^ error[E0252]: the name `x` is defined multiple times - --> $DIR/use-self-at-end.rs:42:28 + --> $DIR/use-self-at-end.rs:43:28 | LL | pub use crate::x::self; | -------------- previous import of the module `x` here @@ -149,7 +149,7 @@ LL | pub use crate::x::{self}; = note: `x` must be defined only once in the type namespace of this module error[E0252]: the name `Enum` is defined multiple times - --> $DIR/use-self-at-end.rs:71:31 + --> $DIR/use-self-at-end.rs:77:31 | LL | pub use super::Enum::self; | ----------------- previous import of the type `Enum` here @@ -163,7 +163,7 @@ LL | pub use super::Enum::{self}; = note: `Enum` must be defined only once in the type namespace of this module error[E0252]: the name `Trait` is defined multiple times - --> $DIR/use-self-at-end.rs:79:32 + --> $DIR/use-self-at-end.rs:88:32 | LL | pub use super::Trait::self; | ------------------ previous import of the trait `Trait` here @@ -177,103 +177,103 @@ LL | pub use super::Trait::{self}; = note: `Trait` must be defined only once in the type namespace of this module error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:63:24 + --> $DIR/use-self-at-end.rs:69:24 | LL | pub use super::Struct::self; | ^^^^^^ `Struct` is a struct, not a module error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:64:24 + --> $DIR/use-self-at-end.rs:70:24 | LL | pub use super::Struct::self as Struct1; | ^^^^^^ `Struct` is a struct, not a module error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:65:24 + --> $DIR/use-self-at-end.rs:71:24 | LL | pub use super::Struct::{self}; | ^^^^^^ `Struct` is a struct, not a module error[E0433]: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:83:24 + --> $DIR/use-self-at-end.rs:92:24 | LL | pub use super::self::y::z; | ^^^^ can only be used in path start position or last position error[E0433]: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:84:24 + --> $DIR/use-self-at-end.rs:93:24 | LL | pub use super::self::y::z as z3; | ^^^^ can only be used in path start position or last position error[E0433]: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:85:24 + --> $DIR/use-self-at-end.rs:94:24 | LL | pub use super::self::y::{z}; | ^^^^ can only be used in path start position or last position error[E0433]: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:86:24 + --> $DIR/use-self-at-end.rs:95:24 | LL | pub use super::self::y::{z as z4}; | ^^^^ can only be used in path start position or last position error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:66:24 + --> $DIR/use-self-at-end.rs:72:24 | LL | pub use super::Struct::{self as Struct2}; | ^^^^^^ `Struct` is a struct, not a module error[E0433]: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:56:21 + --> $DIR/use-self-at-end.rs:62:21 | LL | type G = z::self::self; | ^^^^ can only be used in path start position or last position error[E0433]: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:82:25 + --> $DIR/use-self-at-end.rs:91:25 | LL | type K = super::self::y::z; | ^^^^ can only be used in path start position or last position error[E0573]: expected type, found module `crate::self` - --> $DIR/use-self-at-end.rs:13:18 + --> $DIR/use-self-at-end.rs:14:18 | LL | type A = crate::self; | ^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self` - --> $DIR/use-self-at-end.rs:19:18 + --> $DIR/use-self-at-end.rs:20:18 | LL | type B = self; | ^^^^ not a type error[E0573]: expected type, found module `self::self` - --> $DIR/use-self-at-end.rs:25:18 + --> $DIR/use-self-at-end.rs:26:18 | LL | type C = self::self; | ^^^^^^^^^^ not a type error[E0573]: expected type, found module `super::self` - --> $DIR/use-self-at-end.rs:32:18 + --> $DIR/use-self-at-end.rs:33:18 | LL | type D = super::self; | ^^^^^^^^^^^ not a type error[E0573]: expected type, found module `crate::x::self` - --> $DIR/use-self-at-end.rs:39:18 + --> $DIR/use-self-at-end.rs:40:18 | LL | type E = crate::x::self; | ^^^^^^^^^^^^^^ not a type error[E0425]: cannot find crate `self` in the list of imported crates - --> $DIR/use-self-at-end.rs:45:20 + --> $DIR/use-self-at-end.rs:46:20 | LL | type F = ::self; | ^^^^ not found in the list of imported crates error[E0223]: ambiguous associated type - --> $DIR/use-self-at-end.rs:62:18 + --> $DIR/use-self-at-end.rs:68:18 | LL | type H = super::Struct::self; | ^^^^^^^^^^^^^^^^^^^ @@ -285,7 +285,7 @@ LL + type H = ::self; | warning: trait objects without an explicit `dyn` are deprecated - --> $DIR/use-self-at-end.rs:74:18 + --> $DIR/use-self-at-end.rs:80:18 | LL | type J = super::Trait::self; | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/use/use-self-at-end.e2021.stderr b/tests/ui/use/use-self-at-end.e2021.stderr new file mode 100644 index 0000000000000..9809179144b7c --- /dev/null +++ b/tests/ui/use/use-self-at-end.e2021.stderr @@ -0,0 +1,301 @@ +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:15:24 + | +LL | pub use crate::self; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use crate::self as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:17:25 + | +LL | pub use crate::{self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use crate::{self as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:21:17 + | +LL | pub use self; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use self as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:23:18 + | +LL | pub use {self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use {self as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:27:23 + | +LL | pub use self::self; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use self::self as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:30:24 + | +LL | pub use self::{self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use self::{self as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:34:24 + | +LL | pub use super::self; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use super::self as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:37:25 + | +LL | pub use super::{self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use super::{self as name}; + | +++++++ + +error: extern prelude cannot be imported + --> $DIR/use-self-at-end.rs:50:17 + | +LL | pub use ::self; + | ^^^^^^ + +error: extern prelude cannot be imported + --> $DIR/use-self-at-end.rs:54:17 + | +LL | pub use ::self as crate4; + | ^^^^^^^^^^^^^^^^ + +error: extern prelude cannot be imported + --> $DIR/use-self-at-end.rs:56:20 + | +LL | pub use ::{self}; + | ^^^^ + +error: extern prelude cannot be imported + --> $DIR/use-self-at-end.rs:59:20 + | +LL | pub use ::{self as crate5}; + | ^^^^^^^^^^^^^^ + +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:63:20 + | +LL | pub use z::self::self; + | ^^^^ + +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:64:20 + | +LL | pub use z::self::self as z1; + | ^^^^ + +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:65:21 + | +LL | pub use z::{self::{self}}; + | ^^^^ + +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:66:21 + | +LL | pub use z::{self::{self as z2}}; + | ^^^^ + +error[E0252]: the name `x` is defined multiple times + --> $DIR/use-self-at-end.rs:43:28 + | +LL | pub use crate::x::self; + | -------------- previous import of the module `x` here +LL | pub use crate::x::self as x3; +LL | pub use crate::x::{self}; + | -------------------^^^^-- + | | | + | | `x` reimported here + | help: remove unnecessary import + | + = note: `x` must be defined only once in the type namespace of this module + +error[E0252]: the name `Enum` is defined multiple times + --> $DIR/use-self-at-end.rs:77:31 + | +LL | pub use super::Enum::self; + | ----------------- previous import of the type `Enum` here +LL | pub use super::Enum::self as Enum1; +LL | pub use super::Enum::{self}; + | ----------------------^^^^-- + | | | + | | `Enum` reimported here + | help: remove unnecessary import + | + = note: `Enum` must be defined only once in the type namespace of this module + +error[E0252]: the name `Trait` is defined multiple times + --> $DIR/use-self-at-end.rs:88:32 + | +LL | pub use super::Trait::self; + | ------------------ previous import of the trait `Trait` here +LL | pub use super::Trait::self as Trait1; +LL | pub use super::Trait::{self}; + | -----------------------^^^^-- + | | | + | | `Trait` reimported here + | help: remove unnecessary import + | + = note: `Trait` must be defined only once in the type namespace of this module + +error[E0432]: unresolved import `super::Struct` + --> $DIR/use-self-at-end.rs:69:24 + | +LL | pub use super::Struct::self; + | ^^^^^^ `Struct` is a struct, not a module + +error[E0432]: unresolved import `super::Struct` + --> $DIR/use-self-at-end.rs:70:24 + | +LL | pub use super::Struct::self as Struct1; + | ^^^^^^ `Struct` is a struct, not a module + +error[E0432]: unresolved import `super::Struct` + --> $DIR/use-self-at-end.rs:71:24 + | +LL | pub use super::Struct::{self}; + | ^^^^^^ `Struct` is a struct, not a module + +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:92:24 + | +LL | pub use super::self::y::z; + | ^^^^ can only be used in path start position or last position + +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:93:24 + | +LL | pub use super::self::y::z as z3; + | ^^^^ can only be used in path start position or last position + +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:94:24 + | +LL | pub use super::self::y::{z}; + | ^^^^ can only be used in path start position or last position + +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:95:24 + | +LL | pub use super::self::y::{z as z4}; + | ^^^^ can only be used in path start position or last position + +error[E0432]: unresolved import `super::Struct` + --> $DIR/use-self-at-end.rs:72:24 + | +LL | pub use super::Struct::{self as Struct2}; + | ^^^^^^ `Struct` is a struct, not a module + +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:62:21 + | +LL | type G = z::self::self; + | ^^^^ can only be used in path start position or last position + +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:91:25 + | +LL | type K = super::self::y::z; + | ^^^^ can only be used in path start position or last position + +error[E0573]: expected type, found module `crate::self` + --> $DIR/use-self-at-end.rs:14:18 + | +LL | type A = crate::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `self` + --> $DIR/use-self-at-end.rs:20:18 + | +LL | type B = self; + | ^^^^ not a type + +error[E0573]: expected type, found module `self::self` + --> $DIR/use-self-at-end.rs:26:18 + | +LL | type C = self::self; + | ^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-self-at-end.rs:33:18 + | +LL | type D = super::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::x::self` + --> $DIR/use-self-at-end.rs:40:18 + | +LL | type E = crate::x::self; + | ^^^^^^^^^^^^^^ not a type + +error[E0425]: cannot find crate `self` in the list of imported crates + --> $DIR/use-self-at-end.rs:46:20 + | +LL | type F = ::self; + | ^^^^ not found in the list of imported crates + +error[E0223]: ambiguous associated type + --> $DIR/use-self-at-end.rs:68:18 + | +LL | type H = super::Struct::self; + | ^^^^^^^^^^^^^^^^^^^ + | +help: if there were a trait named `Example` with associated type `self` implemented for `x::Struct`, you could use the fully-qualified path + | +LL - type H = super::Struct::self; +LL + type H = ::self; + | + +error[E0782]: expected a type, found a trait + --> $DIR/use-self-at-end.rs:80:18 + | +LL | type J = super::Trait::self; + | ^^^^^^^^^^^^^^^^^^ + | +help: you can add the `dyn` keyword if you want a trait object + | +LL | type J = dyn super::Trait::self; + | +++ + +error: aborting due to 37 previous errors + +Some errors have detailed explanations: E0223, E0252, E0425, E0432, E0433, E0573, E0782. +For more information about an error, try `rustc --explain E0223`. diff --git a/tests/ui/use/use-self-at-end.rs b/tests/ui/use/use-self-at-end.rs index 64b17483445a3..29097bc3dffb8 100644 --- a/tests/ui/use/use-self-at-end.rs +++ b/tests/ui/use/use-self-at-end.rs @@ -1,6 +1,7 @@ -//@ revisions: e2015 e2018 +//@ revisions: e2015 e2018 e2021 //@ [e2015] edition: 2015 -//@ [e2018] edition: 2018.. +//@ [e2018] edition: 2018 +//@ [e2021] edition: 2021.. pub mod x { pub struct Struct; @@ -45,13 +46,18 @@ pub mod x { type F = ::self; //[e2015]~^ ERROR expected type, found module `::self` //[e2018]~^^ ERROR cannot find crate `self` in the list of imported crates + //[e2021]~^^^ ERROR cannot find crate `self` in the list of imported crates pub use ::self; //[e2015]~^ ERROR imports need to be explicitly named //[e2018]~^^ ERROR extern prelude cannot be imported + //[e2021]~^^^ ERROR extern prelude cannot be imported pub use ::self as crate4; //[e2018]~ ERROR extern prelude cannot be imported + //[e2021]~^ ERROR extern prelude cannot be imported pub use ::{self}; //[e2018]~ ERROR extern prelude cannot be imported //[e2015]~^ ERROR imports need to be explicitly named + //[e2021]~^^ ERROR extern prelude cannot be imported pub use ::{self as crate5}; //[e2018]~ ERROR extern prelude cannot be imported + //[e2021]~^ ERROR extern prelude cannot be imported type G = z::self::self; //~ ERROR `self` in paths can only be used in start position pub use z::self::self; //~ ERROR `self` in paths can only be used in start position or last position @@ -72,8 +78,11 @@ pub mod x { pub use super::Enum::{self as Enum2}; type J = super::Trait::self; - //~^ WARN trait objects without an explicit `dyn` are deprecated - //~^^ WARN this is accepted in the current edition + //[e2015]~^ WARN trait objects without an explicit `dyn` are deprecated + //[e2015]~^^ WARN this is accepted in the current edition + //[e2018]~^^^ WARN trait objects without an explicit `dyn` are deprecated + //[e2018]~^^^^ WARN this is accepted in the current edition + //[e2021]~^^^^^ ERROR expected a type, found a trait pub use super::Trait::self; pub use super::Trait::self as Trait1; pub use super::Trait::{self}; //~ ERROR the name `Trait` is defined multiple times