1
Fork 0

Auto merge of #85057 - Dylan-DPC:rollup-efaseq2, r=Dylan-DPC

Rollup of 6 pull requests

Successful merges:

 - #76808 (Improve diagnostics for functions in `struct` definitions)
 - #84887 (Remove SpanInterner::get)
 - #85034 (fix null pointer error messages)
 - #85038 (Don't stop running rustdoc-gui tests at first failure)
 - #85044 (Use `path.exists()` instead of `fs::metadata(path).is_ok()`)
 - #85052 (rustdoc: Link to the docs on namespaces when an unknown disambiguator is found)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2021-05-08 00:37:38 +00:00
commit abf3ec5b33
16 changed files with 192 additions and 97 deletions

View file

@ -772,7 +772,7 @@ impl<'a> Linker for MsvcLinker<'a> {
// check to see if the file is there and just omit linking to it if it's // check to see if the file is there and just omit linking to it if it's
// not present. // not present.
let name = format!("{}.dll.lib", lib); let name = format!("{}.dll.lib", lib);
if fs::metadata(&path.join(&name)).is_ok() { if path.join(&name).exists() {
self.cmd.arg(name); self.cmd.arg(name);
} }
} }

View file

@ -170,22 +170,25 @@ impl fmt::Display for InvalidProgramInfo<'_> {
/// Details of why a pointer had to be in-bounds. /// Details of why a pointer had to be in-bounds.
#[derive(Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)] #[derive(Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
pub enum CheckInAllocMsg { pub enum CheckInAllocMsg {
/// We are access memory.
MemoryAccessTest, MemoryAccessTest,
/// We are doing pointer arithmetic.
PointerArithmeticTest, PointerArithmeticTest,
/// None of the above -- generic/unspecific inbounds test.
InboundsTest, InboundsTest,
} }
impl fmt::Display for CheckInAllocMsg { impl fmt::Display for CheckInAllocMsg {
/// When this is printed as an error the context looks like this /// When this is printed as an error the context looks like this
/// "{test name} failed: pointer must be in-bounds at offset..." /// "{msg}pointer must be in-bounds at offset..."
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
"{}", "{}",
match *self { match *self {
CheckInAllocMsg::MemoryAccessTest => "memory access", CheckInAllocMsg::MemoryAccessTest => "memory access failed: ",
CheckInAllocMsg::PointerArithmeticTest => "pointer arithmetic", CheckInAllocMsg::PointerArithmeticTest => "pointer arithmetic failed: ",
CheckInAllocMsg::InboundsTest => "inbounds test", CheckInAllocMsg::InboundsTest => "",
} }
) )
} }
@ -299,18 +302,18 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
} }
PointerOutOfBounds { ptr, msg, allocation_size } => write!( PointerOutOfBounds { ptr, msg, allocation_size } => write!(
f, f,
"{} failed: pointer must be in-bounds at offset {}, \ "{}pointer must be in-bounds at offset {}, \
but is outside bounds of {} which has size {}", but is outside bounds of {} which has size {}",
msg, msg,
ptr.offset.bytes(), ptr.offset.bytes(),
ptr.alloc_id, ptr.alloc_id,
allocation_size.bytes() allocation_size.bytes()
), ),
DanglingIntPointer(_, CheckInAllocMsg::InboundsTest) => { DanglingIntPointer(0, CheckInAllocMsg::InboundsTest) => {
write!(f, "null pointer is not allowed for this operation") write!(f, "null pointer is not a valid pointer for this operation")
} }
DanglingIntPointer(i, msg) => { DanglingIntPointer(i, msg) => {
write!(f, "{} failed: 0x{:x} is not a valid pointer", msg, i) write!(f, "{}0x{:x} is not a valid pointer", msg, i)
} }
AlignmentCheckFailed { required, has } => write!( AlignmentCheckFailed { required, has } => write!(
f, f,

View file

@ -1124,11 +1124,11 @@ impl<'a> Parser<'a> {
if !this.recover_nested_adt_item(kw::Enum)? { if !this.recover_nested_adt_item(kw::Enum)? {
return Ok((None, TrailingToken::None)); return Ok((None, TrailingToken::None));
} }
let ident = this.parse_ident()?; let ident = this.parse_field_ident("enum", vlo)?;
let struct_def = if this.check(&token::OpenDelim(token::Brace)) { let struct_def = if this.check(&token::OpenDelim(token::Brace)) {
// Parse a struct variant. // Parse a struct variant.
let (fields, recovered) = this.parse_record_struct_body()?; let (fields, recovered) = this.parse_record_struct_body("struct")?;
VariantData::Struct(fields, recovered) VariantData::Struct(fields, recovered)
} else if this.check(&token::OpenDelim(token::Paren)) { } else if this.check(&token::OpenDelim(token::Paren)) {
VariantData::Tuple(this.parse_tuple_struct_body()?, DUMMY_NODE_ID) VariantData::Tuple(this.parse_tuple_struct_body()?, DUMMY_NODE_ID)
@ -1182,7 +1182,7 @@ impl<'a> Parser<'a> {
VariantData::Unit(DUMMY_NODE_ID) VariantData::Unit(DUMMY_NODE_ID)
} else { } else {
// If we see: `struct Foo<T> where T: Copy { ... }` // If we see: `struct Foo<T> where T: Copy { ... }`
let (fields, recovered) = self.parse_record_struct_body()?; let (fields, recovered) = self.parse_record_struct_body("struct")?;
VariantData::Struct(fields, recovered) VariantData::Struct(fields, recovered)
} }
// No `where` so: `struct Foo<T>;` // No `where` so: `struct Foo<T>;`
@ -1190,7 +1190,7 @@ impl<'a> Parser<'a> {
VariantData::Unit(DUMMY_NODE_ID) VariantData::Unit(DUMMY_NODE_ID)
// Record-style struct definition // Record-style struct definition
} else if self.token == token::OpenDelim(token::Brace) { } else if self.token == token::OpenDelim(token::Brace) {
let (fields, recovered) = self.parse_record_struct_body()?; let (fields, recovered) = self.parse_record_struct_body("struct")?;
VariantData::Struct(fields, recovered) VariantData::Struct(fields, recovered)
// Tuple-style struct definition with optional where-clause. // Tuple-style struct definition with optional where-clause.
} else if self.token == token::OpenDelim(token::Paren) { } else if self.token == token::OpenDelim(token::Paren) {
@ -1220,10 +1220,10 @@ impl<'a> Parser<'a> {
let vdata = if self.token.is_keyword(kw::Where) { let vdata = if self.token.is_keyword(kw::Where) {
generics.where_clause = self.parse_where_clause()?; generics.where_clause = self.parse_where_clause()?;
let (fields, recovered) = self.parse_record_struct_body()?; let (fields, recovered) = self.parse_record_struct_body("union")?;
VariantData::Struct(fields, recovered) VariantData::Struct(fields, recovered)
} else if self.token == token::OpenDelim(token::Brace) { } else if self.token == token::OpenDelim(token::Brace) {
let (fields, recovered) = self.parse_record_struct_body()?; let (fields, recovered) = self.parse_record_struct_body("union")?;
VariantData::Struct(fields, recovered) VariantData::Struct(fields, recovered)
} else { } else {
let token_str = super::token_descr(&self.token); let token_str = super::token_descr(&self.token);
@ -1236,12 +1236,15 @@ impl<'a> Parser<'a> {
Ok((class_name, ItemKind::Union(vdata, generics))) Ok((class_name, ItemKind::Union(vdata, generics)))
} }
fn parse_record_struct_body(&mut self) -> PResult<'a, (Vec<FieldDef>, /* recovered */ bool)> { fn parse_record_struct_body(
&mut self,
adt_ty: &str,
) -> PResult<'a, (Vec<FieldDef>, /* recovered */ bool)> {
let mut fields = Vec::new(); let mut fields = Vec::new();
let mut recovered = false; let mut recovered = false;
if self.eat(&token::OpenDelim(token::Brace)) { if self.eat(&token::OpenDelim(token::Brace)) {
while self.token != token::CloseDelim(token::Brace) { while self.token != token::CloseDelim(token::Brace) {
let field = self.parse_field_def().map_err(|e| { let field = self.parse_field_def(adt_ty).map_err(|e| {
self.consume_block(token::Brace, ConsumeClosingDelim::No); self.consume_block(token::Brace, ConsumeClosingDelim::No);
recovered = true; recovered = true;
e e
@ -1294,24 +1297,25 @@ impl<'a> Parser<'a> {
} }
/// Parses an element of a struct declaration. /// Parses an element of a struct declaration.
fn parse_field_def(&mut self) -> PResult<'a, FieldDef> { fn parse_field_def(&mut self, adt_ty: &str) -> PResult<'a, FieldDef> {
let attrs = self.parse_outer_attributes()?; let attrs = self.parse_outer_attributes()?;
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| { self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
let lo = this.token.span; let lo = this.token.span;
let vis = this.parse_visibility(FollowedByType::No)?; let vis = this.parse_visibility(FollowedByType::No)?;
Ok((this.parse_single_struct_field(lo, vis, attrs)?, TrailingToken::None)) Ok((this.parse_single_struct_field(adt_ty, lo, vis, attrs)?, TrailingToken::None))
}) })
} }
/// Parses a structure field declaration. /// Parses a structure field declaration.
fn parse_single_struct_field( fn parse_single_struct_field(
&mut self, &mut self,
adt_ty: &str,
lo: Span, lo: Span,
vis: Visibility, vis: Visibility,
attrs: Vec<Attribute>, attrs: Vec<Attribute>,
) -> PResult<'a, FieldDef> { ) -> PResult<'a, FieldDef> {
let mut seen_comma: bool = false; let mut seen_comma: bool = false;
let a_var = self.parse_name_and_ty(lo, vis, attrs)?; let a_var = self.parse_name_and_ty(adt_ty, lo, vis, attrs)?;
if self.token == token::Comma { if self.token == token::Comma {
seen_comma = true; seen_comma = true;
} }
@ -1398,11 +1402,12 @@ impl<'a> Parser<'a> {
/// Parses a structure field. /// Parses a structure field.
fn parse_name_and_ty( fn parse_name_and_ty(
&mut self, &mut self,
adt_ty: &str,
lo: Span, lo: Span,
vis: Visibility, vis: Visibility,
attrs: Vec<Attribute>, attrs: Vec<Attribute>,
) -> PResult<'a, FieldDef> { ) -> PResult<'a, FieldDef> {
let name = self.parse_ident_common(false)?; let name = self.parse_field_ident(adt_ty, lo)?;
self.expect(&token::Colon)?; self.expect(&token::Colon)?;
let ty = self.parse_ty()?; let ty = self.parse_ty()?;
Ok(FieldDef { Ok(FieldDef {
@ -1416,6 +1421,29 @@ impl<'a> Parser<'a> {
}) })
} }
/// Parses a field identifier. Specialized version of `parse_ident_common`
/// for better diagnostics and suggestions.
fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> {
let (ident, is_raw) = self.ident_or_err()?;
if !is_raw && ident.is_reserved() {
let err = if self.check_fn_front_matter(false) {
let _ = self.parse_fn(&mut Vec::new(), |_| true, lo);
let mut err = self.struct_span_err(
lo.to(self.prev_token.span),
&format!("functions are not allowed in {} definitions", adt_ty),
);
err.help("unlike in C++, Java, and C#, functions are declared in `impl` blocks");
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
err
} else {
self.expected_ident_found()
};
return Err(err);
}
self.bump();
Ok(ident)
}
/// Parses a declarative macro 2.0 definition. /// Parses a declarative macro 2.0 definition.
/// The `macro` keyword has already been parsed. /// The `macro` keyword has already been parsed.
/// ``` /// ```

View file

@ -522,27 +522,27 @@ impl<'a> Parser<'a> {
self.parse_ident_common(true) self.parse_ident_common(true)
} }
fn parse_ident_common(&mut self, recover: bool) -> PResult<'a, Ident> { fn ident_or_err(&mut self) -> PResult<'a, (Ident, /* is_raw */ bool)> {
match self.token.ident() { self.token.ident().ok_or_else(|| match self.prev_token.kind {
Some((ident, is_raw)) => { TokenKind::DocComment(..) => {
if !is_raw && ident.is_reserved() { self.span_fatal_err(self.prev_token.span, Error::UselessDocComment)
let mut err = self.expected_ident_found(); }
if recover { _ => self.expected_ident_found(),
err.emit(); })
} else { }
return Err(err);
} fn parse_ident_common(&mut self, recover: bool) -> PResult<'a, Ident> {
} let (ident, is_raw) = self.ident_or_err()?;
self.bump(); if !is_raw && ident.is_reserved() {
Ok(ident) let mut err = self.expected_ident_found();
if recover {
err.emit();
} else {
return Err(err);
} }
_ => Err(match self.prev_token.kind {
TokenKind::DocComment(..) => {
self.span_fatal_err(self.prev_token.span, Error::UselessDocComment)
}
_ => self.expected_ident_found(),
}),
} }
self.bump();
Ok(ident)
} }
/// Checks if the next token is `tok`, and returns `true` if so. /// Checks if the next token is `tok`, and returns `true` if so.

View file

@ -109,7 +109,7 @@ pub struct RealFileLoader;
impl FileLoader for RealFileLoader { impl FileLoader for RealFileLoader {
fn file_exists(&self, path: &Path) -> bool { fn file_exists(&self, path: &Path) -> bool {
fs::metadata(path).is_ok() path.exists()
} }
fn read_file(&self, path: &Path) -> io::Result<String> { fn read_file(&self, path: &Path) -> io::Result<String> {

View file

@ -102,7 +102,7 @@ impl Span {
// Interned format. // Interned format.
debug_assert!(self.ctxt_or_zero == 0); debug_assert!(self.ctxt_or_zero == 0);
let index = self.base_or_index; let index = self.base_or_index;
with_span_interner(|interner| *interner.get(index)) with_span_interner(|interner| interner.spans[index as usize])
} }
} }
} }
@ -117,11 +117,6 @@ impl SpanInterner {
let (index, _) = self.spans.insert_full(*span_data); let (index, _) = self.spans.insert_full(*span_data);
index as u32 index as u32
} }
#[inline]
fn get(&self, index: u32) -> &SpanData {
&self.spans[index as usize]
}
} }
// If an interner exists, return it. Otherwise, prepare a fresh one. // If an interner exists, return it. Otherwise, prepare a fresh one.

View file

@ -831,28 +831,14 @@ impl Step for RustdocGUI {
command.arg("src/test/rustdoc-gui/lib.rs").arg("-o").arg(&out_dir); command.arg("src/test/rustdoc-gui/lib.rs").arg("-o").arg(&out_dir);
builder.run(&mut command); builder.run(&mut command);
let mut tests = Vec::new(); let mut command = Command::new(&nodejs);
for file in fs::read_dir("src/test/rustdoc-gui").unwrap() { command
let file = file.unwrap(); .arg("src/tools/rustdoc-gui/tester.js")
let file_path = file.path(); .arg("--doc-folder")
let file_name = file.file_name(); .arg(out_dir.join("test_docs"))
.arg("--tests-folder")
if !file_name.to_str().unwrap().ends_with(".goml") { .arg("src/test/rustdoc-gui");
continue; builder.run(&mut command);
}
tests.push(file_path);
}
tests.sort_unstable();
for test in tests {
let mut command = Command::new(&nodejs);
command
.arg("src/tools/rustdoc-gui/tester.js")
.arg("--doc-folder")
.arg(out_dir.join("test_docs"))
.arg("--test-file")
.arg(test);
builder.run(&mut command);
}
} else { } else {
builder.info("No nodejs found, skipping \"src/test/rustdoc-gui\" tests"); builder.info("No nodejs found, skipping \"src/test/rustdoc-gui\" tests");
} }

View file

@ -2017,7 +2017,10 @@ fn disambiguator_error(
msg: &str, msg: &str,
) { ) {
diag_info.link_range = disambiguator_range; diag_info.link_range = disambiguator_range;
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |_diag, _sp| {}); report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |diag, _sp| {
let msg = "see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators";
diag.note(msg);
});
} }
/// Report an ambiguity error, where there were multiple possible resolutions. /// Report an ambiguity error, where there were multiple possible resolutions.

View file

@ -10,6 +10,7 @@ note: the lint level is defined here
LL | #![deny(warnings)] LL | #![deny(warnings)]
| ^^^^^^^^ | ^^^^^^^^
= note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(warnings)]` = note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(warnings)]`
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: aborting due to previous error error: aborting due to previous error

View file

@ -10,36 +10,47 @@ note: the lint level is defined here
LL | #![deny(warnings)] LL | #![deny(warnings)]
| ^^^^^^^^ | ^^^^^^^^
= note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(warnings)]` = note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(warnings)]`
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: unknown disambiguator `bar` error: unknown disambiguator `bar`
--> $DIR/unknown-disambiguator.rs:3:35 --> $DIR/unknown-disambiguator.rs:3:35
| |
LL | //! Linking to [foo@banana] and [`bar@banana!()`]. LL | //! Linking to [foo@banana] and [`bar@banana!()`].
| ^^^ | ^^^
|
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: unknown disambiguator `foo` error: unknown disambiguator `foo`
--> $DIR/unknown-disambiguator.rs:9:34 --> $DIR/unknown-disambiguator.rs:9:34
| |
LL | //! And with weird backticks: [``foo@hello``] [foo`@`hello]. LL | //! And with weird backticks: [``foo@hello``] [foo`@`hello].
| ^^^ | ^^^
|
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: unknown disambiguator `foo` error: unknown disambiguator `foo`
--> $DIR/unknown-disambiguator.rs:9:48 --> $DIR/unknown-disambiguator.rs:9:48
| |
LL | //! And with weird backticks: [``foo@hello``] [foo`@`hello]. LL | //! And with weird backticks: [``foo@hello``] [foo`@`hello].
| ^^^ | ^^^
|
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: unknown disambiguator `` error: unknown disambiguator ``
--> $DIR/unknown-disambiguator.rs:6:31 --> $DIR/unknown-disambiguator.rs:6:31
| |
LL | //! And to [no disambiguator](@nectarine) and [another](@apricot!()). LL | //! And to [no disambiguator](@nectarine) and [another](@apricot!()).
| ^ | ^
|
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: unknown disambiguator `` error: unknown disambiguator ``
--> $DIR/unknown-disambiguator.rs:6:57 --> $DIR/unknown-disambiguator.rs:6:57
| |
LL | //! And to [no disambiguator](@nectarine) and [another](@apricot!()). LL | //! And to [no disambiguator](@nectarine) and [another](@apricot!()).
| ^ | ^
|
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: aborting due to 6 previous errors error: aborting due to 6 previous errors

