Skip to content

Commit 89485b2

Browse files
committed
Auto merge of #26428 - Manishearth:rollup, r=Manishearth
- Successful merges: #26388, #26401, #26414, #26427 - Failed merges:
2 parents 2f56839 + a760d05 commit 89485b2

File tree

5 files changed

+232
-6
lines changed

5 files changed

+232
-6
lines changed

src/librustc/diagnostics.rs

+51-2
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,21 @@ See [RFC 911] for more details on the design of `const fn`s.
256256
[RFC 911]: https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md
257257
"##,
258258

259+
E0016: r##"
260+
Blocks in constants may only contain items (such as constant, function
261+
definition, etc...) and a tail expression. Example:
262+
263+
```
264+
const FOO: i32 = { let x = 0; x }; // 'x' isn't an item!
265+
```
266+
267+
To avoid it, you have to replace the non-item object:
268+
269+
```
270+
const FOO: i32 = { const X : i32 = 0; X };
271+
```
272+
"##,
273+
259274
E0018: r##"
260275
The value of static and const variables must be known at compile time. You
261276
can't cast a pointer as an integer because we can't know what value the
@@ -279,6 +294,42 @@ println!("{}", Y);
279294
```
280295
"##,
281296

297+
E0019: r##"
298+
A function call isn't allowed in the const's initialization expression
299+
because the expression's value must be known at compile-time. Example of
300+
erroneous code:
301+
302+
```
303+
enum Test {
304+
V1
305+
}
306+
307+
impl Test {
308+
fn test(&self) -> i32 {
309+
12
310+
}
311+
}
312+
313+
fn main() {
314+
const FOO: Test = Test::V1;
315+
316+
const A: i32 = FOO.test(); // You can't call Test::func() here !
317+
}
318+
```
319+
320+
Remember: you can't use a function call inside a const's initialization
321+
expression! However, you can totally use it elsewhere you want:
322+
323+
```
324+
fn main() {
325+
const FOO: Test = Test::V1;
326+
327+
FOO.func(); // here is good
328+
let x = FOO.func(); // or even here!
329+
}
330+
```
331+
"##,
332+
282333
E0020: r##"
283334
This error indicates that an attempt was made to divide by zero (or take the
284335
remainder of a zero divisor) in a static or constant expression.
@@ -950,9 +1001,7 @@ static mut BAR: Option<Vec<i32>> = None;
9501001

9511002

9521003
register_diagnostics! {
953-
E0016,
9541004
E0017,
955-
E0019,
9561005
E0022,
9571006
E0038,
9581007
E0109,

src/librustc_trans/trans/base.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,12 @@ pub fn invoke<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
756756
}
757757

758758
pub fn need_invoke(bcx: Block) -> bool {
759-
if bcx.sess().no_landing_pads() {
759+
// FIXME(#25869) currently unwinding is not implemented for MSVC and our
760+
// normal unwinding infrastructure ends up just causing linker
761+
// errors with the current LLVM implementation, so landing
762+
// pads are disabled entirely for MSVC targets
763+
if bcx.sess().no_landing_pads() ||
764+
bcx.sess().target.target.options.is_like_msvc {
760765
return false;
761766
}
762767

src/librustc_typeck/diagnostics.rs

+144-3
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,150 @@ Reference:
211211
http://doc.rust-lang.org/reference.html#trait-objects
212212
"##,
213213

214+
E0034: r##"
215+
The compiler doesn't know what method to call because more than one method
216+
has the same prototype. Example:
217+
218+
```
219+
struct Test;
220+
221+
trait Trait1 {
222+
fn foo();
223+
}
224+
225+
trait Trait2 {
226+
fn foo();
227+
}
228+
229+
impl Trait1 for Test { fn foo() {} }
230+
impl Trait2 for Test { fn foo() {} }
231+
232+
fn main() {
233+
Test::foo() // error, which foo() to call?
234+
}
235+
```
236+
237+
To avoid this error, you have to keep only one of them and remove the others.
238+
So let's take our example and fix it:
239+
240+
```
241+
struct Test;
242+
243+
trait Trait1 {
244+
fn foo();
245+
}
246+
247+
impl Trait1 for Test { fn foo() {} }
248+
249+
fn main() {
250+
Test::foo() // and now that's good!
251+
}
252+
```
253+
254+
However, a better solution would be using fully explicit naming of type and
255+
trait:
256+
257+
```
258+
struct Test;
259+
260+
trait Trait1 {
261+
fn foo();
262+
}
263+
264+
trait Trait2 {
265+
fn foo();
266+
}
267+
268+
impl Trait1 for Test { fn foo() {} }
269+
impl Trait2 for Test { fn foo() {} }
270+
271+
fn main() {
272+
<Test as Trait1>::foo()
273+
}
274+
```
275+
"##,
276+
277+
E0035: r##"
278+
You tried to give a type parameter where it wasn't needed. Bad example:
279+
280+
```
281+
struct Test;
282+
283+
impl Test {
284+
fn method(&self) {}
285+
}
286+
287+
fn main() {
288+
let x = Test;
289+
290+
x.method::<i32>(); // Error: Test::method doesn't need type parameter!
291+
}
292+
```
293+
294+
To fix this error, just remove the type parameter:
295+
296+
```
297+
struct Test;
298+
299+
impl Test {
300+
fn method(&self) {}
301+
}
302+
303+
fn main() {
304+
let x = Test;
305+
306+
x.method(); // OK, we're good!
307+
}
308+
```
309+
"##,
310+
311+
E0036: r##"
312+
This error occurrs when you pass too many or not enough type parameters to
313+
a method. Example:
314+
315+
```
316+
struct Test;
317+
318+
impl Test {
319+
fn method<T>(&self, v: &[T]) -> usize {
320+
v.len()
321+
}
322+
}
323+
324+
fn main() {
325+
let x = Test;
326+
let v = &[0i32];
327+
328+
x.method::<i32, i32>(v); // error: only one type parameter is expected!
329+
}
330+
```
331+
332+
To fix it, just specify a correct number of type parameters:
333+
334+
```
335+
struct Test;
336+
337+
impl Test {
338+
fn method<T>(&self, v: &[T]) -> usize {
339+
v.len()
340+
}
341+
}
342+
343+
fn main() {
344+
let x = Test;
345+
let v = &[0i32];
346+
347+
x.method::<i32>(v); // OK, we're good!
348+
}
349+
```
350+
351+
Please note on the last example that we could have called `method` like this:
352+
353+
```
354+
x.method(v);
355+
```
356+
"##,
357+
214358
E0040: r##"
215359
It is not allowed to manually call destructors in Rust. It is also not
216360
necessary to do this since `drop` is called automatically whenever a value goes
@@ -1320,9 +1464,6 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust
13201464
}
13211465

13221466
register_diagnostics! {
1323-
E0034, // multiple applicable methods in scope
1324-
E0035, // does not take type parameters
1325-
E0036, // incorrect number of type parameters given for this method
13261467
E0044, // foreign items may not have type parameters
13271468
E0045, // variadic function must have C calling convention
13281469
E0068,

src/librustdoc/html/static/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,9 @@
571571
return;
572572
}
573573

574+
// Update document title to maintain a meaningful browser history
575+
$(document).prop("title", "Results for " + query.query + " - Rust");
576+
574577
// Because searching is incremental by character, only the most
575578
// recent search query is added to the browser history.
576579
if (browserSupportsHistoryApi()) {

src/test/run-pass/issue-21622.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2015 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+
12+
struct Index;
13+
14+
impl Index {
15+
fn new() -> Self { Index }
16+
}
17+
18+
fn user() {
19+
let new = Index::new;
20+
21+
fn inner() {
22+
let index = Index::new();
23+
}
24+
25+
let index2 = new();
26+
}
27+
28+
fn main() {}

0 commit comments

Comments
 (0)