Skip to content

Rollup of 11 pull requests #46829

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

Merged
merged 23 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6351ebb
make doc search more relevant
GuillaumeGomez Dec 12, 2017
97c18f4
Improve results a bit
GuillaumeGomez Dec 15, 2017
05cb6a5
Display binary notation for numeric swap_bytes methods.
frewsxcv Dec 17, 2017
61181ae
Point at def span on redefined name diagnostic
estebank Dec 18, 2017
ea64ab7
Use def span for conflicting impls and recursive fn
estebank Dec 18, 2017
0df39bf
Fix ?Sized where bound not being displayed at the correct place
GuillaumeGomez Dec 17, 2017
749d8a8
Fix the wrong subtraction in align_offset intrinsic.
kennytm Dec 18, 2017
c08dab8
Point at def span in "impl has stricter requirements" diagnostic
estebank Dec 18, 2017
0555d25
Rework expected closure error
estebank Dec 18, 2017
e1dc7ac
Tweak "unecessary unsafe block" error spans
estebank Dec 18, 2017
cf18b1f
Fix dynamic crates listing in doc sidebar
GuillaumeGomez Dec 18, 2017
3d4c505
Improve search display on mobile
GuillaumeGomez Dec 18, 2017
9ab2227
Rollup merge of #46700 - GuillaumeGomez:more-relevant-doc-search, r=Q…
GuillaumeGomez Dec 18, 2017
7231907
Rollup merge of #46786 - GuillaumeGomez:fix-sized-rendering, r=QuietM…
GuillaumeGomez Dec 18, 2017
c0a547a
Rollup merge of #46790 - frewsxcv:frewsxcv-swap-bytes, r=QuietMisdreavus
GuillaumeGomez Dec 18, 2017
6cc58b3
Rollup merge of #46800 - estebank:expected-closure-def-span, r=arielb1
GuillaumeGomez Dec 18, 2017
12cd452
Rollup merge of #46801 - estebank:impl-extra-req-def-span, r=arielb1
GuillaumeGomez Dec 18, 2017
015502c
Rollup merge of #46802 - estebank:redefined-def-span, r=michaelwoerister
GuillaumeGomez Dec 18, 2017
3a2becb
Rollup merge of #46804 - estebank:conflicting-impl-def-span, r=arielb1
GuillaumeGomez Dec 18, 2017
325d9fb
Rollup merge of #46805 - estebank:unnecessary-unsafe-spans, r=arielb1
GuillaumeGomez Dec 18, 2017
c68c4b5
Rollup merge of #46812 - kennytm:fix-align-offset-sign, r=petrochenkov
GuillaumeGomez Dec 18, 2017
25e5af8
Rollup merge of #46824 - GuillaumeGomez:doc-sidebar, r=QuietMisdreavus
GuillaumeGomez Dec 18, 2017
b5f6884
Rollup merge of #46825 - GuillaumeGomez:mobile-search, r=QuietMisdreavus
GuillaumeGomez Dec 18, 2017
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
18 changes: 12 additions & 6 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,13 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// let n = 0x0123456789ABCDEFi64;
/// let m = -0x1032547698BADCFFi64;
/// let n: i16 = 0b0000000_01010101;
/// assert_eq!(n, 85);
///
/// assert_eq!(n.swap_bytes(), m);
/// let m = n.swap_bytes();
///
/// assert_eq!(m, 0b01010101_00000000);
/// assert_eq!(m, 21760);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down Expand Up @@ -1466,10 +1469,13 @@ macro_rules! uint_impl {
/// Basic usage:
///
/// ```
/// let n = 0x0123456789ABCDEFu64;
/// let m = 0xEFCDAB8967452301u64;
/// let n: u16 = 0b0000000_01010101;
/// assert_eq!(n, 85);
///
/// let m = n.swap_bytes();
///
/// assert_eq!(n.swap_bytes(), m);
/// assert_eq!(m, 0b01010101_00000000);
/// assert_eq!(m, 21760);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down
21 changes: 11 additions & 10 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,19 +484,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
-> DiagnosticBuilder<'tcx>
{
let msg = "impl has stricter requirements than trait";
let mut err = struct_span_err!(self.tcx.sess,
error_span,
E0276,
"{}", msg);
let sp = self.tcx.sess.codemap().def_span(error_span);

let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg);

