Skip to content

Commit 1b32e50

Browse files
authored
Rollup merge of rust-lang#73305 - crlf0710:disallow_loading_monsters, 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.
2 parents 9f204c6 + 1990f97 commit 1b32e50

5 files changed

+53
-0
lines changed

src/librustc_metadata/creader.rs

+8
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,14 @@ impl<'a> CrateLoader<'a> {
452452
if dep.is_none() {
453453
self.used_extern_options.insert(name);
454454
}
455+
if !name.as_str().is_ascii() {
456+
self.sess
457+
.struct_span_err(
458+
span,
459+
&format!("cannot load a crate with a non-ascii name `{}`", name,),
460+
)
461+
.emit();
462+
}
455463
self.maybe_resolve_crate(name, span, dep_kind, dep).unwrap_or_else(|err| err.report())
456464
}
457465

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![feature(non_ascii_idents)]
2+
3+
extern crate ьаг; //~ ERROR cannot load a crate with a non-ascii name `ьаг`
4+
//~| ERROR can't find crate for `ьаг`
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: cannot load a crate with a non-ascii name `ьаг`
2+
--> $DIR/crate_name_nonascii_forbidden-1.rs:3:1
3+
|
4+
LL | extern crate ьаг;
5+
| ^^^^^^^^^^^^^^^^^
6+
7+
error[E0463]: can't find crate for `ьаг`
8+
--> $DIR/crate_name_nonascii_forbidden-1.rs:3:1
9+
|
10+
LL | extern crate ьаг;
11+
| ^^^^^^^^^^^^^^^^^ can't find crate
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0463`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile-flags:--extern му_сгате
2+
// edition:2018
3+
#![feature(non_ascii_idents)]
4+
5+
use му_сгате::baz; //~ ERROR cannot load a crate with a non-ascii name `му_сгате`
6+
//~| can't find crate for `му_сгате`
7+
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: cannot load a crate with a non-ascii name `му_сгате`
2+
--> $DIR/crate_name_nonascii_forbidden-2.rs:5:5
3+
|
4+
LL | use му_сгате::baz;
5+
| ^^^^^^^^
6+
7+
error[E0463]: can't find crate for `му_сгате`
8+
--> $DIR/crate_name_nonascii_forbidden-2.rs:5:5
9+
|
10+
LL | use му_сгате::baz;
11+
| ^^^^^^^^ can't find crate
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0463`.

0 commit comments

Comments
 (0)