diff --git a/src/doc/unstable-book/src/language-features/const-fn.md b/src/doc/unstable-book/src/language-features/const-fn.md index d5a2243683862..50dbbaf56743c 100644 --- a/src/doc/unstable-book/src/language-features/const-fn.md +++ b/src/doc/unstable-book/src/language-features/const-fn.md @@ -1,8 +1,8 @@ # `const_fn` -The tracking issue for this feature is: [#24111] +The tracking issue for this feature is: [#57563] -[#24111]: /~https://github.com/rust-lang/rust/issues/24111 +[#57563]: /~https://github.com/rust-lang/rust/issues/57563 ------------------------ diff --git a/src/etc/lldb_batchmode.py b/src/etc/lldb_batchmode.py index 6b4c44806740f..537b419b3279f 100644 --- a/src/etc/lldb_batchmode.py +++ b/src/etc/lldb_batchmode.py @@ -18,10 +18,15 @@ import os import sys import threading -import thread import re import time +try: + import thread +except ModuleNotFoundError: + # The `thread` module was renamed to `_thread` in Python 3. + import _thread as thread + # Set this to True for additional output DEBUG_OUTPUT = False diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index f420d0d00a401..86f28a957cd2c 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -1,27 +1,22 @@ //! Functionality for ordering and comparison. //! -//! This module defines both [`PartialOrd`] and [`PartialEq`] traits which are used -//! by the compiler to implement comparison operators. Rust programs may -//! implement [`PartialOrd`] to overload the `<`, `<=`, `>`, and `>=` operators, -//! and may implement [`PartialEq`] to overload the `==` and `!=` operators. +//! This module contains various tools for ordering and comparing values. In +//! summary: //! -//! [`PartialOrd`]: trait.PartialOrd.html -//! [`PartialEq`]: trait.PartialEq.html +//! * [`Eq`] and [`PartialEq`] are traits that allow you to define total and +//! partial equality between values, respectively. Implementing them overloads +//! the `==` and `!=` operators. +//! * [`Ord`] and [`PartialOrd`] are traits that allow you to define total and +//! partial orderings between values, respectively. Implementing them overloads +//! the `<`, `<=`, `>`, and `>=` operators. +//! * [`Ordering`][cmp::Ordering] is an enum returned by the +//! main functions of [`Ord`] and [`PartialOrd`], and describes an ordering. +//! * [`Reverse`][cmp::Reverse] is a struct that allows you to easily reverse +//! an ordering. +//! * [`max`][cmp::max] and [`min`][cmp::min] are functions that build off of +//! [`Ord`] and allow you to find the maximum or minimum of two values. //! -//! # Examples -//! -//! ``` -//! let x: u32 = 0; -//! let y: u32 = 1; -//! -//! // these two lines are equivalent -//! assert_eq!(x < y, true); -//! assert_eq!(x.lt(&y), true); -//! -//! // these two lines are also equivalent -//! assert_eq!(x == y, false); -//! assert_eq!(x.eq(&y), false); -//! ``` +//! For more details, see the respective documentation of each item in the list. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index ec1aeb8a7d1e9..214b5d3a84f24 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -191,29 +191,8 @@ pub trait Write { /// assert_eq!(&buf, "world"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - fn write_fmt(&mut self, args: Arguments) -> Result { - // This Adapter is needed to allow `self` (of type `&mut - // Self`) to be cast to a Write (below) without - // requiring a `Sized` bound. - struct Adapter<'a,T: ?Sized +'a>(&'a mut T); - - impl Write for Adapter<'_, T> - where T: Write - { - fn write_str(&mut self, s: &str) -> Result { - self.0.write_str(s) - } - - fn write_char(&mut self, c: char) -> Result { - self.0.write_char(c) - } - - fn write_fmt(&mut self, args: Arguments) -> Result { - self.0.write_fmt(args) - } - } - - write(&mut Adapter(self), args) + fn write_fmt(mut self: &mut Self, args: Arguments) -> Result { + write(&mut self, args) } } @@ -268,7 +247,7 @@ struct Void { /// family of functions. It contains a function to format the given value. At /// compile time it is ensured that the function and the value have the correct /// types, and then this struct is used to canonicalize arguments to one type. -#[derive(Copy)] +#[derive(Copy, Clone)] #[allow(missing_debug_implementations)] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")] @@ -278,14 +257,6 @@ pub struct ArgumentV1<'a> { formatter: fn(&Void, &mut Formatter) -> Result, } -#[unstable(feature = "fmt_internals", reason = "internal to format_args!", - issue = "0")] -impl Clone for ArgumentV1<'_> { - fn clone(&self) -> Self { - *self - } -} - impl<'a> ArgumentV1<'a> { #[inline(never)] fn show_usize(x: &usize, f: &mut Formatter) -> Result { @@ -1105,7 +1076,7 @@ impl<'a> Formatter<'a> { self.args[i].as_usize() } rt::v1::Count::NextParam => { - self.curarg.next().and_then(|arg| arg.as_usize()) + self.curarg.next()?.as_usize() } } } @@ -1171,15 +1142,15 @@ impl<'a> Formatter<'a> { sign = Some('+'); width += 1; } - let mut prefixed = false; - if self.alternate() { - prefixed = true; width += prefix.chars().count(); + let prefixed = self.alternate(); + if prefixed { + width += prefix.chars().count(); } // Writes the sign if it exists, and then the prefix if it was requested let write_prefix = |f: &mut Formatter| { if let Some(c) = sign { - f.buf.write_str(c.encode_utf8(&mut [0; 4]))?; + f.buf.write_char(c)?; } if prefixed { f.buf.write_str(prefix) } else { Ok(()) } @@ -1341,7 +1312,7 @@ impl<'a> Formatter<'a> { // remove the sign from the formatted parts formatted.sign = b""; - width = if width < sign.len() { 0 } else { width - sign.len() }; + width = width.saturating_sub(sign.len()); align = rt::v1::Alignment::Right; self.fill = '0'; self.align = rt::v1::Alignment::Right; diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index d1bd97552024d..68da79135d3a3 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -161,6 +161,14 @@ impl f32 { self != self } + // FIXME(#50145): `abs` is publicly unavailable in libcore due to + // concerns about portability, so this implementation is for + // private use internally. + #[inline] + fn abs_private(self) -> f32 { + f32::from_bits(self.to_bits() & 0x7fff_ffff) + } + /// Returns `true` if this value is positive infinity or negative infinity and /// false otherwise. /// @@ -181,7 +189,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn is_infinite(self) -> bool { - self == INFINITY || self == NEG_INFINITY + self.abs_private() == INFINITY } /// Returns `true` if this number is neither infinite nor `NaN`. @@ -203,7 +211,9 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn is_finite(self) -> bool { - !(self.is_nan() || self.is_infinite()) + // There's no need to handle NaN separately: if self is NaN, + // the comparison is not true, exactly as desired. + self.abs_private() < INFINITY } /// Returns `true` if the number is neither zero, infinite, diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 8ada5b6756c38..b677391548146 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -161,6 +161,14 @@ impl f64 { self != self } + // FIXME(#50145): `abs` is publicly unavailable in libcore due to + // concerns about portability, so this implementation is for + // private use internally. + #[inline] + fn abs_private(self) -> f64 { + f64::from_bits(self.to_bits() & 0x7fff_ffff_ffff_ffff) + } + /// Returns `true` if this value is positive infinity or negative infinity and /// false otherwise. /// @@ -181,7 +189,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn is_infinite(self) -> bool { - self == INFINITY || self == NEG_INFINITY + self.abs_private() == INFINITY } /// Returns `true` if this number is neither infinite nor `NaN`. @@ -203,7 +211,9 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn is_finite(self) -> bool { - !(self.is_nan() || self.is_infinite()) + // There's no need to handle NaN separately: if self is NaN, + // the comparison is not true, exactly as desired. + self.abs_private() < INFINITY } /// Returns `true` if the number is neither zero, infinite, diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index b4eae4d1bb742..55a7ba181e527 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -425,8 +425,7 @@ impl<'a> Pattern<'a> for char { #[inline] fn into_searcher(self, haystack: &'a str) -> Self::Searcher { let mut utf8_encoded = [0; 4]; - self.encode_utf8(&mut utf8_encoded); - let utf8_size = self.len_utf8(); + let utf8_size = self.encode_utf8(&mut utf8_encoded).len(); CharSearcher { haystack, finger: 0, diff --git a/src/librustc/infer/lexical_region_resolve/mod.rs b/src/librustc/infer/lexical_region_resolve/mod.rs index dbf8f270ab0c9..39ce8cc621b49 100644 --- a/src/librustc/infer/lexical_region_resolve/mod.rs +++ b/src/librustc/infer/lexical_region_resolve/mod.rs @@ -13,6 +13,7 @@ use rustc_data_structures::graph::implementation::{ Direction, Graph, NodeIndex, INCOMING, OUTGOING, }; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; +use smallvec::SmallVec; use std::fmt; use std::u32; use ty::fold::TypeFoldable; @@ -190,19 +191,24 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> { match *constraint { Constraint::RegSubVar(a_region, b_vid) => { let b_data = var_values.value_mut(b_vid); - self.expand_node(a_region, b_vid, b_data) + (self.expand_node(a_region, b_vid, b_data), false) } Constraint::VarSubVar(a_vid, b_vid) => match *var_values.value(a_vid) { - VarValue::ErrorValue => false, + VarValue::ErrorValue => (false, false), VarValue::Value(a_region) => { let b_node = var_values.value_mut(b_vid); - self.expand_node(a_region, b_vid, b_node) + let changed = self.expand_node(a_region, b_vid, b_node); + let retain = match *b_node { + VarValue::Value(ReStatic) | VarValue::ErrorValue => false, + _ => true + }; + (changed, retain) } }, Constraint::RegSubReg(..) | Constraint::VarSubReg(..) => { // These constraints are checked after expansion // is done, in `collect_errors`. - false + (false, false) } } }) @@ -268,6 +274,13 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> { fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> { let tcx = self.tcx(); + + // Equal scopes can show up quite often, if the fixed point + // iteration converges slowly, skip them + if a == b { + return a; + } + match (a, b) { (&ty::ReClosureBound(..), _) | (_, &ty::ReClosureBound(..)) @@ -710,21 +723,23 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> { fn iterate_until_fixed_point(&self, tag: &str, mut body: F) where - F: FnMut(&Constraint<'tcx>, &SubregionOrigin<'tcx>) -> bool, + F: FnMut(&Constraint<'tcx>, &SubregionOrigin<'tcx>) -> (bool, bool), { + let mut constraints: SmallVec<[_; 16]> = self.data.constraints.iter().collect(); let mut iteration = 0; let mut changed = true; while changed { changed = false; iteration += 1; debug!("---- {} Iteration {}{}", "#", tag, iteration); - for (constraint, origin) in &self.data.constraints { - let edge_changed = body(constraint, origin); + constraints.retain(|(constraint, origin)| { + let (edge_changed, retain) = body(constraint, origin); if edge_changed { debug!("Updated due to constraint {:?}", constraint); changed = true; } - } + retain + }); } debug!("---- {} Complete after {} iteration(s)", tag, iteration); } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 8d4b8aae8b176..032a1621fe60b 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -59,6 +59,7 @@ use std::hash::{Hash, Hasher}; use std::fmt; use std::mem; use std::ops::{Deref, Bound}; +use std::ptr; use std::iter; use std::sync::mpsc; use std::sync::Arc; @@ -168,7 +169,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> { // Make sure we don't end up with inference // types/regions in the global interner - if local as *const _ as usize == global as *const _ as usize { + if ptr::eq(local, global) { bug!("Attempted to intern `{:?}` which contains \ inference types/regions in the global type context", &ty_struct); @@ -1135,9 +1136,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// Returns true if self is the same as self.global_tcx(). fn is_global(self) -> bool { - let local = self.interners as *const _; - let global = &self.global_interners as *const _; - local as usize == global as usize + ptr::eq(self.interners, &self.global_interners) } /// Create a type context and call the closure with a `TyCtxt` reference @@ -1787,6 +1786,7 @@ pub mod tls { use std::fmt; use std::mem; use std::marker::PhantomData; + use std::ptr; use syntax_pos; use ty::query; use errors::{Diagnostic, TRACK_DIAGNOSTICS}; @@ -2021,8 +2021,7 @@ pub mod tls { { with_context(|context| { unsafe { - let gcx = tcx.gcx as *const _ as usize; - assert!(context.tcx.gcx as *const _ as usize == gcx); + assert!(ptr::eq(context.tcx.gcx, tcx.gcx)); let context: &ImplicitCtxt<'_, '_, '_> = mem::transmute(context); f(context) } @@ -2040,10 +2039,8 @@ pub mod tls { { with_context(|context| { unsafe { - let gcx = tcx.gcx as *const _ as usize; - let interners = tcx.interners as *const _ as usize; - assert!(context.tcx.gcx as *const _ as usize == gcx); - assert!(context.tcx.interners as *const _ as usize == interners); + assert!(ptr::eq(context.tcx.gcx, tcx.gcx)); + assert!(ptr::eq(context.tcx.interners, tcx.interners)); let context: &ImplicitCtxt<'_, '_, '_> = mem::transmute(context); f(context) } diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 72ed55df94658..6deedd0b5ea33 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -47,7 +47,7 @@ use syntax_pos::{self, Span, FileName}; impl PartialEq for llvm::Metadata { fn eq(&self, other: &Self) -> bool { - self as *const _ == other as *const _ + ptr::eq(self, other) } } diff --git a/src/librustc_codegen_llvm/type_.rs b/src/librustc_codegen_llvm/type_.rs index 1462423d0da2a..958e00506d62a 100644 --- a/src/librustc_codegen_llvm/type_.rs +++ b/src/librustc_codegen_llvm/type_.rs @@ -20,12 +20,13 @@ use abi::{LlvmType, FnTypeExt}; use std::fmt; use std::cell::RefCell; +use std::ptr; use libc::c_uint; impl PartialEq for Type { fn eq(&self, other: &Self) -> bool { - self as *const _ == other as *const _ + ptr::eq(self, other) } } diff --git a/src/librustc_codegen_llvm/value.rs b/src/librustc_codegen_llvm/value.rs index 0ec964d4c422f..3ad1521be9393 100644 --- a/src/librustc_codegen_llvm/value.rs +++ b/src/librustc_codegen_llvm/value.rs @@ -4,10 +4,11 @@ use llvm; use std::fmt; use std::hash::{Hash, Hasher}; +use std::ptr; impl PartialEq for Value { fn eq(&self, other: &Self) -> bool { - self as *const _ == other as *const _ + ptr::eq(self, other) } } diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 01177e5e49a0e..f5f4048167938 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -35,6 +35,16 @@ const STEPS_UNTIL_DETECTOR_ENABLED: isize = 1_000_000; /// Should be a power of two for performance reasons. const DETECTOR_SNAPSHOT_PERIOD: isize = 256; +/// Warning: do not use this function if you expect to start interpreting the given `Mir`. +/// The `EvalContext` is only meant to be used to query values from constants and statics. +/// +/// This function is used during const propagation. We cannot use `mk_eval_cx`, because copy +/// propagation happens *during* the computation of the MIR of the current function. So if we +/// tried to call the `optimized_mir` query, we'd get a cycle error because we are (transitively) +/// inside the `optimized_mir` query of the `Instance` given. +/// +/// Since we are looking at the MIR of the function in an abstract manner, we don't have a +/// `ParamEnv` available to us. This function creates a `ParamEnv` for the given instance. pub fn mk_borrowck_eval_cx<'a, 'mir, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance<'tcx>, @@ -43,9 +53,22 @@ pub fn mk_borrowck_eval_cx<'a, 'mir, 'tcx>( ) -> EvalResult<'tcx, CompileTimeEvalContext<'a, 'mir, 'tcx>> { debug!("mk_borrowck_eval_cx: {:?}", instance); let param_env = tcx.param_env(instance.def_id()); + mk_eval_cx_inner(tcx, instance, mir, span, param_env) +} + +/// This is just a helper function to reduce code duplication between `mk_borrowck_eval_cx` and +/// `mk_eval_cx`. Do not call this function directly. +fn mk_eval_cx_inner<'a, 'mir, 'tcx>( + tcx: TyCtxt<'a, 'tcx, 'tcx>, + instance: Instance<'tcx>, + mir: &'mir mir::Mir<'tcx>, + span: Span, + param_env: ty::ParamEnv<'tcx>, +) -> EvalResult<'tcx, CompileTimeEvalContext<'a, 'mir, 'tcx>> { let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeInterpreter::new()); - // insert a stack frame so any queries have the correct substs - // cannot use `push_stack_frame`; if we do `const_prop` explodes + // Insert a stack frame so any queries have the correct substs. + // We also avoid all the extra work performed by push_stack_frame, + // like initializing local variables ecx.stack.push(interpret::Frame { block: mir::START_BLOCK, locals: IndexVec::new(), @@ -60,24 +83,23 @@ pub fn mk_borrowck_eval_cx<'a, 'mir, 'tcx>( Ok(ecx) } -pub fn mk_eval_cx<'a, 'tcx>( +/// Warning: do not use this function if you expect to start interpreting the given `Mir`. +/// The `EvalContext` is only meant to be used to do field and index projections into constants for +/// `simd_shuffle` and const patterns in match arms. +/// +/// The function containing the `match` that is currently being analyzed may have generic bounds +/// that inform us about the generic bounds of the constant. E.g. using an associated constant +/// of a function's generic parameter will require knowledge about the bounds on the generic +/// parameter. These bounds are passed to `mk_eval_cx` via the `ParamEnv` argument. +fn mk_eval_cx<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance<'tcx>, param_env: ty::ParamEnv<'tcx>, ) -> EvalResult<'tcx, CompileTimeEvalContext<'a, 'tcx, 'tcx>> { debug!("mk_eval_cx: {:?}, {:?}", instance, param_env); let span = tcx.def_span(instance.def_id()); - let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeInterpreter::new()); - let mir = ecx.load_mir(instance.def)?; - // insert a stack frame so any queries have the correct substs - ecx.push_stack_frame( - instance, - mir.span, - mir, - None, - StackPopCleanup::Goto(None), // never pop - )?; - Ok(ecx) + let mir = tcx.optimized_mir(instance.def.def_id()); + mk_eval_cx_inner(tcx, instance, mir, span, param_env) } pub(crate) fn eval_promoted<'a, 'mir, 'tcx>( diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs index a324761f06ab5..ea9e19c75c215 100644 --- a/src/librustc_mir/diagnostics.rs +++ b/src/librustc_mir/diagnostics.rs @@ -573,7 +573,7 @@ const Y: i32 = A; ``` "##, -// FIXME(#24111) Change the language here when const fn stabilizes +// FIXME(#57563) Change the language here when const fn stabilizes E0015: r##" The only functions that can be called in static or constant expressions are `const` functions, and struct/enum constructors. `const` functions are only diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 193b0fe05f002..78cf7153500c9 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -901,7 +901,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { err.emit(); } } else { - // FIXME(#24111): remove this check when const fn stabilizes. + // FIXME(#57563): remove this check when const fn stabilizes. let (msg, note) = if let UnstableFeatures::Disallow = self.tcx.sess.opts.unstable_features { (format!("calls in {}s are limited to \ diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 7c05913467c54..39be3cb744080 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2017,16 +2017,14 @@ impl<'a> Resolver<'a> { if ident.name == keywords::Invalid.name() { return Some(LexicalScopeBinding::Def(Def::Err)); } - if ns == TypeNS { - ident.span = if ident.name == keywords::SelfUpper.name() { - // FIXME(jseyfried) improve `Self` hygiene - ident.span.with_ctxt(SyntaxContext::empty()) - } else { - ident.span.modern() - } + ident.span = if ident.name == keywords::SelfUpper.name() { + // FIXME(jseyfried) improve `Self` hygiene + ident.span.with_ctxt(SyntaxContext::empty()) + } else if ns == TypeNS { + ident.span.modern() } else { - ident = ident.modern_and_legacy(); - } + ident.span.modern_and_legacy() + }; // Walk backwards up the ribs in scope. let record_used = record_used_id.is_some(); @@ -5112,6 +5110,9 @@ impl<'a> Resolver<'a> { } self.extern_prelude.get(&ident.modern()).cloned().and_then(|entry| { if let Some(binding) = entry.extern_crate_item { + if !speculative && entry.introduced_by_item { + self.record_use(ident, TypeNS, binding, false); + } Some(binding) } else { let crate_id = if !speculative { diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 891537309177e..0c9e443efe0db 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -14,7 +14,7 @@ //! recording the output. use rustc::hir::def::Def as HirDef; -use rustc::hir::def_id::{DefId, LOCAL_CRATE}; +use rustc::hir::def_id::DefId; use rustc::session::config::Input; use rustc::ty::{self, TyCtxt}; use rustc_data_structures::fx::FxHashSet; @@ -56,14 +56,14 @@ macro_rules! access_from { ($save_ctxt:expr, $vis:expr, $id:expr) => { Access { public: $vis.node.is_pub(), - reachable: $save_ctxt.tcx.privacy_access_levels(LOCAL_CRATE).is_reachable($id), + reachable: $save_ctxt.access_levels.is_reachable($id), } }; ($save_ctxt:expr, $item:expr) => { Access { public: $item.vis.node.is_pub(), - reachable: $save_ctxt.tcx.privacy_access_levels(LOCAL_CRATE).is_reachable($item.id), + reachable: $save_ctxt.access_levels.is_reachable($item.id), } }; } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index d5b3070372ba5..132bd4f1430a0 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -35,11 +35,13 @@ use rustc::hir; use rustc::hir::def::Def as HirDef; use rustc::hir::Node; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; +use rustc::middle::privacy::AccessLevels; use rustc::middle::cstore::ExternCrate; use rustc::session::config::{CrateType, Input, OutputType}; use rustc::ty::{self, TyCtxt}; use rustc_typeck::hir_ty_to_ty; use rustc_codegen_utils::link::{filename_for_metadata, out_filename}; +use rustc_data_structures::sync::Lrc; use std::cell::Cell; use std::default::Default; @@ -68,6 +70,7 @@ use rls_data::config::Config; pub struct SaveContext<'l, 'tcx: 'l> { tcx: TyCtxt<'l, 'tcx, 'tcx>, tables: &'l ty::TypeckTables<'tcx>, + access_levels: &'l AccessLevels, analysis: &'l ty::CrateAnalysis, span_utils: SpanUtils<'tcx>, config: Config, @@ -622,9 +625,11 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { Node::Visibility(&Spanned { node: hir::VisibilityKind::Restricted { ref path, .. }, .. }) => path.def, - Node::PathSegment(seg) => match seg.def { - Some(def) => def, - None => HirDef::Err, + Node::PathSegment(seg) => { + match seg.def { + Some(def) if def != HirDef::Err => def, + _ => self.get_path_def(self.tcx.hir().get_parent_node(id)), + } }, Node::Expr(&hir::Expr { node: hir::ExprKind::Struct(ref qpath, ..), @@ -1126,10 +1131,18 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>( info!("Dumping crate {}", cratename); + // Privacy checking requires and is done after type checking; use a + // fallback in case the access levels couldn't have been correctly computed. + let access_levels = match tcx.sess.compile_status() { + Ok(..) => tcx.privacy_access_levels(LOCAL_CRATE), + Err(..) => Lrc::new(AccessLevels::default()), + }; + let save_ctxt = SaveContext { tcx, tables: &ty::TypeckTables::empty(None), analysis, + access_levels: &access_levels, span_utils: SpanUtils::new(&tcx.sess), config: find_config(config), impl_counter: Cell::new(0), diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 54e4a86cc4ec5..2df137c3f5094 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -40,7 +40,7 @@ impl<'cx, 'tcx, 'v> ItemLikeVisitor<'v> for OrphanChecker<'cx, 'tcx> { "only traits defined in the current crate can be \ implemented for arbitrary types") .span_label(sp, "impl doesn't use types inside crate") - .note("the impl does not reference any types defined in this crate") + .note("the impl does not reference only types defined in this crate") .note("define and implement a trait or new type instead") .emit(); return; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 37c6407fbd1c0..6eea95b61c990 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -587,7 +587,7 @@ impl Clean for doctree::Module { let attrs = self.attrs.clean(cx); let mut items: Vec = vec![]; - items.extend(self.extern_crates.iter().map(|x| x.clean(cx))); + items.extend(self.extern_crates.iter().flat_map(|x| x.clean(cx))); items.extend(self.imports.iter().flat_map(|x| x.clean(cx))); items.extend(self.structs.iter().map(|x| x.clean(cx))); items.extend(self.unions.iter().map(|x| x.clean(cx))); @@ -3503,9 +3503,30 @@ fn build_deref_target_impls(cx: &DocContext, } } -impl Clean for doctree::ExternCrate { - fn clean(&self, cx: &DocContext) -> Item { - Item { +impl Clean> for doctree::ExternCrate { + fn clean(&self, cx: &DocContext) -> Vec { + + let please_inline = self.vis.node.is_pub() && self.attrs.iter().any(|a| { + a.name() == "doc" && match a.meta_item_list() { + Some(l) => attr::list_contains_name(&l, "inline"), + None => false, + } + }); + + if please_inline { + let mut visited = FxHashSet::default(); + + let def = Def::Mod(DefId { + krate: self.cnum, + index: CRATE_DEF_INDEX, + }); + + if let Some(items) = inline::try_inline(cx, def, self.name, &mut visited) { + return items; + } + } + + vec![Item { name: None, attrs: self.attrs.clean(cx), source: self.whence.clean(cx), @@ -3514,7 +3535,7 @@ impl Clean for doctree::ExternCrate { stability: None, deprecation: None, inner: ExternCrateItem(self.name.clean(cx), self.path.clone()) - } + }] } } diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 06c58659c08ae..08a166bd8c504 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -393,7 +393,16 @@ impl From for ExitStatus { impl fmt::Display for ExitStatus { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "exit code: {}", self.0) + // Windows exit codes with the high bit set typically mean some form of + // unhandled exception or warning. In this scenario printing the exit + // code in decimal doesn't always make sense because it's a very large + // and somewhat gibberish number. The hex code is a bit more + // recognizable and easier to search for, so print that. + if self.0 & 0x80000000 != 0 { + write!(f, "exit code: {:#x}", self.0) + } else { + write!(f, "exit code: {}", self.0) + } } } diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index d55f785bd9b4b..b4003ac729add 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -271,7 +271,7 @@ pub enum ParseResult { Success(T), /// Arm failed to match. If the second parameter is `token::Eof`, it indicates an unexpected /// end of macro invocation. Otherwise, it indicates that no rules expected the given token. - Failure(syntax_pos::Span, Token, String), + Failure(syntax_pos::Span, Token, &'static str), /// Fatal error (malformed macro?). Abort compilation. Error(syntax_pos::Span, String), } @@ -721,7 +721,7 @@ pub fn parse( sess.source_map().next_point(parser.span) }, token::Eof, - "missing tokens in macro arguments".to_string(), + "missing tokens in macro arguments", ); } } @@ -760,7 +760,7 @@ pub fn parse( return Failure( parser.span, parser.token, - "no rules expected this token in macro call".to_string(), + "no rules expected this token in macro call", ); } // Dump all possible `next_items` into `cur_items` for the next iteration. diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index cb8fbce66978b..24202ca8fbdc0 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -202,7 +202,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt, let best_fail_msg = parse_failure_msg(best_fail_tok.expect("ran no matchers")); let span = best_fail_spot.substitute_dummy(sp); let mut err = cx.struct_span_err(span, &best_fail_msg); - err.span_label(span, best_fail_text.unwrap_or(best_fail_msg)); + err.span_label(span, best_fail_text.unwrap_or(&best_fail_msg)); if let Some(sp) = def_span { if cx.source_map().span_to_filename(sp).is_real() && !sp.is_dummy() { err.span_label(cx.source_map().def_span(sp), "when calling this macro"); diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 89da1a219b70a..9b4231d8803a3 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -191,7 +191,7 @@ declare_features! ( (active, slice_patterns, "1.0.0", Some(23121), None), // Allows the definition of `const` functions with some advanced features. - (active, const_fn, "1.2.0", Some(24111), None), + (active, const_fn, "1.2.0", Some(57563), None), // Allows accessing fields of unions inside `const` functions. (active, const_fn_union, "1.27.0", Some(51909), None), diff --git a/src/test/rustdoc/auxiliary/pub-extern-crate.rs b/src/test/rustdoc/auxiliary/pub-extern-crate.rs new file mode 100644 index 0000000000000..8c89c8d6c76c5 --- /dev/null +++ b/src/test/rustdoc/auxiliary/pub-extern-crate.rs @@ -0,0 +1,2 @@ +#![crate_name = "inner"] +pub struct SomeStruct; diff --git a/src/test/rustdoc/pub-extern-crate.rs b/src/test/rustdoc/pub-extern-crate.rs new file mode 100644 index 0000000000000..26747a4d1aca5 --- /dev/null +++ b/src/test/rustdoc/pub-extern-crate.rs @@ -0,0 +1,9 @@ +// aux-build:pub-extern-crate.rs + +// @has pub_extern_crate/index.html +// @!has - '//code' 'pub extern crate inner' +// @has - '//a/@href' 'inner/index.html' +// @has pub_extern_crate/inner/index.html +// @has pub_extern_crate/inner/struct.SomeStruct.html +#[doc(inline)] +pub extern crate inner; diff --git a/src/test/ui/coherence/coherence-cow.re_a.stderr b/src/test/ui/coherence/coherence-cow.re_a.stderr index ed627600b0f5d..b0ec55a9bc578 100644 --- a/src/test/ui/coherence/coherence-cow.re_a.stderr +++ b/src/test/ui/coherence/coherence-cow.re_a.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Remote for Pair> { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-cow.re_b.stderr b/src/test/ui/coherence/coherence-cow.re_b.stderr index 1a85887ae7bc4..ce2611270938d 100644 --- a/src/test/ui/coherence/coherence-cow.re_b.stderr +++ b/src/test/ui/coherence/coherence-cow.re_b.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Remote for Pair,T> { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-cow.re_c.stderr b/src/test/ui/coherence/coherence-cow.re_c.stderr index 8043b6702b07e..1c2030d8dfea8 100644 --- a/src/test/ui/coherence/coherence-cow.re_c.stderr +++ b/src/test/ui/coherence/coherence-cow.re_c.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Remote for Pair,U> { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-fundamental-trait-objects.old.stderr b/src/test/ui/coherence/coherence-fundamental-trait-objects.old.stderr index 756ab2b102b56..2d1247e831ec4 100644 --- a/src/test/ui/coherence/coherence-fundamental-trait-objects.old.stderr +++ b/src/test/ui/coherence/coherence-fundamental-trait-objects.old.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Misc for dyn Fundamental {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-fundamental-trait-objects.re.stderr b/src/test/ui/coherence/coherence-fundamental-trait-objects.re.stderr index 756ab2b102b56..2d1247e831ec4 100644 --- a/src/test/ui/coherence/coherence-fundamental-trait-objects.re.stderr +++ b/src/test/ui/coherence/coherence-fundamental-trait-objects.re.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Misc for dyn Fundamental {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-impls-copy.old.stderr b/src/test/ui/coherence/coherence-impls-copy.old.stderr index defbbbadd5598..e870c267ce141 100644 --- a/src/test/ui/coherence/coherence-impls-copy.old.stderr +++ b/src/test/ui/coherence/coherence-impls-copy.old.stderr @@ -51,7 +51,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Copy for i32 {} | ^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -60,7 +60,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Copy for (MyType, MyType) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -69,7 +69,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Copy for [MyType] {} | ^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -78,7 +78,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Copy for &'static [NotSync] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to 10 previous errors diff --git a/src/test/ui/coherence/coherence-impls-copy.re.stderr b/src/test/ui/coherence/coherence-impls-copy.re.stderr index defbbbadd5598..e870c267ce141 100644 --- a/src/test/ui/coherence/coherence-impls-copy.re.stderr +++ b/src/test/ui/coherence/coherence-impls-copy.re.stderr @@ -51,7 +51,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Copy for i32 {} | ^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -60,7 +60,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Copy for (MyType, MyType) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -69,7 +69,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Copy for [MyType] {} | ^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -78,7 +78,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Copy for &'static [NotSync] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to 10 previous errors diff --git a/src/test/ui/coherence/coherence-impls-send.old.stderr b/src/test/ui/coherence/coherence-impls-send.old.stderr index ca45c28ec2d74..3ede8363d119e 100644 --- a/src/test/ui/coherence/coherence-impls-send.old.stderr +++ b/src/test/ui/coherence/coherence-impls-send.old.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | unsafe impl Send for (MyType, MyType) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0321]: cross-crate traits with a default impl, like `std::marker::Send`, can only be implemented for a struct/enum type, not `&'static NotSync` @@ -19,7 +19,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | unsafe impl Send for [MyType] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -28,7 +28,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | unsafe impl Send for &'static [NotSync] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to 4 previous errors diff --git a/src/test/ui/coherence/coherence-impls-send.re.stderr b/src/test/ui/coherence/coherence-impls-send.re.stderr index ca45c28ec2d74..3ede8363d119e 100644 --- a/src/test/ui/coherence/coherence-impls-send.re.stderr +++ b/src/test/ui/coherence/coherence-impls-send.re.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | unsafe impl Send for (MyType, MyType) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0321]: cross-crate traits with a default impl, like `std::marker::Send`, can only be implemented for a struct/enum type, not `&'static NotSync` @@ -19,7 +19,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | unsafe impl Send for [MyType] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -28,7 +28,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | unsafe impl Send for &'static [NotSync] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to 4 previous errors diff --git a/src/test/ui/coherence/coherence-impls-sized.old.stderr b/src/test/ui/coherence/coherence-impls-sized.old.stderr index c9c7dd0ed6688..86a0996554d41 100644 --- a/src/test/ui/coherence/coherence-impls-sized.old.stderr +++ b/src/test/ui/coherence/coherence-impls-sized.old.stderr @@ -40,7 +40,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Sized for (MyType, MyType) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -49,7 +49,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Sized for [MyType] {} | ^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -58,7 +58,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Sized for &'static [NotSync] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to 9 previous errors diff --git a/src/test/ui/coherence/coherence-impls-sized.re.stderr b/src/test/ui/coherence/coherence-impls-sized.re.stderr index c9c7dd0ed6688..86a0996554d41 100644 --- a/src/test/ui/coherence/coherence-impls-sized.re.stderr +++ b/src/test/ui/coherence/coherence-impls-sized.re.stderr @@ -40,7 +40,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Sized for (MyType, MyType) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -49,7 +49,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Sized for [MyType] {} | ^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -58,7 +58,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Sized for &'static [NotSync] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to 9 previous errors diff --git a/src/test/ui/coherence/coherence-orphan.old.stderr b/src/test/ui/coherence/coherence-orphan.old.stderr index da5de461bf41b..e6dc17d95a241 100644 --- a/src/test/ui/coherence/coherence-orphan.old.stderr +++ b/src/test/ui/coherence/coherence-orphan.old.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl TheTrait for isize { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -13,7 +13,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl !Send for Vec { } | ^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to 2 previous errors diff --git a/src/test/ui/coherence/coherence-orphan.re.stderr b/src/test/ui/coherence/coherence-orphan.re.stderr index da5de461bf41b..e6dc17d95a241 100644 --- a/src/test/ui/coherence/coherence-orphan.re.stderr +++ b/src/test/ui/coherence/coherence-orphan.re.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl TheTrait for isize { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -13,7 +13,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl !Send for Vec { } | ^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to 2 previous errors diff --git a/src/test/ui/coherence/coherence-overlapping-pairs.re.stderr b/src/test/ui/coherence/coherence-overlapping-pairs.re.stderr index 0f2ec6f4ce069..a6fa609deb214 100644 --- a/src/test/ui/coherence/coherence-overlapping-pairs.re.stderr +++ b/src/test/ui/coherence/coherence-overlapping-pairs.re.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Remote for lib::Pair { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-pair-covered-uncovered-1.re.stderr b/src/test/ui/coherence/coherence-pair-covered-uncovered-1.re.stderr index 0c654ca41835d..e45cd78363ca7 100644 --- a/src/test/ui/coherence/coherence-pair-covered-uncovered-1.re.stderr +++ b/src/test/ui/coherence/coherence-pair-covered-uncovered-1.re.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Remote1>> for i32 { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-pair-covered-uncovered.re.stderr b/src/test/ui/coherence/coherence-pair-covered-uncovered.re.stderr index 9bddc15390212..54d5f3058a85c 100644 --- a/src/test/ui/coherence/coherence-pair-covered-uncovered.re.stderr +++ b/src/test/ui/coherence/coherence-pair-covered-uncovered.re.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Remote for Pair> { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-vec-local-2.re.stderr b/src/test/ui/coherence/coherence-vec-local-2.re.stderr index 37859f7cfa285..6992aa7a0bdc6 100644 --- a/src/test/ui/coherence/coherence-vec-local-2.re.stderr +++ b/src/test/ui/coherence/coherence-vec-local-2.re.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Remote for Vec> { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-vec-local.old.stderr b/src/test/ui/coherence/coherence-vec-local.old.stderr index 304aaaf36875c..b35e7a8ba8bed 100644 --- a/src/test/ui/coherence/coherence-vec-local.old.stderr +++ b/src/test/ui/coherence/coherence-vec-local.old.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Remote for Vec { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-vec-local.re.stderr b/src/test/ui/coherence/coherence-vec-local.re.stderr index 304aaaf36875c..b35e7a8ba8bed 100644 --- a/src/test/ui/coherence/coherence-vec-local.re.stderr +++ b/src/test/ui/coherence/coherence-vec-local.re.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Remote for Vec { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_local_err_struct.old.stderr b/src/test/ui/coherence/coherence_local_err_struct.old.stderr index 61c94c1c7cad7..e1f651493f67c 100644 --- a/src/test/ui/coherence/coherence_local_err_struct.old.stderr +++ b/src/test/ui/coherence/coherence_local_err_struct.old.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl lib::MyCopy for lib::MyStruct { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_local_err_struct.re.stderr b/src/test/ui/coherence/coherence_local_err_struct.re.stderr index 61c94c1c7cad7..e1f651493f67c 100644 --- a/src/test/ui/coherence/coherence_local_err_struct.re.stderr +++ b/src/test/ui/coherence/coherence_local_err_struct.re.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl lib::MyCopy for lib::MyStruct { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_local_err_tuple.old.stderr b/src/test/ui/coherence/coherence_local_err_tuple.old.stderr index 934e2fcb890e3..171daa54861fe 100644 --- a/src/test/ui/coherence/coherence_local_err_tuple.old.stderr +++ b/src/test/ui/coherence/coherence_local_err_tuple.old.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl lib::MyCopy for (MyType,) { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_local_err_tuple.re.stderr b/src/test/ui/coherence/coherence_local_err_tuple.re.stderr index 934e2fcb890e3..171daa54861fe 100644 --- a/src/test/ui/coherence/coherence_local_err_tuple.re.stderr +++ b/src/test/ui/coherence/coherence_local_err_tuple.re.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl lib::MyCopy for (MyType,) { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to previous error diff --git a/src/test/ui/dropck/drop-on-non-struct.stderr b/src/test/ui/dropck/drop-on-non-struct.stderr index c458635040a21..6b670d5d434e4 100644 --- a/src/test/ui/dropck/drop-on-non-struct.stderr +++ b/src/test/ui/dropck/drop-on-non-struct.stderr @@ -10,7 +10,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl<'a> Drop for &'a mut isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to 2 previous errors diff --git a/src/test/ui/error-codes/E0117.stderr b/src/test/ui/error-codes/E0117.stderr index 8e32db49cedee..b007ca05ab2cf 100644 --- a/src/test/ui/error-codes/E0117.stderr +++ b/src/test/ui/error-codes/E0117.stderr @@ -10,7 +10,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Drop for u32 {} //~ ERROR E0117 | ^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to 2 previous errors diff --git a/src/test/ui/error-codes/E0206.stderr b/src/test/ui/error-codes/E0206.stderr index 499c6ae3f8852..a0c4b0149a099 100644 --- a/src/test/ui/error-codes/E0206.stderr +++ b/src/test/ui/error-codes/E0206.stderr @@ -16,7 +16,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Copy for Foo { } | ^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to 3 previous errors diff --git a/src/test/ui/feature-gates/feature-gate-const_fn.stderr b/src/test/ui/feature-gates/feature-gate-const_fn.stderr index b3fc587b1cf77..be5237fbfcf3b 100644 --- a/src/test/ui/feature-gates/feature-gate-const_fn.stderr +++ b/src/test/ui/feature-gates/feature-gate-const_fn.stderr @@ -16,7 +16,7 @@ error[E0379]: trait fns cannot be declared const LL | const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const | ^^^^^ trait fns cannot be const -error[E0658]: const fn is unstable (see issue #24111) +error[E0658]: const fn is unstable (see issue #57563) --> $DIR/feature-gate-const_fn.rs:6:5 | LL | const fn foo() -> u32; //~ ERROR const fn is unstable @@ -24,7 +24,7 @@ LL | const fn foo() -> u32; //~ ERROR const fn is unstable | = help: add #![feature(const_fn)] to the crate attributes to enable -error[E0658]: const fn is unstable (see issue #24111) +error[E0658]: const fn is unstable (see issue #57563) --> $DIR/feature-gate-const_fn.rs:8:5 | LL | const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable diff --git a/src/test/ui/feature-gates/feature-gate-min_const_fn.stderr b/src/test/ui/feature-gates/feature-gate-min_const_fn.stderr index bcc5b0198c319..056e33111f0df 100644 --- a/src/test/ui/feature-gates/feature-gate-min_const_fn.stderr +++ b/src/test/ui/feature-gates/feature-gate-min_const_fn.stderr @@ -16,7 +16,7 @@ error[E0379]: trait fns cannot be declared const LL | const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const | ^^^^^ trait fns cannot be const -error[E0658]: const fn is unstable (see issue #24111) +error[E0658]: const fn is unstable (see issue #57563) --> $DIR/feature-gate-min_const_fn.rs:6:5 | LL | const fn foo() -> u32; //~ ERROR const fn is unstable @@ -24,7 +24,7 @@ LL | const fn foo() -> u32; //~ ERROR const fn is unstable | = help: add #![feature(const_fn)] to the crate attributes to enable -error[E0658]: const fn is unstable (see issue #24111) +error[E0658]: const fn is unstable (see issue #57563) --> $DIR/feature-gate-min_const_fn.rs:8:5 | LL | const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable diff --git a/src/test/ui/imports/extern-crate-used.rs b/src/test/ui/imports/extern-crate-used.rs new file mode 100644 index 0000000000000..2d91cbc00f27d --- /dev/null +++ b/src/test/ui/imports/extern-crate-used.rs @@ -0,0 +1,28 @@ +// Extern crate items are marked as used if they are used +// through extern prelude entries introduced by them. + +// edition:2018 + +#![deny(unused_extern_crates)] + +extern crate core as iso1; //~ ERROR `extern crate` is not idiomatic in the new edition +extern crate core as iso2; //~ ERROR `extern crate` is not idiomatic in the new edition +extern crate core as iso3; //~ ERROR `extern crate` is not idiomatic in the new edition +extern crate core as iso4; //~ ERROR `extern crate` is not idiomatic in the new edition + +// Doesn't introduce its extern prelude entry, so it's still considered unused. +extern crate core; //~ ERROR unused extern crate + +mod m { + use iso1::any as are_you_okay1; + use ::iso2::any as are_you_okay2; + type AreYouOkay1 = iso3::any::Any; + type AreYouOkay2 = ::iso4::any::Any; + + use core::any as are_you_okay3; + use ::core::any as are_you_okay4; + type AreYouOkay3 = core::any::Any; + type AreYouOkay4 = ::core::any::Any; +} + +fn main() {} diff --git a/src/test/ui/imports/extern-crate-used.stderr b/src/test/ui/imports/extern-crate-used.stderr new file mode 100644 index 0000000000000..3f9aab9dc79cb --- /dev/null +++ b/src/test/ui/imports/extern-crate-used.stderr @@ -0,0 +1,38 @@ +error: `extern crate` is not idiomatic in the new edition + --> $DIR/extern-crate-used.rs:8:1 + | +LL | extern crate core as iso1; //~ ERROR `extern crate` is not idiomatic in the new edition + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use` + | +note: lint level defined here + --> $DIR/extern-crate-used.rs:6:9 + | +LL | #![deny(unused_extern_crates)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: `extern crate` is not idiomatic in the new edition + --> $DIR/extern-crate-used.rs:9:1 + | +LL | extern crate core as iso2; //~ ERROR `extern crate` is not idiomatic in the new edition + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use` + +error: `extern crate` is not idiomatic in the new edition + --> $DIR/extern-crate-used.rs:10:1 + | +LL | extern crate core as iso3; //~ ERROR `extern crate` is not idiomatic in the new edition + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use` + +error: `extern crate` is not idiomatic in the new edition + --> $DIR/extern-crate-used.rs:11:1 + | +LL | extern crate core as iso4; //~ ERROR `extern crate` is not idiomatic in the new edition + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use` + +error: unused extern crate + --> $DIR/extern-crate-used.rs:14:1 + | +LL | extern crate core; //~ ERROR unused extern crate + | ^^^^^^^^^^^^^^^^^^ help: remove it + +error: aborting due to 5 previous errors + diff --git a/src/test/ui/resolve/issue-57523.rs b/src/test/ui/resolve/issue-57523.rs new file mode 100644 index 0000000000000..c2a2f28254226 --- /dev/null +++ b/src/test/ui/resolve/issue-57523.rs @@ -0,0 +1,21 @@ +// compile-pass + +struct S(u8); + +impl S { + fn method1() -> Self { + Self(0) + } +} + +macro_rules! define_method { () => { + impl S { + fn method2() -> Self { + Self(0) // OK + } + } +}} + +define_method!(); + +fn main() {} diff --git a/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr b/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr index b8b743d3f4072..2bfb4110603f5 100644 --- a/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr +++ b/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl DefaultedTrait for (A,) { } //~ ERROR E0117 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types @@ -13,7 +13,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl !DefaultedTrait for (B,) { } //~ ERROR E0117 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error[E0321]: cross-crate traits with a default impl, like `lib::DefaultedTrait`, can only be implemented for a struct/enum type defined in the current crate @@ -28,7 +28,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl DefaultedTrait for lib::Something { } //~ ERROR E0117 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | - = note: the impl does not reference any types defined in this crate + = note: the impl does not reference only types defined in this crate = note: define and implement a trait or new type instead error: aborting due to 4 previous errors diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index 049a0ee49f0a4..2435a0cfd4e38 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -336,12 +336,11 @@ fn map_lib_features(base_src_path: &Path, level: Status::Unstable, since: "None".to_owned(), has_gate_test: false, - // Whether there is a common tracking issue - // for these feature gates remains an open question - // /~https://github.com/rust-lang/rust/issues/24111#issuecomment-340283184 - // But we take 24111 otherwise they will be shown as - // "internal to the compiler" which they are not. - tracking_issue: Some(24111), + // FIXME(#57563): #57563 is now used as a common tracking issue, + // although we would like to have specific tracking + // issues for each `rustc_const_unstable` in the + // future. + tracking_issue: Some(57563), }; mf(Ok((feature_name, feature)), file, i + 1); continue;