diff --git a/.gitignore b/.gitignore index 309fbd95345a4..57407a2399a2f 100644 --- a/.gitignore +++ b/.gitignore @@ -95,7 +95,6 @@ config.stamp keywords.md lexer.ml src/etc/dl -src/librustc_llvm/llvmdeps.rs tmp.*.rs version.md version.ml diff --git a/src/Cargo.lock b/src/Cargo.lock index cde93b1a6a617..ae82c07cfcf1f 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -2014,7 +2014,6 @@ version = "0.0.0" dependencies = [ "build_helper 0.1.0", "cc 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "html-diff 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 9186699a3b583..3c12cfc4c7ffd 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -159,7 +159,7 @@ impl Step for CargoBook { let target = self.target; let name = self.name; - let src = PathBuf::from("src/tools/cargo/src/doc/book"); + let src = build.src.join("src/tools/cargo/src/doc/book"); let out = build.doc_out(target); t!(fs::create_dir_all(&out)); diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index ac068ebe65178..a5408ee381bbb 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -316,7 +316,7 @@ impl Step for TestHelpers { .warnings(false) .debug(false) .file(build.src.join("src/rt/rust_test_helpers.c")) - .compile("librust_test_helpers.a"); + .compile("rust_test_helpers"); } } diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs index a41a04d7cd4f6..de5006ad3960a 100644 --- a/src/liballoc_jemalloc/build.rs +++ b/src/liballoc_jemalloc/build.rs @@ -140,6 +140,6 @@ fn main() { cc::Build::new() .flag("-fvisibility=hidden") .file("pthread_atfork_dummy.c") - .compile("libpthread_atfork_dummy.a"); + .compile("pthread_atfork_dummy"); } } diff --git a/src/libcompiler_builtins b/src/libcompiler_builtins index 02b3734a5ba6d..18feaccbfd0df 160000 --- a/src/libcompiler_builtins +++ b/src/libcompiler_builtins @@ -1 +1 @@ -Subproject commit 02b3734a5ba6de984eb5a02c50860cc014e58d56 +Subproject commit 18feaccbfd0dfbd5ab5d0a2a6eac9c04be667266 diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index 22f788e34ecff..4a6841aedca12 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -95,7 +95,7 @@ impl FromStr for TokenStream { // notify the expansion info that it is unhygienic let mark = Mark::fresh(mark); mark.set_expn_info(expn_info); - let span = call_site.with_ctxt(SyntaxContext::empty().apply_mark(mark)); + let span = call_site.with_ctxt(call_site.ctxt().apply_mark(mark)); let stream = parse::parse_stream_from_source_str(name, src, sess, Some(span)); Ok(__internal::token_stream_wrap(stream)) }) diff --git a/src/libprofiler_builtins/build.rs b/src/libprofiler_builtins/build.rs index 8508b2dae2c56..dd88dd933f691 100644 --- a/src/libprofiler_builtins/build.rs +++ b/src/libprofiler_builtins/build.rs @@ -56,5 +56,5 @@ fn main() { cfg.file(Path::new("../libcompiler_builtins/compiler-rt/lib/profile").join(src)); } - cfg.compile("libprofiler-rt.a"); + cfg.compile("profiler-rt"); } diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index dfa675f2e9351..7c2f0bc3cef84 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -575,7 +575,8 @@ impl Definitions { self.node_to_def_index.insert(node_id, index); } - if expansion.is_modern() { + let expansion = expansion.modern(); + if expansion != Mark::root() { self.expansions.insert(index, expansion); } diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index bccef6dc91bcd..77bf3da679dd7 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -884,13 +884,13 @@ impl<'gcx> HashStable> for hir::Item { fn hash_stable(&self, hcx: &mut StableHashingContext<'gcx>, hasher: &mut StableHasher) { - let (is_const, hash_spans) = match self.node { + let is_const = match self.node { hir::ItemStatic(..) | hir::ItemConst(..) => { - (true, hcx.hash_spans()) + true } hir::ItemFn(_, _, constness, ..) => { - (constness == hir::Constness::Const, hcx.hash_spans()) + constness == hir::Constness::Const } hir::ItemUse(..) | hir::ItemExternCrate(..) | @@ -904,7 +904,7 @@ impl<'gcx> HashStable> for hir::Item { hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemUnion(..) => { - (false, false) + false } }; @@ -919,13 +919,11 @@ impl<'gcx> HashStable> for hir::Item { } = *self; hcx.hash_hir_item_like(attrs, is_const, |hcx| { - hcx.while_hashing_spans(hash_spans, |hcx| { - name.hash_stable(hcx, hasher); - attrs.hash_stable(hcx, hasher); - node.hash_stable(hcx, hasher); - vis.hash_stable(hcx, hasher); - span.hash_stable(hcx, hasher); - }); + name.hash_stable(hcx, hasher); + attrs.hash_stable(hcx, hasher); + node.hash_stable(hcx, hasher); + vis.hash_stable(hcx, hasher); + span.hash_stable(hcx, hasher); }); } } diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 6fadafc7b97ae..514b29120a96a 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -555,6 +555,39 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { fn cmp(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) -> (DiagnosticStyledString, DiagnosticStyledString) { + fn equals<'tcx>(a: &Ty<'tcx>, b: &Ty<'tcx>) -> bool { + match (&a.sty, &b.sty) { + (a, b) if *a == *b => true, + (&ty::TyInt(_), &ty::TyInfer(ty::InferTy::IntVar(_))) | + (&ty::TyInfer(ty::InferTy::IntVar(_)), &ty::TyInt(_)) | + (&ty::TyInfer(ty::InferTy::IntVar(_)), &ty::TyInfer(ty::InferTy::IntVar(_))) | + (&ty::TyFloat(_), &ty::TyInfer(ty::InferTy::FloatVar(_))) | + (&ty::TyInfer(ty::InferTy::FloatVar(_)), &ty::TyFloat(_)) | + (&ty::TyInfer(ty::InferTy::FloatVar(_)), + &ty::TyInfer(ty::InferTy::FloatVar(_))) => true, + _ => false, + } + } + + fn push_ty_ref<'tcx>(r: &ty::Region<'tcx>, + tnm: &ty::TypeAndMut<'tcx>, + s: &mut DiagnosticStyledString) { + let r = &format!("{}", r); + s.push_highlighted(format!("&{}{}{}", + r, + if r == "" { + "" + } else { + " " + }, + if tnm.mutbl == hir::MutMutable { + "mut " + } else { + "" + })); + s.push_normal(format!("{}", tnm.ty)); + } + match (&t1.sty, &t2.sty) { (&ty::TyAdt(def1, sub1), &ty::TyAdt(def2, sub2)) => { let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); @@ -672,6 +705,29 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { DiagnosticStyledString::highlighted(format!("{}", t2))) } } + + // When finding T != &T, hightlight only the borrow + (&ty::TyRef(r1, ref tnm1), _) if equals(&tnm1.ty, &t2) => { + let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); + push_ty_ref(&r1, tnm1, &mut values.0); + values.1.push_normal(format!("{}", t2)); + values + } + (_, &ty::TyRef(r2, ref tnm2)) if equals(&t1, &tnm2.ty) => { + let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); + values.0.push_normal(format!("{}", t1)); + push_ty_ref(&r2, tnm2, &mut values.1); + values + } + + // When encountering &T != &mut T, highlight only the borrow + (&ty::TyRef(r1, ref tnm1), &ty::TyRef(r2, ref tnm2)) if equals(&tnm1.ty, &tnm2.ty) => { + let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); + push_ty_ref(&r1, tnm1, &mut values.0); + push_ty_ref(&r2, tnm2, &mut values.1); + values + } + _ => { if t1 == t2 { // The two types are the same, elide and don't highlight. diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index ef4a1c8c39949..1008da1e937a5 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -222,6 +222,12 @@ declare_lint! { "detect mut variables which don't need to be mutable" } +declare_lint! { + pub COERCE_NEVER, + Deny, + "detect coercion to !" +} + /// Does nothing as a lint pass, but registers some `Lint`s /// which are used by other parts of the compiler. #[derive(Copy, Clone)] @@ -263,7 +269,8 @@ impl LintPass for HardwiredLints { LATE_BOUND_LIFETIME_ARGUMENTS, DEPRECATED, UNUSED_UNSAFE, - UNUSED_MUT + UNUSED_MUT, + COERCE_NEVER ) } } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 583dcb46f000c..a63c89a03269b 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2302,9 +2302,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn item_name(self, id: DefId) -> InternedString { - if let Some(id) = self.hir.as_local_node_id(id) { - self.hir.name(id).as_str() - } else if id.index == CRATE_DEF_INDEX { + if id.index == CRATE_DEF_INDEX { self.original_crate_name(id.krate).as_str() } else { let def_key = self.def_key(id); diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index b4d439f0ba809..c352198e8463f 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -247,6 +247,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { id: LintId::of(SAFE_PACKED_BORROWS), reference: "issue #46043 ", }, + FutureIncompatibleInfo { + id: LintId::of(COERCE_NEVER), + reference: "issue #46325 ", + }, ]); diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index 141a9a8d704d2..f294ceb3f3832 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -154,13 +154,13 @@ fn main() { } for component in &components { - let mut flag = String::from("-DLLVM_COMPONENT_"); + let mut flag = String::from("LLVM_COMPONENT_"); flag.push_str(&component.to_uppercase()); - cfg.flag(&flag); + cfg.define(&flag, None); } if env::var_os("LLVM_RUSTLLVM").is_some() { - cfg.flag("-DLLVM_RUSTLLVM"); + cfg.define("LLVM_RUSTLLVM", None); } build_helper::rerun_if_changed_anything_in_dir(Path::new("../rustllvm")); @@ -169,7 +169,7 @@ fn main() { .file("../rustllvm/ArchiveWrapper.cpp") .cpp(true) .cpp_link_stdlib(None) // we handle this below - .compile("librustllvm.a"); + .compile("rustllvm"); let (llvm_kind, llvm_link_arg) = detect_llvm_link(major, minor, &llvm_config); diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index dd64d76bc0c51..1c2fa1bbb4848 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -505,17 +505,13 @@ pub mod debuginfo { pub enum ModuleBuffer {} -// Link to our native llvm bindings (things that we need to use the C++ api -// for) and because llvm is written in C++ we need to link against libstdc++ -// -// You'll probably notice that there is an omission of all LLVM libraries -// from this location. This is because the set of LLVM libraries that we -// link to is mostly defined by LLVM, and the `llvm-config` tool is used to -// figure out the exact set of libraries. To do this, the build system -// generates an llvmdeps.rs file next to this one which will be -// automatically updated whenever LLVM is updated to include an up-to-date -// set of the libraries we need to link to LLVM for. -#[link(name = "rustllvm", kind = "static")] // not quite true but good enough +// This annotation is primarily needed for MSVC where attributes like +// dllimport/dllexport are applied and need to be correct for everything to +// link successfully. The #[link] annotation here says "these symbols are +// included statically" which means that they're all exported with dllexport +// and from the rustc_llvm dynamic library. Otherwise the rustc_trans dynamic +// library would not be able to access these symbols. +#[link(name = "rustllvm", kind = "static")] extern "C" { // Create and destroy contexts. pub fn LLVMContextCreate() -> ContextRef; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 3243152527ffc..85e2144f6cd79 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1560,6 +1560,15 @@ impl<'a> Resolver<'a> { } } + fn macro_def(&self, mut ctxt: SyntaxContext) -> DefId { + loop { + match self.macro_defs.get(&ctxt.outer()) { + Some(&def_id) => return def_id, + None => ctxt.remove_mark(), + }; + } + } + /// Entry point to crate resolution. pub fn resolve_crate(&mut self, krate: &Crate) { ImportResolver { resolver: self }.finalize_imports(); @@ -1663,7 +1672,7 @@ impl<'a> Resolver<'a> { module = match self.ribs[ns][i].kind { ModuleRibKind(module) => module, - MacroDefinition(def) if def == self.macro_defs[&ident.ctxt.outer()] => { + MacroDefinition(def) if def == self.macro_def(ident.ctxt) => { // If an invocation of this macro created `ident`, give up on `ident` // and switch to `ident`'s source from the macro definition. ident.ctxt.remove_mark(); @@ -1830,7 +1839,7 @@ impl<'a> Resolver<'a> { // If an invocation of this macro created `ident`, give up on `ident` // and switch to `ident`'s source from the macro definition. MacroDefinition(def) => { - if def == self.macro_defs[&ident.ctxt.outer()] { + if def == self.macro_def(ident.ctxt) { ident.ctxt.remove_mark(); } } diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 94422f93e5922..3e725d7ef415c 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -66,6 +66,7 @@ use rustc::hir; use rustc::hir::def_id::DefId; use rustc::infer::{Coercion, InferResult, InferOk}; use rustc::infer::type_variable::TypeVariableOrigin; +use rustc::lint; use rustc::traits::{self, ObligationCause, ObligationCauseCode}; use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow}; use rustc::ty::{self, LvaluePreference, TypeAndMut, @@ -754,7 +755,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // type, but only if the source expression diverges. if target.is_never() && expr_diverges.always() { debug!("permit coercion to `!` because expr diverges"); - return Ok(target); + if self.can_eq(self.param_env, source, target).is_err() { + self.tcx.lint_node( + lint::builtin::COERCE_NEVER, + expr.id, + expr.span, + &format!("cannot coerce `{}` to !", source) + ); + return Ok(target); + } } let cause = self.cause(expr.span, ObligationCauseCode::ExprAssignable); diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 08cf6d3a59ec5..03145a1c68346 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -134,10 +134,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } - if let Some(suggestion) = self.check_ref(expr, - checked_ty, - expected) { - err.help(&suggestion); + if let Some((msg, suggestion)) = self.check_ref(expr, checked_ty, expected) { + err.span_suggestion(expr.span, msg, suggestion); } else { let mode = probe::Mode::MethodCall; let suggestions = self.probe_for_return_type(syntax_pos::DUMMY_SP, @@ -214,7 +212,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { expr: &hir::Expr, checked_ty: Ty<'tcx>, expected: Ty<'tcx>) - -> Option { + -> Option<(&'static str, String)> { match (&expected.sty, &checked_ty.sty) { (&ty::TyRef(_, exp), &ty::TyRef(_, check)) => match (&exp.ty.sty, &check.ty.sty) { (&ty::TyStr, &ty::TyArray(arr, _)) | @@ -222,7 +220,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if let hir::ExprLit(_) = expr.node { let sp = self.sess().codemap().call_span_if_macro(expr.span); if let Ok(src) = self.tcx.sess.codemap().span_to_snippet(sp) { - return Some(format!("try `{}`", &src[1..])); + return Some(("consider removing the leading `b`", + src[1..].to_string())); } } None @@ -232,7 +231,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if let hir::ExprLit(_) = expr.node { let sp = self.sess().codemap().call_span_if_macro(expr.span); if let Ok(src) = self.tcx.sess.codemap().span_to_snippet(sp) { - return Some(format!("try `b{}`", src)); + return Some(("consider adding a leading `b`", + format!("b{}", src))); } } None @@ -260,12 +260,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Use the callsite's span if this is a macro call. #41858 let sp = self.sess().codemap().call_span_if_macro(expr.span); if let Ok(src) = self.tcx.sess.codemap().span_to_snippet(sp) { - return Some(format!("try with `{}{}`", - match mutability.mutbl { - hir::Mutability::MutMutable => "&mut ", - hir::Mutability::MutImmutable => "&", - }, - &src)); + return Some(match mutability.mutbl { + hir::Mutability::MutMutable => { + ("consider using a mutable borrow", format!("&mut {}", src)) + } + hir::Mutability::MutImmutable => { + ("consider using a borrow", format!("&{}", src)) + } + }); } } None @@ -284,7 +286,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Maybe remove `&`? hir::ExprAddrOf(_, ref expr) => { if let Ok(code) = self.tcx.sess.codemap().span_to_snippet(expr.span) { - return Some(format!("try with `{}`", code)); + return Some(("consider removing the borrow", + code)); } } @@ -295,7 +298,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { expr.span) { let sp = self.sess().codemap().call_span_if_macro(expr.span); if let Ok(code) = self.tcx.sess.codemap().span_to_snippet(sp) { - return Some(format!("try with `*{}`", code)); + return Some(("consider dereferencing the borrow", + format!("*{}", code))); } } }, diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index 55d2df5f28bd9..eca3ebe9130fd 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -11,7 +11,6 @@ path = "lib.rs" doctest = false [dependencies] -env_logger = { version = "0.4", default-features = false } log = "0.3" pulldown-cmark = { version = "0.1.0", default-features = false } html-diff = "0.0.5" diff --git a/src/librustdoc/build.rs b/src/librustdoc/build.rs index 97c9ca1e2d27c..276825bd31a75 100644 --- a/src/librustdoc/build.rs +++ b/src/librustdoc/build.rs @@ -27,6 +27,6 @@ fn main() { .warnings(false) .include(src_dir) .warnings(false) - .compile("libhoedown.a"); + .compile("hoedown"); } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 820c3e856dbb1..85c1796ecef39 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -332,74 +332,10 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec) { let predicates = tcx.predicates_of(did); let trait_items = tcx.associated_items(did).filter_map(|item| { - match item.kind { - ty::AssociatedKind::Const => { - let default = if item.defaultness.has_value() { - Some(print_inlined_const(cx, item.def_id)) - } else { - None - }; - Some(clean::Item { - name: Some(item.name.clean(cx)), - inner: clean::AssociatedConstItem( - tcx.type_of(item.def_id).clean(cx), - default, - ), - source: tcx.def_span(item.def_id).clean(cx), - attrs: clean::Attributes::default(), - visibility: None, - stability: tcx.lookup_stability(item.def_id).clean(cx), - deprecation: tcx.lookup_deprecation(item.def_id).clean(cx), - def_id: item.def_id - }) - } - ty::AssociatedKind::Method => { - if item.vis != ty::Visibility::Public && associated_trait.is_none() { - return None - } - let mut cleaned = item.clean(cx); - cleaned.inner = match cleaned.inner.clone() { - clean::TyMethodItem(clean::TyMethod { - unsafety, decl, generics, abi - }) => { - let constness = if tcx.is_const_fn(item.def_id) { - hir::Constness::Const - } else { - hir::Constness::NotConst - }; - - clean::MethodItem(clean::Method { - unsafety, - constness, - decl, - generics, - abi, - }) - } - ref r => panic!("not a tymethod: {:?}", r), - }; - Some(cleaned) - } - ty::AssociatedKind::Type => { - let typedef = clean::Typedef { - type_: tcx.type_of(item.def_id).clean(cx), - generics: clean::Generics { - lifetimes: vec![], - type_params: vec![], - where_predicates: vec![] - } - }; - Some(clean::Item { - name: Some(item.name.clean(cx)), - inner: clean::TypedefItem(typedef, true), - source: tcx.def_span(item.def_id).clean(cx), - attrs: clean::Attributes::default(), - visibility: None, - stability: tcx.lookup_stability(item.def_id).clean(cx), - deprecation: tcx.lookup_deprecation(item.def_id).clean(cx), - def_id: item.def_id - }) - } + if associated_trait.is_some() || item.vis == ty::Visibility::Public { + Some(item.clean(cx)) + } else { + None } }).collect::>(); let polarity = tcx.impl_polarity(did); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 538737e7fe4d9..be7bd3d5510ef 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1595,7 +1595,12 @@ impl<'tcx> Clean for ty::AssociatedItem { let inner = match self.kind { ty::AssociatedKind::Const => { let ty = cx.tcx.type_of(self.def_id); - AssociatedConstItem(ty.clean(cx), None) + let default = if self.defaultness.has_value() { + Some(inline::print_inlined_const(cx, self.def_id)) + } else { + None + }; + AssociatedConstItem(ty.clean(cx), default) } ty::AssociatedKind::Method => { let generics = (cx.tcx.generics_of(self.def_id), @@ -1626,18 +1631,21 @@ impl<'tcx> Clean for ty::AssociatedItem { } let provided = match self.container { - ty::ImplContainer(_) => false, + ty::ImplContainer(_) => true, ty::TraitContainer(_) => self.defaultness.has_value() }; if provided { + let constness = if cx.tcx.is_const_fn(self.def_id) { + hir::Constness::Const + } else { + hir::Constness::NotConst + }; MethodItem(Method { unsafety: sig.unsafety(), generics, decl, abi: sig.abi(), - - // trait methods cannot (currently, at least) be const - constness: hir::Constness::NotConst, + constness, }) } else { TyMethodItem(TyMethod { @@ -1651,14 +1659,14 @@ impl<'tcx> Clean for ty::AssociatedItem { ty::AssociatedKind::Type => { let my_name = self.name.clean(cx); - let mut bounds = if let ty::TraitContainer(did) = self.container { + if let ty::TraitContainer(did) = self.container { // When loading a cross-crate associated type, the bounds for this type // are actually located on the trait/impl itself, so we need to load // all of the generics from there and then look for bounds that are // applied to this associated type in question. let predicates = cx.tcx.predicates_of(did); let generics = (cx.tcx.generics_of(did), &predicates).clean(cx); - generics.where_predicates.iter().filter_map(|pred| { + let mut bounds = generics.where_predicates.iter().filter_map(|pred| { let (name, self_type, trait_, bounds) = match *pred { WherePredicate::BoundPredicate { ty: QPath { ref name, ref self_type, ref trait_ }, @@ -1676,34 +1684,45 @@ impl<'tcx> Clean for ty::AssociatedItem { _ => return None, } Some(bounds) - }).flat_map(|i| i.iter().cloned()).collect::>() - } else { - vec![] - }; + }).flat_map(|i| i.iter().cloned()).collect::>(); + // Our Sized/?Sized bound didn't get handled when creating the generics + // because we didn't actually get our whole set of bounds until just now + // (some of them may have come from the trait). If we do have a sized + // bound, we remove it, and if we don't then we add the `?Sized` bound + // at the end. + match bounds.iter().position(|b| b.is_sized_bound(cx)) { + Some(i) => { bounds.remove(i); } + None => bounds.push(TyParamBound::maybe_sized(cx)), + } - // Our Sized/?Sized bound didn't get handled when creating the generics - // because we didn't actually get our whole set of bounds until just now - // (some of them may have come from the trait). If we do have a sized - // bound, we remove it, and if we don't then we add the `?Sized` bound - // at the end. - match bounds.iter().position(|b| b.is_sized_bound(cx)) { - Some(i) => { bounds.remove(i); } - None => bounds.push(TyParamBound::maybe_sized(cx)), - } + let ty = if self.defaultness.has_value() { + Some(cx.tcx.type_of(self.def_id)) + } else { + None + }; - let ty = if self.defaultness.has_value() { - Some(cx.tcx.type_of(self.def_id)) + AssociatedTypeItem(bounds, ty.clean(cx)) } else { - None - }; - - AssociatedTypeItem(bounds, ty.clean(cx)) + TypedefItem(Typedef { + type_: cx.tcx.type_of(self.def_id).clean(cx), + generics: Generics { + lifetimes: Vec::new(), + type_params: Vec::new(), + where_predicates: Vec::new(), + }, + }, true) + } } }; + let visibility = match self.container { + ty::ImplContainer(_) => self.vis.clean(cx), + ty::TraitContainer(_) => None, + }; + Item { name: Some(self.name.clean(cx)), - visibility: Some(Inherited), + visibility, stability: get_stability(cx, self.def_id), deprecation: get_deprecation(cx, self.def_id), def_id: self.def_id, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index cf557b1c661d6..b8a0b334b86af 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2621,7 +2621,8 @@ fn assoc_const(w: &mut fmt::Formatter, ty: &clean::Type, _default: Option<&String>, link: AssocItemLink) -> fmt::Result { - write!(w, "const {}: {}", + write!(w, "{}const {}: {}", + VisSpace(&it.visibility), naive_assoc_href(it, link), it.name.as_ref().unwrap(), ty)?; diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 951163d35fa0f..6f20104dda5d7 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -73,6 +73,13 @@ impl<'a> StringReader<'a> { fn mk_sp(&self, lo: BytePos, hi: BytePos) -> Span { unwrap_or!(self.override_span, Span::new(lo, hi, NO_EXPANSION)) } + fn mk_ident(&self, string: &str) -> Ident { + let mut ident = Ident::from_str(string); + if let Some(span) = self.override_span { + ident.ctxt = span.ctxt(); + } + ident + } fn next_token(&mut self) -> TokenAndSpan where Self: Sized { let res = self.try_next_token(); @@ -1103,7 +1110,7 @@ impl<'a> StringReader<'a> { token::Underscore } else { // FIXME: perform NFKC normalization here. (Issue #2253) - token::Ident(Ident::from_str(string)) + token::Ident(self.mk_ident(string)) } })); } @@ -1286,13 +1293,13 @@ impl<'a> StringReader<'a> { // expansion purposes. See #12512 for the gory details of why // this is necessary. let ident = self.with_str_from(start, |lifetime_name| { - Ident::from_str(&format!("'{}", lifetime_name)) + self.mk_ident(&format!("'{}", lifetime_name)) }); // Conjure up a "keyword checking ident" to make sure that // the lifetime name is not a keyword. let keyword_checking_ident = self.with_str_from(start, |lifetime_name| { - Ident::from_str(lifetime_name) + self.mk_ident(lifetime_name) }); let keyword_checking_token = &token::Ident(keyword_checking_ident); let last_bpos = self.pos; diff --git a/src/test/compile-fail-fulldeps/proc-macro/lints_in_proc_macros.rs b/src/test/compile-fail-fulldeps/proc-macro/lints_in_proc_macros.rs index b1fb7d42d8683..773b16b945f07 100644 --- a/src/test/compile-fail-fulldeps/proc-macro/lints_in_proc_macros.rs +++ b/src/test/compile-fail-fulldeps/proc-macro/lints_in_proc_macros.rs @@ -23,5 +23,5 @@ fn main() { bang_proc_macro2!(); //~^ ERROR cannot find value `foobar2` in this scope //~^^ did you mean `foobar`? - println!("{}", x); + println!("{}", x); //~ ERROR cannot find value `x` in this scope } diff --git a/src/test/compile-fail/coerce-to-bang-cast.rs b/src/test/compile-fail/coerce-to-bang-cast.rs index 0479f5cce6537..0d5bf6cd68cb8 100644 --- a/src/test/compile-fail/coerce-to-bang-cast.rs +++ b/src/test/compile-fail/coerce-to-bang-cast.rs @@ -12,8 +12,11 @@ fn foo(x: usize, y: !, z: usize) { } +#[deny(coerce_never)] fn cast_a() { let y = {return; 22} as !; + //~^ ERROR cannot coerce `i32` to ! + //~| hard error } fn cast_b() { diff --git a/src/test/compile-fail/coerce-to-bang.rs b/src/test/compile-fail/coerce-to-bang.rs index 870665bb49ee6..2cf568777d475 100644 --- a/src/test/compile-fail/coerce-to-bang.rs +++ b/src/test/compile-fail/coerce-to-bang.rs @@ -9,6 +9,7 @@ // except according to those terms. #![feature(never_type)] +#![deny(coerce_never)] fn foo(x: usize, y: !, z: usize) { } @@ -17,6 +18,8 @@ fn call_foo_a() { // the coercion to `!`, but within same expression. Not clear that // these are the rules we want. foo(return, 22, 44); + //~^ ERROR cannot coerce `{integer}` to ! + //~| hard error } fn call_foo_b() { @@ -36,6 +39,8 @@ fn call_foo_d() { let b = 22; let c = 44; foo(a, b, c); // ... and hence a reference to `a` is expected to diverge. + //~^ ERROR cannot coerce `{integer}` to ! + //~| hard error } fn call_foo_e() { @@ -75,6 +80,8 @@ fn tuple_a() { fn tuple_b() { // Divergence happens before coercion: OK let x: (usize, !, usize) = (return, 44, 66); + //~^ ERROR cannot coerce `{integer}` to ! + //~| hard error } fn tuple_c() { diff --git a/src/test/compile-fail/diverging-fn-tail-35849.rs b/src/test/compile-fail/diverging-fn-tail-35849.rs index 3a27c08413328..a91c000bbf712 100644 --- a/src/test/compile-fail/diverging-fn-tail-35849.rs +++ b/src/test/compile-fail/diverging-fn-tail-35849.rs @@ -8,9 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn _converge() -> ! { - 42 //~ ERROR mismatched types +#[deny(coerce_never)] +fn assert_sizeof() -> ! { + unsafe { + ::std::mem::transmute::(panic!()) + //~^ ERROR cannot coerce `[u8; 8]` to ! + //~| hard error + } } fn main() { } - diff --git a/src/test/compile-fail/issue-13058.rs b/src/test/compile-fail/issue-13058.rs index 590f8073a1a0d..b0716561546fc 100644 --- a/src/test/compile-fail/issue-13058.rs +++ b/src/test/compile-fail/issue-13058.rs @@ -35,5 +35,5 @@ fn check<'r, I: Iterator, T: Itble<'r, usize, I>>(cont: &T) -> bool fn main() { check((3, 5)); //~^ ERROR mismatched types -//~| HELP try with `&(3, 5)` +//~| HELP consider using a borrow } diff --git a/src/test/mir-opt/lower_128bit_debug_test.rs b/src/test/mir-opt/lower_128bit_debug_test.rs index 134a868f933fb..ccc6e75a1b42e 100644 --- a/src/test/mir-opt/lower_128bit_debug_test.rs +++ b/src/test/mir-opt/lower_128bit_debug_test.rs @@ -11,37 +11,6 @@ // compile-flags: -Z lower_128bit_ops -C debug_assertions=yes #![feature(i128_type)] -#![feature(lang_items)] - -#[lang="i128_div"] -fn i128_div(_x: i128, _y: i128) -> i128 { 3 } -#[lang="u128_div"] -fn u128_div(_x: u128, _y: u128) -> u128 { 4 } -#[lang="i128_rem"] -fn i128_rem(_x: i128, _y: i128) -> i128 { 5 } -#[lang="u128_rem"] -fn u128_rem(_x: u128, _y: u128) -> u128 { 6 } - -#[lang="i128_addo"] -fn i128_addo(_x: i128, _y: i128) -> (i128, bool) { (0, false) } -#[lang="u128_addo"] -fn u128_addo(_x: u128, _y: u128) -> (u128, bool) { (1, false) } -#[lang="i128_subo"] -fn i128_subo(_x: i128, _y: i128) -> (i128, bool) { (2, false) } -#[lang="u128_subo"] -fn u128_subo(_x: u128, _y: u128) -> (u128, bool) { (3, false) } -#[lang="i128_mulo"] -fn i128_mulo(_x: i128, _y: i128) -> (i128, bool) { (4, false) } -#[lang="u128_mulo"] -fn u128_mulo(_x: u128, _y: u128) -> (u128, bool) { (5, false) } -#[lang="i128_shlo"] -fn i128_shlo(_x: i128, _y: u128) -> (i128, bool) { (6, false) } -#[lang="u128_shlo"] -fn u128_shlo(_x: u128, _y: u128) -> (u128, bool) { (6, false) } -#[lang="i128_shro"] -fn i128_shro(_x: i128, _y: u128) -> (i128, bool) { (7, false) } -#[lang="u128_shro"] -fn u128_shro(_x: u128, _y: u128) -> (u128, bool) { (8, false) } fn test_signed(mut x: i128) -> i128 { x += 1; @@ -66,31 +35,31 @@ fn test_unsigned(mut x: u128) -> u128 { } fn main() { - test_signed(-200); - test_unsigned(200); + assert_eq!(test_signed(-222), -1); + assert_eq!(test_unsigned(200), 2); } // END RUST SOURCE // START rustc.test_signed.Lower128Bit.after.mir -// _2 = const i128_addo(_1, const 1i128) -> bb10; +// _2 = const compiler_builtins::int::addsub::rust_i128_addo(_1, const 1i128) -> bb10; // ... // _1 = move (_2.0: i128); -// _3 = const i128_subo(_1, const 2i128) -> bb11; +// _3 = const compiler_builtins::int::addsub::rust_i128_subo(_1, const 2i128) -> bb11; // ... // _1 = move (_3.0: i128); -// _4 = const i128_mulo(_1, const 3i128) -> bb12; +// _4 = const compiler_builtins::int::mul::rust_i128_mulo(_1, const 3i128) -> bb12; // ... // _1 = move (_4.0: i128); // ... -// _1 = const i128_div(_1, const 4i128) -> bb13; +// _1 = const compiler_builtins::int::sdiv::rust_i128_div(_1, const 4i128) -> bb13; // ... -// _1 = const i128_rem(_1, const 5i128) -> bb15; +// _1 = const compiler_builtins::int::sdiv::rust_i128_rem(_1, const 5i128) -> bb15; // ... // _1 = move (_13.0: i128); // ... // _17 = const 7i32 as u128 (Misc); -// _14 = const i128_shro(_1, move _17) -> bb16; +// _14 = const compiler_builtins::int::shift::rust_i128_shro(_1, move _17) -> bb16; // ... // _1 = move (_14.0: i128); // ... @@ -103,30 +72,30 @@ fn main() { // assert(!move (_13.1: bool), "attempt to shift left with overflow") -> bb8; // ... // _16 = const 6i32 as u128 (Misc); -// _13 = const i128_shlo(_1, move _16) -> bb14; +// _13 = const compiler_builtins::int::shift::rust_i128_shlo(_1, move _16) -> bb14; // ... // assert(!move (_14.1: bool), "attempt to shift right with overflow") -> bb9; // END rustc.test_signed.Lower128Bit.after.mir // START rustc.test_unsigned.Lower128Bit.after.mir -// _2 = const u128_addo(_1, const 1u128) -> bb8; +// _2 = const compiler_builtins::int::addsub::rust_u128_addo(_1, const 1u128) -> bb8; // ... // _1 = move (_2.0: u128); -// _3 = const u128_subo(_1, const 2u128) -> bb9; +// _3 = const compiler_builtins::int::addsub::rust_u128_subo(_1, const 2u128) -> bb9; // ... // _1 = move (_3.0: u128); -// _4 = const u128_mulo(_1, const 3u128) -> bb10; +// _4 = const compiler_builtins::int::mul::rust_u128_mulo(_1, const 3u128) -> bb10; // ... // _1 = move (_4.0: u128); // ... -// _1 = const u128_div(_1, const 4u128) -> bb11; +// _1 = const compiler_builtins::int::udiv::rust_u128_div(_1, const 4u128) -> bb11; // ... -// _1 = const u128_rem(_1, const 5u128) -> bb13; +// _1 = const compiler_builtins::int::udiv::rust_u128_rem(_1, const 5u128) -> bb13; // ... // _1 = move (_7.0: u128); // ... // _11 = const 7i32 as u128 (Misc); -// _8 = const u128_shro(_1, move _11) -> bb14; +// _8 = const compiler_builtins::int::shift::rust_u128_shro(_1, move _11) -> bb14; // ... // _1 = move (_8.0: u128); // ... @@ -139,7 +108,7 @@ fn main() { // assert(!move (_7.1: bool), "attempt to shift left with overflow") -> bb6; // ... // _10 = const 6i32 as u128 (Misc); -// _7 = const u128_shlo(_1, move _10) -> bb12; +// _7 = const compiler_builtins::int::shift::rust_u128_shlo(_1, move _10) -> bb12; // ... // assert(!move (_8.1: bool), "attempt to shift right with overflow") -> bb7; // END rustc.test_unsigned.Lower128Bit.after.mir diff --git a/src/test/mir-opt/lower_128bit_test.rs b/src/test/mir-opt/lower_128bit_test.rs index 5de75014f0efb..dc6beb436db21 100644 --- a/src/test/mir-opt/lower_128bit_test.rs +++ b/src/test/mir-opt/lower_128bit_test.rs @@ -11,36 +11,6 @@ // compile-flags: -Z lower_128bit_ops -C debug_assertions=no #![feature(i128_type)] -#![feature(lang_items)] - -#[lang="i128_add"] -fn i128_add(_x: i128, _y: i128) -> i128 { 0 } -#[lang="u128_add"] -fn u128_add(_x: u128, _y: u128) -> u128 { 0 } -#[lang="i128_sub"] -fn i128_sub(_x: i128, _y: i128) -> i128 { 1 } -#[lang="u128_sub"] -fn u128_sub(_x: u128, _y: u128) -> u128 { 1 } -#[lang="i128_mul"] -fn i128_mul(_x: i128, _y: i128) -> i128 { 2 } -#[lang="u128_mul"] -fn u128_mul(_x: u128, _y: u128) -> u128 { 2 } -#[lang="i128_div"] -fn i128_div(_x: i128, _y: i128) -> i128 { 3 } -#[lang="u128_div"] -fn u128_div(_x: u128, _y: u128) -> u128 { 4 } -#[lang="i128_rem"] -fn i128_rem(_x: i128, _y: i128) -> i128 { 5 } -#[lang="u128_rem"] -fn u128_rem(_x: u128, _y: u128) -> u128 { 6 } -#[lang="i128_shl"] -fn i128_shl(_x: i128, _y: u32) -> i128 { 7 } -#[lang="u128_shl"] -fn u128_shl(_x: u128, _y: u32) -> u128 { 7 } -#[lang="i128_shr"] -fn i128_shr(_x: i128, _y: u32) -> i128 { 8 } -#[lang="u128_shr"] -fn u128_shr(_x: u128, _y: u32) -> u128 { 9 } fn test_signed(mut x: i128) -> i128 { x += 1; @@ -65,44 +35,44 @@ fn test_unsigned(mut x: u128) -> u128 { } fn main() { - test_signed(-200); - test_unsigned(200); + assert_eq!(test_signed(-222), -1); + assert_eq!(test_unsigned(200), 2); } // END RUST SOURCE // START rustc.test_signed.Lower128Bit.after.mir -// _1 = const i128_add(_1, const 1i128) -> bb7; +// _1 = const compiler_builtins::int::addsub::rust_i128_add(_1, const 1i128) -> bb7; // ... -// _1 = const i128_div(_1, const 4i128) -> bb8; +// _1 = const compiler_builtins::int::sdiv::rust_i128_div(_1, const 4i128) -> bb8; // ... -// _1 = const i128_rem(_1, const 5i128) -> bb11; +// _1 = const compiler_builtins::int::sdiv::rust_i128_rem(_1, const 5i128) -> bb11; // ... -// _1 = const i128_mul(_1, const 3i128) -> bb5; +// _1 = const compiler_builtins::int::mul::rust_i128_mul(_1, const 3i128) -> bb5; // ... -// _1 = const i128_sub(_1, const 2i128) -> bb6; +// _1 = const compiler_builtins::int::addsub::rust_i128_sub(_1, const 2i128) -> bb6; // ... // _11 = const 7i32 as u32 (Misc); -// _1 = const i128_shr(_1, move _11) -> bb9; +// _1 = const compiler_builtins::int::shift::rust_i128_shr(_1, move _11) -> bb9; // ... // _12 = const 6i32 as u32 (Misc); -// _1 = const i128_shl(_1, move _12) -> bb10; +// _1 = const compiler_builtins::int::shift::rust_i128_shl(_1, move _12) -> bb10; // END rustc.test_signed.Lower128Bit.after.mir // START rustc.test_unsigned.Lower128Bit.after.mir -// _1 = const u128_add(_1, const 1u128) -> bb5; +// _1 = const compiler_builtins::int::addsub::rust_u128_add(_1, const 1u128) -> bb5; // ... -// _1 = const u128_div(_1, const 4u128) -> bb6; +// _1 = const compiler_builtins::int::udiv::rust_u128_div(_1, const 4u128) -> bb6; // ... -// _1 = const u128_rem(_1, const 5u128) -> bb9; +// _1 = const compiler_builtins::int::udiv::rust_u128_rem(_1, const 5u128) -> bb9; // ... -// _1 = const u128_mul(_1, const 3u128) -> bb3; +// _1 = const compiler_builtins::int::mul::rust_u128_mul(_1, const 3u128) -> bb3; // ... -// _1 = const u128_sub(_1, const 2u128) -> bb4; +// _1 = const compiler_builtins::int::addsub::rust_u128_sub(_1, const 2u128) -> bb4; // ... // _5 = const 7i32 as u32 (Misc); -// _1 = const u128_shr(_1, move _5) -> bb7; +// _1 = const compiler_builtins::int::shift::rust_u128_shr(_1, move _5) -> bb7; // ... // _6 = const 6i32 as u32 (Misc); -// _1 = const u128_shl(_1, move _6) -> bb8; +// _1 = const compiler_builtins::int::shift::rust_u128_shl(_1, move _6) -> bb8; // END rustc.test_unsigned.Lower128Bit.after.mir diff --git a/src/test/run-pass-fulldeps/proc-macro/auxiliary/issue-42708.rs b/src/test/run-pass-fulldeps/proc-macro/auxiliary/issue-42708.rs new file mode 100644 index 0000000000000..58b4b2a5293b3 --- /dev/null +++ b/src/test/run-pass-fulldeps/proc-macro/auxiliary/issue-42708.rs @@ -0,0 +1,28 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// no-prefer-dynamic + +#![crate_type = "proc-macro"] +#![feature(proc_macro)] + +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro_derive(Test)] +pub fn derive(_input: TokenStream) -> TokenStream { + "fn f(s: S) { s.x }".parse().unwrap() +} + +#[proc_macro_attribute] +pub fn attr_test(_attr: TokenStream, input: TokenStream) -> TokenStream { + input +} diff --git a/src/test/run-pass-fulldeps/proc-macro/issue-42708.rs b/src/test/run-pass-fulldeps/proc-macro/issue-42708.rs new file mode 100644 index 0000000000000..e53e94ae475b2 --- /dev/null +++ b/src/test/run-pass-fulldeps/proc-macro/issue-42708.rs @@ -0,0 +1,36 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue-42708.rs +// ignore-stage1 + +#![feature(decl_macro, proc_macro)] +#![allow(unused)] + +extern crate issue_42708; + +macro m() { + #[derive(issue_42708::Test)] + struct S { x: () } + + #[issue_42708::attr_test] + struct S2 { x: () } + + #[derive(Clone)] + struct S3 { x: () } + + fn g(s: S, s2: S2, s3: S3) { + (s.x, s2.x, s3.x); + } +} + +m!(); + +fn main() {} diff --git a/src/test/run-pass/diverging-fn-tail-35849.rs b/src/test/run-pass/diverging-fn-tail-35849.rs index 6c05a02e7183c..dfd99bcc9fb47 100644 --- a/src/test/run-pass/diverging-fn-tail-35849.rs +++ b/src/test/run-pass/diverging-fn-tail-35849.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[allow(coerce_never)] fn assert_sizeof() -> ! { unsafe { ::std::mem::transmute::(panic!()) @@ -15,4 +16,3 @@ fn assert_sizeof() -> ! { } fn main() { } - diff --git a/src/test/rustdoc/inline_cross/assoc-items.rs b/src/test/rustdoc/inline_cross/assoc-items.rs new file mode 100644 index 0000000000000..95d936883ffa9 --- /dev/null +++ b/src/test/rustdoc/inline_cross/assoc-items.rs @@ -0,0 +1,57 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:assoc-items.rs +// build-aux-docs +// ignore-cross-compile + +#![crate_name = "foo"] + +extern crate assoc_items; + +// @has foo/struct.MyStruct.html +// @!has - 'PrivateConst' +// @has - '//*[@id="associatedconstant.PublicConst"]' 'pub const PublicConst: u8' +// @has - '//*[@class="docblock"]' 'PublicConst: u8 = 123' +// @has - '//*[@class="docblock"]' 'docs for PublicConst' +// @!has - 'private_method' +// @has - '//*[@id="method.public_method"]' 'pub fn public_method()' +// @has - '//*[@class="docblock"]' 'docs for public_method' +// @has - '//*[@id="associatedconstant.ConstNoDefault"]' 'const ConstNoDefault: i16' +// @has - '//*[@class="docblock"]' 'ConstNoDefault: i16 = -123' +// @has - '//*[@class="docblock"]' 'dox for ConstNoDefault' +// @has - '//*[@id="associatedconstant.ConstWithDefault"]' 'const ConstWithDefault: u16' +// @has - '//*[@class="docblock"]' 'ConstWithDefault: u16 = 12345' +// @has - '//*[@class="docblock"]' 'docs for ConstWithDefault' +// @has - '//*[@id="associatedtype.TypeNoDefault"]' 'type TypeNoDefault = i32' +// @has - '//*[@class="docblock"]' 'dox for TypeNoDefault' +// @has - '//*[@id="associatedtype.TypeWithDefault"]' 'type TypeWithDefault = u32' +// @has - '//*[@class="docblock"]' 'docs for TypeWithDefault' +// @has - '//*[@id="method.method_no_default"]' 'fn method_no_default()' +// @has - '//*[@class="docblock"]' 'dox for method_no_default' +// @has - '//*[@id="method.method_with_default"]' 'fn method_with_default()' +// @has - '//*[@class="docblock"]' 'docs for method_with_default' +pub use assoc_items::MyStruct; + +// @has foo/trait.MyTrait.html +// @has - '//*[@id="associatedconstant.ConstNoDefault"]' 'const ConstNoDefault: i16' +// @has - '//*[@class="docblock"]' 'docs for ConstNoDefault' +// @has - '//*[@id="associatedconstant.ConstWithDefault"]' 'const ConstWithDefault: u16' +// @has - '//*[@class="docblock"]' 'ConstWithDefault: u16 = 12345' +// @has - '//*[@class="docblock"]' 'docs for ConstWithDefault' +// @has - '//*[@id="associatedtype.TypeNoDefault"]' 'type TypeNoDefault' +// @has - '//*[@class="docblock"]' 'docs for TypeNoDefault' +// @has - '//*[@id="associatedtype.TypeWithDefault"]' 'type TypeWithDefault = u32' +// @has - '//*[@class="docblock"]' 'docs for TypeWithDefault' +// @has - '//*[@id="tymethod.method_no_default"]' 'fn method_no_default()' +// @has - '//*[@class="docblock"]' 'docs for method_no_default' +// @has - '//*[@id="method.method_with_default"]' 'fn method_with_default()' +// @has - '//*[@class="docblock"]' 'docs for method_with_default' +pub use assoc_items::MyTrait; diff --git a/src/test/rustdoc/inline_cross/auxiliary/assoc-items.rs b/src/test/rustdoc/inline_cross/auxiliary/assoc-items.rs new file mode 100644 index 0000000000000..e955526900e99 --- /dev/null +++ b/src/test/rustdoc/inline_cross/auxiliary/assoc-items.rs @@ -0,0 +1,48 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(associated_type_defaults)] + +pub struct MyStruct; + +impl MyStruct { + /// docs for PrivateConst + const PrivateConst: i8 = -123; + /// docs for PublicConst + pub const PublicConst: u8 = 123; + /// docs for private_method + fn private_method() {} + /// docs for public_method + pub fn public_method() {} +} + +pub trait MyTrait { + /// docs for ConstNoDefault + const ConstNoDefault: i16; + /// docs for ConstWithDefault + const ConstWithDefault: u16 = 12345; + /// docs for TypeNoDefault + type TypeNoDefault; + /// docs for TypeWithDefault + type TypeWithDefault = u32; + /// docs for method_no_default + fn method_no_default(); + /// docs for method_with_default + fn method_with_default() {} +} + +impl MyTrait for MyStruct { + /// dox for ConstNoDefault + const ConstNoDefault: i16 = -12345; + /// dox for TypeNoDefault + type TypeNoDefault = i32; + /// dox for method_no_default + fn method_no_default() {} +} diff --git a/src/test/ui/deref-suggestion.stderr b/src/test/ui/deref-suggestion.stderr index 6c418cf4bfbed..98ec3d9693fb8 100644 --- a/src/test/ui/deref-suggestion.stderr +++ b/src/test/ui/deref-suggestion.stderr @@ -17,31 +17,37 @@ error[E0308]: mismatched types --> $DIR/deref-suggestion.rs:23:10 | 23 | foo3(u); //~ ERROR mismatched types - | ^ expected u32, found &u32 + | ^ + | | + | expected u32, found &u32 + | help: consider dereferencing the borrow: `*u` | = note: expected type `u32` found type `&u32` - = help: try with `*u` error[E0308]: mismatched types --> $DIR/deref-suggestion.rs:30:9 | 30 | foo(&"aaa".to_owned()); //~ ERROR mismatched types - | ^^^^^^^^^^^^^^^^^ expected struct `std::string::String`, found reference + | ^^^^^^^^^^^^^^^^^ + | | + | expected struct `std::string::String`, found reference + | help: consider removing the borrow: `"aaa".to_owned()` | = note: expected type `std::string::String` found type `&std::string::String` - = help: try with `"aaa".to_owned()` error[E0308]: mismatched types --> $DIR/deref-suggestion.rs:31:9 | 31 | foo(&mut "aaa".to_owned()); //~ ERROR mismatched types - | ^^^^^^^^^^^^^^^^^^^^^ expected struct `std::string::String`, found mutable reference + | ^^^^^^^^^^^^^^^^^^^^^ + | | + | expected struct `std::string::String`, found mutable reference + | help: consider removing the borrow: `"aaa".to_owned()` | = note: expected type `std::string::String` found type `&mut std::string::String` - = help: try with `"aaa".to_owned()` error[E0308]: mismatched types --> $DIR/deref-suggestion.rs:12:20 diff --git a/src/test/ui/reachable/expr_unary.rs b/src/test/ui/reachable/expr_unary.rs index 6cff3ff964439..ad12cb876fe9b 100644 --- a/src/test/ui/reachable/expr_unary.rs +++ b/src/test/ui/reachable/expr_unary.rs @@ -12,11 +12,14 @@ #![allow(unused_assignments)] #![allow(dead_code)] #![deny(unreachable_code)] +#![deny(coerce_never)] #![feature(never_type)] fn foo() { let x: ! = ! { return; 22 }; //~ ERROR unreachable - //~^ ERROR cannot apply unary operator `!` to type `!` + //~^ ERROR cannot coerce + //~| hard error + //~| ERROR cannot apply unary operator `!` to type `!` } fn main() { } diff --git a/src/test/ui/reachable/expr_unary.stderr b/src/test/ui/reachable/expr_unary.stderr index f14824728a70c..710cf79cbe9a7 100644 --- a/src/test/ui/reachable/expr_unary.stderr +++ b/src/test/ui/reachable/expr_unary.stderr @@ -1,7 +1,7 @@ error: unreachable expression - --> $DIR/expr_unary.rs:18:28 + --> $DIR/expr_unary.rs:19:28 | -18 | let x: ! = ! { return; 22 }; //~ ERROR unreachable +19 | let x: ! = ! { return; 22 }; //~ ERROR unreachable | ^^ | note: lint level defined here @@ -10,11 +10,25 @@ note: lint level defined here 14 | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ +error: cannot coerce `{integer}` to ! + --> $DIR/expr_unary.rs:19:28 + | +19 | let x: ! = ! { return; 22 }; //~ ERROR unreachable + | ^^ + | +note: lint level defined here + --> $DIR/expr_unary.rs:15:9 + | +15 | #![deny(coerce_never)] + | ^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #46325 + error[E0600]: cannot apply unary operator `!` to type `!` - --> $DIR/expr_unary.rs:18:16 + --> $DIR/expr_unary.rs:19:16 | -18 | let x: ! = ! { return; 22 }; //~ ERROR unreachable +19 | let x: ! = ! { return; 22 }; //~ ERROR unreachable | ^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors diff --git a/src/test/ui/span/coerce-suggestions.rs b/src/test/ui/span/coerce-suggestions.rs index a1a250b0e9ad2..ba6807d93959c 100644 --- a/src/test/ui/span/coerce-suggestions.rs +++ b/src/test/ui/span/coerce-suggestions.rs @@ -23,7 +23,7 @@ fn main() { //~^ ERROR E0308 //~| NOTE expected &str, found struct `std::string::String` //~| NOTE expected type `&str` - //~| HELP try with `&String::new()` + //~| HELP consider using a borrow let y = String::new(); test(&y); //~^ ERROR E0308 diff --git a/src/test/ui/span/coerce-suggestions.stderr b/src/test/ui/span/coerce-suggestions.stderr index 98ea34fd992c8..59cae4913444f 100644 --- a/src/test/ui/span/coerce-suggestions.stderr +++ b/src/test/ui/span/coerce-suggestions.stderr @@ -14,11 +14,13 @@ error[E0308]: mismatched types --> $DIR/coerce-suggestions.rs:22:19 | 22 | let x: &str = String::new(); - | ^^^^^^^^^^^^^ expected &str, found struct `std::string::String` + | ^^^^^^^^^^^^^ + | | + | expected &str, found struct `std::string::String` + | help: consider using a borrow: `&String::new()` | = note: expected type `&str` found type `std::string::String` - = help: try with `&String::new()` error[E0308]: mismatched types --> $DIR/coerce-suggestions.rs:28:10 @@ -48,11 +50,13 @@ error[E0308]: mismatched types --> $DIR/coerce-suggestions.rs:42:9 | 42 | s = format!("foo"); - | ^^^^^^^^^^^^^^ expected mutable reference, found struct `std::string::String` + | ^^^^^^^^^^^^^^ + | | + | expected mutable reference, found struct `std::string::String` + | help: consider using a mutable borrow: `&mut format!("foo")` | = note: expected type `&mut std::string::String` found type `std::string::String` - = help: try with `&mut format!("foo")` = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to 6 previous errors diff --git a/src/test/ui/str-lit-type-mismatch.stderr b/src/test/ui/str-lit-type-mismatch.stderr index bf7646d81eb1d..b232bf74666b1 100644 --- a/src/test/ui/str-lit-type-mismatch.stderr +++ b/src/test/ui/str-lit-type-mismatch.stderr @@ -2,31 +2,37 @@ error[E0308]: mismatched types --> $DIR/str-lit-type-mismatch.rs:13:20 | 13 | let x: &[u8] = "foo"; //~ ERROR mismatched types - | ^^^^^ expected slice, found str + | ^^^^^ + | | + | expected slice, found str + | help: consider adding a leading `b`: `b"foo"` | = note: expected type `&[u8]` found type `&'static str` - = help: try `b"foo"` error[E0308]: mismatched types --> $DIR/str-lit-type-mismatch.rs:14:23 | 14 | let y: &[u8; 4] = "baaa"; //~ ERROR mismatched types - | ^^^^^^ expected array of 4 elements, found str + | ^^^^^^ + | | + | expected array of 4 elements, found str + | help: consider adding a leading `b`: `b"baaa"` | = note: expected type `&[u8; 4]` found type `&'static str` - = help: try `b"baaa"` error[E0308]: mismatched types --> $DIR/str-lit-type-mismatch.rs:15:19 | 15 | let z: &str = b"foo"; //~ ERROR mismatched types - | ^^^^^^ expected str, found array of 3 elements + | ^^^^^^ + | | + | expected str, found array of 3 elements + | help: consider removing the leading `b`: `"foo"` | = note: expected type `&str` found type `&'static [u8; 3]` - = help: try `"foo"` error: aborting due to 3 previous errors