diff options
| author | bors <bors@rust-lang.org> | 2020-10-05 02:49:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-10-05 02:49:51 +0000 |
| commit | efbaa413061c2a6e52f06f00a60ee7830fcf3ea5 (patch) | |
| tree | d728ec6e5c6bbcaaf0accc89b53a176515718745 /compiler | |
| parent | ced813fec0fb9e883906f18b76d618baf9f5bc08 (diff) | |
| parent | 9dbc9ed870a3956d938c823338ac8943377845e8 (diff) | |
| download | rust-efbaa413061c2a6e52f06f00a60ee7830fcf3ea5.tar.gz rust-efbaa413061c2a6e52f06f00a60ee7830fcf3ea5.zip | |
Auto merge of #77557 - Dylan-DPC:rollup-aib9ptp, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - #75853 (Use more intra-doc-links in `core::fmt`) - #75928 (Remove trait_selection error message in specific case) - #76329 (Add check for doc alias attribute at crate level) - #77219 (core::global_allocator docs link to std::alloc::GlobalAlloc) - #77395 (BTreeMap: admit the existence of leaf edges in comments) - #77407 (Improve build-manifest to work with the improved promote-release) - #77426 (Include scope id in SocketAddrV6::Display) - #77439 (Fix missing diagnostic span for `impl Trait` with const generics, and add various tests for `min_const_generics` and `const_generics`) - #77471 (BTreeMap: refactoring around edges, missed spots) - #77512 (Allow `Abort` terminators in all const-contexts) - #77514 (Replace some once(x).chain(once(y)) with [x, y] IntoIter) Failed merges: r? `@ghost`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_feature/src/active.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/def.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/target.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/transform/check_consts/ops.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/transform/check_consts/validation.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 56 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/entry.rs | 44 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/diagnostics.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/lib.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_session/src/lint/builtin.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/object_safety.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/astconv/generics.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/astconv/mod.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/collect.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/lib.rs | 1 |
17 files changed, 110 insertions, 52 deletions
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 5cd0a56d524..cd018ae1204 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -581,7 +581,7 @@ declare_features! ( /// Allows `if let` guard in match arms. (active, if_let_guard, "1.47.0", Some(51114), None), - /// Allows non trivial generic constants which have to be manually propageted upwards. + /// Allows non-trivial generic constants which have to be manually propageted upwards. (active, const_evaluatable_checked, "1.48.0", Some(76560), None), /// Allows basic arithmetic on floating point types in a `const fn`. diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 96fde48d96c..62b12542877 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -341,9 +341,7 @@ impl<T> PerNS<Option<T>> { /// Returns an iterator over the items which are `Some`. pub fn present_items(self) -> impl Iterator<Item = T> { - use std::iter::once; - - once(self.type_ns).chain(once(self.value_ns)).chain(once(self.macro_ns)).filter_map(|it| it) + IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).filter_map(|it| it) } } diff --git a/compiler/rustc_hir/src/target.rs b/compiler/rustc_hir/src/target.rs index 1efc8bc3124..fd6a312ef3a 100644 --- a/compiler/rustc_hir/src/target.rs +++ b/compiler/rustc_hir/src/target.rs @@ -9,13 +9,13 @@ use crate::{Item, ItemKind, TraitItem, TraitItemKind}; use std::fmt::{self, Display}; -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq, Debug)] pub enum MethodKind { Trait { body: bool }, Inherent, } -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq, Debug)] pub enum Target { ExternCrate, Use, diff --git a/compiler/rustc_mir/src/transform/check_consts/ops.rs b/compiler/rustc_mir/src/transform/check_consts/ops.rs index 32e233e337d..9a1b77e994d 100644 --- a/compiler/rustc_mir/src/transform/check_consts/ops.rs +++ b/compiler/rustc_mir/src/transform/check_consts/ops.rs @@ -42,18 +42,6 @@ pub trait NonConstOp: std::fmt::Debug { } #[derive(Debug)] -pub struct Abort; -impl NonConstOp for Abort { - fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status { - mcf_status_in_item(ccx) - } - - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { - mcf_build_error(ccx, span, "abort is not stable in const fn") - } -} - -#[derive(Debug)] pub struct FloatingPointOp; impl NonConstOp for FloatingPointOp { fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status { diff --git a/compiler/rustc_mir/src/transform/check_consts/validation.rs b/compiler/rustc_mir/src/transform/check_consts/validation.rs index 4e714bfeed3..94806116eaf 100644 --- a/compiler/rustc_mir/src/transform/check_consts/validation.rs +++ b/compiler/rustc_mir/src/transform/check_consts/validation.rs @@ -434,11 +434,13 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> { fn visit_basic_block_data(&mut self, bb: BasicBlock, block: &BasicBlockData<'tcx>) { trace!("visit_basic_block_data: bb={:?} is_cleanup={:?}", bb, block.is_cleanup); - // Just as the old checker did, we skip const-checking basic blocks on the unwind path. - // These blocks often drop locals that would otherwise be returned from the function. + // We don't const-check basic blocks on the cleanup path since we never unwind during + // const-eval: a panic causes an immediate compile error. In other words, cleanup blocks + // are unreachable during const-eval. // - // FIXME: This shouldn't be unsound since a panic at compile time will cause a compiler - // error anyway, but maybe we should do more here? + // We can't be more conservative (e.g., by const-checking cleanup blocks anyways) because + // locals that would never be dropped during normal execution are sometimes dropped during + // unwinding, which means backwards-incompatible live-drop errors. if block.is_cleanup { return; } @@ -874,12 +876,16 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> { } TerminatorKind::InlineAsm { .. } => self.check_op(ops::InlineAsm), - TerminatorKind::Abort => self.check_op(ops::Abort), TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => { self.check_op(ops::Generator(hir::GeneratorKind::Gen)) } + TerminatorKind::Abort => { + // Cleanup blocks are skipped for const checking (see `visit_basic_block_data`). + span_bug!(self.span, "`Abort` terminator outside of cleanup block") + } + TerminatorKind::Assert { .. } | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index b52216c45ce..59955b27334 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -13,12 +13,14 @@ use rustc_errors::{pluralize, struct_span_err}; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; -use rustc_hir::{self, FnSig, ForeignItem, ForeignItemKind, HirId, Item, ItemKind, TraitItem}; +use rustc_hir::{ + self, FnSig, ForeignItem, ForeignItemKind, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID, +}; use rustc_hir::{MethodKind, Target}; use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES}; use rustc_session::parse::feature_err; -use rustc_span::symbol::sym; -use rustc_span::Span; +use rustc_span::symbol::{sym, Symbol}; +use rustc_span::{Span, DUMMY_SP}; pub(crate) fn target_from_impl_item<'tcx>( tcx: TyCtxt<'tcx>, @@ -333,6 +335,17 @@ impl CheckAttrVisitor<'tcx> { .emit(); return false; } + if CRATE_HIR_ID == hir_id { + self.tcx + .sess + .struct_span_err( + meta.span(), + "`#![doc(alias = \"...\")]` isn't allowed as a crate \ + level attribute", + ) + .emit(); + return false; + } } } } @@ -808,9 +821,46 @@ fn is_c_like_enum(item: &Item<'_>) -> bool { } } +fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) { + const ATTRS_TO_CHECK: &[Symbol] = &[ + sym::macro_export, + sym::repr, + sym::path, + sym::automatically_derived, + sym::start, + sym::main, + ]; + + for attr in attrs { + for attr_to_check in ATTRS_TO_CHECK { + if tcx.sess.check_name(attr, *attr_to_check) { + tcx.sess + .struct_span_err( + attr.span, + &format!( + "`{}` attribute cannot be used at crate level", + attr_to_check.to_ident_string() + ), + ) + .emit(); + } + } + } +} + fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { tcx.hir() .visit_item_likes_in_module(module_def_id, &mut CheckAttrVisitor { tcx }.as_deep_visitor()); + if module_def_id.is_top_level_module() { + CheckAttrVisitor { tcx }.check_attributes( + CRATE_HIR_ID, + tcx.hir().krate_attrs(), + &DUMMY_SP, + Target::Mod, + None, + ); + check_invalid_crate_level_attr(tcx, tcx.hir().krate_attrs()); + } } pub(crate) fn provide(providers: &mut Providers) { diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index 8aa6e7936be..e87adb378e7 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -78,29 +78,38 @@ fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(LocalDefId, EntryFnType) // Beware, this is duplicated in `librustc_builtin_macros/test_harness.rs` // (with `ast::Item`), so make sure to keep them in sync. fn entry_point_type(sess: &Session, item: &Item<'_>, at_root: bool) -> EntryPointType { - match item.kind { - ItemKind::Fn(..) => { - if sess.contains_name(&item.attrs, sym::start) { - EntryPointType::Start - } else if sess.contains_name(&item.attrs, sym::main) { - EntryPointType::MainAttr - } else if item.ident.name == sym::main { - if at_root { - // This is a top-level function so can be `main`. - EntryPointType::MainNamed - } else { - EntryPointType::OtherMain - } - } else { - EntryPointType::None - } + if sess.contains_name(&item.attrs, sym::start) { + EntryPointType::Start + } else if sess.contains_name(&item.attrs, sym::main) { + EntryPointType::MainAttr + } else if item.ident.name == sym::main { + if at_root { + // This is a top-level function so can be `main`. + EntryPointType::MainNamed + } else { + EntryPointType::OtherMain } - _ => EntryPointType::None, + } else { + EntryPointType::None } } +fn throw_attr_err(sess: &Session, span: Span, attr: &str) { + sess.struct_span_err(span, &format!("`{}` attribute can only be used on functions", attr)) + .emit(); +} + fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) { match entry_point_type(&ctxt.session, item, at_root) { + EntryPointType::None => (), + _ if !matches!(item.kind, ItemKind::Fn(..)) => { + if let Some(attr) = ctxt.session.find_by_name(item.attrs, sym::start) { + throw_attr_err(&ctxt.session, attr.span, "start"); + } + if let Some(attr) = ctxt.session.find_by_name(item.attrs, sym::main) { + throw_attr_err(&ctxt.session, attr.span, "main"); + } + } EntryPointType::MainNamed => { if ctxt.main_fn.is_none() { ctxt.main_fn = Some((item.hir_id, item.span)); @@ -137,7 +146,6 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) { .emit(); } } - EntryPointType::None => (), } } diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 612bc3e7491..e3cf6d12bd5 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -469,7 +469,7 @@ impl<'a> Resolver<'a> { ResolutionError::ParamInNonTrivialAnonConst { name, is_type } => { let mut err = self.session.struct_span_err( span, - "generic parameters must not be used inside of non trivial constant values", + "generic parameters must not be used inside of non-trivial constant values", ); err.span_label( span, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 283db1404d0..fe8f5926385 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -218,7 +218,7 @@ enum ResolutionError<'a> { ParamInTyOfConstParam(Symbol), /// constant values inside of type parameter defaults must not depend on generic parameters. ParamInAnonConstInTyDefault(Symbol), - /// generic parameters must not be used inside of non trivial constant values. + /// generic parameters must not be used inside of non-trivial constant values. /// /// This error is only emitted when using `min_const_generics`. ParamInNonTrivialAnonConst { name: Symbol, is_type: bool }, diff --git a/compiler/rustc_session/src/lint/builtin.rs b/compiler/rustc_session/src/lint/builtin.rs index 0cc97fb4541..3e899e00d11 100644 --- a/compiler/rustc_session/src/lint/builtin.rs +++ b/compiler/rustc_session/src/lint/builtin.rs @@ -518,7 +518,7 @@ declare_lint! { /// ### Example /// /// ```rust - /// #![macro_export] + /// #![ignore] /// ``` /// /// {{produces}} diff --git a/compiler/rustc_trait_selection/src/lib.rs b/compiler/rustc_trait_selection/src/lib.rs index ddeab340f38..406e8936e6e 100644 --- a/compiler/rustc_trait_selection/src/lib.rs +++ b/compiler/rustc_trait_selection/src/lib.rs @@ -11,6 +11,7 @@ //! This API is completely unstable and subject to change. #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] +#![feature(array_value_iter)] #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(drain_filter)] diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 90a8d9634ae..967374ffdc2 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1907,6 +1907,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ObligationCauseCode::BuiltinDerivedObligation(ref data) => { let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); let ty = parent_trait_ref.skip_binder().self_ty(); + if parent_trait_ref.references_error() { + err.cancel(); + return; + } + err.note(&format!("required because it appears within the type `{}`", ty)); obligated_types.push(ty); diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 2f2ac9f094d..8fc14cb2997 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -24,6 +24,7 @@ use rustc_span::symbol::Symbol; use rustc_span::Span; use smallvec::SmallVec; +use std::array; use std::iter; pub use crate::traits::{MethodViolationCode, ObjectSafetyViolation}; @@ -652,8 +653,7 @@ fn receiver_is_dispatchable<'tcx>( let caller_bounds: Vec<Predicate<'tcx>> = param_env .caller_bounds() .iter() - .chain(iter::once(unsize_predicate)) - .chain(iter::once(trait_predicate)) + .chain(array::IntoIter::new([unsize_predicate, trait_predicate])) .collect(); ty::ParamEnv::new(tcx.intern_predicates(&caller_bounds), param_env.reveal()) diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index b54de1d0916..b867798c76c 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -562,7 +562,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .args .iter() .filter_map(|arg| match arg { - GenericArg::Type(_) => Some(arg.span()), + GenericArg::Type(_) | GenericArg::Const(_) => Some(arg.span()), _ => None, }) .collect::<Vec<_>>(); diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 46b8b2e14c7..170ca2ce744 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -35,8 +35,8 @@ use rustc_trait_selection::traits::error_reporting::report_object_safety_error; use rustc_trait_selection::traits::wf::object_region_bounds; use smallvec::SmallVec; +use std::array; use std::collections::BTreeSet; -use std::iter; use std::slice; #[derive(Debug)] @@ -1346,7 +1346,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2); let is_equality = is_equality(); - let bounds = iter::once(bound).chain(iter::once(bound2)).chain(matching_candidates); + let bounds = array::IntoIter::new([bound, bound2]).chain(matching_candidates); let mut err = if is_equality.is_some() { // More specific Error Index entry. struct_span_err!( diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 9aca112a914..1f4f40fca9b 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -222,6 +222,7 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { hir::GenericParamKind::Const { .. } => { let def_id = self.tcx.hir().local_def_id(param.hir_id); self.tcx.ensure().type_of(def_id); + // FIXME(const_generics:defaults) } } } diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index 21fb92ec889..7efda54fbe0 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -56,6 +56,7 @@ This API is completely unstable and subject to change. */ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] +#![feature(array_value_iter)] #![feature(bool_to_option)] #![feature(box_syntax)] #![feature(crate_visibility_modifier)] |
