diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index cca1d499088f4..4fcf352173500 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -1,6 +1,6 @@ use std::collections::BTreeSet; use std::fmt::{self, Write}; -use std::ops::{Bound, Deref}; +use std::ops::Deref; use std::{cmp, iter}; use rustc_hashes::Hash64; @@ -348,7 +348,6 @@ impl LayoutCalculator { variants: &IndexSlice>, is_enum: bool, is_special_no_niche: bool, - scalar_valid_range: (Bound, Bound), discr_range_of_repr: impl Fn(i128, i128) -> (Integer, bool), discriminants: impl Iterator, always_sized: bool, @@ -380,7 +379,6 @@ impl LayoutCalculator { variants, is_enum, is_special_no_niche, - scalar_valid_range, always_sized, present_first, ) @@ -530,7 +528,6 @@ impl LayoutCalculator { variants: &IndexSlice>, is_enum: bool, is_special_no_niche: bool, - scalar_valid_range: (Bound, Bound), always_sized: bool, present_first: VariantIdx, ) -> LayoutCalculatorResult { @@ -570,52 +567,6 @@ impl LayoutCalculator { return Ok(st); } - let (start, end) = scalar_valid_range; - match st.backend_repr { - BackendRepr::Scalar(ref mut scalar) | BackendRepr::ScalarPair(ref mut scalar, _) => { - // Enlarging validity ranges would result in missed - // optimizations, *not* wrongly assuming the inner - // value is valid. e.g. unions already enlarge validity ranges, - // because the values may be uninitialized. - // - // Because of that we only check that the start and end - // of the range is representable with this scalar type. - - let max_value = scalar.size(dl).unsigned_int_max(); - if let Bound::Included(start) = start { - // FIXME(eddyb) this might be incorrect - it doesn't - // account for wrap-around (end < start) ranges. - assert!(start <= max_value, "{start} > {max_value}"); - scalar.valid_range_mut().start = start; - } - if let Bound::Included(end) = end { - // FIXME(eddyb) this might be incorrect - it doesn't - // account for wrap-around (end < start) ranges. - assert!(end <= max_value, "{end} > {max_value}"); - scalar.valid_range_mut().end = end; - } - - // Update `largest_niche` if we have introduced a larger niche. - let niche = Niche::from_scalar(dl, Size::ZERO, *scalar); - if let Some(niche) = niche { - match st.largest_niche { - Some(largest_niche) => { - // Replace the existing niche even if they're equal, - // because this one is at a lower offset. - if largest_niche.available(dl) <= niche.available(dl) { - st.largest_niche = Some(niche); - } - } - None => st.largest_niche = Some(niche), - } - } - } - _ => assert!( - start == Bound::Unbounded && end == Bound::Unbounded, - "nonscalar layout for layout_scalar_valid_range type: {st:#?}", - ), - } - Ok(st) } diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 19dfa5d21d022..3e0bc072a8d04 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -569,16 +569,16 @@ impl<'hir> LoweringContext<'_, 'hir> { (safety, items, bounds) }, ); - hir::ItemKind::Trait( + hir::ItemKind::Trait { impl_restriction, constness, - *is_auto, + is_auto: *is_auto, safety, ident, generics, bounds, items, - ) + } } ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds }) => { let constness = self.lower_constness(*constness); diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 5e9674b7a0422..df2eeec74cf2d 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -41,7 +41,7 @@ use std::sync::Arc; use rustc_ast::node_id::NodeMap; use rustc_ast::visit::Visitor; use rustc_ast::{self as ast, *}; -use rustc_attr_parsing::{AttributeParser, EmitAttribute, Late, OmitDoc}; +use rustc_attr_parsing::{AttributeParser, Late, OmitDoc}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::sorted_map::SortedMap; @@ -52,7 +52,7 @@ use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle}; use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res}; use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId}; use rustc_hir::definitions::PerParentDisambiguatorState; -use rustc_hir::lints::{AttributeLint, DelayedLint, DynAttribute}; +use rustc_hir::lints::DelayedLint; use rustc_hir::{ self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LifetimeSource, LifetimeSyntax, ParamName, Target, TraitCandidate, find_attr, @@ -1096,23 +1096,18 @@ impl<'hir> LoweringContext<'_, 'hir> { target, OmitDoc::Lower, |s| l.lower(s), - |lint_id, span, kind| match kind { - EmitAttribute::Static(attr_kind) => { - self.delayed_lints.push(DelayedLint::AttributeParsing(AttributeLint { - lint_id, - id: target_hir_id, - span, - kind: attr_kind, - })); - } - EmitAttribute::Dynamic(callback) => { - self.delayed_lints.push(DelayedLint::Dynamic(DynAttribute { - lint_id, - id: target_hir_id, - span, - callback, - })); - } + |lint_id, span, kind| { + self.delayed_lints.push(DelayedLint { + lint_id, + id: target_hir_id, + span, + callback: Box::new(move |dcx, level, sess: &dyn std::any::Any| { + let sess = sess + .downcast_ref::() + .expect("expected `Session`"); + (kind.0)(dcx, level, sess) + }), + }); }, ) } diff --git a/compiler/rustc_attr_parsing/src/attributes/cfg.rs b/compiler/rustc_attr_parsing/src/attributes/cfg.rs index c2dda74e9f515..84dd2b907aec8 100644 --- a/compiler/rustc_attr_parsing/src/attributes/cfg.rs +++ b/compiler/rustc_attr_parsing/src/attributes/cfg.rs @@ -3,12 +3,11 @@ use std::convert::identity; use rustc_ast::token::Delimiter; use rustc_ast::tokenstream::DelimSpan; use rustc_ast::{AttrItem, Attribute, LitKind, ast, token}; -use rustc_errors::{Applicability, PResult, msg}; +use rustc_errors::{Applicability, Diagnostic, PResult, msg}; use rustc_feature::{ AttrSuggestionStyle, AttributeTemplate, Features, GatedCfg, find_gated_cfg, template, }; use rustc_hir::attrs::CfgEntry; -use rustc_hir::lints::AttributeLintKind; use rustc_hir::{AttrPath, RustcVersion, Target}; use rustc_parse::parser::{ForceCollect, Parser, Recovery}; use rustc_parse::{exp, parse_in}; @@ -20,6 +19,7 @@ use rustc_span::{ErrorGuaranteed, Span, Symbol, sym}; use thin_vec::ThinVec; use crate::attributes::AttributeSafety; +use crate::attributes::diagnostic::check_cfg; use crate::context::{AcceptContext, ShouldEmit, Stage}; use crate::parser::{ AllowExprMetavar, ArgParser, MetaItemListParser, MetaItemOrLitParser, NameValueParser, @@ -224,14 +224,19 @@ pub(crate) fn parse_name_value( match cx.sess.psess.check_config.expecteds.get(&name) { Some(ExpectedValues::Some(values)) if !values.contains(&value.map(|(v, _)| v)) => cx - .emit_lint( + .emit_dyn_lint_with_sess( UNEXPECTED_CFGS, - AttributeLintKind::UnexpectedCfgValue((name, name_span), value), + move |dcx, level, sess| { + check_cfg::unexpected_cfg_value(sess, (name, name_span), value) + .into_diag(dcx, level) + }, span, ), - None if cx.sess.psess.check_config.exhaustive_names => cx.emit_lint( + None if cx.sess.psess.check_config.exhaustive_names => cx.emit_dyn_lint_with_sess( UNEXPECTED_CFGS, - AttributeLintKind::UnexpectedCfgName((name, name_span), value), + move |dcx, level, sess| { + check_cfg::unexpected_cfg_name(sess, (name, name_span), value).into_diag(dcx, level) + }, span, ), _ => { /* not unexpected */ } diff --git a/compiler/rustc_lint/src/early/diagnostics/check_cfg.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/check_cfg.rs similarity index 78% rename from compiler/rustc_lint/src/early/diagnostics/check_cfg.rs rename to compiler/rustc_attr_parsing/src/attributes/diagnostic/check_cfg.rs index 9fcabfa623d80..d6347c457b2b5 100644 --- a/compiler/rustc_lint/src/early/diagnostics/check_cfg.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/check_cfg.rs @@ -1,12 +1,10 @@ -use rustc_hir::def_id::LOCAL_CRATE; -use rustc_middle::bug; -use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_session::config::ExpectedValues; +use rustc_span::def_id::LOCAL_CRATE; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::{ExpnKind, Ident, Span, Symbol, sym}; -use crate::lints; +use crate::errors; const MAX_CHECK_CFG_NAMES_OR_VALUES: usize = 35; @@ -64,57 +62,48 @@ fn to_check_cfg_arg(name: Ident, value: Option, quotes: EscapeQuotes) -> fn cargo_help_sub( sess: &Session, inst: &impl Fn(EscapeQuotes) -> String, -) -> lints::UnexpectedCfgCargoHelp { +) -> errors::UnexpectedCfgCargoHelp { // We don't want to suggest the `build.rs` way to expected cfgs if we are already in a // `build.rs`. We therefor do a best effort check (looking if the `--crate-name` is // `build_script_build`) to try to figure out if we are building a Cargo build script let unescaped = &inst(EscapeQuotes::No); if let Some("build_script_build") = sess.opts.crate_name.as_deref() { - lints::UnexpectedCfgCargoHelp::lint_cfg(unescaped) + errors::UnexpectedCfgCargoHelp::lint_cfg(unescaped) } else { - lints::UnexpectedCfgCargoHelp::lint_cfg_and_build_rs(unescaped, &inst(EscapeQuotes::Yes)) + errors::UnexpectedCfgCargoHelp::lint_cfg_and_build_rs(unescaped, &inst(EscapeQuotes::Yes)) } } -fn rustc_macro_help(span: Span) -> Option { +fn rustc_macro_help(span: Span) -> Option { let oexpn = span.ctxt().outer_expn_data(); if let Some(def_id) = oexpn.macro_def_id && let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind && def_id.krate != LOCAL_CRATE { - Some(lints::UnexpectedCfgRustcMacroHelp { macro_kind: macro_kind.descr(), macro_name }) + Some(errors::UnexpectedCfgRustcMacroHelp { macro_kind: macro_kind.descr(), macro_name }) } else { None } } -fn cargo_macro_help( - tcx: Option>, - span: Span, -) -> Option { +fn cargo_macro_help(span: Span) -> Option { let oexpn = span.ctxt().outer_expn_data(); if let Some(def_id) = oexpn.macro_def_id - && let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind && def_id.krate != LOCAL_CRATE - && let Some(tcx) = tcx + && let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind { - Some(lints::UnexpectedCfgCargoMacroHelp { - macro_kind: macro_kind.descr(), - macro_name, - crate_name: tcx.crate_name(def_id.krate), - }) + Some(errors::UnexpectedCfgCargoMacroHelp { macro_kind: macro_kind.descr(), macro_name }) } else { None } } -pub(super) fn unexpected_cfg_name( +pub(crate) fn unexpected_cfg_name( sess: &Session, - tcx: Option>, (name, name_span): (Symbol, Span), value: Option<(Symbol, Span)>, -) -> lints::UnexpectedCfgName { +) -> errors::UnexpectedCfgName { #[allow(rustc::potential_query_instability)] let possibilities: Vec = sess.psess.check_config.expecteds.keys().copied().collect(); @@ -149,12 +138,12 @@ pub(super) fn unexpected_cfg_name( } let code_sugg = if is_feature_cfg && is_from_cargo { - lints::unexpected_cfg_name::CodeSuggestion::DefineFeatures + errors::unexpected_cfg_name::CodeSuggestion::DefineFeatures // Suggest correct `version("..")` predicate syntax } else if let Some((_value, value_span)) = value && name == sym::version { - lints::unexpected_cfg_name::CodeSuggestion::VersionSyntax { + errors::unexpected_cfg_name::CodeSuggestion::VersionSyntax { between_name_and_value: name_span.between(value_span), after_value: value_span.shrink_to_hi(), } @@ -169,7 +158,7 @@ pub(super) fn unexpected_cfg_name( .span_to_snippet(name_span) .map_or(true, |snippet| !snippet.contains("r#")) { - lints::unexpected_cfg_name::CodeSuggestion::BooleanLiteral { + errors::unexpected_cfg_name::CodeSuggestion::BooleanLiteral { span: name_span, literal: boolean, } @@ -189,7 +178,7 @@ pub(super) fn unexpected_cfg_name( if !possibilities.is_empty() { let possibilities = possibilities.iter().copied().cloned().collect::>().into(); - Some(lints::unexpected_cfg_name::ExpectedValues { best_match, possibilities }) + Some(errors::unexpected_cfg_name::ExpectedValues { best_match, possibilities }) } else { None } @@ -198,37 +187,37 @@ pub(super) fn unexpected_cfg_name( let best_match = Ident::new(best_match, name_span); if let Some((value, value_span)) = value { if best_match_values.contains(&Some(value)) { - lints::unexpected_cfg_name::CodeSuggestion::SimilarNameAndValue { + errors::unexpected_cfg_name::CodeSuggestion::SimilarNameAndValue { span: name_span, code: best_match.to_string(), } } else if best_match_values.contains(&None) { - lints::unexpected_cfg_name::CodeSuggestion::SimilarNameNoValue { + errors::unexpected_cfg_name::CodeSuggestion::SimilarNameNoValue { span: name_span.to(value_span), code: best_match.to_string(), } } else if let Some(first_value) = possibilities.first() { - lints::unexpected_cfg_name::CodeSuggestion::SimilarNameDifferentValues { + errors::unexpected_cfg_name::CodeSuggestion::SimilarNameDifferentValues { span: name_span.to(value_span), code: format!("{best_match} = \"{first_value}\""), expected: get_possibilities_sub(), } } else { - lints::unexpected_cfg_name::CodeSuggestion::SimilarNameDifferentValues { + errors::unexpected_cfg_name::CodeSuggestion::SimilarNameDifferentValues { span: name_span.to(value_span), code: best_match.to_string(), expected: get_possibilities_sub(), } } } else { - lints::unexpected_cfg_name::CodeSuggestion::SimilarName { + errors::unexpected_cfg_name::CodeSuggestion::SimilarName { span: name_span, code: best_match.to_string(), expected: get_possibilities_sub(), } } } else { - lints::unexpected_cfg_name::CodeSuggestion::SimilarName { + errors::unexpected_cfg_name::CodeSuggestion::SimilarName { span: name_span, code: best_match.to_string(), expected: None, @@ -239,7 +228,7 @@ pub(super) fn unexpected_cfg_name( names_possibilities.sort(); names_possibilities .iter() - .map(|cfg_name| lints::unexpected_cfg_name::FoundWithSimilarValue { + .map(|cfg_name| errors::unexpected_cfg_name::FoundWithSimilarValue { span: name_span, code: format!("{cfg_name} = \"{name}\""), }) @@ -253,14 +242,14 @@ pub(super) fn unexpected_cfg_name( let expected_names = if !possibilities.is_empty() { let possibilities: Vec<_> = possibilities.into_iter().map(|s| Ident::new(s, name_span)).collect(); - Some(lints::unexpected_cfg_name::ExpectedNames { + Some(errors::unexpected_cfg_name::ExpectedNames { possibilities: possibilities.into(), and_more, }) } else { None }; - lints::unexpected_cfg_name::CodeSuggestion::SimilarValues { + errors::unexpected_cfg_name::CodeSuggestion::SimilarValues { with_similar_values: similar_values, expected_names, } @@ -276,29 +265,28 @@ pub(super) fn unexpected_cfg_name( } else { None }; - lints::unexpected_cfg_name::InvocationHelp::Cargo { + errors::unexpected_cfg_name::InvocationHelp::Cargo { help, - macro_help: cargo_macro_help(tcx, name_span), + macro_help: cargo_macro_help(name_span), } } else { - let help = lints::UnexpectedCfgRustcHelp::new(&inst(EscapeQuotes::No)); - lints::unexpected_cfg_name::InvocationHelp::Rustc { + let help = errors::UnexpectedCfgRustcHelp::new(&inst(EscapeQuotes::No)); + errors::unexpected_cfg_name::InvocationHelp::Rustc { help, macro_help: rustc_macro_help(name_span), } }; - lints::UnexpectedCfgName { code_sugg, invocation_help, name } + errors::UnexpectedCfgName { code_sugg, invocation_help, name } } -pub(super) fn unexpected_cfg_value( +pub(crate) fn unexpected_cfg_value( sess: &Session, - tcx: Option>, (name, name_span): (Symbol, Span), value: Option<(Symbol, Span)>, -) -> lints::UnexpectedCfgValue { +) -> errors::UnexpectedCfgValue { let Some(ExpectedValues::Some(values)) = &sess.psess.check_config.expecteds.get(&name) else { - bug!( + panic!( "it shouldn't be possible to have a diagnostic on a value whose name is not in values" ); }; @@ -327,13 +315,13 @@ pub(super) fn unexpected_cfg_value( .iter() .take(max_suggestions) .copied() - .map(|name| lints::unexpected_cfg_value::ChangeNameSuggestion { + .map(|name| errors::unexpected_cfg_value::ChangeNameSuggestion { span: name_span, name, value, }) .collect::>(); - lints::unexpected_cfg_value::CodeSuggestion::ChangeName { suggestions } + errors::unexpected_cfg_value::CodeSuggestion::ChangeName { suggestions } } else if !possibilities.is_empty() { // Show the full list if all possible values for a given name, but don't do it // for names as the possibilities could be very long @@ -343,7 +331,7 @@ pub(super) fn unexpected_cfg_value( possibilities.clone(), FilterWellKnownNames::No, ); - lints::unexpected_cfg_value::ExpectedValues { + errors::unexpected_cfg_value::ExpectedValues { name, have_none_possibility, possibilities: possibilities.into(), @@ -354,7 +342,7 @@ pub(super) fn unexpected_cfg_value( let suggestion = if let Some((value, value_span)) = value { // Suggest the most probable if we found one if let Some(best_match) = find_best_match_for_name(&possibilities, value, None) { - Some(lints::unexpected_cfg_value::ChangeValueSuggestion::SimilarName { + Some(errors::unexpected_cfg_value::ChangeValueSuggestion::SimilarName { span: value_span, best_match, }) @@ -362,7 +350,7 @@ pub(super) fn unexpected_cfg_value( None } } else if let &[first_possibility] = &possibilities[..] { - Some(lints::unexpected_cfg_value::ChangeValueSuggestion::SpecifyValue { + Some(errors::unexpected_cfg_value::ChangeValueSuggestion::SpecifyValue { span: name_span.shrink_to_hi(), first_possibility, }) @@ -370,21 +358,21 @@ pub(super) fn unexpected_cfg_value( None }; - lints::unexpected_cfg_value::CodeSuggestion::ChangeValue { expected_values, suggestion } + errors::unexpected_cfg_value::CodeSuggestion::ChangeValue { expected_values, suggestion } } else if have_none_possibility { let suggestion = - value.map(|(_value, value_span)| lints::unexpected_cfg_value::RemoveValueSuggestion { + value.map(|(_value, value_span)| errors::unexpected_cfg_value::RemoveValueSuggestion { span: name_span.shrink_to_hi().to(value_span), }); - lints::unexpected_cfg_value::CodeSuggestion::RemoveValue { suggestion, name } + errors::unexpected_cfg_value::CodeSuggestion::RemoveValue { suggestion, name } } else { let span = if let Some((_value, value_span)) = value { name_span.to(value_span) } else { name_span }; - let suggestion = lints::unexpected_cfg_value::RemoveConditionSuggestion { span }; - lints::unexpected_cfg_value::CodeSuggestion::RemoveCondition { suggestion, name } + let suggestion = errors::unexpected_cfg_value::RemoveConditionSuggestion { span }; + errors::unexpected_cfg_value::CodeSuggestion::RemoveCondition { suggestion, name } }; // We don't want to encourage people to add values to a well-known names, as these are @@ -405,32 +393,32 @@ pub(super) fn unexpected_cfg_value( let invocation_help = if is_from_cargo { let help = if name == sym::feature && !is_from_external_macro { if let Some((value, _value_span)) = value { - Some(lints::unexpected_cfg_value::CargoHelp::AddFeature { value }) + Some(errors::unexpected_cfg_value::CargoHelp::AddFeature { value }) } else { - Some(lints::unexpected_cfg_value::CargoHelp::DefineFeatures) + Some(errors::unexpected_cfg_value::CargoHelp::DefineFeatures) } } else if can_suggest_adding_value && !is_from_external_macro { - Some(lints::unexpected_cfg_value::CargoHelp::Other(cargo_help_sub(sess, &inst))) + Some(errors::unexpected_cfg_value::CargoHelp::Other(cargo_help_sub(sess, &inst))) } else { None }; - lints::unexpected_cfg_value::InvocationHelp::Cargo { + errors::unexpected_cfg_value::InvocationHelp::Cargo { help, - macro_help: cargo_macro_help(tcx, name_span), + macro_help: cargo_macro_help(name_span), } } else { let help = if can_suggest_adding_value { - Some(lints::UnexpectedCfgRustcHelp::new(&inst(EscapeQuotes::No))) + Some(errors::UnexpectedCfgRustcHelp::new(&inst(EscapeQuotes::No))) } else { None }; - lints::unexpected_cfg_value::InvocationHelp::Rustc { + errors::unexpected_cfg_value::InvocationHelp::Rustc { help, macro_help: rustc_macro_help(name_span), } }; - lints::UnexpectedCfgValue { + errors::UnexpectedCfgValue { code_sugg, invocation_help, has_value: value.is_some(), diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs index b215f77c39adb..5f21d29035b01 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs @@ -23,6 +23,7 @@ use crate::errors::{ }; use crate::parser::{ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser}; +pub(crate) mod check_cfg; pub(crate) mod do_not_recommend; pub(crate) mod on_const; pub(crate) mod on_move; diff --git a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs index 1d35923339eb7..aac3a3a22eb89 100644 --- a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs +++ b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs @@ -92,32 +92,6 @@ impl NoArgsAttributeParser for RustcNoImplicitAutorefsParser { const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoImplicitAutorefs; } -pub(crate) struct RustcLayoutScalarValidRangeStartParser; - -impl SingleAttributeParser for RustcLayoutScalarValidRangeStartParser { - const PATH: &[Symbol] = &[sym::rustc_layout_scalar_valid_range_start]; - const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Struct)]); - const TEMPLATE: AttributeTemplate = template!(List: &["start"]); - - fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option { - parse_single_integer(cx, args) - .map(|n| AttributeKind::RustcLayoutScalarValidRangeStart(Box::new(n), cx.attr_span)) - } -} - -pub(crate) struct RustcLayoutScalarValidRangeEndParser; - -impl SingleAttributeParser for RustcLayoutScalarValidRangeEndParser { - const PATH: &[Symbol] = &[sym::rustc_layout_scalar_valid_range_end]; - const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Struct)]); - const TEMPLATE: AttributeTemplate = template!(List: &["end"]); - - fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option { - parse_single_integer(cx, args) - .map(|n| AttributeKind::RustcLayoutScalarValidRangeEnd(Box::new(n), cx.attr_span)) - } -} - pub(crate) struct RustcLegacyConstGenericsParser; impl SingleAttributeParser for RustcLegacyConstGenericsParser { diff --git a/compiler/rustc_attr_parsing/src/attributes/util.rs b/compiler/rustc_attr_parsing/src/attributes/util.rs index f3a0fe89729f2..e0510130fbaf7 100644 --- a/compiler/rustc_attr_parsing/src/attributes/util.rs +++ b/compiler/rustc_attr_parsing/src/attributes/util.rs @@ -33,7 +33,7 @@ pub fn is_builtin_attr(attr: &ast::Attribute) -> bool { /// Parse a single integer. /// /// Used by attributes that take a single integer as argument, such as -/// `#[link_ordinal]` and `#[rustc_layout_scalar_valid_range_start]`. +/// `#[link_ordinal]`. /// `cx` is the context given to the attribute. /// `args` is the parser for the attribute arguments. pub(crate) fn parse_single_integer( diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 4aa7ebffbd3cf..64b6439d7ffb0 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -11,7 +11,6 @@ use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level, MultiSpan}; use rustc_feature::{AttrSuggestionStyle, AttributeTemplate}; use rustc_hir::attrs::AttributeKind; -use rustc_hir::lints::AttributeLintKind; use rustc_hir::{AttrPath, HirId}; use rustc_parse::parser::Recovery; use rustc_session::Session; @@ -226,8 +225,6 @@ attribute_parsers!( Single, Single, Single, - Single, - Single, Single, Single, Single, @@ -463,27 +460,33 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> { /// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing /// must be delayed until after HIR is built. This method will take care of the details of /// that. - pub(crate) fn emit_lint( + pub(crate) fn emit_dyn_lint< + F: for<'a> Fn(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + DynSync + 'static, + >( &mut self, lint: &'static Lint, - kind: AttributeLintKind, + callback: F, span: impl Into, ) { - self.emit_lint_inner(lint, EmitAttribute::Static(kind), span); + self.emit_lint_inner( + lint, + EmitAttribute(Box::new(move |dcx, level, _| callback(dcx, level))), + span, + ); } - /// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing - /// must be delayed until after HIR is built. This method will take care of the details of - /// that. - pub(crate) fn emit_dyn_lint< - F: for<'a> Fn(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + DynSync + 'static, + pub(crate) fn emit_dyn_lint_with_sess< + F: for<'a> Fn(DiagCtxtHandle<'a>, Level, &Session) -> Diag<'a, ()> + + DynSend + + DynSync + + 'static, >( &mut self, lint: &'static Lint, callback: F, span: impl Into, ) { - self.emit_lint_inner(lint, EmitAttribute::Dynamic(Box::new(callback)), span); + self.emit_lint_inner(lint, EmitAttribute(Box::new(callback)), span); } fn emit_lint_inner( diff --git a/compiler/rustc_attr_parsing/src/errors.rs b/compiler/rustc_attr_parsing/src/errors.rs index e35f73de35ec0..85304241660be 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -421,3 +421,371 @@ pub(crate) enum FormatWarning { allowed: &'static str, }, } + +#[derive(Subdiagnostic)] +pub(crate) enum UnexpectedCfgCargoHelp { + #[help("consider using a Cargo feature instead")] + #[help( + "or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:{$cargo_toml_lint_cfg}" + )] + LintCfg { cargo_toml_lint_cfg: String }, + #[help("consider using a Cargo feature instead")] + #[help( + "or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:{$cargo_toml_lint_cfg}" + )] + #[help("or consider adding `{$build_rs_println}` to the top of the `build.rs`")] + LintCfgAndBuildRs { cargo_toml_lint_cfg: String, build_rs_println: String }, +} + +impl UnexpectedCfgCargoHelp { + fn cargo_toml_lint_cfg(unescaped: &str) -> String { + format!( + "\n [lints.rust]\n unexpected_cfgs = {{ level = \"warn\", check-cfg = ['{unescaped}'] }}" + ) + } + + pub(crate) fn lint_cfg(unescaped: &str) -> Self { + UnexpectedCfgCargoHelp::LintCfg { + cargo_toml_lint_cfg: Self::cargo_toml_lint_cfg(unescaped), + } + } + + pub(crate) fn lint_cfg_and_build_rs(unescaped: &str, escaped: &str) -> Self { + UnexpectedCfgCargoHelp::LintCfgAndBuildRs { + cargo_toml_lint_cfg: Self::cargo_toml_lint_cfg(unescaped), + build_rs_println: format!("println!(\"cargo::rustc-check-cfg={escaped}\");"), + } + } +} + +#[derive(Subdiagnostic)] +#[help("to expect this configuration use `{$cmdline_arg}`")] +pub(crate) struct UnexpectedCfgRustcHelp { + pub cmdline_arg: String, +} + +impl UnexpectedCfgRustcHelp { + pub(crate) fn new(unescaped: &str) -> Self { + Self { cmdline_arg: format!("--check-cfg={unescaped}") } + } +} + +#[derive(Subdiagnostic)] +#[note( + "using a cfg inside a {$macro_kind} will use the cfgs from the destination crate and not the ones from the defining crate" +)] +#[help("try referring to `{$macro_name}` crate for guidance on how handle this unexpected cfg")] +pub(crate) struct UnexpectedCfgRustcMacroHelp { + pub macro_kind: &'static str, + pub macro_name: Symbol, +} + +#[derive(Subdiagnostic)] +#[note( + "using a cfg inside a {$macro_kind} will use the cfgs from the destination crate and not the ones from the defining crate" +)] +#[help("try referring to `{$macro_name}` crate for guidance on how handle this unexpected cfg")] +pub(crate) struct UnexpectedCfgCargoMacroHelp { + pub macro_kind: &'static str, + pub macro_name: Symbol, +} + +#[derive(Diagnostic)] +#[diag("unexpected `cfg` condition name: `{$name}`")] +pub(crate) struct UnexpectedCfgName { + #[subdiagnostic] + pub code_sugg: unexpected_cfg_name::CodeSuggestion, + #[subdiagnostic] + pub invocation_help: unexpected_cfg_name::InvocationHelp, + + pub name: Symbol, +} + +pub(crate) mod unexpected_cfg_name { + use rustc_errors::DiagSymbolList; + use rustc_macros::Subdiagnostic; + use rustc_span::{Ident, Span, Symbol}; + + #[derive(Subdiagnostic)] + pub(crate) enum CodeSuggestion { + #[help("consider defining some features in `Cargo.toml`")] + DefineFeatures, + #[multipart_suggestion( + "there is a similar config predicate: `version(\"..\")`", + applicability = "machine-applicable" + )] + VersionSyntax { + #[suggestion_part(code = "(")] + between_name_and_value: Span, + #[suggestion_part(code = ")")] + after_value: Span, + }, + #[suggestion( + "there is a config with a similar name and value", + applicability = "maybe-incorrect", + code = "{code}" + )] + SimilarNameAndValue { + #[primary_span] + span: Span, + code: String, + }, + #[suggestion( + "there is a config with a similar name and no value", + applicability = "maybe-incorrect", + code = "{code}" + )] + SimilarNameNoValue { + #[primary_span] + span: Span, + code: String, + }, + #[suggestion( + "there is a config with a similar name and different values", + applicability = "maybe-incorrect", + code = "{code}" + )] + SimilarNameDifferentValues { + #[primary_span] + span: Span, + code: String, + #[subdiagnostic] + expected: Option, + }, + #[suggestion( + "there is a config with a similar name", + applicability = "maybe-incorrect", + code = "{code}" + )] + SimilarName { + #[primary_span] + span: Span, + code: String, + #[subdiagnostic] + expected: Option, + }, + SimilarValues { + #[subdiagnostic] + with_similar_values: Vec, + #[subdiagnostic] + expected_names: Option, + }, + #[suggestion( + "you may have meant to use `{$literal}` (notice the capitalization). Doing so makes this predicate evaluate to `{$literal}` unconditionally", + applicability = "machine-applicable", + style = "verbose", + code = "{literal}" + )] + BooleanLiteral { + #[primary_span] + span: Span, + literal: bool, + }, + } + + #[derive(Subdiagnostic)] + #[help("expected values for `{$best_match}` are: {$possibilities}")] + pub(crate) struct ExpectedValues { + pub best_match: Symbol, + pub possibilities: DiagSymbolList, + } + + #[derive(Subdiagnostic)] + #[suggestion( + "found config with similar value", + applicability = "maybe-incorrect", + code = "{code}" + )] + pub(crate) struct FoundWithSimilarValue { + #[primary_span] + pub span: Span, + pub code: String, + } + + #[derive(Subdiagnostic)] + #[help_once( + "expected names are: {$possibilities}{$and_more -> + [0] {\"\"} + *[other] {\" \"}and {$and_more} more + }" + )] + pub(crate) struct ExpectedNames { + pub possibilities: DiagSymbolList, + pub and_more: usize, + } + + #[derive(Subdiagnostic)] + pub(crate) enum InvocationHelp { + #[note( + "see for more information about checking conditional configuration" + )] + Cargo { + #[subdiagnostic] + macro_help: Option, + #[subdiagnostic] + help: Option, + }, + #[note( + "see for more information about checking conditional configuration" + )] + Rustc { + #[subdiagnostic] + macro_help: Option, + #[subdiagnostic] + help: super::UnexpectedCfgRustcHelp, + }, + } +} + +#[derive(Diagnostic)] +#[diag( + "unexpected `cfg` condition value: {$has_value -> + [true] `{$value}` + *[false] (none) + }" +)] +pub(crate) struct UnexpectedCfgValue { + #[subdiagnostic] + pub code_sugg: unexpected_cfg_value::CodeSuggestion, + #[subdiagnostic] + pub invocation_help: unexpected_cfg_value::InvocationHelp, + + pub has_value: bool, + pub value: String, +} + +pub(crate) mod unexpected_cfg_value { + use rustc_errors::DiagSymbolList; + use rustc_macros::Subdiagnostic; + use rustc_span::{Span, Symbol}; + + #[derive(Subdiagnostic)] + pub(crate) enum CodeSuggestion { + ChangeValue { + #[subdiagnostic] + expected_values: ExpectedValues, + #[subdiagnostic] + suggestion: Option, + }, + #[note("no expected value for `{$name}`")] + RemoveValue { + #[subdiagnostic] + suggestion: Option, + + name: Symbol, + }, + #[note("no expected values for `{$name}`")] + RemoveCondition { + #[subdiagnostic] + suggestion: RemoveConditionSuggestion, + + name: Symbol, + }, + ChangeName { + #[subdiagnostic] + suggestions: Vec, + }, + } + + #[derive(Subdiagnostic)] + pub(crate) enum ChangeValueSuggestion { + #[suggestion( + "there is a expected value with a similar name", + code = r#""{best_match}""#, + applicability = "maybe-incorrect" + )] + SimilarName { + #[primary_span] + span: Span, + best_match: Symbol, + }, + #[suggestion( + "specify a config value", + code = r#" = "{first_possibility}""#, + applicability = "maybe-incorrect" + )] + SpecifyValue { + #[primary_span] + span: Span, + first_possibility: Symbol, + }, + } + + #[derive(Subdiagnostic)] + #[suggestion("remove the value", code = "", applicability = "maybe-incorrect")] + pub(crate) struct RemoveValueSuggestion { + #[primary_span] + pub span: Span, + } + + #[derive(Subdiagnostic)] + #[suggestion("remove the condition", code = "", applicability = "maybe-incorrect")] + pub(crate) struct RemoveConditionSuggestion { + #[primary_span] + pub span: Span, + } + + #[derive(Subdiagnostic)] + #[note( + "expected values for `{$name}` are: {$have_none_possibility -> + [true] {\"(none), \"} + *[false] {\"\"} + }{$possibilities}{$and_more -> + [0] {\"\"} + *[other] {\" \"}and {$and_more} more + }" + )] + pub(crate) struct ExpectedValues { + pub name: Symbol, + pub have_none_possibility: bool, + pub possibilities: DiagSymbolList, + pub and_more: usize, + } + + #[derive(Subdiagnostic)] + #[suggestion( + "`{$value}` is an expected value for `{$name}`", + code = "{name}", + applicability = "maybe-incorrect", + style = "verbose" + )] + pub(crate) struct ChangeNameSuggestion { + #[primary_span] + pub span: Span, + pub name: Symbol, + pub value: Symbol, + } + + #[derive(Subdiagnostic)] + pub(crate) enum InvocationHelp { + #[note( + "see for more information about checking conditional configuration" + )] + Cargo { + #[subdiagnostic] + help: Option, + #[subdiagnostic] + macro_help: Option, + }, + #[note( + "see for more information about checking conditional configuration" + )] + Rustc { + #[subdiagnostic] + help: Option, + #[subdiagnostic] + macro_help: Option, + }, + } + + #[derive(Subdiagnostic)] + pub(crate) enum CargoHelp { + #[help("consider adding `{$value}` as a feature in `Cargo.toml`")] + AddFeature { + value: Symbol, + }, + #[help("consider defining some features in `Cargo.toml`")] + DefineFeatures, + Other(#[subdiagnostic] super::UnexpectedCfgCargoHelp), + } +} diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index d350bfee7f348..21f1561d67d70 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -7,7 +7,6 @@ use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_errors::{Diag, DiagCtxtHandle, Level, MultiSpan}; use rustc_feature::{AttributeTemplate, Features}; use rustc_hir::attrs::AttributeKind; -use rustc_hir::lints::AttributeLintKind; use rustc_hir::{AttrArgs, AttrItem, AttrPath, Attribute, HashIgnoredAttrId, Target}; use rustc_session::Session; use rustc_session::lint::LintId; @@ -20,14 +19,14 @@ use crate::parser::{AllowExprMetavar, ArgParser, PathParser, RefPathParser}; use crate::session_diagnostics::ParsedDescription; use crate::{Early, Late, OmitDoc, ShouldEmit}; -pub enum EmitAttribute { - Static(AttributeLintKind), - Dynamic( - Box< - dyn for<'a> Fn(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + DynSync + 'static, - >, - ), -} +pub struct EmitAttribute( + pub Box< + dyn for<'a> Fn(DiagCtxtHandle<'a>, Level, &Session) -> Diag<'a, ()> + + DynSend + + DynSync + + 'static, + >, +); /// Context created once, for example as part of the ast lowering /// context, through which all attributes can be lowered. @@ -127,13 +126,8 @@ impl<'sess> AttributeParser<'sess, Early> { target, OmitDoc::Skip, std::convert::identity, - |lint_id, span, kind| match kind { - EmitAttribute::Static(kind) => { - sess.psess.buffer_lint(lint_id.lint, span, target_node_id, kind) - } - EmitAttribute::Dynamic(callback) => { - sess.psess.dyn_buffer_lint(lint_id.lint, span, target_node_id, callback) - } + |lint_id, span, kind| { + sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0) }, ) } @@ -214,13 +208,8 @@ impl<'sess> AttributeParser<'sess, Early> { sess, stage: Early { emit_errors }, }; - let mut emit_lint = |lint_id: LintId, span: MultiSpan, kind: EmitAttribute| match kind { - EmitAttribute::Static(kind) => { - sess.psess.buffer_lint(lint_id.lint, span, target_node_id, kind) - } - EmitAttribute::Dynamic(callback) => { - sess.psess.dyn_buffer_lint(lint_id.lint, span, target_node_id, callback) - } + let mut emit_lint = |lint_id: LintId, span: MultiSpan, kind: EmitAttribute| { + sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0) }; if let Some(safety) = attr_safety { parser.check_attribute_safety( diff --git a/compiler/rustc_attr_parsing/src/safety.rs b/compiler/rustc_attr_parsing/src/safety.rs index 6566aaa557057..78a4e700fdcab 100644 --- a/compiler/rustc_attr_parsing/src/safety.rs +++ b/compiler/rustc_attr_parsing/src/safety.rs @@ -79,7 +79,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> { emit_lint( LintId::of(UNSAFE_ATTR_OUTSIDE_UNSAFE), path_span.into(), - EmitAttribute::Dynamic(Box::new(move |dcx, level| { + EmitAttribute(Box::new(move |dcx, level, _| { errors::UnsafeAttrOutsideUnsafeLint { span: path_span, suggestion: not_from_proc_macro diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index 8e055c855c4f1..1caa0e823090a 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -635,7 +635,7 @@ fn make_format_args( span: Some(arg_name.span.into()), node_id: rustc_ast::CRATE_NODE_ID, lint_id: LintId::of(NAMED_ARGUMENTS_USED_POSITIONALLY), - diagnostic: DecorateDiagCompat::Dynamic(Box::new(move |dcx, level, sess| { + diagnostic: DecorateDiagCompat(Box::new(move |dcx, level, sess| { let (suggestion, name) = if let Some(positional_arg_to_replace) = position_sp_to_replace { let mut name = arg_name.name.to_string(); diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index c1b72369dfadf..6e7d8354dc9b4 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -1442,7 +1442,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt, // First check that the base type is valid self.visit_value(&val.transmute(self.ecx.layout_of(*base)?, self.ecx)?)?; // When you extend this match, make sure to also add tests to - // tests/ui/type/pattern_types/validity.rs(( + // tests/ui/type/pattern_types/validity.rs match **pat { // Range and non-null patterns are precisely reflected into `valid_range` and thus // handled fully by `visit_scalar` (called below). @@ -1457,6 +1457,34 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt, // we won't see optimizations actually breaking such programs. ty::PatternKind::Or(_patterns) => {} } + // FIXME(pattern_types): handle everything based on the pattern, not on the layout. + // it's ok to run scalar validation even if the pattern type is `u8 is 0..=255` and thus + // allows uninit values, because that's rare and so not a perf issue. + match val.layout.backend_repr { + BackendRepr::Scalar(scalar_layout) => { + if !scalar_layout.is_uninit_valid() { + // There is something to check here. + // We read directly via `ecx` since the read cannot fail -- we already read + // this field above when recursing into the field. + let scalar = self.ecx.read_scalar(val)?; + self.visit_scalar(scalar, scalar_layout)?; + } + } + BackendRepr::ScalarPair(a_layout, b_layout) => { + // We can only proceed if *both* scalars need to be initialized. + // FIXME: find a way to also check ScalarPair when one side can be uninit but + // the other must be init. + if !a_layout.is_uninit_valid() && !b_layout.is_uninit_valid() { + // We read directly via `ecx` since the read cannot fail -- we already read + // this field above when recursing into the field. + let (a, b) = self.ecx.read_immediate(val)?.to_scalar_pair(); + self.visit_scalar(a, a_layout)?; + self.visit_scalar(b, b_layout)?; + } + } + BackendRepr::SimdVector { .. } | BackendRepr::SimdScalableVector { .. } => unreachable!(), + BackendRepr::Memory { .. } => unreachable!() + } } ty::Adt(adt, _) if adt.is_maybe_dangling() => { let old_may_dangle = mem::replace(&mut self.may_dangle, true); @@ -1479,15 +1507,14 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt, } } - // *After* all of this, check further information stored in the layout. We need to check - // this to handle types like `NonNull` where the `Scalar` info is more restrictive than what - // the fields say (`rustc_layout_scalar_valid_range_start`). But in most cases, this will - // just propagate what the fields say, and then we want the error to point at the field -- - // so, we first recurse, then we do this check. + // *After* all of this, check further information stored in the layout. + // On leaf types like `!` or empty enums, this will raise the error. + // This means that for types wrapping such a type, we won't ever get here, but it's + // just the simplest way to check for this case. // // FIXME: We could avoid some redundant checks here. For newtypes wrapping // scalars, we do the same check on every "level" (e.g., first we check - // MyNewtype and then the scalar in there). + // the fields of MyNewtype, and then we check MyNewType again). if val.layout.is_uninhabited() { let ty = val.layout.ty; throw_validation_failure!( @@ -1495,35 +1522,40 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt, format!("encountered a value of uninhabited type `{ty}`") ); } - match val.layout.backend_repr { - BackendRepr::Scalar(scalar_layout) => { - if !scalar_layout.is_uninit_valid() { - // There is something to check here. - // We read directly via `ecx` since the read cannot fail -- we already read - // this field above when recursing into the field. - let scalar = self.ecx.read_scalar(val)?; - self.visit_scalar(scalar, scalar_layout)?; + if cfg!(debug_assertions) { + // Check that we don't miss any new changes to layout computation in our checks above. + match val.layout.backend_repr { + BackendRepr::Scalar(scalar_layout) => { + if !scalar_layout.is_uninit_valid() { + // There is something to check here. + // We read directly via `ecx` since the read cannot fail -- we already read + // this field above when recursing into the field. + let scalar = self + .ecx + .read_scalar(val) + .expect("the above checks should have fully handled this situation"); + self.visit_scalar(scalar, scalar_layout) + .expect("the above checks should have fully handled this situation"); + } } - } - BackendRepr::ScalarPair(a_layout, b_layout) => { - // We can only proceed if *both* scalars need to be initialized. - // FIXME: find a way to also check ScalarPair when one side can be uninit but - // the other must be init. - if !a_layout.is_uninit_valid() && !b_layout.is_uninit_valid() { - // We read directly via `ecx` since the read cannot fail -- we already read - // this field above when recursing into the field. - let (a, b) = self.ecx.read_immediate(val)?.to_scalar_pair(); - self.visit_scalar(a, a_layout)?; - self.visit_scalar(b, b_layout)?; + BackendRepr::ScalarPair(a_layout, b_layout) => { + // We can only proceed if *both* scalars need to be initialized. + // FIXME: find a way to also check ScalarPair when one side can be uninit but + // the other must be init. + if !a_layout.is_uninit_valid() && !b_layout.is_uninit_valid() { + let (a, b) = self + .ecx + .read_immediate(val) + .expect("the above checks should have fully handled this situation") + .to_scalar_pair(); + self.visit_scalar(a, a_layout) + .expect("the above checks should have fully handled this situation"); + self.visit_scalar(b, b_layout) + .expect("the above checks should have fully handled this situation"); + } } - } - BackendRepr::SimdVector { .. } | BackendRepr::SimdScalableVector { .. } => { - // No checks here, we assume layout computation gets this right. - // (This is harder to check since Miri does not represent these as `Immediate`. We - // also cannot use field projections since this might be a newtype around a vector.) - } - BackendRepr::Memory { .. } => { - // Nothing to do. + BackendRepr::SimdVector { .. } | BackendRepr::SimdScalableVector { .. } => {} + BackendRepr::Memory { .. } => {} } } diff --git a/compiler/rustc_error_codes/src/error_codes/E0429.md b/compiler/rustc_error_codes/src/error_codes/E0429.md index 8c5fd8624fdea..26986564722f5 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0429.md +++ b/compiler/rustc_error_codes/src/error_codes/E0429.md @@ -1,9 +1,11 @@ +#### Note: this error code is no longer emitted by the compiler. + The `self` keyword cannot appear alone as the last segment in a `use` declaration. Erroneous code example: -```compile_fail,E0429 +```ignore (error is no longer emitted) use std::fmt::self; // error: `self` imports are only allowed within a { } list ``` diff --git a/compiler/rustc_errors/src/decorate_diag.rs b/compiler/rustc_errors/src/decorate_diag.rs index 18c0c571fd1b8..3a222fd8a10cf 100644 --- a/compiler/rustc_errors/src/decorate_diag.rs +++ b/compiler/rustc_errors/src/decorate_diag.rs @@ -5,25 +5,20 @@ use rustc_ast::node_id::NodeId; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_error_messages::MultiSpan; -use rustc_lint_defs::{AttributeLintKind, Lint, LintId}; +use rustc_lint_defs::{Lint, LintId}; use crate::{Diag, DiagCtxtHandle, Diagnostic, Level}; -/// We can't implement `Diagnostic` for `AttributeLintKind`, because decorating some of its -/// variants requires types we don't have yet. So, handle that case separately. -pub enum DecorateDiagCompat { +pub struct DecorateDiagCompat( /// The third argument of the closure is a `Session`. However, due to the dependency tree, /// we don't have access to `rustc_session` here, so we downcast it when needed. - Dynamic( - Box< - dyn for<'a> FnOnce(DiagCtxtHandle<'a>, Level, &dyn Any) -> Diag<'a, ()> - + DynSync - + DynSend - + 'static, - >, - ), - Builtin(AttributeLintKind), -} + pub Box< + dyn for<'a> FnOnce(DiagCtxtHandle<'a>, Level, &dyn Any) -> Diag<'a, ()> + + DynSync + + DynSend + + 'static, + >, +); impl std::fmt::Debug for DecorateDiagCompat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -34,14 +29,7 @@ impl std::fmt::Debug for DecorateDiagCompat { impl Diagnostic<'a, ()> + DynSync + DynSend + 'static> From for DecorateDiagCompat { #[inline] fn from(d: D) -> Self { - Self::Dynamic(Box::new(|dcx, level, _| d.into_diag(dcx, level))) - } -} - -impl From for DecorateDiagCompat { - #[inline] - fn from(b: AttributeLintKind) -> Self { - Self::Builtin(b) + Self(Box::new(|dcx, level, _| d.into_diag(dcx, level))) } } @@ -106,7 +94,7 @@ impl LintBuffer { lint_id: LintId::of(lint), node_id, span: Some(span.into()), - diagnostic: DecorateDiagCompat::Dynamic(Box::new(|dcx, level, _| callback(dcx, level))), + diagnostic: DecorateDiagCompat(Box::new(|dcx, level, _| callback(dcx, level))), }); } @@ -126,7 +114,7 @@ impl LintBuffer { lint_id: LintId::of(lint), node_id, span: Some(span.into()), - diagnostic: DecorateDiagCompat::Dynamic(Box::new(callback)), + diagnostic: DecorateDiagCompat(Box::new(callback)), }); } } diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index ecde304aabfc2..377d96b73e9b8 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -129,18 +129,6 @@ impl<'a> Diagnostic<'a, ()> } } -pub struct DiagCallback<'a>( - pub &'a Box< - dyn for<'b> Fn(DiagCtxtHandle<'b>, Level) -> Diag<'b, ()> + DynSend + DynSync + 'static, - >, -); - -impl<'a, 'b> Diagnostic<'a, ()> for DiagCallback<'b> { - fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { - (self.0)(dcx, level) - } -} - /// Type used to emit diagnostic through a closure instead of implementing the `Diagnostic` trait. pub struct DiagDecorator)>(pub F); diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index f4874652f6ace..9c51df1a49fef 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -36,8 +36,8 @@ pub use anstyle::{ pub use codes::*; pub use decorate_diag::{BufferedEarlyLint, DecorateDiagCompat, LintBuffer}; pub use diagnostic::{ - BugAbort, Diag, DiagCallback, DiagDecorator, DiagInner, DiagLocation, DiagStyledString, - Diagnostic, EmissionGuarantee, FatalAbort, StringPart, Subdiag, Subdiagnostic, + BugAbort, Diag, DiagDecorator, DiagInner, DiagLocation, DiagStyledString, Diagnostic, + EmissionGuarantee, FatalAbort, StringPart, Subdiag, Subdiagnostic, }; pub use diagnostic_impls::{ DiagSymbolList, ElidedLifetimeInPathSubdiag, ExpectedLifetimeParameter, diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 053caee258f7b..58bf12855ad6e 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -573,16 +573,6 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // Internal attributes, Layout related: // ========================================================================== - rustc_attr!( - rustc_layout_scalar_valid_range_start, - "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \ - niche optimizations in the standard library", - ), - rustc_attr!( - rustc_layout_scalar_valid_range_end, - "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \ - niche optimizations in the standard library", - ), rustc_attr!( rustc_simd_monomorphize_lane_limit, "the `#[rustc_simd_monomorphize_lane_limit]` attribute is just used by std::simd \ diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index 6304b830f6ed7..d1308ea9aaee7 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -1451,12 +1451,6 @@ pub enum AttributeKind { /// Represents `#[rustc_intrinsic_const_stable_indirect]` RustcIntrinsicConstStableIndirect, - /// Represents `#[rustc_layout_scalar_valid_range_end]`. - RustcLayoutScalarValidRangeEnd(Box, Span), - - /// Represents `#[rustc_layout_scalar_valid_range_start]`. - RustcLayoutScalarValidRangeStart(Box, Span), - /// Represents `#[rustc_legacy_const_generics]` RustcLegacyConstGenerics { fn_indexes: ThinVec<(usize, Span)>, diff --git a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs index 41e466a9d16b7..dd92440c7680d 100644 --- a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs +++ b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs @@ -147,8 +147,6 @@ impl AttributeKind { RustcInsignificantDtor => Yes, RustcIntrinsic => Yes, RustcIntrinsicConstStableIndirect => No, - RustcLayoutScalarValidRangeEnd(..) => Yes, - RustcLayoutScalarValidRangeStart(..) => Yes, RustcLegacyConstGenerics { .. } => Yes, RustcLintOptDenyFieldAccess { .. } => Yes, RustcLintOptTy => Yes, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index d8e675c6c56b4..fa3cf4ea8855a 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -4467,7 +4467,7 @@ impl<'hir> Item<'hir> { GenericBounds<'hir>, &'hir [TraitItemId] ), - ItemKind::Trait(impl_restriction, constness, is_auto, safety, ident, generics, bounds, items), + ItemKind::Trait { impl_restriction, constness, is_auto, safety, ident, generics, bounds, items }, (impl_restriction, *constness, *is_auto, *safety, *ident, generics, bounds, items); expect_trait_alias, (Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>), @@ -4659,16 +4659,16 @@ pub enum ItemKind<'hir> { /// A union definition, e.g., `union Foo {x: A, y: B}`. Union(Ident, &'hir Generics<'hir>, VariantData<'hir>), /// A trait definition. - Trait( - &'hir ImplRestriction<'hir>, - Constness, - IsAuto, - Safety, - Ident, - &'hir Generics<'hir>, - GenericBounds<'hir>, - &'hir [TraitItemId], - ), + Trait { + impl_restriction: &'hir ImplRestriction<'hir>, + constness: Constness, + is_auto: IsAuto, + safety: Safety, + ident: Ident, + generics: &'hir Generics<'hir>, + bounds: GenericBounds<'hir>, + items: &'hir [TraitItemId], + }, /// A trait alias. TraitAlias(Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>), @@ -4714,7 +4714,7 @@ impl ItemKind<'_> { | ItemKind::Enum(ident, ..) | ItemKind::Struct(ident, ..) | ItemKind::Union(ident, ..) - | ItemKind::Trait(_, _, _, _, ident, ..) + | ItemKind::Trait { ident, .. } | ItemKind::TraitAlias(_, ident, ..) => Some(ident), ItemKind::Use(_, UseKind::Glob | UseKind::ListStem) @@ -4732,7 +4732,7 @@ impl ItemKind<'_> { | ItemKind::Enum(_, generics, _) | ItemKind::Struct(_, generics, _) | ItemKind::Union(_, generics, _) - | ItemKind::Trait(_, _, _, _, _, generics, _, _) + | ItemKind::Trait { generics, .. } | ItemKind::TraitAlias(_, _, generics, _) | ItemKind::Impl(Impl { generics, .. }) => generics, _ => return None, diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index b77b5cfbc0953..e93059f752223 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -618,16 +618,16 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V:: try_visit!(visitor.visit_generics(generics)); try_visit!(visitor.visit_variant_data(struct_definition)); } - ItemKind::Trait( - ref impl_restriction, - _constness, - _is_auto, - _safety, + ItemKind::Trait { + impl_restriction, + constness: _, + is_auto: _, + safety: _, ident, - ref generics, + generics, bounds, - trait_item_refs, - ) => { + items: trait_item_refs, + } => { if let RestrictionKind::Restricted(path) = &impl_restriction.kind { walk_list!(visitor, visit_path_segment, path.segments); } diff --git a/compiler/rustc_hir/src/lints.rs b/compiler/rustc_hir/src/lints.rs index cdafca37a504a..0d9fc669bda7f 100644 --- a/compiler/rustc_hir/src/lints.rs +++ b/compiler/rustc_hir/src/lints.rs @@ -1,7 +1,6 @@ use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_error_messages::MultiSpan; use rustc_errors::{Diag, DiagCtxtHandle, Level}; -pub use rustc_lint_defs::AttributeLintKind; use rustc_lint_defs::LintId; use crate::HirId; @@ -14,32 +13,21 @@ pub type DelayedLints = Box<[DelayedLint]>; /// and then there's a gap where no lints can be emitted until HIR is done. /// The variants in this enum represent lints that are temporarily stashed during /// AST lowering to be emitted once HIR is built. -#[derive(Debug)] -pub enum DelayedLint { - AttributeParsing(AttributeLint), - Dynamic(DynAttribute), -} - -#[derive(Debug)] -pub struct AttributeLint { - pub lint_id: LintId, - pub id: HirId, - pub span: MultiSpan, - pub kind: AttributeLintKind, -} - -pub struct DynAttribute { +pub struct DelayedLint { pub lint_id: LintId, pub id: HirId, pub span: MultiSpan, pub callback: Box< - dyn for<'a> Fn(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + DynSync + 'static, + dyn for<'a> Fn(DiagCtxtHandle<'a>, Level, &dyn std::any::Any) -> Diag<'a, ()> + + DynSend + + DynSync + + 'static, >, } -impl std::fmt::Debug for DynAttribute { +impl std::fmt::Debug for DelayedLint { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("DynAttribute") + f.debug_struct("DelayedLint") .field("lint_id", &self.lint_id) .field("id", &self.id) .field("span", &self.span) diff --git a/compiler/rustc_hir/src/target.rs b/compiler/rustc_hir/src/target.rs index 07c33eb935f21..6a1218e4ed10b 100644 --- a/compiler/rustc_hir/src/target.rs +++ b/compiler/rustc_hir/src/target.rs @@ -132,7 +132,7 @@ impl Target { ItemKind::Enum(..) => Target::Enum, ItemKind::Struct(..) => Target::Struct, ItemKind::Union(..) => Target::Union, - ItemKind::Trait(..) => Target::Trait, + ItemKind::Trait { .. } => Target::Trait, ItemKind::TraitAlias(..) => Target::TraitAlias, ItemKind::Impl(imp_) => Target::Impl { of_trait: imp_.of_trait.is_some() }, } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 32610619fe713..05d16d2ddb49c 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -326,7 +326,7 @@ pub(super) fn check_item<'tcx>( hir::ItemKind::Struct(..) => check_type_defn(tcx, item, false), hir::ItemKind::Union(..) => check_type_defn(tcx, item, true), hir::ItemKind::Enum(..) => check_type_defn(tcx, item, true), - hir::ItemKind::Trait(..) => check_trait(tcx, item), + hir::ItemKind::Trait { .. } => check_trait(tcx, item), hir::ItemKind::TraitAlias(..) => check_trait(tcx, item), _ => Ok(()), } @@ -911,6 +911,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), Er // Can never implement `ConstParamTy`, don't suggest anything. Err( ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed + | ConstParamTyImplementationError::NonExhaustive(..) | ConstParamTyImplementationError::InvalidInnerTyOfBuiltinTy(..), ) => None, Err(ConstParamTyImplementationError::UnsizedConstParamsFeatureRequired) => { @@ -1188,7 +1189,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant }); // Only check traits, don't check trait aliases - if let hir::ItemKind::Trait(..) = item.kind { + if let hir::ItemKind::Trait { .. } = item.kind { check_gat_where_clauses(tcx, item.owner_id.def_id); } res diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 7c3511e91d79d..4a10bde4d6da3 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -221,6 +221,12 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E let span = tcx.hir_expect_item(impl_did).expect_impl().self_ty.span; Err(tcx.dcx().emit_err(errors::ConstParamTyImplOnNonAdt { span })) } + Err(ConstParamTyImplementationError::NonExhaustive(attr_span)) => { + let defn_span = tcx.hir_expect_item(impl_did).expect_impl().self_ty.span; + Err(tcx + .dcx() + .emit_err(errors::ConstParamTyImplOnNonExhaustive { defn_span, attr_span })) + } Err(ConstParamTyImplementationError::InvalidInnerTyOfBuiltinTy(infringing_tys)) => { let span = tcx.hir_expect_item(impl_did).expect_impl().self_ty.span; Err(infringing_fields_error( diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 978af77497b02..73aefeca73192 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -15,7 +15,7 @@ //! crate as a kind of pass. This should eventually be factored away. use std::cell::Cell; -use std::ops::{Bound, ControlFlow}; +use std::ops::ControlFlow; use std::{assert_matches, iter}; use rustc_abi::{ExternAbi, Size}; @@ -895,7 +895,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef { let item = tcx.hir_expect_item(def_id); let (constness, is_alias, is_auto, safety, impl_restriction) = match item.kind { - hir::ItemKind::Trait(impl_restriction, constness, is_auto, safety, ..) => ( + hir::ItemKind::Trait { impl_restriction, constness, is_auto, safety, .. } => ( constness, false, is_auto == hir::IsAuto::Yes, @@ -1039,12 +1039,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn .fields() .iter() .map(|f| tcx.type_of(f.def_id).instantiate_identity().skip_norm_wip()); - // constructors for structs with `layout_scalar_valid_range` are unsafe to call - let safety = match tcx.layout_scalar_valid_range(adt_def_id) { - (Bound::Unbounded, Bound::Unbounded) => hir::Safety::Safe, - _ => hir::Safety::Unsafe, - }; - ty::Binder::dummy(tcx.mk_fn_sig_rust_abi(inputs, ty, safety)) + ty::Binder::dummy(tcx.mk_fn_sig_rust_abi(inputs, ty, hir::Safety::Safe)) } Expr(&hir::Expr { kind: hir::ExprKind::Closure { .. }, .. }) => { diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index 3647c91fb7f15..f5935a4742eea 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -221,7 +221,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { // Add in the self type parameter. let opt_self = if let Node::Item(item) = node - && let ItemKind::Trait(..) | ItemKind::TraitAlias(..) = item.kind + && let ItemKind::Trait { .. } | ItemKind::TraitAlias(..) = item.kind { // Something of a hack: We reuse the node ID of the trait for the self type parameter. Some(ty::GenericParamDef { @@ -402,7 +402,7 @@ fn param_default_policy(node: Node<'_>) -> Option { Some(match node { Node::Item(item) => match item.kind { - ItemKind::Trait(..) + ItemKind::Trait { .. } | ItemKind::TraitAlias(..) | ItemKind::TyAlias(..) | ItemKind::Enum(..) diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index bd1faded7587a..ad46f011a79cb 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -172,7 +172,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen )); } } - ItemKind::Trait(_, _, _, _, _, _, self_bounds, ..) + ItemKind::Trait { bounds: self_bounds, .. } | ItemKind::TraitAlias(_, _, _, self_bounds) => { is_trait = Some((self_bounds, item.span)); } @@ -669,7 +669,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>( }; let (generics, superbounds) = match item.kind { - hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits), + hir::ItemKind::Trait { generics, bounds: supertraits, .. } => (generics, supertraits), hir::ItemKind::TraitAlias(_, _, generics, supertraits) => (generics, supertraits), _ => span_bug!(item.span, "super_predicates invoked on non-trait"), }; @@ -934,7 +934,7 @@ pub(super) fn type_param_predicates<'tcx>( }; if let Node::Item(item) = hir_node - && let hir::ItemKind::Trait(..) = item.kind + && let hir::ItemKind::Trait { .. } = item.kind // Implied `Self: Trait` and supertrait bounds. && param_id == item_hir_id { @@ -1073,7 +1073,7 @@ pub(super) fn const_conditions<'tcx>( Node::Item(item) => match item.kind { hir::ItemKind::Impl(impl_) => (impl_.generics, None, false), hir::ItemKind::Fn { generics, .. } => (generics, None, false), - hir::ItemKind::Trait(_, _, _, _, _, generics, supertraits, _) => { + hir::ItemKind::Trait { generics, bounds: supertraits, .. } => { (generics, Some((Some(item.owner_id.def_id), supertraits)), false) } hir::ItemKind::TraitAlias(_, _, generics, supertraits) => { @@ -1194,7 +1194,7 @@ pub(super) fn explicit_implied_const_bounds<'tcx>( } None => match tcx.hir_node_by_def_id(def_id) { Node::Item(hir::Item { - kind: hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..), + kind: hir::ItemKind::Trait { .. } | hir::ItemKind::TraitAlias(..), .. }) => implied_predicates_with_filter( tcx, diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index 2aebe267dc4bc..3a2f3948f0abc 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -647,7 +647,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { | hir::ItemKind::Enum(_, generics, _) | hir::ItemKind::Struct(_, generics, _) | hir::ItemKind::Union(_, generics, _) - | hir::ItemKind::Trait(_, _, _, _, _, generics, ..) + | hir::ItemKind::Trait { generics, .. } | hir::ItemKind::TraitAlias(_, _, generics, ..) | hir::ItemKind::Impl(hir::Impl { generics, .. }) => { // These kinds of items have only early-bound lifetime parameters. @@ -2258,7 +2258,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { // we already do that in `BoundVarContext::supertrait_hrtb_vars`. if let Res::SelfTyParam { trait_: _ } = expected_res && let hir::Node::Item(item) = node - && let hir::ItemKind::Trait(..) = item.kind + && let hir::ItemKind::Trait { .. } = item.kind { // Yield the trait's def id. Supertraits will be // elaborated from that. diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index aeb9be39c3143..41b1ec91e0e75 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -171,7 +171,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ Ty::new_adt(tcx, def, args) } ItemKind::GlobalAsm { .. } => tcx.typeck(def_id).node_type(hir_id), - ItemKind::Trait(..) + ItemKind::Trait { .. } | ItemKind::TraitAlias(..) | ItemKind::Macro(..) | ItemKind::Mod(..) diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index f353ace0b3886..1bb54f27dcbdd 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -317,6 +317,16 @@ pub(crate) struct ConstParamTyImplOnNonAdt { pub span: Span, } +#[derive(Diagnostic)] +#[diag("the trait `ConstParamTy` may not be implemented for this type")] +pub(crate) struct ConstParamTyImplOnNonExhaustive { + #[primary_span] + #[label("non exhaustive const params are forbidden")] + pub defn_span: Span, + #[label("caused by this attribute")] + pub attr_span: Span, +} + #[derive(Diagnostic)] #[diag("the trait `ConstParamTy` may not be implemented for this struct")] pub(crate) struct ConstParamTyFieldVisMismatch { diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 484fe6395173c..1a401af1d328d 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -757,7 +757,7 @@ impl<'a> State<'a> { } self.bclose(item.span, cb); } - hir::ItemKind::Trait( + hir::ItemKind::Trait { impl_restriction, constness, is_auto, @@ -765,8 +765,8 @@ impl<'a> State<'a> { ident, generics, bounds, - trait_items, - ) => { + items: trait_items, + } => { let (cb, ib) = self.head(""); self.print_impl_restriction(impl_restriction); self.print_constness(constness); diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 4dac314b91812..1fa08bbde9a24 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1998,9 +1998,13 @@ impl<'tcx> CoerceMany<'tcx> { ); } - let ret_coercion_span = fcx.ret_coercion_span.get(); + let is_return_position = fcx + .tcx + .hir_get_fn_id_for_return_block(block_or_return_id) + .is_some_and(|fn_id| fn_id == fcx.tcx.local_def_id_to_hir_id(fcx.body_id)); - if let Some(sp) = ret_coercion_span + if is_return_position + && let Some(sp) = fcx.ret_coercion_span.get() // If the closure has an explicit return type annotation, or if // the closure's return type has been inferred from outside // requirements (such as an Fn* trait bound), then a type error @@ -2009,9 +2013,6 @@ impl<'tcx> CoerceMany<'tcx> { // note in this case, since it would be incorrect. && let Some(fn_sig) = fcx.body_fn_sig() && fn_sig.output().is_ty_var() - && fcx.ret_coercion.as_ref().is_some_and(|ret_coercion| { - fcx.resolve_vars_if_possible(ret_coercion.borrow().expected_ty()) == expected - }) { err.span_note(sp, format!("return type inferred to be `{expected}` here")); } diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 7cf4822e4df67..d773420512590 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1967,7 +1967,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { entry.1.insert((self_ty.span, String::new())); } Some(Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, rustc_ast::ast::IsAuto::Yes, ..), + kind: hir::ItemKind::Trait { is_auto: rustc_ast::ast::IsAuto::Yes, .. }, span: item_span, .. })) => { @@ -1979,7 +1979,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Some( Node::Item(hir::Item { kind: - hir::ItemKind::Trait(_, _, _, _, ident, ..) + hir::ItemKind::Trait { ident, .. } | hir::ItemKind::TraitAlias(_, ident, ..), .. }) @@ -4638,7 +4638,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; } Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, _, _, ident, _, bounds, _), + kind: hir::ItemKind::Trait { ident, bounds, .. }, .. }) => { let (sp, sep, article) = if bounds.is_empty() { diff --git a/compiler/rustc_incremental/src/persist/clean.rs b/compiler/rustc_incremental/src/persist/clean.rs index e999404c6cc8a..51e65573a3566 100644 --- a/compiler/rustc_incremental/src/persist/clean.rs +++ b/compiler/rustc_incremental/src/persist/clean.rs @@ -267,7 +267,7 @@ impl<'tcx> CleanVisitor<'tcx> { HirItem::Union(..) => ("ItemUnion", LABELS_ADT), // Represents a Trait Declaration - HirItem::Trait(..) => ("ItemTrait", LABELS_TRAIT), + HirItem::Trait { .. } => ("ItemTrait", LABELS_TRAIT), // An implementation, eg `impl Trait for Foo { .. }` HirItem::Impl { .. } => ("ItemKind::Impl", LABELS_IMPL), diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 9c020c35e1429..eba38cf24b346 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -11,10 +11,12 @@ use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::{CompiledModules, CrateInfo}; use rustc_data_structures::indexmap::IndexMap; use rustc_data_structures::steal::Steal; -use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, WorkerLocal, par_fns}; +use rustc_data_structures::sync::{ + AppendOnlyIndexVec, DynSend, DynSync, FreezeLock, WorkerLocal, par_fns, +}; use rustc_data_structures::thousands; -use rustc_errors::DiagCallback; use rustc_errors::timings::TimingSection; +use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level}; use rustc_expand::base::{ExtCtxt, LintStoreExpand}; use rustc_feature::Features; use rustc_fs_util::try_canonicalize; @@ -22,12 +24,9 @@ use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::{LOCAL_CRATE, StableCrateId, StableCrateIdMap}; use rustc_hir::definitions::Definitions; use rustc_hir::limit::Limit; -use rustc_hir::lints::DelayedLint; use rustc_hir::{Attribute, MaybeOwner, Target, find_attr}; use rustc_incremental::setup_dep_graph; -use rustc_lint::{ - BufferedEarlyLint, DecorateAttrLint, EarlyCheckNode, LintStore, unerased_lint_store, -}; +use rustc_lint::{BufferedEarlyLint, EarlyCheckNode, LintStore, unerased_lint_store}; use rustc_metadata::EncodedMetadata; use rustc_metadata::creader::CStore; use rustc_middle::arena::Arena; @@ -97,7 +96,6 @@ fn pre_expansion_lint<'a>( || { rustc_lint::check_ast_node( sess, - None, features, true, lint_store, @@ -141,7 +139,7 @@ fn configure_and_expand( let tcx = resolver.tcx(); let sess = tcx.sess; let features = tcx.features(); - let lint_store = unerased_lint_store(tcx.sess); + let lint_store = unerased_lint_store(sess); let crate_name = tcx.crate_name(LOCAL_CRATE); let lint_check_node = (&krate, pre_configured_attrs); pre_expansion_lint( @@ -470,7 +468,6 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { let lint_store = unerased_lint_store(tcx.sess); rustc_lint::check_ast_node( sess, - Some(tcx), tcx.features(), false, lint_store, @@ -1028,30 +1025,29 @@ pub fn create_and_enter_global_ctxt FnOnce(TyCtxt<'tcx>) -> T>( ) } +struct DiagCallback<'a, 'tcx> { + callback: &'a Box< + dyn for<'b> Fn(DiagCtxtHandle<'b>, Level, &dyn Any) -> Diag<'b, ()> + DynSend + DynSync, + >, + tcx: TyCtxt<'tcx>, +} + +impl<'a, 'b, 'tcx> Diagnostic<'a, ()> for DiagCallback<'b, 'tcx> { + fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { + (self.callback)(dcx, level, self.tcx.sess) + } +} + pub fn emit_delayed_lints(tcx: TyCtxt<'_>) { for owner_id in tcx.hir_crate_items(()).delayed_lint_items() { if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id) { for lint in delayed_lints { - match lint { - DelayedLint::AttributeParsing(attribute_lint) => { - tcx.emit_node_span_lint( - attribute_lint.lint_id.lint, - attribute_lint.id, - attribute_lint.span.clone(), - DecorateAttrLint { - sess: tcx.sess, - tcx: Some(tcx), - diagnostic: &attribute_lint.kind, - }, - ); - } - DelayedLint::Dynamic(attribute_lint) => tcx.emit_node_span_lint( - attribute_lint.lint_id.lint, - attribute_lint.id, - attribute_lint.span.clone(), - DiagCallback(&attribute_lint.callback), - ), - } + tcx.emit_node_span_lint( + lint.lint_id.lint, + lint.id, + lint.span.clone(), + DiagCallback { callback: &lint.callback, tcx }, + ); } } } diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index df5adf694d3aa..903e223e97938 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -7,17 +7,17 @@ use rustc_ast::visit::{self as ast_visit, Visitor, walk_list}; use rustc_ast::{self as ast, AttrVec, HasAttrs}; use rustc_data_structures::stack::ensure_sufficient_stack; -use rustc_errors::{BufferedEarlyLint, DecorateDiagCompat, LintBuffer}; +use rustc_errors::{BufferedEarlyLint, LintBuffer}; use rustc_feature::Features; -use rustc_middle::ty::{RegisteredTools, TyCtxt}; +use rustc_middle::ty::RegisteredTools; use rustc_session::Session; use rustc_session::lint::LintPass; use rustc_span::{Ident, Span}; use tracing::debug; +use crate::DiagAndSess; use crate::context::{EarlyContext, LintContext, LintStore}; use crate::passes::{EarlyLintPass, EarlyLintPassObject}; -use crate::{DecorateAttrLint, DiagAndSess}; pub(super) mod diagnostics; @@ -27,36 +27,20 @@ macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({ /// Implements the AST traversal for early lint passes. `T` provides the /// `check_*` methods. -pub struct EarlyContextAndPass<'ecx, 'tcx, T: EarlyLintPass> { +pub struct EarlyContextAndPass<'ecx, T: EarlyLintPass> { context: EarlyContext<'ecx>, - tcx: Option>, pass: T, } -impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> { +impl<'ecx, T: EarlyLintPass> EarlyContextAndPass<'ecx, T> { fn check_id(&mut self, id: ast::NodeId) { for early_lint in self.context.buffered.take(id) { let BufferedEarlyLint { span, node_id: _, lint_id, diagnostic } = early_lint; - match diagnostic { - DecorateDiagCompat::Builtin(b) => { - self.context.opt_span_lint( - lint_id.lint, - span, - DecorateAttrLint { - sess: self.context.sess(), - tcx: self.tcx, - diagnostic: &b, - }, - ); - } - DecorateDiagCompat::Dynamic(callback) => { - self.context.opt_span_lint( - lint_id.lint, - span, - DiagAndSess { callback, sess: self.context.sess() }, - ); - } - } + self.context.opt_span_lint( + lint_id.lint, + span, + DiagAndSess { callback: diagnostic.0, sess: self.context.sess() }, + ); } } @@ -80,9 +64,7 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> { } } -impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast> - for EarlyContextAndPass<'ecx, 'tcx, T> -{ +impl<'ast, 'ecx, T: EarlyLintPass> ast_visit::Visitor<'ast> for EarlyContextAndPass<'ecx, T> { fn visit_id(&mut self, id: rustc_ast::NodeId) { self.check_id(id); } @@ -297,7 +279,7 @@ crate::early_lint_methods!(impl_early_lint_pass, []); pub trait EarlyCheckNode<'a>: Copy { fn id(self) -> ast::NodeId; fn attrs(self) -> &'a [ast::Attribute]; - fn check<'ecx, 'tcx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, 'tcx, T>); + fn check<'ecx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, T>); } impl<'a> EarlyCheckNode<'a> for (&'a ast::Crate, &'a [ast::Attribute]) { @@ -307,7 +289,7 @@ impl<'a> EarlyCheckNode<'a> for (&'a ast::Crate, &'a [ast::Attribute]) { fn attrs(self) -> &'a [ast::Attribute] { self.1 } - fn check<'ecx, 'tcx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, 'tcx, T>) { + fn check<'ecx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, T>) { lint_callback!(cx, check_crate, self.0); ast_visit::walk_crate(cx, self.0); lint_callback!(cx, check_crate_post, self.0); @@ -321,7 +303,7 @@ impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [ast::Attribute], &'a [Box &'a [ast::Attribute] { self.1 } - fn check<'ecx, 'tcx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, 'tcx, T>) { + fn check<'ecx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, T>) { walk_list!(cx, visit_attribute, self.1); walk_list!(cx, visit_item, self.2); } @@ -329,7 +311,6 @@ impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [ast::Attribute], &'a [Box( sess: &Session, - tcx: Option>, features: &Features, pre_expansion: bool, lint_store: &LintStore, @@ -353,23 +334,22 @@ pub fn check_ast_node<'a>( let passes = if pre_expansion { &lint_store.pre_expansion_passes } else { &lint_store.early_passes }; if passes.is_empty() { - check_ast_node_inner(sess, tcx, check_node, context, builtin_lints); + check_ast_node_inner(sess, check_node, context, builtin_lints); } else { let mut passes: Vec<_> = passes.iter().map(|mk_pass| (mk_pass)()).collect(); passes.push(Box::new(builtin_lints)); let pass = RuntimeCombinedEarlyLintPass { passes: &mut passes[..] }; - check_ast_node_inner(sess, tcx, check_node, context, pass); + check_ast_node_inner(sess, check_node, context, pass); } } fn check_ast_node_inner<'a, T: EarlyLintPass>( sess: &Session, - tcx: Option>, check_node: impl EarlyCheckNode<'a>, context: EarlyContext<'_>, pass: T, ) { - let mut cx = EarlyContextAndPass { context, tcx, pass }; + let mut cx = EarlyContextAndPass { context, pass }; cx.with_lint_attrs(check_node.id(), check_node.attrs(), |cx| check_node.check(cx)); diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index a4cb4e5320672..91259b010178d 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -2,12 +2,8 @@ use std::any::Any; use rustc_data_structures::sync::DynSend; use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level}; -use rustc_hir::lints::AttributeLintKind; -use rustc_middle::ty::TyCtxt; use rustc_session::Session; -mod check_cfg; - pub struct DiagAndSess<'sess> { pub callback: Box< dyn for<'b> FnOnce(DiagCtxtHandle<'b>, Level, &dyn Any) -> Diag<'b, ()> + DynSend + 'static, @@ -20,26 +16,3 @@ impl<'a> Diagnostic<'a, ()> for DiagAndSess<'_> { (self.callback)(dcx, level, self.sess) } } - -/// This is a diagnostic struct that will decorate a `AttributeLintKind` -/// Directly creating the lint structs is expensive, using this will only decorate the lint structs when needed. -pub struct DecorateAttrLint<'a, 'sess, 'tcx> { - pub sess: &'sess Session, - pub tcx: Option>, - pub diagnostic: &'a AttributeLintKind, -} - -impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> { - fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { - match self.diagnostic { - &AttributeLintKind::UnexpectedCfgName(name, value) => { - check_cfg::unexpected_cfg_name(self.sess, self.tcx, name, value) - .into_diag(dcx, level) - } - &AttributeLintKind::UnexpectedCfgValue(name, value) => { - check_cfg::unexpected_cfg_value(self.sess, self.tcx, name, value) - .into_diag(dcx, level) - } - } - } -} diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 4a5172a237e71..ea0e657f7edef 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -130,7 +130,7 @@ use unused::*; #[rustfmt::skip] pub use builtin::{MissingDoc, SoftLints}; pub use context::{CheckLintNameResult, EarlyContext, LateContext, LintContext, LintStore}; -pub use early::diagnostics::{DecorateAttrLint, DiagAndSess}; +pub use early::diagnostics::DiagAndSess; pub use early::{EarlyCheckNode, check_ast_node}; pub use late::{check_crate, late_lint_mod, unerased_lint_store}; pub use levels::LintLevelsBuilder; diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 05914686705a6..1e3ce972a3667 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -2653,378 +2653,6 @@ pub(crate) enum InvalidAsmLabel { }, } -#[derive(Subdiagnostic)] -pub(crate) enum UnexpectedCfgCargoHelp { - #[help("consider using a Cargo feature instead")] - #[help( - "or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:{$cargo_toml_lint_cfg}" - )] - LintCfg { cargo_toml_lint_cfg: String }, - #[help("consider using a Cargo feature instead")] - #[help( - "or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:{$cargo_toml_lint_cfg}" - )] - #[help("or consider adding `{$build_rs_println}` to the top of the `build.rs`")] - LintCfgAndBuildRs { cargo_toml_lint_cfg: String, build_rs_println: String }, -} - -impl UnexpectedCfgCargoHelp { - fn cargo_toml_lint_cfg(unescaped: &str) -> String { - format!( - "\n [lints.rust]\n unexpected_cfgs = {{ level = \"warn\", check-cfg = ['{unescaped}'] }}" - ) - } - - pub(crate) fn lint_cfg(unescaped: &str) -> Self { - UnexpectedCfgCargoHelp::LintCfg { - cargo_toml_lint_cfg: Self::cargo_toml_lint_cfg(unescaped), - } - } - - pub(crate) fn lint_cfg_and_build_rs(unescaped: &str, escaped: &str) -> Self { - UnexpectedCfgCargoHelp::LintCfgAndBuildRs { - cargo_toml_lint_cfg: Self::cargo_toml_lint_cfg(unescaped), - build_rs_println: format!("println!(\"cargo::rustc-check-cfg={escaped}\");"), - } - } -} - -#[derive(Subdiagnostic)] -#[help("to expect this configuration use `{$cmdline_arg}`")] -pub(crate) struct UnexpectedCfgRustcHelp { - pub cmdline_arg: String, -} - -impl UnexpectedCfgRustcHelp { - pub(crate) fn new(unescaped: &str) -> Self { - Self { cmdline_arg: format!("--check-cfg={unescaped}") } - } -} - -#[derive(Subdiagnostic)] -#[note( - "using a cfg inside a {$macro_kind} will use the cfgs from the destination crate and not the ones from the defining crate" -)] -#[help("try referring to `{$macro_name}` crate for guidance on how handle this unexpected cfg")] -pub(crate) struct UnexpectedCfgRustcMacroHelp { - pub macro_kind: &'static str, - pub macro_name: Symbol, -} - -#[derive(Subdiagnostic)] -#[note( - "using a cfg inside a {$macro_kind} will use the cfgs from the destination crate and not the ones from the defining crate" -)] -#[help("try referring to `{$macro_name}` crate for guidance on how handle this unexpected cfg")] -#[help( - "the {$macro_kind} `{$macro_name}` may come from an old version of the `{$crate_name}` crate, try updating your dependency with `cargo update -p {$crate_name}`" -)] -pub(crate) struct UnexpectedCfgCargoMacroHelp { - pub macro_kind: &'static str, - pub macro_name: Symbol, - pub crate_name: Symbol, -} - -#[derive(Diagnostic)] -#[diag("unexpected `cfg` condition name: `{$name}`")] -pub(crate) struct UnexpectedCfgName { - #[subdiagnostic] - pub code_sugg: unexpected_cfg_name::CodeSuggestion, - #[subdiagnostic] - pub invocation_help: unexpected_cfg_name::InvocationHelp, - - pub name: Symbol, -} - -pub(crate) mod unexpected_cfg_name { - use rustc_errors::DiagSymbolList; - use rustc_macros::Subdiagnostic; - use rustc_span::{Ident, Span, Symbol}; - - #[derive(Subdiagnostic)] - pub(crate) enum CodeSuggestion { - #[help("consider defining some features in `Cargo.toml`")] - DefineFeatures, - #[multipart_suggestion( - "there is a similar config predicate: `version(\"..\")`", - applicability = "machine-applicable" - )] - VersionSyntax { - #[suggestion_part(code = "(")] - between_name_and_value: Span, - #[suggestion_part(code = ")")] - after_value: Span, - }, - #[suggestion( - "there is a config with a similar name and value", - applicability = "maybe-incorrect", - code = "{code}" - )] - SimilarNameAndValue { - #[primary_span] - span: Span, - code: String, - }, - #[suggestion( - "there is a config with a similar name and no value", - applicability = "maybe-incorrect", - code = "{code}" - )] - SimilarNameNoValue { - #[primary_span] - span: Span, - code: String, - }, - #[suggestion( - "there is a config with a similar name and different values", - applicability = "maybe-incorrect", - code = "{code}" - )] - SimilarNameDifferentValues { - #[primary_span] - span: Span, - code: String, - #[subdiagnostic] - expected: Option, - }, - #[suggestion( - "there is a config with a similar name", - applicability = "maybe-incorrect", - code = "{code}" - )] - SimilarName { - #[primary_span] - span: Span, - code: String, - #[subdiagnostic] - expected: Option, - }, - SimilarValues { - #[subdiagnostic] - with_similar_values: Vec, - #[subdiagnostic] - expected_names: Option, - }, - #[suggestion( - "you may have meant to use `{$literal}` (notice the capitalization). Doing so makes this predicate evaluate to `{$literal}` unconditionally", - applicability = "machine-applicable", - style = "verbose", - code = "{literal}" - )] - BooleanLiteral { - #[primary_span] - span: Span, - literal: bool, - }, - } - - #[derive(Subdiagnostic)] - #[help("expected values for `{$best_match}` are: {$possibilities}")] - pub(crate) struct ExpectedValues { - pub best_match: Symbol, - pub possibilities: DiagSymbolList, - } - - #[derive(Subdiagnostic)] - #[suggestion( - "found config with similar value", - applicability = "maybe-incorrect", - code = "{code}" - )] - pub(crate) struct FoundWithSimilarValue { - #[primary_span] - pub span: Span, - pub code: String, - } - - #[derive(Subdiagnostic)] - #[help_once( - "expected names are: {$possibilities}{$and_more -> - [0] {\"\"} - *[other] {\" \"}and {$and_more} more - }" - )] - pub(crate) struct ExpectedNames { - pub possibilities: DiagSymbolList, - pub and_more: usize, - } - - #[derive(Subdiagnostic)] - pub(crate) enum InvocationHelp { - #[note( - "see for more information about checking conditional configuration" - )] - Cargo { - #[subdiagnostic] - macro_help: Option, - #[subdiagnostic] - help: Option, - }, - #[note( - "see for more information about checking conditional configuration" - )] - Rustc { - #[subdiagnostic] - macro_help: Option, - #[subdiagnostic] - help: super::UnexpectedCfgRustcHelp, - }, - } -} - -#[derive(Diagnostic)] -#[diag( - "unexpected `cfg` condition value: {$has_value -> - [true] `{$value}` - *[false] (none) - }" -)] -pub(crate) struct UnexpectedCfgValue { - #[subdiagnostic] - pub code_sugg: unexpected_cfg_value::CodeSuggestion, - #[subdiagnostic] - pub invocation_help: unexpected_cfg_value::InvocationHelp, - - pub has_value: bool, - pub value: String, -} - -pub(crate) mod unexpected_cfg_value { - use rustc_errors::DiagSymbolList; - use rustc_macros::Subdiagnostic; - use rustc_span::{Span, Symbol}; - - #[derive(Subdiagnostic)] - pub(crate) enum CodeSuggestion { - ChangeValue { - #[subdiagnostic] - expected_values: ExpectedValues, - #[subdiagnostic] - suggestion: Option, - }, - #[note("no expected value for `{$name}`")] - RemoveValue { - #[subdiagnostic] - suggestion: Option, - - name: Symbol, - }, - #[note("no expected values for `{$name}`")] - RemoveCondition { - #[subdiagnostic] - suggestion: RemoveConditionSuggestion, - - name: Symbol, - }, - ChangeName { - #[subdiagnostic] - suggestions: Vec, - }, - } - - #[derive(Subdiagnostic)] - pub(crate) enum ChangeValueSuggestion { - #[suggestion( - "there is a expected value with a similar name", - code = r#""{best_match}""#, - applicability = "maybe-incorrect" - )] - SimilarName { - #[primary_span] - span: Span, - best_match: Symbol, - }, - #[suggestion( - "specify a config value", - code = r#" = "{first_possibility}""#, - applicability = "maybe-incorrect" - )] - SpecifyValue { - #[primary_span] - span: Span, - first_possibility: Symbol, - }, - } - - #[derive(Subdiagnostic)] - #[suggestion("remove the value", code = "", applicability = "maybe-incorrect")] - pub(crate) struct RemoveValueSuggestion { - #[primary_span] - pub span: Span, - } - - #[derive(Subdiagnostic)] - #[suggestion("remove the condition", code = "", applicability = "maybe-incorrect")] - pub(crate) struct RemoveConditionSuggestion { - #[primary_span] - pub span: Span, - } - - #[derive(Subdiagnostic)] - #[note( - "expected values for `{$name}` are: {$have_none_possibility -> - [true] {\"(none), \"} - *[false] {\"\"} - }{$possibilities}{$and_more -> - [0] {\"\"} - *[other] {\" \"}and {$and_more} more - }" - )] - pub(crate) struct ExpectedValues { - pub name: Symbol, - pub have_none_possibility: bool, - pub possibilities: DiagSymbolList, - pub and_more: usize, - } - - #[derive(Subdiagnostic)] - #[suggestion( - "`{$value}` is an expected value for `{$name}`", - code = "{name}", - applicability = "maybe-incorrect", - style = "verbose" - )] - pub(crate) struct ChangeNameSuggestion { - #[primary_span] - pub span: Span, - pub name: Symbol, - pub value: Symbol, - } - - #[derive(Subdiagnostic)] - pub(crate) enum InvocationHelp { - #[note( - "see for more information about checking conditional configuration" - )] - Cargo { - #[subdiagnostic] - help: Option, - #[subdiagnostic] - macro_help: Option, - }, - #[note( - "see for more information about checking conditional configuration" - )] - Rustc { - #[subdiagnostic] - help: Option, - #[subdiagnostic] - macro_help: Option, - }, - } - - #[derive(Subdiagnostic)] - pub(crate) enum CargoHelp { - #[help("consider adding `{$value}` as a feature in `Cargo.toml`")] - AddFeature { - value: Symbol, - }, - #[help("consider defining some features in `Cargo.toml`")] - DefineFeatures, - Other(#[subdiagnostic] super::UnexpectedCfgCargoHelp), - } -} - #[derive(Diagnostic)] #[diag("creating a {$shared_label}reference to mutable static")] pub(crate) struct RefOfMutStatic<'a> { diff --git a/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs b/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs index 9f2c2058998e1..be6bd68c8140f 100644 --- a/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs +++ b/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs @@ -40,7 +40,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleSupertraitUpcastable { let def_id = item.owner_id.to_def_id(); // NOTE(nbdd0121): use `dyn_compatibility_violations` instead of `is_dyn_compatible` because // the latter will report `where_clause_object_safety` lint. - if let hir::ItemKind::Trait(_, _, _, _, ident, ..) = item.kind + if let hir::ItemKind::Trait { ident, .. } = item.kind && cx.tcx.is_dyn_compatible(def_id) { let direct_super_traits_iter = cx diff --git a/compiler/rustc_lint/src/types/improper_ctypes.rs b/compiler/rustc_lint/src/types/improper_ctypes.rs index eddc3f628ae63..bb047e9782d44 100644 --- a/compiler/rustc_lint/src/types/improper_ctypes.rs +++ b/compiler/rustc_lint/src/types/improper_ctypes.rs @@ -1145,7 +1145,7 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesLint { // Doesn't define something that can contain a external type to be checked. hir::ItemKind::Impl(..) | hir::ItemKind::TraitAlias(..) - | hir::ItemKind::Trait(..) + | hir::ItemKind::Trait { .. } | hir::ItemKind::GlobalAsm { .. } | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::Mod(..) diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 8cbd2456fccd0..94f03125ae8eb 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -12,7 +12,7 @@ use rustc_hir_id::{HirId, ItemLocalId}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_span::def_id::DefPathHash; pub use rustc_span::edition::Edition; -use rustc_span::{HashStableContext, Ident, Span, Symbol, sym}; +use rustc_span::{HashStableContext, Ident, Symbol, sym}; use serde::{Deserialize, Serialize}; pub use self::Level::*; @@ -652,12 +652,6 @@ pub enum DeprecatedSinceKind { InVersion(String), } -#[derive(Debug)] -pub enum AttributeLintKind { - UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>), - UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>), -} - pub type RegisteredTools = FxIndexSet; /// Declares a static item of type `&'static Lint`. diff --git a/compiler/rustc_middle/src/hir/map.rs b/compiler/rustc_middle/src/hir/map.rs index 68357212bebe8..5a28dde4c9ba0 100644 --- a/compiler/rustc_middle/src/hir/map.rs +++ b/compiler/rustc_middle/src/hir/map.rs @@ -644,7 +644,7 @@ impl<'tcx> TyCtxt<'tcx> { | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) - | ItemKind::Trait(..) + | ItemKind::Trait { .. } | ItemKind::Impl { .. }, .. }) @@ -695,7 +695,7 @@ impl<'tcx> TyCtxt<'tcx> { ItemKind::Enum(..) => "enum", ItemKind::Struct(..) => "struct", ItemKind::Union(..) => "union", - ItemKind::Trait(..) => "trait", + ItemKind::Trait { .. } => "trait", ItemKind::TraitAlias(..) => "trait alias", ItemKind::Impl { .. } => "impl", }; @@ -945,7 +945,7 @@ impl<'tcx> TyCtxt<'tcx> { }) => until_within(*outer_span, ty.span), // With generics and bounds. Node::Item(Item { - kind: ItemKind::Trait(_, _, _, _, _, generics, bounds, _), + kind: ItemKind::Trait { generics, bounds, .. }, span: outer_span, .. }) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 03193400f88e9..1b7d73407a589 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -11,7 +11,7 @@ use std::env::VarError; use std::ffi::OsStr; use std::hash::{Hash, Hasher}; use std::marker::{PhantomData, PointeeSized}; -use std::ops::{Bound, Deref}; +use std::ops::Deref; use std::sync::{Arc, OnceLock}; use std::{fmt, iter, mem}; @@ -1047,17 +1047,6 @@ impl<'tcx> TyCtxt<'tcx> { matches!(self.as_lang_item(def_id), Some(LangItem::Sized | LangItem::MetaSized)) } - /// Returns a range of the start/end indices specified with the - /// `rustc_layout_scalar_valid_range` attribute. - // FIXME(eddyb) this is an awkward spot for this method, maybe move it? - pub fn layout_scalar_valid_range(self, def_id: DefId) -> (Bound, Bound) { - let start = find_attr!(self, def_id, RustcLayoutScalarValidRangeStart(n, _) => Bound::Included(**n)).unwrap_or(Bound::Unbounded); - let end = - find_attr!(self, def_id, RustcLayoutScalarValidRangeEnd(n, _) => Bound::Included(**n)) - .unwrap_or(Bound::Unbounded); - (start, end) - } - pub fn lift>>(self, value: T) -> Option { value.lift_to_interner(self) } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 53706cc8202b4..13d864e3dace4 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1,4 +1,3 @@ -use std::ops::Bound; use std::{cmp, fmt}; use rustc_abi as abi; @@ -465,17 +464,7 @@ impl<'tcx> SizeSkeleton<'tcx> { // Newtype. if def.variants().len() == 1 { if let Some(SizeSkeleton::Pointer { non_zero, tail }) = v0 { - return Ok(SizeSkeleton::Pointer { - non_zero: non_zero - || match tcx.layout_scalar_valid_range(def.did()) { - (Bound::Included(start), Bound::Unbounded) => start > 0, - (Bound::Included(start), Bound::Included(end)) => { - 0 < start && start < end - } - _ => false, - }, - tail, - }); + return Ok(SizeSkeleton::Pointer { non_zero, tail }); } else { return Err(err); } diff --git a/compiler/rustc_mir_build/src/builder/mod.rs b/compiler/rustc_mir_build/src/builder/mod.rs index 8e51ab7d4edb1..e585fb85e4c8f 100644 --- a/compiler/rustc_mir_build/src/builder/mod.rs +++ b/compiler/rustc_mir_build/src/builder/mod.rs @@ -1276,5 +1276,3 @@ mod expr; mod matches; mod misc; mod scope; - -pub(crate) use expr::category::Category as ExprCategory; diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index aed0c6e6085d3..aceddcc54de95 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -1,6 +1,5 @@ use std::borrow::Cow; use std::mem; -use std::ops::Bound; use rustc_ast::AsmMacro; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -8,7 +7,6 @@ use rustc_errors::DiagArgValue; use rustc_hir::def::DefKind; use rustc_hir::{self as hir, BindingMode, ByRef, HirId, Mutability, find_attr}; use rustc_middle::middle::codegen_fn_attrs::{TargetFeature, TargetFeatureKind}; -use rustc_middle::mir::BorrowKind; use rustc_middle::span_bug; use rustc_middle::thir::visit::Visitor; use rustc_middle::thir::*; @@ -19,7 +17,6 @@ use rustc_session::lint::builtin::{DEPRECATED_SAFE_2024, UNSAFE_OP_IN_UNSAFE_FN, use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::{Span, Symbol}; -use crate::builder::ExprCategory; use crate::errors::*; struct UnsafetyVisitor<'a, 'tcx> { @@ -221,50 +218,6 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> { } } -// Searches for accesses to layout constrained fields. -struct LayoutConstrainedPlaceVisitor<'a, 'tcx> { - found: bool, - thir: &'a Thir<'tcx>, - tcx: TyCtxt<'tcx>, -} - -impl<'a, 'tcx> LayoutConstrainedPlaceVisitor<'a, 'tcx> { - fn new(thir: &'a Thir<'tcx>, tcx: TyCtxt<'tcx>) -> Self { - Self { found: false, thir, tcx } - } -} - -impl<'a, 'tcx> Visitor<'a, 'tcx> for LayoutConstrainedPlaceVisitor<'a, 'tcx> { - fn thir(&self) -> &'a Thir<'tcx> { - self.thir - } - - fn visit_expr(&mut self, expr: &'a Expr<'tcx>) { - match expr.kind { - ExprKind::Field { lhs, .. } => { - if let ty::Adt(adt_def, _) = self.thir[lhs].ty.kind() { - if (Bound::Unbounded, Bound::Unbounded) - != self.tcx.layout_scalar_valid_range(adt_def.did()) - { - self.found = true; - } - } - visit::walk_expr(self, expr); - } - - // Keep walking through the expression as long as we stay in the same - // place, i.e. the expression is a place expression and not a dereference - // (since dereferencing something leads us to a different place). - ExprKind::Deref { .. } => {} - ref kind if ExprCategory::of(kind).is_none_or(|cat| cat == ExprCategory::Place) => { - visit::walk_expr(self, expr); - } - - _ => {} - } - } -} - impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { fn thir(&self) -> &'a Thir<'tcx> { self.thir @@ -342,12 +295,6 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { std::mem::replace(&mut self.in_union_destructure, true); visit::walk_pat(self, pat); self.in_union_destructure = old_in_union_destructure; - } else if (Bound::Unbounded, Bound::Unbounded) - != self.tcx.layout_scalar_valid_range(adt_def.did()) - { - let old_inside_adt = std::mem::replace(&mut self.inside_adt, true); - visit::walk_pat(self, pat); - self.inside_adt = old_inside_adt; } else { visit::walk_pat(self, pat); } @@ -612,10 +559,6 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { if adt_def.variant(variant_index).has_unsafe_fields() { self.requires_unsafe(expr.span, InitializingTypeWithUnsafeField) } - match self.tcx.layout_scalar_valid_range(adt_def.did()) { - (Bound::Unbounded, Bound::Unbounded) => {} - _ => self.requires_unsafe(expr.span, InitializingTypeWith), - } } ExprKind::Closure(box ClosureExpr { closure_id, @@ -653,14 +596,8 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { } ExprKind::Assign { lhs, rhs } | ExprKind::AssignOp { lhs, rhs, .. } => { let lhs = &self.thir[lhs]; - // First, check whether we are mutating a layout constrained field - let mut visitor = LayoutConstrainedPlaceVisitor::new(self.thir, self.tcx); - visit::walk_expr(&mut visitor, lhs); - if visitor.found { - self.requires_unsafe(expr.span, MutationOfLayoutConstrainedField); - } - // Second, check for accesses to union fields. Don't have any + // Check for accesses to union fields. Don't have any // special handling for AssignOp since it causes a read *and* // write to lhs. if matches!(expr.kind, ExprKind::Assign { .. }) { @@ -671,23 +608,6 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { return; // We have already visited everything by now. } } - ExprKind::Borrow { borrow_kind, arg } => { - let mut visitor = LayoutConstrainedPlaceVisitor::new(self.thir, self.tcx); - visit::walk_expr(&mut visitor, expr); - if visitor.found { - match borrow_kind { - BorrowKind::Fake(_) | BorrowKind::Shared - if !self.thir[arg].ty.is_freeze(self.tcx, self.typing_env) => - { - self.requires_unsafe(expr.span, BorrowOfLayoutConstrainedField) - } - BorrowKind::Mut { .. } => { - self.requires_unsafe(expr.span, MutationOfLayoutConstrainedField) - } - BorrowKind::Fake(_) | BorrowKind::Shared => {} - } - } - } ExprKind::PlaceUnwrapUnsafeBinder { .. } | ExprKind::ValueUnwrapUnsafeBinder { .. } | ExprKind::WrapUnsafeBinder { .. } => { @@ -723,7 +643,6 @@ struct UnusedUnsafeWarning { enum UnsafeOpKind { CallToUnsafeFunction(Option), UseOfInlineAssembly, - InitializingTypeWith, InitializingTypeWithUnsafeField, UseOfMutableStatic, UseOfExternStatic, @@ -807,15 +726,6 @@ impl UnsafeOpKind { unsafe_not_inherited_note, }, ), - InitializingTypeWith => tcx.emit_node_span_lint( - UNSAFE_OP_IN_UNSAFE_FN, - hir_id, - span, - UnsafeOpInUnsafeFnInitializingTypeWithRequiresUnsafe { - span, - unsafe_not_inherited_note, - }, - ), InitializingTypeWithUnsafeField => tcx.emit_node_span_lint( UNSAFE_OP_IN_UNSAFE_FN, hir_id, @@ -988,18 +898,6 @@ impl UnsafeOpKind { UseOfInlineAssembly => { dcx.emit_err(UseOfInlineAssemblyRequiresUnsafe { span, unsafe_not_inherited_note }); } - InitializingTypeWith if unsafe_op_in_unsafe_fn_allowed => { - dcx.emit_err(InitializingTypeWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed { - span, - unsafe_not_inherited_note, - }); - } - InitializingTypeWith => { - dcx.emit_err(InitializingTypeWithRequiresUnsafe { - span, - unsafe_not_inherited_note, - }); - } InitializingTypeWithUnsafeField if unsafe_op_in_unsafe_fn_allowed => { dcx.emit_err( InitializingTypeWithUnsafeFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed { diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index 857a4056bae87..841081e30ea96 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -66,18 +66,6 @@ pub(crate) struct UnsafeOpInUnsafeFnUseOfInlineAssemblyRequiresUnsafe { pub(crate) unsafe_not_inherited_note: Option, } -#[derive(Diagnostic)] -#[diag("initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe block", code = E0133)] -#[note( - "initializing a layout restricted type's field with a value outside the valid range is undefined behavior" -)] -pub(crate) struct UnsafeOpInUnsafeFnInitializingTypeWithRequiresUnsafe { - #[label("initializing type with `rustc_layout_scalar_valid_range` attr")] - pub(crate) span: Span, - #[subdiagnostic] - pub(crate) unsafe_not_inherited_note: Option, -} - #[derive(Diagnostic)] #[diag("initializing type with an unsafe field is unsafe and requires unsafe block", code = E0133)] #[note("unsafe fields may carry library invariants")] @@ -282,19 +270,6 @@ pub(crate) struct UseOfInlineAssemblyRequiresUnsafeUnsafeOpInUnsafeFnAllowed { pub(crate) unsafe_not_inherited_note: Option, } -#[derive(Diagnostic)] -#[diag("initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe block", code = E0133)] -#[note( - "initializing a layout restricted type's field with a value outside the valid range is undefined behavior" -)] -pub(crate) struct InitializingTypeWithRequiresUnsafe { - #[primary_span] - #[label("initializing type with `rustc_layout_scalar_valid_range` attr")] - pub(crate) span: Span, - #[subdiagnostic] - pub(crate) unsafe_not_inherited_note: Option, -} - #[derive(Diagnostic)] #[diag("initializing type with an unsafe field is unsafe and requires unsafe block", code = E0133)] #[note("unsafe fields may carry library invariants")] @@ -306,22 +281,6 @@ pub(crate) struct InitializingTypeWithUnsafeFieldRequiresUnsafe { pub(crate) unsafe_not_inherited_note: Option, } -#[derive(Diagnostic)] -#[diag( - "initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block", - code = E0133 -)] -#[note( - "initializing a layout restricted type's field with a value outside the valid range is undefined behavior" -)] -pub(crate) struct InitializingTypeWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed { - #[primary_span] - #[label("initializing type with `rustc_layout_scalar_valid_range` attr")] - pub(crate) span: Span, - #[subdiagnostic] - pub(crate) unsafe_not_inherited_note: Option, -} - #[derive(Diagnostic)] #[diag( "initializing type with an unsafe field is unsafe and requires unsafe block", diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index ebf0f06f7173d..1809ce02f1d79 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -314,8 +314,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | AttributeKind::RustcInsignificantDtor | AttributeKind::RustcIntrinsic | AttributeKind::RustcIntrinsicConstStableIndirect - | AttributeKind::RustcLayoutScalarValidRangeEnd(..) - | AttributeKind::RustcLayoutScalarValidRangeStart(..) | AttributeKind::RustcLintOptDenyFieldAccess { .. } | AttributeKind::RustcLintOptTy | AttributeKind::RustcLintQueryInstability @@ -495,7 +493,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { fn check_diagnostic_on_unimplemented(&self, hir_id: HirId, directive: Option<&Directive>) { if let Some(directive) = directive { if let Node::Item(Item { - kind: ItemKind::Trait(_, _, _, _, trait_name, generics, _, _), + kind: ItemKind::Trait { ident: trait_name, generics, .. }, .. }) = self.tcx.hir_node(hir_id) { @@ -915,7 +913,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match item.kind { ItemKind::Enum(_, generics, _) | ItemKind::Struct(_, generics, _) if generics.params.len() != 0 => {} - ItemKind::Trait(_, _, _, _, _, generics, _, items) + ItemKind::Trait { generics, items, .. } if generics.params.len() != 0 || items.iter().any(|item| { matches!(self.tcx.def_kind(item.owner_id), DefKind::AssocTy) diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index e229559ae9e5d..7eb484b1d57a7 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -486,7 +486,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { intravisit::walk_item(self, item) } hir::ItemKind::ForeignMod { .. } => ControlFlow::Continue(()), - hir::ItemKind::Trait(.., trait_item_refs) => { + hir::ItemKind::Trait { items: trait_item_refs, .. } => { // mark assoc ty live if the trait is live for trait_item in trait_item_refs { if self.tcx.def_kind(trait_item.owner_id) == DefKind::AssocTy { diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 41ec056217210..6b5457daf4a27 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -256,7 +256,7 @@ impl<'tcx> ReachableContext<'tcx> { | hir::ItemKind::Mod(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::Impl { .. } - | hir::ItemKind::Trait(..) + | hir::ItemKind::Trait { .. } | hir::ItemKind::TraitAlias(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Enum(..) diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index cf234080e100a..6310155154b95 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -37,7 +37,7 @@ use crate::ref_mut::CmCell; use crate::{ BindingKey, Decl, DeclData, DeclKind, ExternModule, ExternPreludeEntry, Finalize, IdentKey, LocalModule, MacroData, Module, ModuleKind, ModuleOrUniformRoot, ParentScope, PathResult, Res, - ResolutionError, Resolver, Segment, Used, VisResolutionError, errors, + Resolver, Segment, Used, VisResolutionError, errors, }; impl<'ra, 'tcx> Resolver<'ra, 'tcx> { @@ -531,18 +531,16 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { self.r.indeterminate_imports.push(import); match import.kind { - ImportKind::Single { target, type_ns_only, .. } => { + ImportKind::Single { target, .. } => { // Don't add underscore imports to `single_imports` // because they cannot define any usable names. if target.name != kw::Underscore { self.r.per_ns(|this, ns| { - if !type_ns_only || ns == TypeNS { - let key = BindingKey::new(IdentKey::new(target), ns); - this.resolution_or_default(current_module, key, target.span) - .borrow_mut(this) - .single_imports - .insert(import); - } + let key = BindingKey::new(IdentKey::new(target), ns); + this.resolution_or_default(current_module, key, target.span) + .borrow_mut(this) + .single_imports + .insert(import); }); } } @@ -612,30 +610,8 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { let mut module_path = prefix; let source = module_path.pop().unwrap(); - // `true` for `...::{self [as target]}` imports, `false` otherwise. - let type_ns_only = nested && source.ident.name == kw::SelfLower; - - // Suggest `use prefix::{self};` for `use prefix::self;` - if source.ident.name == kw::SelfLower - && let Some(parent) = module_path.last() - && !type_ns_only - && (parent.ident.name != kw::PathRoot - || self.r.path_root_is_crate_root(parent.ident)) - { - let span_with_rename = match rename { - Some(rename) => source.ident.span.to(rename.span), - None => source.ident.span, - }; - - self.r.report_error( - parent.ident.span.shrink_to_hi().to(source.ident.span), - ResolutionError::SelfImportsOnlyAllowedWithin { - root: parent.ident.name == kw::PathRoot, - span_with_rename, - }, - ); - } - + // If the identifier is `self` without a rename, + // then it is replaced with the parent identifier. let ident = if source.ident.name == kw::SelfLower && rename.is_none() && let Some(parent) = module_path.last() @@ -689,22 +665,29 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { self.r.dcx().span_err(use_tree.span(), "extern prelude cannot be imported"); return; } - _ => {} + _ => (), + } + + // Deny `use ...::self::source [as target];` or `use ...::self::self [as target];`, + // but allow `use self::source [as target];` and `use self::self as target;`. + if let Some(parent) = module_path.last() + && parent.ident.name == kw::SelfLower + && module_path.len() > 1 + { + self.r.dcx().span_err( + parent.ident.span, + "`self` in paths can only be used in start position or last position", + ); + return; } // Deny importing path-kw without renaming if rename.is_none() && ident.is_path_segment_keyword() { let ident = use_tree.ident(); - - // Don't suggest `use xx::self as name;` for `use xx::self;` - // But it's OK to suggest `use xx::{self as name};` for `use xx::{self};` - let sugg = if !type_ns_only && ident.name == kw::SelfLower { - None - } else { - Some(errors::UnnamedImportSugg { span: ident.span, ident }) - }; - - self.r.dcx().emit_err(errors::UnnamedImport { span: ident.span, sugg }); + self.r.dcx().emit_err(errors::UnnamedImport { + span: ident.span, + sugg: errors::UnnamedImportSugg { span: ident.span, ident }, + }); return; } @@ -712,7 +695,6 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { source: source.ident, target: ident, decls: Default::default(), - type_ns_only, nested, id, }; diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index cbec647bdc95e..723890a2f1ca2 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -386,9 +386,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let mut suggestion = None; let mut span = binding_span; match import.kind { - ImportKind::Single { type_ns_only: true, .. } => { - suggestion = Some(format!("self as {suggested_name}")) - } ImportKind::Single { source, .. } => { if let Some(pos) = source.span.hi().0.checked_sub(binding_span.lo().0) && let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(binding_span) @@ -913,29 +910,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { sub_unreachable, }) } - ResolutionError::SelfImportsOnlyAllowedWithin { root, span_with_rename } => { - // None of the suggestions below would help with a case like `use self`. - let (suggestion, mpart_suggestion) = if root { - (None, None) - } else { - // use foo::bar::self -> foo::bar - // use foo::bar::self as abc -> foo::bar as abc - let suggestion = errs::SelfImportsOnlyAllowedWithinSuggestion { span }; - - // use foo::bar::self -> foo::bar::{self} - // use foo::bar::self as abc -> foo::bar::{self as abc} - let mpart_suggestion = errs::SelfImportsOnlyAllowedWithinMultipartSuggestion { - multipart_start: span_with_rename.shrink_to_lo(), - multipart_end: span_with_rename.shrink_to_hi(), - }; - (Some(suggestion), Some(mpart_suggestion)) - }; - self.dcx().create_err(errs::SelfImportsOnlyAllowedWithin { - span, - suggestion, - mpart_suggestion, - }) - } ResolutionError::FailedToResolve { segment, label, suggestion, module, message } => { let mut err = struct_span_code_err!(self.dcx(), span, E0433, "{message}"); err.span_label(span, label); diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index 8c7bf61949a29..9f26fc076e57f 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -301,40 +301,6 @@ pub(crate) struct AttemptToUseNonConstantValueInConstantWithoutSuggestion<'a> { pub(crate) suggestion: &'a str, } -#[derive(Diagnostic)] -#[diag("`self` imports are only allowed within a {\"{\"} {\"}\"} list", code = E0429)] -pub(crate) struct SelfImportsOnlyAllowedWithin { - #[primary_span] - pub(crate) span: Span, - #[subdiagnostic] - pub(crate) suggestion: Option, - #[subdiagnostic] - pub(crate) mpart_suggestion: Option, -} - -#[derive(Subdiagnostic)] -#[suggestion( - "consider importing the module directly", - code = "", - applicability = "machine-applicable" -)] -pub(crate) struct SelfImportsOnlyAllowedWithinSuggestion { - #[primary_span] - pub(crate) span: Span, -} - -#[derive(Subdiagnostic)] -#[multipart_suggestion( - "alternatively, use the multi-path `use` syntax to import `self`", - applicability = "machine-applicable" -)] -pub(crate) struct SelfImportsOnlyAllowedWithinMultipartSuggestion { - #[suggestion_part(code = "{{")] - pub(crate) multipart_start: Span, - #[suggestion_part(code = "}}")] - pub(crate) multipart_end: Span, -} - #[derive(Diagnostic)] #[diag("{$shadowing_binding}s cannot shadow {$shadowed_binding}s", code = E0530)] pub(crate) struct BindingShadowsSomethingUnacceptable<'a> { @@ -998,7 +964,7 @@ pub(crate) struct UnnamedImport { #[primary_span] pub(crate) span: Span, #[subdiagnostic] - pub(crate) sugg: Option, + pub(crate) sugg: UnnamedImportSugg, } #[derive(Diagnostic)] diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 35ed1c772a328..a0f63a47f9b4e 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -1837,8 +1837,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } } + let allow_trailing_self = is_last && name == kw::SelfLower; + // Report special messages for path segment keywords in wrong positions. - if ident.is_path_segment_keyword() && segment_idx != 0 { + if ident.is_path_segment_keyword() && segment_idx != 0 && !allow_trailing_self { return PathResult::failed( ident, false, @@ -1858,6 +1860,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { format!("global paths cannot start with {name_str}"), "cannot start with this".to_string(), ) + } else if name == kw::SelfLower { + ( + format!( + "`self` in paths can only be used in start position or last position" + ), + "can only be used in path start position or last position" + .to_string(), + ) } else { ( format!("{name_str} in paths can only be used in start position"), diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index b6ba35f0f3db8..a3b80ae264da6 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -73,8 +73,6 @@ pub(crate) enum ImportKind<'ra> { target: Ident, /// Name declarations introduced by the import. decls: PerNS>>, - /// `true` for `...::{self [as target]}` imports, `false` otherwise. - type_ns_only: bool, /// Did this import result from a nested import? i.e. `use foo::{bar, baz};` nested: bool, /// The ID of the `UseTree` that imported this `Import`. @@ -115,7 +113,7 @@ impl<'ra> std::fmt::Debug for ImportKind<'ra> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use ImportKind::*; match self { - Single { source, target, decls, type_ns_only, nested, id, .. } => f + Single { source, target, decls, nested, id, .. } => f .debug_struct("Single") .field("source", source) .field("target", target) @@ -124,7 +122,6 @@ impl<'ra> std::fmt::Debug for ImportKind<'ra> { "decls", &decls.clone().map(|b| b.into_inner().decl().map(|_| format_args!(".."))), ) - .field("type_ns_only", type_ns_only) .field("nested", nested) .field("id", id) .finish(), @@ -1004,10 +1001,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { }; import.imported_module.set_unchecked(Some(module)); - let (source, target, bindings, type_ns_only) = match import.kind { - ImportKind::Single { source, target, ref decls, type_ns_only, .. } => { - (source, target, decls, type_ns_only) - } + let (source, target, bindings) = match import.kind { + ImportKind::Single { source, target, ref decls, .. } => (source, target, decls), ImportKind::Glob { .. } => { self.get_mut_unchecked().resolve_glob_import(import); return 0; @@ -1017,64 +1012,62 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let mut indeterminate_count = 0; self.per_ns_cm(|mut this, ns| { - if !type_ns_only || ns == TypeNS { - if bindings[ns].get() != PendingDecl::Pending { - return; - }; - let binding_result = this.reborrow().maybe_resolve_ident_in_module( - module, - source, - ns, - &import.parent_scope, - Some(import), - ); - let parent = import.parent_scope.module; - let binding = match binding_result { - Ok(binding) => { - if binding.is_assoc_item() - && !this.tcx.features().import_trait_associated_functions() - { - feature_err( - this.tcx.sess, - sym::import_trait_associated_functions, - import.span, - "`use` associated items of traits is unstable", - ) - .emit(); - } - // We need the `target`, `source` can be extracted. - let import_decl = this.new_import_decl(binding, import); - this.get_mut_unchecked().plant_decl_into_local_module( - IdentKey::new(target), + if bindings[ns].get() != PendingDecl::Pending { + return; + }; + let binding_result = this.reborrow().maybe_resolve_ident_in_module( + module, + source, + ns, + &import.parent_scope, + Some(import), + ); + let parent = import.parent_scope.module; + let binding = match binding_result { + Ok(binding) => { + if binding.is_assoc_item() + && !this.tcx.features().import_trait_associated_functions() + { + feature_err( + this.tcx.sess, + sym::import_trait_associated_functions, + import.span, + "`use` associated items of traits is unstable", + ) + .emit(); + } + // We need the `target`, `source` can be extracted. + let import_decl = this.new_import_decl(binding, import); + this.get_mut_unchecked().plant_decl_into_local_module( + IdentKey::new(target), + target.span, + ns, + import_decl, + ); + PendingDecl::Ready(Some(import_decl)) + } + Err(Determinacy::Determined) => { + // Don't remove underscores from `single_imports`, they were never added. + if target.name != kw::Underscore { + let key = BindingKey::new(IdentKey::new(target), ns); + this.get_mut_unchecked().update_local_resolution( + parent.expect_local(), + key, target.span, - ns, - import_decl, + false, + |_, resolution| { + resolution.single_imports.swap_remove(&import); + }, ); - PendingDecl::Ready(Some(import_decl)) } - Err(Determinacy::Determined) => { - // Don't remove underscores from `single_imports`, they were never added. - if target.name != kw::Underscore { - let key = BindingKey::new(IdentKey::new(target), ns); - this.get_mut_unchecked().update_local_resolution( - parent.expect_local(), - key, - target.span, - false, - |_, resolution| { - resolution.single_imports.swap_remove(&import); - }, - ); - } - PendingDecl::Ready(None) - } - Err(Determinacy::Undetermined) => { - indeterminate_count += 1; - PendingDecl::Pending - } - }; - bindings[ns].set_unchecked(binding); - } + PendingDecl::Ready(None) + } + Err(Determinacy::Undetermined) => { + indeterminate_count += 1; + PendingDecl::Pending + } + }; + bindings[ns].set_unchecked(binding); }); indeterminate_count @@ -1215,10 +1208,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { PathResult::Indeterminate => unreachable!(), }; - let (ident, target, bindings, type_ns_only, import_id) = match import.kind { - ImportKind::Single { source, target, ref decls, type_ns_only, id, .. } => { - (source, target, decls, type_ns_only, id) - } + let (ident, target, bindings, import_id) = match import.kind { + ImportKind::Single { source, target, ref decls, id, .. } => (source, target, decls, id), ImportKind::Glob { ref max_vis, id } => { if import.module_path.len() <= 1 { // HACK(eddyb) `lint_if_path_starts_with_module` needs at least @@ -1286,86 +1277,82 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let mut all_ns_err = true; self.per_ns(|this, ns| { - if !type_ns_only || ns == TypeNS { - let binding = this.cm().resolve_ident_in_module( - module, - ident, - ns, - &import.parent_scope, - Some(Finalize { - report_private: false, - import: Some(import.summary()), - ..finalize - }), - bindings[ns].get().decl(), - Some(import), - ); + let binding = this.cm().resolve_ident_in_module( + module, + ident, + ns, + &import.parent_scope, + Some(Finalize { + report_private: false, + import: Some(import.summary()), + ..finalize + }), + bindings[ns].get().decl(), + Some(import), + ); - match binding { - Ok(binding) => { - // Consistency checks, analogous to `finalize_macro_resolutions`. - let initial_res = bindings[ns].get().decl().map(|binding| { - let initial_binding = binding.import_source(); - all_ns_err = false; - if target.name == kw::Underscore - && initial_binding.is_extern_crate() - && !initial_binding.is_import() - { - let used = if import.module_path.is_empty() { - Used::Scope - } else { - Used::Other - }; - this.record_use(ident, binding, used); - } - initial_binding.res() - }); - let res = binding.res(); - let has_ambiguity_error = - this.ambiguity_errors.iter().any(|error| error.warning.is_none()); - if res == Res::Err || has_ambiguity_error { - this.dcx() - .span_delayed_bug(import.span, "some error happened for an import"); - return; - } - if let Some(initial_res) = initial_res { - if res != initial_res && !this.issue_145575_hack_applied { - span_bug!(import.span, "inconsistent resolution for an import"); - } - } else if this.privacy_errors.is_empty() { - this.dcx() - .create_err(CannotDetermineImportResolution { span: import.span }) - .emit(); + match binding { + Ok(binding) => { + // Consistency checks, analogous to `finalize_macro_resolutions`. + let initial_res = bindings[ns].get().decl().map(|binding| { + let initial_binding = binding.import_source(); + all_ns_err = false; + if target.name == kw::Underscore + && initial_binding.is_extern_crate() + && !initial_binding.is_import() + { + let used = if import.module_path.is_empty() { + Used::Scope + } else { + Used::Other + }; + this.record_use(ident, binding, used); } + initial_binding.res() + }); + let res = binding.res(); + let has_ambiguity_error = + this.ambiguity_errors.iter().any(|error| error.warning.is_none()); + if res == Res::Err || has_ambiguity_error { + this.dcx() + .span_delayed_bug(import.span, "some error happened for an import"); + return; } - Err(..) => { - // FIXME: This assert may fire if public glob is later shadowed by a private - // single import (see test `issue-55884-2.rs`). In theory single imports should - // always block globs, even if they are not yet resolved, so that this kind of - // self-inconsistent resolution never happens. - // Re-enable the assert when the issue is fixed. - // assert!(result[ns].get().is_err()); + if let Some(initial_res) = initial_res { + if res != initial_res && !this.issue_145575_hack_applied { + span_bug!(import.span, "inconsistent resolution for an import"); + } + } else if this.privacy_errors.is_empty() { + this.dcx() + .create_err(CannotDetermineImportResolution { span: import.span }) + .emit(); } } + Err(..) => { + // FIXME: This assert may fire if public glob is later shadowed by a private + // single import (see test `issue-55884-2.rs`). In theory single imports should + // always block globs, even if they are not yet resolved, so that this kind of + // self-inconsistent resolution never happens. + // Re-enable the assert when the issue is fixed. + // assert!(result[ns].get().is_err()); + } } }); if all_ns_err { let mut all_ns_failed = true; self.per_ns(|this, ns| { - if !type_ns_only || ns == TypeNS { - let binding = this.cm().resolve_ident_in_module( - module, - ident, - ns, - &import.parent_scope, - Some(finalize), - None, - None, - ); - if binding.is_ok() { - all_ns_failed = false; - } + let binding = this.cm().resolve_ident_in_module( + module, + ident, + ns, + &import.parent_scope, + Some(finalize), + None, + None, + ); + if binding.is_ok() { + all_ns_failed = false; } }); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 6e15f055c6aca..3b8f3c4a24c90 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -270,8 +270,6 @@ enum ResolutionError<'ra> { IdentifierBoundMoreThanOnceInSamePattern(Ident), /// Error E0426: use of undeclared label. UndeclaredLabel { name: Symbol, suggestion: Option }, - /// Error E0429: `self` imports are only allowed within a `{ }` list. - SelfImportsOnlyAllowedWithin { root: bool, span_with_rename: Span }, /// Error E0433: failed to resolve. FailedToResolve { segment: Symbol, diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 8251050b6aead..1f18b178489de 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -344,7 +344,30 @@ impl ParseSess { lint, Some(span.into()), node_id, - DecorateDiagCompat::Dynamic(Box::new(|dcx, level, _| callback(dcx, level))), + DecorateDiagCompat(Box::new(|dcx, level, _| callback(dcx, level))), + ) + } + + pub fn dyn_buffer_lint_sess< + F: for<'a> FnOnce(DiagCtxtHandle<'a>, Level, &Session) -> Diag<'a, ()> + + DynSync + + DynSend + + 'static, + >( + &self, + lint: &'static Lint, + span: impl Into, + node_id: NodeId, + callback: F, + ) { + self.opt_span_buffer_lint( + lint, + Some(span.into()), + node_id, + DecorateDiagCompat(Box::new(|dcx, level, sess| { + let sess = sess.downcast_ref::().expect("expected a `Session`"); + callback(dcx, level, sess) + })), ) } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 4cacdbd3408a5..cb680ce7467db 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1755,8 +1755,6 @@ symbols! { rustc_insignificant_dtor, rustc_intrinsic, rustc_intrinsic_const_stable_indirect, - rustc_layout_scalar_valid_range_end, - rustc_layout_scalar_valid_range_start, rustc_legacy_const_generics, rustc_lint_opt_deny_field_access, rustc_lint_opt_ty, diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index 9040c4eb1e399..963b167be424d 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -829,18 +829,18 @@ static LOONGARCH_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ // tidy-alphabetical-start ("32s", Unstable(sym::loongarch_target_feature), &[]), ("d", Stable, &["f"]), - ("div32", Unstable(sym::loongarch_target_feature), &[]), + ("div32", Stable, &[]), ("f", Stable, &[]), ("frecipe", Stable, &[]), - ("lam-bh", Unstable(sym::loongarch_target_feature), &[]), - ("lamcas", Unstable(sym::loongarch_target_feature), &[]), + ("lam-bh", Stable, &[]), + ("lamcas", Stable, &[]), ("lasx", Stable, &["lsx"]), ("lbt", Stable, &[]), - ("ld-seq-sa", Unstable(sym::loongarch_target_feature), &[]), + ("ld-seq-sa", Stable, &[]), ("lsx", Stable, &["d"]), ("lvz", Stable, &[]), ("relax", Unstable(sym::loongarch_target_feature), &[]), - ("scq", Unstable(sym::loongarch_target_feature), &[]), + ("scq", Stable, &[]), ("ual", Unstable(sym::loongarch_target_feature), &[]), // tidy-alphabetical-end ]; diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs index 67bd3dc63afb1..990a703409d17 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs @@ -577,8 +577,9 @@ pub fn report_dyn_incompatibility<'tcx>( let trait_str = tcx.def_path_str(trait_def_id); let trait_span = tcx.hir_get_if_local(trait_def_id).and_then(|node| match node { hir::Node::Item(item) => match item.kind { - hir::ItemKind::Trait(_, _, _, _, ident, ..) - | hir::ItemKind::TraitAlias(_, ident, _, _) => Some(ident.span), + hir::ItemKind::Trait { ident, .. } | hir::ItemKind::TraitAlias(_, ident, _, _) => { + Some(ident.span) + } _ => unreachable!(), }, _ => None, diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 562c5956c9a84..148f1471b1b66 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -494,7 +494,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let node = self.tcx.hir_node_by_def_id(body_id); match node { hir::Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, _, _, ident, generics, bounds, _), + kind: hir::ItemKind::Trait { ident, generics, bounds, .. }, .. }) if self_ty == self.tcx.types.self_param => { assert!(param_ty); @@ -557,7 +557,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } hir::Node::Item(hir::Item { kind: - hir::ItemKind::Trait(_, _, _, _, _, generics, ..) + hir::ItemKind::Trait { generics, .. } | hir::ItemKind::Impl(hir::Impl { generics, .. }), .. }) if projection.is_some() => { @@ -581,7 +581,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { hir::ItemKind::Struct(_, generics, _) | hir::ItemKind::Enum(_, generics, _) | hir::ItemKind::Union(_, generics, _) - | hir::ItemKind::Trait(_, _, _, _, _, generics, ..) + | hir::ItemKind::Trait { generics, .. } | hir::ItemKind::Impl(hir::Impl { generics, .. }) | hir::ItemKind::Fn { generics, .. } | hir::ItemKind::TyAlias(_, generics, _) @@ -661,7 +661,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { hir::ItemKind::Struct(_, generics, _) | hir::ItemKind::Enum(_, generics, _) | hir::ItemKind::Union(_, generics, _) - | hir::ItemKind::Trait(_, _, _, _, _, generics, ..) + | hir::ItemKind::Trait { generics, .. } | hir::ItemKind::Impl(hir::Impl { generics, .. }) | hir::ItemKind::Fn { generics, .. } | hir::ItemKind::TyAlias(_, generics, _) @@ -4184,7 +4184,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let mut is_auto_trait = false; match tcx.hir_get_if_local(data.impl_or_alias_def_id) { Some(Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, is_auto, _, ident, _, _, _), + kind: hir::ItemKind::Trait { is_auto, ident, .. }, .. })) => { // FIXME: we should do something else so that it works even on crate foreign diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index 1271233d26e18..3610ffbb30c3b 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -623,7 +623,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> { match self.tcx.parent_hir_node(self.tcx.local_def_id_to_hir_id(anon_reg.scope)) { hir::Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, _, _, _, generics, ..), + kind: hir::ItemKind::Trait { generics, .. }, .. }) | hir::Node::Item(hir::Item { diff --git a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs index 4e8ee9ed426c7..d1522ec89a016 100644 --- a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs +++ b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs @@ -141,7 +141,7 @@ fn get_sized_bounds(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]> tcx.hir_get_if_local(trait_def_id) .and_then(|node| match node { hir::Node::Item(hir::Item { - kind: hir::ItemKind::Trait(.., generics, bounds, _), + kind: hir::ItemKind::Trait { generics, bounds, .. }, .. }) => Some( generics diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs index bd0068c19886f..7a0062c503685 100644 --- a/compiler/rustc_trait_selection/src/traits/misc.rs +++ b/compiler/rustc_trait_selection/src/traits/misc.rs @@ -4,8 +4,9 @@ use hir::LangItem; use rustc_ast::Mutability; use rustc_hir as hir; use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt}; +use rustc_middle::bug; use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt, TypeVisitableExt, TypingMode, Unnormalized}; -use rustc_span::sym; +use rustc_span::{Span, sym}; use crate::regions::InferCtxtRegionExt; use crate::traits::{self, FulfillmentError, Obligation, ObligationCause}; @@ -22,6 +23,7 @@ pub enum ConstParamTyImplementationError<'tcx> { InvalidInnerTyOfBuiltinTy(Vec<(Ty<'tcx>, InfringingFieldsReason<'tcx>)>), InfrigingFields(Vec<(&'tcx ty::FieldDef, Ty<'tcx>, InfringingFieldsReason<'tcx>)>), NotAnAdtOrBuiltinAllowed, + NonExhaustive(Span), } pub enum InfringingFieldsReason<'tcx> { @@ -124,6 +126,19 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>( ty::Tuple(inner_tys) => inner_tys.into_iter().collect(), ty::Adt(adt, args) if adt.is_enum() || adt.is_struct() => { + if !tcx.features().adt_const_params() { + for variant in adt.variants() { + if variant.is_field_list_non_exhaustive() { + let attr_span = match hir::find_attr!(tcx, variant.def_id, hir::attrs::AttributeKind::NonExhaustive(span) => *span) + { + Some(sp) => sp, + None => bug!("non_exhaustive variant missing NonExhaustive attribute"), + }; + return Err(ConstParamTyImplementationError::NonExhaustive(attr_span)); + } + } + } + all_fields_implement_trait( tcx, param_env, diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs index 1bfe6e94cc3b6..41ee6255a8fdd 100644 --- a/compiler/rustc_transmute/src/layout/tree.rs +++ b/compiler/rustc_transmute/src/layout/tree.rs @@ -329,33 +329,11 @@ pub(crate) mod rustc { .fold(Tree::unit(), |tree, elt| tree.then(elt))) } - ty::Adt(adt_def, _args_ref) if !ty.is_box() => { - let (lo, hi) = cx.tcx().layout_scalar_valid_range(adt_def.did()); - - use core::ops::Bound::*; - let is_transparent = adt_def.repr().transparent(); - match (adt_def.adt_kind(), lo, hi) { - (AdtKind::Struct, Unbounded, Unbounded) => { - Self::from_struct((ty, layout), *adt_def, cx) - } - (AdtKind::Struct, Included(1), Included(_hi)) if is_transparent => { - // FIXME(@joshlf): Support `NonZero` types: - // - Check to make sure that the first field is - // numerical - // - Check to make sure that the upper bound is the - // maximum value for the field's type - // - Construct `Self::nonzero` - Err(Err::NotYetSupported) - } - (AdtKind::Enum, Unbounded, Unbounded) => { - Self::from_enum((ty, layout), *adt_def, cx) - } - (AdtKind::Union, Unbounded, Unbounded) => { - Self::from_union((ty, layout), *adt_def, cx) - } - _ => Err(Err::NotYetSupported), - } - } + ty::Adt(adt_def, _args_ref) if !ty.is_box() => match adt_def.adt_kind() { + AdtKind::Struct => Self::from_struct((ty, layout), *adt_def, cx), + AdtKind::Enum => Self::from_enum((ty, layout), *adt_def, cx), + AdtKind::Union => Self::from_union((ty, layout), *adt_def, cx), + }, ty::Ref(region, ty, mutability) => { let layout = layout_of(cx, *ty)?; diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index 443f33aaa0b01..12bf1c2e5dae7 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -23,7 +23,7 @@ pub(crate) fn provide(providers: &mut Providers) { fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] { let item = tcx.hir_expect_item(def_id); match item.kind { - hir::ItemKind::Trait(.., trait_item_refs) => { + hir::ItemKind::Trait { items: trait_item_refs, .. } => { // We collect RPITITs for each trait method's return type and create a corresponding // associated item using the associated_types_for_impl_traits_in_trait_or_impl // query. @@ -151,7 +151,7 @@ fn associated_types_for_impl_traits_in_trait_or_impl<'tcx>( let item = tcx.hir_expect_item(def_id); let disambiguator = &mut PerParentDisambiguatorState::new(def_id); match item.kind { - ItemKind::Trait(.., trait_item_refs) => trait_item_refs + ItemKind::Trait { items: trait_item_refs, .. } => trait_item_refs .iter() .filter_map(move |item| { if !matches!(tcx.def_kind(item.owner_id), DefKind::AssocFn) { diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 716ecf5723839..2ee27ed0914f7 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -700,7 +700,6 @@ fn layout_of_uncached<'tcx>( &variants, def.is_enum(), is_special_no_niche, - tcx.layout_scalar_valid_range(def.did()), discr_range_of_repr, discriminants_iter(), !maybe_unsized, @@ -725,7 +724,6 @@ fn layout_of_uncached<'tcx>( &variants, def.is_enum(), is_special_no_niche, - tcx.layout_scalar_valid_range(def.did()), discr_range_of_repr, discriminants_iter(), !maybe_unsized, diff --git a/compiler/rustc_ty_utils/src/layout/invariant.rs b/compiler/rustc_ty_utils/src/layout/invariant.rs index 03ac1674dbd50..a9edaa7371a88 100644 --- a/compiler/rustc_ty_utils/src/layout/invariant.rs +++ b/compiler/rustc_ty_utils/src/layout/invariant.rs @@ -1,8 +1,8 @@ use std::assert_matches; use rustc_abi::{BackendRepr, FieldsShape, Scalar, Size, TagEncoding, Variants}; -use rustc_middle::bug; use rustc_middle::ty::layout::{HasTyCtxt, LayoutCx, TyAndLayout}; +use rustc_middle::{bug, ty}; /// Enforce some basic invariants on layouts. pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) { @@ -52,6 +52,14 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou } fn skip_newtypes<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) -> TyAndLayout<'tcx> { + match *layout.ty.kind() { + ty::UnsafeBinder(bound_ty) => { + let ty = cx.tcx().instantiate_bound_regions_with_erased(bound_ty.into()); + return skip_newtypes(cx, &TyAndLayout { ty, ..*layout }); + } + _ => {} + } + if matches!(layout.layout.variants(), Variants::Multiple { .. }) { // Definitely not a newtype of anything. return *layout; diff --git a/library/std_detect/src/detect/arch/loongarch.rs b/library/std_detect/src/detect/arch/loongarch.rs index 6299627738111..2e021cb4352fe 100644 --- a/library/std_detect/src/detect/arch/loongarch.rs +++ b/library/std_detect/src/detect/arch/loongarch.rs @@ -35,19 +35,19 @@ features! { /// D @FEATURE: #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] frecipe: "frecipe"; /// Frecipe - @FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] div32: "div32"; + @FEATURE: #[stable(feature = "stdarch_loongarch_div32", since = "CURRENT_RUSTC_VERSION")] div32: "div32"; /// Div32 @FEATURE: #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] lsx: "lsx"; /// LSX @FEATURE: #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] lasx: "lasx"; /// LASX - @FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lam_bh: "lam-bh"; + @FEATURE: #[stable(feature = "stdarch_loongarch_lam_bh", since = "CURRENT_RUSTC_VERSION")] lam_bh: "lam-bh"; /// LAM-BH - @FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lamcas: "lamcas"; + @FEATURE: #[stable(feature = "stdarch_loongarch_lamcas", since = "CURRENT_RUSTC_VERSION")] lamcas: "lamcas"; /// LAM-CAS - @FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] ld_seq_sa: "ld-seq-sa"; + @FEATURE: #[stable(feature = "stdarch_loongarch_ld_seq_sa", since = "CURRENT_RUSTC_VERSION")] ld_seq_sa: "ld-seq-sa"; /// LD-SEQ-SA - @FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] scq: "scq"; + @FEATURE: #[stable(feature = "stdarch_loongarch_scq", since = "CURRENT_RUSTC_VERSION")] scq: "scq"; /// SCQ @FEATURE: #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] lbt: "lbt"; /// LBT diff --git a/src/ci/docker/scripts/rfl-build.sh b/src/ci/docker/scripts/rfl-build.sh index a959bc9da3ac5..54ede153f6153 100755 --- a/src/ci/docker/scripts/rfl-build.sh +++ b/src/ci/docker/scripts/rfl-build.sh @@ -2,7 +2,7 @@ set -euo pipefail -LINUX_VERSION=v7.0 +LINUX_VERSION=v7.1-rc1 # Build rustc, rustdoc, cargo, clippy-driver and rustfmt ../x.py build --stage 2 library rustdoc clippy rustfmt diff --git a/src/doc/rustc-dev-guide/src/unsafety-checking.md b/src/doc/rustc-dev-guide/src/unsafety-checking.md index ed05f8a4c865a..e4547634280e6 100644 --- a/src/doc/rustc-dev-guide/src/unsafety-checking.md +++ b/src/doc/rustc-dev-guide/src/unsafety-checking.md @@ -30,14 +30,8 @@ side of an assignment expression and allows union fields to directly appear there, while erroring in all other cases. Union field accesses can also occur in patterns, so those have to be walked as well. -The other complicated safety check is for writes to fields of layout constrained -structs (such as [`NonNull`]). These are found by looking for the borrow or -assignment expression and then visiting the subexpression being borrowed or -assigned with a separate visitor. - [THIR]: ./thir.md [`check_unsafety`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/check_unsafety/index.html -[`NonNull`]: https://doc.rust-lang.org/std/ptr/struct.NonNull.html ## The unused_unsafe lint diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 81e348f96e569..c59bd016b5e36 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2942,7 +2942,7 @@ fn clean_maybe_renamed_item<'tcx>( clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx) } // FIXME: rustdoc will need to handle `impl` restrictions at some point - ItemKind::Trait(_impl_restriction, _, _, _, _, generics, bounds, item_ids) => { + ItemKind::Trait { generics, bounds, items: item_ids, .. } => { let items = item_ids .iter() .map(|&ti| clean_trait_item(cx.tcx.hir_trait_item(ti), cx)) diff --git a/src/librustdoc/html/render/span_map.rs b/src/librustdoc/html/render/span_map.rs index 47cda92066282..ff214bad59f1d 100644 --- a/src/librustdoc/html/render/span_map.rs +++ b/src/librustdoc/html/render/span_map.rs @@ -349,7 +349,7 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> { | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) - | ItemKind::Trait(..) + | ItemKind::Trait { .. } | ItemKind::TraitAlias(..) => self.extract_info_from_hir_id(item.hir_id()), ItemKind::Impl(_) | ItemKind::Use(..) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index fda03563c79f2..8746253d6ebba 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -537,7 +537,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { | hir::ItemKind::Union(..) | hir::ItemKind::TyAlias(..) | hir::ItemKind::Static(..) - | hir::ItemKind::Trait(..) + | hir::ItemKind::Trait { .. } | hir::ItemKind::TraitAlias(..) => { self.add_to_current_mod(item, renamed, import_id); } @@ -607,7 +607,7 @@ impl<'tcx> Visitor<'tcx> for RustdocVisitor<'_, 'tcx> { hir::ItemKind::Mod(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::Impl(..) - | hir::ItemKind::Trait(..) + | hir::ItemKind::Trait { .. } ); let prev = mem::replace(&mut self.is_importable_from_parent, new_value); walk_item(self, i); diff --git a/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs b/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs index 4a6c024cac9a6..21cb3c5d0443c 100644 --- a/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs +++ b/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs @@ -306,16 +306,16 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering { cur_f = Some(field); } }, - ItemKind::Trait( - _impl_restriction, - _constness, + ItemKind::Trait { + impl_restriction:_, + constness:_, is_auto, - _safety, - _ident, - _generics, - _generic_bounds, - item_ref, - ) if self.enable_ordering_for_trait && *is_auto == IsAuto::No => { + safety:_, + ident:_, + generics: _, + bounds: _, + items: item_ref} + if self.enable_ordering_for_trait && *is_auto == IsAuto::No => { let mut cur_t: Option<(TraitItemId, Ident)> = None; for &item in *item_ref { @@ -510,7 +510,7 @@ fn convert_module_item_kind(value: &ItemKind<'_>) -> SourceItemOrderingModuleIte ItemKind::Enum(..) => Enum, ItemKind::Struct(..) => Struct, ItemKind::Union(..) => Union, - ItemKind::Trait(..) => Trait, + ItemKind::Trait { .. } => Trait, ItemKind::TraitAlias(..) => TraitAlias, ItemKind::Impl(..) => Impl, } diff --git a/src/tools/clippy/clippy_lints/src/doc/mod.rs b/src/tools/clippy/clippy_lints/src/doc/mod.rs index 81812880a743a..e772c20abf94d 100644 --- a/src/tools/clippy/clippy_lints/src/doc/mod.rs +++ b/src/tools/clippy/clippy_lints/src/doc/mod.rs @@ -769,7 +769,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { { missing_headers::check(cx, item.owner_id, sig, headers, Some(body), self.check_private_items); }, - ItemKind::Trait(_, _, _, unsafety, ..) => match (headers.safety, unsafety) { + ItemKind::Trait { safety, .. } => match (headers.safety, safety) { (false, Safety::Unsafe) => span_lint( cx, MISSING_SAFETY_DOC, diff --git a/src/tools/clippy/clippy_lints/src/doc/too_long_first_doc_paragraph.rs b/src/tools/clippy/clippy_lints/src/doc/too_long_first_doc_paragraph.rs index 674690e7e31d8..8ba6e9d332ba8 100644 --- a/src/tools/clippy/clippy_lints/src/doc/too_long_first_doc_paragraph.rs +++ b/src/tools/clippy/clippy_lints/src/doc/too_long_first_doc_paragraph.rs @@ -33,7 +33,7 @@ pub(super) fn check( | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) - | ItemKind::Trait(..) + | ItemKind::Trait { .. } | ItemKind::TraitAlias(..) ) { diff --git a/src/tools/clippy/clippy_lints/src/item_name_repetitions.rs b/src/tools/clippy/clippy_lints/src/item_name_repetitions.rs index 06bea4ba1ffd8..5ded0efacb815 100644 --- a/src/tools/clippy/clippy_lints/src/item_name_repetitions.rs +++ b/src/tools/clippy/clippy_lints/src/item_name_repetitions.rs @@ -528,7 +528,7 @@ impl LateLintPass<'_> for ItemNameRepetitions { | ItemKind::Fn { ident, .. } | ItemKind::Macro(ident, ..) | ItemKind::Static(_, ident, ..) - | ItemKind::Trait(_, _, _, _, ident, ..) + | ItemKind::Trait { ident, ..} | ItemKind::TraitAlias(_, ident, ..) | ItemKind::TyAlias(ident, ..) | ItemKind::Union(ident, ..) diff --git a/src/tools/clippy/clippy_lints/src/len_without_is_empty.rs b/src/tools/clippy/clippy_lints/src/len_without_is_empty.rs index 1f019531f602b..9bf06dbf452d6 100644 --- a/src/tools/clippy/clippy_lints/src/len_without_is_empty.rs +++ b/src/tools/clippy/clippy_lints/src/len_without_is_empty.rs @@ -44,7 +44,7 @@ declare_lint_pass!(LenWithoutIsEmpty => [LEN_WITHOUT_IS_EMPTY]); impl<'tcx> LateLintPass<'tcx> for LenWithoutIsEmpty { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Trait(_, _, _, _, ident, _, _, trait_items) = item.kind + if let ItemKind::Trait { ident, items: trait_items, .. } = item.kind && !item.span.from_expansion() { check_trait_items(cx, item, ident, trait_items); diff --git a/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs b/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs index 0839219c5b613..b9378d2cdd8cc 100644 --- a/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs +++ b/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs @@ -141,7 +141,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { let parent = cx.tcx.hir_get_parent_item(hir_id).def_id; if parent != CRATE_DEF_ID && let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(parent) - && let hir::ItemKind::Trait(..) = &item.kind + && let hir::ItemKind::Trait { .. } = &item.kind { return; } diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index 35e75d34a5d3a..694a473ff5a97 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { | ItemKind::Macro(ident, ..) | ItemKind::Static(_, ident, ..) | ItemKind::Struct(ident, ..) - | ItemKind::Trait(_, _, _, _, ident, ..) + | ItemKind::Trait { ident, .. } | ItemKind::TraitAlias(_, ident, ..) | ItemKind::TyAlias(ident, ..) | ItemKind::Union(ident, ..) => ident.span, diff --git a/src/tools/clippy/clippy_lints/src/missing_inline.rs b/src/tools/clippy/clippy_lints/src/missing_inline.rs index 16dae67c29865..93cfed38c43ed 100644 --- a/src/tools/clippy/clippy_lints/src/missing_inline.rs +++ b/src/tools/clippy/clippy_lints/src/missing_inline.rs @@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { let attrs = cx.tcx.hir_attrs(it.hir_id()); check_missing_inline_attrs(cx, attrs, it.span, desc, None); }, - hir::ItemKind::Trait(.., trait_items) => { + hir::ItemKind::Trait { items: trait_items, .. } => { // note: we need to check if the trait is exported so we can't use // `LateLintPass::check_trait_item` here. for &tit in trait_items { diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs index 74a37077b0a1d..91358ef77fa1e 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -167,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) && matches!( item.kind, - ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait { .. } ) { return; diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index 593eff6a9bbd1..4ff5b0b0b3c39 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) && matches!( item.kind, - ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait { .. } ) { return; diff --git a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs index b4a1713222123..6b81b9d117a37 100644 --- a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs +++ b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs @@ -292,7 +292,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) && matches!( item.kind, - ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait { .. } ) { return; diff --git a/src/tools/clippy/clippy_lints/src/trait_bounds.rs b/src/tools/clippy/clippy_lints/src/trait_bounds.rs index 4cd3707854c48..e4faf8e82a8e6 100644 --- a/src/tools/clippy/clippy_lints/src/trait_bounds.rs +++ b/src/tools/clippy/clippy_lints/src/trait_bounds.rs @@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { // special handling for self trait bounds as these are not considered generics // i.e. trait Foo: Display {} if let Item { - kind: ItemKind::Trait(_, _, _, _, _, _, bounds, ..), + kind: ItemKind::Trait { bounds, .. }, .. } = item { @@ -136,7 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { .. }) = segments.first() && let Some(Node::Item(Item { - kind: ItemKind::Trait(_, _, _, _, _, _, self_bounds, _), + kind: ItemKind::Trait {bounds: self_bounds,..}, .. })) = cx.tcx.hir_get_if_local(*def_id) { diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs b/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs index 17e05db644b06..cecffaae69704 100644 --- a/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs +++ b/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs @@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) && matches!( item.kind, - ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait { .. } ) { return; diff --git a/src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs b/src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs index 52dfcab363dbd..0b95468436127 100644 --- a/src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs +++ b/src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs @@ -131,7 +131,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms { return; } match it.kind { - ItemKind::TyAlias(ident, ..) | ItemKind::Struct(ident, ..) | ItemKind::Trait(_, _, _, _, ident, ..) => { + ItemKind::TyAlias(ident, ..) | ItemKind::Struct(ident, ..) | ItemKind::Trait { ident, .. }=> { check_ident(cx, &ident, it.hir_id(), self.upper_case_acronyms_aggressive); }, ItemKind::Enum(ident, _, ref enumdef) => { diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index 44b9084cd4f69..e1382f5b706c0 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -265,15 +265,15 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) { ItemKind::Struct(_, _, VariantData::Struct { .. }) => (Pat::Str("struct"), Pat::Str("}")), ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")), ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")), - ItemKind::Trait(_, _, _, Safety::Unsafe, ..) + ItemKind::Trait { safety: Safety::Unsafe, .. } | ItemKind::Impl(Impl { of_trait: Some(TraitImplHeader { safety: Safety::Unsafe, .. }), .. }) => (Pat::Str("unsafe"), Pat::Str("}")), - ItemKind::Trait(_, _, IsAuto::Yes, ..) => (Pat::Str("auto"), Pat::Str("}")), - ItemKind::Trait(..) => (Pat::Str("trait"), Pat::Str("}")), + ItemKind::Trait { is_auto: IsAuto::Yes, .. } => (Pat::Str("auto"), Pat::Str("}")), + ItemKind::Trait { .. } => (Pat::Str("trait"), Pat::Str("}")), ItemKind::Impl(_) => (Pat::Str("impl"), Pat::Str("}")), ItemKind::Mod(..) => (Pat::Str("mod"), Pat::Str("")), ItemKind::Macro(_, def, _) => ( diff --git a/src/tools/clippy/clippy_utils/src/paths.rs b/src/tools/clippy/clippy_utils/src/paths.rs index c5fd66eeb93cd..f27c92f0d4921 100644 --- a/src/tools/clippy/clippy_utils/src/paths.rs +++ b/src/tools/clippy/clippy_utils/src/paths.rs @@ -332,7 +332,7 @@ fn local_item_child_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, ns: PathNS, n None } }), - ItemKind::Impl(..) | ItemKind::Trait(..) => tcx + ItemKind::Impl(..) | ItemKind::Trait { .. } => tcx .associated_items(local_id) .filter_by_name_unhygienic(name) .find(|assoc_item| ns.matches(Some(assoc_item.namespace()))) diff --git a/src/tools/clippy/tests/ui/eager_transmute.fixed b/src/tools/clippy/tests/ui/eager_transmute.fixed index 47a32ec836cc9..dbb3fdee43ad1 100644 --- a/src/tools/clippy/tests/ui/eager_transmute.fixed +++ b/src/tools/clippy/tests/ui/eager_transmute.fixed @@ -1,8 +1,9 @@ -#![feature(rustc_attrs)] +#![feature(rustc_attrs, pattern_types, pattern_type_macro)] #![warn(clippy::eager_transmute)] #![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)] use std::num::NonZero; +use std::pat::pattern_type; #[repr(u8)] enum Opcode { @@ -77,23 +78,25 @@ unsafe fn f2(op: u8) { } } -#[rustc_layout_scalar_valid_range_end(254)] -struct NonMaxU8(u8); -#[rustc_layout_scalar_valid_range_end(254)] -#[rustc_layout_scalar_valid_range_start(1)] -struct NonZeroNonMaxU8(u8); +struct NonMaxU8(pattern_type!(u8 is 0..=254)); +struct NonZeroNonMaxU8(pattern_type!(u8 is 1..=254)); macro_rules! impls { ($($t:ty),*) => { $( + impl $t { + fn get(&self) -> u8 { + unsafe { std::mem::transmute(self.0) } + } + } impl PartialEq for $t { fn eq(&self, other: &u8) -> bool { - self.0 == *other + self.get() == *other } } impl PartialOrd for $t { fn partial_cmp(&self, other: &u8) -> Option { - self.0.partial_cmp(other) + self.get().partial_cmp(other) } } )* diff --git a/src/tools/clippy/tests/ui/eager_transmute.rs b/src/tools/clippy/tests/ui/eager_transmute.rs index 906cd7bccc86f..d44c501467cd7 100644 --- a/src/tools/clippy/tests/ui/eager_transmute.rs +++ b/src/tools/clippy/tests/ui/eager_transmute.rs @@ -1,8 +1,9 @@ -#![feature(rustc_attrs)] +#![feature(rustc_attrs, pattern_types, pattern_type_macro)] #![warn(clippy::eager_transmute)] #![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)] use std::num::NonZero; +use std::pat::pattern_type; #[repr(u8)] enum Opcode { @@ -77,23 +78,25 @@ unsafe fn f2(op: u8) { } } -#[rustc_layout_scalar_valid_range_end(254)] -struct NonMaxU8(u8); -#[rustc_layout_scalar_valid_range_end(254)] -#[rustc_layout_scalar_valid_range_start(1)] -struct NonZeroNonMaxU8(u8); +struct NonMaxU8(pattern_type!(u8 is 0..=254)); +struct NonZeroNonMaxU8(pattern_type!(u8 is 1..=254)); macro_rules! impls { ($($t:ty),*) => { $( + impl $t { + fn get(&self) -> u8 { + unsafe { std::mem::transmute(self.0) } + } + } impl PartialEq for $t { fn eq(&self, other: &u8) -> bool { - self.0 == *other + self.get() == *other } } impl PartialOrd for $t { fn partial_cmp(&self, other: &u8) -> Option { - self.0.partial_cmp(other) + self.get().partial_cmp(other) } } )* diff --git a/src/tools/clippy/tests/ui/eager_transmute.stderr b/src/tools/clippy/tests/ui/eager_transmute.stderr index c719ca8adc12e..847d05cc5432f 100644 --- a/src/tools/clippy/tests/ui/eager_transmute.stderr +++ b/src/tools/clippy/tests/ui/eager_transmute.stderr @@ -1,5 +1,5 @@ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:21:33 + --> tests/ui/eager_transmute.rs:22:33 | LL | (op < 4).then_some(unsafe { std::mem::transmute(op) }) | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + (op < 4).then(|| unsafe { std::mem::transmute(op) }) | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:28:33 + --> tests/ui/eager_transmute.rs:29:33 | LL | (op < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + (op < 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:30:33 + --> tests/ui/eager_transmute.rs:31:33 | LL | (op > 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + (op > 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:32:34 + --> tests/ui/eager_transmute.rs:33:34 | LL | (op == 0).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + (op == 0).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:35:68 + --> tests/ui/eager_transmute.rs:36:68 | LL | let _: Option = (op > 0 && op < 10).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + let _: Option = (op > 0 && op < 10).then(|| unsafe { std::mem:: | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:37:86 + --> tests/ui/eager_transmute.rs:38:86 | LL | let _: Option = (op > 0 && op < 10 && unrelated == 0).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + let _: Option = (op > 0 && op < 10 && unrelated == 0).then(|| u | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:41:84 + --> tests/ui/eager_transmute.rs:42:84 | LL | let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[0]) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then(|| uns | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:54:70 + --> tests/ui/eager_transmute.rs:55:70 | LL | let _: Option = (1..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + let _: Option = (1..=3).contains(&op).then(|| unsafe { std::mem | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:56:83 + --> tests/ui/eager_transmute.rs:57:83 | LL | let _: Option = ((1..=3).contains(&op) || op == 4).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + let _: Option = ((1..=3).contains(&op) || op == 4).then(|| unsa | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:58:69 + --> tests/ui/eager_transmute.rs:59:69 | LL | let _: Option = (1..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + let _: Option = (1..3).contains(&op).then(|| unsafe { std::mem: | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:60:68 + --> tests/ui/eager_transmute.rs:61:68 | LL | let _: Option = (1..).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + let _: Option = (1..).contains(&op).then(|| unsafe { std::mem:: | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:62:68 + --> tests/ui/eager_transmute.rs:63:68 | LL | let _: Option = (..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + let _: Option = (..3).contains(&op).then(|| unsafe { std::mem:: | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:64:69 + --> tests/ui/eager_transmute.rs:65:69 | LL | let _: Option = (..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + let _: Option = (..=3).contains(&op).then(|| unsafe { std::mem: | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:75:28 + --> tests/ui/eager_transmute.rs:76:28 | LL | (op < 4).then_some(std::mem::transmute::<_, Opcode>(op)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + (op < 4).then(|| std::mem::transmute::<_, Opcode>(op)); | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:106:62 + --> tests/ui/eager_transmute.rs:109:62 | LL | let _: Option> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + let _: Option> = (v1 > 0).then(|| unsafe { std::mem::transm | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:113:86 + --> tests/ui/eager_transmute.rs:116:86 | LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| u | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:120:93 + --> tests/ui/eager_transmute.rs:123:93 | LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/miri/tests/fail/validity/nonzero.rs b/src/tools/miri/tests/fail/validity/nonzero.rs index 7cba90bc15d13..fba37ee170e3a 100644 --- a/src/tools/miri/tests/fail/validity/nonzero.rs +++ b/src/tools/miri/tests/fail/validity/nonzero.rs @@ -1,11 +1,10 @@ -#![feature(rustc_attrs)] +#![feature(rustc_attrs, pattern_types, pattern_type_macro)] #![allow(unused_attributes)] -#[rustc_layout_scalar_valid_range_start(1)] #[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); +struct NonZero(std::pat::pattern_type!(u32 is 1..=u32::MAX)); fn main() { // Make sure that we detect this even when no function call is happening along the way - let _x = Some(unsafe { NonZero(0) }); //~ ERROR: encountered 0, but expected something greater or equal to 1 + let _x = Some(unsafe { NonZero(std::mem::transmute(0_u32)) }); //~ ERROR: encountered 0, but expected something greater or equal to 1 } diff --git a/src/tools/miri/tests/fail/validity/nonzero.stderr b/src/tools/miri/tests/fail/validity/nonzero.stderr index 2b352400b6e81..08647f18fb422 100644 --- a/src/tools/miri/tests/fail/validity/nonzero.stderr +++ b/src/tools/miri/tests/fail/validity/nonzero.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: constructing invalid value of type NonZero: encountered 0, but expected something greater or equal to 1 +error: Undefined Behavior: constructing invalid value of type (u32) is 1..: encountered 0, but expected something greater or equal to 1 --> tests/fail/validity/nonzero.rs:LL:CC | -LL | let _x = Some(unsafe { NonZero(0) }); - | ^^^^^^^^^^ Undefined Behavior occurred here +LL | let _x = Some(unsafe { NonZero(std::mem::transmute(0_u32)) }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/tests/codegen-llvm/function-arguments.rs b/tests/codegen-llvm/function-arguments.rs index 80e6ac7bb0f03..667e4f79df8c5 100644 --- a/tests/codegen-llvm/function-arguments.rs +++ b/tests/codegen-llvm/function-arguments.rs @@ -151,21 +151,6 @@ pub fn option_borrow(_x: Option<&i32>) {} #[no_mangle] pub fn option_borrow_mut(_x: Option<&mut i32>) {} -// Function that must NOT have `dereferenceable` or `align`. -#[rustc_layout_scalar_valid_range_start(16)] -pub struct RestrictedAddress(&'static i16); -enum E { - A(RestrictedAddress), - B, - C, -} -// If the `nonnull` ever goes missing, you might have to tweak the -// scalar_valid_range on `RestrictedAddress` to get it back. You -// might even have to add a `rustc_layout_scalar_valid_range_end`. -// CHECK: @nonnull_and_nondereferenceable(ptr noundef nonnull %_x) -#[no_mangle] -pub fn nonnull_and_nondereferenceable(_x: E) {} - // CHECK: @raw_struct(ptr noundef %_1) #[no_mangle] pub fn raw_struct(_: *const S) {} diff --git a/tests/crashes/122681.rs b/tests/crashes/122681.rs deleted file mode 100644 index 7dae276950e1d..0000000000000 --- a/tests/crashes/122681.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ known-bug: #122681 -#[rustc_layout_scalar_valid_range_start(1)] -struct UnitStruct; - -#[derive(Default)] -enum SomeEnum { - #[default] - Unit, - Tuple(UnitStruct), -} diff --git a/tests/debuginfo/msvc-pretty-enums.rs b/tests/debuginfo/msvc-pretty-enums.rs index de5dfef004a6e..363db99f83390 100644 --- a/tests/debuginfo/msvc-pretty-enums.rs +++ b/tests/debuginfo/msvc-pretty-enums.rs @@ -270,10 +270,10 @@ enum NicheLayoutWithFields3 { F, } -#[rustc_layout_scalar_valid_range_start(340282366920938463463374607431768211454)] -#[rustc_layout_scalar_valid_range_end(1)] #[repr(transparent)] -struct Wrapping128(u128); +struct Wrapping128( + pattern_type!(u128 is 340282366920938463463374607431768211454..=u128::MAX | 0..=1), +); enum Wrapping128Niche { X(Wrapping128), @@ -325,8 +325,11 @@ fn main() { let niche128_some = NonZero::new(123456i128); let niche128_none: Option> = None; - let wrapping_niche128_untagged = - unsafe { Wrapping128Niche::X(Wrapping128(340282366920938463463374607431768211454)) }; + let wrapping_niche128_untagged = unsafe { + Wrapping128Niche::X(Wrapping128(unsafe { + std::mem::transmute(340282366920938463463374607431768211454) + })) + }; let wrapping_niche128_none1 = Wrapping128Niche::Y; let wrapping_niche128_none2 = Wrapping128Niche::Z; diff --git a/tests/incremental/issue-59524-layout-scalar-valid-range-is-not-unused.rs b/tests/incremental/issue-59524-layout-scalar-valid-range-is-not-unused.rs deleted file mode 100644 index 3a2e6cf9f02aa..0000000000000 --- a/tests/incremental/issue-59524-layout-scalar-valid-range-is-not-unused.rs +++ /dev/null @@ -1,20 +0,0 @@ -// We should not see the unused_attributes lint fire for -// rustc_layout_scalar_valid_range_start, but with this bug we are -// seeing it fire (on subsequent runs) if incremental compilation is -// enabled. - -//@ revisions: bpass1 bpass2 -//@ ignore-backends: gcc -// FIXME(#62277): could be check-pass? - -#![feature(rustc_attrs)] -#![deny(unused_attributes)] - -#[rustc_layout_scalar_valid_range_start(10)] -#[rustc_layout_scalar_valid_range_end(30)] -struct RestrictedRange(u32); -const OKAY_RANGE: RestrictedRange = unsafe { RestrictedRange(20) }; - -fn main() { - OKAY_RANGE.0; -} diff --git a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.32bit.diff index e2cd73404bec3..f1aae54c12d60 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.32bit.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.32bit.diff @@ -4,13 +4,17 @@ fn mutate_discriminant() -> u8 { let mut _0: u8; let mut _1: std::option::Option; - let mut _2: isize; + let mut _2: (usize) is 1..; + let mut _3: isize; bb0: { discriminant(_1) = 1; - (((_1 as variant#1).0: NonZeroUsize).0: usize) = const 0_usize; - _2 = discriminant(_1); - switchInt(copy _2) -> [0: bb1, otherwise: bb2]; +- _2 = const 0_usize as (usize) is 1.. (Transmute); +- (((_1 as variant#1).0: NonZeroUsize).0: (usize) is 1..=usize::MAX) = copy _2; ++ _2 = const {transmute(0x00000000): (usize) is 1..}; ++ (((_1 as variant#1).0: NonZeroUsize).0: (usize) is 1..=usize::MAX) = const {transmute(0x00000000): (usize) is 1..=usize::MAX}; + _3 = discriminant(_1); + switchInt(copy _3) -> [0: bb1, otherwise: bb2]; } bb1: { diff --git a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff index e2cd73404bec3..382f81722cd91 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff @@ -4,13 +4,17 @@ fn mutate_discriminant() -> u8 { let mut _0: u8; let mut _1: std::option::Option; - let mut _2: isize; + let mut _2: (usize) is 1..; + let mut _3: isize; bb0: { discriminant(_1) = 1; - (((_1 as variant#1).0: NonZeroUsize).0: usize) = const 0_usize; - _2 = discriminant(_1); - switchInt(copy _2) -> [0: bb1, otherwise: bb2]; +- _2 = const 0_usize as (usize) is 1.. (Transmute); +- (((_1 as variant#1).0: NonZeroUsize).0: (usize) is 1..=usize::MAX) = copy _2; ++ _2 = const {transmute(0x0000000000000000): (usize) is 1..}; ++ (((_1 as variant#1).0: NonZeroUsize).0: (usize) is 1..=usize::MAX) = const {transmute(0x0000000000000000): (usize) is 1..=usize::MAX}; + _3 = discriminant(_1); + switchInt(copy _3) -> [0: bb1, otherwise: bb2]; } bb1: { diff --git a/tests/mir-opt/dataflow-const-prop/enum.rs b/tests/mir-opt/dataflow-const-prop/enum.rs index 207e29e63df9e..80553a3974881 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.rs +++ b/tests/mir-opt/dataflow-const-prop/enum.rs @@ -2,7 +2,7 @@ //@ compile-flags: -Zdump-mir-exclude-alloc-bytes // EMIT_MIR_FOR_EACH_BIT_WIDTH -#![feature(custom_mir, core_intrinsics, rustc_attrs)] +#![feature(custom_mir, core_intrinsics, rustc_attrs, pattern_types, pattern_type_macro)] use std::intrinsics::mir::*; @@ -72,7 +72,7 @@ fn statics() { static RC: &E = &E::V2(4); - // CHECK: [[t:_.*]] = const {alloc5: &&E}; + // CHECK: [[t:_.*]] = const {alloc7: &&E}; // CHECK: [[e2]] = copy (*[[t]]); let e2 = RC; @@ -88,9 +88,8 @@ fn statics() { }; } -#[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] -struct NonZeroUsize(usize); +struct NonZeroUsize(std::pat::pattern_type!(usize is 1..=usize::MAX)); // EMIT_MIR enum.mutate_discriminant.DataflowConstProp.diff @@ -101,8 +100,9 @@ fn mutate_discriminant() -> u8 { let x: Option; { SetDiscriminant(x, 1); + let y = CastTransmute::<_, std::pat::pattern_type!(usize is 1..=usize::MAX)>(0_usize); // This assignment overwrites the niche in which the discriminant is stored. - place!(Field(Field(Variant(x, 1), 0), 0)) = 0_usize; + place!(Field(Field(Variant(x, 1), 0), 0)) = y; // So we cannot know the value of this discriminant. // CHECK: [[a:_.*]] = discriminant({{_.*}}); diff --git a/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-abort.diff b/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-abort.diff index 9f8a839eee9a0..c525a94342598 100644 --- a/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-abort.diff @@ -6,79 +6,81 @@ debug thin => _2; let mut _0: (); let _3: MyId; - let mut _4: u16; - let _5: (); - let mut _6: u16; - let mut _7: MyId; - let mut _9: u16; - let mut _10: std::marker::PhantomData; - let _11: (); - let mut _12: u16; - let mut _13: TypedId; - let mut _15: u16; - let _16: (); - let mut _17: u16; - let mut _18: std::result::Result; - let mut _20: u16; - let _21: (); - let mut _22: u32; - let mut _23: std::option::Option; - let mut _25: u16; - let _26: (); - let mut _27: i16; - let mut _28: MyId; - let mut _30: u16; - let mut _31: u16; - let _32: (); - let mut _33: u32; - let mut _34: aggregate_struct_then_transmute::Pair; - let mut _36: u16; - let mut _37: u16; - let _38: (); + let mut _4: (u16) is 0..=55554; + let mut _5: u16; + let _6: (); + let mut _7: u16; + let mut _8: MyId; + let mut _10: u16; + let mut _11: std::marker::PhantomData; + let _12: (); + let mut _13: u16; + let mut _14: TypedId; + let mut _16: u16; + let _17: (); + let mut _18: u16; + let mut _19: std::result::Result; + let mut _21: u16; + let _22: (); + let mut _23: u32; + let mut _24: std::option::Option; + let mut _26: (u16) is 0..=55554; + let mut _27: u16; + let _28: (); + let mut _29: i16; + let mut _30: MyId; + let mut _32: u16; + let mut _33: u16; + let _34: (); + let mut _35: u32; + let mut _36: aggregate_struct_then_transmute::Pair; + let mut _38: u16; let mut _39: u16; - let mut _40: aggregate_struct_then_transmute::Pair; - let mut _42: u16; - let _43: (); + let _40: (); + let mut _41: u16; + let mut _42: aggregate_struct_then_transmute::Pair; let mut _44: u16; - let mut _45: (u16,); - let mut _47: u16; - let _48: (); + let _45: (); + let mut _46: u16; + let mut _47: (u16,); let mut _49: u16; - let mut _50: [u16; 1]; - let mut _52: *const u8; - let mut _53: (); - let _54: (); - let mut _55: *const u8; - let mut _56: *const i32; + let _50: (); + let mut _51: u16; + let mut _52: [u16; 1]; + let mut _54: *const u8; + let mut _55: (); + let _56: (); + let mut _57: *const u8; + let mut _58: *const i32; scope 1 { debug a => _3; - let _8: TypedId; + let _9: TypedId; scope 2 { - debug b => _8; - let _14: std::result::Result; + debug b => _9; + let _15: std::result::Result; scope 3 { - debug c => _14; - let _19: std::option::Option; + debug c => _15; + let _20: std::option::Option; scope 4 { - debug d => _19; - let _24: MyId; + debug d => _20; + let _25: MyId; scope 5 { - debug e => _24; - let _29: aggregate_struct_then_transmute::Pair; + debug e => _25; + let _31: aggregate_struct_then_transmute::Pair; scope 6 { - debug f => _29; - let _35: aggregate_struct_then_transmute::Pair; + debug f => _31; + let _37: aggregate_struct_then_transmute::Pair; scope 7 { - debug g => _35; - let _41: (u16,); + debug g => _37; + let _43: (u16,); scope 8 { - debug h => _41; - let _46: [u16; 1]; + debug h => _43; + let _48: [u16; 1]; scope 9 { - debug i => _46; - let _51: *const i32; + debug i => _48; + let _53: *const i32; scope 10 { - debug j => _51; + debug j => _53; } } } @@ -92,231 +94,240 @@ bb0: { StorageLive(_3); - StorageLive(_4); - _4 = copy _1; -- _3 = MyId(move _4); -+ _3 = MyId(copy _1); - StorageDead(_4); +- StorageLive(_4); ++ nop; StorageLive(_5); + _5 = copy _1; +- _4 = move _5 as (u16) is 0..=55554 (Transmute); ++ _4 = copy _1 as (u16) is 0..=55554 (Transmute); + StorageDead(_5); +- _3 = MyId(move _4); +- StorageDead(_4); ++ _3 = MyId(copy _4); ++ nop; StorageLive(_6); StorageLive(_7); -- _7 = move _3; -- _6 = move _7 as u16 (Transmute); -+ _7 = copy _3; -+ _6 = copy _1; - StorageDead(_7); -- _5 = opaque::(move _6) -> [return: bb1, unwind unreachable]; -+ _5 = opaque::(copy _1) -> [return: bb1, unwind unreachable]; + StorageLive(_8); +- _8 = move _3; +- _7 = move _8 as u16 (Transmute); ++ _8 = copy _3; ++ _7 = copy _4 as u16 (Transmute); + StorageDead(_8); + _6 = opaque::(move _7) -> [return: bb1, unwind unreachable]; } bb1: { + StorageDead(_7); StorageDead(_6); - StorageDead(_5); - StorageLive(_8); StorageLive(_9); - _9 = copy _1; StorageLive(_10); -- _10 = PhantomData::; -- _8 = TypedId::(move _9, move _10); -+ _10 = const PhantomData::; -+ _8 = TypedId::(copy _1, const PhantomData::); - StorageDead(_10); - StorageDead(_9); + _10 = copy _1; StorageLive(_11); +- _11 = PhantomData::; +- _9 = TypedId::(move _10, move _11); ++ _11 = const PhantomData::; ++ _9 = TypedId::(copy _1, const PhantomData::); + StorageDead(_11); + StorageDead(_10); StorageLive(_12); StorageLive(_13); -- _13 = move _8; -- _12 = move _13 as u16 (Transmute); -+ _13 = copy _8; -+ _12 = copy _1; - StorageDead(_13); -- _11 = opaque::(move _12) -> [return: bb2, unwind unreachable]; -+ _11 = opaque::(copy _1) -> [return: bb2, unwind unreachable]; + StorageLive(_14); +- _14 = move _9; +- _13 = move _14 as u16 (Transmute); ++ _14 = copy _9; ++ _13 = copy _1; + StorageDead(_14); +- _12 = opaque::(move _13) -> [return: bb2, unwind unreachable]; ++ _12 = opaque::(copy _1) -> [return: bb2, unwind unreachable]; } bb2: { + StorageDead(_13); StorageDead(_12); - StorageDead(_11); - StorageLive(_14); StorageLive(_15); - _15 = copy _1; -- _14 = Result::::Err(move _15); -+ _14 = Result::::Err(copy _1); - StorageDead(_15); StorageLive(_16); + _16 = copy _1; +- _15 = Result::::Err(move _16); ++ _15 = Result::::Err(copy _1); + StorageDead(_16); StorageLive(_17); StorageLive(_18); -- _18 = move _14; -- _17 = move _18 as u16 (Transmute); -+ _18 = copy _14; -+ _17 = copy _1; - StorageDead(_18); -- _16 = opaque::(move _17) -> [return: bb3, unwind unreachable]; -+ _16 = opaque::(copy _1) -> [return: bb3, unwind unreachable]; + StorageLive(_19); +- _19 = move _15; +- _18 = move _19 as u16 (Transmute); ++ _19 = copy _15; ++ _18 = copy _1; + StorageDead(_19); +- _17 = opaque::(move _18) -> [return: bb3, unwind unreachable]; ++ _17 = opaque::(copy _1) -> [return: bb3, unwind unreachable]; } bb3: { + StorageDead(_18); StorageDead(_17); - StorageDead(_16); - StorageLive(_19); StorageLive(_20); - _20 = copy _1; -- _19 = Option::::Some(move _20); -+ _19 = Option::::Some(copy _1); - StorageDead(_20); StorageLive(_21); + _21 = copy _1; +- _20 = Option::::Some(move _21); ++ _20 = Option::::Some(copy _1); + StorageDead(_21); StorageLive(_22); StorageLive(_23); - _23 = copy _19; -- _22 = move _23 as u32 (Transmute); -+ _22 = copy _19 as u32 (Transmute); - StorageDead(_23); - _21 = opaque::(move _22) -> [return: bb4, unwind unreachable]; + StorageLive(_24); + _24 = copy _20; +- _23 = move _24 as u32 (Transmute); ++ _23 = copy _20 as u32 (Transmute); + StorageDead(_24); + _22 = opaque::(move _23) -> [return: bb4, unwind unreachable]; } bb4: { + StorageDead(_23); StorageDead(_22); - StorageDead(_21); - StorageLive(_24); StorageLive(_25); - _25 = copy _1; -- _24 = MyId(move _25); -+ _24 = copy _3; - StorageDead(_25); StorageLive(_26); StorageLive(_27); - StorageLive(_28); -- _28 = move _24; -- _27 = move _28 as i16 (Transmute); -+ _28 = copy _3; -+ _27 = copy _1 as i16 (Transmute); - StorageDead(_28); - _26 = opaque::(move _27) -> [return: bb5, unwind unreachable]; - } - - bb5: { + _27 = copy _1; +- _26 = move _27 as (u16) is 0..=55554 (Transmute); ++ _26 = copy _4; StorageDead(_27); +- _25 = MyId(move _26); ++ _25 = copy _3; StorageDead(_26); + StorageLive(_28); StorageLive(_29); StorageLive(_30); - _30 = copy _1; - StorageLive(_31); - _31 = copy _1; -- _29 = Pair(move _30, move _31); -+ _29 = Pair(copy _1, copy _1); - StorageDead(_31); +- _30 = move _25; +- _29 = move _30 as i16 (Transmute); ++ _30 = copy _3; ++ _29 = copy _4 as i16 (Transmute); StorageDead(_30); - StorageLive(_32); - StorageLive(_33); - StorageLive(_34); -- _34 = move _29; -- _33 = move _34 as u32 (Transmute); -+ _34 = copy _29; -+ _33 = copy _29 as u32 (Transmute); - StorageDead(_34); - _32 = opaque::(move _33) -> [return: bb6, unwind unreachable]; + _28 = opaque::(move _29) -> [return: bb5, unwind unreachable]; } - bb6: { + bb5: { + StorageDead(_29); + StorageDead(_28); + StorageLive(_31); + StorageLive(_32); + _32 = copy _1; + StorageLive(_33); + _33 = copy _1; +- _31 = Pair(move _32, move _33); ++ _31 = Pair(copy _1, copy _1); StorageDead(_33); StorageDead(_32); + StorageLive(_34); StorageLive(_35); StorageLive(_36); - _36 = copy _1; - StorageLive(_37); - _37 = copy _1; -- _35 = Pair(move _36, move _37); -+ _35 = copy _29; - StorageDead(_37); +- _36 = move _31; +- _35 = move _36 as u32 (Transmute); ++ _36 = copy _31; ++ _35 = copy _31 as u32 (Transmute); StorageDead(_36); - StorageLive(_38); - StorageLive(_39); - StorageLive(_40); -- _40 = move _35; -- _39 = move _40 as u16 (Transmute); -+ _40 = copy _29; -+ _39 = copy _29 as u16 (Transmute); - StorageDead(_40); - _38 = opaque::(move _39) -> [return: bb7, unwind unreachable]; + _34 = opaque::(move _35) -> [return: bb6, unwind unreachable]; } - bb7: { + bb6: { + StorageDead(_35); + StorageDead(_34); + StorageLive(_37); + StorageLive(_38); + _38 = copy _1; + StorageLive(_39); + _39 = copy _1; +- _37 = Pair(move _38, move _39); ++ _37 = copy _31; StorageDead(_39); StorageDead(_38); + StorageLive(_40); StorageLive(_41); StorageLive(_42); - _42 = copy _1; -- _41 = (move _42,); -+ _41 = (copy _1,); +- _42 = move _37; +- _41 = move _42 as u16 (Transmute); ++ _42 = copy _31; ++ _41 = copy _31 as u16 (Transmute); StorageDead(_42); - StorageLive(_43); - StorageLive(_44); - StorageLive(_45); - _45 = copy _41; -- _44 = move _45 as u16 (Transmute); -+ _44 = copy _1; - StorageDead(_45); -- _43 = opaque::(move _44) -> [return: bb8, unwind unreachable]; -+ _43 = opaque::(copy _1) -> [return: bb8, unwind unreachable]; + _40 = opaque::(move _41) -> [return: bb7, unwind unreachable]; } - bb8: { + bb7: { + StorageDead(_41); + StorageDead(_40); + StorageLive(_43); + StorageLive(_44); + _44 = copy _1; +- _43 = (move _44,); ++ _43 = (copy _1,); StorageDead(_44); - StorageDead(_43); + StorageLive(_45); StorageLive(_46); StorageLive(_47); - _47 = copy _1; -- _46 = [move _47]; -+ _46 = [copy _1]; + _47 = copy _43; +- _46 = move _47 as u16 (Transmute); ++ _46 = copy _1; StorageDead(_47); +- _45 = opaque::(move _46) -> [return: bb8, unwind unreachable]; ++ _45 = opaque::(copy _1) -> [return: bb8, unwind unreachable]; + } + + bb8: { + StorageDead(_46); + StorageDead(_45); StorageLive(_48); StorageLive(_49); + _49 = copy _1; +- _48 = [move _49]; ++ _48 = [copy _1]; + StorageDead(_49); StorageLive(_50); - _50 = copy _46; -- _49 = move _50 as u16 (Transmute); -+ _49 = copy _1; - StorageDead(_50); -- _48 = opaque::(move _49) -> [return: bb9, unwind unreachable]; -+ _48 = opaque::(copy _1) -> [return: bb9, unwind unreachable]; + StorageLive(_51); + StorageLive(_52); + _52 = copy _48; +- _51 = move _52 as u16 (Transmute); ++ _51 = copy _1; + StorageDead(_52); +- _50 = opaque::(move _51) -> [return: bb9, unwind unreachable]; ++ _50 = opaque::(copy _1) -> [return: bb9, unwind unreachable]; } bb9: { - StorageDead(_49); - StorageDead(_48); - StorageLive(_51); - StorageLive(_52); - _52 = copy _2; + StorageDead(_51); + StorageDead(_50); StorageLive(_53); -- _53 = (); -- _51 = *const i32 from (move _52, move _53); -+ _53 = const (); -+ _51 = *const i32 from (copy _2, const ()); - StorageDead(_53); - StorageDead(_52); StorageLive(_54); + _54 = copy _2; StorageLive(_55); +- _55 = (); +- _53 = *const i32 from (move _54, move _55); ++ _55 = const (); ++ _53 = *const i32 from (copy _2, const ()); + StorageDead(_55); + StorageDead(_54); StorageLive(_56); - _56 = copy _51; -- _55 = move _56 as *const u8 (Transmute); -+ _55 = copy _2; - StorageDead(_56); -- _54 = opaque::<*const u8>(move _55) -> [return: bb10, unwind unreachable]; -+ _54 = opaque::<*const u8>(copy _2) -> [return: bb10, unwind unreachable]; + StorageLive(_57); + StorageLive(_58); + _58 = copy _53; +- _57 = move _58 as *const u8 (Transmute); ++ _57 = copy _2; + StorageDead(_58); +- _56 = opaque::<*const u8>(move _57) -> [return: bb10, unwind unreachable]; ++ _56 = opaque::<*const u8>(copy _2) -> [return: bb10, unwind unreachable]; } bb10: { - StorageDead(_55); - StorageDead(_54); + StorageDead(_57); + StorageDead(_56); _0 = const (); - StorageDead(_51); - StorageDead(_46); - StorageDead(_41); - StorageDead(_35); - StorageDead(_29); - StorageDead(_24); - StorageDead(_19); - StorageDead(_14); - StorageDead(_8); + StorageDead(_53); + StorageDead(_48); + StorageDead(_43); + StorageDead(_37); + StorageDead(_31); + StorageDead(_25); + StorageDead(_20); + StorageDead(_15); + StorageDead(_9); StorageDead(_3); return; } diff --git a/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-unwind.diff b/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-unwind.diff index f04f778349dba..b617b3ba1eebf 100644 --- a/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-unwind.diff @@ -6,79 +6,81 @@ debug thin => _2; let mut _0: (); let _3: MyId; - let mut _4: u16; - let _5: (); - let mut _6: u16; - let mut _7: MyId; - let mut _9: u16; - let mut _10: std::marker::PhantomData; - let _11: (); - let mut _12: u16; - let mut _13: TypedId; - let mut _15: u16; - let _16: (); - let mut _17: u16; - let mut _18: std::result::Result; - let mut _20: u16; - let _21: (); - let mut _22: u32; - let mut _23: std::option::Option; - let mut _25: u16; - let _26: (); - let mut _27: i16; - let mut _28: MyId; - let mut _30: u16; - let mut _31: u16; - let _32: (); - let mut _33: u32; - let mut _34: aggregate_struct_then_transmute::Pair; - let mut _36: u16; - let mut _37: u16; - let _38: (); + let mut _4: (u16) is 0..=55554; + let mut _5: u16; + let _6: (); + let mut _7: u16; + let mut _8: MyId; + let mut _10: u16; + let mut _11: std::marker::PhantomData; + let _12: (); + let mut _13: u16; + let mut _14: TypedId; + let mut _16: u16; + let _17: (); + let mut _18: u16; + let mut _19: std::result::Result; + let mut _21: u16; + let _22: (); + let mut _23: u32; + let mut _24: std::option::Option; + let mut _26: (u16) is 0..=55554; + let mut _27: u16; + let _28: (); + let mut _29: i16; + let mut _30: MyId; + let mut _32: u16; + let mut _33: u16; + let _34: (); + let mut _35: u32; + let mut _36: aggregate_struct_then_transmute::Pair; + let mut _38: u16; let mut _39: u16; - let mut _40: aggregate_struct_then_transmute::Pair; - let mut _42: u16; - let _43: (); + let _40: (); + let mut _41: u16; + let mut _42: aggregate_struct_then_transmute::Pair; let mut _44: u16; - let mut _45: (u16,); - let mut _47: u16; - let _48: (); + let _45: (); + let mut _46: u16; + let mut _47: (u16,); let mut _49: u16; - let mut _50: [u16; 1]; - let mut _52: *const u8; - let mut _53: (); - let _54: (); - let mut _55: *const u8; - let mut _56: *const i32; + let _50: (); + let mut _51: u16; + let mut _52: [u16; 1]; + let mut _54: *const u8; + let mut _55: (); + let _56: (); + let mut _57: *const u8; + let mut _58: *const i32; scope 1 { debug a => _3; - let _8: TypedId; + let _9: TypedId; scope 2 { - debug b => _8; - let _14: std::result::Result; + debug b => _9; + let _15: std::result::Result; scope 3 { - debug c => _14; - let _19: std::option::Option; + debug c => _15; + let _20: std::option::Option; scope 4 { - debug d => _19; - let _24: MyId; + debug d => _20; + let _25: MyId; scope 5 { - debug e => _24; - let _29: aggregate_struct_then_transmute::Pair; + debug e => _25; + let _31: aggregate_struct_then_transmute::Pair; scope 6 { - debug f => _29; - let _35: aggregate_struct_then_transmute::Pair; + debug f => _31; + let _37: aggregate_struct_then_transmute::Pair; scope 7 { - debug g => _35; - let _41: (u16,); + debug g => _37; + let _43: (u16,); scope 8 { - debug h => _41; - let _46: [u16; 1]; + debug h => _43; + let _48: [u16; 1]; scope 9 { - debug i => _46; - let _51: *const i32; + debug i => _48; + let _53: *const i32; scope 10 { - debug j => _51; + debug j => _53; } } } @@ -92,231 +94,240 @@ bb0: { StorageLive(_3); - StorageLive(_4); - _4 = copy _1; -- _3 = MyId(move _4); -+ _3 = MyId(copy _1); - StorageDead(_4); +- StorageLive(_4); ++ nop; StorageLive(_5); + _5 = copy _1; +- _4 = move _5 as (u16) is 0..=55554 (Transmute); ++ _4 = copy _1 as (u16) is 0..=55554 (Transmute); + StorageDead(_5); +- _3 = MyId(move _4); +- StorageDead(_4); ++ _3 = MyId(copy _4); ++ nop; StorageLive(_6); StorageLive(_7); -- _7 = move _3; -- _6 = move _7 as u16 (Transmute); -+ _7 = copy _3; -+ _6 = copy _1; - StorageDead(_7); -- _5 = opaque::(move _6) -> [return: bb1, unwind continue]; -+ _5 = opaque::(copy _1) -> [return: bb1, unwind continue]; + StorageLive(_8); +- _8 = move _3; +- _7 = move _8 as u16 (Transmute); ++ _8 = copy _3; ++ _7 = copy _4 as u16 (Transmute); + StorageDead(_8); + _6 = opaque::(move _7) -> [return: bb1, unwind continue]; } bb1: { + StorageDead(_7); StorageDead(_6); - StorageDead(_5); - StorageLive(_8); StorageLive(_9); - _9 = copy _1; StorageLive(_10); -- _10 = PhantomData::; -- _8 = TypedId::(move _9, move _10); -+ _10 = const PhantomData::; -+ _8 = TypedId::(copy _1, const PhantomData::); - StorageDead(_10); - StorageDead(_9); + _10 = copy _1; StorageLive(_11); +- _11 = PhantomData::; +- _9 = TypedId::(move _10, move _11); ++ _11 = const PhantomData::; ++ _9 = TypedId::(copy _1, const PhantomData::); + StorageDead(_11); + StorageDead(_10); StorageLive(_12); StorageLive(_13); -- _13 = move _8; -- _12 = move _13 as u16 (Transmute); -+ _13 = copy _8; -+ _12 = copy _1; - StorageDead(_13); -- _11 = opaque::(move _12) -> [return: bb2, unwind continue]; -+ _11 = opaque::(copy _1) -> [return: bb2, unwind continue]; + StorageLive(_14); +- _14 = move _9; +- _13 = move _14 as u16 (Transmute); ++ _14 = copy _9; ++ _13 = copy _1; + StorageDead(_14); +- _12 = opaque::(move _13) -> [return: bb2, unwind continue]; ++ _12 = opaque::(copy _1) -> [return: bb2, unwind continue]; } bb2: { + StorageDead(_13); StorageDead(_12); - StorageDead(_11); - StorageLive(_14); StorageLive(_15); - _15 = copy _1; -- _14 = Result::::Err(move _15); -+ _14 = Result::::Err(copy _1); - StorageDead(_15); StorageLive(_16); + _16 = copy _1; +- _15 = Result::::Err(move _16); ++ _15 = Result::::Err(copy _1); + StorageDead(_16); StorageLive(_17); StorageLive(_18); -- _18 = move _14; -- _17 = move _18 as u16 (Transmute); -+ _18 = copy _14; -+ _17 = copy _1; - StorageDead(_18); -- _16 = opaque::(move _17) -> [return: bb3, unwind continue]; -+ _16 = opaque::(copy _1) -> [return: bb3, unwind continue]; + StorageLive(_19); +- _19 = move _15; +- _18 = move _19 as u16 (Transmute); ++ _19 = copy _15; ++ _18 = copy _1; + StorageDead(_19); +- _17 = opaque::(move _18) -> [return: bb3, unwind continue]; ++ _17 = opaque::(copy _1) -> [return: bb3, unwind continue]; } bb3: { + StorageDead(_18); StorageDead(_17); - StorageDead(_16); - StorageLive(_19); StorageLive(_20); - _20 = copy _1; -- _19 = Option::::Some(move _20); -+ _19 = Option::::Some(copy _1); - StorageDead(_20); StorageLive(_21); + _21 = copy _1; +- _20 = Option::::Some(move _21); ++ _20 = Option::::Some(copy _1); + StorageDead(_21); StorageLive(_22); StorageLive(_23); - _23 = copy _19; -- _22 = move _23 as u32 (Transmute); -+ _22 = copy _19 as u32 (Transmute); - StorageDead(_23); - _21 = opaque::(move _22) -> [return: bb4, unwind continue]; + StorageLive(_24); + _24 = copy _20; +- _23 = move _24 as u32 (Transmute); ++ _23 = copy _20 as u32 (Transmute); + StorageDead(_24); + _22 = opaque::(move _23) -> [return: bb4, unwind continue]; } bb4: { + StorageDead(_23); StorageDead(_22); - StorageDead(_21); - StorageLive(_24); StorageLive(_25); - _25 = copy _1; -- _24 = MyId(move _25); -+ _24 = copy _3; - StorageDead(_25); StorageLive(_26); StorageLive(_27); - StorageLive(_28); -- _28 = move _24; -- _27 = move _28 as i16 (Transmute); -+ _28 = copy _3; -+ _27 = copy _1 as i16 (Transmute); - StorageDead(_28); - _26 = opaque::(move _27) -> [return: bb5, unwind continue]; - } - - bb5: { + _27 = copy _1; +- _26 = move _27 as (u16) is 0..=55554 (Transmute); ++ _26 = copy _4; StorageDead(_27); +- _25 = MyId(move _26); ++ _25 = copy _3; StorageDead(_26); + StorageLive(_28); StorageLive(_29); StorageLive(_30); - _30 = copy _1; - StorageLive(_31); - _31 = copy _1; -- _29 = Pair(move _30, move _31); -+ _29 = Pair(copy _1, copy _1); - StorageDead(_31); +- _30 = move _25; +- _29 = move _30 as i16 (Transmute); ++ _30 = copy _3; ++ _29 = copy _4 as i16 (Transmute); StorageDead(_30); - StorageLive(_32); - StorageLive(_33); - StorageLive(_34); -- _34 = move _29; -- _33 = move _34 as u32 (Transmute); -+ _34 = copy _29; -+ _33 = copy _29 as u32 (Transmute); - StorageDead(_34); - _32 = opaque::(move _33) -> [return: bb6, unwind continue]; + _28 = opaque::(move _29) -> [return: bb5, unwind continue]; } - bb6: { + bb5: { + StorageDead(_29); + StorageDead(_28); + StorageLive(_31); + StorageLive(_32); + _32 = copy _1; + StorageLive(_33); + _33 = copy _1; +- _31 = Pair(move _32, move _33); ++ _31 = Pair(copy _1, copy _1); StorageDead(_33); StorageDead(_32); + StorageLive(_34); StorageLive(_35); StorageLive(_36); - _36 = copy _1; - StorageLive(_37); - _37 = copy _1; -- _35 = Pair(move _36, move _37); -+ _35 = copy _29; - StorageDead(_37); +- _36 = move _31; +- _35 = move _36 as u32 (Transmute); ++ _36 = copy _31; ++ _35 = copy _31 as u32 (Transmute); StorageDead(_36); - StorageLive(_38); - StorageLive(_39); - StorageLive(_40); -- _40 = move _35; -- _39 = move _40 as u16 (Transmute); -+ _40 = copy _29; -+ _39 = copy _29 as u16 (Transmute); - StorageDead(_40); - _38 = opaque::(move _39) -> [return: bb7, unwind continue]; + _34 = opaque::(move _35) -> [return: bb6, unwind continue]; } - bb7: { + bb6: { + StorageDead(_35); + StorageDead(_34); + StorageLive(_37); + StorageLive(_38); + _38 = copy _1; + StorageLive(_39); + _39 = copy _1; +- _37 = Pair(move _38, move _39); ++ _37 = copy _31; StorageDead(_39); StorageDead(_38); + StorageLive(_40); StorageLive(_41); StorageLive(_42); - _42 = copy _1; -- _41 = (move _42,); -+ _41 = (copy _1,); +- _42 = move _37; +- _41 = move _42 as u16 (Transmute); ++ _42 = copy _31; ++ _41 = copy _31 as u16 (Transmute); StorageDead(_42); - StorageLive(_43); - StorageLive(_44); - StorageLive(_45); - _45 = copy _41; -- _44 = move _45 as u16 (Transmute); -+ _44 = copy _1; - StorageDead(_45); -- _43 = opaque::(move _44) -> [return: bb8, unwind continue]; -+ _43 = opaque::(copy _1) -> [return: bb8, unwind continue]; + _40 = opaque::(move _41) -> [return: bb7, unwind continue]; } - bb8: { + bb7: { + StorageDead(_41); + StorageDead(_40); + StorageLive(_43); + StorageLive(_44); + _44 = copy _1; +- _43 = (move _44,); ++ _43 = (copy _1,); StorageDead(_44); - StorageDead(_43); + StorageLive(_45); StorageLive(_46); StorageLive(_47); - _47 = copy _1; -- _46 = [move _47]; -+ _46 = [copy _1]; + _47 = copy _43; +- _46 = move _47 as u16 (Transmute); ++ _46 = copy _1; StorageDead(_47); +- _45 = opaque::(move _46) -> [return: bb8, unwind continue]; ++ _45 = opaque::(copy _1) -> [return: bb8, unwind continue]; + } + + bb8: { + StorageDead(_46); + StorageDead(_45); StorageLive(_48); StorageLive(_49); + _49 = copy _1; +- _48 = [move _49]; ++ _48 = [copy _1]; + StorageDead(_49); StorageLive(_50); - _50 = copy _46; -- _49 = move _50 as u16 (Transmute); -+ _49 = copy _1; - StorageDead(_50); -- _48 = opaque::(move _49) -> [return: bb9, unwind continue]; -+ _48 = opaque::(copy _1) -> [return: bb9, unwind continue]; + StorageLive(_51); + StorageLive(_52); + _52 = copy _48; +- _51 = move _52 as u16 (Transmute); ++ _51 = copy _1; + StorageDead(_52); +- _50 = opaque::(move _51) -> [return: bb9, unwind continue]; ++ _50 = opaque::(copy _1) -> [return: bb9, unwind continue]; } bb9: { - StorageDead(_49); - StorageDead(_48); - StorageLive(_51); - StorageLive(_52); - _52 = copy _2; + StorageDead(_51); + StorageDead(_50); StorageLive(_53); -- _53 = (); -- _51 = *const i32 from (move _52, move _53); -+ _53 = const (); -+ _51 = *const i32 from (copy _2, const ()); - StorageDead(_53); - StorageDead(_52); StorageLive(_54); + _54 = copy _2; StorageLive(_55); +- _55 = (); +- _53 = *const i32 from (move _54, move _55); ++ _55 = const (); ++ _53 = *const i32 from (copy _2, const ()); + StorageDead(_55); + StorageDead(_54); StorageLive(_56); - _56 = copy _51; -- _55 = move _56 as *const u8 (Transmute); -+ _55 = copy _2; - StorageDead(_56); -- _54 = opaque::<*const u8>(move _55) -> [return: bb10, unwind continue]; -+ _54 = opaque::<*const u8>(copy _2) -> [return: bb10, unwind continue]; + StorageLive(_57); + StorageLive(_58); + _58 = copy _53; +- _57 = move _58 as *const u8 (Transmute); ++ _57 = copy _2; + StorageDead(_58); +- _56 = opaque::<*const u8>(move _57) -> [return: bb10, unwind continue]; ++ _56 = opaque::<*const u8>(copy _2) -> [return: bb10, unwind continue]; } bb10: { - StorageDead(_55); - StorageDead(_54); + StorageDead(_57); + StorageDead(_56); _0 = const (); - StorageDead(_51); - StorageDead(_46); - StorageDead(_41); - StorageDead(_35); - StorageDead(_29); - StorageDead(_24); - StorageDead(_19); - StorageDead(_14); - StorageDead(_8); + StorageDead(_53); + StorageDead(_48); + StorageDead(_43); + StorageDead(_37); + StorageDead(_31); + StorageDead(_25); + StorageDead(_20); + StorageDead(_15); + StorageDead(_9); StorageDead(_3); return; } diff --git a/tests/mir-opt/gvn.rs b/tests/mir-opt/gvn.rs index 07309c1569cd8..26ad012fa330b 100644 --- a/tests/mir-opt/gvn.rs +++ b/tests/mir-opt/gvn.rs @@ -6,7 +6,7 @@ #![feature(rustc_attrs)] #![feature(custom_mir)] #![feature(core_intrinsics)] -#![feature(freeze)] +#![feature(freeze, pattern_type_range_trait, const_trait_impl, pattern_types, pattern_type_macro)] #![allow(ambiguous_wide_pointer_comparisons)] #![allow(unconditional_panic)] #![allow(unnecessary_transmutes)] @@ -947,9 +947,12 @@ fn cast_pointer_eq(p1: *mut u8, p2: *mut u32, p3: *mut u32, p4: *mut [u32]) { // CHECK: _0 = const (); } +// CHECK: fn aggregate_struct_then_transmute unsafe fn aggregate_struct_then_transmute(id: u16, thin: *const u8) { - // CHECK: opaque::(copy _1) - let a = MyId(id); + // CHECK: [[PAT:_[0-9]+]] = copy _1 as (u16) is 0..=55554 (Transmute); + // CHECK: [[TEMP:_[0-9]+]] = copy [[PAT]] as u16 (Transmute); + // CHECK: opaque::(move [[TEMP]]) + let a = MyId(std::intrinsics::transmute(id)); opaque(std::intrinsics::transmute::<_, u16>(a)); // CHECK: opaque::(copy _1) @@ -967,9 +970,9 @@ unsafe fn aggregate_struct_then_transmute(id: u16, thin: *const u8) { opaque(std::intrinsics::transmute::<_, u32>(d)); // Still need the transmute, but the aggregate can be skipped - // CHECK: [[TEMP:_[0-9]+]] = copy _1 as i16 (Transmute); + // CHECK: [[TEMP:_[0-9]+]] = copy [[PAT]] as i16 (Transmute); // CHECK: opaque::(move [[TEMP]]) - let e = MyId(id); + let e = MyId(std::intrinsics::transmute(id)); opaque(std::intrinsics::transmute::<_, i16>(e)); // CHECK: [[PAIR:_[0-9]+]] = Pair(copy _1, copy _1); @@ -1193,8 +1196,7 @@ fn identity(x: T) -> T { fn takes_const_ptr(_: *const T) {} #[repr(transparent)] -#[rustc_layout_scalar_valid_range_end(55555)] -struct MyId(u16); +struct MyId(std::pat::pattern_type!(u16 is 0..55555)); #[repr(transparent)] struct TypedId(u16, PhantomData); diff --git a/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-abort.diff b/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-abort.diff index 7014146cb8624..9940e32982871 100644 --- a/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-abort.diff +++ b/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-abort.diff @@ -4,13 +4,15 @@ fn mutate_discriminant() -> u8 { let mut _0: u8; let mut _1: std::option::Option; - let mut _2: isize; + let mut _2: (usize) is 1..; + let mut _3: isize; bb0: { discriminant(_1) = 1; - (((_1 as variant#1).0: NonZeroUsize).0: usize) = const 0_usize; - _2 = discriminant(_1); - switchInt(copy _2) -> [0: bb1, otherwise: bb2]; + _2 = const 0_usize as (usize) is 1.. (Transmute); + (((_1 as variant#1).0: NonZeroUsize).0: (usize) is 1..=usize::MAX) = copy _2; + _3 = discriminant(_1); + switchInt(copy _3) -> [0: bb1, otherwise: bb2]; } bb1: { diff --git a/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-unwind.diff b/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-unwind.diff index 7014146cb8624..9940e32982871 100644 --- a/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-unwind.diff +++ b/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-unwind.diff @@ -4,13 +4,15 @@ fn mutate_discriminant() -> u8 { let mut _0: u8; let mut _1: std::option::Option; - let mut _2: isize; + let mut _2: (usize) is 1..; + let mut _3: isize; bb0: { discriminant(_1) = 1; - (((_1 as variant#1).0: NonZeroUsize).0: usize) = const 0_usize; - _2 = discriminant(_1); - switchInt(copy _2) -> [0: bb1, otherwise: bb2]; + _2 = const 0_usize as (usize) is 1.. (Transmute); + (((_1 as variant#1).0: NonZeroUsize).0: (usize) is 1..=usize::MAX) = copy _2; + _3 = discriminant(_1); + switchInt(copy _3) -> [0: bb1, otherwise: bb2]; } bb1: { diff --git a/tests/mir-opt/jump_threading.rs b/tests/mir-opt/jump_threading.rs index 39a2f16c5ad6f..e4942a5c173fd 100644 --- a/tests/mir-opt/jump_threading.rs +++ b/tests/mir-opt/jump_threading.rs @@ -2,7 +2,7 @@ //@ compile-flags: -Zmir-enable-passes=+Inline // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -#![feature(try_trait_v2)] +#![feature(try_trait_v2, pattern_type_macro, pattern_types)] #![feature(custom_mir, core_intrinsics, rustc_attrs)] use std::intrinsics::mir::*; @@ -311,9 +311,8 @@ fn duplicate_chain(x: bool) -> u8 { } } -#[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] -struct NonZeroUsize(usize); +struct NonZeroUsize(std::pat::pattern_type!(usize is 1..=usize::MAX)); /// Verify that we correctly discard threads that may mutate a discriminant by aliasing. #[custom_mir(dialect = "runtime", phase = "post-cleanup")] @@ -326,8 +325,9 @@ fn mutate_discriminant() -> u8 { let x: Option; { SetDiscriminant(x, 1); + let y = CastTransmute::<_, std::pat::pattern_type!(usize is 1..=usize::MAX)>(0_usize); // This assignment overwrites the niche in which the discriminant is stored. - place!(Field(Field(Variant(x, 1), 0), 0)) = 0_usize; + place!(Field(Field(Variant(x, 1), 0), 0)) = y; // So we cannot know the value of this discriminant. let a = Discriminant(x); match a { diff --git a/tests/ui/attributes/invalid_rustc_layout_scalar_valid_range.rs b/tests/ui/attributes/invalid_rustc_layout_scalar_valid_range.rs deleted file mode 100644 index 8ea4eac1a6173..0000000000000 --- a/tests/ui/attributes/invalid_rustc_layout_scalar_valid_range.rs +++ /dev/null @@ -1,32 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(u32::MAX)] //~ ERROR -pub struct A(u32); - -#[rustc_layout_scalar_valid_range_end(1, 2)] //~ ERROR -pub struct B(u8); - -#[rustc_layout_scalar_valid_range_end(a = "a")] //~ ERROR -pub struct C(i32); - -#[rustc_layout_scalar_valid_range_end(1)] //~ ERROR -enum E { - X = 1, - Y = 14, -} - -#[rustc_layout_scalar_valid_range_start(rustc_layout_scalar_valid_range_start)] //~ ERROR -struct NonZero(T); - -fn not_field() -> impl Send { - NonZero(false) -} - -fn main() { - let _ = A(0); - let _ = B(0); - let _ = C(0); - unsafe { - let _ = E::X; - } -} diff --git a/tests/ui/attributes/invalid_rustc_layout_scalar_valid_range.stderr b/tests/ui/attributes/invalid_rustc_layout_scalar_valid_range.stderr deleted file mode 100644 index 457affe4950ee..0000000000000 --- a/tests/ui/attributes/invalid_rustc_layout_scalar_valid_range.stderr +++ /dev/null @@ -1,68 +0,0 @@ -error[E0539]: malformed `rustc_layout_scalar_valid_range_start` attribute input - --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:3:1 - | -LL | #[rustc_layout_scalar_valid_range_start(u32::MAX)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------^^ - | | - | expected an integer literal here - | -help: must be of the form - | -LL - #[rustc_layout_scalar_valid_range_start(u32::MAX)] -LL + #[rustc_layout_scalar_valid_range_start(start)] - | - -error[E0805]: malformed `rustc_layout_scalar_valid_range_end` attribute input - --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:6:1 - | -LL | #[rustc_layout_scalar_valid_range_end(1, 2)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------^ - | | - | expected a single argument here - | -help: must be of the form - | -LL - #[rustc_layout_scalar_valid_range_end(1, 2)] -LL + #[rustc_layout_scalar_valid_range_end(end)] - | - -error[E0539]: malformed `rustc_layout_scalar_valid_range_end` attribute input - --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:9:1 - | -LL | #[rustc_layout_scalar_valid_range_end(a = "a")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------^^ - | | - | expected an integer literal here - | -help: must be of the form - | -LL - #[rustc_layout_scalar_valid_range_end(a = "a")] -LL + #[rustc_layout_scalar_valid_range_end(end)] - | - -error: `#[rustc_layout_scalar_valid_range_end]` attribute cannot be used on enums - --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:12:1 - | -LL | #[rustc_layout_scalar_valid_range_end(1)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: `#[rustc_layout_scalar_valid_range_end]` can only be applied to structs - -error[E0539]: malformed `rustc_layout_scalar_valid_range_start` attribute input - --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:18:1 - | -LL | #[rustc_layout_scalar_valid_range_start(rustc_layout_scalar_valid_range_start)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------------------------------^^ - | | - | expected an integer literal here - | -help: must be of the form - | -LL - #[rustc_layout_scalar_valid_range_start(rustc_layout_scalar_valid_range_start)] -LL + #[rustc_layout_scalar_valid_range_start(start)] - | - -error: aborting due to 5 previous errors - -Some errors have detailed explanations: E0539, E0805. -For more information about an error, try `rustc --explain E0539`. diff --git a/tests/ui/attributes/malformed-attrs.rs b/tests/ui/attributes/malformed-attrs.rs index 9dcdb9a69272b..c73feb9110f11 100644 --- a/tests/ui/attributes/malformed-attrs.rs +++ b/tests/ui/attributes/malformed-attrs.rs @@ -129,10 +129,6 @@ fn test2() { } //~| ERROR the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type pub fn test3() {} -#[rustc_layout_scalar_valid_range_start] -//~^ ERROR malformed -#[rustc_layout_scalar_valid_range_end] -//~^ ERROR malformed #[must_not_suspend()] //~^ ERROR malformed #[cfi_encoding = ""] diff --git a/tests/ui/attributes/malformed-attrs.stderr b/tests/ui/attributes/malformed-attrs.stderr index bc539438613b0..784cbb38aaedd 100644 --- a/tests/ui/attributes/malformed-attrs.stderr +++ b/tests/ui/attributes/malformed-attrs.stderr @@ -23,13 +23,13 @@ LL | #[cfg_attr(predicate, attr1, attr2, ...)] | ++++++++++++++++++++++++++++++ error[E0463]: can't find crate for `wloop` - --> $DIR/malformed-attrs.rs:214:1 + --> $DIR/malformed-attrs.rs:210:1 | LL | extern crate wloop; | ^^^^^^^^^^^^^^^^^^^ can't find crate error: malformed `allow` attribute input - --> $DIR/malformed-attrs.rs:180:1 + --> $DIR/malformed-attrs.rs:176:1 | LL | #[allow] | ^^^^^^^^ @@ -45,7 +45,7 @@ LL | #[allow(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `expect` attribute input - --> $DIR/malformed-attrs.rs:182:1 + --> $DIR/malformed-attrs.rs:178:1 | LL | #[expect] | ^^^^^^^^^ @@ -61,7 +61,7 @@ LL | #[expect(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `warn` attribute input - --> $DIR/malformed-attrs.rs:184:1 + --> $DIR/malformed-attrs.rs:180:1 | LL | #[warn] | ^^^^^^^ @@ -77,7 +77,7 @@ LL | #[warn(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `deny` attribute input - --> $DIR/malformed-attrs.rs:186:1 + --> $DIR/malformed-attrs.rs:182:1 | LL | #[deny] | ^^^^^^^ @@ -93,7 +93,7 @@ LL | #[deny(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `forbid` attribute input - --> $DIR/malformed-attrs.rs:188:1 + --> $DIR/malformed-attrs.rs:184:1 | LL | #[forbid] | ^^^^^^^^^ @@ -127,7 +127,7 @@ LL | #[proc_macro_derive] | ^^^^^^^^^^^^^^^^^^^^ error[E0658]: allow_internal_unsafe side-steps the unsafe_code lint - --> $DIR/malformed-attrs.rs:219:1 + --> $DIR/malformed-attrs.rs:215:1 | LL | #[allow_internal_unsafe = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -583,30 +583,8 @@ LL | #[proc_macro_derive(TraitName)] LL | #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] | ++++++++++++++++++++++++++++++++++++++++++ -error[E0539]: malformed `rustc_layout_scalar_valid_range_start` attribute input - --> $DIR/malformed-attrs.rs:132:1 - | -LL | #[rustc_layout_scalar_valid_range_start] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected this to be a list - | -help: must be of the form - | -LL | #[rustc_layout_scalar_valid_range_start(start)] - | +++++++ - -error[E0539]: malformed `rustc_layout_scalar_valid_range_end` attribute input - --> $DIR/malformed-attrs.rs:134:1 - | -LL | #[rustc_layout_scalar_valid_range_end] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected this to be a list - | -help: must be of the form - | -LL | #[rustc_layout_scalar_valid_range_end(end)] - | +++++ - error[E0539]: malformed `must_not_suspend` attribute input - --> $DIR/malformed-attrs.rs:136:1 + --> $DIR/malformed-attrs.rs:132:1 | LL | #[must_not_suspend()] | ^^^^^^^^^^^^^^^^^^--^ @@ -622,7 +600,7 @@ LL + #[must_not_suspend] | error[E0539]: malformed `cfi_encoding` attribute input - --> $DIR/malformed-attrs.rs:138:1 + --> $DIR/malformed-attrs.rs:134:1 | LL | #[cfi_encoding = ""] | ^^^^^^^^^^^^^^^^^--^ @@ -635,7 +613,7 @@ LL | #[cfi_encoding = "encoding"] | ++++++++ error[E0565]: malformed `marker` attribute input - --> $DIR/malformed-attrs.rs:157:1 + --> $DIR/malformed-attrs.rs:153:1 | LL | #[marker = 3] | ^^^^^^^^^---^ @@ -649,7 +627,7 @@ LL + #[marker] | error[E0565]: malformed `fundamental` attribute input - --> $DIR/malformed-attrs.rs:159:1 + --> $DIR/malformed-attrs.rs:155:1 | LL | #[fundamental()] | ^^^^^^^^^^^^^--^ @@ -663,7 +641,7 @@ LL + #[fundamental] | error[E0565]: malformed `ffi_pure` attribute input - --> $DIR/malformed-attrs.rs:167:5 + --> $DIR/malformed-attrs.rs:163:5 | LL | #[unsafe(ffi_pure = 1)] | ^^^^^^^^^^^^^^^^^^---^^ @@ -677,7 +655,7 @@ LL + #[ffi_pure] | error[E0539]: malformed `link_ordinal` attribute input - --> $DIR/malformed-attrs.rs:169:5 + --> $DIR/malformed-attrs.rs:165:5 | LL | #[link_ordinal] | ^^^^^^^^^^^^^^^ expected this to be a list @@ -689,7 +667,7 @@ LL | #[link_ordinal(ordinal)] | +++++++++ error[E0565]: malformed `ffi_const` attribute input - --> $DIR/malformed-attrs.rs:173:5 + --> $DIR/malformed-attrs.rs:169:5 | LL | #[unsafe(ffi_const = 1)] | ^^^^^^^^^^^^^^^^^^^---^^ @@ -703,13 +681,13 @@ LL + #[ffi_const] | error[E0539]: malformed `linkage` attribute input - --> $DIR/malformed-attrs.rs:175:5 + --> $DIR/malformed-attrs.rs:171:5 | LL | #[linkage] | ^^^^^^^^^^ expected this to be of the form `linkage = "..."` error[E0539]: malformed `debugger_visualizer` attribute input - --> $DIR/malformed-attrs.rs:190:1 + --> $DIR/malformed-attrs.rs:186:1 | LL | #[debugger_visualizer] | ^^^^^^^^^^^^^^^^^^^^^^ expected this to be a list @@ -721,7 +699,7 @@ LL | #[debugger_visualizer(natvis_file = "...", gdb_script_file = "...")] | ++++++++++++++++++++++++++++++++++++++++++++++ error[E0565]: malformed `automatically_derived` attribute input - --> $DIR/malformed-attrs.rs:192:1 + --> $DIR/malformed-attrs.rs:188:1 | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^^^^----^ @@ -735,7 +713,7 @@ LL + #[automatically_derived] | error[E0565]: malformed `non_exhaustive` attribute input - --> $DIR/malformed-attrs.rs:200:1 + --> $DIR/malformed-attrs.rs:196:1 | LL | #[non_exhaustive = 1] | ^^^^^^^^^^^^^^^^^---^ @@ -749,7 +727,7 @@ LL + #[non_exhaustive] | error[E0565]: malformed `thread_local` attribute input - --> $DIR/malformed-attrs.rs:206:1 + --> $DIR/malformed-attrs.rs:202:1 | LL | #[thread_local()] | ^^^^^^^^^^^^^^--^ @@ -763,7 +741,7 @@ LL + #[thread_local] | error[E0565]: malformed `no_link` attribute input - --> $DIR/malformed-attrs.rs:210:1 + --> $DIR/malformed-attrs.rs:206:1 | LL | #[no_link()] | ^^^^^^^^^--^ @@ -777,7 +755,7 @@ LL + #[no_link] | error[E0539]: malformed `macro_use` attribute input - --> $DIR/malformed-attrs.rs:212:1 + --> $DIR/malformed-attrs.rs:208:1 | LL | #[macro_use = 1] | ^^^^^^^^^^^^---^ @@ -795,7 +773,7 @@ LL + #[macro_use] | error[E0539]: malformed `macro_export` attribute input - --> $DIR/malformed-attrs.rs:217:1 + --> $DIR/malformed-attrs.rs:213:1 | LL | #[macro_export = 18] | ^^^^^^^^^^^^^^^----^ @@ -812,7 +790,7 @@ LL + #[macro_export] | error[E0565]: malformed `allow_internal_unsafe` attribute input - --> $DIR/malformed-attrs.rs:219:1 + --> $DIR/malformed-attrs.rs:215:1 | LL | #[allow_internal_unsafe = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^---^ @@ -935,7 +913,7 @@ LL | #[no_implicit_prelude = 23] = help: `#[no_implicit_prelude]` can be applied to crates and modules warning: missing options for `diagnostic::on_unimplemented` attribute - --> $DIR/malformed-attrs.rs:142:1 + --> $DIR/malformed-attrs.rs:138:1 | LL | #[diagnostic::on_unimplemented] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -944,7 +922,7 @@ LL | #[diagnostic::on_unimplemented] = note: `#[warn(malformed_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default warning: malformed `diagnostic::on_unimplemented` attribute - --> $DIR/malformed-attrs.rs:144:1 + --> $DIR/malformed-attrs.rs:140:1 | LL | #[diagnostic::on_unimplemented = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here @@ -952,13 +930,13 @@ LL | #[diagnostic::on_unimplemented = 1] = help: only `message`, `note` and `label` are allowed as options warning: `#[diagnostic::do_not_recommend]` does not expect any arguments - --> $DIR/malformed-attrs.rs:151:1 + --> $DIR/malformed-attrs.rs:147:1 | LL | #[diagnostic::do_not_recommend()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: `#[automatically_derived]` attribute cannot be used on modules - --> $DIR/malformed-attrs.rs:192:1 + --> $DIR/malformed-attrs.rs:188:1 | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -967,7 +945,7 @@ LL | #[automatically_derived = 18] = help: `#[automatically_derived]` can only be applied to trait impl blocks error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:226:1 + --> $DIR/malformed-attrs.rs:222:1 | LL | #[ignore = 1] | ^^^^^^^^^^^^^ @@ -986,7 +964,7 @@ LL | #[coroutine = 63] || {} = note: expected unit type `()` found coroutine `{coroutine@$DIR/malformed-attrs.rs:115:23: 115:25}` -error: aborting due to 75 previous errors; 8 warnings emitted +error: aborting due to 73 previous errors; 8 warnings emitted Some errors have detailed explanations: E0308, E0463, E0539, E0565, E0658, E0805. For more information about an error, try `rustc --explain E0308`. @@ -1014,7 +992,7 @@ LL | #[ignore()] Future breakage diagnostic: error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:226:1 + --> $DIR/malformed-attrs.rs:222:1 | LL | #[ignore = 1] | ^^^^^^^^^^^^^ diff --git a/tests/ui/check-cfg/report-in-external-macros.cargo.stderr b/tests/ui/check-cfg/report-in-external-macros.cargo.stderr index b474322d6afaf..18d361ccdbd7f 100644 --- a/tests/ui/check-cfg/report-in-external-macros.cargo.stderr +++ b/tests/ui/check-cfg/report-in-external-macros.cargo.stderr @@ -7,7 +7,6 @@ LL | cfg_macro::my_lib_macro!(); = help: expected names are: `feature` and 32 more = note: using a cfg inside a macro will use the cfgs from the destination crate and not the ones from the defining crate = help: try referring to `cfg_macro::my_lib_macro` crate for guidance on how handle this unexpected cfg - = help: the macro `cfg_macro::my_lib_macro` may come from an old version of the `cfg_macro` crate, try updating your dependency with `cargo update -p cfg_macro` = note: see for more information about checking conditional configuration = note: `#[warn(unexpected_cfgs)]` on by default = note: this warning originates in the macro `cfg_macro::my_lib_macro` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -21,7 +20,6 @@ LL | cfg_macro::my_lib_macro_value!(); = note: expected values for `panic` are: `abort`, `immediate-abort`, and `unwind` = note: using a cfg inside a macro will use the cfgs from the destination crate and not the ones from the defining crate = help: try referring to `cfg_macro::my_lib_macro_value` crate for guidance on how handle this unexpected cfg - = help: the macro `cfg_macro::my_lib_macro_value` may come from an old version of the `cfg_macro` crate, try updating your dependency with `cargo update -p cfg_macro` = note: see for more information about checking conditional configuration = note: this warning originates in the macro `cfg_macro::my_lib_macro_value` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -34,7 +32,6 @@ LL | cfg_macro::my_lib_macro_feature!(); = note: no expected values for `feature` = note: using a cfg inside a macro will use the cfgs from the destination crate and not the ones from the defining crate = help: try referring to `cfg_macro::my_lib_macro_feature` crate for guidance on how handle this unexpected cfg - = help: the macro `cfg_macro::my_lib_macro_feature` may come from an old version of the `cfg_macro` crate, try updating your dependency with `cargo update -p cfg_macro` = note: see for more information about checking conditional configuration = note: this warning originates in the macro `cfg_macro::my_lib_macro_feature` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/closures/closure-return-block-note-issue-155670.rs b/tests/ui/closures/closure-return-block-note-issue-155670.rs index fccce9ee54ca2..004d96aa04635 100644 --- a/tests/ui/closures/closure-return-block-note-issue-155670.rs +++ b/tests/ui/closures/closure-return-block-note-issue-155670.rs @@ -11,4 +11,28 @@ const _: fn() = || { }; }; +const _: fn() -> SmolStr = || { + match Some(()) { + Some(()) => (), + None => return SmolStr, + }; + let _: String = { + SmolStr + //~^ ERROR mismatched types + }; + SmolStr +}; + +const _: fn() -> String = || { + match Some(()) { + Some(()) => (), + None => return String::new(), + }; + let _: String = { + SmolStr + //~^ ERROR mismatched types + }; + String::new() +}; + fn main() {} diff --git a/tests/ui/closures/closure-return-block-note-issue-155670.stderr b/tests/ui/closures/closure-return-block-note-issue-155670.stderr index f38d2f14200d4..faacdcca8ab61 100644 --- a/tests/ui/closures/closure-return-block-note-issue-155670.stderr +++ b/tests/ui/closures/closure-return-block-note-issue-155670.stderr @@ -4,6 +4,18 @@ error[E0308]: mismatched types LL | SmolStr | ^^^^^^^ expected `String`, found `SmolStr` -error: aborting due to 1 previous error +error[E0308]: mismatched types + --> $DIR/closure-return-block-note-issue-155670.rs:20:9 + | +LL | SmolStr + | ^^^^^^^ expected `String`, found `SmolStr` + +error[E0308]: mismatched types + --> $DIR/closure-return-block-note-issue-155670.rs:32:9 + | +LL | SmolStr + | ^^^^^^^ expected `String`, found `SmolStr` + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.min.stderr b/tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.min.stderr new file mode 100644 index 0000000000000..196c3397742fe --- /dev/null +++ b/tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.min.stderr @@ -0,0 +1,23 @@ +error: the trait `ConstParamTy` may not be implemented for this type + --> $DIR/forbid-non_exhaustive-const-param-ty.rs:13:12 + | +LL | #[non_exhaustive] + | ----------------- caused by this attribute +LL | #[derive(PartialEq, Eq, ConstParamTy)] + | ------------ in this derive macro expansion +LL | pub struct Miow; + | ^^^^ non exhaustive const params are forbidden + +error: the trait `ConstParamTy` may not be implemented for this type + --> $DIR/forbid-non_exhaustive-const-param-ty.rs:17:10 + | +LL | #[derive(PartialEq, Eq, ConstParamTy)] + | ------------ in this derive macro expansion +LL | pub enum Enumiow { + | ^^^^^^^ non exhaustive const params are forbidden +LL | +LL | #[non_exhaustive] NonExhaustiveThingie, + | ----------------- caused by this attribute + +error: aborting due to 2 previous errors + diff --git a/tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.rs b/tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.rs new file mode 100644 index 0000000000000..978f6951b12e7 --- /dev/null +++ b/tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.rs @@ -0,0 +1,30 @@ +//! Ensure that non exhaustive structs and enums with non exhaustive variants +//! aren't allowed to implement ConstParamTy under min_adt_const_params feature +//@ revisions: full min +//@[full] check-pass +#![cfg_attr(min, feature(min_adt_const_params))] +#![cfg_attr(full, feature(adt_const_params))] +#![allow(incomplete_features)] + +use std::marker::ConstParamTy; + +#[non_exhaustive] +#[derive(PartialEq, Eq, ConstParamTy)] +pub struct Miow; + //[min]~^ ERROR: the trait `ConstParamTy` may not be implemented for this type + +#[derive(PartialEq, Eq, ConstParamTy)] +pub enum Enumiow { + //[min]~^ ERROR: the trait `ConstParamTy` may not be implemented for this type + #[non_exhaustive] NonExhaustiveThingie, + ExhaustiveThingie, +} + +#[non_exhaustive] +#[derive(PartialEq, Eq, ConstParamTy)] +pub enum EnumiowButFine { + ExhaustiveThingie, + AlsoExhaustiveThingie, +} + +fn main() {} diff --git a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr index 6ae23c6b24b1d..4493067e9a8bb 100644 --- a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr @@ -1,5 +1,5 @@ error[E0080]: constructing invalid value of type Enum: at ., encountered 0x00000001, but expected a valid enum tag - --> $DIR/raw-bytes.rs:23:1 + --> $DIR/raw-bytes.rs:24:1 | LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) }; | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -10,7 +10,7 @@ LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) }; } error[E0080]: constructing invalid value of type Enum2: at ., encountered 0x00000000, but expected a valid enum tag - --> $DIR/raw-bytes.rs:31:1 + --> $DIR/raw-bytes.rs:32:1 | LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -21,7 +21,7 @@ LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type UninhDiscriminant: at ., encountered an uninhabited enum variant - --> $DIR/raw-bytes.rs:45:1 + --> $DIR/raw-bytes.rs:46:1 | LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -32,7 +32,7 @@ LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute } error[E0080]: constructing invalid value of type UninhDiscriminant: at ., encountered 0x03, but expected a valid enum tag - --> $DIR/raw-bytes.rs:47:1 + --> $DIR/raw-bytes.rs:48:1 | LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -43,7 +43,7 @@ LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute } error[E0080]: constructing invalid value of type Option<(char, char)>: at ..0.1, encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`) - --> $DIR/raw-bytes.rs:53:1 + --> $DIR/raw-bytes.rs:54:1 | LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -54,7 +54,7 @@ LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::tran } error[E0080]: constructing invalid value of type NonNull: at .pointer, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:58:1 + --> $DIR/raw-bytes.rs:59:1 | LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -65,7 +65,7 @@ LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type NonZero: at .0.0, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:61:1 + --> $DIR/raw-bytes.rs:62:1 | LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -76,7 +76,7 @@ LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; } error[E0080]: constructing invalid value of type NonZero: at .0.0, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:63:1 + --> $DIR/raw-bytes.rs:64:1 | LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -86,10 +86,10 @@ LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; 00 00 00 00 │ .... } -error[E0080]: constructing invalid value of type RestrictedRange1: encountered 42, but expected something in the range 10..=30 - --> $DIR/raw-bytes.rs:69:1 +error[E0080]: constructing invalid value of type RestrictedRange1: at .0, encountered 42, but expected something in the range 10..=30 + --> $DIR/raw-bytes.rs:68:1 | -LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; +LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(mem::transmute(42_u32)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. @@ -97,10 +97,10 @@ LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; 2a 00 00 00 │ *... } -error[E0080]: constructing invalid value of type RestrictedRange2: encountered 20, but expected something less or equal to 10, or greater or equal to 30 - --> $DIR/raw-bytes.rs:75:1 +error[E0080]: constructing invalid value of type RestrictedRange2: at .0, encountered 20, but expected something less or equal to 10, or greater or equal to 30 + --> $DIR/raw-bytes.rs:72:1 | -LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; +LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(mem::transmute(20_i32)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. @@ -109,7 +109,7 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; } error[E0080]: constructing invalid value of type NonNull: at .pointer, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:78:1 + --> $DIR/raw-bytes.rs:75:1 | LL | const NULL_FAT_PTR: NonNull = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -120,7 +120,7 @@ LL | const NULL_FAT_PTR: NonNull = unsafe { } error[E0080]: constructing invalid value of type &u16: encountered an unaligned reference (required 2 byte alignment but found 1) - --> $DIR/raw-bytes.rs:85:1 + --> $DIR/raw-bytes.rs:82:1 | LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -131,7 +131,7 @@ LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; } error[E0080]: constructing invalid value of type Box: encountered an unaligned box (required 2 byte alignment but found 1) - --> $DIR/raw-bytes.rs:88:1 + --> $DIR/raw-bytes.rs:85:1 | LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -142,7 +142,7 @@ LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; } error[E0080]: constructing invalid value of type &u16: encountered a null reference - --> $DIR/raw-bytes.rs:91:1 + --> $DIR/raw-bytes.rs:88:1 | LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -153,7 +153,7 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type Box: encountered a null box - --> $DIR/raw-bytes.rs:94:1 + --> $DIR/raw-bytes.rs:91:1 | LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -164,7 +164,7 @@ LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type &u8: encountered a dangling reference (0x539[noalloc] has no provenance) - --> $DIR/raw-bytes.rs:97:1 + --> $DIR/raw-bytes.rs:94:1 | LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -175,7 +175,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; } error[E0080]: constructing invalid value of type Box: encountered a dangling box (0x539[noalloc] has no provenance) - --> $DIR/raw-bytes.rs:100:1 + --> $DIR/raw-bytes.rs:97:1 | LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -186,7 +186,7 @@ LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; } error[E0080]: constructing invalid value of type fn(): encountered null pointer, but expected a function pointer - --> $DIR/raw-bytes.rs:103:1 + --> $DIR/raw-bytes.rs:100:1 | LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -197,7 +197,7 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type fn(): encountered 0xd[noalloc], but expected a function pointer - --> $DIR/raw-bytes.rs:105:1 + --> $DIR/raw-bytes.rs:102:1 | LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -208,7 +208,7 @@ LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; } error[E0080]: constructing invalid value of type fn(): encountered ALLOC3, but expected a function pointer - --> $DIR/raw-bytes.rs:107:1 + --> $DIR/raw-bytes.rs:104:1 | LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -219,7 +219,7 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; } error[E0080]: constructing invalid value of type &Bar: encountered a reference pointing to uninhabited type Bar - --> $DIR/raw-bytes.rs:113:1 + --> $DIR/raw-bytes.rs:110:1 | LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -230,7 +230,7 @@ LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; } error[E0080]: constructing invalid value of type &str: encountered a dangling reference (going beyond the bounds of its allocation) - --> $DIR/raw-bytes.rs:137:1 + --> $DIR/raw-bytes.rs:134:1 | LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -241,7 +241,7 @@ LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) }; } error[E0080]: constructing invalid value of type (&str,): at .0, encountered invalid reference metadata: slice is bigger than largest supported object - --> $DIR/raw-bytes.rs:139:1 + --> $DIR/raw-bytes.rs:136:1 | LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -252,7 +252,7 @@ LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, us } error[E0080]: constructing invalid value of type &MyStr: encountered invalid reference metadata: slice is bigger than largest supported object - --> $DIR/raw-bytes.rs:141:1 + --> $DIR/raw-bytes.rs:138:1 | LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -263,7 +263,7 @@ LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize: } error[E0080]: constructing invalid value of type &str: at ., encountered uninitialized memory, but expected a string - --> $DIR/raw-bytes.rs:144:1 + --> $DIR/raw-bytes.rs:141:1 | LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:: { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -274,7 +274,7 @@ LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit: } error[E0080]: constructing invalid value of type &MyStr: at ..0, encountered uninitialized memory, but expected a string - --> $DIR/raw-bytes.rs:146:1 + --> $DIR/raw-bytes.rs:143:1 | LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:: { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -285,7 +285,7 @@ LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUni } error[E0080]: constructing invalid value of type &MyStr: at ..0, encountered a pointer, but expected a string - --> $DIR/raw-bytes.rs:148:1 + --> $DIR/raw-bytes.rs:145:1 | LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -298,7 +298,7 @@ LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _> } error[E0080]: constructing invalid value of type &[u8]: encountered a dangling reference (going beyond the bounds of its allocation) - --> $DIR/raw-bytes.rs:152:1 + --> $DIR/raw-bytes.rs:149:1 | LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -309,7 +309,7 @@ LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; } error[E0080]: constructing invalid value of type &[u32]: encountered invalid reference metadata: slice is bigger than largest supported object - --> $DIR/raw-bytes.rs:154:1 + --> $DIR/raw-bytes.rs:151:1 | LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -320,7 +320,7 @@ LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, is } error[E0080]: constructing invalid value of type Box<[u8]>: encountered a dangling box (going beyond the bounds of its allocation) - --> $DIR/raw-bytes.rs:157:1 + --> $DIR/raw-bytes.rs:154:1 | LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -331,7 +331,7 @@ LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999us } error[E0080]: constructing invalid value of type &[bool; 1]: at .[0], encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:160:1 + --> $DIR/raw-bytes.rs:157:1 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -342,13 +342,13 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; } note: erroneous constant encountered - --> $DIR/raw-bytes.rs:160:40 + --> $DIR/raw-bytes.rs:157:40 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..0, encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:164:1 + --> $DIR/raw-bytes.rs:161:1 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -359,13 +359,13 @@ LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3 } note: erroneous constant encountered - --> $DIR/raw-bytes.rs:164:42 + --> $DIR/raw-bytes.rs:161:42 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..1[0], encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:167:1 + --> $DIR/raw-bytes.rs:164:1 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -376,13 +376,13 @@ LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::tran } note: erroneous constant encountered - --> $DIR/raw-bytes.rs:167:42 + --> $DIR/raw-bytes.rs:164:42 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered ALLOC17, but expected a vtable pointer - --> $DIR/raw-bytes.rs:171:1 + --> $DIR/raw-bytes.rs:168:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -393,7 +393,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W(( } error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered ALLOC19, but expected a vtable pointer - --> $DIR/raw-bytes.rs:174:1 + --> $DIR/raw-bytes.rs:171:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -404,7 +404,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W(( } error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered 0x4[noalloc], but expected a vtable pointer - --> $DIR/raw-bytes.rs:177:1 + --> $DIR/raw-bytes.rs:174:1 | LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -415,7 +415,7 @@ LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u } error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered ALLOC22, but expected a vtable pointer - --> $DIR/raw-bytes.rs:179:1 + --> $DIR/raw-bytes.rs:176:1 | LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -426,7 +426,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::trans } error[E0080]: constructing invalid value of type &dyn Trait: at .., encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:182:1 + --> $DIR/raw-bytes.rs:179:1 | LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -437,7 +437,7 @@ LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, } error[E0080]: constructing invalid value of type *const dyn Trait: encountered null pointer, but expected a vtable pointer - --> $DIR/raw-bytes.rs:185:1 + --> $DIR/raw-bytes.rs:182:1 | LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -448,7 +448,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute } error[E0080]: constructing invalid value of type *const dyn Trait: encountered ALLOC27, but expected a vtable pointer - --> $DIR/raw-bytes.rs:187:1 + --> $DIR/raw-bytes.rs:184:1 | LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -459,7 +459,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transm } error[E0080]: constructing invalid value of type &[!; 1]: encountered a reference pointing to uninhabited type [!; 1] - --> $DIR/raw-bytes.rs:191:1 + --> $DIR/raw-bytes.rs:188:1 | LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; | ^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -470,7 +470,7 @@ LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; } error[E0080]: constructing invalid value of type &[!]: at .[0], encountered a value of the never type `!` - --> $DIR/raw-bytes.rs:192:1 + --> $DIR/raw-bytes.rs:189:1 | LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; | ^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -481,7 +481,7 @@ LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; } error[E0080]: constructing invalid value of type &[!]: at .[0], encountered a value of the never type `!` - --> $DIR/raw-bytes.rs:193:1 + --> $DIR/raw-bytes.rs:190:1 | LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; | ^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -492,7 +492,7 @@ LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered uninitialized memory, but expected an integer - --> $DIR/raw-bytes.rs:196:1 + --> $DIR/raw-bytes.rs:193:1 | LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) }; | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -503,7 +503,7 @@ LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) } } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered a pointer, but expected an integer - --> $DIR/raw-bytes.rs:199:1 + --> $DIR/raw-bytes.rs:196:1 | LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem::size_of::<&u32>()) }; | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -516,7 +516,7 @@ LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem: } error[E0080]: constructing invalid value of type &[bool]: at .[0], encountered 0x11, but expected a boolean - --> $DIR/raw-bytes.rs:202:1 + --> $DIR/raw-bytes.rs:199:1 | LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) }; | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -527,7 +527,7 @@ LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) } error[E0080]: constructing invalid value of type &[u16]: at .[1], encountered uninitialized memory, but expected an integer - --> $DIR/raw-bytes.rs:206:1 + --> $DIR/raw-bytes.rs:203:1 | LL | pub static S7: &[u16] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -538,7 +538,7 @@ LL | pub static S7: &[u16] = unsafe { } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered uninitialized memory, but expected an integer - --> $DIR/raw-bytes.rs:213:1 + --> $DIR/raw-bytes.rs:210:1 | LL | pub static R4: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -549,7 +549,7 @@ LL | pub static R4: &[u8] = unsafe { } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered a pointer, but expected an integer - --> $DIR/raw-bytes.rs:218:1 + --> $DIR/raw-bytes.rs:215:1 | LL | pub static R5: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -562,7 +562,7 @@ LL | pub static R5: &[u8] = unsafe { } error[E0080]: constructing invalid value of type &[bool]: at .[0], encountered 0x11, but expected a boolean - --> $DIR/raw-bytes.rs:223:1 + --> $DIR/raw-bytes.rs:220:1 | LL | pub static R6: &[bool] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value diff --git a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr index 0f1e095719f54..07deb955d24e7 100644 --- a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr @@ -1,5 +1,5 @@ error[E0080]: constructing invalid value of type Enum: at ., encountered 0x0000000000000001, but expected a valid enum tag - --> $DIR/raw-bytes.rs:23:1 + --> $DIR/raw-bytes.rs:24:1 | LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) }; | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -10,7 +10,7 @@ LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) }; } error[E0080]: constructing invalid value of type Enum2: at ., encountered 0x0000000000000000, but expected a valid enum tag - --> $DIR/raw-bytes.rs:31:1 + --> $DIR/raw-bytes.rs:32:1 | LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -21,7 +21,7 @@ LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type UninhDiscriminant: at ., encountered an uninhabited enum variant - --> $DIR/raw-bytes.rs:45:1 + --> $DIR/raw-bytes.rs:46:1 | LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -32,7 +32,7 @@ LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute } error[E0080]: constructing invalid value of type UninhDiscriminant: at ., encountered 0x03, but expected a valid enum tag - --> $DIR/raw-bytes.rs:47:1 + --> $DIR/raw-bytes.rs:48:1 | LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -43,7 +43,7 @@ LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute } error[E0080]: constructing invalid value of type Option<(char, char)>: at ..0.1, encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`) - --> $DIR/raw-bytes.rs:53:1 + --> $DIR/raw-bytes.rs:54:1 | LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -54,7 +54,7 @@ LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::tran } error[E0080]: constructing invalid value of type NonNull: at .pointer, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:58:1 + --> $DIR/raw-bytes.rs:59:1 | LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -65,7 +65,7 @@ LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type NonZero: at .0.0, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:61:1 + --> $DIR/raw-bytes.rs:62:1 | LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -76,7 +76,7 @@ LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; } error[E0080]: constructing invalid value of type NonZero: at .0.0, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:63:1 + --> $DIR/raw-bytes.rs:64:1 | LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -86,10 +86,10 @@ LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; 00 00 00 00 00 00 00 00 │ ........ } -error[E0080]: constructing invalid value of type RestrictedRange1: encountered 42, but expected something in the range 10..=30 - --> $DIR/raw-bytes.rs:69:1 +error[E0080]: constructing invalid value of type RestrictedRange1: at .0, encountered 42, but expected something in the range 10..=30 + --> $DIR/raw-bytes.rs:68:1 | -LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; +LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(mem::transmute(42_u32)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. @@ -97,10 +97,10 @@ LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; 2a 00 00 00 │ *... } -error[E0080]: constructing invalid value of type RestrictedRange2: encountered 20, but expected something less or equal to 10, or greater or equal to 30 - --> $DIR/raw-bytes.rs:75:1 +error[E0080]: constructing invalid value of type RestrictedRange2: at .0, encountered 20, but expected something less or equal to 10, or greater or equal to 30 + --> $DIR/raw-bytes.rs:72:1 | -LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; +LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(mem::transmute(20_i32)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. @@ -109,7 +109,7 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; } error[E0080]: constructing invalid value of type NonNull: at .pointer, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:78:1 + --> $DIR/raw-bytes.rs:75:1 | LL | const NULL_FAT_PTR: NonNull = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -120,7 +120,7 @@ LL | const NULL_FAT_PTR: NonNull = unsafe { } error[E0080]: constructing invalid value of type &u16: encountered an unaligned reference (required 2 byte alignment but found 1) - --> $DIR/raw-bytes.rs:85:1 + --> $DIR/raw-bytes.rs:82:1 | LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -131,7 +131,7 @@ LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; } error[E0080]: constructing invalid value of type Box: encountered an unaligned box (required 2 byte alignment but found 1) - --> $DIR/raw-bytes.rs:88:1 + --> $DIR/raw-bytes.rs:85:1 | LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -142,7 +142,7 @@ LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; } error[E0080]: constructing invalid value of type &u16: encountered a null reference - --> $DIR/raw-bytes.rs:91:1 + --> $DIR/raw-bytes.rs:88:1 | LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -153,7 +153,7 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type Box: encountered a null box - --> $DIR/raw-bytes.rs:94:1 + --> $DIR/raw-bytes.rs:91:1 | LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -164,7 +164,7 @@ LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type &u8: encountered a dangling reference (0x539[noalloc] has no provenance) - --> $DIR/raw-bytes.rs:97:1 + --> $DIR/raw-bytes.rs:94:1 | LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -175,7 +175,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; } error[E0080]: constructing invalid value of type Box: encountered a dangling box (0x539[noalloc] has no provenance) - --> $DIR/raw-bytes.rs:100:1 + --> $DIR/raw-bytes.rs:97:1 | LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -186,7 +186,7 @@ LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; } error[E0080]: constructing invalid value of type fn(): encountered null pointer, but expected a function pointer - --> $DIR/raw-bytes.rs:103:1 + --> $DIR/raw-bytes.rs:100:1 | LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -197,7 +197,7 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type fn(): encountered 0xd[noalloc], but expected a function pointer - --> $DIR/raw-bytes.rs:105:1 + --> $DIR/raw-bytes.rs:102:1 | LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -208,7 +208,7 @@ LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; } error[E0080]: constructing invalid value of type fn(): encountered ALLOC3, but expected a function pointer - --> $DIR/raw-bytes.rs:107:1 + --> $DIR/raw-bytes.rs:104:1 | LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -219,7 +219,7 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; } error[E0080]: constructing invalid value of type &Bar: encountered a reference pointing to uninhabited type Bar - --> $DIR/raw-bytes.rs:113:1 + --> $DIR/raw-bytes.rs:110:1 | LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -230,7 +230,7 @@ LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; } error[E0080]: constructing invalid value of type &str: encountered a dangling reference (going beyond the bounds of its allocation) - --> $DIR/raw-bytes.rs:137:1 + --> $DIR/raw-bytes.rs:134:1 | LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -241,7 +241,7 @@ LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) }; } error[E0080]: constructing invalid value of type (&str,): at .0, encountered invalid reference metadata: slice is bigger than largest supported object - --> $DIR/raw-bytes.rs:139:1 + --> $DIR/raw-bytes.rs:136:1 | LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -252,7 +252,7 @@ LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, us } error[E0080]: constructing invalid value of type &MyStr: encountered invalid reference metadata: slice is bigger than largest supported object - --> $DIR/raw-bytes.rs:141:1 + --> $DIR/raw-bytes.rs:138:1 | LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -263,7 +263,7 @@ LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize: } error[E0080]: constructing invalid value of type &str: at ., encountered uninitialized memory, but expected a string - --> $DIR/raw-bytes.rs:144:1 + --> $DIR/raw-bytes.rs:141:1 | LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:: { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -274,7 +274,7 @@ LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit: } error[E0080]: constructing invalid value of type &MyStr: at ..0, encountered uninitialized memory, but expected a string - --> $DIR/raw-bytes.rs:146:1 + --> $DIR/raw-bytes.rs:143:1 | LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:: { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -285,7 +285,7 @@ LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUni } error[E0080]: constructing invalid value of type &MyStr: at ..0, encountered a pointer, but expected a string - --> $DIR/raw-bytes.rs:148:1 + --> $DIR/raw-bytes.rs:145:1 | LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -298,7 +298,7 @@ LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _> } error[E0080]: constructing invalid value of type &[u8]: encountered a dangling reference (going beyond the bounds of its allocation) - --> $DIR/raw-bytes.rs:152:1 + --> $DIR/raw-bytes.rs:149:1 | LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -309,7 +309,7 @@ LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; } error[E0080]: constructing invalid value of type &[u32]: encountered invalid reference metadata: slice is bigger than largest supported object - --> $DIR/raw-bytes.rs:154:1 + --> $DIR/raw-bytes.rs:151:1 | LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -320,7 +320,7 @@ LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, is } error[E0080]: constructing invalid value of type Box<[u8]>: encountered a dangling box (going beyond the bounds of its allocation) - --> $DIR/raw-bytes.rs:157:1 + --> $DIR/raw-bytes.rs:154:1 | LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -331,7 +331,7 @@ LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999us } error[E0080]: constructing invalid value of type &[bool; 1]: at .[0], encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:160:1 + --> $DIR/raw-bytes.rs:157:1 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -342,13 +342,13 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; } note: erroneous constant encountered - --> $DIR/raw-bytes.rs:160:40 + --> $DIR/raw-bytes.rs:157:40 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..0, encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:164:1 + --> $DIR/raw-bytes.rs:161:1 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -359,13 +359,13 @@ LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3 } note: erroneous constant encountered - --> $DIR/raw-bytes.rs:164:42 + --> $DIR/raw-bytes.rs:161:42 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..1[0], encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:167:1 + --> $DIR/raw-bytes.rs:164:1 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -376,13 +376,13 @@ LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::tran } note: erroneous constant encountered - --> $DIR/raw-bytes.rs:167:42 + --> $DIR/raw-bytes.rs:164:42 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered ALLOC17, but expected a vtable pointer - --> $DIR/raw-bytes.rs:171:1 + --> $DIR/raw-bytes.rs:168:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -393,7 +393,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W(( } error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered ALLOC19, but expected a vtable pointer - --> $DIR/raw-bytes.rs:174:1 + --> $DIR/raw-bytes.rs:171:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -404,7 +404,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W(( } error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered 0x4[noalloc], but expected a vtable pointer - --> $DIR/raw-bytes.rs:177:1 + --> $DIR/raw-bytes.rs:174:1 | LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -415,7 +415,7 @@ LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u } error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered ALLOC22, but expected a vtable pointer - --> $DIR/raw-bytes.rs:179:1 + --> $DIR/raw-bytes.rs:176:1 | LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -426,7 +426,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::trans } error[E0080]: constructing invalid value of type &dyn Trait: at .., encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:182:1 + --> $DIR/raw-bytes.rs:179:1 | LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -437,7 +437,7 @@ LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, } error[E0080]: constructing invalid value of type *const dyn Trait: encountered null pointer, but expected a vtable pointer - --> $DIR/raw-bytes.rs:185:1 + --> $DIR/raw-bytes.rs:182:1 | LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -448,7 +448,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute } error[E0080]: constructing invalid value of type *const dyn Trait: encountered ALLOC27, but expected a vtable pointer - --> $DIR/raw-bytes.rs:187:1 + --> $DIR/raw-bytes.rs:184:1 | LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -459,7 +459,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transm } error[E0080]: constructing invalid value of type &[!; 1]: encountered a reference pointing to uninhabited type [!; 1] - --> $DIR/raw-bytes.rs:191:1 + --> $DIR/raw-bytes.rs:188:1 | LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; | ^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -470,7 +470,7 @@ LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; } error[E0080]: constructing invalid value of type &[!]: at .[0], encountered a value of the never type `!` - --> $DIR/raw-bytes.rs:192:1 + --> $DIR/raw-bytes.rs:189:1 | LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; | ^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -481,7 +481,7 @@ LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; } error[E0080]: constructing invalid value of type &[!]: at .[0], encountered a value of the never type `!` - --> $DIR/raw-bytes.rs:193:1 + --> $DIR/raw-bytes.rs:190:1 | LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; | ^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -492,7 +492,7 @@ LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered uninitialized memory, but expected an integer - --> $DIR/raw-bytes.rs:196:1 + --> $DIR/raw-bytes.rs:193:1 | LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) }; | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -503,7 +503,7 @@ LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) } } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered a pointer, but expected an integer - --> $DIR/raw-bytes.rs:199:1 + --> $DIR/raw-bytes.rs:196:1 | LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem::size_of::<&u32>()) }; | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -516,7 +516,7 @@ LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem: } error[E0080]: constructing invalid value of type &[bool]: at .[0], encountered 0x11, but expected a boolean - --> $DIR/raw-bytes.rs:202:1 + --> $DIR/raw-bytes.rs:199:1 | LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) }; | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -527,7 +527,7 @@ LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) } error[E0080]: constructing invalid value of type &[u16]: at .[1], encountered uninitialized memory, but expected an integer - --> $DIR/raw-bytes.rs:206:1 + --> $DIR/raw-bytes.rs:203:1 | LL | pub static S7: &[u16] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -538,7 +538,7 @@ LL | pub static S7: &[u16] = unsafe { } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered uninitialized memory, but expected an integer - --> $DIR/raw-bytes.rs:213:1 + --> $DIR/raw-bytes.rs:210:1 | LL | pub static R4: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -549,7 +549,7 @@ LL | pub static R4: &[u8] = unsafe { } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered a pointer, but expected an integer - --> $DIR/raw-bytes.rs:218:1 + --> $DIR/raw-bytes.rs:215:1 | LL | pub static R5: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -562,7 +562,7 @@ LL | pub static R5: &[u8] = unsafe { } error[E0080]: constructing invalid value of type &[bool]: at .[0], encountered 0x11, but expected a boolean - --> $DIR/raw-bytes.rs:223:1 + --> $DIR/raw-bytes.rs:220:1 | LL | pub static R6: &[bool] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value diff --git a/tests/ui/consts/const-eval/raw-bytes.rs b/tests/ui/consts/const-eval/raw-bytes.rs index d63e1d5b062cf..acaf8c8310aab 100644 --- a/tests/ui/consts/const-eval/raw-bytes.rs +++ b/tests/ui/consts/const-eval/raw-bytes.rs @@ -6,6 +6,7 @@ //@ ignore-parallel-frontend different alloc ids #![allow(invalid_value, unnecessary_transmutes)] #![feature(never_type, rustc_attrs, ptr_metadata, slice_from_ptr_range, const_slice_from_ptr_range)] +#![feature(pattern_types, pattern_type_macro)] use std::mem; use std::alloc::Layout; @@ -63,16 +64,12 @@ const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; //~^ ERROR constructing invalid value -#[rustc_layout_scalar_valid_range_start(10)] -#[rustc_layout_scalar_valid_range_end(30)] -struct RestrictedRange1(u32); -const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; +struct RestrictedRange1(std::pat::pattern_type!(u32 is 10..=30)); +const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(mem::transmute(42_u32)) }; //~^ ERROR constructing invalid value -#[rustc_layout_scalar_valid_range_start(30)] -#[rustc_layout_scalar_valid_range_end(10)] -struct RestrictedRange2(u32); -const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; +struct RestrictedRange2(std::pat::pattern_type!(i32 is 30.. | ..=10)); +const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(mem::transmute(20_i32)) }; //~^ ERROR constructing invalid value const NULL_FAT_PTR: NonNull = unsafe { diff --git a/tests/ui/consts/const-eval/ub-nonnull.rs b/tests/ui/consts/const-eval/ub-nonnull.rs index daa4c40f98a96..b6aca0684b84d 100644 --- a/tests/ui/consts/const-eval/ub-nonnull.rs +++ b/tests/ui/consts/const-eval/ub-nonnull.rs @@ -36,20 +36,6 @@ union MaybeUninit { const UNINIT: NonZero = unsafe { MaybeUninit { uninit: () }.init }; //~^ ERROR uninitialized -// Also test other uses of rustc_layout_scalar_valid_range_start - -#[rustc_layout_scalar_valid_range_start(10)] -#[rustc_layout_scalar_valid_range_end(30)] -struct RestrictedRange1(u32); -const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; -//~^ ERROR invalid value - -#[rustc_layout_scalar_valid_range_start(30)] -#[rustc_layout_scalar_valid_range_end(10)] -struct RestrictedRange2(u32); -const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; -//~^ ERROR invalid value - const NULL_FAT_PTR: NonNull = unsafe { //~^ ERROR invalid value let x: &dyn Send = &42; diff --git a/tests/ui/consts/const-eval/ub-nonnull.stderr b/tests/ui/consts/const-eval/ub-nonnull.stderr index 9c88f149b32e9..5bd23944ed5be 100644 --- a/tests/ui/consts/const-eval/ub-nonnull.stderr +++ b/tests/ui/consts/const-eval/ub-nonnull.stderr @@ -47,30 +47,8 @@ LL | const UNINIT: NonZero = unsafe { MaybeUninit { uninit: () }.init }; __ │ ░ } -error[E0080]: constructing invalid value of type RestrictedRange1: encountered 42, but expected something in the range 10..=30 - --> $DIR/ub-nonnull.rs:44:1 - | -LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value - | - = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. - = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { - HEX_DUMP - } - -error[E0080]: constructing invalid value of type RestrictedRange2: encountered 20, but expected something less or equal to 10, or greater or equal to 30 - --> $DIR/ub-nonnull.rs:50:1 - | -LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value - | - = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. - = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { - HEX_DUMP - } - error[E0080]: constructing invalid value of type NonNull: at .pointer, encountered 0, but expected something greater or equal to 1 - --> $DIR/ub-nonnull.rs:53:1 + --> $DIR/ub-nonnull.rs:39:1 | LL | const NULL_FAT_PTR: NonNull = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -81,7 +59,7 @@ LL | const NULL_FAT_PTR: NonNull = unsafe { } error[E0080]: constructing invalid value of type NonNull<()>: at .pointer, encountered a maybe-null pointer, but expected something that is definitely non-zero - --> $DIR/ub-nonnull.rs:61:1 + --> $DIR/ub-nonnull.rs:47:1 | LL | const MAYBE_NULL_PTR: NonNull<()> = unsafe { mem::transmute((&raw const S).wrapping_add(4)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -91,6 +69,6 @@ LL | const MAYBE_NULL_PTR: NonNull<()> = unsafe { mem::transmute((&raw const S). HEX_DUMP } -error: aborting due to 9 previous errors +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/const-eval/ub-ref-ptr.rs b/tests/ui/consts/const-eval/ub-ref-ptr.rs index 5cc327797a139..1f92e8edec2ca 100644 --- a/tests/ui/consts/const-eval/ub-ref-ptr.rs +++ b/tests/ui/consts/const-eval/ub-ref-ptr.rs @@ -4,10 +4,10 @@ //@ normalize-stderr: "([0-9a-f][0-9a-f] |__ |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?()?─*╼ )+ *│.*" -> "HEX_DUMP" //@ dont-require-annotations: NOTE //@ normalize-stderr: "0x[0-9](\.\.|\])" -> "0x%$1" -#![feature(rustc_attrs)] +#![feature(pattern_types, pattern_type_macro)] #![allow(invalid_value)] //@ ignore-parallel-frontend different alloc ids -use std::mem; +use std::{mem, pat::pattern_type}; #[repr(C)] union MaybeUninit { @@ -75,14 +75,15 @@ const UNALIGNED_READ: () = unsafe { ptr.read(); //~ ERROR accessing memory }; -// Check the general case of a pointer value not falling into the scalar valid range. -#[rustc_layout_scalar_valid_range_start(1000)] +/* +FIXME(pattern_types): allow for other integer range restricitons on raw pointers? pub struct High { - pointer: *const (), + pointer: pattern_type!(*const () is 1000..), } static S: u32 = 0; // just a static to construct a pointer with unknown absolute address const INVALID_VALUE_PTR: High = unsafe { mem::transmute(&S) }; -//~^ ERROR invalid value +//^ ERROR invalid value +*/ fn main() {} diff --git a/tests/ui/consts/const-eval/ub-ref-ptr.stderr b/tests/ui/consts/const-eval/ub-ref-ptr.stderr index 17ddea05e93f7..1087d89f6389d 100644 --- a/tests/ui/consts/const-eval/ub-ref-ptr.stderr +++ b/tests/ui/consts/const-eval/ub-ref-ptr.stderr @@ -114,7 +114,7 @@ LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; HEX_DUMP } -error[E0080]: reading memory at ALLOC6[0x%..0x%], but memory is uninitialized at [0x%..0x%], and this operation requires initialized memory +error[E0080]: reading memory at ALLOC5[0x%..0x%], but memory is uninitialized at [0x%..0x%], and this operation requires initialized memory --> $DIR/ub-ref-ptr.rs:54:41 | LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init }; @@ -135,7 +135,7 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; HEX_DUMP } -error[E0080]: reading memory at ALLOC7[0x%..0x%], but memory is uninitialized at [0x%..0x%], and this operation requires initialized memory +error[E0080]: reading memory at ALLOC6[0x%..0x%], but memory is uninitialized at [0x%..0x%], and this operation requires initialized memory --> $DIR/ub-ref-ptr.rs:59:38 | LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init }; @@ -184,17 +184,6 @@ error[E0080]: accessing memory based on pointer with alignment 1, but alignment LL | ptr.read(); | ^^^^^^^^^^ evaluation of `UNALIGNED_READ` failed here -error[E0080]: constructing invalid value of type High: encountered a pointer with unknown absolute address, but expected something that is definitely greater or equal to 1000 - --> $DIR/ub-ref-ptr.rs:84:1 - | -LL | const INVALID_VALUE_PTR: High = unsafe { mem::transmute(&S) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value - | - = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. - = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { - HEX_DUMP - } - -error: aborting due to 18 previous errors +error: aborting due to 17 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/delegation/bad-resolve.rs b/tests/ui/delegation/bad-resolve.rs index 5744bd1f994c8..2c2c622e09006 100644 --- a/tests/ui/delegation/bad-resolve.rs +++ b/tests/ui/delegation/bad-resolve.rs @@ -41,5 +41,6 @@ impl Trait for S { mod prefix {} reuse unresolved_prefix::{a, b, c}; //~ ERROR cannot find module or crate `unresolved_prefix` reuse prefix::{self, super, crate}; //~ ERROR `crate` in paths can only be used in start position +//~^ ERROR expected function, found module `prefix::self` fn main() {} diff --git a/tests/ui/delegation/bad-resolve.stderr b/tests/ui/delegation/bad-resolve.stderr index f79eaa5bfc28f..d1b3974e77081 100644 --- a/tests/ui/delegation/bad-resolve.stderr +++ b/tests/ui/delegation/bad-resolve.stderr @@ -82,6 +82,12 @@ LL - reuse Trait::foo2 { self.0 } LL + reuse Trait::foo { self.0 } | +error[E0423]: expected function, found module `prefix::self` + --> $DIR/bad-resolve.rs:43:7 + | +LL | reuse prefix::{self, super, crate}; + | ^^^^^^ not a function + error[E0046]: not all trait items implemented, missing: `Type` --> $DIR/bad-resolve.rs:21:1 | @@ -105,7 +111,7 @@ error[E0433]: `crate` in paths can only be used in start position LL | reuse prefix::{self, super, crate}; | ^^^^^ can only be used in path start position -error: aborting due to 12 previous errors +error: aborting due to 13 previous errors Some errors have detailed explanations: E0046, E0324, E0407, E0423, E0425, E0433, E0575, E0576. For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/enum-discriminant/ptr_niche.rs b/tests/ui/enum-discriminant/ptr_niche.rs index 32df08bce6345..45dbe50248217 100644 --- a/tests/ui/enum-discriminant/ptr_niche.rs +++ b/tests/ui/enum-discriminant/ptr_niche.rs @@ -2,37 +2,41 @@ //! Check that we can codegen setting and getting discriminants, including non-null niches, //! for enums with a pointer-like ABI. This used to crash llvm. -#![feature(rustc_attrs)] -use std::{ptr, mem}; +#![feature(rustc_attrs, pattern_types, pattern_type_macro)] +use std::{ptr, mem, pat::pattern_type}; - -#[rustc_layout_scalar_valid_range_start(1)] -#[rustc_layout_scalar_valid_range_end(100)] #[derive(Copy, Clone)] -struct PointerWithRange(#[allow(dead_code)] *const u8); +struct PointerWithRange(#[allow(dead_code)] pattern_type!(*const u8 is !null)); fn main() { - let val = unsafe { PointerWithRange(ptr::without_provenance(90)) }; + let val = + unsafe { PointerWithRange(mem::transmute::<*const u8, _>(ptr::without_provenance(90))) }; let ptr = Some(val); assert!(ptr.is_some()); let raw = unsafe { mem::transmute::<_, usize>(ptr) }; assert_eq!(raw, 90); + /* + FIXME(pattern_types): allow restricting raw pointers to smaller integer ranges? let ptr = Some(Some(val)); assert!(ptr.is_some()); assert!(ptr.unwrap().is_some()); let raw = unsafe { mem::transmute::<_, usize>(ptr) }; assert_eq!(raw, 90); + */ let ptr: Option = None; assert!(ptr.is_none()); let raw = unsafe { mem::transmute::<_, usize>(ptr) }; assert!(!(1..=100).contains(&raw)); + /* + FIXME(pattern_types): allow restricting raw pointers to smaller integer ranges? let ptr: Option> = None; assert!(ptr.is_none()); let raw = unsafe { mem::transmute::<_, usize>(ptr) }; assert!(!(1..=100).contains(&raw)); + */ } diff --git a/tests/ui/error-codes/E0429.rs b/tests/ui/error-codes/E0429.rs index e74b27a78b67d..234ff52cff709 100644 --- a/tests/ui/error-codes/E0429.rs +++ b/tests/ui/error-codes/E0429.rs @@ -1,4 +1,6 @@ -use std::fmt::self; //~ ERROR E0429 +//@ check-pass + +use std::fmt::self; fn main () { } diff --git a/tests/ui/error-codes/E0429.stderr b/tests/ui/error-codes/E0429.stderr deleted file mode 100644 index d2d9ba209f745..0000000000000 --- a/tests/ui/error-codes/E0429.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/E0429.rs:1:13 - | -LL | use std::fmt::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use std::fmt::self; -LL + use std::fmt; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use std::fmt::{self}; - | + + - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0429`. diff --git a/tests/ui/impl-trait/unsafety-checking-cycle.rs b/tests/ui/impl-trait/unsafety-checking-cycle.rs deleted file mode 100644 index 2306f079e5da8..0000000000000 --- a/tests/ui/impl-trait/unsafety-checking-cycle.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Ensure that we don't get a cycle error from trying to determine whether an -// opaque type implements `Freeze` in safety checking, when it doesn't matter. - -//@ check-pass - -#![feature(rustc_attrs)] - -struct AnyValue(T); - -// No need to check for `Freeze` here, there's no -// `rustc_layout_scalar_valid_range_start` involved. -fn not_restricted(c: bool) -> impl Sized { - if c { - let x = AnyValue(not_restricted(false)); - &x.0; - } - 2u32 -} - -#[rustc_layout_scalar_valid_range_start(1)] -struct NonZero(T); - -// No need to check for `Freeze` here, we're not borrowing the field. -fn not_field(c: bool) -> impl Sized { - if c { - let x = unsafe { NonZero(not_field(false)) }; - &x; - } - 5u32 -} - -fn main() {} diff --git a/tests/ui/imports/absolute-paths-in-nested-use-groups.rs b/tests/ui/imports/absolute-paths-in-nested-use-groups.rs index 9a8c9aab72828..9f6799ce7eff5 100644 --- a/tests/ui/imports/absolute-paths-in-nested-use-groups.rs +++ b/tests/ui/imports/absolute-paths-in-nested-use-groups.rs @@ -8,7 +8,7 @@ use foo::{ super::bar, //~^ ERROR: `super` in paths can only be used in start position self::bar, - //~^ ERROR: `self` in paths can only be used in start position + //~^ ERROR: `self` in paths can only be used in start position or last position }; fn main() {} diff --git a/tests/ui/imports/absolute-paths-in-nested-use-groups.stderr b/tests/ui/imports/absolute-paths-in-nested-use-groups.stderr index ff951ad7489c7..48ea0ad32400f 100644 --- a/tests/ui/imports/absolute-paths-in-nested-use-groups.stderr +++ b/tests/ui/imports/absolute-paths-in-nested-use-groups.stderr @@ -1,3 +1,9 @@ +error: `self` in paths can only be used in start position or last position + --> $DIR/absolute-paths-in-nested-use-groups.rs:10:5 + | +LL | self::bar, + | ^^^^ + error[E0433]: the crate root in paths can only be used in start position --> $DIR/absolute-paths-in-nested-use-groups.rs:6:5 | @@ -10,12 +16,6 @@ error[E0433]: `super` in paths can only be used in start position LL | super::bar, | ^^^^^ can only be used in path start position -error[E0433]: `self` in paths can only be used in start position - --> $DIR/absolute-paths-in-nested-use-groups.rs:10:5 - | -LL | self::bar, - | ^^^^ can only be used in path start position - error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/imports/issue-45829/import-self.rs b/tests/ui/imports/issue-45829/import-self.rs index 2dc4331ced775..deff8dcbeacc6 100644 --- a/tests/ui/imports/issue-45829/import-self.rs +++ b/tests/ui/imports/issue-45829/import-self.rs @@ -10,7 +10,6 @@ use foo as self; //~^ ERROR expected identifier use foo::self; //~ ERROR is defined multiple times -//~^ ERROR `self` imports are only allowed within a { } list use foo::A; use foo::{self as A}; diff --git a/tests/ui/imports/issue-45829/import-self.stderr b/tests/ui/imports/issue-45829/import-self.stderr index 458bad618754c..978d20490b282 100644 --- a/tests/ui/imports/issue-45829/import-self.stderr +++ b/tests/ui/imports/issue-45829/import-self.stderr @@ -4,22 +4,6 @@ error: expected identifier, found keyword `self` LL | use foo as self; | ^^^^ expected identifier, found keyword -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/import-self.rs:12:8 - | -LL | use foo::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use foo::self; -LL + use foo; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use foo::{self}; - | + + - error[E0255]: the name `foo` is defined multiple times --> $DIR/import-self.rs:6:11 | @@ -51,7 +35,7 @@ LL | use foo::self as other_foo; | ++++++++++++ error[E0252]: the name `A` is defined multiple times - --> $DIR/import-self.rs:16:11 + --> $DIR/import-self.rs:15:11 | LL | use foo::A; | ------ previous import of the type `A` here @@ -64,7 +48,7 @@ help: you can use `as` to change the binding name of the import LL | use foo::{self as OtherA}; | +++++ -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0252, E0255, E0429. +Some errors have detailed explanations: E0252, E0255. For more information about an error, try `rustc --explain E0252`. diff --git a/tests/ui/imports/issue-47623.stderr b/tests/ui/imports/issue-47623.stderr index 64f443bf69e48..21baf29bd9521 100644 --- a/tests/ui/imports/issue-47623.stderr +++ b/tests/ui/imports/issue-47623.stderr @@ -3,6 +3,11 @@ error: imports need to be explicitly named | LL | use self; | ^^^^ + | +help: try renaming it with a name + | +LL | use self as name; + | +++++++ error: aborting due to 1 previous error diff --git a/tests/ui/layout/valid_range_oob.rs b/tests/ui/layout/valid_range_oob.rs deleted file mode 100644 index 8ae9f6e97260c..0000000000000 --- a/tests/ui/layout/valid_range_oob.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ failure-status: 101 -//@ normalize-stderr: "note: .*\n\n" -> "" -//@ normalize-stderr: "thread 'rustc'.*panicked.*\n" -> "" -//@ rustc-env:RUST_BACKTRACE=0 - -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_end(257)] -struct Foo(i8); - -// Need to do in a constant, as runtime codegen -// does not compute the layout of `Foo` in check builds. -const FOO: Foo = unsafe { Foo(1) }; - -fn main() {} diff --git a/tests/ui/layout/valid_range_oob.stderr b/tests/ui/layout/valid_range_oob.stderr deleted file mode 100644 index fc6ebcf1692fe..0000000000000 --- a/tests/ui/layout/valid_range_oob.stderr +++ /dev/null @@ -1,8 +0,0 @@ - -257 > 255 -error: the compiler unexpectedly panicked. This is a bug - -query stack during panic: -#0 [layout_of] computing layout of `Foo` -#1 [eval_to_allocation_raw] const-evaluating + checking `FOO` -... and 2 other queries... use `env RUST_BACKTRACE=1` to see the full query stack diff --git a/tests/ui/lint/invalid_value.rs b/tests/ui/lint/invalid_value.rs index 29e8e6cfef6dd..54435583b1341 100644 --- a/tests/ui/lint/invalid_value.rs +++ b/tests/ui/lint/invalid_value.rs @@ -2,11 +2,12 @@ // in a lint. #![allow(deprecated)] #![deny(invalid_value)] -#![feature(never_type, rustc_attrs)] +#![feature(never_type, rustc_attrs, pattern_types, pattern_type_macro)] use std::mem::{self, MaybeUninit}; use std::ptr::NonNull; use std::num::NonZero; +use std::pat::pattern_type; enum Void {} @@ -16,10 +17,8 @@ struct RefPair((&'static i32, i32)); struct Wrap { wrapped: T } enum WrapEnum { Wrapped(T) } -#[rustc_layout_scalar_valid_range_start(0)] -#[rustc_layout_scalar_valid_range_end(128)] #[repr(transparent)] -pub(crate) struct NonBig(u64); +pub(crate) struct NonBig(pattern_type!(u64 is 0..=128)); /// A two-variant enum, thus needs a tag and may not remain uninitialized. enum Fruit { @@ -43,9 +42,7 @@ enum TwoUninhabited { B(Void), } -#[rustc_layout_scalar_valid_range_start(254)] -#[rustc_layout_scalar_valid_range_end(1)] -pub(crate) struct WrapAroundRange(u8); +pub(crate) struct WrapAroundRange(pattern_type!(i8 is -1..=1)); #[allow(unused)] fn generic() { diff --git a/tests/ui/lint/invalid_value.stderr b/tests/ui/lint/invalid_value.stderr index 63df1e5d11d68..8500d3732e1a4 100644 --- a/tests/ui/lint/invalid_value.stderr +++ b/tests/ui/lint/invalid_value.stderr @@ -1,5 +1,5 @@ error: the type `&T` does not permit zero-initialization - --> $DIR/invalid_value.rs:53:32 + --> $DIR/invalid_value.rs:50:32 | LL | let _val: &'static T = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | #![deny(invalid_value)] | ^^^^^^^^^^^^^ error: the type `&T` does not permit being left uninitialized - --> $DIR/invalid_value.rs:54:32 + --> $DIR/invalid_value.rs:51:32 | LL | let _val: &'static T = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | let _val: &'static T = mem::uninitialized(); = note: references must be non-null error: the type `Wrap<&T>` does not permit zero-initialization - --> $DIR/invalid_value.rs:56:38 + --> $DIR/invalid_value.rs:53:38 | LL | let _val: Wrap<&'static T> = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -36,13 +36,13 @@ LL | let _val: Wrap<&'static T> = mem::zeroed(); | = note: `Wrap<&T>` must be non-null note: because references must be non-null (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ error: the type `Wrap<&T>` does not permit being left uninitialized - --> $DIR/invalid_value.rs:57:38 + --> $DIR/invalid_value.rs:54:38 | LL | let _val: Wrap<&'static T> = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -52,13 +52,13 @@ LL | let _val: Wrap<&'static T> = mem::uninitialized(); | = note: `Wrap<&T>` must be non-null note: because references must be non-null (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ error: the type `!` does not permit zero-initialization - --> $DIR/invalid_value.rs:64:23 + --> $DIR/invalid_value.rs:61:23 | LL | let _val: ! = mem::zeroed(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -66,7 +66,7 @@ LL | let _val: ! = mem::zeroed(); = note: the `!` type has no valid value error: the type `!` does not permit being left uninitialized - --> $DIR/invalid_value.rs:65:23 + --> $DIR/invalid_value.rs:62:23 | LL | let _val: ! = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -74,7 +74,7 @@ LL | let _val: ! = mem::uninitialized(); = note: the `!` type has no valid value error: the type `(i32, !)` does not permit zero-initialization - --> $DIR/invalid_value.rs:67:30 + --> $DIR/invalid_value.rs:64:30 | LL | let _val: (i32, !) = mem::zeroed(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -82,7 +82,7 @@ LL | let _val: (i32, !) = mem::zeroed(); = note: the `!` type has no valid value error: the type `(i32, !)` does not permit being left uninitialized - --> $DIR/invalid_value.rs:68:30 + --> $DIR/invalid_value.rs:65:30 | LL | let _val: (i32, !) = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -90,31 +90,31 @@ LL | let _val: (i32, !) = mem::uninitialized(); = note: integers must be initialized error: the type `Void` does not permit zero-initialization - --> $DIR/invalid_value.rs:70:26 + --> $DIR/invalid_value.rs:67:26 | LL | let _val: Void = mem::zeroed(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed | note: enums with no inhabited variants have no valid value - --> $DIR/invalid_value.rs:11:1 + --> $DIR/invalid_value.rs:12:1 | LL | enum Void {} | ^^^^^^^^^ error: the type `Void` does not permit being left uninitialized - --> $DIR/invalid_value.rs:71:26 + --> $DIR/invalid_value.rs:68:26 | LL | let _val: Void = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | note: enums with no inhabited variants have no valid value - --> $DIR/invalid_value.rs:11:1 + --> $DIR/invalid_value.rs:12:1 | LL | enum Void {} | ^^^^^^^^^ error: the type `&i32` does not permit zero-initialization - --> $DIR/invalid_value.rs:73:34 + --> $DIR/invalid_value.rs:70:34 | LL | let _val: &'static i32 = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -125,7 +125,7 @@ LL | let _val: &'static i32 = mem::zeroed(); = note: references must be non-null error: the type `&i32` does not permit being left uninitialized - --> $DIR/invalid_value.rs:74:34 + --> $DIR/invalid_value.rs:71:34 | LL | let _val: &'static i32 = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | let _val: &'static i32 = mem::uninitialized(); = note: references must be non-null error: the type `Ref` does not permit zero-initialization - --> $DIR/invalid_value.rs:76:25 + --> $DIR/invalid_value.rs:73:25 | LL | let _val: Ref = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -146,13 +146,13 @@ LL | let _val: Ref = mem::zeroed(); | = note: `Ref` must be non-null note: because references must be non-null (in this struct field) - --> $DIR/invalid_value.rs:13:12 + --> $DIR/invalid_value.rs:14:12 | LL | struct Ref(&'static i32); | ^^^^^^^^^^^^ error: the type `Ref` does not permit being left uninitialized - --> $DIR/invalid_value.rs:77:25 + --> $DIR/invalid_value.rs:74:25 | LL | let _val: Ref = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -162,13 +162,13 @@ LL | let _val: Ref = mem::uninitialized(); | = note: `Ref` must be non-null note: because references must be non-null (in this struct field) - --> $DIR/invalid_value.rs:13:12 + --> $DIR/invalid_value.rs:14:12 | LL | struct Ref(&'static i32); | ^^^^^^^^^^^^ error: the type `fn()` does not permit zero-initialization - --> $DIR/invalid_value.rs:79:26 + --> $DIR/invalid_value.rs:76:26 | LL | let _val: fn() = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -179,7 +179,7 @@ LL | let _val: fn() = mem::zeroed(); = note: function pointers must be non-null error: the type `fn()` does not permit being left uninitialized - --> $DIR/invalid_value.rs:80:26 + --> $DIR/invalid_value.rs:77:26 | LL | let _val: fn() = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -190,7 +190,7 @@ LL | let _val: fn() = mem::uninitialized(); = note: function pointers must be non-null error: the type `Wrap` does not permit zero-initialization - --> $DIR/invalid_value.rs:82:32 + --> $DIR/invalid_value.rs:79:32 | LL | let _val: Wrap = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -200,13 +200,13 @@ LL | let _val: Wrap = mem::zeroed(); | = note: `Wrap` must be non-null note: because function pointers must be non-null (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ error: the type `Wrap` does not permit being left uninitialized - --> $DIR/invalid_value.rs:83:32 + --> $DIR/invalid_value.rs:80:32 | LL | let _val: Wrap = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -216,13 +216,13 @@ LL | let _val: Wrap = mem::uninitialized(); | = note: `Wrap` must be non-null note: because function pointers must be non-null (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ error: the type `WrapEnum` does not permit zero-initialization - --> $DIR/invalid_value.rs:85:36 + --> $DIR/invalid_value.rs:82:36 | LL | let _val: WrapEnum = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -232,13 +232,13 @@ LL | let _val: WrapEnum = mem::zeroed(); | = note: `WrapEnum` must be non-null note: because function pointers must be non-null (in this field of the only potentially inhabited enum variant) - --> $DIR/invalid_value.rs:17:28 + --> $DIR/invalid_value.rs:18:28 | LL | enum WrapEnum { Wrapped(T) } | ^ error: the type `WrapEnum` does not permit being left uninitialized - --> $DIR/invalid_value.rs:86:36 + --> $DIR/invalid_value.rs:83:36 | LL | let _val: WrapEnum = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -248,13 +248,13 @@ LL | let _val: WrapEnum = mem::uninitialized(); | = note: `WrapEnum` must be non-null note: because function pointers must be non-null (in this field of the only potentially inhabited enum variant) - --> $DIR/invalid_value.rs:17:28 + --> $DIR/invalid_value.rs:18:28 | LL | enum WrapEnum { Wrapped(T) } | ^ error: the type `Wrap<(RefPair, i32)>` does not permit zero-initialization - --> $DIR/invalid_value.rs:88:42 + --> $DIR/invalid_value.rs:85:42 | LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -263,18 +263,18 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | note: `RefPair` must be non-null (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ note: because references must be non-null (in this struct field) - --> $DIR/invalid_value.rs:14:16 + --> $DIR/invalid_value.rs:15:16 | LL | struct RefPair((&'static i32, i32)); | ^^^^^^^^^^^^^^^^^^^ error: the type `Wrap<(RefPair, i32)>` does not permit being left uninitialized - --> $DIR/invalid_value.rs:89:42 + --> $DIR/invalid_value.rs:86:42 | LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -283,18 +283,18 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | note: `RefPair` must be non-null (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ note: because references must be non-null (in this struct field) - --> $DIR/invalid_value.rs:14:16 + --> $DIR/invalid_value.rs:15:16 | LL | struct RefPair((&'static i32, i32)); | ^^^^^^^^^^^^^^^^^^^ error: the type `NonNull` does not permit zero-initialization - --> $DIR/invalid_value.rs:91:34 + --> $DIR/invalid_value.rs:88:34 | LL | let _val: NonNull = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -305,7 +305,7 @@ LL | let _val: NonNull = mem::zeroed(); = note: `std::ptr::NonNull` must be non-null error: the type `NonNull` does not permit being left uninitialized - --> $DIR/invalid_value.rs:92:34 + --> $DIR/invalid_value.rs:89:34 | LL | let _val: NonNull = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -316,7 +316,7 @@ LL | let _val: NonNull = mem::uninitialized(); = note: `std::ptr::NonNull` must be non-null error: the type `(NonZero, i32)` does not permit zero-initialization - --> $DIR/invalid_value.rs:94:41 + --> $DIR/invalid_value.rs:91:41 | LL | let _val: (NonZero, i32) = mem::zeroed(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -325,7 +325,7 @@ LL | let _val: (NonZero, i32) = mem::zeroed(); = note: because `core::num::niche_types::NonZeroU32Inner` must be non-null error: the type `(NonZero, i32)` does not permit being left uninitialized - --> $DIR/invalid_value.rs:95:41 + --> $DIR/invalid_value.rs:92:41 | LL | let _val: (NonZero, i32) = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -334,7 +334,7 @@ LL | let _val: (NonZero, i32) = mem::uninitialized(); = note: because `core::num::niche_types::NonZeroU32Inner` must be non-null error: the type `*const dyn Send` does not permit zero-initialization - --> $DIR/invalid_value.rs:97:37 + --> $DIR/invalid_value.rs:94:37 | LL | let _val: *const dyn Send = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -345,7 +345,7 @@ LL | let _val: *const dyn Send = mem::zeroed(); = note: the vtable of a wide raw pointer must be non-null error: the type `*const dyn Send` does not permit being left uninitialized - --> $DIR/invalid_value.rs:98:37 + --> $DIR/invalid_value.rs:95:37 | LL | let _val: *const dyn Send = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -356,7 +356,7 @@ LL | let _val: *const dyn Send = mem::uninitialized(); = note: the vtable of a wide raw pointer must be non-null error: the type `[fn(); 2]` does not permit zero-initialization - --> $DIR/invalid_value.rs:100:31 + --> $DIR/invalid_value.rs:97:31 | LL | let _val: [fn(); 2] = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -367,7 +367,7 @@ LL | let _val: [fn(); 2] = mem::zeroed(); = note: function pointers must be non-null error: the type `[fn(); 2]` does not permit being left uninitialized - --> $DIR/invalid_value.rs:101:31 + --> $DIR/invalid_value.rs:98:31 | LL | let _val: [fn(); 2] = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -378,59 +378,59 @@ LL | let _val: [fn(); 2] = mem::uninitialized(); = note: function pointers must be non-null error: the type `TwoUninhabited` does not permit zero-initialization - --> $DIR/invalid_value.rs:103:36 + --> $DIR/invalid_value.rs:100:36 | LL | let _val: TwoUninhabited = mem::zeroed(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed | note: enums with no inhabited variants have no valid value - --> $DIR/invalid_value.rs:41:1 + --> $DIR/invalid_value.rs:40:1 | LL | enum TwoUninhabited { | ^^^^^^^^^^^^^^^^^^^ error: the type `TwoUninhabited` does not permit being left uninitialized - --> $DIR/invalid_value.rs:104:36 + --> $DIR/invalid_value.rs:101:36 | LL | let _val: TwoUninhabited = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | note: enums with no inhabited variants have no valid value - --> $DIR/invalid_value.rs:41:1 + --> $DIR/invalid_value.rs:40:1 | LL | enum TwoUninhabited { | ^^^^^^^^^^^^^^^^^^^ error: the type `OneFruitNonZero` does not permit zero-initialization - --> $DIR/invalid_value.rs:106:37 + --> $DIR/invalid_value.rs:103:37 | LL | let _val: OneFruitNonZero = mem::zeroed(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed | = note: `OneFruitNonZero` must be non-null note: because `std::num::NonZero` must be non-null (in this field of the only potentially inhabited enum variant) - --> $DIR/invalid_value.rs:38:12 + --> $DIR/invalid_value.rs:37:12 | LL | Banana(NonZero), | ^^^^^^^^^^^^ = note: because `core::num::niche_types::NonZeroU32Inner` must be non-null error: the type `OneFruitNonZero` does not permit being left uninitialized - --> $DIR/invalid_value.rs:107:37 + --> $DIR/invalid_value.rs:104:37 | LL | let _val: OneFruitNonZero = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | = note: `OneFruitNonZero` must be non-null note: because `std::num::NonZero` must be non-null (in this field of the only potentially inhabited enum variant) - --> $DIR/invalid_value.rs:38:12 + --> $DIR/invalid_value.rs:37:12 | LL | Banana(NonZero), | ^^^^^^^^^^^^ = note: because `core::num::niche_types::NonZeroU32Inner` must be non-null error: the type `bool` does not permit being left uninitialized - --> $DIR/invalid_value.rs:111:26 + --> $DIR/invalid_value.rs:108:26 | LL | let _val: bool = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -441,7 +441,7 @@ LL | let _val: bool = mem::uninitialized(); = note: booleans must be either `true` or `false` error: the type `Wrap` does not permit being left uninitialized - --> $DIR/invalid_value.rs:114:32 + --> $DIR/invalid_value.rs:111:32 | LL | let _val: Wrap = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -451,13 +451,13 @@ LL | let _val: Wrap = mem::uninitialized(); | = note: `Wrap` must be initialized inside its custom valid range note: characters must be a valid Unicode codepoint (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ error: the type `NonBig` does not permit being left uninitialized - --> $DIR/invalid_value.rs:117:28 + --> $DIR/invalid_value.rs:114:28 | LL | let _val: NonBig = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -466,14 +466,9 @@ LL | let _val: NonBig = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | = note: `NonBig` must be initialized inside its custom valid range -note: integers must be initialized (in this struct field) - --> $DIR/invalid_value.rs:22:26 - | -LL | pub(crate) struct NonBig(u64); - | ^^^ error: the type `Fruit` does not permit being left uninitialized - --> $DIR/invalid_value.rs:120:27 + --> $DIR/invalid_value.rs:117:27 | LL | let _val: Fruit = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -482,13 +477,13 @@ LL | let _val: Fruit = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | note: enums with multiple inhabited variants have to be initialized to a variant - --> $DIR/invalid_value.rs:25:1 + --> $DIR/invalid_value.rs:24:1 | LL | enum Fruit { | ^^^^^^^^^^ error: the type `[bool; 2]` does not permit being left uninitialized - --> $DIR/invalid_value.rs:123:31 + --> $DIR/invalid_value.rs:120:31 | LL | let _val: [bool; 2] = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -499,7 +494,7 @@ LL | let _val: [bool; 2] = mem::uninitialized(); = note: booleans must be either `true` or `false` error: the type `i32` does not permit being left uninitialized - --> $DIR/invalid_value.rs:126:25 + --> $DIR/invalid_value.rs:123:25 | LL | let _val: i32 = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -510,7 +505,7 @@ LL | let _val: i32 = mem::uninitialized(); = note: integers must be initialized error: the type `f32` does not permit being left uninitialized - --> $DIR/invalid_value.rs:129:25 + --> $DIR/invalid_value.rs:126:25 | LL | let _val: f32 = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -521,7 +516,7 @@ LL | let _val: f32 = mem::uninitialized(); = note: floats must be initialized error: the type `*const ()` does not permit being left uninitialized - --> $DIR/invalid_value.rs:132:31 + --> $DIR/invalid_value.rs:129:31 | LL | let _val: *const () = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -532,7 +527,7 @@ LL | let _val: *const () = mem::uninitialized(); = note: raw pointers must be initialized error: the type `*const [()]` does not permit being left uninitialized - --> $DIR/invalid_value.rs:135:33 + --> $DIR/invalid_value.rs:132:33 | LL | let _val: *const [()] = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -543,7 +538,7 @@ LL | let _val: *const [()] = mem::uninitialized(); = note: raw pointers must be initialized error: the type `WrapAroundRange` does not permit being left uninitialized - --> $DIR/invalid_value.rs:138:37 + --> $DIR/invalid_value.rs:135:37 | LL | let _val: WrapAroundRange = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -552,14 +547,9 @@ LL | let _val: WrapAroundRange = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | = note: `WrapAroundRange` must be initialized inside its custom valid range -note: integers must be initialized (in this struct field) - --> $DIR/invalid_value.rs:48:35 - | -LL | pub(crate) struct WrapAroundRange(u8); - | ^^ error: the type `Result` does not permit being left uninitialized - --> $DIR/invalid_value.rs:143:38 + --> $DIR/invalid_value.rs:140:38 | LL | let _val: Result = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -571,7 +561,7 @@ note: enums with multiple inhabited variants have to be initialized to a variant --> $SRC_DIR/core/src/result.rs:LL:COL error: the type `&i32` does not permit zero-initialization - --> $DIR/invalid_value.rs:151:34 + --> $DIR/invalid_value.rs:148:34 | LL | let _val: &'static i32 = mem::transmute(0usize); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -582,7 +572,7 @@ LL | let _val: &'static i32 = mem::transmute(0usize); = note: references must be non-null error: the type `&[i32]` does not permit zero-initialization - --> $DIR/invalid_value.rs:152:36 + --> $DIR/invalid_value.rs:149:36 | LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -593,7 +583,7 @@ LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize)); = note: references must be non-null error: the type `NonZero` does not permit zero-initialization - --> $DIR/invalid_value.rs:153:34 + --> $DIR/invalid_value.rs:150:34 | LL | let _val: NonZero = mem::transmute(0); | ^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -602,7 +592,7 @@ LL | let _val: NonZero = mem::transmute(0); = note: because `core::num::niche_types::NonZeroU32Inner` must be non-null error: the type `NonNull` does not permit zero-initialization - --> $DIR/invalid_value.rs:156:34 + --> $DIR/invalid_value.rs:153:34 | LL | let _val: NonNull = MaybeUninit::zeroed().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -613,7 +603,7 @@ LL | let _val: NonNull = MaybeUninit::zeroed().assume_init(); = note: `std::ptr::NonNull` must be non-null error: the type `NonNull` does not permit being left uninitialized - --> $DIR/invalid_value.rs:157:34 + --> $DIR/invalid_value.rs:154:34 | LL | let _val: NonNull = MaybeUninit::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -624,7 +614,7 @@ LL | let _val: NonNull = MaybeUninit::uninit().assume_init(); = note: `std::ptr::NonNull` must be non-null error: the type `bool` does not permit being left uninitialized - --> $DIR/invalid_value.rs:158:26 + --> $DIR/invalid_value.rs:155:26 | LL | let _val: bool = MaybeUninit::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/parser/bad-lit-suffixes.rs b/tests/ui/parser/bad-lit-suffixes.rs index 0a1ee12073023..70e3f7aa6c3b2 100644 --- a/tests/ui/parser/bad-lit-suffixes.rs +++ b/tests/ui/parser/bad-lit-suffixes.rs @@ -40,8 +40,6 @@ fn g() {} //~^ ERROR suffixes on string literals are invalid extern "C" {} -#[rustc_layout_scalar_valid_range_start(0suffix)] -//~^ ERROR invalid suffix `suffix` for number literal struct S; impl S { diff --git a/tests/ui/parser/bad-lit-suffixes.stderr b/tests/ui/parser/bad-lit-suffixes.stderr index 6c3dbbcec6453..f93db6ab29a23 100644 --- a/tests/ui/parser/bad-lit-suffixes.stderr +++ b/tests/ui/parser/bad-lit-suffixes.stderr @@ -160,20 +160,12 @@ error: suffixes on string literals are invalid LL | #[link(name = "string"suffix)] | ^^^^^^^^^^^^^^ invalid suffix `suffix` -error: invalid suffix `suffix` for number literal - --> $DIR/bad-lit-suffixes.rs:43:41 - | -LL | #[rustc_layout_scalar_valid_range_start(0suffix)] - | ^^^^^^^ invalid suffix `suffix` - | - = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) - error: suffixes on string literals are invalid - --> $DIR/bad-lit-suffixes.rs:48:25 + --> $DIR/bad-lit-suffixes.rs:46:25 | LL | #[rustc_confusables("blah"suffix)] | ^^^^^^^^^^^^ invalid suffix `suffix` -error: aborting due to 22 previous errors; 2 warnings emitted +error: aborting due to 21 previous errors; 2 warnings emitted For more information about this error, try `rustc --explain E0539`. diff --git a/tests/ui/print_type_sizes/niche-filling.rs b/tests/ui/print_type_sizes/niche-filling.rs index 719bc2a07dc91..4a8d3b81b9d37 100644 --- a/tests/ui/print_type_sizes/niche-filling.rs +++ b/tests/ui/print_type_sizes/niche-filling.rs @@ -15,16 +15,14 @@ // ^-- needed because `--pass check` does not emit the output needed. // FIXME: consider using an attribute instead of side-effects. #![allow(dead_code)] -#![feature(rustc_attrs)] +#![feature(rustc_attrs, pattern_types, pattern_type_macro)] use std::num::NonZero; pub enum MyOption { None, Some(T) } -#[rustc_layout_scalar_valid_range_start(0)] -#[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)] pub struct MyNotNegativeOne { - _i: i32, + _i: std::pat::pattern_type!(i32 is 0..=i32::MAX | i32::MIN..=-2), } impl Default for MyOption { diff --git a/tests/ui/structs-enums/type-sizes.rs b/tests/ui/structs-enums/type-sizes.rs index a8fadcc1d1ec6..af87b4cd92b72 100644 --- a/tests/ui/structs-enums/type-sizes.rs +++ b/tests/ui/structs-enums/type-sizes.rs @@ -238,10 +238,6 @@ struct VecDummy { len: usize, } -#[rustc_layout_scalar_valid_range_start(1)] -#[rustc_layout_scalar_valid_range_end(100)] -struct PointerWithRange(#[allow(dead_code)] *const u8); - pub fn main() { assert_eq!(size_of::(), 1 as usize); assert_eq!(size_of::(), 4 as usize); @@ -357,8 +353,4 @@ pub fn main() { // the end which means the 8-sized field shouldn't be alignment-promoted before the 4-sized one. let v = ReorderEndNiche { a: EndNiche8([0; 7], false), b: MiddleNiche4(0, 0, false, 0) }; assert!(ptr::from_ref(&v.a).addr() > ptr::from_ref(&v.b).addr()); - - - assert_eq!(size_of::>(), size_of::()); - assert_eq!(size_of::>>(), size_of::()); } diff --git a/tests/ui/unsafe-binders/layout-invariant.rs b/tests/ui/unsafe-binders/layout-invariant.rs new file mode 100644 index 0000000000000..46fb2e2839eae --- /dev/null +++ b/tests/ui/unsafe-binders/layout-invariant.rs @@ -0,0 +1,17 @@ +// Regression test for https://github.com/rust-lang/rust/issues/154426 +#![feature(unsafe_binders)] + +#[derive(Copy, Clone)] +struct Adt<'a> { + a: &'a String, +} + +const None: Option Option Adt<'a>>> = None; +//~^ ERROR the trait bound `unsafe<'a> Adt<'a>: Copy` is not satisfied +//~| ERROR the trait bound `unsafe<'a> Adt<'a>: Copy` is not satisfied + +fn main() { + match None { + _ => {} + }; +} diff --git a/tests/ui/unsafe-binders/layout-invariant.stderr b/tests/ui/unsafe-binders/layout-invariant.stderr new file mode 100644 index 0000000000000..8eb00897c8520 --- /dev/null +++ b/tests/ui/unsafe-binders/layout-invariant.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `unsafe<'a> Adt<'a>: Copy` is not satisfied + --> $DIR/layout-invariant.rs:9:13 + | +LL | const None: Option Option Adt<'a>>> = None; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `unsafe<'a> Adt<'a>` + | + = note: required for `Option Adt<'a>>` to implement `Copy` + +error[E0277]: the trait bound `unsafe<'a> Adt<'a>: Copy` is not satisfied + --> $DIR/layout-invariant.rs:9:59 + | +LL | const None: Option Option Adt<'a>>> = None; + | ^^^^ the trait `Copy` is not implemented for `unsafe<'a> Adt<'a>` + | + = note: required for `Option Adt<'a>>` to implement `Copy` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.rs deleted file mode 100644 index ca44fa7e4e756..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![feature(rustc_attrs)] -#![allow(internal_features)] - -#[derive(Debug)] -#[rustc_layout_scalar_valid_range_start(2)] -struct NonZeroAndOneU8(u8); - -fn main() { - println!("{:?}", Some(1).map(NonZeroAndOneU8).unwrap()); - //~^ ERROR found `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.stderr deleted file mode 100644 index 040c1d5bcbee4..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0277]: expected a `FnOnce({integer})` closure, found `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` - --> $DIR/initializing-ranged-via-ctor.rs:9:34 - | -LL | println!("{:?}", Some(1).map(NonZeroAndOneU8).unwrap()); - | --- ^^^^^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` - | | - | required by a bound introduced by this call - | - = help: the trait `FnOnce({integer})` is not implemented for fn item `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` - = note: unsafe function cannot be called generically without an unsafe block -note: required by a bound in `Option::::map` - --> $SRC_DIR/core/src/option.rs:LL:COL - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.rs deleted file mode 100644 index a91e579510d4d..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![feature(rustc_attrs)] - -#[derive(Debug)] -#[rustc_layout_scalar_valid_range_start(2)] -struct NonZeroAndOneU8(u8); - -fn main() { - let x: fn(u8) -> NonZeroAndOneU8 = NonZeroAndOneU8; - //~^ ERROR mismatched types -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.stderr deleted file mode 100644 index abd59bdbc75bf..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/ranged-ctor-as-fn-ptr.rs:8:40 - | -LL | let x: fn(u8) -> NonZeroAndOneU8 = NonZeroAndOneU8; - | ------------------------- ^^^^^^^^^^^^^^^ expected safe fn, found unsafe fn - | | - | expected due to this - | - = note: expected fn pointer `fn(_) -> NonZeroAndOneU8` - found struct constructor `unsafe fn(_) -> NonZeroAndOneU8 {NonZeroAndOneU8}` - = note: unsafe functions cannot be coerced into safe function pointers - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.rs deleted file mode 100644 index 0fa2da917e9f8..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() { - let _x = NonZero(0); //~ ERROR initializing type with `rustc_layout_scalar_valid_range` attr -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.stderr deleted file mode 100644 index b6875e1581514..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block - --> $DIR/ranged_ints.rs:7:14 - | -LL | let _x = NonZero(0); - | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr - | - = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.rs deleted file mode 100644 index a3d9f54efe20c..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() { - let mut x = unsafe { NonZero(1) }; - let y = &mut x.0; //~ ERROR mutation of layout constrained field is unsafe - if let Some(NonZero(ref mut y)) = Some(x) {} //~ ERROR mutation of layout constrained field is unsafe -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.stderr deleted file mode 100644 index 1885e77af7e0b..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/ranged_ints2.rs:8:13 - | -LL | let y = &mut x.0; - | ^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/ranged_ints2.rs:9:25 - | -LL | if let Some(NonZero(ref mut y)) = Some(x) {} - | ^^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.rs deleted file mode 100644 index a9f5b2089c4d8..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() { -} - -const fn foo() -> NonZero { - let mut x = unsafe { NonZero(1) }; - let y = &mut x.0; - //~^ ERROR mutation of layout constrained field is unsafe - unsafe { NonZero(1) } -} - -const fn bar() -> NonZero { - let mut x = unsafe { NonZero(1) }; - let y = unsafe { &mut x.0 }; - unsafe { NonZero(1) } -} - -const fn boo() -> NonZero { - let mut x = unsafe { NonZero(1) }; - unsafe { let y = &mut x.0; } - unsafe { NonZero(1) } -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.stderr deleted file mode 100644 index 3373d627b5e12..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/ranged_ints2_const.rs:11:13 - | -LL | let y = &mut x.0; - | ^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.rs deleted file mode 100644 index 47d67fac6785c..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![feature(rustc_attrs)] - -use std::cell::Cell; - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() { - let mut x = unsafe { NonZero(Cell::new(1)) }; - let y = &x.0; //~ ERROR borrow of layout constrained field with interior mutability -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.stderr deleted file mode 100644 index 8dcb99fc16dbf..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block - --> $DIR/ranged_ints3.rs:10:13 - | -LL | let y = &x.0; - | ^^^^ borrow of layout constrained field with interior mutability - | - = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.rs deleted file mode 100644 index 91e84f7ffbd1b..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![feature(rustc_attrs)] - -use std::cell::Cell; - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() {} - -const fn foo() -> NonZero> { - let mut x = unsafe { NonZero(Cell::new(1)) }; - let y = &x.0; - //~^ ERROR borrow of layout constrained field with interior mutability - unsafe { NonZero(Cell::new(1)) } -} - -const fn bar() -> NonZero> { - let mut x = unsafe { NonZero(Cell::new(1)) }; - let y = unsafe { &x.0 }; - unsafe { NonZero(Cell::new(1)) } -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.stderr deleted file mode 100644 index a72ab1a3b7449..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block - --> $DIR/ranged_ints3_const.rs:12:13 - | -LL | let y = &x.0; - | ^^^^ borrow of layout constrained field with interior mutability - | - = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.rs deleted file mode 100644 index de6be506d5611..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![feature(rustc_attrs)] - -use std::cell::Cell; - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() { - let mut x = unsafe { NonZero(Cell::new(1)) }; - match x { - NonZero(ref x) => { x } - //~^ ERROR borrow of layout constrained field with interior mutability - }; - - let mut y = unsafe { NonZero(42) }; - match y { NonZero(ref y) => { y } }; // OK, type of `y` is freeze - match y { NonZero(ref mut y) => { y } }; - //~^ ERROR mutation of layout constrained field -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.stderr deleted file mode 100644 index 1bdc29d077c0f..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block - --> $DIR/ranged_ints3_match.rs:11:17 - | -LL | NonZero(ref x) => { x } - | ^^^^^ borrow of layout constrained field with interior mutability - | - = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values - -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/ranged_ints3_match.rs:17:23 - | -LL | match y { NonZero(ref mut y) => { y } }; - | ^^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.rs deleted file mode 100644 index d8632c48434f2..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() { - let mut x = unsafe { NonZero(1) }; - x.0 = 0; //~ ERROR mutation of layout constrained field is unsafe -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.stderr deleted file mode 100644 index 4a703696b8847..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/ranged_ints4.rs:8:5 - | -LL | x.0 = 0; - | ^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.rs deleted file mode 100644 index f09168c3d3f9c..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() {} - -const fn foo() -> NonZero { - let mut x = unsafe { NonZero(1) }; - x.0 = 0; - //~^ ERROR mutation of layout constrained field is unsafe - x -} - -const fn bar() -> NonZero { - let mut x = unsafe { NonZero(1) }; - unsafe { x.0 = 0 }; // this is UB - x -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.stderr deleted file mode 100644 index 604ec1167e49f..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/ranged_ints4_const.rs:10:5 - | -LL | x.0 = 0; - | ^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.rs deleted file mode 100644 index 8477772867e91..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() {} - -const fn foo() -> NonZero { NonZero(0) } -//~^ ERROR initializing type with `rustc_layout_scalar_valid_range` attr is unsafe - -const fn bar() -> NonZero { unsafe { NonZero(0) } } diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.stderr deleted file mode 100644 index 2b8be290d3adb..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block - --> $DIR/ranged_ints_const.rs:8:34 - | -LL | const fn foo() -> NonZero { NonZero(0) } - | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr - | - = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_macro.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_macro.rs deleted file mode 100644 index 44a12bbd0a6bd..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_macro.rs +++ /dev/null @@ -1,17 +0,0 @@ -//@ build-pass - -#![feature(rustc_attrs)] - -macro_rules! apply { - ($val:expr) => { - #[rustc_layout_scalar_valid_range_start($val)] - #[repr(transparent)] - pub(crate) struct NonZero(pub(crate) T); - } -} - -apply!(1); - -fn main() { - let _x = unsafe { NonZero(1) }; -} diff --git a/tests/ui/unsafe/unsafe-assign.rs b/tests/ui/unsafe/unsafe-assign.rs deleted file mode 100644 index 02ce238854d87..0000000000000 --- a/tests/ui/unsafe/unsafe-assign.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![feature(rustc_attrs)] -#![allow(unused,dead_code)] - -fn nested_field() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero(T); - - let mut foo = unsafe { NonZero((1,)) }; - foo.0.0 = 0; - //~^ ERROR: mutation of layout constrained field is unsafe -} - -fn block() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero(T); - - let mut foo = unsafe { NonZero((1,)) }; - { foo.0 }.0 = 0; - // ^ not unsafe because the result of the block expression is a new place -} - -fn main() {} diff --git a/tests/ui/unsafe/unsafe-assign.stderr b/tests/ui/unsafe/unsafe-assign.stderr deleted file mode 100644 index 1fa5d715c2e1a..0000000000000 --- a/tests/ui/unsafe/unsafe-assign.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/unsafe-assign.rs:9:5 - | -LL | foo.0.0 = 0; - | ^^^^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/unsafe-borrow.rs b/tests/ui/unsafe/unsafe-borrow.rs deleted file mode 100644 index ab0e59489a96a..0000000000000 --- a/tests/ui/unsafe/unsafe-borrow.rs +++ /dev/null @@ -1,53 +0,0 @@ -#![feature(rustc_attrs)] -#![allow(unused,dead_code)] - -fn tuple_struct() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero(T); - - let mut foo = unsafe { NonZero((1,)) }; - let a = &mut foo.0.0; - //~^ ERROR: mutation of layout constrained field is unsafe -} - -fn slice() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero<'a, T>(&'a mut [T]); - - let mut nums = [1, 2, 3, 4]; - let mut foo = unsafe { NonZero(&mut nums[..]) }; - let a = &mut foo.0[2]; - // ^ not unsafe because there is an implicit dereference here -} - -fn array() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero([T; 4]); - - let nums = [1, 2, 3, 4]; - let mut foo = unsafe { NonZero(nums) }; - let a = &mut foo.0[2]; - //~^ ERROR: mutation of layout constrained field is unsafe -} - -fn block() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero(T); - - let foo = unsafe { NonZero((1,)) }; - &mut { foo.0 }.0; - // ^ not unsafe because the result of the block expression is a new place -} - -fn mtch() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero(T); - - let mut foo = unsafe { NonZero((1,)) }; - match &mut foo { - NonZero((a,)) => *a = 0, - //~^ ERROR: mutation of layout constrained field is unsafe - } -} - -fn main() {} diff --git a/tests/ui/unsafe/unsafe-borrow.stderr b/tests/ui/unsafe/unsafe-borrow.stderr deleted file mode 100644 index a53b50583ca40..0000000000000 --- a/tests/ui/unsafe/unsafe-borrow.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/unsafe-borrow.rs:9:13 - | -LL | let a = &mut foo.0.0; - | ^^^^^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/unsafe-borrow.rs:29:13 - | -LL | let a = &mut foo.0[2]; - | ^^^^^^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/unsafe-borrow.rs:48:18 - | -LL | NonZero((a,)) => *a = 0, - | ^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/use/use-mod/use-mod-3.stderr b/tests/ui/use/use-mod/use-mod-3.stderr index 1b12b3c6fa09a..049b50e5b3b0f 100644 --- a/tests/ui/use/use-mod/use-mod-3.stderr +++ b/tests/ui/use/use-mod/use-mod-3.stderr @@ -3,6 +3,8 @@ error[E0603]: module `bar` is private | LL | use foo::bar::{ | ^^^ private module +LL | self + | ---- module `self` is not publicly re-exported | note: the module `bar` is defined here --> $DIR/use-mod-3.rs:9:5 diff --git a/tests/ui/use/use-mod/use-mod-4.rs b/tests/ui/use/use-mod/use-mod-4.rs index 34ce7c7195758..570731e1896d2 100644 --- a/tests/ui/use/use-mod/use-mod-4.rs +++ b/tests/ui/use/use-mod/use-mod-4.rs @@ -1,7 +1,5 @@ use crate::foo::self; //~ ERROR unresolved import `crate::foo` -//~^ ERROR `self` imports are only allowed within a { } list use std::mem::self; -//~^ ERROR `self` imports are only allowed within a { } list fn main() {} diff --git a/tests/ui/use/use-mod/use-mod-4.stderr b/tests/ui/use/use-mod/use-mod-4.stderr index 03284298c16f7..8039450702552 100644 --- a/tests/ui/use/use-mod/use-mod-4.stderr +++ b/tests/ui/use/use-mod/use-mod-4.stderr @@ -1,35 +1,3 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-mod-4.rs:1:15 - | -LL | use crate::foo::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::foo::self; -LL + use crate::foo; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::foo::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-mod-4.rs:4:13 - | -LL | use std::mem::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use std::mem::self; -LL + use std::mem; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use std::mem::{self}; - | + + - error[E0432]: unresolved import `crate::foo` --> $DIR/use-mod-4.rs:1:12 | @@ -41,7 +9,6 @@ help: you might be missing a crate named `foo`, add it to your project and impor LL + extern crate foo; | -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0429, E0432. -For more information about an error, try `rustc --explain E0429`. +For more information about this error, try `rustc --explain E0432`. diff --git a/tests/ui/use/use-mod/use-mod-5.rs b/tests/ui/use/use-mod/use-mod-5.rs index df5b423ec57e6..040b592e3748d 100644 --- a/tests/ui/use/use-mod/use-mod-5.rs +++ b/tests/ui/use/use-mod/use-mod-5.rs @@ -1,3 +1,5 @@ +//@ check-pass + mod foo { pub mod bar { pub fn drop() {} @@ -5,9 +7,7 @@ mod foo { } use foo::bar::self; -//~^ ERROR `self` imports are only allowed within a { } list fn main() { - // Because of error recovery this shouldn't error bar::drop(); } diff --git a/tests/ui/use/use-mod/use-mod-5.stderr b/tests/ui/use/use-mod/use-mod-5.stderr deleted file mode 100644 index 22201361c584f..0000000000000 --- a/tests/ui/use/use-mod/use-mod-5.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-mod-5.rs:7:13 - | -LL | use foo::bar::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use foo::bar::self; -LL + use foo::bar; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use foo::bar::{self}; - | + + - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0429`. diff --git a/tests/ui/use/use-mod/use-mod-6.rs b/tests/ui/use/use-mod/use-mod-6.rs index 1f8777daca491..b11b1f17aa1e2 100644 --- a/tests/ui/use/use-mod/use-mod-6.rs +++ b/tests/ui/use/use-mod/use-mod-6.rs @@ -1,3 +1,5 @@ +//@ check-pass + mod foo { pub mod bar { pub fn drop() {} @@ -5,9 +7,7 @@ mod foo { } use foo::bar::self as abc; -//~^ ERROR `self` imports are only allowed within a { } list fn main() { - // Because of error recovery this shouldn't error abc::drop(); } diff --git a/tests/ui/use/use-mod/use-mod-6.stderr b/tests/ui/use/use-mod/use-mod-6.stderr deleted file mode 100644 index f9ab346f8c36e..0000000000000 --- a/tests/ui/use/use-mod/use-mod-6.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-mod-6.rs:7:13 - | -LL | use foo::bar::self as abc; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use foo::bar::self as abc; -LL + use foo::bar as abc; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use foo::bar::{self as abc}; - | + + - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0429`. diff --git a/tests/ui/use/use-path-segment-kw.e2015.stderr b/tests/ui/use/use-path-segment-kw.e2015.stderr index dce3071f789bc..a63cce80896ab 100644 --- a/tests/ui/use/use-path-segment-kw.e2015.stderr +++ b/tests/ui/use/use-path-segment-kw.e2015.stderr @@ -1,5 +1,5 @@ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:97:13 + --> $DIR/use-path-segment-kw.rs:96:13 | LL | use crate; | ^^^^^ @@ -10,127 +10,127 @@ LL | use crate as name; | +++++++ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:101:15 + --> $DIR/use-path-segment-kw.rs:100:15 | LL | use ::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:102:15 + --> $DIR/use-path-segment-kw.rs:101:15 | LL | use ::crate as _crate2; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:103:16 + --> $DIR/use-path-segment-kw.rs:102:16 | LL | use ::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:104:16 + --> $DIR/use-path-segment-kw.rs:103:16 | LL | use ::{crate as _nested_crate2}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:107:21 + --> $DIR/use-path-segment-kw.rs:106:21 | LL | use foobar::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:108:21 + --> $DIR/use-path-segment-kw.rs:107:21 | LL | use foobar::crate as _crate3; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:109:22 + --> $DIR/use-path-segment-kw.rs:108:22 | LL | use foobar::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:110:22 + --> $DIR/use-path-segment-kw.rs:109:22 | LL | use foobar::{crate as _nested_crate3}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:113:20 + --> $DIR/use-path-segment-kw.rs:112:20 | LL | use crate::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:114:20 + --> $DIR/use-path-segment-kw.rs:113:20 | LL | use crate::crate as _crate4; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:115:21 + --> $DIR/use-path-segment-kw.rs:114:21 | LL | use crate::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:116:21 + --> $DIR/use-path-segment-kw.rs:115:21 | LL | use crate::{crate as _nested_crate4}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:119:20 + --> $DIR/use-path-segment-kw.rs:118:20 | LL | use super::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:120:20 + --> $DIR/use-path-segment-kw.rs:119:20 | LL | use super::crate as _crate5; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:121:21 + --> $DIR/use-path-segment-kw.rs:120:21 | LL | use super::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:122:21 + --> $DIR/use-path-segment-kw.rs:121:21 | LL | use super::{crate as _nested_crate5}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:125:19 + --> $DIR/use-path-segment-kw.rs:124:19 | LL | use self::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:126:19 + --> $DIR/use-path-segment-kw.rs:125:19 | LL | use self::crate as _crate6; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:127:20 + --> $DIR/use-path-segment-kw.rs:126:20 | LL | use self::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:128:20 + --> $DIR/use-path-segment-kw.rs:127:20 | LL | use self::{crate as _nested_crate6}; | ^^^^^ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:135:13 + --> $DIR/use-path-segment-kw.rs:134:13 | LL | use super; | ^^^^^ @@ -141,79 +141,79 @@ LL | use super as name; | +++++++ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:139:15 + --> $DIR/use-path-segment-kw.rs:138:15 | LL | use ::super; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:140:15 + --> $DIR/use-path-segment-kw.rs:139:15 | LL | use ::super as _super2; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:141:16 + --> $DIR/use-path-segment-kw.rs:140:16 | LL | use ::{super}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:142:16 + --> $DIR/use-path-segment-kw.rs:141:16 | LL | ... use ::{super as _nested_super2}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:145:21 + --> $DIR/use-path-segment-kw.rs:144:21 | LL | use foobar::super; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:146:21 + --> $DIR/use-path-segment-kw.rs:145:21 | LL | ... use foobar::super as _super3; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:147:22 + --> $DIR/use-path-segment-kw.rs:146:22 | LL | use foobar::{super}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:148:22 + --> $DIR/use-path-segment-kw.rs:147:22 | LL | ... use foobar::{super as _nested_super3}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:151:20 + --> $DIR/use-path-segment-kw.rs:150:20 | LL | use crate::super; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:152:20 + --> $DIR/use-path-segment-kw.rs:151:20 | LL | ... use crate::super as _super4; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:153:21 + --> $DIR/use-path-segment-kw.rs:152:21 | LL | use crate::{super}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:154:21 + --> $DIR/use-path-segment-kw.rs:153:21 | LL | ... use crate::{super as _nested_super4}; | ^^^^^ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:157:20 + --> $DIR/use-path-segment-kw.rs:156:20 | LL | use super::super; | ^^^^^ @@ -224,7 +224,7 @@ LL | use super::super as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:159:21 + --> $DIR/use-path-segment-kw.rs:158:21 | LL | use super::{super}; | ^^^^^ @@ -235,7 +235,7 @@ LL | use super::{super as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:163:19 + --> $DIR/use-path-segment-kw.rs:162:19 | LL | use self::super; | ^^^^^ @@ -246,7 +246,7 @@ LL | use self::super as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:165:20 + --> $DIR/use-path-segment-kw.rs:164:20 | LL | use self::{super}; | ^^^^^ @@ -257,31 +257,29 @@ LL | use self::{super as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:173:13 + --> $DIR/use-path-segment-kw.rs:172:13 | LL | use self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:177:13 | -LL | use ::self; - | ^^^^^^ +help: try renaming it with a name + | +LL | use self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:177:15 + --> $DIR/use-path-segment-kw.rs:178:15 | LL | use ::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:180:13 | -LL | use ::self as _self2; - | ^^^^^^ +help: try renaming it with a name + | +LL | use ::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:182:16 + --> $DIR/use-path-segment-kw.rs:181:16 | LL | use ::{self}; | ^^^^ @@ -291,78 +289,19 @@ help: try renaming it with a name LL | use ::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:187:28 - | -LL | pub use foobar::qux::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use foobar::qux::self; -LL + pub use foobar::qux; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use foobar::qux::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:189:23 - | -LL | pub use foobar::self as _self3; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use foobar::self as _self3; -LL + pub use foobar as _self3; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use foobar::{self as _self3}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:195:18 - | -LL | use crate::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::self; -LL + use crate; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:195:20 + --> $DIR/use-path-segment-kw.rs:194:20 | LL | use crate::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:197:22 - | -LL | pub use crate::self as _self4; - | ^^^^^^ - | -help: consider importing the module directly | -LL - pub use crate::self as _self4; -LL + pub use crate as _self4; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use crate::{self as _self4}; - | + + +LL | use crate::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:198:21 + --> $DIR/use-path-segment-kw.rs:196:21 | LL | use crate::{self}; | ^^^^ @@ -372,46 +311,19 @@ help: try renaming it with a name LL | use crate::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:202:18 - | -LL | use super::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use super::self; -LL + use super; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use super::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:202:20 + --> $DIR/use-path-segment-kw.rs:200:20 | LL | use super::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:204:22 | -LL | pub use super::self as _self5; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::self as _self5; -LL + pub use super as _self5; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use super::{self as _self5}; - | + + +LL | use super::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:205:21 + --> $DIR/use-path-segment-kw.rs:202:21 | LL | use super::{self}; | ^^^^ @@ -421,46 +333,19 @@ help: try renaming it with a name LL | use super::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:209:17 - | -LL | use self::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use self::self; -LL + use self; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use self::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:209:19 + --> $DIR/use-path-segment-kw.rs:206:19 | LL | use self::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:211:21 - | -LL | pub use self::self as _self6; - | ^^^^^^ | -help: consider importing the module directly - | -LL - pub use self::self as _self6; -LL + pub use self as _self6; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use self::{self as _self6}; - | + + +LL | use self::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:212:20 + --> $DIR/use-path-segment-kw.rs:208:20 | LL | use self::{self}; | ^^^^ @@ -470,38 +355,6 @@ help: try renaming it with a name LL | use self::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:216:28 - | -LL | use crate::foo::bar::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::foo::bar::self; -LL + use crate::foo::bar; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::foo::bar::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:217:28 - | -LL | use crate::foo::bar::self as _self7; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::foo::bar::self as _self7; -LL + use crate::foo::bar as _self7; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::foo::bar::{self as _self7}; - | + + - error: imports need to be explicitly named --> $DIR/use-path-segment-kw.rs:11:13 | @@ -869,26 +722,6 @@ LL | ... macro_dollar_crate!(); | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:63:19 - | -LL | use $crate::self; - | ^^^^^^ -... -LL | macro_dollar_crate!(); - | --------------------- in this macro invocation - | - = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider importing the module directly - | -LL - use $crate::self; -LL + use $crate; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use $crate::{self}; - | + + - error: imports need to be explicitly named --> $DIR/use-path-segment-kw.rs:63:21 | @@ -899,29 +732,13 @@ LL | macro_dollar_crate!(); | --------------------- in this macro invocation | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:65:23 - | -LL | pub use $crate::self as _m_self8; - | ^^^^^^ -... -LL | macro_dollar_crate!(); - | --------------------- in this macro invocation - | - = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider importing the module directly - | -LL - pub use $crate::self as _m_self8; -LL + pub use $crate as _m_self8; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use $crate::{self as _m_self8}; - | + + +LL | use $crate::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:66:22 + --> $DIR/use-path-segment-kw.rs:65:22 | LL | use $crate::{self}; | ^^^^ @@ -936,7 +753,7 @@ LL | use $crate::{self as name}; | +++++++ error[E0433]: cannot find module or crate `foobar` in the crate root - --> $DIR/use-path-segment-kw.rs:187:17 + --> $DIR/use-path-segment-kw.rs:186:17 | LL | pub use foobar::qux::self; | ^^^^^^ use of unresolved module or unlinked crate `foobar` @@ -947,7 +764,7 @@ LL + extern crate foobar; | error[E0433]: cannot find module or crate `foobar` in the crate root - --> $DIR/use-path-segment-kw.rs:191:17 + --> $DIR/use-path-segment-kw.rs:190:17 | LL | pub use foobar::baz::{self}; | ^^^^^^ use of unresolved module or unlinked crate `foobar` @@ -958,7 +775,7 @@ LL + extern crate foobar; | error[E0432]: unresolved import `foobar` - --> $DIR/use-path-segment-kw.rs:189:17 + --> $DIR/use-path-segment-kw.rs:188:17 | LL | pub use foobar::self as _self3; | ^^^^^^ @@ -969,7 +786,7 @@ LL | pub use self::foobar::self as _self3; | ++++++ error[E0432]: unresolved import `foobar` - --> $DIR/use-path-segment-kw.rs:192:17 + --> $DIR/use-path-segment-kw.rs:191:17 | LL | pub use foobar::{self as _nested_self3}; | ^^^^^^ @@ -979,12 +796,6 @@ help: a similar path exists LL | pub use self::foobar::{self as _nested_self3}; | ++++++ -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:215:36 - | -LL | type D7 = crate::foo::bar::self; - | ^^^^ can only be used in path start position - error[E0573]: expected type, found module `$crate` --> $DIR/use-path-segment-kw.rs:10:19 | @@ -996,36 +807,83 @@ LL | macro_dollar_crate!(); | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0573]: expected type, found module `$crate::self` + --> $DIR/use-path-segment-kw.rs:62:20 + | +LL | type A10 = $crate::self; + | ^^^^^^^^^^^^ not a type +... +LL | macro_dollar_crate!(); + | --------------------- in this macro invocation + | + = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0573]: expected type, found module `crate` - --> $DIR/use-path-segment-kw.rs:96:19 + --> $DIR/use-path-segment-kw.rs:95:19 | LL | type B1 = crate; | ^^^^^ not a type error[E0573]: expected type, found module `super` - --> $DIR/use-path-segment-kw.rs:134:19 + --> $DIR/use-path-segment-kw.rs:133:19 | LL | type C1 = super; | ^^^^^ not a type error[E0573]: expected type, found module `super::super` - --> $DIR/use-path-segment-kw.rs:156:19 + --> $DIR/use-path-segment-kw.rs:155:19 | LL | type C5 = super::super; | ^^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self::super` - --> $DIR/use-path-segment-kw.rs:162:19 + --> $DIR/use-path-segment-kw.rs:161:19 | LL | type C6 = self::super; | ^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self` - --> $DIR/use-path-segment-kw.rs:172:19 + --> $DIR/use-path-segment-kw.rs:171:19 | LL | type D1 = self; | ^^^^ not a type +error[E0573]: expected type, found module `::self` + --> $DIR/use-path-segment-kw.rs:175:19 + | +LL | type D2 = ::self; + | ^^^^^^ not a type + +error[E0573]: expected type, found module `foobar::self` + --> $DIR/use-path-segment-kw.rs:185:19 + | +LL | type D3 = foobar::self; + | ^^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::self` + --> $DIR/use-path-segment-kw.rs:193:19 + | +LL | type D4 = crate::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-path-segment-kw.rs:199:19 + | +LL | type D5 = super::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `self::self` + --> $DIR/use-path-segment-kw.rs:205:19 + | +LL | type D6 = self::self; + | ^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::foo::bar::self` + --> $DIR/use-path-segment-kw.rs:211:19 + | +LL | type D7 = crate::foo::bar::self; + | ^^^^^^^^^^^^^^^^^^^^^ not a type + error[E0433]: global paths cannot start with `$crate` --> $DIR/use-path-segment-kw.rs:14:21 | @@ -1114,96 +972,55 @@ LL | macro_dollar_crate!(); | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:62:28 - | -LL | type A10 = $crate::self; - | ^^^^ can only be used in path start position -... -LL | macro_dollar_crate!(); - | --------------------- in this macro invocation - | - = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0433]: global paths cannot start with `crate` - --> $DIR/use-path-segment-kw.rs:100:21 + --> $DIR/use-path-segment-kw.rs:99:21 | LL | type B2 = ::crate; | ^^^^^ cannot start with this error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:106:27 + --> $DIR/use-path-segment-kw.rs:105:27 | LL | type B3 = foobar::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:112:26 + --> $DIR/use-path-segment-kw.rs:111:26 | LL | type B4 = crate::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:118:26 + --> $DIR/use-path-segment-kw.rs:117:26 | LL | type B5 = super::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:124:25 + --> $DIR/use-path-segment-kw.rs:123:25 | LL | type B6 = self::crate; | ^^^^^ can only be used in path start position error[E0433]: global paths cannot start with `super` - --> $DIR/use-path-segment-kw.rs:138:21 + --> $DIR/use-path-segment-kw.rs:137:21 | LL | type C2 = ::super; | ^^^^^ cannot start with this error[E0433]: `super` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:144:27 + --> $DIR/use-path-segment-kw.rs:143:27 | LL | type C3 = foobar::super; | ^^^^^ can only be used in path start position error[E0433]: `super` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:150:26 + --> $DIR/use-path-segment-kw.rs:149:26 | LL | type C4 = crate::super; | ^^^^^ can only be used in path start position -error[E0433]: global paths cannot start with `self` - --> $DIR/use-path-segment-kw.rs:176:21 - | -LL | type D2 = ::self; - | ^^^^ cannot start with this - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:186:27 - | -LL | type D3 = foobar::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:194:26 - | -LL | type D4 = crate::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:201:26 - | -LL | type D5 = super::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:208:25 - | -LL | type D6 = self::self; - | ^^^^ can only be used in path start position - -error: aborting due to 129 previous errors +error: aborting due to 115 previous errors -Some errors have detailed explanations: E0429, E0432, E0433, E0573. -For more information about an error, try `rustc --explain E0429`. +Some errors have detailed explanations: E0432, E0433, E0573. +For more information about an error, try `rustc --explain E0432`. diff --git a/tests/ui/use/use-path-segment-kw.e2018.stderr b/tests/ui/use/use-path-segment-kw.e2018.stderr index 878fd166b845d..3f1b01a27de54 100644 --- a/tests/ui/use/use-path-segment-kw.e2018.stderr +++ b/tests/ui/use/use-path-segment-kw.e2018.stderr @@ -1,5 +1,5 @@ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:97:13 + --> $DIR/use-path-segment-kw.rs:96:13 | LL | use crate; | ^^^^^ @@ -10,127 +10,127 @@ LL | use crate as name; | +++++++ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:101:15 + --> $DIR/use-path-segment-kw.rs:100:15 | LL | use ::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:102:15 + --> $DIR/use-path-segment-kw.rs:101:15 | LL | use ::crate as _crate2; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:103:16 + --> $DIR/use-path-segment-kw.rs:102:16 | LL | use ::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:104:16 + --> $DIR/use-path-segment-kw.rs:103:16 | LL | use ::{crate as _nested_crate2}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:107:21 + --> $DIR/use-path-segment-kw.rs:106:21 | LL | use foobar::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:108:21 + --> $DIR/use-path-segment-kw.rs:107:21 | LL | use foobar::crate as _crate3; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:109:22 + --> $DIR/use-path-segment-kw.rs:108:22 | LL | use foobar::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:110:22 + --> $DIR/use-path-segment-kw.rs:109:22 | LL | use foobar::{crate as _nested_crate3}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:113:20 + --> $DIR/use-path-segment-kw.rs:112:20 | LL | use crate::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:114:20 + --> $DIR/use-path-segment-kw.rs:113:20 | LL | use crate::crate as _crate4; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:115:21 + --> $DIR/use-path-segment-kw.rs:114:21 | LL | use crate::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:116:21 + --> $DIR/use-path-segment-kw.rs:115:21 | LL | use crate::{crate as _nested_crate4}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:119:20 + --> $DIR/use-path-segment-kw.rs:118:20 | LL | use super::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:120:20 + --> $DIR/use-path-segment-kw.rs:119:20 | LL | use super::crate as _crate5; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:121:21 + --> $DIR/use-path-segment-kw.rs:120:21 | LL | use super::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:122:21 + --> $DIR/use-path-segment-kw.rs:121:21 | LL | use super::{crate as _nested_crate5}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:125:19 + --> $DIR/use-path-segment-kw.rs:124:19 | LL | use self::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:126:19 + --> $DIR/use-path-segment-kw.rs:125:19 | LL | use self::crate as _crate6; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:127:20 + --> $DIR/use-path-segment-kw.rs:126:20 | LL | use self::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:128:20 + --> $DIR/use-path-segment-kw.rs:127:20 | LL | use self::{crate as _nested_crate6}; | ^^^^^ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:135:13 + --> $DIR/use-path-segment-kw.rs:134:13 | LL | use super; | ^^^^^ @@ -141,79 +141,79 @@ LL | use super as name; | +++++++ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:139:15 + --> $DIR/use-path-segment-kw.rs:138:15 | LL | use ::super; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:140:15 + --> $DIR/use-path-segment-kw.rs:139:15 | LL | use ::super as _super2; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:141:16 + --> $DIR/use-path-segment-kw.rs:140:16 | LL | use ::{super}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:142:16 + --> $DIR/use-path-segment-kw.rs:141:16 | LL | ... use ::{super as _nested_super2}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:145:21 + --> $DIR/use-path-segment-kw.rs:144:21 | LL | use foobar::super; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:146:21 + --> $DIR/use-path-segment-kw.rs:145:21 | LL | ... use foobar::super as _super3; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:147:22 + --> $DIR/use-path-segment-kw.rs:146:22 | LL | use foobar::{super}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:148:22 + --> $DIR/use-path-segment-kw.rs:147:22 | LL | ... use foobar::{super as _nested_super3}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:151:20 + --> $DIR/use-path-segment-kw.rs:150:20 | LL | use crate::super; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:152:20 + --> $DIR/use-path-segment-kw.rs:151:20 | LL | ... use crate::super as _super4; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:153:21 + --> $DIR/use-path-segment-kw.rs:152:21 | LL | use crate::{super}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:154:21 + --> $DIR/use-path-segment-kw.rs:153:21 | LL | ... use crate::{super as _nested_super4}; | ^^^^^ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:157:20 + --> $DIR/use-path-segment-kw.rs:156:20 | LL | use super::super; | ^^^^^ @@ -224,7 +224,7 @@ LL | use super::super as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:159:21 + --> $DIR/use-path-segment-kw.rs:158:21 | LL | use super::{super}; | ^^^^^ @@ -235,7 +235,7 @@ LL | use super::{super as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:163:19 + --> $DIR/use-path-segment-kw.rs:162:19 | LL | use self::super; | ^^^^^ @@ -246,7 +246,7 @@ LL | use self::super as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:165:20 + --> $DIR/use-path-segment-kw.rs:164:20 | LL | use self::{super}; | ^^^^^ @@ -257,13 +257,18 @@ LL | use self::{super as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:173:13 + --> $DIR/use-path-segment-kw.rs:172:13 | LL | use self; | ^^^^ + | +help: try renaming it with a name + | +LL | use self as name; + | +++++++ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:177:13 + --> $DIR/use-path-segment-kw.rs:178:13 | LL | use ::self; | ^^^^^^ @@ -275,89 +280,30 @@ LL | use ::self as _self2; | ^^^^^^^^^^^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:182:16 + --> $DIR/use-path-segment-kw.rs:181:16 | LL | use ::{self}; | ^^^^ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:184:20 + --> $DIR/use-path-segment-kw.rs:183:20 | LL | pub use ::{self as _nested_self2}; | ^^^^^^^^^^^^^^^^^^^^^ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:187:28 - | -LL | pub use foobar::qux::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use foobar::qux::self; -LL + pub use foobar::qux; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use foobar::qux::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:189:23 - | -LL | pub use foobar::self as _self3; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use foobar::self as _self3; -LL + pub use foobar as _self3; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use foobar::{self as _self3}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:195:18 - | -LL | use crate::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::self; -LL + use crate; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:195:20 + --> $DIR/use-path-segment-kw.rs:194:20 | LL | use crate::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:197:22 | -LL | pub use crate::self as _self4; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::self as _self4; -LL + pub use crate as _self4; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use crate::{self as _self4}; - | + + +LL | use crate::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:198:21 + --> $DIR/use-path-segment-kw.rs:196:21 | LL | use crate::{self}; | ^^^^ @@ -367,46 +313,19 @@ help: try renaming it with a name LL | use crate::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:202:18 - | -LL | use super::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use super::self; -LL + use super; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use super::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:202:20 + --> $DIR/use-path-segment-kw.rs:200:20 | LL | use super::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:204:22 - | -LL | pub use super::self as _self5; - | ^^^^^^ - | -help: consider importing the module directly | -LL - pub use super::self as _self5; -LL + pub use super as _self5; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use super::{self as _self5}; - | + + +LL | use super::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:205:21 + --> $DIR/use-path-segment-kw.rs:202:21 | LL | use super::{self}; | ^^^^ @@ -416,46 +335,19 @@ help: try renaming it with a name LL | use super::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:209:17 - | -LL | use self::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use self::self; -LL + use self; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use self::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:209:19 + --> $DIR/use-path-segment-kw.rs:206:19 | LL | use self::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:211:21 | -LL | pub use self::self as _self6; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use self::self as _self6; -LL + pub use self as _self6; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use self::{self as _self6}; - | + + +LL | use self::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:212:20 + --> $DIR/use-path-segment-kw.rs:208:20 | LL | use self::{self}; | ^^^^ @@ -465,38 +357,6 @@ help: try renaming it with a name LL | use self::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:216:28 - | -LL | use crate::foo::bar::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::foo::bar::self; -LL + use crate::foo::bar; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::foo::bar::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:217:28 - | -LL | use crate::foo::bar::self as _self7; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::foo::bar::self as _self7; -LL + use crate::foo::bar as _self7; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::foo::bar::{self as _self7}; - | + + - error: imports need to be explicitly named --> $DIR/use-path-segment-kw.rs:11:13 | @@ -864,26 +724,6 @@ LL | ... macro_dollar_crate!(); | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:63:19 - | -LL | use $crate::self; - | ^^^^^^ -... -LL | macro_dollar_crate!(); - | --------------------- in this macro invocation - | - = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider importing the module directly - | -LL - use $crate::self; -LL + use $crate; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use $crate::{self}; - | + + - error: imports need to be explicitly named --> $DIR/use-path-segment-kw.rs:63:21 | @@ -894,29 +734,13 @@ LL | macro_dollar_crate!(); | --------------------- in this macro invocation | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:65:23 - | -LL | pub use $crate::self as _m_self8; - | ^^^^^^ -... -LL | macro_dollar_crate!(); - | --------------------- in this macro invocation - | - = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider importing the module directly - | -LL - pub use $crate::self as _m_self8; -LL + pub use $crate as _m_self8; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use $crate::{self as _m_self8}; - | + + +LL | use $crate::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:66:22 + --> $DIR/use-path-segment-kw.rs:65:22 | LL | use $crate::{self}; | ^^^^ @@ -930,14 +754,8 @@ help: try renaming it with a name LL | use $crate::{self as name}; | +++++++ -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:215:36 - | -LL | type D7 = crate::foo::bar::self; - | ^^^^ can only be used in path start position - error[E0433]: cannot find `_nested_self2` in `bar` - --> $DIR/use-path-segment-kw.rs:241:15 + --> $DIR/use-path-segment-kw.rs:237:15 | LL | foo::bar::_nested_self2::outer(); | ^^^^^^^^^^^^^ could not find `_nested_self2` in `bar` @@ -953,36 +771,83 @@ LL | macro_dollar_crate!(); | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0573]: expected type, found module `$crate::self` + --> $DIR/use-path-segment-kw.rs:62:20 + | +LL | type A10 = $crate::self; + | ^^^^^^^^^^^^ not a type +... +LL | macro_dollar_crate!(); + | --------------------- in this macro invocation + | + = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0573]: expected type, found module `crate` - --> $DIR/use-path-segment-kw.rs:96:19 + --> $DIR/use-path-segment-kw.rs:95:19 | LL | type B1 = crate; | ^^^^^ not a type error[E0573]: expected type, found module `super` - --> $DIR/use-path-segment-kw.rs:134:19 + --> $DIR/use-path-segment-kw.rs:133:19 | LL | type C1 = super; | ^^^^^ not a type error[E0573]: expected type, found module `super::super` - --> $DIR/use-path-segment-kw.rs:156:19 + --> $DIR/use-path-segment-kw.rs:155:19 | LL | type C5 = super::super; | ^^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self::super` - --> $DIR/use-path-segment-kw.rs:162:19 + --> $DIR/use-path-segment-kw.rs:161:19 | LL | type C6 = self::super; | ^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self` - --> $DIR/use-path-segment-kw.rs:172:19 + --> $DIR/use-path-segment-kw.rs:171:19 | LL | type D1 = self; | ^^^^ not a type +error[E0425]: cannot find crate `self` in the list of imported crates + --> $DIR/use-path-segment-kw.rs:175:21 + | +LL | type D2 = ::self; + | ^^^^ not found in the list of imported crates + +error[E0573]: expected type, found module `foobar::self` + --> $DIR/use-path-segment-kw.rs:185:19 + | +LL | type D3 = foobar::self; + | ^^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::self` + --> $DIR/use-path-segment-kw.rs:193:19 + | +LL | type D4 = crate::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-path-segment-kw.rs:199:19 + | +LL | type D5 = super::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `self::self` + --> $DIR/use-path-segment-kw.rs:205:19 + | +LL | type D6 = self::self; + | ^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::foo::bar::self` + --> $DIR/use-path-segment-kw.rs:211:19 + | +LL | type D7 = crate::foo::bar::self; + | ^^^^^^^^^^^^^^^^^^^^^ not a type + error[E0433]: global paths cannot start with `$crate` --> $DIR/use-path-segment-kw.rs:14:21 | @@ -1071,96 +936,55 @@ LL | macro_dollar_crate!(); | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:62:28 - | -LL | type A10 = $crate::self; - | ^^^^ can only be used in path start position -... -LL | macro_dollar_crate!(); - | --------------------- in this macro invocation - | - = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0433]: global paths cannot start with `crate` - --> $DIR/use-path-segment-kw.rs:100:21 + --> $DIR/use-path-segment-kw.rs:99:21 | LL | type B2 = ::crate; | ^^^^^ cannot start with this error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:106:27 + --> $DIR/use-path-segment-kw.rs:105:27 | LL | type B3 = foobar::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:112:26 + --> $DIR/use-path-segment-kw.rs:111:26 | LL | type B4 = crate::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:118:26 + --> $DIR/use-path-segment-kw.rs:117:26 | LL | type B5 = super::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:124:25 + --> $DIR/use-path-segment-kw.rs:123:25 | LL | type B6 = self::crate; | ^^^^^ can only be used in path start position error[E0433]: global paths cannot start with `super` - --> $DIR/use-path-segment-kw.rs:138:21 + --> $DIR/use-path-segment-kw.rs:137:21 | LL | type C2 = ::super; | ^^^^^ cannot start with this error[E0433]: `super` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:144:27 + --> $DIR/use-path-segment-kw.rs:143:27 | LL | type C3 = foobar::super; | ^^^^^ can only be used in path start position error[E0433]: `super` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:150:26 + --> $DIR/use-path-segment-kw.rs:149:26 | LL | type C4 = crate::super; | ^^^^^ can only be used in path start position -error[E0433]: global paths cannot start with `self` - --> $DIR/use-path-segment-kw.rs:176:21 - | -LL | type D2 = ::self; - | ^^^^ cannot start with this - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:186:27 - | -LL | type D3 = foobar::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:194:26 - | -LL | type D4 = crate::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:201:26 - | -LL | type D5 = super::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:208:25 - | -LL | type D6 = self::self; - | ^^^^ can only be used in path start position - -error: aborting due to 126 previous errors +error: aborting due to 114 previous errors -Some errors have detailed explanations: E0429, E0433, E0573. -For more information about an error, try `rustc --explain E0429`. +Some errors have detailed explanations: E0425, E0433, E0573. +For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/use/use-path-segment-kw.rs b/tests/ui/use/use-path-segment-kw.rs index c9b404887e605..583f07d9a81fb 100644 --- a/tests/ui/use/use-path-segment-kw.rs +++ b/tests/ui/use/use-path-segment-kw.rs @@ -59,10 +59,9 @@ macro_rules! macro_dollar_crate { use $crate::{super}; //~ ERROR `super` in paths can only be used in start position, after `self`, or after another `super` use $crate::{super as _m_nested_super8}; //~ ERROR `super` in paths can only be used in start position, after `self`, or after another `super` - type A10 = $crate::self; //~ ERROR `self` in paths can only be used in start position + type A10 = $crate::self; //~ ERROR expected type, found module `$crate::self` use $crate::self; //~ ERROR imports need to be explicitly named - //~^ ERROR `self` imports are only allowed within a { } list - pub use $crate::self as _m_self8; //~ ERROR `self` imports are only allowed within a { } list + pub use $crate::self as _m_self8; use $crate::{self}; //~ ERROR imports need to be explicitly named pub use $crate::{self as _m_nested_self8}; // Good } @@ -173,48 +172,45 @@ pub mod foo { use self; //~ ERROR imports need to be explicitly named pub use self as _self; - type D2 = ::self; //~ ERROR global paths cannot start with `self` + type D2 = ::self; + //[e2015]~^ ERROR expected type, found module `::self` + //[e2018]~^^ ERROR cannot find crate `self` in the list of imported crates use ::self; //[e2018]~ ERROR extern prelude cannot be imported //[e2015]~^ ERROR imports need to be explicitly named - //[e2015]~^^ ERROR `self` imports are only allowed within a { } list use ::self as _self2; //[e2018]~ ERROR extern prelude cannot be imported - //[e2015]~^ ERROR `self` imports are only allowed within a { } list use ::{self}; //[e2018]~ ERROR extern prelude cannot be imported //[e2015]~^ ERROR imports need to be explicitly named pub use ::{self as _nested_self2}; //[e2018]~ ERROR extern prelude cannot be imported - type D3 = foobar::self; //~ ERROR `self` in paths can only be used in start position - pub use foobar::qux::self; //~ ERROR `self` imports are only allowed within a { } list + type D3 = foobar::self; //~ ERROR expected type, found module `foobar::self` + pub use foobar::qux::self; //[e2015]~^ ERROR cannot find module or crate `foobar` in the crate root - pub use foobar::self as _self3; //~ ERROR `self` imports are only allowed within a { } list + pub use foobar::self as _self3; //[e2015]~^ ERROR unresolved import `foobar` pub use foobar::baz::{self}; //[e2015]~ ERROR cannot find module or crate `foobar` in the crate root pub use foobar::{self as _nested_self3}; //[e2015]~ ERROR unresolved import `foobar` - type D4 = crate::self; //~ ERROR `self` in paths can only be used in start position + type D4 = crate::self; //~ ERROR expected type, found module `crate::self` use crate::self; //~ ERROR imports need to be explicitly named - //~^ ERROR `self` imports are only allowed within a { } list - pub use crate::self as _self4; //~ ERROR `self` imports are only allowed within a { } list + pub use crate::self as _self4; use crate::{self}; //~ ERROR imports need to be explicitly named pub use crate::{self as _nested_self4}; // Good - type D5 = super::self; //~ ERROR `self` in paths can only be used in start position + type D5 = super::self; //~ ERROR expected type, found module `super::self` use super::self; //~ ERROR imports need to be explicitly named - //~^ ERROR `self` imports are only allowed within a { } list - pub use super::self as _self5; //~ ERROR `self` imports are only allowed within a { } list + pub use super::self as _self5; use super::{self}; //~ ERROR imports need to be explicitly named pub use super::{self as _nested_self5}; - type D6 = self::self; //~ ERROR `self` in paths can only be used in start position - use self::self; //~ ERROR `self` imports are only allowed within a { } list - //~^ ERROR imports need to be explicitly named - pub use self::self as _self6; //~ ERROR `self` imports are only allowed within a { } list + type D6 = self::self; //~ ERROR expected type, found module `self::self` + use self::self; //~ ERROR imports need to be explicitly named + pub use self::self as _self6; use self::{self}; //~ ERROR imports need to be explicitly named pub use self::{self as _nested_self6}; - type D7 = crate::foo::bar::self; //~ ERROR `self` in paths can only be used in start position - use crate::foo::bar::self; //~ ERROR `self` imports are only allowed within a { } list - use crate::foo::bar::self as _self7; //~ ERROR `self` imports are only allowed within a { } list + type D7 = crate::foo::bar::self; //~ ERROR expected type, found module `crate::foo::bar::self` + use crate::foo::bar::self; + use crate::foo::bar::self as _self7; use crate::foo::{bar::foobar::quxbaz::self}; use crate::foo::{bar::foobar::quxbaz::self as _nested_self7}; } diff --git a/tests/ui/use/use-self-at-end.e2015.stderr b/tests/ui/use/use-self-at-end.e2015.stderr index a7e458831feb4..a0f834bda1052 100644 --- a/tests/ui/use/use-self-at-end.e2015.stderr +++ b/tests/ui/use/use-self-at-end.e2015.stderr @@ -1,43 +1,16 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:14:22 - | -LL | pub use crate::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::self; -LL + pub use crate; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use crate::{self}; - | + + - error: imports need to be explicitly named --> $DIR/use-self-at-end.rs:14:24 | LL | pub use crate::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:16:22 - | -LL | pub use crate::self as crate1; - | ^^^^^^ - | -help: consider importing the module directly | -LL - pub use crate::self as crate1; -LL + pub use crate as crate1; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use crate::{self as crate1}; - | + + +LL | pub use crate::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:17:25 + --> $DIR/use-self-at-end.rs:16:25 | LL | pub use crate::{self}; | ^^^^ @@ -48,13 +21,18 @@ LL | pub use crate::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:21:17 + --> $DIR/use-self-at-end.rs:20: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 + --> $DIR/use-self-at-end.rs:22:18 | LL | pub use {self}; | ^^^^ @@ -64,46 +42,19 @@ help: try renaming it with a name LL | pub use {self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:27:21 - | -LL | pub use self::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use self::self; -LL + pub use self; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use self::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:27:23 + --> $DIR/use-self-at-end.rs:26:23 | LL | pub use self::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:29:21 | -LL | pub use self::self as self3; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use self::self as self3; -LL + pub use self as self3; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use self::{self as self3}; - | + + +LL | pub use self::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:30:24 + --> $DIR/use-self-at-end.rs:29:24 | LL | pub use self::{self}; | ^^^^ @@ -113,46 +64,19 @@ help: try renaming it with a name LL | pub use self::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:34:22 - | -LL | pub use super::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::self; -LL + pub use super; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:34:24 + --> $DIR/use-self-at-end.rs:33:24 | LL | pub use super::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:36:22 - | -LL | pub use super::self as super1; - | ^^^^^^ - | -help: consider importing the module directly | -LL - pub use super::self as super1; -LL + pub use super as super1; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use super::{self as super1}; - | + + +LL | pub use super::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:37:25 + --> $DIR/use-self-at-end.rs:36:25 | LL | pub use super::{self}; | ^^^^ @@ -162,55 +86,16 @@ help: try renaming it with a name LL | pub use super::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:41:25 - | -LL | pub use crate::x::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::x::self; -LL + pub use crate::x; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use crate::x::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:42:25 - | -LL | pub use crate::x::self as x3; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::x::self as x3; -LL + pub use crate::x as x3; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use crate::x::{self as x3}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:47:17 - | -LL | pub use ::self; - | ^^^^^^ - error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:47:19 + --> $DIR/use-self-at-end.rs:48:19 | LL | pub use ::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:50:17 | -LL | pub use ::self as crate4; - | ^^^^^^ +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:52:20 @@ -223,153 +108,32 @@ help: try renaming it with a name LL | pub use ::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:57:24 - | -LL | pub use z::self::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use z::self::self; -LL + pub use z::self; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use z::self::{self}; - | + + - -error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:57:26 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:57:20 | LL | pub use z::self::self; - | ^^^^ + | ^^^^ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:59:24 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:58:20 | LL | pub use z::self::self as z1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use z::self::self as z1; -LL + pub use z::self as z1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use z::self::{self as z1}; - | + + + | ^^^^ -error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:61:28 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:59:21 | LL | pub use z::{self::{self}}; - | ^^^^ - | -help: try renaming it with a name - | -LL | pub use z::{self::{self as name}}; - | +++++++ + | ^^^^ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:65:30 - | -LL | pub use super::Struct::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Struct::self; -LL + pub use super::Struct; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Struct::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:67:30 - | -LL | pub use super::Struct::self as Struct1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Struct::self as Struct1; -LL + pub use super::Struct as Struct1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Struct::{self as Struct1}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:73:28 - | -LL | pub use super::Enum::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Enum::self; -LL + pub use super::Enum; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Enum::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:74:28 - | -LL | pub use super::Enum::self as Enum1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Enum::self as Enum1; -LL + pub use super::Enum as Enum1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Enum::{self as Enum1}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:79:29 - | -LL | pub use super::Trait::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Trait::self; -LL + pub use super::Trait; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Trait::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:80:29 - | -LL | pub use super::Trait::self as Trait1; - | ^^^^^^ +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:60:21 | -help: consider importing the module directly - | -LL - pub use super::Trait::self as Trait1; -LL + pub use super::Trait as Trait1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Trait::{self as Trait1}; - | + + +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 + --> $DIR/use-self-at-end.rs:42:28 | LL | pub use crate::x::self; | -------------- previous import of the module `x` here @@ -383,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:75:31 + --> $DIR/use-self-at-end.rs:71:31 | LL | pub use super::Enum::self; | ----------------- previous import of the type `Enum` here @@ -397,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:81:32 + --> $DIR/use-self-at-end.rs:79:32 | LL | pub use super::Trait::self; | ------------------ previous import of the trait `Trait` here @@ -410,84 +174,104 @@ LL | pub use super::Trait::{self}; | = note: `Trait` must be defined only once in the type namespace of this module -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:59:20 - | -LL | pub use z::self::self as z1; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:62:21 - | -LL | pub use z::{self::{self as z2}}; - | ^^^^ can only be used in path start position - error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:65:24 + --> $DIR/use-self-at-end.rs:63: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:67:24 + --> $DIR/use-self-at-end.rs:64: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:69:24 + --> $DIR/use-self-at-end.rs:65: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 + | +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 + | +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 + | +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 + | +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:70:24 + --> $DIR/use-self-at-end.rs:66: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 +error[E0433]: `self` in paths can only be used in start position or last position --> $DIR/use-self-at-end.rs:56:21 | LL | type G = z::self::self; - | ^^^^ can only be used in path start position + | ^^^^ can only be used in path start position or last position -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:72:31 +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:82:25 | -LL | type I = super::Enum::self; - | ^^^^ can only be used in path start position +LL | type K = 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 - --> $DIR/use-self-at-end.rs:78:32 +error[E0573]: expected type, found module `crate::self` + --> $DIR/use-self-at-end.rs:13:18 | -LL | type J = super::Trait::self; - | ^^^^ can only be used in path start position +LL | type A = crate::self; + | ^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self` - --> $DIR/use-self-at-end.rs:20:18 + --> $DIR/use-self-at-end.rs:19:18 | LL | type B = self; | ^^^^ not a type -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:40:28 - | -LL | type E = crate::x::self; - | ^^^^ can only be used in path start position +error[E0573]: expected type, found module `self::self` + --> $DIR/use-self-at-end.rs:25:18 | -help: consider importing this module - | -LL + use x; +LL | type C = self::self; + | ^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-self-at-end.rs:32:18 | -help: if you import `x`, refer to it directly +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 | -LL - type E = crate::x::self; -LL + type E = x::self; +LL | type E = crate::x::self; + | ^^^^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `::self` + --> $DIR/use-self-at-end.rs:45:18 | +LL | type F = ::self; + | ^^^^^^ not a type error[E0223]: ambiguous associated type - --> $DIR/use-self-at-end.rs:64:18 + --> $DIR/use-self-at-end.rs:62:18 | LL | type H = super::Struct::self; | ^^^^^^^^^^^^^^^^^^^ @@ -498,31 +282,21 @@ LL - type H = super::Struct::self; LL + type H = ::self; | -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:13:25 +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/use-self-at-end.rs:74:18 | -LL | type A = crate::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:26:24 - | -LL | type C = self::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:33:25 +LL | type J = super::Trait::self; + | ^^^^^^^^^^^^^^^^^^ | -LL | type D = super::self; - | ^^^^ can only be used in path start position - -error[E0433]: global paths cannot start with `self` - --> $DIR/use-self-at-end.rs:46:20 + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default +help: if this is a dyn-compatible trait, use `dyn` | -LL | type F = ::self; - | ^^^^ cannot start with this +LL | type J = dyn super::Trait::self; + | +++ -error: aborting due to 49 previous errors +error: aborting due to 34 previous errors; 1 warning emitted -Some errors have detailed explanations: E0223, E0252, E0429, E0432, E0433, E0573. +Some errors have detailed explanations: E0223, E0252, E0432, E0433, E0573. For more information about an error, try `rustc --explain E0223`. diff --git a/tests/ui/use/use-self-at-end.e2018.stderr b/tests/ui/use/use-self-at-end.e2018.stderr index 5d56f4058069f..6d82c061d9247 100644 --- a/tests/ui/use/use-self-at-end.e2018.stderr +++ b/tests/ui/use/use-self-at-end.e2018.stderr @@ -1,43 +1,16 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:14:22 - | -LL | pub use crate::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::self; -LL + pub use crate; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use crate::{self}; - | + + - error: imports need to be explicitly named --> $DIR/use-self-at-end.rs:14:24 | LL | pub use crate::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:16:22 - | -LL | pub use crate::self as crate1; - | ^^^^^^ | -help: consider importing the module directly - | -LL - pub use crate::self as crate1; -LL + pub use crate as crate1; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use crate::{self as crate1}; - | + + +LL | pub use crate::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:17:25 + --> $DIR/use-self-at-end.rs:16:25 | LL | pub use crate::{self}; | ^^^^ @@ -48,13 +21,18 @@ LL | pub use crate::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:21:17 + --> $DIR/use-self-at-end.rs:20: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 + --> $DIR/use-self-at-end.rs:22:18 | LL | pub use {self}; | ^^^^ @@ -64,46 +42,19 @@ help: try renaming it with a name LL | pub use {self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:27:21 - | -LL | pub use self::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use self::self; -LL + pub use self; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use self::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:27:23 + --> $DIR/use-self-at-end.rs:26:23 | LL | pub use self::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:29:21 - | -LL | pub use self::self as self3; - | ^^^^^^ - | -help: consider importing the module directly | -LL - pub use self::self as self3; -LL + pub use self as self3; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use self::{self as self3}; - | + + +LL | pub use self::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:30:24 + --> $DIR/use-self-at-end.rs:29:24 | LL | pub use self::{self}; | ^^^^ @@ -113,46 +64,19 @@ help: try renaming it with a name LL | pub use self::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:34:22 - | -LL | pub use super::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::self; -LL + pub use super; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:34:24 + --> $DIR/use-self-at-end.rs:33:24 | LL | pub use super::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:36:22 - | -LL | pub use super::self as super1; - | ^^^^^^ | -help: consider importing the module directly - | -LL - pub use super::self as super1; -LL + pub use super as super1; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use super::{self as super1}; - | + + +LL | pub use super::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:37:25 + --> $DIR/use-self-at-end.rs:36:25 | LL | pub use super::{self}; | ^^^^ @@ -162,46 +86,14 @@ help: try renaming it with a name LL | pub use super::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:41:25 - | -LL | pub use crate::x::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::x::self; -LL + pub use crate::x; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use crate::x::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:42:25 - | -LL | pub use crate::x::self as x3; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::x::self as x3; -LL + pub use crate::x as x3; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use crate::x::{self as x3}; - | + + - error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:47:17 + --> $DIR/use-self-at-end.rs:48:17 | LL | pub use ::self; | ^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:50:17 + --> $DIR/use-self-at-end.rs:51:17 | LL | pub use ::self as crate4; | ^^^^^^^^^^^^^^^^ @@ -218,153 +110,32 @@ error: extern prelude cannot be imported LL | pub use ::{self as crate5}; | ^^^^^^^^^^^^^^ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:57:24 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:57:20 | LL | pub use z::self::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use z::self::self; -LL + pub use z::self; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use z::self::{self}; - | + + - -error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:57:26 - | -LL | pub use z::self::self; - | ^^^^ + | ^^^^ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:59:24 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:58:20 | LL | pub use z::self::self as z1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use z::self::self as z1; -LL + pub use z::self as z1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use z::self::{self as z1}; - | + + + | ^^^^ -error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:61:28 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:59:21 | LL | pub use z::{self::{self}}; - | ^^^^ - | -help: try renaming it with a name - | -LL | pub use z::{self::{self as name}}; - | +++++++ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:65:30 - | -LL | pub use super::Struct::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Struct::self; -LL + pub use super::Struct; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Struct::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:67:30 - | -LL | pub use super::Struct::self as Struct1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Struct::self as Struct1; -LL + pub use super::Struct as Struct1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Struct::{self as Struct1}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:73:28 - | -LL | pub use super::Enum::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Enum::self; -LL + pub use super::Enum; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Enum::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:74:28 - | -LL | pub use super::Enum::self as Enum1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Enum::self as Enum1; -LL + pub use super::Enum as Enum1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Enum::{self as Enum1}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:79:29 - | -LL | pub use super::Trait::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Trait::self; -LL + pub use super::Trait; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Trait::{self}; - | + + + | ^^^^ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:80:29 - | -LL | pub use super::Trait::self as Trait1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Trait::self as Trait1; -LL + pub use super::Trait as Trait1; +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:60:21 | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Trait::{self as Trait1}; - | + + +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 + --> $DIR/use-self-at-end.rs:42:28 | LL | pub use crate::x::self; | -------------- previous import of the module `x` here @@ -378,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:75:31 + --> $DIR/use-self-at-end.rs:71:31 | LL | pub use super::Enum::self; | ----------------- previous import of the type `Enum` here @@ -392,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:81:32 + --> $DIR/use-self-at-end.rs:79:32 | LL | pub use super::Trait::self; | ------------------ previous import of the trait `Trait` here @@ -405,84 +176,104 @@ LL | pub use super::Trait::{self}; | = note: `Trait` must be defined only once in the type namespace of this module -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:59:20 - | -LL | pub use z::self::self as z1; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:62:21 - | -LL | pub use z::{self::{self as z2}}; - | ^^^^ can only be used in path start position - error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:65:24 + --> $DIR/use-self-at-end.rs:63: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:67:24 + --> $DIR/use-self-at-end.rs:64: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:69:24 + --> $DIR/use-self-at-end.rs:65: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 + | +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 + | +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 + | +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 + | +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:70:24 + --> $DIR/use-self-at-end.rs:66: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 +error[E0433]: `self` in paths can only be used in start position or last position --> $DIR/use-self-at-end.rs:56:21 | LL | type G = z::self::self; - | ^^^^ can only be used in path start position + | ^^^^ can only be used in path start position or last position -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:72:31 +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:82:25 | -LL | type I = super::Enum::self; - | ^^^^ can only be used in path start position +LL | type K = 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 - --> $DIR/use-self-at-end.rs:78:32 +error[E0573]: expected type, found module `crate::self` + --> $DIR/use-self-at-end.rs:13:18 | -LL | type J = super::Trait::self; - | ^^^^ can only be used in path start position +LL | type A = crate::self; + | ^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self` - --> $DIR/use-self-at-end.rs:20:18 + --> $DIR/use-self-at-end.rs:19:18 | LL | type B = self; | ^^^^ not a type -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:40:28 +error[E0573]: expected type, found module `self::self` + --> $DIR/use-self-at-end.rs:25:18 | -LL | type E = crate::x::self; - | ^^^^ can only be used in path start position - | -help: consider importing this module - | -LL + use crate::x; +LL | type C = self::self; + | ^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-self-at-end.rs:32:18 | -help: if you import `x`, refer to it directly +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 | -LL - type E = crate::x::self; -LL + type E = x::self; +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 | +LL | type F = ::self; + | ^^^^ not found in the list of imported crates error[E0223]: ambiguous associated type - --> $DIR/use-self-at-end.rs:64:18 + --> $DIR/use-self-at-end.rs:62:18 | LL | type H = super::Struct::self; | ^^^^^^^^^^^^^^^^^^^ @@ -493,31 +284,21 @@ LL - type H = super::Struct::self; LL + type H = ::self; | -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:13:25 +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/use-self-at-end.rs:74:18 | -LL | type A = crate::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:26:24 - | -LL | type C = self::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:33:25 +LL | type J = super::Trait::self; + | ^^^^^^^^^^^^^^^^^^ | -LL | type D = super::self; - | ^^^^ can only be used in path start position - -error[E0433]: global paths cannot start with `self` - --> $DIR/use-self-at-end.rs:46:20 + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see + = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default +help: if this is a dyn-compatible trait, use `dyn` | -LL | type F = ::self; - | ^^^^ cannot start with this +LL | type J = dyn super::Trait::self; + | +++ -error: aborting due to 49 previous errors +error: aborting due to 36 previous errors; 1 warning emitted -Some errors have detailed explanations: E0223, E0252, E0429, E0432, E0433, E0573. +Some errors have detailed explanations: E0223, E0252, E0425, E0432, E0433, E0573. 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 84337dc9e5031..64b17483445a3 100644 --- a/tests/ui/use/use-self-at-end.rs +++ b/tests/ui/use/use-self-at-end.rs @@ -10,10 +10,9 @@ pub mod x { pub mod y { pub mod z {} - type A = crate::self; //~ ERROR `self` in paths can only be used in start position - pub use crate::self; //~ ERROR `self` imports are only allowed within a { } list - //~^ ERROR imports need to be explicitly named - pub use crate::self as crate1; //~ ERROR `self` imports are only allowed within a { } list + type A = crate::self; //~ ERROR expected type, found module `crate::self` + pub use crate::self; //~ ERROR imports need to be explicitly named + pub use crate::self as crate1; pub use crate::{self}; //~ ERROR imports need to be explicitly named pub use crate::{self as crate2}; @@ -23,63 +22,68 @@ pub mod x { pub use {self}; //~ ERROR imports need to be explicitly named pub use {self as self2}; - type C = self::self; //~ ERROR `self` in paths can only be used in start position - pub use self::self; //~ ERROR `self` imports are only allowed within a { } list + type C = self::self; //~ ERROR expected type, found module `self::self` + pub use self::self; //~^ ERROR imports need to be explicitly named - pub use self::self as self3; //~ ERROR `self` imports are only allowed within a { } list + pub use self::self as self3; pub use self::{self}; //~ ERROR imports need to be explicitly named pub use self::{self as self4}; - type D = super::self; //~ ERROR `self` in paths can only be used in start position - pub use super::self; //~ ERROR `self` imports are only allowed within a { } list + type D = super::self; //~ ERROR expected type, found module `super::self` + pub use super::self; //~^ ERROR imports need to be explicitly named - pub use super::self as super1; //~ ERROR `self` imports are only allowed within a { } list + pub use super::self as super1; pub use super::{self}; //~ ERROR imports need to be explicitly named pub use super::{self as super2}; - type E = crate::x::self; //~ ERROR `self` in paths can only be used in start position - pub use crate::x::self; //~ ERROR `self` imports are only allowed within a { } list - pub use crate::x::self as x3; //~ ERROR `self` imports are only allowed within a { } list + type E = crate::x::self; //~ ERROR expected type, found module `crate::x::self` + pub use crate::x::self; + pub use crate::x::self as x3; pub use crate::x::{self}; //~ ERROR the name `x` is defined multiple times pub use crate::x::{self as x4}; - type F = ::self; //~ ERROR global paths cannot start with `self` - pub use ::self; //[e2018]~ ERROR extern prelude cannot be imported + type F = ::self; + //[e2015]~^ ERROR expected type, found module `::self` + //[e2018]~^^ ERROR cannot find crate `self` in the list of imported crates + pub use ::self; //[e2015]~^ ERROR imports need to be explicitly named - //[e2015]~^^ ERROR `self` imports are only allowed within a { } list + //[e2018]~^^ ERROR extern prelude cannot be imported pub use ::self as crate4; //[e2018]~ ERROR extern prelude cannot be imported - //[e2015]~^ ERROR `self` imports are only allowed within a { } list pub use ::{self}; //[e2018]~ ERROR extern prelude cannot be imported //[e2015]~^ ERROR imports need to be explicitly named pub use ::{self as crate5}; //[e2018]~ 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 imports need to be explicitly named - //~^ ERROR `self` imports are only allowed within a { } list + pub use z::self::self; //~ ERROR `self` in paths can only be used in start position or last position pub use z::self::self as z1; //~ ERROR `self` in paths can only be used in start position - //~^ ERROR `self` imports are only allowed within a { } list - pub use z::{self::{self}}; //~ ERROR imports need to be explicitly named + pub use z::{self::{self}}; //~ ERROR `self` in paths can only be used in start position or last position pub use z::{self::{self as z2}}; //~ ERROR `self` in paths can only be used in start position type H = super::Struct::self; //~ ERROR ambiguous associated type pub use super::Struct::self; //~ ERROR unresolved import `super::Struct` - //~^ ERROR `self` imports are only allowed within a { } list pub use super::Struct::self as Struct1; //~ ERROR unresolved import `super::Struct` - //~^ ERROR `self` imports are only allowed within a { } list pub use super::Struct::{self}; //~ ERROR unresolved import `super::Struct` pub use super::Struct::{self as Struct2}; //~ ERROR unresolved import `super::Struct` - type I = super::Enum::self; //~ ERROR `self` in paths can only be used in start position - pub use super::Enum::self; //~ ERROR `self` imports are only allowed within a { } list - pub use super::Enum::self as Enum1; //~ ERROR `self` imports are only allowed within a { } list + type I = super::Enum::self; + pub use super::Enum::self; + pub use super::Enum::self as Enum1; pub use super::Enum::{self}; //~ ERROR the name `Enum` is defined multiple times pub use super::Enum::{self as Enum2}; - type J = super::Trait::self; //~ ERROR `self` in paths can only be used in start position - pub use super::Trait::self; //~ ERROR `self` imports are only allowed within a { } list - pub use super::Trait::self as Trait1; //~ ERROR `self` imports are only allowed within a { } list + type J = super::Trait::self; + //~^ WARN trait objects without an explicit `dyn` are deprecated + //~^^ WARN this is accepted in the current edition + 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 pub use super::Trait::{self as Trait2}; + + type K = super::self::y::z; //~ ERROR `self` in paths can only be used in start position or last position + pub use super::self::y::z; //~ ERROR `self` in paths can only be used in start position or last position + pub use super::self::y::z as z3; //~ ERROR `self` in paths can only be used in start position or last position + pub use super::self::y::{z}; //~ ERROR `self` in paths can only be used in start position or last position + pub use super::self::y::{z as z4}; //~ ERROR `self` in paths can only be used in start position or last position } } diff --git a/tests/ui/use/use-super-in-middle.stderr b/tests/ui/use/use-super-in-middle.stderr index af28edd48b44e..d33f49f5d599f 100644 --- a/tests/ui/use/use-super-in-middle.stderr +++ b/tests/ui/use/use-super-in-middle.stderr @@ -4,11 +4,11 @@ error[E0433]: `super` in paths can only be used in start position LL | pub use crate::x::super::{self as crate1}; | ^^^^^ can only be used in path start position -error[E0433]: `self` in paths can only be used in start position +error[E0433]: `self` in paths can only be used in start position or last position --> $DIR/use-super-in-middle.rs:3:23 | LL | pub use crate::x::self::super::{self as crate2}; - | ^^^^ can only be used in path start position + | ^^^^ can only be used in path start position or last position error[E0433]: `super` in paths can only be used in start position --> $DIR/use-super-in-middle.rs:12:15 @@ -16,11 +16,11 @@ error[E0433]: `super` in paths can only be used in start position LL | crate::x::super::x::foo(); | ^^^^^ can only be used in path start position -error[E0433]: `self` in paths can only be used in start position +error[E0433]: `self` in paths can only be used in start position or last position --> $DIR/use-super-in-middle.rs:13:15 | LL | crate::x::self::super::x::foo(); - | ^^^^ can only be used in path start position + | ^^^^ can only be used in path start position or last position error: aborting due to 4 previous errors diff --git a/triagebot.toml b/triagebot.toml index 19b6fa9bc5289..a0b13a46ad548 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1051,7 +1051,7 @@ cc = ["@Nadrieril"] message = "Some changes occurred in cfg and check-cfg configuration" cc = ["@Urgau"] -[mentions."compiler/rustc_lint/src/early/diagnostics/check_cfg.rs"] +[mentions."compiler/rustc_attr_parsing/src/attributes/diagnostic/check_cfg.rs"] message = "Some changes occurred in check-cfg diagnostics" cc = ["@Urgau"]