Skip to content

Commit

Permalink
Auto merge of #67419 - Centril:rollup-v7b0ypv, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - #67189 (Unify binop wording)
 - #67270 (std: Implement `LineWriter::write_vectored`)
 - #67286 (Fix the configure.py TOML field for a couple LLVM options)
 - #67321 (make htons const fn)
 - #67382 (Remove some unnecessary `ATTR_*` constants.)
 - #67389 (Remove `SO_NOSIGPIPE` dummy variable on platforms that don't use it.)
 - #67394 (Remove outdated references to @t from comments)
 - #67406 (Suggest associated type when the specified one cannot be found)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Dec 19, 2019
2 parents c605199 + 06985c6 commit 0de96d3
Show file tree
Hide file tree
Showing 60 changed files with 435 additions and 217 deletions.
4 changes: 2 additions & 2 deletions src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ def v(*args):
o("lld", "rust.lld", "build lld")
o("lldb", "rust.lldb", "build lldb")
o("missing-tools", "dist.missing-tools", "allow failures when building tools")
o("use-libcxx", "llvm.use_libcxx", "build LLVM with libc++")
o("use-libcxx", "llvm.use-libcxx", "build LLVM with libc++")

o("cflags", "llvm.cflags", "build LLVM with these extra compiler flags")
o("cxxflags", "llvm.cxxflags", "build LLVM with these extra compiler flags")
o("ldflags", "llvm.ldflags", "build LLVM with these extra linker flags")

o("llvm-libunwind", "rust.llvm_libunwind", "use LLVM libunwind")
o("llvm-libunwind", "rust.llvm-libunwind", "use LLVM libunwind")

# Optimization and debugging options. These may be overridden by the release
# channel, etc.
Expand Down
22 changes: 7 additions & 15 deletions src/librustc/ich/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,13 @@ mod impls_hir;
mod impls_ty;
mod impls_syntax;

pub const ATTR_DIRTY: Symbol = sym::rustc_dirty;
pub const ATTR_CLEAN: Symbol = sym::rustc_clean;
pub const ATTR_IF_THIS_CHANGED: Symbol = sym::rustc_if_this_changed;
pub const ATTR_THEN_THIS_WOULD_NEED: Symbol = sym::rustc_then_this_would_need;
pub const ATTR_PARTITION_REUSED: Symbol = sym::rustc_partition_reused;
pub const ATTR_PARTITION_CODEGENED: Symbol = sym::rustc_partition_codegened;
pub const ATTR_EXPECTED_CGU_REUSE: Symbol = sym::rustc_expected_cgu_reuse;

pub const IGNORED_ATTRIBUTES: &[Symbol] = &[
sym::cfg,
ATTR_IF_THIS_CHANGED,
ATTR_THEN_THIS_WOULD_NEED,
ATTR_DIRTY,
ATTR_CLEAN,
ATTR_PARTITION_REUSED,
ATTR_PARTITION_CODEGENED,
ATTR_EXPECTED_CGU_REUSE,
sym::rustc_if_this_changed,
sym::rustc_then_this_would_need,
sym::rustc_dirty,
sym::rustc_clean,
sym::rustc_partition_reused,
sym::rustc_partition_codegened,
sym::rustc_expected_cgu_reuse,
];
9 changes: 4 additions & 5 deletions src/librustc_incremental/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ use rustc_data_structures::graph::implementation::{
};
use rustc::hir;
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc::ich::{ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
use std::env;
use std::fs::{self, File};
use std::io::Write;
use syntax::ast;
use syntax::{ast, symbol::sym};
use syntax_pos::Span;

pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
Expand Down Expand Up @@ -78,7 +77,7 @@ pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
assert!(tcx.sess.opts.debugging_opts.query_dep_graph,
"cannot use the `#[{}]` or `#[{}]` annotations \
without supplying `-Z query-dep-graph`",
ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED);
sym::rustc_if_this_changed, sym::rustc_then_this_would_need);
}

