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 5 pull requests #67555

Closed
wants to merge 23 commits into from
Closed
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
f13b8fb
Suggest calling method when first argument is `self`
VirrageS Nov 30, 2019
4b6305c
Add more detailed suggestion
VirrageS Dec 9, 2019
e047368
Add arguments to suggestion method call
VirrageS Dec 21, 2019
89986a3
add partialeq and eq to cursor
Luro02 Dec 11, 2019
4ce2384
Improve JS code a bit by avoid erasing all event handlers
GuillaumeGomez Dec 22, 2019
b677013
Improve code readability
GuillaumeGomez Dec 22, 2019
71ff18f
Fix invalid results showing back
GuillaumeGomez Dec 22, 2019
9273f59
Extend suggestion span to whole method call
VirrageS Dec 22, 2019
101dd7b
Use `is_none` instead of `if let`
JohnTitor Dec 22, 2019
7c485cc
Add test for issue-61747
JohnTitor Dec 22, 2019
96253c2
Add test for issue-66205
JohnTitor Dec 22, 2019
6ec3a63
Add test for issue-66270
JohnTitor Dec 22, 2019
3265dc7
Add test for issue-66868
JohnTitor Dec 22, 2019
40bec99
Add test for issue-67424
JohnTitor Dec 22, 2019
e55ed79
Apply suggestion from Centril
JohnTitor Dec 22, 2019
056dff5
Fix ICE in mir interpretation
oli-obk Dec 23, 2019
ac05c84
Bless test
JohnTitor Dec 23, 2019
5b8df34
Update src/librustc_mir/interpret/place.rs
oli-obk Dec 23, 2019
bc2213e
Rollup merge of #66913 - VirrageS:help-self, r=varkor
Centril Dec 23, 2019
58423a0
Rollup merge of #67233 - Luro02:cursor_traits, r=sfackler
Centril Dec 23, 2019
05c3295
Rollup merge of #67527 - GuillaumeGomez:results-show-too-much, r=kinn…
Centril Dec 23, 2019
286cb14
Rollup merge of #67543 - JohnTitor:regression-tests, r=Dylan-DPC
Centril Dec 23, 2019
4a551ff
Rollup merge of #67546 - oli-obk:slice_pattern_ice, r=varkor
Centril Dec 23, 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
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let span = self.tcx.def_span(generator_did);

// Do not ICE on closure typeck (#66868).
if let None = self.tcx.hir().as_local_hir_id(generator_did) {
if self.tcx.hir().as_local_hir_id(generator_did).is_none() {
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,12 @@ where
// This can only be reached in ConstProp and non-rustc-MIR.
throw_ub!(BoundsCheckFailed { len: min_length as u64, index: n as u64 });
}
assert!(offset < min_length);

let index = if from_end {
assert!(0 < offset && offset - 1 < min_length);
n - u64::from(offset)
} else {
assert!(offset < min_length);
u64::from(offset)
};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ struct DiagnosticMetadata {
/// The current self item if inside an ADT (used for better errors).
current_self_item: Option<NodeId>,

/// The current enclosing funciton (used for better errors).
/// The current enclosing function (used for better errors).
current_function: Option<Span>,

/// A list of labels as of yet unused. Labels will be removed from this map when
Expand Down
50 changes: 50 additions & 0 deletions src/librustc_resolve/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,56 @@ impl<'a> LateResolutionVisitor<'a, '_> {
}
return (err, candidates);
}

// Check if the first argument is `self` and suggest calling a method.
let mut has_self_arg = None;
if let PathSource::Expr(parent) = source {
match &parent.map(|p| &p.kind) {
Some(ExprKind::Call(_, args)) if args.len() > 0 => {
let mut expr_kind = &args[0].kind;
loop {
match expr_kind {
ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => {
if arg_name.segments[0].ident.name == kw::SelfLower {
let call_span = parent.unwrap().span;
let args_span = if args.len() > 1 {
Some(Span::new(
args[1].span.lo(),
args.last().unwrap().span.hi(),
call_span.ctxt(),
))
} else {
None
};
has_self_arg = Some((call_span, args_span));
}
break;
},
ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind,
_ => break,
}
}
}
_ => (),
}
};

if let Some((call_span, args_span)) = has_self_arg {
let mut args_snippet: String = String::from("");
if let Some(args_span) = args_span {
if let Ok(snippet) = self.r.session.source_map().span_to_snippet(args_span) {
args_snippet = snippet;
}
}

err.span_suggestion(
call_span,
&format!("try calling `{}` as a method", ident),
format!("self.{}({})", path_str, args_snippet),
Applicability::MachineApplicable,
);
return (err, candidates);
}
}