View file

@ -296,7 +296,7 @@ error[E0080]: could not evaluate static initializer
--> $DIR/ub-wide-ptr.rs:135:5 --> $DIR/ub-wide-ptr.rs:135:5
| |
LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize)) LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ null pointer is not allowed for this operation | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ null pointer is not a valid pointer for this operation
error[E0080]: could not evaluate static initializer error[E0080]: could not evaluate static initializer
--> $DIR/ub-wide-ptr.rs:139:5 --> $DIR/ub-wide-ptr.rs:139:5

View file

@ -296,7 +296,7 @@ error[E0080]: could not evaluate static initializer
--> $DIR/ub-wide-ptr.rs:135:5 --> $DIR/ub-wide-ptr.rs:135:5
| |
LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize)) LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ null pointer is not allowed for this operation | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ null pointer is not a valid pointer for this operation
error[E0080]: could not evaluate static initializer error[E0080]: could not evaluate static initializer
--> $DIR/ub-wide-ptr.rs:139:5 --> $DIR/ub-wide-ptr.rs:139:5

View file

@ -74,7 +74,7 @@ error: any use of this value will cause an error
LL | unsafe { intrinsics::ptr_offset_from(self, origin) } LL | unsafe { intrinsics::ptr_offset_from(self, origin) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | | |
| null pointer is not allowed for this operation | null pointer is not a valid pointer for this operation
| inside `ptr::const_ptr::<impl *const u8>::offset_from` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL | inside `ptr::const_ptr::<impl *const u8>::offset_from` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
| inside `OFFSET_FROM_NULL` at $DIR/offset_from_ub.rs:36:14 | inside `OFFSET_FROM_NULL` at $DIR/offset_from_ub.rs:36:14
| |

View file

@ -0,0 +1,33 @@
// It might be intuitive for a user coming from languages like Java
// to declare a method directly in a struct's definition. Make sure
// rustc can give a helpful suggestion.
// Suggested in issue #76421
struct S {
field: usize,
fn foo() {}
//~^ ERROR functions are not allowed in struct definitions
//~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks
//~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
}
union U {
variant: usize,
fn foo() {}
//~^ ERROR functions are not allowed in union definitions
//~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks
//~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
}
enum E {
Variant,
fn foo() {}
//~^ ERROR functions are not allowed in enum definitions
//~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks
//~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
}
fn main() {}

View file

@ -0,0 +1,29 @@
error: functions are not allowed in struct definitions
--> $DIR/struct-fn-in-definition.rs:9:5
|
LL | fn foo() {}
| ^^^^^^^^^^^
|
= help: unlike in C++, Java, and C#, functions are declared in `impl` blocks
= help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
error: functions are not allowed in union definitions
--> $DIR/struct-fn-in-definition.rs:18:5
|
LL | fn foo() {}
| ^^^^^^^^^^^
|
= help: unlike in C++, Java, and C#, functions are declared in `impl` blocks
= help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
error: functions are not allowed in enum definitions
--> $DIR/struct-fn-in-definition.rs:27:5
|
LL | fn foo() {}
| ^^^^^^^^^^^
|
= help: unlike in C++, Java, and C#, functions are declared in `impl` blocks
= help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
error: aborting due to 3 previous errors

View file

@ -3,29 +3,30 @@
// ``` // ```
// npm install browser-ui-test // npm install browser-ui-test
// ``` // ```
const path = require('path'); const fs = require("fs");
const path = require("path");
const {Options, runTest} = require('browser-ui-test'); const {Options, runTest} = require('browser-ui-test');
function showHelp() { function showHelp() {
console.log("rustdoc-js options:"); console.log("rustdoc-js options:");
console.log(" --doc-folder [PATH] : location of the generated doc folder"); console.log(" --doc-folder [PATH] : location of the generated doc folder");
console.log(" --help : show this message then quit"); console.log(" --help : show this message then quit");
console.log(" --test-file [PATH] : location of the JS test file"); console.log(" --tests-folder [PATH] : location of the .GOML tests folder");
} }
function parseOptions(args) { function parseOptions(args) {
var opts = { var opts = {
"doc_folder": "", "doc_folder": "",
"test_file": "", "tests_folder": "",
}; };
var correspondances = { var correspondances = {
"--doc-folder": "doc_folder", "--doc-folder": "doc_folder",
"--test-file": "test_file", "--tests-folder": "tests_folder",
}; };
for (var i = 0; i < args.length; ++i) { for (var i = 0; i < args.length; ++i) {
if (args[i] === "--doc-folder" if (args[i] === "--doc-folder"
|| args[i] === "--test-file") { || args[i] === "--tests-folder") {
i += 1; i += 1;
if (i >= args.length) { if (i >= args.length) {
console.log("Missing argument after `" + args[i - 1] + "` option."); console.log("Missing argument after `" + args[i - 1] + "` option.");
@ -41,8 +42,8 @@ function parseOptions(args) {
return null; return null;
} }
} }
if (opts["test_file"].length < 1) { if (opts["tests_folder"].length < 1) {
console.log("Missing `--test-file` option."); console.log("Missing `--tests-folder` option.");
} else if (opts["doc_folder"].length < 1) { } else if (opts["doc_folder"].length < 1) {
console.log("Missing `--doc-folder` option."); console.log("Missing `--doc-folder` option.");
} else { } else {
@ -51,15 +52,8 @@ function parseOptions(args) {
return null; return null;
} }
function checkFile(test_file, opts, loaded, index) { async function main(argv) {
const test_name = path.basename(test_file, ".js"); let opts = parseOptions(argv.slice(2));
process.stdout.write('Checking "' + test_name + '" ... ');
return runChecks(test_file, loaded, index);
}
function main(argv) {
var opts = parseOptions(argv.slice(2));
if (opts === null) { if (opts === null) {
process.exit(1); process.exit(1);
} }
@ -68,7 +62,7 @@ function main(argv) {
try { try {
// This is more convenient that setting fields one by one. // This is more convenient that setting fields one by one.
options.parseArguments([ options.parseArguments([
'--no-screenshot', "--no-screenshot",
"--variable", "DOC_PATH", opts["doc_folder"], "--variable", "DOC_PATH", opts["doc_folder"],
]); ]);
} catch (error) { } catch (error) {
@ -76,14 +70,26 @@ function main(argv) {
process.exit(1); process.exit(1);
} }
runTest(opts["test_file"], options).then(out => { let failed = false;
const [output, nb_failures] = out; let files = fs.readdirSync(opts["tests_folder"]).filter(file => path.extname(file) == ".goml");
console.log(output);
process.exit(nb_failures); files.sort();
}).catch(err => { for (var i = 0; i < files.length; ++i) {
console.error(err); const testPath = path.join(opts["tests_folder"], files[i]);
await runTest(testPath, options).then(out => {
const [output, nb_failures] = out;
console.log(output);
if (nb_failures > 0) {
failed = true;
}
}).catch(err => {
console.error(err);
failed = true;
});
}
if (failed) {
process.exit(1); process.exit(1);
}); }
} }
main(process.argv); main(process.argv);