// Check paths.
Expand Down Expand Up @@ -114,7 +113,7 @@ impl IfThisChanged<'tcx> {
let def_id = self.tcx.hir().local_def_id(hir_id);
let def_path_hash = self.tcx.def_path_hash(def_id);
for attr in attrs {
if attr.check_name(ATTR_IF_THIS_CHANGED) {
if attr.check_name(sym::rustc_if_this_changed) {
let dep_node_interned = self.argument(attr);
let dep_node = match dep_node_interned {
None => def_path_hash.to_dep_node(DepKind::Hir),
Expand All @@ -130,7 +129,7 @@ impl IfThisChanged<'tcx> {
}
};
self.if_this_changed.push((attr.span, def_id, dep_node));
} else if attr.check_name(ATTR_THEN_THIS_WOULD_NEED) {
} else if attr.check_name(sym::rustc_then_this_would_need) {
let dep_node_interned = self.argument(attr);
let dep_node = match dep_node_interned {
Some(n) => {
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_incremental/assert_module_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ use rustc::ty::TyCtxt;
use std::collections::BTreeSet;
use syntax::ast;
use syntax::symbol::{Symbol, sym};
use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_CODEGENED,
ATTR_EXPECTED_CGU_REUSE};

pub fn assert_module_sources(tcx: TyCtxt<'_>) {
tcx.dep_graph.with_ignore(|| {
Expand Down Expand Up @@ -62,11 +60,11 @@ struct AssertModuleSource<'tcx> {

impl AssertModuleSource<'tcx> {
fn check_attr(&self, attr: &ast::Attribute) {
let (expected_reuse, comp_kind) = if attr.check_name(ATTR_PARTITION_REUSED) {
let (expected_reuse, comp_kind) = if attr.check_name(sym::rustc_partition_reused) {
(CguReuse::PreLto, ComparisonKind::AtLeast)
} else if attr.check_name(ATTR_PARTITION_CODEGENED) {
} else if attr.check_name(sym::rustc_partition_codegened) {
(CguReuse::No, ComparisonKind::Exact)
} else if attr.check_name(ATTR_EXPECTED_CGU_REUSE) {
} else if attr.check_name(sym::rustc_expected_cgu_reuse) {
match &*self.field(attr, sym::kind).as_str() {
"no" => (CguReuse::No, ComparisonKind::Exact),
"pre-lto" => (CguReuse::PreLto, ComparisonKind::Exact),
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use rustc::hir::Node as HirNode;
use rustc::hir::def_id::DefId;
use rustc::hir::itemlikevisit::ItemLikeVisitor;
use rustc::hir::intravisit;
use rustc::ich::{ATTR_DIRTY, ATTR_CLEAN};
use rustc::ty::TyCtxt;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashSet;
Expand Down Expand Up @@ -224,7 +223,7 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {

let mut all_attrs = FindAllAttrs {
tcx,
attr_names: vec![ATTR_DIRTY, ATTR_CLEAN],
attr_names: vec![sym::rustc_dirty, sym::rustc_clean],
found_attrs: vec![],
};
intravisit::walk_crate(&mut all_attrs, krate);
Expand All @@ -246,9 +245,9 @@ impl DirtyCleanVisitor<'tcx> {
fn assertion_maybe(&mut self, item_id: hir::HirId, attr: &Attribute)
-> Option<Assertion>
{
let is_clean = if attr.check_name(ATTR_DIRTY) {
let is_clean = if attr.check_name(sym::rustc_dirty) {
false
} else if attr.check_name(ATTR_CLEAN) {
} else if attr.check_name(sym::rustc_clean) {
true
} else {
// skip: not rustc_clean/dirty
Expand Down
103 changes: 72 additions & 31 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,11 +1145,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} else {
// Otherwise, we have to walk through the supertraits to find
// those that do.
let candidates = traits::supertraits(tcx, trait_ref).filter(|r| {
self.trait_defines_associated_type_named(r.def_id(), binding.item_name)
});
self.one_bound_for_assoc_type(
candidates,
|| traits::supertraits(tcx, trait_ref),
&trait_ref.print_only_trait_path().to_string(),
binding.item_name,
binding.span
Expand Down Expand Up @@ -1531,50 +1528,48 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {

debug!("find_bound_for_assoc_item: predicates={:#?}", predicates);

let bounds = predicates.iter().filter_map(|(p, _)| p.to_opt_poly_trait_ref());

// Check that there is exactly one way to find an associated type with the
// correct name.
let suitable_bounds = traits::transitive_bounds(tcx, bounds)
.filter(|b| self.trait_defines_associated_type_named(b.def_id(), assoc_name));

let param_hir_id = tcx.hir().as_local_hir_id(ty_param_def_id).unwrap();
let param_name = tcx.hir().ty_param_name(param_hir_id);
self.one_bound_for_assoc_type(suitable_bounds,
&param_name.as_str(),
assoc_name,
span)
self.one_bound_for_assoc_type(
|| traits::transitive_bounds(tcx, predicates
.iter().filter_map(|(p, _)| p.to_opt_poly_trait_ref())),
&param_name.as_str(),
assoc_name,
span,
)
}

// Checks that `bounds` contains exactly one element and reports appropriate
// errors otherwise.
fn one_bound_for_assoc_type<I>(&self,
mut bounds: I,
all_candidates: impl Fn() -> I,
ty_param_name: &str,
assoc_name: ast::Ident,
span: Span)
-> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
where I: Iterator<Item = ty::PolyTraitRef<'tcx>>
{
let bound = match bounds.next() {
let mut matching_candidates = all_candidates().filter(|r| {
self.trait_defines_associated_type_named(r.def_id(), assoc_name)
});

let bound = match matching_candidates.next() {
Some(bound) => bound,
None => {
struct_span_err!(self.tcx().sess, span, E0220,
"associated type `{}` not found for `{}`",
assoc_name,
ty_param_name)
.span_label(span, format!("associated type `{}` not found", assoc_name))
.emit();
self.complain_about_assoc_type_not_found(
all_candidates,
ty_param_name,
assoc_name,
span
);
return Err(ErrorReported);
}
};

debug!("one_bound_for_assoc_type: bound = {:?}", bound);

if let Some(bound2) = bounds.next() {
if let Some(bound2) = matching_candidates.next() {
debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2);

let bounds = iter::once(bound).chain(iter::once(bound2)).chain(bounds);
let bounds = iter::once(bound).chain(iter::once(bound2)).chain(matching_candidates);
let mut err = struct_span_err!(
self.tcx().sess, span, E0221,
"ambiguous associated type `{}` in bounds of `{}`",
Expand Down Expand Up @@ -1606,6 +1601,50 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
return Ok(bound);
}

fn complain_about_assoc_type_not_found<I>(&self,
all_candidates: impl Fn() -> I,
ty_param_name: &str,
assoc_name: ast::Ident,
span: Span)
where I: Iterator<Item = ty::PolyTraitRef<'tcx>> {
let mut err = struct_span_err!(self.tcx().sess, span, E0220,
"associated type `{}` not found for `{}`",
assoc_name,
ty_param_name);

let all_candidate_names: Vec<_> = all_candidates()
.map(|r| self.tcx().associated_items(r.def_id()))
.flatten()
.filter_map(|item|
if item.kind == ty::AssocKind::Type {
Some(item.ident.name)
} else {
None
}
)
.collect();

if let Some(suggested_name) = find_best_match_for_name(
all_candidate_names.iter(),
&assoc_name.as_str(),
None,
) {
err.span_suggestion(
span,
"there is an associated type with a similar name",
suggested_name.to_string(),
Applicability::MaybeIncorrect,
);
} else {
err.span_label(
span,
format!("associated type `{}` not found", assoc_name)
);
}

err.emit();
}

// Create a type from a path to an associated type.
// For a path `A::B::C::D`, `qself_ty` and `qself_def` are the type and def for `A::B::C`
// and item_segment is the path segment for `D`. We return a type and a def for
Expand Down Expand Up @@ -1660,10 +1699,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
};

let candidates = traits::supertraits(tcx, ty::Binder::bind(trait_ref))
.filter(|r| self.trait_defines_associated_type_named(r.def_id(), assoc_ident));

self.one_bound_for_assoc_type(candidates, "Self", assoc_ident, span)?
self.one_bound_for_assoc_type(
|| traits::supertraits(tcx, ty::Binder::bind(trait_ref)),
"Self",
assoc_ident,
span
)?
}
(&ty::Param(_), Res::SelfTy(Some(param_did), None)) |
(&ty::Param(_), Res::Def(DefKind::TyParam, param_did)) => {
Expand Down
85 changes: 63 additions & 22 deletions src/librustc_typeck/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,70 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.emit();
}
IsAssign::No => {
let (message, missing_trait) = match op.node {
hir::BinOpKind::Add => {
(format!("cannot add `{}` to `{}`", rhs_ty, lhs_ty),
Some("std::ops::Add"))
},
hir::BinOpKind::Sub => {
(format!("cannot substract `{}` from `{}`", rhs_ty, lhs_ty),
Some("std::ops::Sub"))
},
hir::BinOpKind::Mul => {
(format!("cannot multiply `{}` to `{}`", rhs_ty, lhs_ty),
Some("std::ops::Mul"))
},
hir::BinOpKind::Div => {
(format!("cannot divide `{}` by `{}`", lhs_ty, rhs_ty),
Some("std::ops::Div"))
},
hir::BinOpKind::Rem => {
(format!("cannot mod `{}` by `{}`", lhs_ty, rhs_ty),
Some("std::ops::Rem"))
},
hir::BinOpKind::BitAnd => {
(format!("no implementation for `{} & {}`", lhs_ty, rhs_ty),
Some("std::ops::BitAnd"))
},
hir::BinOpKind::BitXor => {
(format!("no implementation for `{} ^ {}`", lhs_ty, rhs_ty),
Some("std::ops::BitXor"))
},
hir::BinOpKind::BitOr => {
(format!("no implementation for `{} | {}`", lhs_ty, rhs_ty),
Some("std::ops::BitOr"))
},
hir::BinOpKind::Shl => {
(format!("no implementation for `{} << {}`", lhs_ty, rhs_ty),
Some("std::ops::Shl"))
},
hir::BinOpKind::Shr => {
(format!("no implementation for `{} >> {}`", lhs_ty, rhs_ty),
Some("std::ops::Shr"))
},
hir::BinOpKind::Eq |
hir::BinOpKind::Ne => {
(format!(
"binary operation `{}` cannot be applied to type `{}`",
op.node.as_str(), lhs_ty),
Some("std::cmp::PartialEq"))
},
hir::BinOpKind::Lt |
hir::BinOpKind::Le |
hir::BinOpKind::Gt |
hir::BinOpKind::Ge => {
(format!(
"binary operation `{}` cannot be applied to type `{}`",
op.node.as_str(), lhs_ty),
Some("std::cmp::PartialOrd"))
}
_ => (format!(
"binary operation `{}` cannot be applied to type `{}`",
op.node.as_str(), lhs_ty),
None)
};
let mut err = struct_span_err!(self.tcx.sess, op.span, E0369,
"binary operation `{}` cannot be applied to type `{}`",
op.node.as_str(),
lhs_ty);
"{}", message.as_str());

let mut involves_fn = false;
if !lhs_expr.span.eq(&rhs_expr.span) {
Expand Down Expand Up @@ -382,25 +442,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
}
let missing_trait = match op.node {
hir::BinOpKind::Add => Some("std::ops::Add"),
hir::BinOpKind::Sub => Some("std::ops::Sub"),
hir::BinOpKind::Mul => Some("std::ops::Mul"),
hir::BinOpKind::Div => Some("std::ops::Div"),
hir::BinOpKind::Rem => Some("std::ops::Rem"),
hir::BinOpKind::BitAnd => Some("std::ops::BitAnd"),
hir::BinOpKind::BitXor => Some("std::ops::BitXor"),
hir::BinOpKind::BitOr => Some("std::ops::BitOr"),
hir::BinOpKind::Shl => Some("std::ops::Shl"),
hir::BinOpKind::Shr => Some("std::ops::Shr"),
hir::BinOpKind::Eq |
hir::BinOpKind::Ne => Some("std::cmp::PartialEq"),
hir::BinOpKind::Lt |
hir::BinOpKind::Le |
hir::BinOpKind::Gt |
hir::BinOpKind::Ge => Some("std::cmp::PartialOrd"),
_ => None
};
if let Some(missing_trait) = missing_trait {
if op.node == hir::BinOpKind::Add &&
self.check_str_addition(
Expand Down
Loading

0 comments on commit 0de96d3

Please sign in to comment.