// Try Levenshtein algorithm.
Expand Down
91 changes: 45 additions & 46 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ function getSearchElement() {
}
}

function showSearchResults(search) {
if (search === null || typeof search === 'undefined') {
search = getSearchElement();
}
addClass(main, "hidden");
removeClass(search, "hidden");
}

function hideSearchResults(search) {
if (search === null || typeof search === 'undefined') {
search = getSearchElement();
}
addClass(search, "hidden");
removeClass(main, "hidden");
}

// used for special search precedence
var TY_PRIMITIVE = itemTypes.indexOf("primitive");
var TY_KEYWORD = itemTypes.indexOf("keyword");
Expand Down Expand Up @@ -169,8 +185,7 @@ function getSearchElement() {
if (ev !== null && search && !hasClass(search, "hidden") && ev.newURL) {
// This block occurs when clicking on an element in the navbar while
// in a search.
addClass(search, "hidden");
removeClass(main, "hidden");
hideSearchResults(search);
var hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1);
if (browserSupportsHistoryApi()) {
history.replaceState(hash, "", "?search=#" + hash);
Expand Down Expand Up @@ -331,8 +346,7 @@ function getSearchElement() {
displayHelp(false, ev, help);
} else if (hasClass(search, "hidden") === false) {
ev.preventDefault();
addClass(search, "hidden");
removeClass(main, "hidden");
hideSearchResults(search);
document.title = titleBeforeSearch;
}
defocusSearchBar();
Expand Down Expand Up @@ -390,8 +404,8 @@ function getSearchElement() {
return null;
}

document.onkeypress = handleShortcut;
document.onkeydown = handleShortcut;
document.addEventListener("keypress", handleShortcut);
document.addEventListener("keydown", handleShortcut);

var handleSourceHighlight = (function() {
var prev_line_id = 0;
Expand Down Expand Up @@ -430,7 +444,7 @@ function getSearchElement() {
}
})();

document.onclick = function(ev) {
document.addEventListener("click", function(ev) {
if (hasClass(ev.target, "collapse-toggle")) {
collapseDocs(ev.target, "toggle");
} else if (hasClass(ev.target.parentNode, "collapse-toggle")) {
Expand All @@ -452,7 +466,7 @@ function getSearchElement() {
expandSection(a.hash.replace(/^#/, ""));
}
}
};
});

var x = document.getElementsByClassName("version-selector");
if (x.length > 0) {
Expand Down Expand Up @@ -1264,8 +1278,7 @@ function getSearchElement() {
}
dst = dst[0];
if (window.location.pathname === dst.pathname) {
addClass(getSearchElement(), "hidden");
removeClass(main, "hidden");
hideSearchResults();
document.location.href = dst.href;
}
};
Expand Down Expand Up @@ -1340,8 +1353,6 @@ function getSearchElement() {
e.preventDefault();
} else if (e.which === 16) { // shift
// Does nothing, it's just to avoid losing "focus" on the highlighted element.
} else if (e.which === 27) { // escape
handleEscape(e);
} else if (actives[currentTab].length > 0) {
removeClass(actives[currentTab][0], "highlighted");
}
Expand Down Expand Up @@ -1491,10 +1502,9 @@ function getSearchElement() {
"</div><div id=\"results\">" +
ret_others[0] + ret_in_args[0] + ret_returned[0] + "</div>";

addClass(main, "hidden");
var search = getSearchElement();
removeClass(search, "hidden");
search.innerHTML = output;
showSearchResults(search);
var tds = search.getElementsByTagName("td");
var td_width = 0;
if (tds.length > 0) {
Expand Down Expand Up @@ -1699,13 +1709,7 @@ function getSearchElement() {
if (browserSupportsHistoryApi()) {
history.replaceState("", window.currentCrate + " - Rust", "?search=");
}
if (hasClass(main, "content")) {
removeClass(main, "hidden");
}
var search_c = getSearchElement();
if (hasClass(search_c, "content")) {
addClass(search_c, "hidden");
}
hideSearchResults();
} else {
searchTimeout = setTimeout(search, 500);
}
Expand All @@ -1718,6 +1722,10 @@ function getSearchElement() {
search();
};
search_input.onchange = function(e) {
if (e.target !== document.activeElement) {
// To prevent doing anything when it's from a blur event.
return;
}
// Do NOT e.preventDefault() here. It will prevent pasting.
clearTimeout(searchTimeout);
// zero-timeout necessary here because at the time of event handler execution the
Expand All @@ -1741,19 +1749,8 @@ function getSearchElement() {
// Store the previous <title> so we can revert back to it later.
var previousTitle = document.title;

window.onpopstate = function(e) {
window.addEventListener("popstate", function(e) {
var params = getQueryStringParams();
// When browsing back from search results the main page
// visibility must be reset.
if (!params.search) {
if (hasClass(main, "content")) {
removeClass(main, "hidden");
}
var search_c = getSearchElement();
if (hasClass(search_c, "content")) {
addClass(search_c, "hidden");
}
}
// Revert to the previous title manually since the History
// API ignores the title parameter.
document.title = previousTitle;
Expand All @@ -1765,18 +1762,21 @@ function getSearchElement() {
// perform the search. This will empty the bar if there's
// nothing there, which lets you really go back to a
// previous state with nothing in the bar.
if (params.search) {
if (params.search && params.search.length > 0) {
search_input.value = params.search;
// Some browsers fire "onpopstate" for every page load
// (Chrome), while others fire the event only when actually
// popping a state (Firefox), which is why search() is
// called both here and at the end of the startSearch()
// function.
search(e);
} else {
search_input.value = "";
// When browsing back from search results the main page
// visibility must be reset.
hideSearchResults();
}
// Some browsers fire "onpopstate" for every page load
// (Chrome), while others fire the event only when actually
// popping a state (Firefox), which is why search() is
// called both here and at the end of the startSearch()
// function.
search();
};
});
}
search();
}
Expand Down Expand Up @@ -2522,9 +2522,9 @@ function getSearchElement() {
}

function putBackSearch(search_input) {
if (search_input.value !== "") {
addClass(main, "hidden");
removeClass(getSearchElement(), "hidden");
var search = getSearchElement();
if (search_input.value !== "" && hasClass(search, "hidden")) {
showSearchResults(search);
if (browserSupportsHistoryApi()) {
history.replaceState(search_input.value,
"",
Expand All @@ -2541,10 +2541,9 @@ function getSearchElement() {

var params = getQueryStringParams();
if (params && params.search) {
addClass(main, "hidden");
var search = getSearchElement();
removeClass(search, "hidden");
search.innerHTML = "<h3 style=\"text-align: center;\">Loading search results...</h3>";
showSearchResults(search);
}

var sidebar_menu = document.getElementsByClassName("sidebar-menu")[0];
Expand Down
14 changes: 13 additions & 1 deletion src/libstd/io/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ use core::convert::TryInto;
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Cursor<T> {
inner: T,
pos: u64,
Expand Down Expand Up @@ -942,4 +942,16 @@ mod tests {
c.set_position(<usize>::max_value() as u64 + 1);
assert!(c.write_all(&[1, 2, 3]).is_err());
}

#[test]
fn test_partial_eq() {
assert_eq!(Cursor::new(Vec::<u8>::new()), Cursor::new(Vec::<u8>::new()));
}

#[test]
fn test_eq() {
struct AssertEq<T: Eq>(pub T);

let _: AssertEq<Cursor<Vec<u8>>> = AssertEq(Cursor::new(Vec::new()));
}
}
16 changes: 16 additions & 0 deletions src/test/ui/const-generics/issues/issue-61747.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// check-pass

#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash

struct Const<const N: usize>;

impl<const C: usize> Const<{C}> {
fn successor() -> Const<{C + 1}> {
Const
}
}

fn main() {
let _x: Const::<2> = Const::<1>::successor();
}
8 changes: 8 additions & 0 deletions src/test/ui/const-generics/issues/issue-61747.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/issue-61747.rs:3:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

10 changes: 10 additions & 0 deletions src/test/ui/const-generics/issues/issue-66205.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// check-pass

#![allow(incomplete_features, dead_code, unconditional_recursion)]
#![feature(const_generics)]

fn fact<const N: usize>() {
fact::<{ N - 1 }>();
}

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/consts/const_prop_slice_pat_ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// check-pass
#![feature(slice_patterns)]

fn main() {
match &[0, 1] as &[i32] {
[a @ .., x] => {}
&[] => {}
}
}
13 changes: 13 additions & 0 deletions src/test/ui/generic-associated-types/issue-67424.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Fixed by #67160

trait Trait1 {
type A;
}

trait Trait2 {
type Type1<B>: Trait1<A=B>;
//~^ ERROR: generic associated types are unstable
//~| ERROR: type-generic associated types are not yet implemented
}

fn main() {}
Loading