Skip to content

Commit

Permalink
Rollup merge of rust-lang#73305 - crlf0710:disallow_loading_monsters,…
Browse files Browse the repository at this point in the history
… r=petrochenkov

Disallow loading crates with non-ascii identifier name.

This turns off external crate loading with non-ascii identifier names.

cc rust-lang#55467.
  • Loading branch information
RalfJung authored Jun 18, 2020
2 parents d67e993 + 1990f97 commit f8ae9a3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,14 @@ impl<'a> CrateLoader<'a> {
if dep.is_none() {
self.used_extern_options.insert(name);
}
if !name.as_str().is_ascii() {
self.sess
.struct_span_err(
span,
&format!("cannot load a crate with a non-ascii name `{}`", name,),
)
.emit();
}
self.maybe_resolve_crate(name, span, dep_kind, dep).unwrap_or_else(|err| err.report())
}

Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/rfc-2457/crate_name_nonascii_forbidden-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![feature(non_ascii_idents)]

extern crate ьаг; //~ ERROR cannot load a crate with a non-ascii name `ьаг`
//~| ERROR can't find crate for `ьаг`

fn main() {}
15 changes: 15 additions & 0 deletions src/test/ui/rfc-2457/crate_name_nonascii_forbidden-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: cannot load a crate with a non-ascii name `ьаг`
--> $DIR/crate_name_nonascii_forbidden-1.rs:3:1
|
LL | extern crate ьаг;
| ^^^^^^^^^^^^^^^^^

error[E0463]: can't find crate for `ьаг`
--> $DIR/crate_name_nonascii_forbidden-1.rs:3:1
|
LL | extern crate ьаг;
| ^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0463`.
9 changes: 9 additions & 0 deletions src/test/ui/rfc-2457/crate_name_nonascii_forbidden-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// compile-flags:--extern му_сгате
// edition:2018
#![feature(non_ascii_idents)]

use му_сгате::baz; //~ ERROR cannot load a crate with a non-ascii name `му_сгате`
//~| can't find crate for `му_сгате`


fn main() {}
15 changes: 15 additions & 0 deletions src/test/ui/rfc-2457/crate_name_nonascii_forbidden-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: cannot load a crate with a non-ascii name `му_сгате`
--> $DIR/crate_name_nonascii_forbidden-2.rs:5:5
|
LL | use му_сгате::baz;
| ^^^^^^^^

error[E0463]: can't find crate for `му_сгате`
--> $DIR/crate_name_nonascii_forbidden-2.rs:5:5
|
LL | use му_сгате::baz;
| ^^^^^^^^ can't find crate

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0463`.

0 comments on commit f8ae9a3

Please sign in to comment.