forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#134651 - matthiaskrgr:rollup-ch58cxz, r=matth…
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#134599 (Detect invalid exprs in parser used by pretty-printer tests) - rust-lang#134602 (Document `PointerLike` implementation restrictions.) - rust-lang#134635 (Don't ICE on illegal `dyn*` casts) - rust-lang#134639 (Make sure we note ambiguity causes on positive/negative impl conflicts) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
13 changed files
with
176 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#![feature(rustc_private)] | ||
|
||
extern crate rustc_ast; | ||
extern crate rustc_driver; | ||
extern crate rustc_errors; | ||
extern crate rustc_parse; | ||
extern crate rustc_session; | ||
extern crate rustc_span; | ||
|
||
use rustc_ast::ast::{DUMMY_NODE_ID, Expr}; | ||
use rustc_ast::mut_visit::MutVisitor; | ||
use rustc_ast::node_id::NodeId; | ||
use rustc_ast::ptr::P; | ||
use rustc_ast::token; | ||
use rustc_errors::Diag; | ||
use rustc_parse::parser::Recovery; | ||
use rustc_session::parse::ParseSess; | ||
use rustc_span::{DUMMY_SP, FileName, Span}; | ||
|
||
pub fn parse_expr(psess: &ParseSess, source_code: &str) -> Option<P<Expr>> { | ||
let parser = rustc_parse::unwrap_or_emit_fatal(rustc_parse::new_parser_from_source_str( | ||
psess, | ||
FileName::anon_source_code(source_code), | ||
source_code.to_owned(), | ||
)); | ||
|
||
let mut parser = parser.recovery(Recovery::Forbidden); | ||
let mut expr = parser.parse_expr().map_err(Diag::cancel).ok()?; | ||
if parser.token != token::Eof { | ||
return None; | ||
} | ||
|
||
Normalize.visit_expr(&mut expr); | ||
Some(expr) | ||
} | ||
|
||
// Erase Span information that could distinguish between identical expressions | ||
// parsed from different source strings. | ||
struct Normalize; | ||
|
||
impl MutVisitor for Normalize { | ||
const VISIT_TOKENS: bool = true; | ||
|
||
fn visit_id(&mut self, id: &mut NodeId) { | ||
*id = DUMMY_NODE_ID; | ||
} | ||
|
||
fn visit_span(&mut self, span: &mut Span) { | ||
*span = DUMMY_SP; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#![feature(dyn_star)] | ||
//~^ WARN the feature `dyn_star` is incomplete | ||
|
||
trait Foo {} | ||
|
||
pub fn lol(x: dyn* Foo + Send) { | ||
x as dyn* Foo; | ||
//~^ ERROR casting `(dyn* Foo + Send + 'static)` as `dyn* Foo` is invalid | ||
} | ||
|
||
fn lol2(x: &dyn Foo) { | ||
*x as dyn* Foo; | ||
//~^ ERROR `dyn Foo` needs to have the same ABI as a pointer | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/illegal.rs:1:12 | ||
| | ||
LL | #![feature(dyn_star)] | ||
| ^^^^^^^^ | ||
| | ||
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0606]: casting `(dyn* Foo + Send + 'static)` as `dyn* Foo` is invalid | ||
--> $DIR/illegal.rs:7:5 | ||
| | ||
LL | x as dyn* Foo; | ||
| ^^^^^^^^^^^^^ | ||
|
||
error[E0277]: `dyn Foo` needs to have the same ABI as a pointer | ||
--> $DIR/illegal.rs:12:5 | ||
| | ||
LL | *x as dyn* Foo; | ||
| ^^ `dyn Foo` needs to be a pointer-like type | ||
| | ||
= help: the trait `PointerLike` is not implemented for `dyn Foo` | ||
|
||
error: aborting due to 2 previous errors; 1 warning emitted | ||
|
||
Some errors have detailed explanations: E0277, E0606. | ||
For more information about an error, try `rustc --explain E0277`. |
14 changes: 14 additions & 0 deletions
14
tests/ui/traits/negative-impls/ambiguity-cause.negative_coherence.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0119]: conflicting implementations of trait `MyTrait` for type `String` | ||
--> $DIR/ambiguity-cause.rs:10:1 | ||
| | ||
LL | impl<T: Copy> MyTrait for T { } | ||
| --------------------------- first implementation here | ||
LL | | ||
LL | impl MyTrait for String { } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `String` | ||
| | ||
= note: upstream crates may add a new impl of trait `std::marker::Copy` for type `std::string::String` in future versions | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0119`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@ revisions: simple negative_coherence | ||
|
||
#![feature(negative_impls)] | ||
#![cfg_attr(negative_coherence, feature(with_negative_coherence))] | ||
|
||
trait MyTrait {} | ||
|
||
impl<T: Copy> MyTrait for T { } | ||
|
||
impl MyTrait for String { } | ||
//~^ ERROR conflicting implementations of trait `MyTrait` for type `String` | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
tests/ui/traits/negative-impls/ambiguity-cause.simple.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0119]: conflicting implementations of trait `MyTrait` for type `String` | ||
--> $DIR/ambiguity-cause.rs:10:1 | ||
| | ||
LL | impl<T: Copy> MyTrait for T { } | ||
| --------------------------- first implementation here | ||
LL | | ||
LL | impl MyTrait for String { } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `String` | ||
| | ||
= note: upstream crates may add a new impl of trait `std::marker::Copy` for type `std::string::String` in future versions | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0119`. |