From 8a472a55677959639a92d359a23f5e075cd3cbce Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 18 Dec 2016 11:30:56 -0800 Subject: [PATCH 01/15] Add a more complete doc example for 'include' macro. --- src/libstd/macros.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 0ce6b0a9431d4..9908afd900bfc 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -470,11 +470,26 @@ pub mod builtin { /// /// # Examples /// + /// Assume there are two files in the same directory with the following + /// contents: + /// + /// File 'my_str.in': + /// /// ```ignore - /// fn foo() { - /// include!("/path/to/a/file") + /// "Hello World!" + /// ``` + /// + /// File 'main.rs': + /// + /// ```ignore + /// fn main() { + /// let my_str = include!("my_str.in"); + /// println!("{}", my_str); /// } /// ``` + /// + /// Compiling 'main.rs' and running the resulting binary will print "Hello + /// World!". #[stable(feature = "rust1", since = "1.0.0")] #[macro_export] macro_rules! include { ($file:expr) => ({ /* compiler built-in */ }) } From 44c2eb9182a74025a486ad3e219134c4e3ae160a Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 18 Dec 2016 11:33:37 -0800 Subject: [PATCH 02/15] Move parenthesized statement within sentence. --- src/libstd/macros.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 9908afd900bfc..a79b9f75b7e76 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -458,8 +458,8 @@ pub mod builtin { /// Parse a file as an expression or an item according to the context. /// - /// The file is located relative to the current file. (similarly to how - /// modules are found) + /// The file is located relative to the current file (similarly to how + /// modules are found). /// /// Using this macro is often a bad idea, because if the file is /// parsed as an expression, it is going to be placed in the From 4a354abeae973ecf7bd92f35bc786e62a128d6ae Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Wed, 21 Dec 2016 10:44:54 -0800 Subject: [PATCH 03/15] Fix 'unhygienically' typo. --- src/libstd/macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index a79b9f75b7e76..d160a68cfc1f1 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -463,7 +463,7 @@ pub mod builtin { /// /// Using this macro is often a bad idea, because if the file is /// parsed as an expression, it is going to be placed in the - /// surrounding code unhygenically. This could result in variables + /// surrounding code unhygienically. This could result in variables /// or functions being different from what the file expected if /// there are variables or functions that have the same name in /// the current file. From 58aac456ae96a9aee3d350df8fc0ca780f9c9c92 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Sun, 8 Jan 2017 17:36:49 +0530 Subject: [PATCH 04/15] Fix a couple of bad Markdown links --- src/libstd/fs.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 41934dc057e37..06402cc0e8e93 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -81,7 +81,8 @@ use time::SystemTime; /// # } /// ``` /// -/// [`BufReader`]: ../io/struct.BufReader.html +/// [`Read`]: ../io/trait.Read.html +/// [`BufReader`]: ../io/struct.BufReader.html #[stable(feature = "rust1", since = "1.0.0")] pub struct File { inner: fs_imp::File, From 9940db63ef60518f6c9824787a979beb09e716ba Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Tue, 10 Jan 2017 17:52:33 -0500 Subject: [PATCH 05/15] Deprecate `#[unsafe_destructor_blind_to_params]` CC #34761 --- src/libsyntax/feature_gate.rs | 6 ++--- .../feature-gate-dropck-ugeh-2.rs | 22 +++++++++++++++++++ .../compile-fail/feature-gate-dropck-ugeh.rs | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/test/compile-fail/feature-gate-dropck-ugeh-2.rs diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 5092412475872..3826db455beef 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -691,10 +691,10 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG cfg_fn!(omit_gdb_pretty_printer_section))), ("unsafe_destructor_blind_to_params", Normal, - Gated(Stability::Unstable, + Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761"), "dropck_parametricity", - "unsafe_destructor_blind_to_params has unstable semantics \ - and may be removed in the future", + "unsafe_destructor_blind_to_params has been replaced by \ + may_dangle and will be removed in the future", cfg_fn!(dropck_parametricity))), ("may_dangle", Normal, diff --git a/src/test/compile-fail/feature-gate-dropck-ugeh-2.rs b/src/test/compile-fail/feature-gate-dropck-ugeh-2.rs new file mode 100644 index 0000000000000..70ec561439c61 --- /dev/null +++ b/src/test/compile-fail/feature-gate-dropck-ugeh-2.rs @@ -0,0 +1,22 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(deprecated)] +#![feature(dropck_parametricity)] + +struct Foo; + +impl Drop for Foo { + #[unsafe_destructor_blind_to_params] + //~^ ERROR use of deprecated attribute `dropck_parametricity` + fn drop(&mut self) {} +} + +fn main() {} diff --git a/src/test/compile-fail/feature-gate-dropck-ugeh.rs b/src/test/compile-fail/feature-gate-dropck-ugeh.rs index aa479a987a35b..b9990b536e706 100644 --- a/src/test/compile-fail/feature-gate-dropck-ugeh.rs +++ b/src/test/compile-fail/feature-gate-dropck-ugeh.rs @@ -25,7 +25,7 @@ struct Foo { data: Vec } impl Drop for Foo { #[unsafe_destructor_blind_to_params] // This is the UGEH attribute - //~^ ERROR unsafe_destructor_blind_to_params has unstable semantics + //~^ ERROR unsafe_destructor_blind_to_params has been replaced fn drop(&mut self) { } } From 62e11ad8bb28707837f07987f9ed5ae02789078c Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Mon, 9 Jan 2017 18:09:11 -0500 Subject: [PATCH 06/15] compiletest: Allow for ignoring tests if certain GDB version is detected. --- src/tools/compiletest/src/header.rs | 41 ++++++++++++++++++++++++----- src/tools/compiletest/src/main.rs | 3 --- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index e57c9949b1c57..eb8624fe71f24 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -73,19 +73,24 @@ impl EarlyProps { return false; } - if parse_name_directive(line, "ignore-gdb") { + if !line.contains("ignore-gdb-version") && + parse_name_directive(line, "ignore-gdb") { return true; } if let Some(actual_version) = config.gdb_version { if line.contains("min-gdb-version") { - let min_version = line.trim() - .split(' ') - .last() - .expect("Malformed GDB version directive"); + let min_version = extract_gdb_version_range(line); + + if min_version.0 != min_version.1 { + panic!("Expected single GDB version") + } // Ignore if actual version is smaller the minimum required // version - actual_version < extract_gdb_version(min_version).unwrap() + actual_version < min_version.0 + } else if line.contains("ignore-gdb-version") { + let version_range = extract_gdb_version_range(line); + actual_version >= version_range.0 && actual_version <= version_range.1 } else { false } @@ -94,6 +99,30 @@ impl EarlyProps { } } + fn extract_gdb_version_range(line: &str) -> (u32, u32) { + const ERROR_MESSAGE: &'static str = "Malformed GDB version directive"; + + let range_components = line.split(' ') + .flat_map(|word| word.split('-')) + .filter(|word| word.len() > 0) + .skip_while(|word| extract_gdb_version(word).is_none()) + .collect::>(); + + match range_components.len() { + 0 => panic!(ERROR_MESSAGE), + 1 => { + let v = extract_gdb_version(range_components[0]).unwrap(); + (v, v) + } + 2 => { + let v_min = extract_gdb_version(range_components[0]).unwrap(); + let v_max = extract_gdb_version(range_components[1]).expect(ERROR_MESSAGE); + (v_min, v_max) + } + _ => panic!(ERROR_MESSAGE), + } + } + fn ignore_lldb(config: &Config, line: &str) -> bool { if config.mode != common::DebugInfoLldb { return false; diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index f6c8393ac2154..8c9982d1d4e39 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -587,7 +587,6 @@ fn extract_gdb_version(full_version_line: &str) -> Option { return Some(((major * 1000) + minor) * 1000 + patch); } - println!("Could not extract GDB version from line '{}'", full_version_line); None } @@ -624,8 +623,6 @@ fn extract_lldb_version(full_version_line: Option) -> Option { }).collect::(); if !vers.is_empty() { return Some(vers) } } - println!("Could not extract LLDB version from line '{}'", - full_version_line); } } None From f4375987633d08e9f0d6c13468c7df90c3ae546d Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 13 Jan 2017 13:33:27 -0500 Subject: [PATCH 07/15] debuginfo: Ignore optimized enum tests for GDB versions that can't handle them. --- src/test/debuginfo/borrowed-enum.rs | 1 + src/test/debuginfo/generic-struct-style-enum.rs | 1 + src/test/debuginfo/generic-tuple-style-enum.rs | 1 + src/test/debuginfo/packed-struct.rs | 1 + src/test/debuginfo/recursive-struct.rs | 1 + src/test/debuginfo/struct-in-enum.rs | 1 + src/test/debuginfo/struct-style-enum.rs | 1 + src/test/debuginfo/tuple-style-enum.rs | 1 + src/test/debuginfo/union-smoke.rs | 1 + src/test/debuginfo/unique-enum.rs | 1 + 10 files changed, 10 insertions(+) diff --git a/src/test/debuginfo/borrowed-enum.rs b/src/test/debuginfo/borrowed-enum.rs index f34fc3b20d2be..c457fed7ecd52 100644 --- a/src/test/debuginfo/borrowed-enum.rs +++ b/src/test/debuginfo/borrowed-enum.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // min-lldb-version: 310 +// ignore-gdb-version: 7.11.90 - 7.12 // compile-flags:-g diff --git a/src/test/debuginfo/generic-struct-style-enum.rs b/src/test/debuginfo/generic-struct-style-enum.rs index a328eec689394..df56ccccca3f5 100644 --- a/src/test/debuginfo/generic-struct-style-enum.rs +++ b/src/test/debuginfo/generic-struct-style-enum.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // min-lldb-version: 310 +// ignore-gdb-version: 7.11.90 - 7.12 // compile-flags:-g diff --git a/src/test/debuginfo/generic-tuple-style-enum.rs b/src/test/debuginfo/generic-tuple-style-enum.rs index 9ada5fdeff788..e538700f0f84c 100644 --- a/src/test/debuginfo/generic-tuple-style-enum.rs +++ b/src/test/debuginfo/generic-tuple-style-enum.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // min-lldb-version: 310 +// ignore-gdb-version: 7.11.90 - 7.12 // compile-flags:-g diff --git a/src/test/debuginfo/packed-struct.rs b/src/test/debuginfo/packed-struct.rs index b84161c36a557..c476e9fe0796f 100644 --- a/src/test/debuginfo/packed-struct.rs +++ b/src/test/debuginfo/packed-struct.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // min-lldb-version: 310 +// ignore-gdb-version: 7.11.90 - 7.12 // compile-flags:-g diff --git a/src/test/debuginfo/recursive-struct.rs b/src/test/debuginfo/recursive-struct.rs index 80147b14174da..f33dfac07d203 100644 --- a/src/test/debuginfo/recursive-struct.rs +++ b/src/test/debuginfo/recursive-struct.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // ignore-lldb +// ignore-gdb-version: 7.11.90 - 7.12 // compile-flags:-g diff --git a/src/test/debuginfo/struct-in-enum.rs b/src/test/debuginfo/struct-in-enum.rs index ffd36ae14ad7c..d9763aedd7c15 100644 --- a/src/test/debuginfo/struct-in-enum.rs +++ b/src/test/debuginfo/struct-in-enum.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // min-lldb-version: 310 +// ignore-gdb-version: 7.11.90 - 7.12 // compile-flags:-g diff --git a/src/test/debuginfo/struct-style-enum.rs b/src/test/debuginfo/struct-style-enum.rs index b6196daaa4656..6212caa69538d 100644 --- a/src/test/debuginfo/struct-style-enum.rs +++ b/src/test/debuginfo/struct-style-enum.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // min-lldb-version: 310 +// ignore-gdb-version: 7.11.90 - 7.12 // compile-flags:-g diff --git a/src/test/debuginfo/tuple-style-enum.rs b/src/test/debuginfo/tuple-style-enum.rs index 988f223b3bc4f..f85cd6a50f519 100644 --- a/src/test/debuginfo/tuple-style-enum.rs +++ b/src/test/debuginfo/tuple-style-enum.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // min-lldb-version: 310 +// ignore-gdb-version: 7.11.90 - 7.12 // compile-flags:-g diff --git a/src/test/debuginfo/union-smoke.rs b/src/test/debuginfo/union-smoke.rs index 5d3fbd6202387..844e9405ba55c 100644 --- a/src/test/debuginfo/union-smoke.rs +++ b/src/test/debuginfo/union-smoke.rs @@ -9,6 +9,7 @@ // except according to those terms. // min-lldb-version: 310 +// ignore-gdb-version: 7.11.90 - 7.12 // compile-flags:-g diff --git a/src/test/debuginfo/unique-enum.rs b/src/test/debuginfo/unique-enum.rs index cf8d90e30f169..e8eb4315007af 100644 --- a/src/test/debuginfo/unique-enum.rs +++ b/src/test/debuginfo/unique-enum.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // min-lldb-version: 310 +// ignore-gdb-version: 7.11.90 - 7.12 // compile-flags:-g From 30ba990fce18dc3dde9e6d05d4bbbb2a56b34aba Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Mon, 16 Jan 2017 18:22:38 -0500 Subject: [PATCH 08/15] ignore-gdb-version: Address review comments. --- src/tools/compiletest/src/header.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index eb8624fe71f24..ac1ac1c2f6c08 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -80,17 +80,22 @@ impl EarlyProps { if let Some(actual_version) = config.gdb_version { if line.contains("min-gdb-version") { - let min_version = extract_gdb_version_range(line); + let (start_ver, end_ver) = extract_gdb_version_range(line); - if min_version.0 != min_version.1 { + if start_ver != end_ver { panic!("Expected single GDB version") } // Ignore if actual version is smaller the minimum required // version - actual_version < min_version.0 + actual_version < start_ver } else if line.contains("ignore-gdb-version") { - let version_range = extract_gdb_version_range(line); - actual_version >= version_range.0 && actual_version <= version_range.1 + let (min_version, max_version) = extract_gdb_version_range(line); + + if max_version < min_version { + panic!("Malformed GDB version range: max < min") + } + + actual_version >= min_version && actual_version <= max_version } else { false } @@ -99,6 +104,11 @@ impl EarlyProps { } } + // Takes a directive of the form "ignore-gdb-version [- ]", + // returns the numeric representation of and as + // tuple: ( as u32, as u32) + // If the part is omitted, the second component of the tuple + // is the same as . fn extract_gdb_version_range(line: &str) -> (u32, u32) { const ERROR_MESSAGE: &'static str = "Malformed GDB version directive"; @@ -109,7 +119,6 @@ impl EarlyProps { .collect::>(); match range_components.len() { - 0 => panic!(ERROR_MESSAGE), 1 => { let v = extract_gdb_version(range_components[0]).unwrap(); (v, v) From 5a462e8a682ca7fd3ccff45f419a2fec4b75fd64 Mon Sep 17 00:00:00 2001 From: king6cong Date: Tue, 17 Jan 2017 11:32:13 +0800 Subject: [PATCH 09/15] consistent doc wording --- src/librustc/dep_graph/thread.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/dep_graph/thread.rs b/src/librustc/dep_graph/thread.rs index 9f755cf86e4e4..d3a940c811b88 100644 --- a/src/librustc/dep_graph/thread.rs +++ b/src/librustc/dep_graph/thread.rs @@ -56,7 +56,7 @@ pub struct DepGraphThreadData { // current buffer, where we accumulate messages messages: VecCell, - // whence to receive new buffer when full + // where to receive new buffer when full swap_in: Receiver>, // where to send buffer when full From 1cf9d6a7f26849d3dbacb6edd778dbf62b094425 Mon Sep 17 00:00:00 2001 From: Eitan Adler Date: Tue, 17 Jan 2017 00:18:45 -0800 Subject: [PATCH 10/15] minor typo fix --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index e85c9d18db980..a2241c20d7419 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -3371,7 +3371,7 @@ Version 1.0.0-alpha (2015-01-09) platforms. * Rust comes with rust-gdb and rust-lldb scripts that launch their respective debuggers with Rust-appropriate pretty-printing. - * The Windows installation of Rust is distributed with the the + * The Windows installation of Rust is distributed with the MinGW components currently required to link binaries on that platform. From c525094badc72c50fb713922d4aa0d0513622ff2 Mon Sep 17 00:00:00 2001 From: "Richard S. Imaoka" Date: Mon, 16 Jan 2017 09:32:09 +0900 Subject: [PATCH 11/15] Add error explanation for E0491 --- src/librustc/diagnostics.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 1655c716b6bfa..5505276d4518c 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1454,6 +1454,40 @@ struct Prince<'kiss, 'SnowWhite: 'kiss> { // You say here that 'kiss must live ``` "##, +E0491: r##" +A reference has a longer lifetime than the data it references. + +Erroneous code example: + +```compile_fail,E0491 +// struct containing a reference requires a lifetime parameter, +// because the data the reference points to must outlive the struct (see E0106) +struct Struct<'a> { + ref_i32: &'a i32, +} + +// However, a nested struct like this, the signature itself does not tell +// whether 'a outlives 'b or the other way around. +// So it could be possible that 'b of reference outlives 'a of the data. +struct Nested<'a, 'b> { + ref_struct: &'b Struct<'a>, // compile error E0491 +} +``` + +To fix this issue, you can specify a bound to the lifetime like below: + +``` +struct Struct<'a> { + ref_i32: &'a i32, +} + +// 'a: 'b means 'a outlives 'b +struct Nested<'a: 'b, 'b> { + ref_struct: &'b Struct<'a>, +} +``` +"##, + E0496: r##" A lifetime name is shadowing another lifetime name. Erroneous code example: @@ -1698,7 +1732,6 @@ register_diagnostics! { E0488, // lifetime of variable does not enclose its declaration E0489, // type/lifetime parameter not in scope here E0490, // a value of type `..` is borrowed for too long - E0491, // in type `..`, reference has a longer lifetime than the data it... E0495, // cannot infer an appropriate lifetime due to conflicting requirements E0566 // conflicting representation hints } From 5c58653e46b73bbc2bb6811be2eefa4b6675c942 Mon Sep 17 00:00:00 2001 From: Chris Stankus Date: Wed, 18 Jan 2017 00:16:19 -0600 Subject: [PATCH 12/15] E0122 should apply with where clauses --- src/librustc_typeck/collect.rs | 10 ++++++++++ src/test/compile-fail/issue-17994.rs | 3 ++- src/test/compile-fail/issue-39122.rs | 13 +++++++++++++ src/test/compile-fail/private-in-public-warn.rs | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/issue-39122.rs diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index f832bf8d86e93..e13434db5d886 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -716,6 +716,16 @@ fn ensure_no_ty_param_bounds(ccx: &CrateCtxt, } } + for predicate in generics.where_clause.predicates.iter() { + match *predicate { + hir::WherePredicate::BoundPredicate(..) => { + warn = true; + } + hir::WherePredicate::RegionPredicate(..) => { } + hir::WherePredicate::EqPredicate(..) => { } + } + } + if warn { // According to accepted RFC #XXX, we should // eventually accept these, but it will not be diff --git a/src/test/compile-fail/issue-17994.rs b/src/test/compile-fail/issue-17994.rs index fcbc08327b9fc..ac15bd9d15b04 100644 --- a/src/test/compile-fail/issue-17994.rs +++ b/src/test/compile-fail/issue-17994.rs @@ -9,5 +9,6 @@ // except according to those terms. trait Tr {} -type Huh where T: Tr = isize; //~ ERROR type parameter `T` is unused +type Huh where T: Tr = isize; //~ ERROR type parameter `T` is unused + //~| WARNING E0122 fn main() {} diff --git a/src/test/compile-fail/issue-39122.rs b/src/test/compile-fail/issue-39122.rs new file mode 100644 index 0000000000000..2e8a740f89394 --- /dev/null +++ b/src/test/compile-fail/issue-39122.rs @@ -0,0 +1,13 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +type Foo = T; //~ WARNING E0122 + +type Bar where T: std::ops::Add = T; //~ WARNING E0122 diff --git a/src/test/compile-fail/private-in-public-warn.rs b/src/test/compile-fail/private-in-public-warn.rs index 3496348985d8d..92d96595fd780 100644 --- a/src/test/compile-fail/private-in-public-warn.rs +++ b/src/test/compile-fail/private-in-public-warn.rs @@ -89,6 +89,7 @@ mod traits_where { pub type Alias where T: PrivTr = T; //~^ ERROR private trait `traits_where::PrivTr` in public interface //~| WARNING hard error + //~| WARNING E0122 pub trait Tr2 where T: PrivTr {} //~^ ERROR private trait `traits_where::PrivTr` in public interface //~| WARNING hard error From 871357a534925cf3476dca615d2a072cbc5cb4f2 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 7 Dec 2016 10:14:46 +0100 Subject: [PATCH 13/15] collections: update docs of slice get() and friends for the new SliceIndex trait. Also made the docs of the unchecked versions a bit clearer; they return a reference, not an "unsafe pointer". --- src/libcollections/slice.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 805021516db71..d25799800b7d1 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -342,15 +342,22 @@ impl [T] { core_slice::SliceExt::last_mut(self) } - /// Returns the element of a slice at the given index, or `None` if the - /// index is out of bounds. + /// Returns a reference to an element or subslice depending on the type of + /// index. + /// + /// - If given a position, returns a reference to the element at that + /// position or `None` if out of bounds. + /// - If given a range, returns the subslice corresponding to that range, + /// or `None` if out of bounds. /// /// # Examples /// /// ``` /// let v = [10, 40, 30]; /// assert_eq!(Some(&40), v.get(1)); + /// assert_eq!(Some(&[10, 40][..]), v.get(0..2)); /// assert_eq!(None, v.get(3)); + /// assert_eq!(None, v.get(0..4)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -360,7 +367,10 @@ impl [T] { core_slice::SliceExt::get(self, index) } - /// Returns a mutable reference to the element at the given index. + /// Returns a mutable reference to an element or subslice depending on the + /// type of index (see [`get()`]) or `None` if the index is out of bounds. + /// + /// [`get()`]: #method.get /// /// # Examples /// @@ -372,7 +382,6 @@ impl [T] { /// } /// assert_eq!(x, &[0, 42, 2]); /// ``` - /// or `None` if the index is out of bounds #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn get_mut(&mut self, index: I) -> Option<&mut I::Output> @@ -381,8 +390,8 @@ impl [T] { core_slice::SliceExt::get_mut(self, index) } - /// Returns a pointer to the element at the given index, without doing - /// bounds checking. So use it very carefully! + /// Returns a reference to an element or subslice, without doing bounds + /// checking. So use it very carefully! /// /// # Examples /// @@ -401,8 +410,8 @@ impl [T] { core_slice::SliceExt::get_unchecked(self, index) } - /// Returns an unsafe mutable pointer to the element in index. So use it - /// very carefully! + /// Returns a mutable reference to an element or subslice, without doing + /// bounds checking. So use it very carefully! /// /// # Examples /// From 2c6bc186100df68ba6dc7e7388e3708af7ba1539 Mon Sep 17 00:00:00 2001 From: Andrew Cann Date: Wed, 18 Jan 2017 15:05:28 +0800 Subject: [PATCH 14/15] Feature gate `&Void`'s uninhabitedness. References to empty types are only considered empty if feature(never_type) is enabled. --- src/librustc/ty/inhabitedness/mod.rs | 8 +++++++- ...ninhabited-reference-type-feature-gated.rs | 19 +++++++++++++++++++ src/test/run-pass/empty-types-in-patterns.rs | 5 +++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/uninhabited-reference-type-feature-gated.rs diff --git a/src/librustc/ty/inhabitedness/mod.rs b/src/librustc/ty/inhabitedness/mod.rs index c5b75839e99b7..92395e3c381aa 100644 --- a/src/librustc/ty/inhabitedness/mod.rs +++ b/src/librustc/ty/inhabitedness/mod.rs @@ -190,7 +190,13 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> { ty.uninhabited_from(visited, tcx) } } - TyRef(_, ref tm) => tm.ty.uninhabited_from(visited, tcx), + TyRef(_, ref tm) => { + if tcx.sess.features.borrow().never_type { + tm.ty.uninhabited_from(visited, tcx) + } else { + DefIdForest::empty() + } + } _ => DefIdForest::empty(), } diff --git a/src/test/compile-fail/uninhabited-reference-type-feature-gated.rs b/src/test/compile-fail/uninhabited-reference-type-feature-gated.rs new file mode 100644 index 0000000000000..8f246eddbcde4 --- /dev/null +++ b/src/test/compile-fail/uninhabited-reference-type-feature-gated.rs @@ -0,0 +1,19 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Void {} + +fn main() { + let x: Result = Ok(23); + let _ = match x { //~ ERROR non-exhaustive + Ok(n) => n, + }; +} + diff --git a/src/test/run-pass/empty-types-in-patterns.rs b/src/test/run-pass/empty-types-in-patterns.rs index 23705d36e3de2..033b185a0ef06 100644 --- a/src/test/run-pass/empty-types-in-patterns.rs +++ b/src/test/run-pass/empty-types-in-patterns.rs @@ -55,6 +55,11 @@ fn main() { Err(e) => match e {}, }; + let x: Result = Ok(123); + match x { + Ok(y) => y, + }; + bar(&[]); } From c8822da79b963b8180b05cd1886d801230e52d05 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 17 Jan 2017 21:59:26 -0500 Subject: [PATCH 15/15] A few improvements to the slice docs. * Simplify `Option::iter_mut` doc example. * Document 'empty' corner-cases for `slice::{starts_with, ends_with}`. * Indicate 'true' as code-like. --- src/libcollections/slice.rs | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 805021516db71..f20ef2727b92f 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -181,7 +181,7 @@ impl [T] { core_slice::SliceExt::len(self) } - /// Returns true if the slice has a length of 0. + /// Returns `true` if the slice has a length of 0. /// /// # Example /// @@ -540,12 +540,8 @@ impl [T] { /// /// ``` /// let x = &mut [1, 2, 4]; - /// { - /// let iterator = x.iter_mut(); - /// - /// for elem in iterator { - /// *elem += 2; - /// } + /// for elem in x.iter_mut() { + /// *elem += 2; /// } /// assert_eq!(x, &[3, 4, 6]); /// ``` @@ -880,7 +876,7 @@ impl [T] { core_slice::SliceExt::rsplitn_mut(self, n, pred) } - /// Returns true if the slice contains an element with the given value. + /// Returns `true` if the slice contains an element with the given value. /// /// # Examples /// @@ -896,7 +892,7 @@ impl [T] { core_slice::SliceExt::contains(self, x) } - /// Returns true if `needle` is a prefix of the slice. + /// Returns `true` if `needle` is a prefix of the slice. /// /// # Examples /// @@ -907,6 +903,15 @@ impl [T] { /// assert!(!v.starts_with(&[50])); /// assert!(!v.starts_with(&[10, 50])); /// ``` + /// + /// Always returns `true` if `needle` is an empty slice: + /// + /// ``` + /// let v = &[10, 40, 30]; + /// assert!(v.starts_with(&[])); + /// let v: &[u8] = &[]; + /// assert!(v.starts_with(&[])); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn starts_with(&self, needle: &[T]) -> bool where T: PartialEq @@ -914,7 +919,7 @@ impl [T] { core_slice::SliceExt::starts_with(self, needle) } - /// Returns true if `needle` is a suffix of the slice. + /// Returns `true` if `needle` is a suffix of the slice. /// /// # Examples /// @@ -925,6 +930,15 @@ impl [T] { /// assert!(!v.ends_with(&[50])); /// assert!(!v.ends_with(&[50, 30])); /// ``` + /// + /// Always returns `true` if `needle` is an empty slice: + /// + /// ``` + /// let v = &[10, 40, 30]; + /// assert!(v.ends_with(&[])); + /// let v: &[u8] = &[]; + /// assert!(v.ends_with(&[])); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn ends_with(&self, needle: &[T]) -> bool where T: PartialEq