Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #68329

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
154cab0
stabilize slice_patterns
Centril Dec 29, 2019
44d54db
slice_patterns: adjust error codes
Centril Dec 29, 2019
864cdd2
slice_patterns: remove internal uses of gate
Centril Dec 29, 2019
120116f
slice_patterns: remove feature gate test
Centril Dec 29, 2019
7407dbf
slice_patterns: remove gates in tests
Centril Dec 30, 2019
932b850
slice_patterns: organize some tests
Centril Dec 30, 2019
fa68165
slice_patterns: remove from unstable book
Centril Dec 30, 2019
0e15893
slice_patterns: address review comments
Centril Jan 2, 2020
12f029b
Fix deref impl on type alias
GuillaumeGomez Jan 10, 2020
fd4a88f
Add test for typedef deref
GuillaumeGomez Jan 10, 2020
81a5b94
formatting
GuillaumeGomez Jan 10, 2020
6e79146
remove unneeded code from cache.rs
GuillaumeGomez Jan 15, 2020
e6ad49a
Include type alias implementations
GuillaumeGomez Jan 15, 2020
d755238
Simplify deref impls for type aliases
GuillaumeGomez Jan 15, 2020
8a9b951
Fix rendering on sidebar and update tests
GuillaumeGomez Jan 15, 2020
25a8f94
Don't warn about snake case for field puns that don't introduce a new…
jumbatm Nov 23, 2019
3094c37
Improve code readability
GuillaumeGomez Jan 16, 2020
10a9ea4
Do not ICE on malformed suggestion spans
estebank Jan 15, 2020
03240e1
review comments
estebank Jan 17, 2020
cdc828e
Stop treating `FalseEdges` and `FalseUnwind` as having semantic value…
oli-obk Jan 17, 2020
a91f77c
Add regression test for integer literals in generic arguments in wher…
varkor Jan 17, 2020
9c6c2f1
Clean up E0198 explanation
GuillaumeGomez Jan 16, 2020
482dc77
formatting
GuillaumeGomez Jan 17, 2020
e8a4b93
Clean up E0199 explanation
GuillaumeGomez Jan 17, 2020
77383a4
Rollup merge of #66660 - jumbatm:dont_warn_about_snake_case_in_patter…
tmandry Jan 18, 2020
a4014b6
Rollup merge of #67712 - Centril:stabilize-slice_patterns, r=matthewj…
tmandry Jan 18, 2020
3c3ae3d
Rollup merge of #68093 - GuillaumeGomez:fix-deref-impl-typedef, r=oli…
tmandry Jan 18, 2020
4fad2ec
Rollup merge of #68256 - estebank:bad-sugg-span, r=petrochenkov
tmandry Jan 18, 2020
246291a
Rollup merge of #68279 - GuillaumeGomez:clean-up-e0198, r=Dylan-DPC
tmandry Jan 18, 2020
6c08ebb
Rollup merge of #68312 - varkor:issue-67753-regression, r=Centril
tmandry Jan 18, 2020
f44a12e
Rollup merge of #68314 - oli-obk:true_unwind, r=eddyb
tmandry Jan 18, 2020
af17550
Rollup merge of #68317 - GuillaumeGomez:clean-up-e0199, r=Dylan-DPC
tmandry Jan 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions src/doc/unstable-book/src/language-features/slice-patterns.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
#![feature(associated_type_bounds)]
#![feature(const_type_id)]
#![feature(const_caller_location)]
#![feature(slice_patterns)]
#![cfg_attr(bootstrap, feature(slice_patterns))]

#[prelude_import]
#[allow(unused)]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![feature(range_is_empty)]
#![feature(raw)]
#![feature(saturating_neg)]
#![feature(slice_patterns)]
#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(sort_internals)]
#![feature(slice_partition_at_index)]
#![feature(specialization)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/benches/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(slice_patterns)]
#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(test)]

extern crate test;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#![feature(optin_builtin_traits)]
#![feature(option_expect_none)]
#![feature(range_is_empty)]
#![feature(slice_patterns)]
#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(specialization)]
#![feature(unboxed_closures)]
#![feature(thread_local)]
Expand Down
21 changes: 0 additions & 21 deletions src/librustc_ast_passes/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,29 +470,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
visit::walk_expr(self, e)
}

fn visit_arm(&mut self, arm: &'a ast::Arm) {
visit::walk_arm(self, arm)
}

