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 7 pull requests #63182

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e8e13f0
simplify std::io::Write::write rustdoc
urandom2 Jul 13, 2019
08a8de8
Add keywords item into the sidebar
GuillaumeGomez Jul 25, 2019
f3a3290
Account for maybe_whole_expr in range patterns.
Centril Jul 30, 2019
f64b66a
Do not downgrade NLL errors for bind_by_move_pattern_guards when AST …
Centril Jul 27, 2019
c4bf275
Remove 'feature(nll)' from bind_by_move_pattern_guards tests.
Centril Jul 27, 2019
bba2e4c
Unconditionally set SignalledError::SawSomeError.
Centril Jul 28, 2019
513852f
borrowck-mutate-in-guard: update test.
Centril Jul 28, 2019
a421e51
borrowck-migrate-to-nll: use #38899 for testing.
Centril Jul 28, 2019
0201cb8
Add tests for #27282, #31287 as hard errors.
Centril Jul 28, 2019
81e6427
Remove redundant check.
Centril Jul 28, 2019
1538b2a
cargotest: bump servo to 9043f247d9b031ed285e880e4b90aa523d4a63ae.
Centril Jul 30, 2019
87e73c1
Remove redundant method with const variable resolution
varkor Jul 31, 2019
804f0f3
Unify spanned and non-spanned Attribute ctors
Mark-Simulacrum Jul 30, 2019
0a42bad
Remove AttrId from Attribute constructors
Mark-Simulacrum Jul 30, 2019
b2c5065
Remove Span argument from ExtCtxt::attribute
Mark-Simulacrum Jul 30, 2019
f78bf50
Remove span argument from mk_attr_{inner,outer}
Mark-Simulacrum Jul 30, 2019
c9bd4a0
Replace a few Attribute constructors with mk_attr
Mark-Simulacrum Jul 30, 2019
0f98581
Replace AstBuilder with inherent methods
Mark-Simulacrum Jul 31, 2019
d4227f6
Use Ident::new over setting span position via builder
Mark-Simulacrum Jul 31, 2019
c146344
Decode AttrId via mk_attr_id
Mark-Simulacrum Jul 30, 2019
3f461f5
cleanup StringReader fields
matklad Jul 31, 2019
6551285
Address review comments.
Centril Jul 31, 2019
757a14a
Rollup merge of #62644 - arnottcr:std_io-doc, r=steveklabnik
Centril Aug 1, 2019
7bd956e
Rollup merge of #62971 - GuillaumeGomez:keyword-sidebar, r=nobody
Centril Aug 1, 2019
8c84efa
Rollup merge of #63059 - Centril:sound-bind-by-move, r=matthewjasper
Centril Aug 1, 2019
54a0a83
Rollup merge of #63122 - Centril:fix-63115, r=petrochenkov
Centril Aug 1, 2019
e83fd29
Rollup merge of #63146 - Mark-Simulacrum:clean-attr, r=petrochenkov
Centril Aug 1, 2019
39d4fe4
Rollup merge of #63153 - varkor:remove-resolve_const_var, r=cramertj
Centril Aug 1, 2019
6905d72
Rollup merge of #63170 - matklad:cleanup-fields, r=petrochenkov
Centril Aug 1, 2019
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
8 changes: 0 additions & 8 deletions src/doc/unstable-book/src/language-features/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ extern crate rustc_plugin;
use syntax::parse::token::{self, Token};
use syntax::tokenstream::TokenTree;
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
use syntax::ext::build::AstBuilder; // A trait for expr_usize.
use syntax_pos::Span;
use rustc_plugin::Registry;

Expand Down Expand Up @@ -164,13 +163,6 @@ can continue and find further errors.
To print syntax fragments for debugging, you can use `span_note` together with
`syntax::print::pprust::*_to_string`.

The example above produced an integer literal using `AstBuilder::expr_usize`.
As an alternative to the `AstBuilder` trait, `libsyntax` provides a set of
quasiquote macros. They are undocumented and very rough around the edges.
However, the implementation may be a good starting point for an improved
quasiquote as an ordinary plugin library.


# Lint plugins

