Skip to content

Commit da1527c

Browse files
committed
Auto merge of #56688 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #56491 (emit error with span for empty asserts) - #56633 (Fix right arrow size for crate filter) - #56641 (fix span for invalid number of parameters in trait method) - #56656 (Fix typo) - #56661 (Add regression test for ICE) Failed merges: r? @ghost
2 parents 1137d29 + a11de41 commit da1527c

File tree

11 files changed

+130
-13
lines changed

11 files changed

+130
-13
lines changed

src/liballoc/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ impl<T: fmt::Display + ?Sized> ToString for T {
21692169
use core::fmt::Write;
21702170
let mut buf = String::new();
21712171
buf.write_fmt(format_args!("{}", self))
2172-
.expect("a Display implementation return an error unexpectedly");
2172+
.expect("a Display implementation returned an error unexpectedly");
21732173
buf.shrink_to_fit();
21742174
buf
21752175
}

src/librustc_typeck/check/compare_method.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -648,12 +648,19 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
648648
let trait_span = if let Some(trait_id) = trait_m_node_id {
649649
match tcx.hir().expect_trait_item(trait_id).node {
650650
TraitItemKind::Method(ref trait_m_sig, _) => {
651-
if let Some(arg) = trait_m_sig.decl.inputs.get(if trait_number_args > 0 {
651+
let pos = if trait_number_args > 0 {
652652
trait_number_args - 1
653653
} else {
654654
0
655-
}) {
656-
Some(arg.span)
655+
};
656+
if let Some(arg) = trait_m_sig.decl.inputs.get(pos) {
657+
Some(if pos == 0 {
658+
arg.span
659+
} else {
660+
Span::new(trait_m_sig.decl.inputs[0].span.lo(),
661+
arg.span.hi(),
662+
arg.span.ctxt())
663+
})
657664
} else {
658665
trait_item_span
659666
}
@@ -666,12 +673,19 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
666673
let impl_m_node_id = tcx.hir().as_local_node_id(impl_m.def_id).unwrap();
667674
let impl_span = match tcx.hir().expect_impl_item(impl_m_node_id).node {
668675
ImplItemKind::Method(ref impl_m_sig, _) => {
669-
if let Some(arg) = impl_m_sig.decl.inputs.get(if impl_number_args > 0 {
676+
let pos = if impl_number_args > 0 {
670677
impl_number_args - 1
671678
} else {
672679
0
673-
}) {
674-
arg.span
680+
};
681+
if let Some(arg) = impl_m_sig.decl.inputs.get(pos) {
682+
if pos == 0 {
683+
arg.span
684+
} else {
685+
Span::new(impl_m_sig.decl.inputs[0].span.lo(),
686+
arg.span.hi(),
687+
arg.span.ctxt())
688+
}
675689
} else {
676690
impl_m_span
677691
}

src/librustdoc/html/static/rustdoc.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ a {
641641
text-overflow: "";
642642
background-repeat: no-repeat;
643643
background-color: transparent;
644-
background-size: 16%;
644+
background-size: 20px;
645645
background-position: calc(100% - 1px) 56%;
646646
}
647647
.search-container > .top-button {

src/libsyntax_ext/assert.rs

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ pub fn expand_assert<'cx>(
2424
tts: &[TokenTree],
2525
) -> Box<dyn MacResult + 'cx> {
2626
let mut parser = cx.new_parser_from_tts(tts);
27+
28+
if parser.token == token::Eof {
29+
cx.struct_span_err(sp, "macro requires a boolean expression as an argument")
30+
.span_label(sp, "boolean expression required")
31+
.emit();
32+
return DummyResult::expr(sp);
33+
}
34+
2735
let cond_expr = panictry!(parser.parse_expr());
2836
let custom_msg_args = if parser.eat(&token::Comma) {
2937
let ts = parser.parse_tokens();

src/test/ui/error-codes/E0050.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0050]: method `foo` has 1 parameter but the declaration in trait `Foo::fo
22
--> $DIR/E0050.rs:20:12
33
|
44
LL | fn foo(&self, x: u8) -> bool;
5-
| -- trait requires 2 parameters
5+
| ------------ trait requires 2 parameters
66
...
77
LL | fn foo(&self) -> bool { true } //~ ERROR E0050
88
| ^^^^^ expected 2 parameters, found 1
@@ -11,19 +11,19 @@ error[E0050]: method `bar` has 1 parameter but the declaration in trait `Foo::ba
1111
--> $DIR/E0050.rs:21:12
1212
|
1313
LL | fn bar(&self, x: u8, y: u8, z: u8);
14-
| -- trait requires 4 parameters
14+
| -------------------------- trait requires 4 parameters
1515
...
1616
LL | fn bar(&self) { } //~ ERROR E0050
1717
| ^^^^^ expected 4 parameters, found 1
1818

1919
error[E0050]: method `less` has 4 parameters but the declaration in trait `Foo::less` has 1
20-
--> $DIR/E0050.rs:22:37
20+
--> $DIR/E0050.rs:22:13
2121
|
2222
LL | fn less(&self);
2323
| ----- trait requires 1 parameter
2424
...
2525
LL | fn less(&self, x: u8, y: u8, z: u8) { } //~ ERROR E0050
26-
| ^^ expected 1 parameter, found 4
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 parameter, found 4
2727

2828
error: aborting due to 3 previous errors
2929

src/test/ui/issue-55846.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// run-pass
2+
3+
// Regression test for #55846, which once caused an ICE.
4+
5+
use std::marker::PhantomData;
6+
7+
struct Foo;
8+
9+
struct Bar<A> {
10+
a: PhantomData<A>,
11+
}
12+
13+
impl Fooifier for Foo {
14+
type Assoc = Foo;
15+
}
16+
17+
trait Fooifier {
18+
type Assoc;
19+
}
20+
21+
trait Barifier<H> {
22+
fn barify();
23+
}
24+
25+
impl<H> Barifier<H> for Bar<H> {
26+
fn barify() {
27+
println!("All correct!");
28+
}
29+
}
30+
31+
impl Bar<<Foo as Fooifier>::Assoc> {
32+
fn this_shouldnt_crash() {
33+
<Self as Barifier<<Foo as Fooifier>::Assoc>>::barify();
34+
}
35+
}
36+
37+
fn main() {
38+
Bar::<Foo>::this_shouldnt_crash();
39+
}

src/test/ui/macros/assert.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
assert!(); //~ ERROR requires a boolean expression
3+
debug_assert!(); //~ ERROR requires a boolean expression
4+
}

src/test/ui/macros/assert.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: macro requires a boolean expression as an argument
2+
--> $DIR/assert.rs:2:5
3+
|
4+
LL | assert!(); //~ ERROR requires a boolean expression
5+
| ^^^^^^^^^^ boolean expression required
6+
7+
error: macro requires a boolean expression as an argument
8+
--> $DIR/assert.rs:3:5
9+
|
10+
LL | debug_assert!(); //~ ERROR requires a boolean expression
11+
| ^^^^^^^^^^^^^^^^ boolean expression required
12+
|
13+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
14+
15+
error: aborting due to 2 previous errors
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Foo {
12+
fn foo(&mut self, x: i32, y: i32) -> i32;
13+
}
14+
15+
impl Foo for i32 {
16+
fn foo(
17+
&mut self, //~ ERROR
18+
x: i32,
19+
) {
20+
}
21+
}
22+
23+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0050]: method `foo` has 2 parameters but the declaration in trait `Foo::foo` has 3
2+
--> $DIR/trait-method-number-parameters.rs:17:9
3+
|
4+
LL | fn foo(&mut self, x: i32, y: i32) -> i32;
5+
| ------------------------- trait requires 3 parameters
6+
...
7+
LL | / &mut self, //~ ERROR
8+
LL | | x: i32,
9+
| |______________^ expected 3 parameters, found 2
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0050`.

src/test/ui/traits/trait-impl-different-num-params.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0050]: method `bar` has 1 parameter but the declaration in trait `foo::ba
22
--> $DIR/trait-impl-different-num-params.rs:15:12
33
|
44
LL | fn bar(&self, x: usize) -> Self;
5-
| ----- trait requires 2 parameters
5+
| --------------- trait requires 2 parameters
66
...
77
LL | fn bar(&self) -> isize {
88
| ^^^^^ expected 2 parameters, found 1

0 commit comments

Comments
 (0)