From 50b4eefcf5ce5e0a7808c6fc3f7effcea2e628c3 Mon Sep 17 00:00:00 2001 From: Georg Semmler <georg_semmler_05@web.de> Date: Wed, 28 Nov 2018 17:10:21 +0100 Subject: [PATCH 01/28] rustdoc: Fix inlining reexported custom derives --- src/librustdoc/clean/inline.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 49cecd5b04bbc..464b6ea4fbe41 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -106,13 +106,23 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa clean::ConstantItem(build_const(cx, did)) } // FIXME: proc-macros don't propagate attributes or spans across crates, so they look empty + Def::Macro(did, MacroKind::Derive) | Def::Macro(did, MacroKind::Bang) => { let mac = build_macro(cx, did, name); - if let clean::MacroItem(..) = mac { - record_extern_fqn(cx, did, clean::TypeKind::Macro); - mac - } else { - return None; + debug!("try_inline: {:?}", mac); + + match build_macro(cx, did, name) { + clean::MacroItem(..) => { + record_extern_fqn(cx, did, clean::TypeKind::Macro); + mac + } + clean::ProcMacroItem(..) => { + record_extern_fqn(cx, did, clean::TypeKind::Derive); + mac + } + _ => { + return None; + } } } _ => return None, From 230f5d5676ffad99e64f73128dc27f629aa8e921 Mon Sep 17 00:00:00 2001 From: Georg Semmler <georg_semmler_05@web.de> Date: Wed, 28 Nov 2018 17:11:06 +0100 Subject: [PATCH 02/28] rustdoc: Fix inlining reexporting bang-macros --- src/librustdoc/visit_ast.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 5d221d3006f3e..b44b1d9e0ba19 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -376,6 +376,10 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> { }); true } + Node::MacroDef(def) if !glob => { + om.macros.push(self.visit_local_macro(def)); + true + } _ => false, }; self.view_item_stack.remove(&def_node_id); From dd717deccb3a4698beac8edb0a75e2efb6f08ebb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez <guillaume1.gomez@gmail.com> Date: Mon, 1 Oct 2018 00:47:54 +0200 Subject: [PATCH 03/28] Add crate filtering --- src/librustdoc/html/layout.rs | 15 ++-- src/librustdoc/html/render.rs | 2 +- src/librustdoc/html/static/main.js | 99 +++++++++++++++++---- src/librustdoc/html/static/rustdoc.css | 24 ++++- src/librustdoc/html/static/themes/dark.css | 8 +- src/librustdoc/html/static/themes/light.css | 9 +- 6 files changed, 131 insertions(+), 26 deletions(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 6868c7707adc8..d585b737517b3 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -81,11 +81,16 @@ pub fn render<T: fmt::Display, S: fmt::Display>( <nav class=\"sub\">\ <form class=\"search-form js-only\">\ <div class=\"search-container\">\ - <input class=\"search-input\" name=\"search\" \ - autocomplete=\"off\" \ - spellcheck=\"false\" \ - placeholder=\"Click or press ‘S’ to search, ‘?’ for more options…\" \ - type=\"search\">\ + <div>\ + <select id=\"crate-search\">\ + <option value=\"All crates\">All crates</option>\ + </select>\ + <input class=\"search-input\" name=\"search\" \ + autocomplete=\"off\" \ + spellcheck=\"false\" \ + placeholder=\"Click or press ‘S’ to search, ‘?’ for more options…\" \ + type=\"search\">\ + </div>\ <a id=\"settings-menu\" href=\"{root_path}settings.html\">\ <img src=\"{root_path}wheel{suffix}.svg\" width=\"18\" alt=\"Change settings\">\ </a>\ diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index f560350d5105d..48da90de02a8a 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -983,7 +983,7 @@ themePicker.onblur = handleThemeButtonsBlur; &[(minifier::js::Keyword::Null, "N")]), &dst); } - try_err!(writeln!(&mut w, "initSearch(searchIndex);"), &dst); + try_err!(writeln!(&mut w, "initSearch(searchIndex);addSearchOptions(searchIndex);"), &dst); if options.enable_index_page { if let Some(index_page) = options.index_page.clone() { diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 4425712eed7a1..66e10b24440be 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -254,12 +254,14 @@ // // So I guess you could say things are getting pretty interoperable. function getVirtualKey(ev) { - if ("key" in ev && typeof ev.key != "undefined") + if ("key" in ev && typeof ev.key != "undefined") { return ev.key; + } var c = ev.charCode || ev.keyCode; - if (c == 27) + if (c == 27) { return "Escape"; + } return String.fromCharCode(c); } @@ -467,12 +469,13 @@ /** * Executes the query and builds an index of results - * @param {[Object]} query [The user query] - * @param {[type]} searchWords [The list of search words to query - * against] - * @return {[type]} [A search index of results] + * @param {[Object]} query [The user query] + * @param {[type]} searchWords [The list of search words to query + * against] + * @param {[type]} filterCrates [Crate to search in if defined] + * @return {[type]} [A search index of results] */ - function execQuery(query, searchWords) { + function execQuery(query, searchWords, filterCrates) { function itemTypeFromName(typename) { for (var i = 0; i < itemTypes.length; ++i) { if (itemTypes[i] === typename) { @@ -848,6 +851,9 @@ { val = extractGenerics(val.substr(1, val.length - 2)); for (var i = 0; i < nSearchWords; ++i) { + if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) { + continue; + } var in_args = findArg(searchIndex[i], val, true); var returned = checkReturned(searchIndex[i], val, true); var ty = searchIndex[i]; @@ -902,6 +908,9 @@ var output = extractGenerics(parts[1]); for (var i = 0; i < nSearchWords; ++i) { + if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) { + continue; + } var type = searchIndex[i].type; var ty = searchIndex[i]; if (!type) { @@ -973,11 +982,11 @@ var contains = paths.slice(0, paths.length > 1 ? paths.length - 1 : 1); for (j = 0; j < nSearchWords; ++j) { - var lev_distance; var ty = searchIndex[j]; - if (!ty) { + if (!ty || (filterCrates !== undefined && ty.crate !== filterCrates)) { continue; } + var lev_distance; var lev_add = 0; if (paths.length > 1) { var lev = checkPath(contains, paths[paths.length - 1], ty); @@ -1353,7 +1362,7 @@ return '<div>' + text + ' <div class="count">(' + nbElems + ')</div></div>'; } - function showResults(results) { + function showResults(results, filterCrates) { if (results['others'].length === 1 && getCurrentValue('rustdoc-go-to-only-result') === "true") { var elem = document.createElement('a'); @@ -1371,8 +1380,13 @@ var ret_in_args = addTab(results['in_args'], query, false); var ret_returned = addTab(results['returned'], query, false); + var filter = ""; + if (filterCrates !== undefined) { + filter = " (in <b>" + filterCrates + "</b> crate)"; + } + var output = '<h1>Results for ' + escape(query.query) + - (query.type ? ' (type: ' + escape(query.type) + ')' : '') + '</h1>' + + (query.type ? ' (type: ' + escape(query.type) + ')' : '') + filter + '</h1>' + '<div id="titles">' + makeTabHeader(0, "In Names", ret_others[1]) + makeTabHeader(1, "In Parameters", ret_in_args[1]) + @@ -1401,7 +1415,7 @@ printTab(currentTab); } - function execSearch(query, searchWords) { + function execSearch(query, searchWords, filterCrates) { var queries = query.raw.split(","); var results = { 'in_args': [], @@ -1412,7 +1426,7 @@ for (var i = 0; i < queries.length; ++i) { var query = queries[i].trim(); if (query.length !== 0) { - var tmp = execQuery(getQuery(query), searchWords); + var tmp = execQuery(getQuery(query), searchWords, filterCrates); results['in_args'].push(tmp['in_args']); results['returned'].push(tmp['returned']); @@ -1474,7 +1488,16 @@ } } - function search(e) { + function getFilterCrates() { + var elem = document.getElementById("crate-search"); + + if (elem && elem.value !== "All crates" && rawSearchIndex.hasOwnProperty(elem.value)) { + return elem.value; + } + return undefined; + } + + function search(e, forced) { var params = getQueryStringParams(); var query = getQuery(search_input.value.trim()); @@ -1482,7 +1505,10 @@ e.preventDefault(); } - if (query.query.length === 0 || query.id === currentResults) { + if (query.query.length === 0) { + return; + } + if (forced !== true && query.id === currentResults) { if (query.query.length > 0) { putBackSearch(search_input); } @@ -1502,7 +1528,8 @@ } } - showResults(execSearch(query, index)); + var filterCrates = getFilterCrates(); + showResults(execSearch(query, index, filterCrates), filterCrates); } function buildIndex(rawSearchIndex) { @@ -1602,6 +1629,13 @@ }; search_input.onpaste = search_input.onchange; + var selectCrate = document.getElementById('crate-search'); + if (selectCrate) { + selectCrate.onchange = function() { + search(undefined, true); + }; + } + // Push and pop states are used to add search results to the browser // history. if (browserSupportsHistoryApi()) { @@ -2350,6 +2384,39 @@ if (window.location.hash && window.location.hash.length > 0) { expandSection(window.location.hash.replace(/^#/, '')); } + + function addSearchOptions(crates) { + var elem = document.getElementById('crate-search'); + + if (!elem) { + return; + } + var crates_text = []; + for (var crate in crates) { + if (crates.hasOwnProperty(crate)) { + crates_text.push(crate); + } + } + crates_text.sort(function(a, b) { + var lower_a = a.toLowerCase(); + var lower_b = b.toLowerCase(); + + if (lower_a < lower_b) { + return -1; + } else if (lower_a > lower_b) { + return 1; + } + return 0; + }); + for (var i = 0; i < crates_text.length; ++i) { + var option = document.createElement("option"); + option.value = crates_text[i]; + option.innerText = crates_text[i]; + elem.appendChild(option); + } + } + + window.addSearchOptions = addSearchOptions; }()); // Sets the focus on the search bar at the top of the page diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 1ae3b0b88c6dd..cbf55c12244d1 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -614,13 +614,32 @@ a { .search-container { position: relative; } +.search-container > div { + display: inline-flex; + width: calc(100% - 34px); +} +#crate-search { + margin-top: 5px; + padding: 6px; + padding-right: 12px; + border: 0; + border-right: 0; + border-radius: 4px 0 0 4px; + outline: none; + cursor: pointer; + border-right: 1px solid; + -moz-appearance: none; + -webkit-appearance: none; + /* Removes default arrow from firefox */ + text-indent: 0.01px; + text-overflow: ""; +} .search-container > .top-button { position: absolute; right: 0; top: 10px; } .search-input { - width: calc(100% - 34px); /* Override Normalize.css: we have margins and do not want to overflow - the `moz` attribute is necessary until Firefox 29, too early to drop at this point */ @@ -628,13 +647,14 @@ a { box-sizing: border-box !important; outline: none; border: none; - border-radius: 1px; + border-radius: 0 1px 1px 0; margin-top: 5px; padding: 10px 16px; font-size: 17px; transition: border-color 300ms ease; transition: border-radius 300ms ease-in-out; transition: box-shadow 300ms ease-in-out; + width: 100%; } .search-input:focus { diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css index 4a8950b236c62..8fdf39ccaa1a6 100644 --- a/src/librustdoc/html/static/themes/dark.css +++ b/src/librustdoc/html/static/themes/dark.css @@ -182,9 +182,15 @@ a.test-arrow { color: #999; } +#crate-search { + color: #111; + background-color: #f0f0f0; + border-color: #000; +} + .search-input { color: #111; - box-shadow: 0 0 0 1px #000, 0 0 0 2px transparent; + box-shadow: 1px 0 0 1px #000, 0 0 0 2px transparent; background-color: #f0f0f0; } diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css index b3b0b6b2ea9e8..425aa601e9b3e 100644 --- a/src/librustdoc/html/static/themes/light.css +++ b/src/librustdoc/html/static/themes/light.css @@ -182,9 +182,16 @@ a.test-arrow { color: #999; } +#crate-search { + color: #555; + background-color: white; + border-color: #e0e0e0; + box-shadow: 0px 0 0 1px #e0e0e0, 0 0 0 2px transparent; +} + .search-input { color: #555; - box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent; + box-shadow: 1px 0 0 1px #e0e0e0, 0 0 0 2px transparent; background-color: white; } From 8062c7ae4b6201b3728baae37fb04215dcc5fcd4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez <guillaume1.gomez@gmail.com> Date: Mon, 1 Oct 2018 00:55:00 +0200 Subject: [PATCH 04/28] Add test for crate filtering --- src/test/rustdoc-js/filter-crate.js | 20 ++++++++++++++++++++ src/tools/rustdoc-js/tester.js | 1 + 2 files changed, 21 insertions(+) create mode 100644 src/test/rustdoc-js/filter-crate.js diff --git a/src/test/rustdoc-js/filter-crate.js b/src/test/rustdoc-js/filter-crate.js new file mode 100644 index 0000000000000..69c959a6ef21c --- /dev/null +++ b/src/test/rustdoc-js/filter-crate.js @@ -0,0 +1,20 @@ +// Copyright 2018 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// should-fail + +const QUERY = 'string'; +const FILTER_CRATE = 'core'; + +const EXPECTED = { + 'others': [ + { 'path': 'std::collections', 'name': 'VecDeque' }, + ], +}; diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index c8ce4cf8bb5be..f7c30df9f3ebb 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -259,6 +259,7 @@ function main(argv) { 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;'); const expected = loadedFile.EXPECTED; const query = loadedFile.QUERY; + const filter_crate = loadedFile.FILTER_CRATE; const ignore_order = loadedFile.ignore_order; const exact_check = loadedFile.exact_check; const should_fail = loadedFile.should_fail; From afe41078add129c821a16f5f7fb6e667c34c153d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez <guillaume1.gomez@gmail.com> Date: Thu, 29 Nov 2018 01:29:49 +0100 Subject: [PATCH 05/28] Add arrow to the crate select box --- src/librustdoc/html/layout.rs | 3 +++ src/librustdoc/html/render.rs | 2 ++ src/librustdoc/html/static/down-arrow.svg | 1 + src/librustdoc/html/static/rustdoc.css | 6 +++++- src/librustdoc/html/static_files.rs | 3 +++ 5 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/librustdoc/html/static/down-arrow.svg diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index d585b737517b3..3a2a6f4c6b9fd 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -57,6 +57,9 @@ pub fn render<T: fmt::Display, S: fmt::Display>( {css_extension}\ {favicon}\ {in_header}\ + <style type=\"text/css\">\ + #crate-search{{background-image:url(\"{root_path}down-arrow{suffix}.svg\");}}\ + </style>\ </head>\ <body class=\"rustdoc {css_class}\">\ <!--[if lte IE 8]>\ diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 48da90de02a8a..1b99641c3e773 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -793,6 +793,8 @@ fn write_shared( static_files::BRUSH_SVG)?; write(cx.dst.join(&format!("wheel{}.svg", cx.shared.resource_suffix)), static_files::WHEEL_SVG)?; + write(cx.dst.join(&format!("down-arrow{}.svg", cx.shared.resource_suffix)), + static_files::DOWN_ARROW_SVG)?; write_minify(cx.dst.join(&format!("light{}.css", cx.shared.resource_suffix)), static_files::themes::LIGHT, options.enable_minification)?; diff --git a/src/librustdoc/html/static/down-arrow.svg b/src/librustdoc/html/static/down-arrow.svg new file mode 100644 index 0000000000000..a2d9a37dde091 --- /dev/null +++ b/src/librustdoc/html/static/down-arrow.svg @@ -0,0 +1 @@ +<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg height="128px" id="Layer_1" style="enable-background:new 0 0 128 128;" version="1.1" viewBox="0 0 128 128" width="128px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g><line style="fill:none;stroke:#2F3435;stroke-width:12;stroke-linecap:square;stroke-miterlimit:10;" x1="111" x2="64" y1="40.5" y2="87.499"/><line style="fill:none;stroke:#2F3435;stroke-width:12;stroke-linecap:square;stroke-miterlimit:10;" x1="64" x2="17" y1="87.499" y2="40.5"/></g></svg> \ No newline at end of file diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index cbf55c12244d1..ff1ba9f541b02 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -621,7 +621,7 @@ a { #crate-search { margin-top: 5px; padding: 6px; - padding-right: 12px; + padding-right: 19px; border: 0; border-right: 0; border-radius: 4px 0 0 4px; @@ -633,6 +633,10 @@ a { /* Removes default arrow from firefox */ text-indent: 0.01px; text-overflow: ""; + background-repeat: no-repeat; + background-color: transparent; + background-size: 16%; + background-position: calc(100% - 1px) 56%; } .search-container > .top-button { position: absolute; diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index 3baa082bd0e69..93f95d8892e48 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -45,6 +45,9 @@ pub static BRUSH_SVG: &'static [u8] = include_bytes!("static/brush.svg"); /// The file contents of `wheel.svg`, the icon used for the settings button. pub static WHEEL_SVG: &'static [u8] = include_bytes!("static/wheel.svg"); +/// The file contents of `down-arrow.svg`, the icon used for the crate choice combobox. +pub static DOWN_ARROW_SVG: &'static [u8] = include_bytes!("static/down-arrow.svg"); + /// The contents of `COPYRIGHT.txt`, the license listing for files distributed with documentation /// output. pub static COPYRIGHT: &'static [u8] = include_bytes!("static/COPYRIGHT.txt"); From f1f6d87eab20f62a4fbb16b327f16fa69dbbaf99 Mon Sep 17 00:00:00 2001 From: varkor <github@varkor.com> Date: Fri, 30 Nov 2018 10:40:59 +0000 Subject: [PATCH 06/28] Stabilise exhaustive_integer_patterns --- src/librustc_mir/hair/pattern/_match.rs | 36 ++++++++++------------ src/libsyntax/feature_gate.rs | 4 +-- src/test/ui/exhaustive_integer_patterns.rs | 2 +- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index fd869d6c334ab..82e368198f245 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -622,7 +622,6 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, -> Vec<Constructor<'tcx>> { debug!("all_constructors({:?})", pcx.ty); - let exhaustive_integer_patterns = cx.tcx.features().exhaustive_integer_patterns; let ctors = match pcx.ty.sty { ty::Bool => { [true, false].iter().map(|&b| { @@ -652,7 +651,7 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, .map(|v| Variant(v.did)) .collect() } - ty::Char if exhaustive_integer_patterns => { + ty::Char => { vec![ // The valid Unicode Scalar Value ranges. ConstantRange('\u{0000}' as u128, @@ -667,14 +666,14 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, ), ] } - ty::Int(ity) if exhaustive_integer_patterns => { + ty::Int(ity) => { // FIXME(49937): refactor these bit manipulations into interpret. let bits = Integer::from_attr(&cx.tcx, SignedInt(ity)).size().bits() as u128; let min = 1u128 << (bits - 1); let max = (1u128 << (bits - 1)) - 1; vec![ConstantRange(min, max, pcx.ty, RangeEnd::Included)] } - ty::Uint(uty) if exhaustive_integer_patterns => { + ty::Uint(uty) => { // FIXME(49937): refactor these bit manipulations into interpret. let bits = Integer::from_attr(&cx.tcx, UnsignedInt(uty)).size().bits() as u128; let max = !0u128 >> (128 - bits); @@ -971,12 +970,10 @@ fn compute_missing_ctors<'a, 'tcx: 'a>( // If a constructor appears in a `match` arm, we can // eliminate it straight away. refined_ctors = vec![] - } else if tcx.features().exhaustive_integer_patterns { - if let Some(interval) = IntRange::from_ctor(tcx, used_ctor) { - // Refine the required constructors for the type by subtracting - // the range defined by the current constructor pattern. - refined_ctors = interval.subtract_from(tcx, refined_ctors); - } + } else if let Some(interval) = IntRange::from_ctor(tcx, used_ctor) { + // Refine the required constructors for the type by subtracting + // the range defined by the current constructor pattern. + refined_ctors = interval.subtract_from(tcx, refined_ctors); } // If the constructor patterns that have been considered so far @@ -1433,17 +1430,16 @@ fn slice_pat_covered_by_constructor<'tcx>( // Whether to evaluate a constructor using exhaustive integer matching. This is true if the // constructor is a range or constant with an integer type. fn should_treat_range_exhaustively(tcx: TyCtxt<'_, 'tcx, 'tcx>, ctor: &Constructor<'tcx>) -> bool { - if tcx.features().exhaustive_integer_patterns { - let ty = match ctor { - ConstantValue(value) => value.ty, - ConstantRange(_, _, ty, _) => ty, - _ => return false, - }; - if let ty::Char | ty::Int(_) | ty::Uint(_) = ty.sty { - return true; - } + let ty = match ctor { + ConstantValue(value) => value.ty, + ConstantRange(_, _, ty, _) => ty, + _ => return false, + }; + if let ty::Char | ty::Int(_) | ty::Uint(_) = ty.sty { + true + } else { + false } - false } /// For exhaustive integer matching, some constructors are grouped within other constructors diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 3bc349170514c..53faf04f27891 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -439,8 +439,6 @@ declare_features! ( // 'a: { break 'a; } (active, label_break_value, "1.28.0", Some(48594), None), - // Integer match exhaustiveness checking - (active, exhaustive_integer_patterns, "1.30.0", Some(50907), None), // #[doc(keyword = "...")] (active, doc_keyword, "1.28.0", Some(51315), None), @@ -686,6 +684,8 @@ declare_features! ( (accepted, extern_crate_item_prelude, "1.31.0", Some(55599), None), // Allows use of the :literal macro fragment specifier (RFC 1576) (accepted, macro_literal_matcher, "1.31.0", Some(35625), None), + // Integer match exhaustiveness checking (RFC 2591) + (accepted, exhaustive_integer_patterns, "1.32.0", Some(50907), None), // Use `?` as the Kleene "at most one" operator (accepted, macro_at_most_once_rep, "1.32.0", Some(48075), None), ); diff --git a/src/test/ui/exhaustive_integer_patterns.rs b/src/test/ui/exhaustive_integer_patterns.rs index 7825aaa291286..cddb301dbdf23 100644 --- a/src/test/ui/exhaustive_integer_patterns.rs +++ b/src/test/ui/exhaustive_integer_patterns.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(exhaustive_integer_patterns)] #![feature(exclusive_range_pattern)] + #![deny(unreachable_patterns)] use std::{char, usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128}; From e018268ffad0e3d2704705cb3337b6195b5cba08 Mon Sep 17 00:00:00 2001 From: varkor <github@varkor.com> Date: Fri, 30 Nov 2018 00:44:33 +0000 Subject: [PATCH 07/28] Add precise_pointer_size_matching feature --- src/librustc/ty/sty.rs | 7 +++++++ src/librustc_mir/hair/pattern/_match.rs | 5 +++-- src/libsyntax/feature_gate.rs | 2 ++ src/test/ui/exhaustive_integer_patterns.rs | 1 + .../feature-gate-precise_pointer_size_matching.rs | 14 ++++++++++++++ ...ture-gate-precise_pointer_size_matching.stderr | 15 +++++++++++++++ 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.rs create mode 100644 src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.stderr diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index a18e3a275467d..fbc986965742f 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -1780,6 +1780,13 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> { } } + pub fn is_pointer_sized(&self) -> bool { + match self.sty { + Int(ast::IntTy::Isize) | Uint(ast::UintTy::Usize) => true, + _ => false, + } + } + pub fn is_machine(&self) -> bool { match self.sty { Int(ast::IntTy::Isize) | Uint(ast::UintTy::Usize) => false, diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 82e368198f245..a2fbfd70a6540 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -1129,7 +1129,8 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, // For privately empty and non-exhaustive enums, we work as if there were an "extra" // `_` constructor for the type, so we can never match over all constructors. - let is_non_exhaustive = is_privately_empty || is_declared_nonexhaustive; + let is_non_exhaustive = is_privately_empty || is_declared_nonexhaustive || + (pcx.ty.is_pointer_sized() && !cx.tcx.features().precise_pointer_size_matching); if cheap_missing_ctors == MissingCtors::Empty && !is_non_exhaustive { split_grouped_constructors(cx.tcx, all_ctors, matrix, pcx.ty).into_iter().map(|c| { @@ -1436,7 +1437,7 @@ fn should_treat_range_exhaustively(tcx: TyCtxt<'_, 'tcx, 'tcx>, ctor: &Construct _ => return false, }; if let ty::Char | ty::Int(_) | ty::Uint(_) = ty.sty { - true + !ty.is_pointer_sized() || tcx.features().precise_pointer_size_matching } else { false } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 53faf04f27891..1567932266313 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -439,6 +439,8 @@ declare_features! ( // 'a: { break 'a; } (active, label_break_value, "1.28.0", Some(48594), None), + // Exhaustive pattern matching on `usize` and `isize`. + (active, precise_pointer_size_matching, "1.32.0", Some(56354), None), // #[doc(keyword = "...")] (active, doc_keyword, "1.28.0", Some(51315), None), diff --git a/src/test/ui/exhaustive_integer_patterns.rs b/src/test/ui/exhaustive_integer_patterns.rs index cddb301dbdf23..ad955fbe05d46 100644 --- a/src/test/ui/exhaustive_integer_patterns.rs +++ b/src/test/ui/exhaustive_integer_patterns.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(precise_pointer_size_matching)] #![feature(exclusive_range_pattern)] #![deny(unreachable_patterns)] diff --git a/src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.rs b/src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.rs new file mode 100644 index 0000000000000..1208552d25637 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.rs @@ -0,0 +1,14 @@ +#![feature(exclusive_range_pattern)] + +use std::usize::MAX; + +fn main() { + match 0usize { //~ERROR non-exhaustive patterns: `_` not covered + 0..=MAX => {} + } + + match 0isize { //~ERROR non-exhaustive patterns: `_` not covered + 1..=20 => {} + -5..3 => {} + } +} diff --git a/src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.stderr b/src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.stderr new file mode 100644 index 0000000000000..5806f6f039157 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.stderr @@ -0,0 +1,15 @@ +error[E0004]: non-exhaustive patterns: `_` not covered + --> $DIR/feature-gate-precise_pointer_size_matching.rs:6:11 + | +LL | match 0usize { //~ERROR non-exhaustive patterns: `_` not covered + | ^^^^^^ pattern `_` not covered + +error[E0004]: non-exhaustive patterns: `_` not covered + --> $DIR/feature-gate-precise_pointer_size_matching.rs:10:11 + | +LL | match 0isize { //~ERROR non-exhaustive patterns: `_` not covered + | ^^^^^^ pattern `_` not covered + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0004`. From 4fc5758a67e38b21e975fc9efe071dd58f4b98c6 Mon Sep 17 00:00:00 2001 From: varkor <github@varkor.com> Date: Fri, 30 Nov 2018 13:53:15 +0000 Subject: [PATCH 08/28] Update existing tests with more precise error messages --- .../vec-matching-autoslice.stderr | 8 ++++++ src/test/run-pass/binding/match-range.stderr | 20 +++++++++++++ .../issue-15881-model-lexer-dotdotdot.stderr | 8 ++++++ src/test/run-pass/issues/issue-7222.stderr | 8 ++++++ .../ui/consts/const-match-check.eval1.stderr | 4 +-- .../ui/consts/const-match-check.eval2.stderr | 4 +-- .../consts/const-match-check.matchck.stderr | 16 +++++------ .../ui/consts/const-pattern-irrefutable.rs | 6 ++-- .../consts/const-pattern-irrefutable.stderr | 12 ++++---- .../ui/exhaustive_integer_patterns.stderr | 28 +++++++++---------- ...eature-gate-exhaustive_integer_patterns.rs | 16 ----------- ...re-gate-exhaustive_integer_patterns.stderr | 9 ------ ...oop-refutable-pattern-error-message.stderr | 4 +-- src/test/ui/match/match-non-exhaustive.stderr | 4 +-- .../ui/match/match-range-fail-dominate.stderr | 8 +++++- .../ui/non-exhaustive/non-exhaustive-match.rs | 3 +- .../non-exhaustive-match.stderr | 14 +++++----- src/test/ui/refutable-pattern-errors.rs | 2 +- src/test/ui/refutable-pattern-errors.stderr | 4 +-- 19 files changed, 102 insertions(+), 76 deletions(-) create mode 100644 src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr create mode 100644 src/test/run-pass/binding/match-range.stderr create mode 100644 src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr create mode 100644 src/test/run-pass/issues/issue-7222.stderr delete mode 100644 src/test/ui/feature-gate-exhaustive_integer_patterns.rs delete mode 100644 src/test/ui/feature-gate-exhaustive_integer_patterns.stderr diff --git a/src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr b/src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr new file mode 100644 index 0000000000000..fd811e8083cf0 --- /dev/null +++ b/src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr @@ -0,0 +1,8 @@ +warning: unreachable pattern + --> $DIR/vec-matching-autoslice.rs:31:9 + | +LL | ([_, _], _) => panic!(), + | ^^^^^^^^^^^ + | + = note: #[warn(unreachable_patterns)] on by default + diff --git a/src/test/run-pass/binding/match-range.stderr b/src/test/run-pass/binding/match-range.stderr new file mode 100644 index 0000000000000..f402a98af49b3 --- /dev/null +++ b/src/test/run-pass/binding/match-range.stderr @@ -0,0 +1,20 @@ +warning: unreachable pattern + --> $DIR/match-range.rs:47:7 + | +LL | _ => panic!("should match float range") + | ^ + | + = note: #[warn(unreachable_patterns)] on by default + +warning: unreachable pattern + --> $DIR/match-range.rs:55:9 + | +LL | _ => {}, + | ^ + +warning: unreachable pattern + --> $DIR/match-range.rs:59:9 + | +LL | _ => panic!("should match the range start"), + | ^ + diff --git a/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr b/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr new file mode 100644 index 0000000000000..41b4130acf435 --- /dev/null +++ b/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr @@ -0,0 +1,8 @@ +warning: unreachable pattern + --> $DIR/issue-15881-model-lexer-dotdotdot.rs:41:7 + | +LL | _ => panic!("should match float range") + | ^ + | + = note: #[warn(unreachable_patterns)] on by default + diff --git a/src/test/run-pass/issues/issue-7222.stderr b/src/test/run-pass/issues/issue-7222.stderr new file mode 100644 index 0000000000000..1b231f2da39eb --- /dev/null +++ b/src/test/run-pass/issues/issue-7222.stderr @@ -0,0 +1,8 @@ +warning: unreachable pattern + --> $DIR/issue-7222.rs:20:9 + | +LL | _ => () + | ^ + | + = note: #[warn(unreachable_patterns)] on by default + diff --git a/src/test/ui/consts/const-match-check.eval1.stderr b/src/test/ui/consts/const-match-check.eval1.stderr index 3caf1491aba68..703453e6bdd93 100644 --- a/src/test/ui/consts/const-match-check.eval1.stderr +++ b/src/test/ui/consts/const-match-check.eval1.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered --> $DIR/const-match-check.rs:35:15 | LL | A = { let 0 = 0; 0 }, - | ^ pattern `_` not covered + | ^ pattern `-2147483648i32..=-1i32` not covered error: aborting due to previous error diff --git a/src/test/ui/consts/const-match-check.eval2.stderr b/src/test/ui/consts/const-match-check.eval2.stderr index de85d4d73db0c..6caff93e64296 100644 --- a/src/test/ui/consts/const-match-check.eval2.stderr +++ b/src/test/ui/consts/const-match-check.eval2.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered --> $DIR/const-match-check.rs:41:24 | LL | let x: [i32; { let 0 = 0; 0 }] = []; - | ^ pattern `_` not covered + | ^ pattern `-2147483648i32..=-1i32` not covered error: aborting due to previous error diff --git a/src/test/ui/consts/const-match-check.matchck.stderr b/src/test/ui/consts/const-match-check.matchck.stderr index bbf1169c577cf..9e45045d27e8d 100644 --- a/src/test/ui/consts/const-match-check.matchck.stderr +++ b/src/test/ui/consts/const-match-check.matchck.stderr @@ -1,26 +1,26 @@ -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered --> $DIR/const-match-check.rs:14:22 | LL | const X: i32 = { let 0 = 0; 0 }; - | ^ pattern `_` not covered + | ^ pattern `-2147483648i32..=-1i32` not covered -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered --> $DIR/const-match-check.rs:18:23 | LL | static Y: i32 = { let 0 = 0; 0 }; - | ^ pattern `_` not covered + | ^ pattern `-2147483648i32..=-1i32` not covered -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered --> $DIR/const-match-check.rs:23:26 | LL | const X: i32 = { let 0 = 0; 0 }; - | ^ pattern `_` not covered + | ^ pattern `-2147483648i32..=-1i32` not covered -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered --> $DIR/const-match-check.rs:29:26 | LL | const X: i32 = { let 0 = 0; 0 }; - | ^ pattern `_` not covered + | ^ pattern `-2147483648i32..=-1i32` not covered error: aborting due to 4 previous errors diff --git a/src/test/ui/consts/const-pattern-irrefutable.rs b/src/test/ui/consts/const-pattern-irrefutable.rs index af0b95e002d84..278864d6de9ec 100644 --- a/src/test/ui/consts/const-pattern-irrefutable.rs +++ b/src/test/ui/consts/const-pattern-irrefutable.rs @@ -19,8 +19,8 @@ use foo::d; const a: u8 = 2; fn main() { - let a = 4; //~ ERROR refutable pattern in local binding: `_` not covered - let c = 4; //~ ERROR refutable pattern in local binding: `_` not covered - let d = 4; //~ ERROR refutable pattern in local binding: `_` not covered + let a = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` not covered + let c = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` not covered + let d = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` not covered fn f() {} // Check that the `NOTE`s still work with an item here (c.f. issue #35115). } diff --git a/src/test/ui/consts/const-pattern-irrefutable.stderr b/src/test/ui/consts/const-pattern-irrefutable.stderr index 6d5738f332877..d9ad16cd0e8da 100644 --- a/src/test/ui/consts/const-pattern-irrefutable.stderr +++ b/src/test/ui/consts/const-pattern-irrefutable.stderr @@ -1,19 +1,19 @@ -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `0u8..=1u8` not covered --> $DIR/const-pattern-irrefutable.rs:22:9 | -LL | let a = 4; //~ ERROR refutable pattern in local binding: `_` not covered +LL | let a = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` not covered | ^ interpreted as a constant pattern, not new variable -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `0u8..=1u8` not covered --> $DIR/const-pattern-irrefutable.rs:23:9 | -LL | let c = 4; //~ ERROR refutable pattern in local binding: `_` not covered +LL | let c = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` not covered | ^ interpreted as a constant pattern, not new variable -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `0u8..=1u8` not covered --> $DIR/const-pattern-irrefutable.rs:24:9 | -LL | let d = 4; //~ ERROR refutable pattern in local binding: `_` not covered +LL | let d = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` not covered | ^ interpreted as a constant pattern, not new variable error: aborting due to 3 previous errors diff --git a/src/test/ui/exhaustive_integer_patterns.stderr b/src/test/ui/exhaustive_integer_patterns.stderr index 44b05a12aebd2..c9b669aefd1ee 100644 --- a/src/test/ui/exhaustive_integer_patterns.stderr +++ b/src/test/ui/exhaustive_integer_patterns.stderr @@ -1,83 +1,83 @@ error: unreachable pattern - --> $DIR/exhaustive_integer_patterns.rs:32:9 + --> $DIR/exhaustive_integer_patterns.rs:33:9 | LL | 200 => {} //~ ERROR unreachable pattern | ^^^ | note: lint level defined here - --> $DIR/exhaustive_integer_patterns.rs:13:9 + --> $DIR/exhaustive_integer_patterns.rs:14:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error[E0004]: non-exhaustive patterns: `128u8..=255u8` not covered - --> $DIR/exhaustive_integer_patterns.rs:37:11 + --> $DIR/exhaustive_integer_patterns.rs:38:11 | LL | match x { //~ ERROR non-exhaustive patterns | ^ pattern `128u8..=255u8` not covered error[E0004]: non-exhaustive patterns: `11u8..=19u8`, `31u8..=34u8`, `36u8..=69u8` and 1 more not covered - --> $DIR/exhaustive_integer_patterns.rs:42:11 + --> $DIR/exhaustive_integer_patterns.rs:43:11 | LL | match x { //~ ERROR non-exhaustive patterns | ^ patterns `11u8..=19u8`, `31u8..=34u8`, `36u8..=69u8` and 1 more not covered error: unreachable pattern - --> $DIR/exhaustive_integer_patterns.rs:53:9 + --> $DIR/exhaustive_integer_patterns.rs:54:9 | LL | -2..=20 => {} //~ ERROR unreachable pattern | ^^^^^^^ error[E0004]: non-exhaustive patterns: `-128i8..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered - --> $DIR/exhaustive_integer_patterns.rs:50:11 + --> $DIR/exhaustive_integer_patterns.rs:51:11 | LL | match x { //~ ERROR non-exhaustive patterns | ^ patterns `-128i8..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered error[E0004]: non-exhaustive patterns: `-128i8` not covered - --> $DIR/exhaustive_integer_patterns.rs:99:11 + --> $DIR/exhaustive_integer_patterns.rs:100:11 | LL | match 0i8 { //~ ERROR non-exhaustive patterns | ^^^ pattern `-128i8` not covered error[E0004]: non-exhaustive patterns: `0i16` not covered - --> $DIR/exhaustive_integer_patterns.rs:107:11 + --> $DIR/exhaustive_integer_patterns.rs:108:11 | LL | match 0i16 { //~ ERROR non-exhaustive patterns | ^^^^ pattern `0i16` not covered error[E0004]: non-exhaustive patterns: `128u8..=255u8` not covered - --> $DIR/exhaustive_integer_patterns.rs:125:11 + --> $DIR/exhaustive_integer_patterns.rs:126:11 | LL | match 0u8 { //~ ERROR non-exhaustive patterns | ^^^ pattern `128u8..=255u8` not covered error[E0004]: non-exhaustive patterns: `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered - --> $DIR/exhaustive_integer_patterns.rs:137:11 + --> $DIR/exhaustive_integer_patterns.rs:138:11 | LL | match (0u8, Some(())) { //~ ERROR non-exhaustive patterns | ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered error[E0004]: non-exhaustive patterns: `(126u8..=127u8, false)` not covered - --> $DIR/exhaustive_integer_patterns.rs:142:11 + --> $DIR/exhaustive_integer_patterns.rs:143:11 | LL | match (0u8, true) { //~ ERROR non-exhaustive patterns | ^^^^^^^^^^^ pattern `(126u8..=127u8, false)` not covered error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211455u128` not covered - --> $DIR/exhaustive_integer_patterns.rs:162:11 + --> $DIR/exhaustive_integer_patterns.rs:163:11 | LL | match 0u128 { //~ ERROR non-exhaustive patterns | ^^^^^ pattern `340282366920938463463374607431768211455u128` not covered error[E0004]: non-exhaustive patterns: `5u128..=340282366920938463463374607431768211455u128` not covered - --> $DIR/exhaustive_integer_patterns.rs:166:11 + --> $DIR/exhaustive_integer_patterns.rs:167:11 | LL | match 0u128 { //~ ERROR non-exhaustive patterns | ^^^^^ pattern `5u128..=340282366920938463463374607431768211455u128` not covered error[E0004]: non-exhaustive patterns: `0u128..=3u128` not covered - --> $DIR/exhaustive_integer_patterns.rs:170:11 + --> $DIR/exhaustive_integer_patterns.rs:171:11 | LL | match 0u128 { //~ ERROR non-exhaustive patterns | ^^^^^ pattern `0u128..=3u128` not covered diff --git a/src/test/ui/feature-gate-exhaustive_integer_patterns.rs b/src/test/ui/feature-gate-exhaustive_integer_patterns.rs deleted file mode 100644 index 3aa1522945548..0000000000000 --- a/src/test/ui/feature-gate-exhaustive_integer_patterns.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 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 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let x: u8 = 0; - match x { //~ ERROR non-exhaustive patterns: `_` not covered - 0 ..= 255 => {} - } -} diff --git a/src/test/ui/feature-gate-exhaustive_integer_patterns.stderr b/src/test/ui/feature-gate-exhaustive_integer_patterns.stderr deleted file mode 100644 index 63d98f6b5eb64..0000000000000 --- a/src/test/ui/feature-gate-exhaustive_integer_patterns.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0004]: non-exhaustive patterns: `_` not covered - --> $DIR/feature-gate-exhaustive_integer_patterns.rs:13:11 - | -LL | match x { //~ ERROR non-exhaustive patterns: `_` not covered - | ^ pattern `_` not covered - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0004`. diff --git a/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr b/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr index b76c2ffc240e1..9b19fc80e2bd6 100644 --- a/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr +++ b/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in `for` loop binding: `&_` not covered +error[E0005]: refutable pattern in `for` loop binding: `&-2147483648i32..=0i32` not covered --> $DIR/for-loop-refutable-pattern-error-message.rs:12:9 | LL | for &1 in [1].iter() {} //~ ERROR refutable pattern in `for` loop binding - | ^^ pattern `&_` not covered + | ^^ pattern `&-2147483648i32..=0i32` not covered error: aborting due to previous error diff --git a/src/test/ui/match/match-non-exhaustive.stderr b/src/test/ui/match/match-non-exhaustive.stderr index 04f09caceed3d..ad895b448dd20 100644 --- a/src/test/ui/match/match-non-exhaustive.stderr +++ b/src/test/ui/match/match-non-exhaustive.stderr @@ -1,8 +1,8 @@ -error[E0004]: non-exhaustive patterns: `_` not covered +error[E0004]: non-exhaustive patterns: `-2147483648i32..=0i32` and `2i32..=2147483647i32` not covered --> $DIR/match-non-exhaustive.rs:12:11 | LL | match 0 { 1 => () } //~ ERROR non-exhaustive patterns - | ^ pattern `_` not covered + | ^ patterns `-2147483648i32..=0i32` and `2i32..=2147483647i32` not covered error[E0004]: non-exhaustive patterns: `_` not covered --> $DIR/match-non-exhaustive.rs:13:11 diff --git a/src/test/ui/match/match-range-fail-dominate.stderr b/src/test/ui/match/match-range-fail-dominate.stderr index d75630e09c507..99f65042d8515 100644 --- a/src/test/ui/match/match-range-fail-dominate.stderr +++ b/src/test/ui/match/match-range-fail-dominate.stderr @@ -62,5 +62,11 @@ error: unreachable pattern LL | 0.02f64 => {} | ^^^^^^^ -error: aborting due to 5 previous errors +error: unreachable pattern + --> $DIR/match-range-fail-dominate.rs:47:7 + | +LL | _ => {} + | ^ + +error: aborting due to 6 previous errors diff --git a/src/test/ui/non-exhaustive/non-exhaustive-match.rs b/src/test/ui/non-exhaustive/non-exhaustive-match.rs index 13b62429f4693..99a0c5d662660 100644 --- a/src/test/ui/non-exhaustive/non-exhaustive-match.rs +++ b/src/test/ui/non-exhaustive/non-exhaustive-match.rs @@ -22,7 +22,8 @@ fn main() { match Some(10) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered None => {} } - match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, _)` not covered + match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, -2147483648i32..=3i32)` + // and `(_, _, 5i32..=2147483647i32)` not covered (_, _, 4) => {} } match (t::a, t::a) { //~ ERROR non-exhaustive patterns: `(a, a)` not covered diff --git a/src/test/ui/non-exhaustive/non-exhaustive-match.stderr b/src/test/ui/non-exhaustive/non-exhaustive-match.stderr index f48a0bc15eb6f..d3703a4445499 100644 --- a/src/test/ui/non-exhaustive/non-exhaustive-match.stderr +++ b/src/test/ui/non-exhaustive/non-exhaustive-match.stderr @@ -16,32 +16,32 @@ error[E0004]: non-exhaustive patterns: `Some(_)` not covered LL | match Some(10) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered | ^^^^^^^^ pattern `Some(_)` not covered -error[E0004]: non-exhaustive patterns: `(_, _, _)` not covered +error[E0004]: non-exhaustive patterns: `(_, _, -2147483648i32..=3i32)` and `(_, _, 5i32..=2147483647i32)` not covered --> $DIR/non-exhaustive-match.rs:25:11 | -LL | match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, _)` not covered - | ^^^^^^^^^ pattern `(_, _, _)` not covered +LL | match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, -2147483648i32..=3i32)` + | ^^^^^^^^^ patterns `(_, _, -2147483648i32..=3i32)` and `(_, _, 5i32..=2147483647i32)` not covered error[E0004]: non-exhaustive patterns: `(a, a)` not covered - --> $DIR/non-exhaustive-match.rs:28:11 + --> $DIR/non-exhaustive-match.rs:29:11 | LL | match (t::a, t::a) { //~ ERROR non-exhaustive patterns: `(a, a)` not covered | ^^^^^^^^^^^^ pattern `(a, a)` not covered error[E0004]: non-exhaustive patterns: `b` not covered - --> $DIR/non-exhaustive-match.rs:32:11 + --> $DIR/non-exhaustive-match.rs:33:11 | LL | match t::a { //~ ERROR non-exhaustive patterns: `b` not covered | ^^^^ pattern `b` not covered error[E0004]: non-exhaustive patterns: `[]` not covered - --> $DIR/non-exhaustive-match.rs:43:11 + --> $DIR/non-exhaustive-match.rs:44:11 | LL | match *vec { //~ ERROR non-exhaustive patterns: `[]` not covered | ^^^^ pattern `[]` not covered error[E0004]: non-exhaustive patterns: `[_, _, _, _]` not covered - --> $DIR/non-exhaustive-match.rs:56:11 + --> $DIR/non-exhaustive-match.rs:57:11 | LL | match *vec { //~ ERROR non-exhaustive patterns: `[_, _, _, _]` not covered | ^^^^ pattern `[_, _, _, _]` not covered diff --git a/src/test/ui/refutable-pattern-errors.rs b/src/test/ui/refutable-pattern-errors.rs index 7b4009481abd4..a140e421a5706 100644 --- a/src/test/ui/refutable-pattern-errors.rs +++ b/src/test/ui/refutable-pattern-errors.rs @@ -14,5 +14,5 @@ fn func((1, (Some(1), 2..=3)): (isize, (Option<isize>, isize))) { } fn main() { let (1, (Some(1), 2..=3)) = (1, (None, 2)); - //~^ ERROR refutable pattern in local binding: `(_, _)` not covered + //~^ ERROR refutable pattern in local binding: `(-2147483648i32..=0i32, _)` not covered } diff --git a/src/test/ui/refutable-pattern-errors.stderr b/src/test/ui/refutable-pattern-errors.stderr index c2d5fe001fc10..42aa572789522 100644 --- a/src/test/ui/refutable-pattern-errors.stderr +++ b/src/test/ui/refutable-pattern-errors.stderr @@ -4,11 +4,11 @@ error[E0005]: refutable pattern in function argument: `(_, _)` not covered LL | fn func((1, (Some(1), 2..=3)): (isize, (Option<isize>, isize))) { } | ^^^^^^^^^^^^^^^^^^^^^ pattern `(_, _)` not covered -error[E0005]: refutable pattern in local binding: `(_, _)` not covered +error[E0005]: refutable pattern in local binding: `(-2147483648i32..=0i32, _)` not covered --> $DIR/refutable-pattern-errors.rs:16:9 | LL | let (1, (Some(1), 2..=3)) = (1, (None, 2)); - | ^^^^^^^^^^^^^^^^^^^^^ pattern `(_, _)` not covered + | ^^^^^^^^^^^^^^^^^^^^^ pattern `(-2147483648i32..=0i32, _)` not covered error: aborting due to 2 previous errors From 0fb52fb538946600dfe76be0b943556363904136 Mon Sep 17 00:00:00 2001 From: varkor <github@varkor.com> Date: Fri, 30 Nov 2018 21:13:07 +0000 Subject: [PATCH 09/28] Separate out precise_pointer_size_matching tests from exhaustive_integer_patterns tests --- src/test/ui/exhaustive_integer_patterns.rs | 10 +------ .../ui/exhaustive_integer_patterns.stderr | 16 ++++++------ src/test/ui/precise_pointer_size_matching.rs | 26 +++++++++++++++++++ .../ui/precise_pointer_size_matching.stderr | 15 +++++++++++ 4 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 src/test/ui/precise_pointer_size_matching.rs create mode 100644 src/test/ui/precise_pointer_size_matching.stderr diff --git a/src/test/ui/exhaustive_integer_patterns.rs b/src/test/ui/exhaustive_integer_patterns.rs index ad955fbe05d46..020382d9fe17d 100644 --- a/src/test/ui/exhaustive_integer_patterns.rs +++ b/src/test/ui/exhaustive_integer_patterns.rs @@ -13,7 +13,7 @@ #![deny(unreachable_patterns)] -use std::{char, usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128}; +use std::{char, u8, u16, u32, u64, u128, i8, i16, i32, i64, i128}; fn main() { let x: u8 = 0; @@ -69,10 +69,6 @@ fn main() { '\u{E000}' ..= '\u{10_FFFF}' => {} } - match 0usize { - 0 ..= usize::MAX => {} // ok - } - match 0u16 { 0 ..= u16::MAX => {} // ok } @@ -89,10 +85,6 @@ fn main() { 0 ..= u128::MAX => {} // ok } - match 0isize { - isize::MIN ..= isize::MAX => {} // ok - } - match 0i8 { -128 ..= 127 => {} // ok } diff --git a/src/test/ui/exhaustive_integer_patterns.stderr b/src/test/ui/exhaustive_integer_patterns.stderr index c9b669aefd1ee..011e93683fb6e 100644 --- a/src/test/ui/exhaustive_integer_patterns.stderr +++ b/src/test/ui/exhaustive_integer_patterns.stderr @@ -35,49 +35,49 @@ LL | match x { //~ ERROR non-exhaustive patterns | ^ patterns `-128i8..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered error[E0004]: non-exhaustive patterns: `-128i8` not covered - --> $DIR/exhaustive_integer_patterns.rs:100:11 + --> $DIR/exhaustive_integer_patterns.rs:92:11 | LL | match 0i8 { //~ ERROR non-exhaustive patterns | ^^^ pattern `-128i8` not covered error[E0004]: non-exhaustive patterns: `0i16` not covered - --> $DIR/exhaustive_integer_patterns.rs:108:11 + --> $DIR/exhaustive_integer_patterns.rs:100:11 | LL | match 0i16 { //~ ERROR non-exhaustive patterns | ^^^^ pattern `0i16` not covered error[E0004]: non-exhaustive patterns: `128u8..=255u8` not covered - --> $DIR/exhaustive_integer_patterns.rs:126:11 + --> $DIR/exhaustive_integer_patterns.rs:118:11 | LL | match 0u8 { //~ ERROR non-exhaustive patterns | ^^^ pattern `128u8..=255u8` not covered error[E0004]: non-exhaustive patterns: `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered - --> $DIR/exhaustive_integer_patterns.rs:138:11 + --> $DIR/exhaustive_integer_patterns.rs:130:11 | LL | match (0u8, Some(())) { //~ ERROR non-exhaustive patterns | ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered error[E0004]: non-exhaustive patterns: `(126u8..=127u8, false)` not covered - --> $DIR/exhaustive_integer_patterns.rs:143:11 + --> $DIR/exhaustive_integer_patterns.rs:135:11 | LL | match (0u8, true) { //~ ERROR non-exhaustive patterns | ^^^^^^^^^^^ pattern `(126u8..=127u8, false)` not covered error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211455u128` not covered - --> $DIR/exhaustive_integer_patterns.rs:163:11 + --> $DIR/exhaustive_integer_patterns.rs:155:11 | LL | match 0u128 { //~ ERROR non-exhaustive patterns | ^^^^^ pattern `340282366920938463463374607431768211455u128` not covered error[E0004]: non-exhaustive patterns: `5u128..=340282366920938463463374607431768211455u128` not covered - --> $DIR/exhaustive_integer_patterns.rs:167:11 + --> $DIR/exhaustive_integer_patterns.rs:159:11 | LL | match 0u128 { //~ ERROR non-exhaustive patterns | ^^^^^ pattern `5u128..=340282366920938463463374607431768211455u128` not covered error[E0004]: non-exhaustive patterns: `0u128..=3u128` not covered - --> $DIR/exhaustive_integer_patterns.rs:171:11 + --> $DIR/exhaustive_integer_patterns.rs:163:11 | LL | match 0u128 { //~ ERROR non-exhaustive patterns | ^^^^^ pattern `0u128..=3u128` not covered diff --git a/src/test/ui/precise_pointer_size_matching.rs b/src/test/ui/precise_pointer_size_matching.rs new file mode 100644 index 0000000000000..31b202fd6aa14 --- /dev/null +++ b/src/test/ui/precise_pointer_size_matching.rs @@ -0,0 +1,26 @@ +#![feature(precise_pointer_size_matching)] +#![feature(exclusive_range_pattern)] + +#![deny(unreachable_patterns)] + +use std::{usize, isize}; + +fn main() { + match 0isize { + isize::MIN ..= isize::MAX => {} // ok + } + + match 0usize { + 0 ..= usize::MAX => {} // ok + } + + match 0isize { //~ ERROR non-exhaustive patterns + 1 ..= 8 => {} + -5 ..= 20 => {} + } + + match 0usize { //~ ERROR non-exhaustive patterns + 1 ..= 8 => {} + 5 ..= 20 => {} + } +} diff --git a/src/test/ui/precise_pointer_size_matching.stderr b/src/test/ui/precise_pointer_size_matching.stderr new file mode 100644 index 0000000000000..8e13be0ae0c74 --- /dev/null +++ b/src/test/ui/precise_pointer_size_matching.stderr @@ -0,0 +1,15 @@ +error[E0004]: non-exhaustive patterns: `-9223372036854775808isize..=-6isize` and `21isize..=9223372036854775807isize` not covered + --> $DIR/precise_pointer_size_matching.rs:17:11 + | +LL | match 0isize { //~ ERROR non-exhaustive patterns + | ^^^^^^ patterns `-9223372036854775808isize..=-6isize` and `21isize..=9223372036854775807isize` not covered + +error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=18446744073709551615usize` not covered + --> $DIR/precise_pointer_size_matching.rs:22:11 + | +LL | match 0usize { //~ ERROR non-exhaustive patterns + | ^^^^^^ patterns `0usize` and `21usize..=18446744073709551615usize` not covered + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0004`. From 4406391cdce37dfd8142cc49e3760c606da8913c Mon Sep 17 00:00:00 2001 From: varkor <github@varkor.com> Date: Fri, 30 Nov 2018 21:13:16 +0000 Subject: [PATCH 10/28] Fix bug in matching on floating-point ranges --- src/librustc_mir/hair/pattern/_match.rs | 17 +++++++++++----- .../vec-matching-autoslice.stderr | 8 -------- src/test/run-pass/binding/match-range.stderr | 20 ------------------- .../issue-15881-model-lexer-dotdotdot.stderr | 8 -------- src/test/run-pass/issues/issue-7222.stderr | 8 -------- .../ui/match/match-range-fail-dominate.stderr | 8 +------- .../non-exhaustive-float-range-match.rs | 13 ++++++++++++ .../non-exhaustive-float-range-match.stderr | 9 +++++++++ 8 files changed, 35 insertions(+), 56 deletions(-) delete mode 100644 src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr delete mode 100644 src/test/run-pass/binding/match-range.stderr delete mode 100644 src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr delete mode 100644 src/test/run-pass/issues/issue-7222.stderr create mode 100644 src/test/ui/non-exhaustive/non-exhaustive-float-range-match.rs create mode 100644 src/test/ui/non-exhaustive/non-exhaustive-float-range-match.stderr diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index a2fbfd70a6540..f7e034df1dadc 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -812,8 +812,17 @@ impl<'tcx> IntRange<'tcx> { fn from_ctor(tcx: TyCtxt<'_, 'tcx, 'tcx>, ctor: &Constructor<'tcx>) -> Option<IntRange<'tcx>> { + // Floating-point ranges are permitted and we don't want + // to consider them when constructing integer ranges. + fn is_integral<'tcx>(ty: Ty<'tcx>) -> bool { + match ty.sty { + ty::Char | ty::Int(_) | ty::Uint(_) => true, + _ => false, + } + } + match ctor { - ConstantRange(lo, hi, ty, end) => { + ConstantRange(lo, hi, ty, end) if is_integral(ty) => { // Perform a shift if the underlying types are signed, // which makes the interval arithmetic simpler. let bias = IntRange::signed_bias(tcx, ty); @@ -826,7 +835,7 @@ impl<'tcx> IntRange<'tcx> { Some(IntRange { range: lo..=(hi - offset), ty }) } } - ConstantValue(val) => { + ConstantValue(val) if is_integral(val.ty) => { let ty = val.ty; if let Some(val) = val.assert_bits(tcx, ty::ParamEnv::empty().and(ty)) { let bias = IntRange::signed_bias(tcx, ty); @@ -836,9 +845,7 @@ impl<'tcx> IntRange<'tcx> { None } } - Single | Variant(_) | Slice(_) => { - None - } + _ => None, } } diff --git a/src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr b/src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr deleted file mode 100644 index fd811e8083cf0..0000000000000 --- a/src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr +++ /dev/null @@ -1,8 +0,0 @@ -warning: unreachable pattern - --> $DIR/vec-matching-autoslice.rs:31:9 - | -LL | ([_, _], _) => panic!(), - | ^^^^^^^^^^^ - | - = note: #[warn(unreachable_patterns)] on by default - diff --git a/src/test/run-pass/binding/match-range.stderr b/src/test/run-pass/binding/match-range.stderr deleted file mode 100644 index f402a98af49b3..0000000000000 --- a/src/test/run-pass/binding/match-range.stderr +++ /dev/null @@ -1,20 +0,0 @@ -warning: unreachable pattern - --> $DIR/match-range.rs:47:7 - | -LL | _ => panic!("should match float range") - | ^ - | - = note: #[warn(unreachable_patterns)] on by default - -warning: unreachable pattern - --> $DIR/match-range.rs:55:9 - | -LL | _ => {}, - | ^ - -warning: unreachable pattern - --> $DIR/match-range.rs:59:9 - | -LL | _ => panic!("should match the range start"), - | ^ - diff --git a/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr b/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr deleted file mode 100644 index 41b4130acf435..0000000000000 --- a/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr +++ /dev/null @@ -1,8 +0,0 @@ -warning: unreachable pattern - --> $DIR/issue-15881-model-lexer-dotdotdot.rs:41:7 - | -LL | _ => panic!("should match float range") - | ^ - | - = note: #[warn(unreachable_patterns)] on by default - diff --git a/src/test/run-pass/issues/issue-7222.stderr b/src/test/run-pass/issues/issue-7222.stderr deleted file mode 100644 index 1b231f2da39eb..0000000000000 --- a/src/test/run-pass/issues/issue-7222.stderr +++ /dev/null @@ -1,8 +0,0 @@ -warning: unreachable pattern - --> $DIR/issue-7222.rs:20:9 - | -LL | _ => () - | ^ - | - = note: #[warn(unreachable_patterns)] on by default - diff --git a/src/test/ui/match/match-range-fail-dominate.stderr b/src/test/ui/match/match-range-fail-dominate.stderr index 99f65042d8515..d75630e09c507 100644 --- a/src/test/ui/match/match-range-fail-dominate.stderr +++ b/src/test/ui/match/match-range-fail-dominate.stderr @@ -62,11 +62,5 @@ error: unreachable pattern LL | 0.02f64 => {} | ^^^^^^^ -error: unreachable pattern - --> $DIR/match-range-fail-dominate.rs:47:7 - | -LL | _ => {} - | ^ - -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors diff --git a/src/test/ui/non-exhaustive/non-exhaustive-float-range-match.rs b/src/test/ui/non-exhaustive/non-exhaustive-float-range-match.rs new file mode 100644 index 0000000000000..588fecbf10dd5 --- /dev/null +++ b/src/test/ui/non-exhaustive/non-exhaustive-float-range-match.rs @@ -0,0 +1,13 @@ +#![allow(illegal_floating_point_literal_pattern)] +#![deny(unreachable_patterns)] + +fn main() { + match 0.0 { + 0.0..=1.0 => {} + _ => {} // ok + } + + match 0.0 { //~ ERROR non-exhaustive patterns + 0.0..=1.0 => {} + } +} diff --git a/src/test/ui/non-exhaustive/non-exhaustive-float-range-match.stderr b/src/test/ui/non-exhaustive/non-exhaustive-float-range-match.stderr new file mode 100644 index 0000000000000..2e285afb3804e --- /dev/null +++ b/src/test/ui/non-exhaustive/non-exhaustive-float-range-match.stderr @@ -0,0 +1,9 @@ +error[E0004]: non-exhaustive patterns: `_` not covered + --> $DIR/non-exhaustive-float-range-match.rs:10:11 + | +LL | match 0.0 { //~ ERROR non-exhaustive patterns + | ^^^ pattern `_` not covered + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0004`. From 3b705a0ece15843e6deef6833025f8548f4348c5 Mon Sep 17 00:00:00 2001 From: Oliver Middleton <olliemail27@gmail.com> Date: Sun, 2 Dec 2018 16:55:00 +0000 Subject: [PATCH 11/28] rustbuild: Fix issues with compiler docs * Create output directories for crates beforehand so rustdoc uses relative links * Readd rustc_codegen_ssa * Don't build out of tree dependencies for rustdoc like we don't for rustc --- src/bootstrap/doc.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index f9b19ffb10d69..c1361b5768032 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -696,9 +696,6 @@ impl Step for Rustc { return; } - // Build libstd docs so that we generate relative links. - builder.ensure(Std { stage, target }); - // Build rustc. builder.ensure(compile::Rustc { compiler, target }); @@ -717,12 +714,16 @@ impl Step for Rustc { // Find dependencies for top level crates. let mut compiler_crates = HashSet::new(); - for root_crate in &["rustc", "rustc_driver", "rustc_codegen_llvm"] { + for root_crate in &["rustc_driver", "rustc_codegen_llvm", "rustc_codegen_ssa"] { let interned_root_crate = INTERNER.intern_str(root_crate); find_compiler_crates(builder, &interned_root_crate, &mut compiler_crates); } for krate in &compiler_crates { + // Create all crate output directories first to make sure rustdoc uses + // relative links. + // FIXME: Cargo should probably do this itself. + t!(fs::create_dir_all(out_dir.join(krate))); cargo.arg("-p").arg(krate); } @@ -796,8 +797,8 @@ impl Step for Rustdoc { return; } - // Build libstd docs so that we generate relative links. - builder.ensure(Std { stage, target }); + // Build rustc docs so that we generate relative links. + builder.ensure(Rustc { stage, target }); // Build rustdoc. builder.ensure(tool::Rustdoc { host: compiler.host }); @@ -821,6 +822,10 @@ impl Step for Rustdoc { &[] ); + // Only include compiler crates, no dependencies of those, such as `libc`. + cargo.arg("--no-deps"); + cargo.arg("-p").arg("rustdoc"); + cargo.env("RUSTDOCFLAGS", "--document-private-items"); builder.run(&mut cargo); } From 59e9a1e75aaa971b1910fd9db98d9fce55534558 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda <ariel.byd@gmail.com> Date: Mon, 3 Dec 2018 00:49:12 +0200 Subject: [PATCH 12/28] pass the parameter environment to `traits::find_associated_item` dropping the param-env on the floor is obviously the wrong thing to do. The ICE was probably exposed by #54490 adding the problem-exposing use of `traits::find_associated_item`. Fixes #55380. --- src/librustc/traits/specialize/mod.rs | 12 +++++++- src/librustc/traits/structural_impls.rs | 4 +-- src/librustc/ty/instance.rs | 5 ++-- src/test/run-pass/issue-55380.rs | 38 +++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 src/test/run-pass/issue-55380.rs diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 19ef3171b13fc..cb17246b15f11 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -85,6 +85,8 @@ pub fn translate_substs<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, source_substs: &'tcx Substs<'tcx>, target_node: specialization_graph::Node) -> &'tcx Substs<'tcx> { + debug!("translate_substs({:?}, {:?}, {:?}, {:?})", + param_env, source_impl, source_substs, target_node); let source_trait_ref = infcx.tcx .impl_trait_ref(source_impl) .unwrap() @@ -119,10 +121,13 @@ pub fn translate_substs<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, /// whichever applies. pub fn find_associated_item<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, + param_env: ty::ParamEnv<'tcx>, item: &ty::AssociatedItem, substs: &'tcx Substs<'tcx>, impl_data: &super::VtableImplData<'tcx, ()>, ) -> (DefId, &'tcx Substs<'tcx>) { + debug!("find_associated_item({:?}, {:?}, {:?}, {:?})", + param_env, item, substs, impl_data); assert!(!substs.needs_infer()); let trait_def_id = tcx.trait_id_of_impl(impl_data.impl_def_id).unwrap(); @@ -132,7 +137,7 @@ pub fn find_associated_item<'a, 'tcx>( match ancestors.defs(tcx, item.ident, item.kind, trait_def_id).next() { Some(node_item) => { let substs = tcx.infer_ctxt().enter(|infcx| { - let param_env = ty::ParamEnv::reveal_all(); + let param_env = param_env.with_reveal_all(); let substs = substs.rebase_onto(tcx, trait_def_id, impl_data.substs); let substs = translate_substs(&infcx, param_env, impl_data.impl_def_id, substs, node_item.node); @@ -219,12 +224,17 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, source_trait_ref: ty::TraitRef<'tcx>, target_impl: DefId) -> Result<&'tcx Substs<'tcx>, ()> { + debug!("fulfill_implication({:?}, trait_ref={:?} |- {:?} applies)", + param_env, source_trait_ref, target_impl); + let selcx = &mut SelectionContext::new(&infcx); let target_substs = infcx.fresh_substs_for_item(DUMMY_SP, target_impl); let (target_trait_ref, mut obligations) = impl_trait_ref_and_oblig(selcx, param_env, target_impl, target_substs); + debug!("fulfill_implication: target_trait_ref={:?}, obligations={:?}", + target_trait_ref, obligations); // do the impls unify? If not, no specialization. match infcx.at(&ObligationCause::dummy(), param_env) diff --git a/src/librustc/traits/structural_impls.rs b/src/librustc/traits/structural_impls.rs index 36538ac0889de..36e93cc774089 100644 --- a/src/librustc/traits/structural_impls.rs +++ b/src/librustc/traits/structural_impls.rs @@ -33,8 +33,8 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> { if ty::tls::with(|tcx| tcx.sess.verbose()) { write!( f, - "Obligation(predicate={:?},cause={:?},depth={})", - self.predicate, self.cause, self.recursion_depth + "Obligation(predicate={:?},cause={:?},param_env={:?},depth={})", + self.predicate, self.cause, self.param_env, self.recursion_depth ) } else { write!( diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 411a6e7e6238e..a24920da158e2 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -347,9 +347,10 @@ fn resolve_associated_item<'a, 'tcx>( ) -> Option<Instance<'tcx>> { let def_id = trait_item.def_id; debug!("resolve_associated_item(trait_item={:?}, \ + param_env={:?}, \ trait_id={:?}, \ rcvr_substs={:?})", - def_id, trait_id, rcvr_substs); + def_id, param_env, trait_id, rcvr_substs); let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs); let vtbl = tcx.codegen_fulfill_obligation((param_env, ty::Binder::bind(trait_ref))); @@ -359,7 +360,7 @@ fn resolve_associated_item<'a, 'tcx>( match vtbl { traits::VtableImpl(impl_data) => { let (def_id, substs) = traits::find_associated_item( - tcx, trait_item, rcvr_substs, &impl_data); + tcx, param_env, trait_item, rcvr_substs, &impl_data); let substs = tcx.erase_regions(&substs); Some(ty::Instance::new(def_id, substs)) } diff --git a/src/test/run-pass/issue-55380.rs b/src/test/run-pass/issue-55380.rs new file mode 100644 index 0000000000000..29392fba8b475 --- /dev/null +++ b/src/test/run-pass/issue-55380.rs @@ -0,0 +1,38 @@ +// Copyright 2018 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-pass + +#![feature(specialization)] + +pub trait Foo { + fn abc() -> u32; + fn def() -> u32; +} + +pub trait Marker {} + +impl Marker for () {} + +impl<T> Foo for T { + default fn abc() -> u32 { 16 } + default fn def() -> u32 { 42 } +} + +impl<T: Marker> Foo for T { + fn def() -> u32 { + Self::abc() + } +} + +fn main() { + assert_eq!(<()>::def(), 16); + assert_eq!(<i32>::def(), 42); +} From 101467c152b26c44079401a712291c29cff0c9ac Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Date: Sun, 2 Dec 2018 03:05:19 +0300 Subject: [PATCH 13/28] syntax: `dyn` is a used keyword now --- src/libsyntax_pos/symbol.rs | 18 +++++++++++++----- .../ui/rust-2018/dyn-trait-compatibility.rs | 2 +- .../rust-2018/dyn-trait-compatibility.stderr | 6 +++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 741877bb4c88f..8ccd123afdcea 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -404,9 +404,11 @@ declare_keywords! { (49, Virtual, "virtual") (50, Yield, "yield") + // Edition-specific keywords used in the language. + (51, Dyn, "dyn") // >= 2018 Edition only + // Edition-specific keywords reserved for future use. - (51, Async, "async") // >= 2018 Edition only - (52, Dyn, "dyn") // >= 2018 Edition only + (52, Async, "async") // >= 2018 Edition only (53, Try, "try") // >= 2018 Edition only // Special lifetime names @@ -417,11 +419,15 @@ declare_keywords! { (56, Auto, "auto") (57, Catch, "catch") (58, Default, "default") - (59, Union, "union") - (60, Existential, "existential") + (59, Existential, "existential") + (60, Union, "union") } impl Symbol { + fn is_used_keyword_2018(self) -> bool { + self == keywords::Dyn.name() + } + fn is_unused_keyword_2018(self) -> bool { self >= keywords::Async.name() && self <= keywords::Try.name() } @@ -436,7 +442,9 @@ impl Ident { /// Returns `true` if the token is a keyword used in the language. pub fn is_used_keyword(self) -> bool { - self.name >= keywords::As.name() && self.name <= keywords::While.name() + // Note: `span.edition()` is relatively expensive, don't call it unless necessary. + self.name >= keywords::As.name() && self.name <= keywords::While.name() || + self.name.is_used_keyword_2018() && self.span.rust_2018() } /// Returns `true` if the token is a keyword reserved for possible future use. diff --git a/src/test/ui/rust-2018/dyn-trait-compatibility.rs b/src/test/ui/rust-2018/dyn-trait-compatibility.rs index 9548df5959bd4..377c85fef490a 100644 --- a/src/test/ui/rust-2018/dyn-trait-compatibility.rs +++ b/src/test/ui/rust-2018/dyn-trait-compatibility.rs @@ -1,7 +1,7 @@ // edition:2018 type A0 = dyn; -type A1 = dyn::dyn; //~ERROR expected identifier, found reserved keyword +type A1 = dyn::dyn; //~ERROR expected identifier, found keyword `dyn` type A2 = dyn<dyn, dyn>; //~ERROR expected identifier, found `<` type A3 = dyn<<dyn as dyn>::dyn>; diff --git a/src/test/ui/rust-2018/dyn-trait-compatibility.stderr b/src/test/ui/rust-2018/dyn-trait-compatibility.stderr index ea0483394b5ea..bd72f9c6786b2 100644 --- a/src/test/ui/rust-2018/dyn-trait-compatibility.stderr +++ b/src/test/ui/rust-2018/dyn-trait-compatibility.stderr @@ -1,8 +1,8 @@ -error: expected identifier, found reserved keyword `dyn` +error: expected identifier, found keyword `dyn` --> $DIR/dyn-trait-compatibility.rs:4:16 | -LL | type A1 = dyn::dyn; //~ERROR expected identifier, found reserved keyword - | ^^^ expected identifier, found reserved keyword +LL | type A1 = dyn::dyn; //~ERROR expected identifier, found keyword `dyn` + | ^^^ expected identifier, found keyword error: expected identifier, found `<` --> $DIR/dyn-trait-compatibility.rs:5:14 From 08f8faedd0e30f45762afbb8d4873f7041e7462c Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Date: Sun, 2 Dec 2018 03:35:55 +0300 Subject: [PATCH 14/28] syntax: Rename some keywords `CrateRoot` -> `PathRoot`, `::` doesn't necessarily mean crate root now `SelfValue` -> `SelfLower`, `SelfType` -> `SelfUpper`, both `self` and `Self` can be used in type and value namespaces now --- src/grammar/parser-lalr.y | 4 +- src/librustc/hir/lowering.rs | 6 +-- src/librustc/hir/map/mod.rs | 2 +- src/librustc/hir/mod.rs | 2 +- src/librustc/hir/print.rs | 6 +-- src/librustc/middle/liveness.rs | 2 +- src/librustc/ty/context.rs | 2 +- src/librustc/ty/sty.rs | 4 +- src/librustc_lint/unused.rs | 2 +- .../borrow_check/mutability_errors.rs | 2 +- src/librustc_resolve/build_reduced_graph.rs | 20 ++++---- src/librustc_resolve/error_reporting.rs | 4 +- src/librustc_resolve/lib.rs | 46 +++++++++---------- src/librustc_resolve/macros.rs | 6 +-- src/librustc_resolve/resolve_imports.rs | 6 +-- src/librustc_typeck/collect.rs | 4 +- src/librustdoc/clean/mod.rs | 6 +-- src/libsyntax/ast.rs | 10 ++-- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/ext/expand.rs | 2 +- src/libsyntax/parse/parser.rs | 6 +-- src/libsyntax/print/pprust.rs | 4 +- src/libsyntax/std_inject.rs | 2 +- src/libsyntax_ext/deriving/clone.rs | 2 +- src/libsyntax_ext/deriving/generic/mod.rs | 2 +- src/libsyntax_pos/symbol.rs | 12 ++--- 26 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/grammar/parser-lalr.y b/src/grammar/parser-lalr.y index a7da69f65faf2..8ea1cb26dc0c7 100644 --- a/src/grammar/parser-lalr.y +++ b/src/grammar/parser-lalr.y @@ -741,14 +741,14 @@ fn_anon_params ; fn_params_with_self -: '(' maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfValue", 3, $2, $4, $5); } +: '(' maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfLower", 3, $2, $4, $5); } | '(' '&' maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfRegion", 3, $3, $5, $6); } | '(' '&' lifetime maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfRegion", 4, $3, $4, $6, $7); } | '(' maybe_params ')' { $$ = mk_node("SelfStatic", 1, $2); } ; fn_anon_params_with_self -: '(' maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfValue", 3, $2, $4, $5); } +: '(' maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfLower", 3, $2, $4, $5); } | '(' '&' maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfRegion", 3, $3, $5, $6); } | '(' '&' lifetime maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfRegion", 4, $3, $4, $6, $7); } | '(' maybe_anon_params ')' { $$ = mk_node("SelfStatic", 1, $2); } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index dc8baa112bb59..a485af0a5eef9 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1201,7 +1201,7 @@ impl<'a> LoweringContext<'a> { None, P(hir::Path { def: self.expect_full_def(t.id), - segments: hir_vec![hir::PathSegment::from_ident(keywords::SelfType.ident())], + segments: hir_vec![hir::PathSegment::from_ident(keywords::SelfUpper.ident())], span: t.span, }), )), @@ -2425,7 +2425,7 @@ impl<'a> LoweringContext<'a> { // Don't expose `Self` (recovered "keyword used as ident" parse error). // `rustc::ty` expects `Self` to be only used for a trait's `Self`. // Instead, use gensym("Self") to create a distinct name that looks the same. - let ident = if param.ident.name == keywords::SelfType.name() { + let ident = if param.ident.name == keywords::SelfUpper.name() { param.ident.gensym() } else { param.ident @@ -2981,7 +2981,7 @@ impl<'a> LoweringContext<'a> { // Correctly resolve `self` imports if path.segments.len() > 1 - && path.segments.last().unwrap().ident.name == keywords::SelfValue.name() + && path.segments.last().unwrap().ident.name == keywords::SelfLower.name() { let _ = path.segments.pop(); if rename.is_none() { diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index ef777abfbc41a..4ac07d78a2613 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -475,7 +475,7 @@ impl<'hir> Map<'hir> { pub fn ty_param_name(&self, id: NodeId) -> Name { match self.get(id) { - Node::Item(&Item { node: ItemKind::Trait(..), .. }) => keywords::SelfType.name(), + Node::Item(&Item { node: ItemKind::Trait(..), .. }) => keywords::SelfUpper.name(), Node::GenericParam(param) => param.name.ident().name, _ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)), } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 1674320165e65..85bf257df237f 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -311,7 +311,7 @@ pub struct Path { impl Path { pub fn is_global(&self) -> bool { - !self.segments.is_empty() && self.segments[0].ident.name == keywords::CrateRoot.name() + !self.segments.is_empty() && self.segments[0].ident.name == keywords::PathRoot.name() } } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 9a0ceddcf1b4a..eb11d40440b19 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1622,7 +1622,7 @@ impl<'a> State<'a> { if i > 0 { self.s.word("::")? } - if segment.ident.name != keywords::CrateRoot.name() && + if segment.ident.name != keywords::PathRoot.name() && segment.ident.name != keywords::DollarCrate.name() { self.print_ident(segment.ident)?; segment.with_generic_args(|generic_args| { @@ -1636,7 +1636,7 @@ impl<'a> State<'a> { } pub fn print_path_segment(&mut self, segment: &hir::PathSegment) -> io::Result<()> { - if segment.ident.name != keywords::CrateRoot.name() && + if segment.ident.name != keywords::PathRoot.name() && segment.ident.name != keywords::DollarCrate.name() { self.print_ident(segment.ident)?; segment.with_generic_args(|generic_args| { @@ -1664,7 +1664,7 @@ impl<'a> State<'a> { if i > 0 { self.s.word("::")? } - if segment.ident.name != keywords::CrateRoot.name() && + if segment.ident.name != keywords::PathRoot.name() && segment.ident.name != keywords::DollarCrate.name() { self.print_ident(segment.ident)?; segment.with_generic_args(|generic_args| { diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 54a0192d2e8a5..b846a1c4930fb 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1575,7 +1575,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { let sp = ident.span; let var = self.variable(hir_id, sp); // Ignore unused self. - if ident.name != keywords::SelfValue.name() { + if ident.name != keywords::SelfLower.name() { if !self.warn_about_unused(sp, hir_id, entry_ln, var) { if self.live_on_entry(entry_ln, var).is_none() { self.report_dead_assign(hir_id, sp, var, true); diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 42a4de1682c39..7862a72433ae1 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2710,7 +2710,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { #[inline] pub fn mk_self_type(self) -> Ty<'tcx> { - self.mk_ty_param(0, keywords::SelfType.name().as_interned_str()) + self.mk_ty_param(0, keywords::SelfUpper.name().as_interned_str()) } pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> Kind<'tcx> { diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 1416cb17feaed..1a52717ef0588 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -1020,7 +1020,7 @@ impl<'a, 'gcx, 'tcx> ParamTy { } pub fn for_self() -> ParamTy { - ParamTy::new(0, keywords::SelfType.name().as_interned_str()) + ParamTy::new(0, keywords::SelfUpper.name().as_interned_str()) } pub fn for_def(def: &ty::GenericParamDef) -> ParamTy { @@ -1035,7 +1035,7 @@ impl<'a, 'gcx, 'tcx> ParamTy { // FIXME(#50125): Ignoring `Self` with `idx != 0` might lead to weird behavior elsewhere, // but this should only be possible when using `-Z continue-parse-after-error` like // `compile-fail/issue-36638.rs`. - self.name == keywords::SelfType.name().as_str() && self.idx == 0 + self.name == keywords::SelfUpper.name().as_str() && self.idx == 0 } } diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index fab618d9c8ec8..c7eb06cbe0053 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -473,7 +473,7 @@ impl UnusedImportBraces { match items[0].0.kind { ast::UseTreeKind::Simple(rename, ..) => { let orig_ident = items[0].0.prefix.segments.last().unwrap().ident; - if orig_ident.name == keywords::SelfValue.name() { + if orig_ident.name == keywords::SelfLower.name() { return; } node_ident = rename.unwrap_or(orig_ident); diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index 7afe2c67adc9b..4bcabfef4fd7f 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -263,7 +263,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { // Deliberately fall into this case for all implicit self types, // so that we don't fall in to the next case with them. *kind == mir::ImplicitSelfKind::MutRef - } else if Some(keywords::SelfValue.name()) == local_decl.name { + } else if Some(keywords::SelfLower.name()) == local_decl.name { // Otherwise, check if the name is the self kewyord - in which case // we have an explicit self. Do the same thing in this case and check // for a `self: &mut Self` to suggest removing the `&mut`. diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 0fa41cb484fc9..68e98320f6f4a 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -145,7 +145,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } _ => None, }.map(|ctxt| Segment::from_ident(Ident::new( - keywords::CrateRoot.name(), use_tree.prefix.span.shrink_to_lo().with_ctxt(ctxt) + keywords::PathRoot.name(), use_tree.prefix.span.shrink_to_lo().with_ctxt(ctxt) ))); let prefix = crate_root.into_iter().chain(prefix_iter).collect::<Vec<_>>(); @@ -153,7 +153,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { let empty_for_self = |prefix: &[Segment]| { prefix.is_empty() || - prefix.len() == 1 && prefix[0].ident.name == keywords::CrateRoot.name() + prefix.len() == 1 && prefix[0].ident.name == keywords::PathRoot.name() }; match use_tree.kind { ast::UseTreeKind::Simple(rename, ..) => { @@ -164,7 +164,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { if nested { // Correctly handle `self` - if source.ident.name == keywords::SelfValue.name() { + if source.ident.name == keywords::SelfLower.name() { type_ns_only = true; if empty_for_self(&module_path) { @@ -185,7 +185,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } } else { // Disallow `self` - if source.ident.name == keywords::SelfValue.name() { + if source.ident.name == keywords::SelfLower.name() { resolve_error(self, use_tree.span, ResolutionError::SelfImportsOnlyAllowedWithin); @@ -205,7 +205,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { // `crate_name` should not be interpreted as relative. module_path.push(Segment { ident: Ident { - name: keywords::CrateRoot.name(), + name: keywords::PathRoot.name(), span: source.ident.span, }, id: Some(self.session.next_node_id()), @@ -270,7 +270,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { // Ensure there is at most one `self` in the list let self_spans = items.iter().filter_map(|&(ref use_tree, _)| { if let ast::UseTreeKind::Simple(..) = use_tree.kind { - if use_tree.ident().name == keywords::SelfValue.name() { + if use_tree.ident().name == keywords::SelfLower.name() { return Some(use_tree.span); } } @@ -305,7 +305,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { let new_span = prefix[prefix.len() - 1].ident.span; let tree = ast::UseTree { prefix: ast::Path::from_ident( - Ident::new(keywords::SelfValue.name(), new_span) + Ident::new(keywords::SelfLower.name(), new_span) ), kind: ast::UseTreeKind::Simple( Some(Ident::new(keywords::Underscore.name().gensymed(), new_span)), @@ -344,13 +344,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } ItemKind::ExternCrate(orig_name) => { - let module = if orig_name.is_none() && ident.name == keywords::SelfValue.name() { + let module = if orig_name.is_none() && ident.name == keywords::SelfLower.name() { self.session .struct_span_err(item.span, "`extern crate self;` requires renaming") .span_suggestion(item.span, "try", "extern crate self as name;".into()) .emit(); return; - } else if orig_name == Some(keywords::SelfValue.name()) { + } else if orig_name == Some(keywords::SelfLower.name()) { if !self.session.features_untracked().extern_crate_self { emit_feature_err(&self.session.parse_sess, "extern_crate_self", item.span, GateIssue::Language, "`extern crate self` is unstable"); @@ -783,7 +783,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { "an `extern crate` loading macros must be at the crate root"); } if let ItemKind::ExternCrate(Some(orig_name)) = item.node { - if orig_name == keywords::SelfValue.name() { + if orig_name == keywords::SelfLower.name() { self.session.span_err(attr.span, "`macro_use` is not supported on `extern crate self`"); } diff --git a/src/librustc_resolve/error_reporting.rs b/src/librustc_resolve/error_reporting.rs index e2a6303f57944..23edaf1243812 100644 --- a/src/librustc_resolve/error_reporting.rs +++ b/src/librustc_resolve/error_reporting.rs @@ -30,7 +30,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { match (path.get(0), path.get(1)) { // `{{root}}::ident::...` on both editions. // On 2015 `{{root}}` is usually added implicitly. - (Some(fst), Some(snd)) if fst.ident.name == keywords::CrateRoot.name() && + (Some(fst), Some(snd)) if fst.ident.name == keywords::PathRoot.name() && !snd.ident.is_path_segment_keyword() => {} // `ident::...` on 2018 (Some(fst), _) if fst.ident.span.rust_2018() && @@ -61,7 +61,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { parent_scope: &ParentScope<'b>, ) -> Option<(Vec<Segment>, Option<String>)> { // Replace first ident with `self` and check if that is valid. - path[0].ident.name = keywords::SelfValue.name(); + path[0].ident.name = keywords::SelfLower.name(); let result = self.resolve_path(&path, None, parent_scope, false, span, CrateLint::No); debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result); if let PathResult::Module(..) = result { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index fdac1e3b81652..9ea39aea86867 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -769,7 +769,7 @@ impl<'a, 'tcx, 'cl> Visitor<'tcx> for Resolver<'a, 'cl> { self.smart_resolve_path(ty.id, qself.as_ref(), path, PathSource::Type); } TyKind::ImplicitSelf => { - let self_ty = keywords::SelfType.ident(); + let self_ty = keywords::SelfUpper.ident(); let def = self.resolve_ident_in_lexical_scope(self_ty, TypeNS, Some(ty.id), ty.span) .map_or(Def::Err, |d| d.def()); self.record_def(ty.id, PathResolution::new(def)); @@ -1679,7 +1679,7 @@ impl<'a, 'cl> hir::lowering::Resolver for Resolver<'a, 'cl> { components: &[&str], is_value: bool ) -> hir::Path { - let segments = iter::once(keywords::CrateRoot.ident()) + let segments = iter::once(keywords::PathRoot.ident()) .chain( crate_root.into_iter() .chain(components.iter().cloned()) @@ -1721,7 +1721,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { let path = if path_str.starts_with("::") { ast::Path { span, - segments: iter::once(keywords::CrateRoot.ident()) + segments: iter::once(keywords::PathRoot.ident()) .chain({ path_str.split("::").skip(1).map(Ident::from_str) }) @@ -2036,7 +2036,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { let record_used = record_used_id.is_some(); assert!(ns == TypeNS || ns == ValueNS); if ns == TypeNS { - ident.span = if ident.name == keywords::SelfType.name() { + ident.span = if ident.name == keywords::SelfUpper.name() { // FIXME(jseyfried) improve `Self` hygiene ident.span.with_ctxt(SyntaxContext::empty()) } else { @@ -2649,7 +2649,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { let mut self_type_rib = Rib::new(NormalRibKind); // plain insert (no renaming, types are not currently hygienic....) - self_type_rib.bindings.insert(keywords::SelfType.ident(), self_def); + self_type_rib.bindings.insert(keywords::SelfUpper.ident(), self_def); self.ribs[TypeNS].push(self_type_rib); f(self); self.ribs[TypeNS].pop(); @@ -2660,7 +2660,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { { let self_def = Def::SelfCtor(impl_id); let mut self_type_rib = Rib::new(NormalRibKind); - self_type_rib.bindings.insert(keywords::SelfType.ident(), self_def); + self_type_rib.bindings.insert(keywords::SelfUpper.ident(), self_def); self.ribs[ValueNS].push(self_type_rib); f(self); self.ribs[ValueNS].pop(); @@ -3146,7 +3146,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { let item_span = path.last().unwrap().ident.span; let (mod_prefix, mod_str) = if path.len() == 1 { (String::new(), "this scope".to_string()) - } else if path.len() == 2 && path[0].ident.name == keywords::CrateRoot.name() { + } else if path.len() == 2 && path[0].ident.name == keywords::PathRoot.name() { (String::new(), "the crate root".to_string()) } else { let mod_path = &path[..path.len() - 1]; @@ -3515,13 +3515,13 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { } fn self_type_is_available(&mut self, span: Span) -> bool { - let binding = self.resolve_ident_in_lexical_scope(keywords::SelfType.ident(), + let binding = self.resolve_ident_in_lexical_scope(keywords::SelfUpper.ident(), TypeNS, None, span); if let Some(LexicalScopeBinding::Def(def)) = binding { def != Def::Err } else { false } } fn self_value_is_available(&mut self, self_span: Span, path_span: Span) -> bool { - let ident = Ident::new(keywords::SelfValue.name(), self_span); + let ident = Ident::new(keywords::SelfLower.name(), self_span); let binding = self.resolve_ident_in_lexical_scope(ident, ValueNS, None, path_span); if let Some(LexicalScopeBinding::Def(def)) = binding { def != Def::Err } else { false } } @@ -3673,7 +3673,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { }; if path.len() > 1 && !global_by_default && result.base_def() != Def::Err && - path[0].ident.name != keywords::CrateRoot.name() && + path[0].ident.name != keywords::PathRoot.name() && path[0].ident.name != keywords::DollarCrate.name() { let unqualified_result = { match self.resolve_path_without_parent_scope( @@ -3755,7 +3755,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { let name = ident.name; allow_super &= ns == TypeNS && - (name == keywords::SelfValue.name() || + (name == keywords::SelfLower.name() || name == keywords::Super.name()); if ns == TypeNS { @@ -3779,24 +3779,24 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { return PathResult::Failed(ident.span, msg, false); } if i == 0 { - if name == keywords::SelfValue.name() { + if name == keywords::SelfLower.name() { let mut ctxt = ident.span.ctxt().modern(); module = Some(ModuleOrUniformRoot::Module( self.resolve_self(&mut ctxt, self.current_module))); continue; } if name == keywords::Extern.name() || - name == keywords::CrateRoot.name() && ident.span.rust_2018() { + name == keywords::PathRoot.name() && ident.span.rust_2018() { module = Some(ModuleOrUniformRoot::ExternPrelude); continue; } - if name == keywords::CrateRoot.name() && + if name == keywords::PathRoot.name() && ident.span.rust_2015() && self.session.rust_2018() { // `::a::b` from 2015 macro on 2018 global edition module = Some(ModuleOrUniformRoot::CrateRootAndExternPrelude); continue; } - if name == keywords::CrateRoot.name() || + if name == keywords::PathRoot.name() || name == keywords::Crate.name() || name == keywords::DollarCrate.name() { // `::a::b`, `crate::a::b` or `$crate::a::b` @@ -3809,12 +3809,12 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { // Report special messages for path segment keywords in wrong positions. if ident.is_path_segment_keyword() && i != 0 { - let name_str = if name == keywords::CrateRoot.name() { + let name_str = if name == keywords::PathRoot.name() { "crate root".to_string() } else { format!("`{}`", name) }; - let msg = if i == 1 && path[0].ident.name == keywords::CrateRoot.name() { + let msg = if i == 1 && path[0].ident.name == keywords::PathRoot.name() { format!("global paths cannot start with {}", name_str) } else { format!("{} in paths can only be used in start position", name_str) @@ -3944,7 +3944,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { // We're only interested in `use` paths which should start with // `{{root}}` or `extern` currently. - if first_name != keywords::Extern.name() && first_name != keywords::CrateRoot.name() { + if first_name != keywords::Extern.name() && first_name != keywords::PathRoot.name() { return } @@ -3953,7 +3953,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { Some(Segment { ident, .. }) if ident.name == keywords::Crate.name() => return, // Otherwise go below to see if it's an extern crate Some(_) => {} - // If the path has length one (and it's `CrateRoot` most likely) + // If the path has length one (and it's `PathRoot` most likely) // then we don't know whether we're gonna be importing a crate or an // item in our crate. Defer this lint to elsewhere None => return, @@ -4740,7 +4740,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { } else { let ctxt = ident.span.ctxt(); Some(Segment::from_ident(Ident::new( - keywords::CrateRoot.name(), path.span.shrink_to_lo().with_ctxt(ctxt) + keywords::PathRoot.name(), path.span.shrink_to_lo().with_ctxt(ctxt) ))) }; @@ -5090,17 +5090,17 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { } fn is_self_type(path: &[Segment], namespace: Namespace) -> bool { - namespace == TypeNS && path.len() == 1 && path[0].ident.name == keywords::SelfType.name() + namespace == TypeNS && path.len() == 1 && path[0].ident.name == keywords::SelfUpper.name() } fn is_self_value(path: &[Segment], namespace: Namespace) -> bool { - namespace == ValueNS && path.len() == 1 && path[0].ident.name == keywords::SelfValue.name() + namespace == ValueNS && path.len() == 1 && path[0].ident.name == keywords::SelfLower.name() } fn names_to_string(idents: &[Ident]) -> String { let mut result = String::new(); for (i, ident) in idents.iter() - .filter(|ident| ident.name != keywords::CrateRoot.name()) + .filter(|ident| ident.name != keywords::PathRoot.name()) .enumerate() { if i > 0 { result.push_str("::"); diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 5db3efee9f6a1..65a9652cd237c 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -167,7 +167,7 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> { if path.segments[0].ident.name == keywords::DollarCrate.name() { let module = self.0.resolve_crate_root(path.segments[0].ident); - path.segments[0].ident.name = keywords::CrateRoot.name(); + path.segments[0].ident.name = keywords::PathRoot.name(); if !module.is_local() { let span = path.segments[0].ident.span; path.segments.insert(1, match module.kind { @@ -674,7 +674,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { _ => Err(Determinacy::Determined), } WhereToResolve::CrateRoot => { - let root_ident = Ident::new(keywords::CrateRoot.name(), orig_ident.span); + let root_ident = Ident::new(keywords::PathRoot.name(), orig_ident.span); let root_module = self.resolve_crate_root(root_ident); let binding = self.resolve_ident_in_module_ext( ModuleOrUniformRoot::Module(root_module), @@ -960,7 +960,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { break 'ok; } if rust_2015 { - let root_ident = Ident::new(keywords::CrateRoot.name(), orig_ident.span); + let root_ident = Ident::new(keywords::PathRoot.name(), orig_ident.span); let root_module = self.resolve_crate_root(root_ident); if self.resolve_ident_in_module_ext(ModuleOrUniformRoot::Module(root_module), orig_ident, ns, None, false, path_span) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index e7cd32f4e810f..865aace8aabb5 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -198,7 +198,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { .to_name_binding(self.arenas); return Ok(binding); } else if ident.name == keywords::Super.name() || - ident.name == keywords::SelfValue.name() { + ident.name == keywords::SelfLower.name() { // FIXME: Implement these with renaming requirements so that e.g. // `use super;` doesn't work, but `use super as name;` does. // Fall through here to get an error from `early_resolve_...`. @@ -1263,8 +1263,8 @@ fn import_path_to_string(names: &[Ident], subclass: &ImportDirectiveSubclass, span: Span) -> String { let pos = names.iter() - .position(|p| span == p.span && p.name != keywords::CrateRoot.name()); - let global = !names.is_empty() && names[0].name == keywords::CrateRoot.name(); + .position(|p| span == p.span && p.name != keywords::PathRoot.name()); + let global = !names.is_empty() && names[0].name == keywords::PathRoot.name(); if let Some(pos) = pos { let names = if global { &names[1..pos + 1] } else { &names[..pos + 1] }; names_to_string(names) diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index a1bb0b53f1fce..5682a73bed573 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -938,7 +938,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty opt_self = Some(ty::GenericParamDef { index: 0, - name: keywords::SelfType.name().as_interned_str(), + name: keywords::SelfUpper.name().as_interned_str(), def_id: tcx.hir.local_def_id(param_id), pure_wrt_drop: false, kind: ty::GenericParamDefKind::Type { @@ -1007,7 +1007,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty synthetic, .. } => { - if param.name.ident().name == keywords::SelfType.name() { + if param.name.ident().name == keywords::SelfUpper.name() { span_bug!( param.span, "`Self` should not be the name of a regular parameter" diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index fd8f70b19e7ec..c68ffbab05ad4 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1575,7 +1575,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, let stripped_typarams = gens.params.iter().filter_map(|param| match param.kind { ty::GenericParamDefKind::Lifetime => None, ty::GenericParamDefKind::Type { .. } => { - if param.name == keywords::SelfType.name().as_str() { + if param.name == keywords::SelfUpper.name().as_str() { assert_eq!(param.index, 0); return None; } @@ -3174,7 +3174,7 @@ fn qpath_to_string(p: &hir::QPath) -> String { if i > 0 { s.push_str("::"); } - if seg.ident.name != keywords::CrateRoot.name() { + if seg.ident.name != keywords::PathRoot.name() { s.push_str(&*seg.ident.as_str()); } } @@ -3726,7 +3726,7 @@ fn resolve_type(cx: &DocContext, hir::Float(float_ty) => return Primitive(float_ty.into()), }, Def::SelfTy(..) if path.segments.len() == 1 => { - return Generic(keywords::SelfType.name().to_string()); + return Generic(keywords::SelfUpper.name().to_string()); } Def::TyParam(..) if path.segments.len() == 1 => { return Generic(format!("{:#}", path)); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 227017a9073fe..b681ed454e2c3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -73,7 +73,7 @@ impl fmt::Debug for Lifetime { pub struct Path { pub span: Span, /// The segments in the path: the things separated by `::`. - /// Global paths begin with `keywords::CrateRoot`. + /// Global paths begin with `keywords::PathRoot`. pub segments: Vec<PathSegment>, } @@ -117,7 +117,7 @@ impl Path { } pub fn is_global(&self) -> bool { - !self.segments.is_empty() && self.segments[0].ident.name == keywords::CrateRoot.name() + !self.segments.is_empty() && self.segments[0].ident.name == keywords::PathRoot.name() } } @@ -145,7 +145,7 @@ impl PathSegment { PathSegment { ident, id: DUMMY_NODE_ID, args: None } } pub fn crate_root(span: Span) -> Self { - PathSegment::from_ident(Ident::new(keywords::CrateRoot.name(), span)) + PathSegment::from_ident(Ident::new(keywords::PathRoot.name(), span)) } } @@ -1688,7 +1688,7 @@ pub type ExplicitSelf = Spanned<SelfKind>; impl Arg { pub fn to_self(&self) -> Option<ExplicitSelf> { if let PatKind::Ident(BindingMode::ByValue(mutbl), ident, _) = self.pat.node { - if ident.name == keywords::SelfValue.name() { + if ident.name == keywords::SelfLower.name() { return match self.ty.node { TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))), TyKind::Rptr(lt, MutTy { ref ty, mutbl }) if ty.node.is_implicit_self() => { @@ -1706,7 +1706,7 @@ impl Arg { pub fn is_self(&self) -> bool { if let PatKind::Ident(_, ident, _) = self.pat.node { - ident.name == keywords::SelfValue.name() + ident.name == keywords::SelfLower.name() } else { false } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index cacec867cf198..63e9744d770e1 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -625,7 +625,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr_path(self.path_ident(span, id)) } fn expr_self(&self, span: Span) -> P<ast::Expr> { - self.expr_ident(span, keywords::SelfValue.ident()) + self.expr_ident(span, keywords::SelfLower.ident()) } fn expr_binary(&self, sp: Span, op: ast::BinOpKind, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 68a96293891a0..67f3dc1bb5272 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -204,7 +204,7 @@ fn macro_bang_format(path: &ast::Path) -> ExpnFormat { path_str.push_str("::"); } - if segment.ident.name != keywords::CrateRoot.name() && + if segment.ident.name != keywords::PathRoot.name() && segment.ident.name != keywords::DollarCrate.name() { path_str.push_str(&segment.ident.as_str()) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1cd5006f3304c..56d42e6e9646c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5508,7 +5508,7 @@ impl<'a> Parser<'a> { _ => unreachable!() }; let isolated_self = |this: &mut Self, n| { - this.look_ahead(n, |t| t.is_keyword(keywords::SelfValue)) && + this.look_ahead(n, |t| t.is_keyword(keywords::SelfLower)) && this.look_ahead(n + 1, |t| t != &token::ModSep) }; @@ -6330,7 +6330,7 @@ impl<'a> Parser<'a> { return Ok(vis) } else if self.look_ahead(2, |t| t == &token::CloseDelim(token::Paren)) && self.look_ahead(1, |t| t.is_keyword(keywords::Super) || - t.is_keyword(keywords::SelfValue)) + t.is_keyword(keywords::SelfLower)) { // `pub(self)` or `pub(super)` self.bump(); // `(` @@ -6782,7 +6782,7 @@ impl<'a> Parser<'a> { let error_msg = "crate name using dashes are not valid in `extern crate` statements"; let suggestion_msg = "if the original crate name uses dashes you need to use underscores \ in the code"; - let mut ident = if self.token.is_keyword(keywords::SelfValue) { + let mut ident = if self.token.is_keyword(keywords::SelfLower) { self.parse_path_segment_ident() } else { self.parse_ident() diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index a9f08fdd41126..e50f28897dd12 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -724,7 +724,7 @@ pub trait PrintState<'a> { if i > 0 { self.writer().word("::")? } - if segment.ident.name != keywords::CrateRoot.name() && + if segment.ident.name != keywords::PathRoot.name() && segment.ident.name != keywords::DollarCrate.name() { self.writer().word(segment.ident.as_str().get())?; @@ -2463,7 +2463,7 @@ impl<'a> State<'a> { colons_before_params: bool) -> io::Result<()> { - if segment.ident.name != keywords::CrateRoot.name() && + if segment.ident.name != keywords::PathRoot.name() && segment.ident.name != keywords::DollarCrate.name() { self.print_ident(segment.ident)?; if let Some(ref args) = segment.args { diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 1210f331b285b..5c994558ab06f 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -112,7 +112,7 @@ pub fn maybe_inject_crates_ref( vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited), node: ast::ItemKind::Use(P(ast::UseTree { prefix: ast::Path { - segments: iter::once(keywords::CrateRoot.ident()) + segments: iter::once(keywords::PathRoot.ident()) .chain( [name, "prelude", "v1"].iter().cloned() .map(ast::Ident::from_str) diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index ec935b3e72f23..b9e0933331cb8 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -140,7 +140,7 @@ fn cs_clone_shallow(name: &str, let mut stmts = Vec::new(); if is_union { // let _: AssertParamIsCopy<Self>; - let self_ty = cx.ty_path(cx.path_ident(trait_span, keywords::SelfType.ident())); + let self_ty = cx.ty_path(cx.path_ident(trait_span, keywords::SelfUpper.ident())); assert_ty_bounds(cx, &mut stmts, self_ty, trait_span, "AssertParamIsCopy"); } else { match *substr.fields { diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index a5b12ce4c4d83..c0c11f64bc3b8 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -938,7 +938,7 @@ impl<'a> MethodDef<'a> { let args = { let self_args = explicit_self.map(|explicit_self| { ast::Arg::from_self(explicit_self, - keywords::SelfValue.ident().with_span_pos(trait_.span)) + keywords::SelfLower.ident().with_span_pos(trait_.span)) }); let nonself_args = arg_types.into_iter() .map(|(name, ty)| cx.arg(trait_.span, name, ty)); diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 8ccd123afdcea..0b8ef60f363e3 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -349,7 +349,7 @@ declare_keywords! { // Special reserved identifiers used internally for elided lifetimes, // unnamed method parameters, crate root module, error recovery etc. (0, Invalid, "") - (1, CrateRoot, "{{root}}") + (1, PathRoot, "{{root}}") (2, DollarCrate, "$crate") (3, Underscore, "_") @@ -378,8 +378,8 @@ declare_keywords! { (25, Pub, "pub") (26, Ref, "ref") (27, Return, "return") - (28, SelfValue, "self") - (29, SelfType, "Self") + (28, SelfLower, "self") + (29, SelfUpper, "Self") (30, Static, "static") (31, Struct, "struct") (32, Super, "super") @@ -462,11 +462,11 @@ impl Ident { /// A keyword or reserved identifier that can be used as a path segment. pub fn is_path_segment_keyword(self) -> bool { self.name == keywords::Super.name() || - self.name == keywords::SelfValue.name() || - self.name == keywords::SelfType.name() || + self.name == keywords::SelfLower.name() || + self.name == keywords::SelfUpper.name() || self.name == keywords::Extern.name() || self.name == keywords::Crate.name() || - self.name == keywords::CrateRoot.name() || + self.name == keywords::PathRoot.name() || self.name == keywords::DollarCrate.name() } From d415844f5e82944dc1907ff4b66f9f74fcbaf6ff Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Date: Sun, 2 Dec 2018 03:59:25 +0300 Subject: [PATCH 15/28] syntax: Remove `#[non_exhaustive]` from `Edition` `Edition` is not a public API, we want users to break when a new edition is added --- src/librustc/ich/impls_syntax.rs | 12 ++++-------- src/librustc/ty/context.rs | 6 ------ src/libsyntax/ext/tt/quoted.rs | 1 - src/libsyntax_pos/edition.rs | 1 - src/libsyntax_pos/hygiene.rs | 4 ++-- 5 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index b629fb820b34d..b9ed0fcd4f38f 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -134,14 +134,10 @@ impl_stable_hash_for!(struct ::syntax::attr::Stability { const_stability }); -impl<'a> HashStable<StableHashingContext<'a>> -for ::syntax::edition::Edition { - fn hash_stable<W: StableHasherResult>(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher<W>) { - mem::discriminant(self).hash_stable(hcx, hasher); - } -} +impl_stable_hash_for!(enum ::syntax::edition::Edition { + Edition2015, + Edition2018, +}); impl<'a> HashStable<StableHashingContext<'a>> for ::syntax::attr::StabilityLevel { diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 7862a72433ae1..f041192413107 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1493,12 +1493,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { BorrowckMode::Ast => match self.sess.edition() { Edition::Edition2015 => BorrowckMode::Ast, Edition::Edition2018 => BorrowckMode::Migrate, - - // For now, future editions mean Migrate. (But it - // would make a lot of sense for it to be changed to - // `BorrowckMode::Mir`, depending on how we plan to - // time the forcing of full migration to NLL.) - _ => BorrowckMode::Migrate, }, } } diff --git a/src/libsyntax/ext/tt/quoted.rs b/src/libsyntax/ext/tt/quoted.rs index edc431be3694b..a7415e845cae3 100644 --- a/src/libsyntax/ext/tt/quoted.rs +++ b/src/libsyntax/ext/tt/quoted.rs @@ -444,7 +444,6 @@ where macro_node_id, ), Edition::Edition2018 => parse_sep_and_kleene_op_2018(input, span, sess, features, attrs), - _ => unimplemented!(), } } diff --git a/src/libsyntax_pos/edition.rs b/src/libsyntax_pos/edition.rs index 5819cd7f480a0..d57078ce91407 100644 --- a/src/libsyntax_pos/edition.rs +++ b/src/libsyntax_pos/edition.rs @@ -13,7 +13,6 @@ use std::str::FromStr; /// The edition of the compiler (RFC 2052) #[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, RustcEncodable, RustcDecodable, Eq)] -#[non_exhaustive] pub enum Edition { // editions must be kept in order, oldest to newest diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index bc52a3e1c7c29..074687fc726e8 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -17,7 +17,7 @@ use GLOBALS; use Span; -use edition::Edition; +use edition::{Edition, DEFAULT_EDITION}; use symbol::Symbol; use serialize::{Encodable, Decodable, Encoder, Decoder}; @@ -217,7 +217,7 @@ impl HygieneData { opaque_and_semitransparent: SyntaxContext(0), }], markings: FxHashMap::default(), - default_edition: Edition::Edition2015, + default_edition: DEFAULT_EDITION, } } From 3f253f53946398199277cfb6e3af7c05b5ed3b4f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez <guillaume1.gomez@gmail.com> Date: Mon, 3 Dec 2018 23:04:59 +0100 Subject: [PATCH 16/28] Improve filter test --- src/test/rustdoc-js/filter-crate.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/rustdoc-js/filter-crate.js b/src/test/rustdoc-js/filter-crate.js index 69c959a6ef21c..97ecc607f4764 100644 --- a/src/test/rustdoc-js/filter-crate.js +++ b/src/test/rustdoc-js/filter-crate.js @@ -8,13 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// should-fail +// exact-check -const QUERY = 'string'; +const QUERY = 'hashmap'; const FILTER_CRATE = 'core'; const EXPECTED = { 'others': [ - { 'path': 'std::collections', 'name': 'VecDeque' }, ], }; From d08f7dcdca861f46bedf8a37af135a7a46633540 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Date: Sun, 2 Dec 2018 15:15:42 +0300 Subject: [PATCH 17/28] Address review comments --- src/libsyntax/ast.rs | 13 +------------ src/libsyntax/ext/build.rs | 16 +++++++--------- src/libsyntax/parse/parser.rs | 4 ++-- src/libsyntax_pos/symbol.rs | 8 ++++---- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b681ed454e2c3..872257118714e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -105,17 +105,6 @@ impl Path { } } - // Make a "crate root" segment for this path unless it already has it - // or starts with something like `self`/`super`/`$crate`/etc. - pub fn make_root(&self) -> Option<PathSegment> { - if let Some(ident) = self.segments.get(0).map(|seg| seg.ident) { - if ident.is_path_segment_keyword() { - return None; - } - } - Some(PathSegment::crate_root(self.span.shrink_to_lo())) - } - pub fn is_global(&self) -> bool { !self.segments.is_empty() && self.segments[0].ident.name == keywords::PathRoot.name() } @@ -144,7 +133,7 @@ impl PathSegment { pub fn from_ident(ident: Ident) -> Self { PathSegment { ident, id: DUMMY_NODE_ID, args: None } } - pub fn crate_root(span: Span) -> Self { + pub fn path_root(span: Span) -> Self { PathSegment::from_ident(Ident::new(keywords::PathRoot.name(), span)) } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 63e9744d770e1..5770f6bb8a28c 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -318,9 +318,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> { args: Vec<ast::GenericArg>, bindings: Vec<ast::TypeBinding> ) -> ast::Path { + assert!(!idents.is_empty()); + let add_root = global && !idents[0].is_path_segment_keyword(); + let mut segments = Vec::with_capacity(idents.len() + add_root as usize); + if add_root { + segments.push(ast::PathSegment::path_root(span)); + } let last_ident = idents.pop().unwrap(); - let mut segments: Vec<ast::PathSegment> = vec![]; - segments.extend(idents.into_iter().map(|ident| { ast::PathSegment::from_ident(ident.with_span_pos(span)) })); @@ -334,13 +338,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, args, }); - let mut path = ast::Path { span, segments }; - if global { - if let Some(seg) = path.make_root() { - path.segments.insert(0, seg); - } - } - path + ast::Path { span, segments } } /// Constructs a qualified path. diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 56d42e6e9646c..8165c0e44c413 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2082,7 +2082,7 @@ impl<'a> Parser<'a> { let mut segments = Vec::new(); let mod_sep_ctxt = self.span.ctxt(); if self.eat(&token::ModSep) { - segments.push(PathSegment::crate_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt))); + segments.push(PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt))); } self.parse_path_segments(&mut segments, style, enable_warning)?; @@ -7685,7 +7685,7 @@ impl<'a> Parser<'a> { let mod_sep_ctxt = self.span.ctxt(); if self.eat(&token::ModSep) { prefix.segments.push( - PathSegment::crate_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt)) + PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt)) ); } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 0b8ef60f363e3..4f2eb74c07227 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -353,7 +353,7 @@ declare_keywords! { (2, DollarCrate, "$crate") (3, Underscore, "_") - // Keywords used in the language. + // Keywords that are used in stable Rust. (4, As, "as") (5, Box, "box") (6, Break, "break") @@ -391,7 +391,7 @@ declare_keywords! { (38, Where, "where") (39, While, "while") - // Keywords reserved for future use. + // Keywords that are used in unstable Rust or reserved for future use. (40, Abstract, "abstract") (41, Become, "become") (42, Do, "do") @@ -404,10 +404,10 @@ declare_keywords! { (49, Virtual, "virtual") (50, Yield, "yield") - // Edition-specific keywords used in the language. + // Edition-specific keywords that are used in stable Rust. (51, Dyn, "dyn") // >= 2018 Edition only - // Edition-specific keywords reserved for future use. + // Edition-specific keywords that are used in unstable Rust or reserved for future use. (52, Async, "async") // >= 2018 Edition only (53, Try, "try") // >= 2018 Edition only From 11fb023d4f8d9ab5c4063b767a26cab87c53653f Mon Sep 17 00:00:00 2001 From: Georg Semmler <georg_semmler_05@web.de> Date: Tue, 4 Dec 2018 10:23:13 +0100 Subject: [PATCH 18/28] Allow renaming macro --- src/librustdoc/visit_ast.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index b44b1d9e0ba19..31adb2e0369c9 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -100,7 +100,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> { None); // attach the crate's exported macros to the top-level module: let macro_exports: Vec<_> = - krate.exported_macros.iter().map(|def| self.visit_local_macro(def)).collect(); + krate.exported_macros.iter().map(|def| self.visit_local_macro(def, None)).collect(); self.module.macros.extend(macro_exports); self.module.is_crate = true; @@ -377,7 +377,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> { true } Node::MacroDef(def) if !glob => { - om.macros.push(self.visit_local_macro(def)); + om.macros.push(self.visit_local_macro(def, renamed)); true } _ => false, @@ -597,7 +597,11 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> { } // convert each exported_macro into a doc item - fn visit_local_macro(&self, def: &hir::MacroDef) -> Macro { + fn visit_local_macro( + &self, + def: &hir::MacroDef, + renamed: Option<ast::Name> + ) -> Macro { debug!("visit_local_macro: {}", def.name); let tts = def.body.trees().collect::<Vec<_>>(); // Extract the spans of all matchers. They represent the "interface" of the macro. @@ -606,7 +610,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> { Macro { def_id: self.cx.tcx.hir.local_def_id(def.id), attrs: def.attrs.clone(), - name: def.name, + name: renamed.unwrap_or(def.name), whence: def.span, matchers, stab: self.stability(def.id), From 9d4e17ae1adb4793071836699ae050c4af5d67f9 Mon Sep 17 00:00:00 2001 From: Georg Semmler <georg_semmler_05@web.de> Date: Tue, 4 Dec 2018 10:23:30 +0100 Subject: [PATCH 19/28] Remove support for proc macro doc inlining --- src/librustdoc/clean/inline.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 464b6ea4fbe41..49cecd5b04bbc 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -106,23 +106,13 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa clean::ConstantItem(build_const(cx, did)) } // FIXME: proc-macros don't propagate attributes or spans across crates, so they look empty - Def::Macro(did, MacroKind::Derive) | Def::Macro(did, MacroKind::Bang) => { let mac = build_macro(cx, did, name); - debug!("try_inline: {:?}", mac); - - match build_macro(cx, did, name) { - clean::MacroItem(..) => { - record_extern_fqn(cx, did, clean::TypeKind::Macro); - mac - } - clean::ProcMacroItem(..) => { - record_extern_fqn(cx, did, clean::TypeKind::Derive); - mac - } - _ => { - return None; - } + if let clean::MacroItem(..) = mac { + record_extern_fqn(cx, did, clean::TypeKind::Macro); + mac + } else { + return None; } } _ => return None, From 956b03f7db8b6b6b73bb4b2b6e0cbb1016e08f8a Mon Sep 17 00:00:00 2001 From: Georg Semmler <georg_semmler_05@web.de> Date: Tue, 4 Dec 2018 10:24:17 +0100 Subject: [PATCH 20/28] Add a test case for inlining the docs of a macro reexport --- .../rustdoc/inline_local/macro_by_example.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/rustdoc/inline_local/macro_by_example.rs diff --git a/src/test/rustdoc/inline_local/macro_by_example.rs b/src/test/rustdoc/inline_local/macro_by_example.rs new file mode 100644 index 0000000000000..93d55ec0798ac --- /dev/null +++ b/src/test/rustdoc/inline_local/macro_by_example.rs @@ -0,0 +1,28 @@ +// Copyright 2018 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +/// docs for foo +#[deprecated(since = "1.2.3", note = "text")] +#[macro_export] +macro_rules! foo { + ($($tt:tt)*) => {} +} + +// @has macro_by_example/macros/index.html +pub mod macros { + // @!has - 'pub use foo as bar;' + // @has macro_by_example/macros/macro.bar.html + // @has - '//*[@class="docblock"]' 'docs for foo' + // @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.2.3: text' + // @has - '//a/@href' 'macro_by_example.rs.html#15-17' + #[doc(inline)] + pub use foo as bar; +} From d0c64bb29631fc5e5fafbe88374e7e1325b70ba5 Mon Sep 17 00:00:00 2001 From: ljedrz <ljedrz@gmail.com> Date: Tue, 4 Dec 2018 12:46:10 +0100 Subject: [PATCH 21/28] cleanup: remove static lifetimes from consts --- src/liballoc/string.rs | 2 +- src/libcore/fmt/mod.rs | 2 +- src/libcore/unicode/printable.rs | 12 +++--- src/librustc/dep_graph/dep_node.rs | 2 +- src/librustc/hir/print.rs | 2 +- src/librustc/ich/mod.rs | 16 +++---- src/librustc/session/config.rs | 43 +++++++++---------- src/librustc/session/filesearch.rs | 8 ++-- src/librustc/util/common.rs | 2 +- .../back/symbol_export.rs | 2 +- src/librustc_codegen_utils/symbol_names.rs | 2 +- .../assert_module_sources.rs | 6 +-- .../persist/file_format.rs | 4 +- src/librustc_incremental/persist/fs.rs | 8 ++-- src/librustc_metadata/schema.rs | 2 +- src/librustc_mir/dataflow/graphviz.rs | 4 +- src/librustc_mir/diagnostics.rs | 8 ++-- src/librustc_mir/util/pretty.rs | 2 +- src/librustc_target/spec/mod.rs | 2 +- src/libsyntax/feature_gate.rs | 35 ++++++++------- src/libsyntax/parse/attr.rs | 4 +- src/libsyntax/parse/lexer/unicode_chars.rs | 2 +- src/libsyntax_ext/asm.rs | 2 +- src/libsyntax_ext/global_asm.rs | 2 +- src/libsyntax_ext/proc_macro_decls.rs | 3 +- src/libsyntax_pos/edition.rs | 2 +- 26 files changed, 88 insertions(+), 91 deletions(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 662f8ae614fcb..acc1f9b306e7d 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -577,7 +577,7 @@ impl String { return Cow::Borrowed(""); }; - const REPLACEMENT: &'static str = "\u{FFFD}"; + const REPLACEMENT: &str = "\u{FFFD}"; let mut res = String::with_capacity(v.len()); res.push_str(first_valid); diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 75ec0d7d50be6..0c5256b981e5c 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1381,7 +1381,7 @@ impl<'a> Formatter<'a> { for part in formatted.parts { match *part { flt2dec::Part::Zero(mut nzeroes) => { - const ZEROES: &'static str = // 64 zeroes + const ZEROES: &str = // 64 zeroes "0000000000000000000000000000000000000000000000000000000000000000"; while nzeroes > ZEROES.len() { self.buf.write_str(ZEROES)?; diff --git a/src/libcore/unicode/printable.rs b/src/libcore/unicode/printable.rs index 519dd17bb9b3f..32e4b6b0fa512 100644 --- a/src/libcore/unicode/printable.rs +++ b/src/libcore/unicode/printable.rs @@ -80,7 +80,7 @@ pub(crate) fn is_printable(x: char) -> bool { } } -const SINGLETONS0U: &'static [(u8, u8)] = &[ +const SINGLETONS0U: &[(u8, u8)] = &[ (0x00, 1), (0x03, 5), (0x05, 6), @@ -122,7 +122,7 @@ const SINGLETONS0U: &'static [(u8, u8)] = &[ (0xfe, 3), (0xff, 9), ]; -const SINGLETONS0L: &'static [u8] = &[ +const SINGLETONS0L: &[u8] = &[ 0xad, 0x78, 0x79, 0x8b, 0x8d, 0xa2, 0x30, 0x57, 0x58, 0x8b, 0x8c, 0x90, 0x1c, 0x1d, 0xdd, 0x0e, 0x0f, 0x4b, 0x4c, 0xfb, 0xfc, 0x2e, 0x2f, 0x3f, @@ -162,7 +162,7 @@ const SINGLETONS0L: &'static [u8] = &[ 0x91, 0xfe, 0xff, 0x53, 0x67, 0x75, 0xc8, 0xc9, 0xd0, 0xd1, 0xd8, 0xd9, 0xe7, 0xfe, 0xff, ]; -const SINGLETONS1U: &'static [(u8, u8)] = &[ +const SINGLETONS1U: &[(u8, u8)] = &[ (0x00, 6), (0x01, 1), (0x03, 1), @@ -197,7 +197,7 @@ const SINGLETONS1U: &'static [(u8, u8)] = &[ (0xf0, 4), (0xf9, 4), ]; -const SINGLETONS1L: &'static [u8] = &[ +const SINGLETONS1L: &[u8] = &[ 0x0c, 0x27, 0x3b, 0x3e, 0x4e, 0x4f, 0x8f, 0x9e, 0x9e, 0x9f, 0x06, 0x07, 0x09, 0x36, 0x3d, 0x3e, 0x56, 0xf3, 0xd0, 0xd1, 0x04, 0x14, 0x18, 0x36, @@ -219,7 +219,7 @@ const SINGLETONS1L: &'static [u8] = &[ 0x78, 0x7d, 0x7f, 0x8a, 0xa4, 0xaa, 0xaf, 0xb0, 0xc0, 0xd0, 0x3f, 0x71, 0x72, 0x7b, ]; -const NORMAL0: &'static [u8] = &[ +const NORMAL0: &[u8] = &[ 0x00, 0x20, 0x5f, 0x22, 0x82, 0xdf, 0x04, @@ -363,7 +363,7 @@ const NORMAL0: &'static [u8] = &[ 0x1b, 0x03, 0x0f, 0x0d, ]; -const NORMAL1: &'static [u8] = &[ +const NORMAL1: &[u8] = &[ 0x5e, 0x22, 0x7b, 0x05, 0x03, 0x04, diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 388bbc52c3b1a..a20d04972fd75 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -381,7 +381,7 @@ macro_rules! define_dep_nodes { #[allow(dead_code, non_upper_case_globals)] pub mod label_strs { $( - pub const $variant: &'static str = stringify!($variant); + pub const $variant: &str = stringify!($variant); )* } ); diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 9a0ceddcf1b4a..113a2377ac926 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -65,7 +65,7 @@ pub trait PpAnn { pub struct NoAnn; impl PpAnn for NoAnn {} -pub const NO_ANN: &'static dyn PpAnn = &NoAnn; +pub const NO_ANN: &dyn PpAnn = &NoAnn; impl PpAnn for hir::Crate { fn try_fetch_item(&self, item: ast::NodeId) -> Option<&hir::Item> { diff --git a/src/librustc/ich/mod.rs b/src/librustc/ich/mod.rs index 9751c560acd1e..fc2f1ee6ff892 100644 --- a/src/librustc/ich/mod.rs +++ b/src/librustc/ich/mod.rs @@ -24,15 +24,15 @@ mod impls_misc; mod impls_ty; mod impls_syntax; -pub const ATTR_DIRTY: &'static str = "rustc_dirty"; -pub const ATTR_CLEAN: &'static str = "rustc_clean"; -pub const ATTR_IF_THIS_CHANGED: &'static str = "rustc_if_this_changed"; -pub const ATTR_THEN_THIS_WOULD_NEED: &'static str = "rustc_then_this_would_need"; -pub const ATTR_PARTITION_REUSED: &'static str = "rustc_partition_reused"; -pub const ATTR_PARTITION_CODEGENED: &'static str = "rustc_partition_codegened"; -pub const ATTR_EXPECTED_CGU_REUSE: &'static str = "rustc_expected_cgu_reuse"; +pub const ATTR_DIRTY: &str = "rustc_dirty"; +pub const ATTR_CLEAN: &str = "rustc_clean"; +pub const ATTR_IF_THIS_CHANGED: &str = "rustc_if_this_changed"; +pub const ATTR_THEN_THIS_WOULD_NEED: &str = "rustc_then_this_would_need"; +pub const ATTR_PARTITION_REUSED: &str = "rustc_partition_reused"; +pub const ATTR_PARTITION_CODEGENED: &str = "rustc_partition_codegened"; +pub const ATTR_EXPECTED_CGU_REUSE: &str = "rustc_expected_cgu_reuse"; -pub const IGNORED_ATTRIBUTES: &'static [&'static str] = &[ +pub const IGNORED_ATTRIBUTES: &[&str] = &[ "cfg", ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED, diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 480d4a8e48f0e..e8b280fb3d802 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -780,43 +780,42 @@ macro_rules! options { } pub type $setter_name = fn(&mut $struct_name, v: Option<&str>) -> bool; - pub const $stat: &'static [(&'static str, $setter_name, - Option<&'static str>, &'static str)] = + pub const $stat: &[(&str, $setter_name, Option<&str>, &str)] = &[ $( (stringify!($opt), $mod_set::$opt, $mod_desc::$parse, $desc) ),* ]; #[allow(non_upper_case_globals, dead_code)] mod $mod_desc { - pub const parse_bool: Option<&'static str> = None; - pub const parse_opt_bool: Option<&'static str> = + pub const parse_bool: Option<&str> = None; + pub const parse_opt_bool: Option<&str> = Some("one of: `y`, `yes`, `on`, `n`, `no`, or `off`"); - pub const parse_string: Option<&'static str> = Some("a string"); - pub const parse_string_push: Option<&'static str> = Some("a string"); - pub const parse_pathbuf_push: Option<&'static str> = Some("a path"); - pub const parse_opt_string: Option<&'static str> = Some("a string"); - pub const parse_opt_pathbuf: Option<&'static str> = Some("a path"); - pub const parse_list: Option<&'static str> = Some("a space-separated list of strings"); - pub const parse_opt_list: Option<&'static str> = Some("a space-separated list of strings"); - pub const parse_uint: Option<&'static str> = Some("a number"); - pub const parse_passes: Option<&'static str> = + pub const parse_string: Option<&str> = Some("a string"); + pub const parse_string_push: Option<&str> = Some("a string"); + pub const parse_pathbuf_push: Option<&str> = Some("a path"); + pub const parse_opt_string: Option<&str> = Some("a string"); + pub const parse_opt_pathbuf: Option<&str> = Some("a path"); + pub const parse_list: Option<&str> = Some("a space-separated list of strings"); + pub const parse_opt_list: Option<&str> = Some("a space-separated list of strings"); + pub const parse_uint: Option<&str> = Some("a number"); + pub const parse_passes: Option<&str> = Some("a space-separated list of passes, or `all`"); - pub const parse_opt_uint: Option<&'static str> = + pub const parse_opt_uint: Option<&str> = Some("a number"); - pub const parse_panic_strategy: Option<&'static str> = + pub const parse_panic_strategy: Option<&str> = Some("either `unwind` or `abort`"); - pub const parse_relro_level: Option<&'static str> = + pub const parse_relro_level: Option<&str> = Some("one of: `full`, `partial`, or `off`"); - pub const parse_sanitizer: Option<&'static str> = + pub const parse_sanitizer: Option<&str> = Some("one of: `address`, `leak`, `memory` or `thread`"); - pub const parse_linker_flavor: Option<&'static str> = + pub const parse_linker_flavor: Option<&str> = Some(::rustc_target::spec::LinkerFlavor::one_of()); - pub const parse_optimization_fuel: Option<&'static str> = + pub const parse_optimization_fuel: Option<&str> = Some("crate=integer"); - pub const parse_unpretty: Option<&'static str> = + pub const parse_unpretty: Option<&str> = Some("`string` or `string=string`"); - pub const parse_lto: Option<&'static str> = + pub const parse_lto: Option<&str> = Some("either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, \ `fat`, or omitted"); - pub const parse_cross_lang_lto: Option<&'static str> = + pub const parse_cross_lang_lto: Option<&str> = Some("either a boolean (`yes`, `no`, `on`, `off`, etc), \ or the path to the linker plugin"); } diff --git a/src/librustc/session/filesearch.rs b/src/librustc/session/filesearch.rs index f410c270bcef9..e686a1d1275b6 100644 --- a/src/librustc/session/filesearch.rs +++ b/src/librustc/session/filesearch.rs @@ -179,12 +179,12 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> { // "lib" (i.e. non-default), this value is used (see issue #16552). #[cfg(target_pointer_width = "64")] - const PRIMARY_LIB_DIR: &'static str = "lib64"; + const PRIMARY_LIB_DIR: &str = "lib64"; #[cfg(target_pointer_width = "32")] - const PRIMARY_LIB_DIR: &'static str = "lib32"; + const PRIMARY_LIB_DIR: &str = "lib32"; - const SECONDARY_LIB_DIR: &'static str = "lib"; + const SECONDARY_LIB_DIR: &str = "lib"; match option_env!("CFG_LIBDIR_RELATIVE") { Some(libdir) if libdir != "lib" => libdir.into(), @@ -198,4 +198,4 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> { // The name of rustc's own place to organize libraries. // Used to be "rustc", now the default is "rustlib" -const RUST_LIB_DIR: &'static str = "rustlib"; +const RUST_LIB_DIR: &str = "rustlib"; diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 7a246af82e5fe..c6ba20de0d3b9 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -28,7 +28,7 @@ use lazy_static; use session::Session; // The name of the associated type for `Fn` return types -pub const FN_OUTPUT_NAME: &'static str = "Output"; +pub const FN_OUTPUT_NAME: &str = "Output"; // Useful type to use with `Result<>` indicate that an error has already // been reported to the user, so no need to continue checking. diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 0fb2641a4f82e..23b35b2e41654 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -225,7 +225,7 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // These are weak symbols that point to the profile version and the // profile name, which need to be treated as exported so LTO doesn't nix // them. - const PROFILER_WEAK_SYMBOLS: [&'static str; 2] = [ + const PROFILER_WEAK_SYMBOLS: [&str; 2] = [ "__llvm_profile_raw_version", "__llvm_profile_filename", ]; diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index 344a252578472..611d7b137c6f2 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -389,7 +389,7 @@ impl SymbolPathBuffer { impl ItemPathBuffer for SymbolPathBuffer { fn root_mode(&self) -> &RootMode { - const ABSOLUTE: &'static RootMode = &RootMode::Absolute; + const ABSOLUTE: &RootMode = &RootMode::Absolute; ABSOLUTE } diff --git a/src/librustc_incremental/assert_module_sources.rs b/src/librustc_incremental/assert_module_sources.rs index 4ff2529b26d93..17ac9a6b53973 100644 --- a/src/librustc_incremental/assert_module_sources.rs +++ b/src/librustc_incremental/assert_module_sources.rs @@ -40,9 +40,9 @@ use syntax::ast; use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_CODEGENED, ATTR_EXPECTED_CGU_REUSE}; -const MODULE: &'static str = "module"; -const CFG: &'static str = "cfg"; -const KIND: &'static str = "kind"; +const MODULE: &str = "module"; +const CFG: &str = "cfg"; +const KIND: &str = "kind"; pub fn assert_module_sources<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { tcx.dep_graph.with_ignore(|| { diff --git a/src/librustc_incremental/persist/file_format.rs b/src/librustc_incremental/persist/file_format.rs index 98f7873fda0e4..e5faba6178233 100644 --- a/src/librustc_incremental/persist/file_format.rs +++ b/src/librustc_incremental/persist/file_format.rs @@ -28,7 +28,7 @@ use rustc::session::config::nightly_options; use rustc_serialize::opaque::Encoder; /// The first few bytes of files generated by incremental compilation -const FILE_MAGIC: &'static [u8] = b"RSIC"; +const FILE_MAGIC: &[u8] = b"RSIC"; /// Change this if the header format changes const HEADER_FORMAT_VERSION: u16 = 0; @@ -36,7 +36,7 @@ const HEADER_FORMAT_VERSION: u16 = 0; /// A version string that hopefully is always different for compiler versions /// with different encodings of incremental compilation artifacts. Contains /// the git commit hash. -const RUSTC_VERSION: Option<&'static str> = option_env!("CFG_VERSION"); +const RUSTC_VERSION: Option<&str> = option_env!("CFG_VERSION"); pub fn write_file_header(stream: &mut Encoder) { stream.emit_raw_bytes(FILE_MAGIC); diff --git a/src/librustc_incremental/persist/fs.rs b/src/librustc_incremental/persist/fs.rs index 75cdefaf49f00..bc98798f77253 100644 --- a/src/librustc_incremental/persist/fs.rs +++ b/src/librustc_incremental/persist/fs.rs @@ -128,10 +128,10 @@ use std::time::{UNIX_EPOCH, SystemTime, Duration}; use rand::{RngCore, thread_rng}; -const LOCK_FILE_EXT: &'static str = ".lock"; -const DEP_GRAPH_FILENAME: &'static str = "dep-graph.bin"; -const WORK_PRODUCTS_FILENAME: &'static str = "work-products.bin"; -const QUERY_CACHE_FILENAME: &'static str = "query-cache.bin"; +const LOCK_FILE_EXT: &str = ".lock"; +const DEP_GRAPH_FILENAME: &str = "dep-graph.bin"; +const WORK_PRODUCTS_FILENAME: &str = "work-products.bin"; +const QUERY_CACHE_FILENAME: &str = "query-cache.bin"; // We encode integers using the following base, so they are shorter than decimal // or hexadecimal numbers (we want short file and directory names). Since these diff --git a/src/librustc_metadata/schema.rs b/src/librustc_metadata/schema.rs index e91d15b78c075..fc3af6cf2e732 100644 --- a/src/librustc_metadata/schema.rs +++ b/src/librustc_metadata/schema.rs @@ -52,7 +52,7 @@ pub const METADATA_VERSION: u8 = 4; /// This header is followed by the position of the `CrateRoot`, /// which is encoded as a 32-bit big-endian unsigned integer, /// and further followed by the rustc version string. -pub const METADATA_HEADER: &'static [u8; 12] = +pub const METADATA_HEADER: &[u8; 12] = &[0, 0, 0, 0, b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION]; /// A value of type T referred to by its absolute position diff --git a/src/librustc_mir/dataflow/graphviz.rs b/src/librustc_mir/dataflow/graphviz.rs index 6896c91352fdd..f6a9d46b5e2cb 100644 --- a/src/librustc_mir/dataflow/graphviz.rs +++ b/src/librustc_mir/dataflow/graphviz.rs @@ -137,8 +137,8 @@ where MWF: MirWithFlowState<'tcx>, block: BasicBlock, mir: &Mir) -> io::Result<()> { // Header rows - const HDRS: [&'static str; 4] = ["ENTRY", "MIR", "BLOCK GENS", "BLOCK KILLS"]; - const HDR_FMT: &'static str = "bgcolor=\"grey\""; + const HDRS: [&str; 4] = ["ENTRY", "MIR", "BLOCK GENS", "BLOCK KILLS"]; + const HDR_FMT: &str = "bgcolor=\"grey\""; write!(w, "<table><tr><td rowspan=\"{}\">", HDRS.len())?; write!(w, "{:?}", block.index())?; write!(w, "</td></tr><tr>")?; diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs index 56a9daf84f768..ec5617d705248 100644 --- a/src/librustc_mir/diagnostics.rs +++ b/src/librustc_mir/diagnostics.rs @@ -606,7 +606,7 @@ static X: i32 = 1; const C: i32 = 2; // these three are not allowed: -const CR: &'static mut i32 = &mut C; +const CR: &mut i32 = &mut C; static STATIC_REF: &'static mut i32 = &mut X; static CONST_REF: &'static mut i32 = &mut C; ``` @@ -1163,7 +1163,7 @@ You can also have this error while using a cell type: use std::cell::Cell; const A: Cell<usize> = Cell::new(1); -const B: &'static Cell<usize> = &A; +const B: &Cell<usize> = &A; // error: cannot borrow a constant which may contain interior mutability, // create a static instead @@ -1171,10 +1171,10 @@ const B: &'static Cell<usize> = &A; struct C { a: Cell<usize> } const D: C = C { a: Cell::new(1) }; -const E: &'static Cell<usize> = &D.a; // error +const E: &Cell<usize> = &D.a; // error // or: -const F: &'static C = &D; // error +const F: &C = &D; // error ``` This is because cell types do operations that are not thread-safe. Due to this, diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index c74492fe64936..2d7e7d01274f6 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -24,7 +24,7 @@ use std::path::{Path, PathBuf}; use super::graphviz::write_mir_fn_graphviz; use transform::MirSource; -const INDENT: &'static str = " "; +const INDENT: &str = " "; /// Alignment for lining up comments following MIR statements pub(crate) const ALIGN: usize = 40; diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 5b8070cbf3d8e..5830fa00be8cb 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -234,7 +234,7 @@ macro_rules! supported_targets { $(mod $module;)* /// List of supported targets - const TARGETS: &'static [&'static str] = &[$($triple),*]; + const TARGETS: &[&str] = &[$($triple),*]; fn load_specific(target: &str) -> TargetResult { match target { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index fac7ff2bf342d..f41de99001a45 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -53,8 +53,7 @@ macro_rules! declare_features { /// Represents active features that are currently being implemented or /// currently being considered for addition/removal. const ACTIVE_FEATURES: - &'static [(&'static str, &'static str, Option<u32>, - Option<Edition>, fn(&mut Features, Span))] = + &[(&str, &str, Option<u32>, Option<Edition>, fn(&mut Features, Span))] = &[$((stringify!($feature), $ver, $issue, $edition, set!($feature))),+]; /// A set of features to be used by later passes. @@ -769,7 +768,7 @@ pub fn is_builtin_attr(attr: &ast::Attribute) -> bool { } // Attributes that have a special meaning to rustc or rustdoc -pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeGate)] = &[ +pub const BUILTIN_ATTRIBUTES: &[(&str, AttributeType, AttributeGate)] = &[ // Normal attributes ("warn", Normal, Ungated), @@ -1383,48 +1382,48 @@ fn leveled_feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue } -const EXPLAIN_BOX_SYNTAX: &'static str = +const EXPLAIN_BOX_SYNTAX: &str = "box expression syntax is experimental; you can call `Box::new` instead."; -pub const EXPLAIN_STMT_ATTR_SYNTAX: &'static str = +pub const EXPLAIN_STMT_ATTR_SYNTAX: &str = "attributes on expressions are experimental."; -pub const EXPLAIN_ASM: &'static str = +pub const EXPLAIN_ASM: &str = "inline assembly is not stable enough for use and is subject to change"; -pub const EXPLAIN_GLOBAL_ASM: &'static str = +pub const EXPLAIN_GLOBAL_ASM: &str = "`global_asm!` is not stable enough for use and is subject to change"; -pub const EXPLAIN_CUSTOM_TEST_FRAMEWORKS: &'static str = +pub const EXPLAIN_CUSTOM_TEST_FRAMEWORKS: &str = "custom test frameworks are an unstable feature"; -pub const EXPLAIN_LOG_SYNTAX: &'static str = +pub const EXPLAIN_LOG_SYNTAX: &str = "`log_syntax!` is not stable enough for use and is subject to change"; -pub const EXPLAIN_CONCAT_IDENTS: &'static str = +pub const EXPLAIN_CONCAT_IDENTS: &str = "`concat_idents` is not stable enough for use and is subject to change"; -pub const EXPLAIN_FORMAT_ARGS_NL: &'static str = +pub const EXPLAIN_FORMAT_ARGS_NL: &str = "`format_args_nl` is only for internal language use and is subject to change"; -pub const EXPLAIN_TRACE_MACROS: &'static str = +pub const EXPLAIN_TRACE_MACROS: &str = "`trace_macros` is not stable enough for use and is subject to change"; -pub const EXPLAIN_ALLOW_INTERNAL_UNSTABLE: &'static str = +pub const EXPLAIN_ALLOW_INTERNAL_UNSTABLE: &str = "allow_internal_unstable side-steps feature gating and stability checks"; -pub const EXPLAIN_ALLOW_INTERNAL_UNSAFE: &'static str = +pub const EXPLAIN_ALLOW_INTERNAL_UNSAFE: &str = "allow_internal_unsafe side-steps the unsafe_code lint"; -pub const EXPLAIN_CUSTOM_DERIVE: &'static str = +pub const EXPLAIN_CUSTOM_DERIVE: &str = "`#[derive]` for custom traits is deprecated and will be removed in the future."; -pub const EXPLAIN_DEPR_CUSTOM_DERIVE: &'static str = +pub const EXPLAIN_DEPR_CUSTOM_DERIVE: &str = "`#[derive]` for custom traits is deprecated and will be removed in the future. \ Prefer using procedural macro custom derive."; -pub const EXPLAIN_DERIVE_UNDERSCORE: &'static str = +pub const EXPLAIN_DERIVE_UNDERSCORE: &str = "attributes of the form `#[derive_*]` are reserved for the compiler"; -pub const EXPLAIN_UNSIZED_TUPLE_COERCION: &'static str = +pub const EXPLAIN_UNSIZED_TUPLE_COERCION: &str = "unsized tuple coercion is not stable enough for use and is subject to change"; struct PostExpansionVisitor<'a> { diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index a240604bfe0ad..4ff6048e82178 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -22,8 +22,8 @@ enum InnerAttributeParsePolicy<'a> { NotPermitted { reason: &'a str }, } -const DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG: &'static str = "an inner attribute is not \ - permitted in this context"; +const DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG: &str = "an inner attribute is not \ + permitted in this context"; impl<'a> Parser<'a> { /// Parse attributes that appear before an item diff --git a/src/libsyntax/parse/lexer/unicode_chars.rs b/src/libsyntax/parse/lexer/unicode_chars.rs index 03bf1b5a4e1ed..8a620c8067d3c 100644 --- a/src/libsyntax/parse/lexer/unicode_chars.rs +++ b/src/libsyntax/parse/lexer/unicode_chars.rs @@ -306,7 +306,7 @@ const UNICODE_ARRAY: &[(char, &str, char)] = &[ ('>', "Fullwidth Greater-Than Sign", '>'), ]; -const ASCII_ARRAY: &'static [(char, &'static str)] = &[ +const ASCII_ARRAY: &[(char, &str)] = &[ (' ', "Space"), ('_', "Underscore"), ('-', "Minus/Hyphen"), diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index 026ddccd7be97..2ff9fb487c4f2 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -47,7 +47,7 @@ impl State { } } -const OPTIONS: &'static [&'static str] = &["volatile", "alignstack", "intel"]; +const OPTIONS: &[&str] = &["volatile", "alignstack", "intel"]; pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, diff --git a/src/libsyntax_ext/global_asm.rs b/src/libsyntax_ext/global_asm.rs index 1130a50537d01..000bede7348a5 100644 --- a/src/libsyntax_ext/global_asm.rs +++ b/src/libsyntax_ext/global_asm.rs @@ -28,7 +28,7 @@ use syntax::symbol::Symbol; use syntax_pos::Span; use syntax::tokenstream; -pub const MACRO: &'static str = "global_asm"; +pub const MACRO: &str = "global_asm"; pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, diff --git a/src/libsyntax_ext/proc_macro_decls.rs b/src/libsyntax_ext/proc_macro_decls.rs index c859275ed020c..f4ff0989b5d86 100644 --- a/src/libsyntax_ext/proc_macro_decls.rs +++ b/src/libsyntax_ext/proc_macro_decls.rs @@ -30,8 +30,7 @@ use syntax_pos::{Span, DUMMY_SP}; use deriving; -const PROC_MACRO_KINDS: [&'static str; 3] = - ["proc_macro_derive", "proc_macro_attribute", "proc_macro"]; +const PROC_MACRO_KINDS: [&str; 3] = ["proc_macro_derive", "proc_macro_attribute", "proc_macro"]; struct ProcMacroDerive { trait_name: ast::Name, diff --git a/src/libsyntax_pos/edition.rs b/src/libsyntax_pos/edition.rs index 5819cd7f480a0..54b2405440171 100644 --- a/src/libsyntax_pos/edition.rs +++ b/src/libsyntax_pos/edition.rs @@ -33,7 +33,7 @@ pub enum Edition { // must be in order from oldest to newest pub const ALL_EDITIONS: &[Edition] = &[Edition::Edition2015, Edition::Edition2018]; -pub const EDITION_NAME_LIST: &'static str = "2015|2018"; +pub const EDITION_NAME_LIST: &str = "2015|2018"; pub const DEFAULT_EDITION: Edition = Edition::Edition2015; From 3512fb046799fe02555b12d1e180d0ef83aba849 Mon Sep 17 00:00:00 2001 From: John-John Tedro <udoprog@tedro.se> Date: Wed, 5 Dec 2018 02:48:18 +0100 Subject: [PATCH 22/28] Avoid extra copy and syscall in std::env::current_exe --- src/libstd/sys/unix/os.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index b387a8d59a56d..03e81a720dc64 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -283,11 +283,14 @@ pub fn current_exe() -> io::Result<PathBuf> { #[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))] pub fn current_exe() -> io::Result<PathBuf> { - let selfexe = PathBuf::from("/proc/self/exe"); - if selfexe.exists() { - ::fs::read_link(selfexe) - } else { - Err(io::Error::new(io::ErrorKind::Other, "no /proc/self/exe available. Is /proc mounted?")) + match ::fs::read_link("/proc/self/exe") { + Err(ref e) if e.kind() == io::ErrorKind::NotFound => { + Err(io::Error::new( + io::ErrorKind::Other, + "no /proc/self/exe available. Is /proc mounted?" + )) + }, + other => other, } } From 6cfbb5b9a15e575de4dacec900b2039031cd1ca2 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada <sinkuu@sinkuu.xyz> Date: Wed, 5 Dec 2018 14:06:32 +0900 Subject: [PATCH 23/28] Remove unused dependency (rustc_lint -> rustc_mir) --- Cargo.lock | 1 - src/librustc_lint/Cargo.toml | 1 - src/librustc_lint/lib.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 69d929e913a9a..02c63200a28c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2352,7 +2352,6 @@ dependencies = [ "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", "rustc_data_structures 0.0.0", - "rustc_mir 0.0.0", "rustc_target 0.0.0", "syntax 0.0.0", "syntax_pos 0.0.0", diff --git a/src/librustc_lint/Cargo.toml b/src/librustc_lint/Cargo.toml index fe197e3e2e28c..7fb7a06ea1ad5 100644 --- a/src/librustc_lint/Cargo.toml +++ b/src/librustc_lint/Cargo.toml @@ -12,7 +12,6 @@ test = false [dependencies] log = "0.4" rustc = { path = "../librustc" } -rustc_mir = { path = "../librustc_mir"} rustc_target = { path = "../librustc_target" } syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 71efc5654eff3..4d709d574c4f1 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -36,7 +36,6 @@ extern crate syntax; extern crate rustc; #[macro_use] extern crate log; -extern crate rustc_mir; extern crate rustc_target; extern crate syntax_pos; extern crate rustc_data_structures; From ed64b1927b4e929e905f778870a9f53d75216b34 Mon Sep 17 00:00:00 2001 From: varkor <github@varkor.com> Date: Wed, 5 Dec 2018 23:21:56 +0100 Subject: [PATCH 24/28] Fix precise_pointer_size_matching tests on all platforms --- src/test/ui/precise_pointer_size_matching.rs | 7 +++++++ src/test/ui/precise_pointer_size_matching.stderr | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/test/ui/precise_pointer_size_matching.rs b/src/test/ui/precise_pointer_size_matching.rs index 31b202fd6aa14..759b63b188b35 100644 --- a/src/test/ui/precise_pointer_size_matching.rs +++ b/src/test/ui/precise_pointer_size_matching.rs @@ -1,3 +1,10 @@ +// normalize-stderr-32bit: "-2147483648isize" -> "$$ISIZE_MIN" +// normalize-stderr-64bit: "-9223372036854775808isize" -> "$$ISIZE_MIN" +// normalize-stderr-32bit: "2147483647isize" -> "$$ISIZE_MAX" +// normalize-stderr-64bit: "9223372036854775807isize" -> "$$ISIZE_MAX" +// normalize-stderr-32bit: "4294967295usize" -> "$$USIZE_MAX" +// normalize-stderr-64bit: "18446744073709551615usize" -> "$$USIZE_MAX" + #![feature(precise_pointer_size_matching)] #![feature(exclusive_range_pattern)] diff --git a/src/test/ui/precise_pointer_size_matching.stderr b/src/test/ui/precise_pointer_size_matching.stderr index 8e13be0ae0c74..4acbec6c7ff1a 100644 --- a/src/test/ui/precise_pointer_size_matching.stderr +++ b/src/test/ui/precise_pointer_size_matching.stderr @@ -1,14 +1,14 @@ -error[E0004]: non-exhaustive patterns: `-9223372036854775808isize..=-6isize` and `21isize..=9223372036854775807isize` not covered - --> $DIR/precise_pointer_size_matching.rs:17:11 +error[E0004]: non-exhaustive patterns: `$ISIZE_MIN..=-6isize` and `21isize..=$ISIZE_MAX` not covered + --> $DIR/precise_pointer_size_matching.rs:24:11 | LL | match 0isize { //~ ERROR non-exhaustive patterns - | ^^^^^^ patterns `-9223372036854775808isize..=-6isize` and `21isize..=9223372036854775807isize` not covered + | ^^^^^^ patterns `$ISIZE_MIN..=-6isize` and `21isize..=$ISIZE_MAX` not covered -error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=18446744073709551615usize` not covered - --> $DIR/precise_pointer_size_matching.rs:22:11 +error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=$USIZE_MAX` not covered + --> $DIR/precise_pointer_size_matching.rs:29:11 | LL | match 0usize { //~ ERROR non-exhaustive patterns - | ^^^^^^ patterns `0usize` and `21usize..=18446744073709551615usize` not covered + | ^^^^^^ patterns `0usize` and `21usize..=$USIZE_MAX` not covered error: aborting due to 2 previous errors From 180dcc3118998ebbe390f876df51f85f1b33407a Mon Sep 17 00:00:00 2001 From: Nathan West <Lucretiel@gmail.com> Date: Wed, 5 Dec 2018 14:37:38 -0800 Subject: [PATCH 25/28] Optimized string FromIterator impls --- src/liballoc/string.rs | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 662f8ae614fcb..ef9a34ec611c6 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1732,18 +1732,31 @@ impl<'a> FromIterator<&'a str> for String { #[stable(feature = "extend_string", since = "1.4.0")] impl FromIterator<String> for String { fn from_iter<I: IntoIterator<Item = String>>(iter: I) -> String { - let mut buf = String::new(); - buf.extend(iter); - buf + let iterator = iter.into_iter(); + + match iterator.next() { + None => String::new(), + Some(buf) => { + buf.extend(iterator); + buf + } + } } } #[stable(feature = "herd_cows", since = "1.19.0")] impl<'a> FromIterator<Cow<'a, str>> for String { fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(iter: I) -> String { - let mut buf = String::new(); - buf.extend(iter); - buf + let iterator = iter.into_iter(); + + match iterator.next() { + None => String::new(), + Some(cow) => { + let buf = cow.into_owned(); + buf.extend(iterator); + buf + } + } } } @@ -1753,9 +1766,7 @@ impl Extend<char> for String { let iterator = iter.into_iter(); let (lower_bound, _) = iterator.size_hint(); self.reserve(lower_bound); - for ch in iterator { - self.push(ch) - } + iterator.for_each(move |c| self.push(c)); } } @@ -1769,27 +1780,21 @@ impl<'a> Extend<&'a char> for String { #[stable(feature = "rust1", since = "1.0.0")] impl<'a> Extend<&'a str> for String { fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I) { - for s in iter { - self.push_str(s) - } + iter.into_iter().for_each(move |s| self.push_str(s)); } } #[stable(feature = "extend_string", since = "1.4.0")] impl Extend<String> for String { fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I) { - for s in iter { - self.push_str(&s) - } + iter.into_iter().for_each(move |s| self.push_str(&s)); } } #[stable(feature = "herd_cows", since = "1.19.0")] impl<'a> Extend<Cow<'a, str>> for String { fn extend<I: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: I) { - for s in iter { - self.push_str(&s) - } + iter.into_iter().for_each(move |s| self.push_str(&s)); } } From 823dd8ca334951962e8b192ca1362c08e33d6bcf Mon Sep 17 00:00:00 2001 From: Nathan West <Lucretiel@gmail.com> Date: Wed, 5 Dec 2018 15:11:32 -0800 Subject: [PATCH 26/28] Fixed mutability --- src/liballoc/string.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index ef9a34ec611c6..6962f2ba85296 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1732,11 +1732,11 @@ impl<'a> FromIterator<&'a str> for String { #[stable(feature = "extend_string", since = "1.4.0")] impl FromIterator<String> for String { fn from_iter<I: IntoIterator<Item = String>>(iter: I) -> String { - let iterator = iter.into_iter(); + let mut iterator = iter.into_iter(); match iterator.next() { None => String::new(), - Some(buf) => { + Some(mut buf) => { buf.extend(iterator); buf } @@ -1747,12 +1747,12 @@ impl FromIterator<String> for String { #[stable(feature = "herd_cows", since = "1.19.0")] impl<'a> FromIterator<Cow<'a, str>> for String { fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(iter: I) -> String { - let iterator = iter.into_iter(); + let mut iterator = iter.into_iter(); match iterator.next() { None => String::new(), Some(cow) => { - let buf = cow.into_owned(); + let mut buf = cow.into_owned(); buf.extend(iterator); buf } From 811a2bfe5332081d7145de6c488ea7f6c5cf42a5 Mon Sep 17 00:00:00 2001 From: Nathan West <Lucretiel@users.noreply.github.com> Date: Wed, 5 Dec 2018 17:46:03 -0800 Subject: [PATCH 27/28] Added explainatory comments --- src/liballoc/string.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 6962f2ba85296..f0a64f4631a00 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1734,6 +1734,9 @@ impl FromIterator<String> for String { fn from_iter<I: IntoIterator<Item = String>>(iter: I) -> String { let mut iterator = iter.into_iter(); + // Because we're iterating over `String`s, we can avoid at least + // one allocation by getting the first string from the iterator + // and appending to it all the subsequent strings. match iterator.next() { None => String::new(), Some(mut buf) => { @@ -1749,6 +1752,9 @@ impl<'a> FromIterator<Cow<'a, str>> for String { fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(iter: I) -> String { let mut iterator = iter.into_iter(); + // Because we're iterating over CoWs, we can (potentially) avoid at least + // one allocation by getting the first item and appending to it all the + // subsequent items. match iterator.next() { None => String::new(), Some(cow) => { From 3858aff9d3c47405051bb87c2c61f709bb690b7b Mon Sep 17 00:00:00 2001 From: Wesley Wiser <wwiser@gmail.com> Date: Wed, 5 Dec 2018 20:25:00 -0500 Subject: [PATCH 28/28] Don't print the profiling summary to stdout when -Zprofile-json is set cc rust-lang-nursery/rustc-perf#299 --- src/librustc/session/mod.rs | 2 +- src/librustc_driver/driver.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index d1c3acc57b723..293cd0c7c546d 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -826,7 +826,7 @@ impl Session { } pub fn profiler<F: FnOnce(&mut SelfProfiler) -> ()>(&self, f: F) { - if self.opts.debugging_opts.self_profile { + if self.opts.debugging_opts.self_profile || self.opts.debugging_opts.profile_json { let mut profiler = self.self_profiling.borrow_mut(); f(&mut profiler); } diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index c1705ad2d58ff..87ef232b9d87d 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -356,10 +356,10 @@ pub fn compile_input( if sess.opts.debugging_opts.self_profile { sess.print_profiler_results(); + } - if sess.opts.debugging_opts.profile_json { - sess.save_json_results(); - } + if sess.opts.debugging_opts.profile_json { + sess.save_json_results(); } controller_entry_point!(