Plugins can extend [Rust's lint
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5168,7 +5168,7 @@ impl<'a> LoweringContext<'a> {
let uc_nested = attr::mk_nested_word_item(uc_ident);
attr::mk_list_item(e.span, allow_ident, vec![uc_nested])
};
attr::mk_spanned_attr_outer(e.span, attr::mk_attr_id(), allow)
attr::mk_attr_outer(allow)
};
let attrs = vec![attr];

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
const_var: &'tcx ty::Const<'tcx>
) -> &'tcx ty::Const<'tcx> {
let infcx = self.infcx.expect("encountered const-var without infcx");
let bound_to = infcx.resolve_const_var(const_var);
let bound_to = infcx.shallow_resolve(const_var);
if bound_to != const_var {
self.fold_const(bound_to)
} else {
Expand Down
27 changes: 4 additions & 23 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,23 +1351,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
}

pub fn resolve_const_var(
&self,
ct: &'tcx ty::Const<'tcx>
) -> &'tcx ty::Const<'tcx> {
if let ty::Const { val: ConstValue::Infer(InferConst::Var(v)), .. } = ct {
self.const_unification_table
.borrow_mut()
.probe_value(*v)
.val
.known()
.map(|c| self.resolve_const_var(c))
.unwrap_or(ct)
} else {
ct
}
}

pub fn fully_resolve<T: TypeFoldable<'tcx>>(&self, value: &T) -> FixupResult<'tcx, T> {
/*!
* Attempts to resolve all type/region/const variables in
Expand Down Expand Up @@ -1586,7 +1569,7 @@ impl<'a, 'tcx> ShallowResolver<'a, 'tcx> {
// it can be resolved to an int/float variable, which
// can then be recursively resolved, hence the
// recursion. Note though that we prevent type
// variables from unifyxing to other type variables
// variables from unifying to other type variables
// directly (though they may be embedded
// structurally), and we prevent cycles in any case,
// so this recursion should always be of very limited
Expand Down Expand Up @@ -1626,17 +1609,15 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> {
}

fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
match ct {
ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } => {
if let ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } = ct {
self.infcx.const_unification_table
.borrow_mut()
.probe_value(*vid)
.val
.known()
.map(|c| self.fold_const(c))
.unwrap_or(ct)
}
_ => ct,
} else {
ct
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ rustc_queries! {
}

TypeChecking {
query check_match(key: DefId) -> () {
query check_match(key: DefId) -> SignalledError {
cache_on_disk_if { key.is_local() }
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::hir::def::{DefKind, Export};
use crate::hir::{self, TraitCandidate, ItemLocalId, CodegenFnAttrs};
use crate::infer::canonical::{self, Canonical};
use crate::lint;
use crate::middle::borrowck::BorrowCheckResult;
use crate::middle::borrowck::{BorrowCheckResult, SignalledError};
use crate::middle::cstore::{ExternCrate, LinkagePreference, NativeLibrary, ForeignModule};
use crate::middle::cstore::{NativeLibraryKind, DepKind, CrateSource};
use crate::middle::privacy::AccessLevels;
Expand Down
12 changes: 5 additions & 7 deletions src/librustc/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,11 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
ty: a.ty,
}))
}
(ConstValue::ByRef { .. }, _) => {
bug!(
"non-Scalar ConstValue encountered in super_relate_consts {:?} {:?}",
a,
b,
);
}

// FIXME(const_generics): we should either handle `Scalar::Ptr` or add a comment
// saying that we're not handling it intentionally.

// FIXME(const_generics): handle `ConstValue::ByRef` and `ConstValue::Slice`.

// FIXME(const_generics): this is wrong, as it is a projection
(ConstValue::Unevaluated(a_def_id, a_substs),
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_ast_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ fn borrowck(tcx: TyCtxt<'_>, owner_def_id: DefId) -> &BorrowCheckResult {

debug!("borrowck(body_owner_def_id={:?})", owner_def_id);

let signalled_error = tcx.check_match(owner_def_id);
if let SignalledError::SawSomeError = signalled_error {
return tcx.arena.alloc(BorrowCheckResult {
signalled_any_error: SignalledError::SawSomeError,
})
}

let owner_id = tcx.hir().as_local_hir_id(owner_def_id).unwrap();

match tcx.hir().get(owner_id) {
Expand Down
9 changes: 1 addition & 8 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,14 +980,7 @@ impl<'a, 'tcx> CrateMetadata {
}

fn get_attributes(&self, item: &Entry<'tcx>, sess: &Session) -> Vec<ast::Attribute> {
item.attributes
.decode((self, sess))
.map(|mut attr| {
// Need new unique IDs: old thread-local IDs won't map to new threads.
attr.id = attr::mk_attr_id();
attr
})
.collect()
item.attributes.decode((self, sess)).collect()
}

// Translate a DefId from the current compilation environment to a DefId
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ When matching on a variable it cannot be mutated in the match guards, as this
could cause the match to be non-exhaustive:

```compile_fail,E0510
#![feature(nll, bind_by_move_pattern_guards)]
#![feature(bind_by_move_pattern_guards)]
let mut x = Some(0);
match x {
None => (),
Expand Down
58 changes: 34 additions & 24 deletions src/librustc_mir/hair/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::_match::WitnessPreference::*;

use super::{Pattern, PatternContext, PatternError, PatternKind};

use rustc::middle::borrowck::SignalledError;
use rustc::middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor};
use rustc::middle::expr_use_visitor::{LoanCause, MutateMode};
use rustc::middle::expr_use_visitor as euv;
Expand All @@ -26,21 +27,24 @@ use std::slice;

use syntax_pos::{Span, DUMMY_SP, MultiSpan};

pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: DefId) {
crate fn check_match(tcx: TyCtxt<'_>, def_id: DefId) -> SignalledError {
let body_id = if let Some(id) = tcx.hir().as_local_hir_id(def_id) {
tcx.hir().body_owned_by(id)
} else {
return;
return SignalledError::NoErrorsSeen;
};

MatchVisitor {
let mut visitor = MatchVisitor {
tcx,
body_owner: def_id,
tables: tcx.body_tables(body_id),
region_scope_tree: &tcx.region_scope_tree(def_id),
param_env: tcx.param_env(def_id),
identity_substs: InternalSubsts::identity_for_item(tcx, def_id),
}.visit_body(tcx.hir().body(body_id));
signalled_error: SignalledError::NoErrorsSeen,
};
visitor.visit_body(tcx.hir().body(body_id));
visitor.signalled_error
}

fn create_e0004(sess: &Session, sp: Span, error_message: String) -> DiagnosticBuilder<'_> {
Expand All @@ -54,6 +58,7 @@ struct MatchVisitor<'a, 'tcx> {
param_env: ty::ParamEnv<'tcx>,
identity_substs: SubstsRef<'tcx>,
region_scope_tree: &'a region::ScopeTree,
signalled_error: SignalledError,
}

impl<'a, 'tcx> Visitor<'tcx> for MatchVisitor<'a, 'tcx> {
Expand All @@ -64,11 +69,8 @@ impl<'a, 'tcx> Visitor<'tcx> for MatchVisitor<'a, 'tcx> {
fn visit_expr(&mut self, ex: &'tcx hir::Expr) {
intravisit::walk_expr(self, ex);

match ex.node {
hir::ExprKind::Match(ref scrut, ref arms, source) => {
self.check_match(scrut, arms, source);
}
_ => {}
if let hir::ExprKind::Match(ref scrut, ref arms, source) = ex.node {
self.check_match(scrut, arms, source);
}
}

Expand Down Expand Up @@ -130,26 +132,27 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
}

impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
fn check_patterns(&self, has_guard: bool, pats: &[P<Pat>]) {
fn check_patterns(&mut self, has_guard: bool, pats: &[P<Pat>]) {
check_legality_of_move_bindings(self, has_guard, pats);
for pat in pats {
check_legality_of_bindings_in_at_patterns(self, pat);
}
}

fn check_match(
&self,
&mut self,
scrut: &hir::Expr,
arms: &'tcx [hir::Arm],
source: hir::MatchSource)
{
source: hir::MatchSource
) {
for arm in arms {
// First, check legality of move bindings.
self.check_patterns(arm.guard.is_some(), &arm.pats);

// Second, if there is a guard on each arm, make sure it isn't
// assigning or borrowing anything mutably.
if let Some(ref guard) = arm.guard {
self.signalled_error = SignalledError::SawSomeError;
if !self.tcx.features().bind_by_move_pattern_guards {
check_for_mutation_in_guard(self, &guard);
}
Expand Down Expand Up @@ -548,7 +551,7 @@ fn maybe_point_at_variant(

// Legality of move bindings checking
fn check_legality_of_move_bindings(
cx: &MatchVisitor<'_, '_>,
cx: &mut MatchVisitor<'_, '_>,
has_guard: bool,
pats: &[P<Pat>],
) {
Expand All @@ -565,7 +568,12 @@ fn check_legality_of_move_bindings(
})
}
let span_vec = &mut Vec::new();
let check_move = |p: &Pat, sub: Option<&Pat>, span_vec: &mut Vec<Span>| {
let check_move = |
cx: &mut MatchVisitor<'_, '_>,
p: &Pat,
sub: Option<&Pat>,
span_vec: &mut Vec<Span>,
| {
// check legality of moving out of the enum

// x @ Foo(..) is legal, but x @ Foo(y) isn't.
Expand All @@ -574,15 +582,17 @@ fn check_legality_of_move_bindings(
"cannot bind by-move with sub-bindings")
.span_label(p.span, "binds an already bound by-move value by moving it")
.emit();
} else if has_guard && !cx.tcx.features().bind_by_move_pattern_guards {
let mut err = struct_span_err!(cx.tcx.sess, p.span, E0008,
"cannot bind by-move into a pattern guard");
err.span_label(p.span, "moves value into pattern guard");
if cx.tcx.sess.opts.unstable_features.is_nightly_build() {
err.help("add `#![feature(bind_by_move_pattern_guards)]` to the \
crate attributes to enable");
} else if has_guard {
if !cx.tcx.features().bind_by_move_pattern_guards {
let mut err = struct_span_err!(cx.tcx.sess, p.span, E0008,
"cannot bind by-move into a pattern guard");
err.span_label(p.span, "moves value into pattern guard");
if cx.tcx.sess.opts.unstable_features.is_nightly_build() {
err.help("add `#![feature(bind_by_move_pattern_guards)]` to the \
crate attributes to enable");
}
err.emit();
}
err.emit();
} else if let Some(_by_ref_span) = by_ref_span {
span_vec.push(p.span);
}
Expand All @@ -596,7 +606,7 @@ fn check_legality_of_move_bindings(
ty::BindByValue(..) => {
let pat_ty = cx.tables.node_type(p.hir_id);
if !pat_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, pat.span) {
check_move(p, sub.as_ref().map(|p| &**p), span_vec);
check_move(cx, p, sub.as_ref().map(|p| &**p), span_vec);
}
}
_ => {}
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5007,7 +5007,8 @@ fn sidebar_module(fmt: &mut fmt::Formatter<'_>, _it: &clean::Item,
ItemType::Enum, ItemType::Constant, ItemType::Static, ItemType::Trait,
ItemType::Function, ItemType::Typedef, ItemType::Union, ItemType::Impl,
ItemType::TyMethod, ItemType::Method, ItemType::StructField, ItemType::Variant,
ItemType::AssocType, ItemType::AssocConst, ItemType::ForeignType] {
ItemType::AssocType, ItemType::AssocConst, ItemType::ForeignType,
ItemType::Keyword] {
if items.iter().any(|it| !it.is_stripped() && it.type_() == myty) {
let (short, name) = item_ty_to_strs(&myty);
sidebar.push_str(&format!("<li><a href=\"#{id}\">{name}</a></li>",
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ pub trait Write {
/// an [`Err`] variant.
///
/// If the return value is [`Ok(n)`] then it must be guaranteed that
/// `0 <= n <= buf.len()`. A return value of `0` typically means that the
/// `n <= buf.len()`. A return value of `0` typically means that the
/// underlying object is no longer able to accept bytes and will likely not
/// be able to in the future as well, or that the buffer provided is empty.
///
Expand Down
16 changes: 13 additions & 3 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2104,9 +2104,7 @@ pub enum AttrStyle {
Inner,
}

#[derive(
Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, PartialOrd, Ord, Copy,
)]
#[derive(Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord, Copy)]
pub struct AttrId(pub usize);

impl Idx for AttrId {
Expand All @@ -2118,6 +2116,18 @@ impl Idx for AttrId {
}
}

impl rustc_serialize::Encodable for AttrId {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_unit()
}
}

impl rustc_serialize::Decodable for AttrId {
fn decode<D: Decoder>(d: &mut D) -> Result<AttrId, D::Error> {
d.read_nil().map(|_| crate::attr::mk_attr_id())
}
}

/// Metadata associated with an item.
/// Doc-comments are promoted to attributes that have `is_sugared_doc = true`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/attr/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::ast::{self, Attribute, MetaItem, NestedMetaItem};
use crate::early_buffered_lints::BufferedEarlyLintId;
use crate::ext::base::ExtCtxt;
use crate::ext::build::AstBuilder;
use crate::feature_gate::{Features, GatedCfg};
use crate::parse::ParseSess;

Expand Down Expand Up @@ -929,7 +928,7 @@ pub fn find_transparency(
pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, name: Symbol) {
// All the built-in macro attributes are "words" at the moment.
let template = AttributeTemplate { word: true, list: None, name_value_str: None };
let attr = ecx.attribute(meta_item.span, meta_item.clone());
let attr = ecx.attribute(meta_item.clone());
check_builtin_attribute(ecx.parse_sess, &attr, name, template);
}

Expand Down
Loading