if let Some(trait_item_span) = self.tcx.hir.span_if_local(trait_item_def_id) {
let span = self.tcx.sess.codemap().def_span(trait_item_span);
err.span_label(span, format!("definition of `{}` from trait", item_name));
}

err.span_label(
error_span,
format!("impl has extra requirement {}", requirement));
err.span_label(sp, format!("impl has extra requirement {}", requirement));

err
}
Expand Down Expand Up @@ -647,7 +644,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
let found_kind = self.closure_kind(closure_def_id, closure_substs).unwrap();
let closure_span = self.tcx.hir.span_if_local(closure_def_id).unwrap();
let closure_span = self.tcx.sess.codemap()
.def_span(self.tcx.hir.span_if_local(closure_def_id).unwrap());
let node_id = self.tcx.hir.as_local_node_id(closure_def_id).unwrap();
let mut err = struct_span_err!(
self.tcx.sess, closure_span, E0525,
Expand All @@ -656,6 +654,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
kind,
found_kind);

err.span_label(
closure_span,
format!("this closure implements `{}`, not `{}`", found_kind, kind));
err.span_label(
obligation.cause.span,
format!("the requirement to implement `{}` derives from here", kind));
Expand All @@ -667,12 +668,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
let closure_hir_id = self.tcx.hir.node_to_hir_id(node_id);
match (found_kind, tables.closure_kind_origins().get(closure_hir_id)) {
(ty::ClosureKind::FnOnce, Some((span, name))) => {
err.span_note(*span, &format!(
err.span_label(*span, format!(
"closure is `FnOnce` because it moves the \
variable `{}` out of its environment", name));
},
(ty::ClosureKind::FnMut, Some((span, name))) => {
err.span_note(*span, &format!(
err.span_label(*span, format!(
"closure is `FnMut` because it mutates the \
variable `{}` here", name));
},
Expand Down
12 changes: 8 additions & 4 deletions src/librustc/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,24 +341,28 @@ pub(super) fn specialization_graph_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
}),
if used_to_be_allowed { " (E0119)" } else { "" }
);
let impl_span = tcx.sess.codemap().def_span(
tcx.span_of_impl(impl_def_id).unwrap()
);
let mut err = if used_to_be_allowed {
tcx.struct_span_lint_node(
lint::builtin::INCOHERENT_FUNDAMENTAL_IMPLS,
tcx.hir.as_local_node_id(impl_def_id).unwrap(),
tcx.span_of_impl(impl_def_id).unwrap(),
impl_span,
&msg)
} else {
struct_span_err!(tcx.sess,
tcx.span_of_impl(impl_def_id).unwrap(),
impl_span,
E0119,
"{}",
msg)
};

match tcx.span_of_impl(overlap.with_impl) {
Ok(span) => {
err.span_label(span, format!("first implementation here"));
err.span_label(tcx.span_of_impl(impl_def_id).unwrap(),
err.span_label(tcx.sess.codemap().def_span(span),
format!("first implementation here"));
err.span_label(impl_span,
format!("conflicting implementation{}",
overlap.self_desc
.map_or(String::new(),
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl MissingDoc {
let has_doc = attrs.iter().any(|a| a.is_value_str() && a.check_name("doc"));
if !has_doc {
cx.span_lint(MISSING_DOCS,
sp,
cx.tcx.sess.codemap().def_span(sp),
&format!("missing documentation for {}", desc));
}
}
Expand Down Expand Up @@ -914,15 +914,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion {
// no break */ }`) shouldn't be linted unless it actually
// recurs.
if !reached_exit_without_self_call && !self_call_spans.is_empty() {
let sp = cx.tcx.sess.codemap().def_span(sp);
let mut db = cx.struct_span_lint(UNCONDITIONAL_RECURSION,
sp,
"function cannot return without recurring");
db.span_label(sp, "cannot return without recurring");
// offer some help to the programmer.
for call in &self_call_spans {
db.span_note(*call, "recursive call site");
db.span_label(*call, "recursive call site");
}
db.help("a `loop` may express intention \
better if this is on purpose");
db.help("a `loop` may express intention better if this is on purpose");
db.emit();
}

Expand Down
11 changes: 6 additions & 5 deletions src/librustc_mir/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,13 @@ fn is_enclosed(tcx: TyCtxt,
}

fn report_unused_unsafe(tcx: TyCtxt, used_unsafe: &FxHashSet<ast::NodeId>, id: ast::NodeId) {
let span = tcx.hir.span(id);
let mut db = tcx.struct_span_lint_node(UNUSED_UNSAFE, id, span, "unnecessary `unsafe` block");
db.span_label(span, "unnecessary `unsafe` block");
let span = tcx.sess.codemap().def_span(tcx.hir.span(id));
let msg = "unnecessary `unsafe` block";
let mut db = tcx.struct_span_lint_node(UNUSED_UNSAFE, id, span, msg);
db.span_label(span, msg);
if let Some((kind, id)) = is_enclosed(tcx, used_unsafe, id) {
db.span_note(tcx.hir.span(id),
&format!("because it's nested under this `unsafe` {}", kind));
db.span_label(tcx.sess.codemap().def_span(tcx.hir.span(id)),
format!("because it's nested under this `unsafe` {}", kind));
}
db.emit();
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3840,7 +3840,7 @@ impl<'a> Resolver<'a> {
false => "defined",
};

let (name, span) = (ident.name, new_binding.span);
let (name, span) = (ident.name, self.session.codemap().def_span(new_binding.span));

if let Some(s) = self.name_already_seen.get(&name) {
if s == &span {
Expand Down Expand Up @@ -3885,8 +3885,8 @@ impl<'a> Resolver<'a> {

err.span_label(span, format!("`{}` re{} here", name, new_participle));
if old_binding.span != syntax_pos::DUMMY_SP {
err.span_label(old_binding.span, format!("previous {} of the {} `{}` here",
old_noun, old_kind, name));
err.span_label(self.session.codemap().def_span(old_binding.span),
format!("previous {} of the {} `{}` here", old_noun, old_kind, name));
}

// See https://github.com/rust-lang/rust/issues/32354
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
let zero = C_null(bcx.ccx.isize_ty());
// `offset == 0`
let is_zero = bcx.icmp(llvm::IntPredicate::IntEQ, offset, zero);
// `if offset == 0 { 0 } else { offset - align }`
bcx.select(is_zero, zero, bcx.sub(offset, align))
// `if offset == 0 { 0 } else { align - offset }`
bcx.select(is_zero, zero, bcx.sub(align, offset))
}
name if name.starts_with("simd_") => {
match generic_simd_intrinsic(bcx, name,
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@ fn build_static(cx: &DocContext, did: DefId, mutable: bool) -> clean::Static {
///
/// The inverse of this filtering logic can be found in the `Clean`
/// implementation for `AssociatedType`
fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics)
-> clean::Generics {
fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean::Generics {
for pred in &mut g.where_predicates {
match *pred {
clean::WherePredicate::BoundPredicate {
Expand Down
26 changes: 23 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,16 +1190,36 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
pub struct Generics {
pub lifetimes: Vec<Lifetime>,
pub type_params: Vec<TyParam>,
pub where_predicates: Vec<WherePredicate>
pub where_predicates: Vec<WherePredicate>,
}

impl Clean<Generics> for hir::Generics {
fn clean(&self, cx: &DocContext) -> Generics {
Generics {
let mut g = Generics {
lifetimes: self.lifetimes.clean(cx),
type_params: self.ty_params.clean(cx),
where_predicates: self.where_clause.predicates.clean(cx)
};

// Some duplicates are generated for ?Sized bounds between type params and where
// predicates. The point in here is to move the bounds definitions from type params
// to where predicates when such cases occur.
for where_pred in &mut g.where_predicates {
match *where_pred {
WherePredicate::BoundPredicate { ty: Generic(ref name), ref mut bounds } => {
if bounds.is_empty() {
for type_params in &mut g.type_params {
if &type_params.name == name {
mem::swap(bounds, &mut type_params.bounds);
break
}
}
}
}
_ => continue,
}
}
g
}
}

Expand All @@ -1225,7 +1245,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
let mut where_predicates = preds.predicates.to_vec().clean(cx);

// Type parameters and have a Sized bound by default unless removed with
// ?Sized. Scan through the predicates and mark any type parameter with
// ?Sized. Scan through the predicates and mark any type parameter with
// a Sized bound, removing the bounds as we find them.
//
// Note that associated types also have a sized bound by default, but we
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/clean/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub fn where_clauses(cx: &DocContext, clauses: Vec<WP>) -> Vec<WP> {
let mut lifetimes = Vec::new();
let mut equalities = Vec::new();
let mut tybounds = Vec::new();

for clause in clauses {
match clause {
WP::BoundPredicate { ty, bounds } => {
Expand Down
25 changes: 12 additions & 13 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,9 @@
}

function checkPath(startsWith, lastElem, ty) {
if (startsWith.length === 0) {
return 0;
}
var ret_lev = MAX_LEV_DISTANCE + 1;
var path = ty.path.split("::");

Expand All @@ -706,18 +709,7 @@
lev_total += lev;
}
if (aborted === false) {
var extra = MAX_LEV_DISTANCE + 1;
if (i + startsWith.length < path.length) {
extra = levenshtein(path[i + startsWith.length], lastElem);
}
if (extra > MAX_LEV_DISTANCE) {
extra = levenshtein(ty.name, lastElem);
}
if (extra < MAX_LEV_DISTANCE + 1) {
lev_total += extra;
ret_lev = Math.min(ret_lev,
Math.round(lev_total / (startsWith.length + 1)));
}
ret_lev = Math.min(ret_lev, Math.round(lev_total / startsWith.length));
}
}
return ret_lev;
Expand Down Expand Up @@ -934,6 +926,13 @@
}

lev += lev_add;
if (lev > 0 && val.length > 3 && searchWords[j].startsWith(val)) {
if (val.length < 6) {
lev -= 1;
} else {
lev = 0;
}
}
if (in_args <= MAX_LEV_DISTANCE) {
if (results_in_args[fullId] === undefined) {
results_in_args[fullId] = {
Expand Down Expand Up @@ -1447,7 +1446,7 @@

// Draw a convenient sidebar of known crates if we have a listing
if (rootPath === '../') {
var sidebar = document.getElementsByClassName('sidebar')[0];
var sidebar = document.getElementsByClassName('sidebar-elems')[0];
var div = document.createElement('div');
div.className = 'block crate';
div.innerHTML = '<h3>Crates</h3>';
Expand Down
20 changes: 20 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,26 @@ h4 > .important-traits {
left: -22px;
top: 24px;
}

#titles > div > div.count {
float: left;
width: 100%;
}

#titles {
height: 50px;
}
}


@media (max-width: 416px) {
#titles {
height: 73px;
}

#titles > div {
height: 73px;
}
}

.modal {
Expand Down
16 changes: 16 additions & 0 deletions src/test/run-pass/align-offset-sign.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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 <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.

#![feature(align_offset)]

fn main() {
let x = 1 as *const u8;
assert_eq!(x.align_offset(8), 7);
}
16 changes: 16 additions & 0 deletions src/test/rustdoc/where-sized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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 <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.

#![crate_name = "foo"]

// @has foo/fn.foo.html
// @has - '//*[@class="rust fn"]' 'pub fn foo<X, Y: ?Sized>(_: &X)'
// @has - '//*[@class="rust fn"]' 'where X: ?Sized,'
pub fn foo<X, Y: ?Sized>(_: &X) where X: ?Sized {}
2 changes: 1 addition & 1 deletion src/test/ui/blind-item-item-shadow.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0255]: the name `foo` is defined multiple times
--> $DIR/blind-item-item-shadow.rs:13:5
|
11 | mod foo { pub mod foo { } }
| ---------------------------- previous definition of the module `foo` here
| ------- previous definition of the module `foo` here
12 |
13 | use foo::foo;
| ^^^^^^^^ `foo` reimported here
Expand Down
Loading