fn visit_pat(&mut self, pattern: &'a ast::Pat) {
match &pattern.kind {
PatKind::Slice(pats) => {
for pat in &*pats {
let span = pat.span;
let inner_pat = match &pat.kind {
PatKind::Ident(.., Some(pat)) => pat,
_ => pat,
};
if inner_pat.is_rest() {
gate_feature_post!(
&self,
slice_patterns,
span,
"subslice patterns are unstable"
);
}
}
}
PatKind::Box(..) => {
gate_feature_post!(
&self,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_passes/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! parsed by `rustc_parse` and then lowered, after the passes in this crate,
//! by `rustc_ast_lowering`.

#![feature(slice_patterns)]
#![cfg_attr(bootstrap, feature(slice_patterns))]

pub mod ast_validation;
pub mod feature_gate;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![feature(box_syntax)]
#![feature(core_intrinsics)]
#![feature(libc)]
#![feature(slice_patterns)]
#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(stmt_expr_attributes)]
#![feature(try_blocks)]
#![feature(in_band_lifetimes)]
Expand Down
17 changes: 9 additions & 8 deletions src/librustc_error_codes/error_codes/E0198.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
A negative implementation is one that excludes a type from implementing a
particular trait. Not being able to use a trait is always a safe operation,
so negative implementations are always safe and never need to be marked as
unsafe.
A negative implementation was marked as unsafe.

```compile_fail
#![feature(optin_builtin_traits)]
Erroneous code example:

```compile_fail
struct Foo;

// unsafe is unnecessary
unsafe impl !Clone for Foo { }
unsafe impl !Clone for Foo { } // error!
```

A negative implementation is one that excludes a type from implementing a
particular trait. Not being able to use a trait is always a safe operation,
so negative implementations are always safe and never need to be marked as
unsafe.

This will compile:

```ignore (ignore auto_trait future compatibility warning)
Expand Down
21 changes: 15 additions & 6 deletions src/librustc_error_codes/error_codes/E0199.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
A trait implementation was marked as unsafe while the trait is safe.

Erroneous code example:

```compile_fail,E0199
struct Foo;

trait Bar { }

unsafe impl Bar for Foo { } // error!
```

Safe traits should not have unsafe implementations, therefore marking an
implementation for a safe trait unsafe will cause a compiler error. Removing
the unsafe marker on the trait noted in the error will resolve this problem.
the unsafe marker on the trait noted in the error will resolve this problem:

```compile_fail,E0199
```
struct Foo;

trait Bar { }

// this won't compile because Bar is safe
unsafe impl Bar for Foo { }
// this will compile
impl Bar for Foo { }
impl Bar for Foo { } // ok!
```
2 changes: 0 additions & 2 deletions src/librustc_error_codes/error_codes/E0527.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Ensure that the pattern is consistent with the size of the matched
array. Additional elements can be matched with `..`:

```
#![feature(slice_patterns)]

let r = &[1, 2, 3, 4];
match r {
&[a, b, ..] => { // ok!
Expand Down
4 changes: 0 additions & 4 deletions src/librustc_error_codes/error_codes/E0528.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ matched array.
Example of erroneous code:

```compile_fail,E0528
#![feature(slice_patterns)]

let r = &[1, 2];
match r {
&[a, b, c, rest @ ..] => { // error: pattern requires at least 3
Expand All @@ -19,8 +17,6 @@ Ensure that the matched array has at least as many elements as the pattern
requires. You can match an arbitrary number of remaining elements with `..`:

```
#![feature(slice_patterns)]

let r = &[1, 2, 3, 4, 5];
match r {
&[a, b, c, rest @ ..] => { // ok!
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_error_codes/error_codes/E0730.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ Ensure that the pattern is consistent with the size of the matched
array. Additional elements can be matched with `..`:

```
#![feature(slice_patterns)]

let r = &[1, 2, 3, 4];
match r {
&[a, b, ..] => { // ok!
Expand Down
16 changes: 12 additions & 4 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,15 @@ impl EmitterWriter {
None => return Ok(()),
};

// Render the replacements for each suggestion
let suggestions = suggestion.splice_lines(&**sm);

if suggestions.is_empty() {
// Suggestions coming from macros can have malformed spans. This is a heavy handed
// approach to avoid ICEs by ignoring the suggestion outright.
return Ok(());
}

let mut buffer = StyledBuffer::new();

// Render the suggestion message
Expand All @@ -1492,9 +1501,6 @@ impl EmitterWriter {
Some(Style::HeaderMsg),
);

// Render the replacements for each suggestion
let suggestions = suggestion.splice_lines(&**sm);

let mut row_num = 2;
let mut notice_capitalization = false;
for (complete, parts, only_capitalization) in suggestions.iter().take(MAX_SUGGESTIONS) {
Expand All @@ -1505,7 +1511,9 @@ impl EmitterWriter {
let show_underline = !(parts.len() == 1 && parts[0].snippet.trim() == complete.trim())
&& complete.lines().count() == 1;

let lines = sm.span_to_lines(parts[0].span).unwrap();
let lines = sm
.span_to_lines(parts[0].span)
.expect("span_to_lines failed when emitting suggestion");

assert!(!lines.lines.is_empty());

Expand Down
10 changes: 10 additions & 0 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

pub use emitter::ColorConfig;

use log::debug;
use Level::*;

use emitter::{is_case_difference, Emitter, EmitterWriter};
Expand Down Expand Up @@ -174,6 +175,15 @@ impl CodeSuggestion {

self.substitutions
.iter()
.filter(|subst| {
// Suggestions coming from macros can have malformed spans. This is a heavy
// handed approach to avoid ICEs by ignoring the suggestion outright.
let invalid = subst.parts.iter().any(|item| cm.is_valid_span(item.span).is_err());
if invalid {
debug!("splice_lines: suggestion contains an invalid span: {:?}", subst);
}
!invalid
})
.cloned()
.map(|mut substitution| {
// Assumption: all spans are in the same file, and all spans
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_feature/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ declare_features! (
/// Allows relaxing the coherence rules such that
/// `impl<T> ForeignTrait<LocalType> for ForeignType<T>` is permitted.
(accepted, re_rebalance_coherence, "1.41.0", Some(55437), None),
/// Allows using subslice patterns, `[a, .., b]` and `[a, xs @ .., b]`.
(accepted, slice_patterns, "1.42.0", Some(62254), None),

// -------------------------------------------------------------------------
// feature-group-end: accepted features
Expand Down
3 changes: 0 additions & 3 deletions src/librustc_feature/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,6 @@ declare_features! (
/// Allows using non lexical lifetimes (RFC 2094).
(active, nll, "1.0.0", Some(43234), None),

/// Allows using slice patterns.
(active, slice_patterns, "1.0.0", Some(62254), None),

/// Allows the definition of `const` functions with some advanced features.
(active, const_fn, "1.2.0", Some(57563), None),

Expand Down
15 changes: 14 additions & 1 deletion src/librustc_lint/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,20 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
}

fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat<'_>) {
if let &PatKind::Binding(_, _, ident, _) = &p.kind {
if let &PatKind::Binding(_, hid, ident, _) = &p.kind {
if let hir::Node::Pat(parent_pat) = cx.tcx.hir().get(cx.tcx.hir().get_parent_node(hid))
{
if let PatKind::Struct(_, field_pats, _) = &parent_pat.kind {
for field in field_pats.iter() {
if field.ident != ident {
// Only check if a new name has been introduced, to avoid warning
// on both the struct definition and this pattern.
self.check_snake_case(cx, "variable", &ident);
}
}
return;
}
}
self.check_snake_case(cx, "variable", &ident);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#![feature(proc_macro_internals)]
#![feature(proc_macro_quote)]
#![feature(rustc_private)]
#![feature(slice_patterns)]
#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(specialization)]
#![feature(stmt_expr_attributes)]
#![recursion_limit = "256"]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#![feature(nll)]
#![feature(in_band_lifetimes)]
#![feature(inner_deref)]
#![feature(slice_patterns)]
#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(box_syntax)]
Expand Down
19 changes: 6 additions & 13 deletions src/librustc_mir/transform/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,21 +309,22 @@ fn check_terminator(
) -> McfResult {
let span = terminator.source_info.span;
match &terminator.kind {
TerminatorKind::Goto { .. } | TerminatorKind::Return | TerminatorKind::Resume => Ok(()),
TerminatorKind::FalseEdges { .. }
| TerminatorKind::FalseUnwind { .. }
| TerminatorKind::Goto { .. }
| TerminatorKind::Return
| TerminatorKind::Resume => Ok(()),

TerminatorKind::Drop { location, .. } => check_place(tcx, location, span, def_id, body),
TerminatorKind::DropAndReplace { location, value, .. } => {
check_place(tcx, location, span, def_id, body)?;
check_operand(tcx, value, span, def_id, body)
}

TerminatorKind::FalseEdges { .. } | TerminatorKind::SwitchInt { .. }
if !feature_allowed(tcx, def_id, sym::const_if_match) =>
{
TerminatorKind::SwitchInt { .. } if !feature_allowed(tcx, def_id, sym::const_if_match) => {
Err((span, "loops and conditional expressions are not stable in const fn".into()))
}

TerminatorKind::FalseEdges { .. } => Ok(()),
TerminatorKind::SwitchInt { discr, switch_ty: _, values: _, targets: _ } => {
check_operand(tcx, discr, span, def_id, body)
}
Expand Down Expand Up @@ -367,13 +368,5 @@ fn check_terminator(
TerminatorKind::Assert { cond, expected: _, msg: _, target: _, cleanup: _ } => {
check_operand(tcx, cond, span, def_id, body)
}

TerminatorKind::FalseUnwind { .. } if feature_allowed(tcx, def_id, sym::const_loop) => {
Ok(())
}

TerminatorKind::FalseUnwind { .. } => {
Err((span, "loops are not allowed in const fn".into()))
}
}
}
2 changes: 1 addition & 1 deletion src/librustc_parse/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)]
#![feature(slice_patterns)]
#![cfg_attr(bootstrap, feature(slice_patterns))]

use syntax::ast;
use syntax::print::pprust;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(in_band_lifetimes)]
#![feature(nll)]
#![feature(slice_patterns)]
#![cfg_attr(bootstrap, feature(slice_patterns))]
#![recursion_limit = "256"]

#[macro_use]
Expand Down
Loading