Skip to content

Commit 8b8431b

Browse files
authored
docs: document SyntaxViolation variants, remove bare URLs (servo#924)
* doc: syntax violation variants * fix: rustdoc::bare_urls
1 parent fd042e0 commit 8b8431b

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

idna/src/uts46.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ impl Idna {
475475
errors
476476
}
477477

478-
/// http://www.unicode.org/reports/tr46/#ToASCII
478+
/// <http://www.unicode.org/reports/tr46/#ToASCII>
479479
#[allow(clippy::wrong_self_convention)]
480480
pub fn to_ascii(&mut self, domain: &str, out: &mut String) -> Result<(), Errors> {
481481
let mut errors = self.to_ascii_inner(domain, out);
@@ -497,7 +497,7 @@ impl Idna {
497497
errors.into()
498498
}
499499

500-
/// http://www.unicode.org/reports/tr46/#ToUnicode
500+
/// <http://www.unicode.org/reports/tr46/#ToUnicode>
501501
#[allow(clippy::wrong_self_convention)]
502502
pub fn to_unicode(&mut self, domain: &str, out: &mut String) -> Result<(), Errors> {
503503
if is_simple(domain) {
@@ -518,7 +518,7 @@ pub struct Config {
518518
use_idna_2008_rules: bool,
519519
}
520520

521-
/// The defaults are that of https://url.spec.whatwg.org/#idna
521+
/// The defaults are that of <https://url.spec.whatwg.org/#idna>
522522
impl Default for Config {
523523
fn default() -> Self {
524524
Config {
@@ -566,14 +566,14 @@ impl Config {
566566
self
567567
}
568568

569-
/// http://www.unicode.org/reports/tr46/#ToASCII
569+
/// <http://www.unicode.org/reports/tr46/#ToASCII>
570570
pub fn to_ascii(self, domain: &str) -> Result<String, Errors> {
571571
let mut result = String::with_capacity(domain.len());
572572
let mut codec = Idna::new(self);
573573
codec.to_ascii(domain, &mut result).map(|()| result)
574574
}
575575

576-
/// http://www.unicode.org/reports/tr46/#ToUnicode
576+
/// <http://www.unicode.org/reports/tr46/#ToUnicode>
577577
pub fn to_unicode(self, domain: &str) -> (String, Result<(), Errors>) {
578578
let mut codec = Idna::new(self);
579579
let mut out = String::with_capacity(domain.len());

url/src/parser.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,18 @@ impl From<::idna::Errors> for ParseError {
9494
}
9595

9696
macro_rules! syntax_violation_enum {
97-
($($name: ident => $description: expr,)+) => {
97+
($($name: ident => $description: literal,)+) => {
9898
/// Non-fatal syntax violations that can occur during parsing.
9999
///
100100
/// This may be extended in the future so exhaustive matching is
101-
/// discouraged with an unused variant.
101+
/// forbidden.
102102
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
103103
#[non_exhaustive]
104104
pub enum SyntaxViolation {
105105
$(
106+
/// ```text
107+
#[doc = $description]
108+
/// ```
106109
$name,
107110
)+
108111
}

url/src/quirks.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
//! Getters and setters for URL components implemented per https://url.spec.whatwg.org/#api
9+
//! Getters and setters for URL components implemented per <https://url.spec.whatwg.org/#api>
1010
//!
1111
//! Unless you need to be interoperable with web browsers,
1212
//! you probably want to use `Url` method instead.
@@ -57,15 +57,15 @@ pub fn internal_components(url: &Url) -> InternalComponents {
5757
}
5858
}
5959

60-
/// https://url.spec.whatwg.org/#dom-url-domaintoascii
60+
/// <https://url.spec.whatwg.org/#dom-url-domaintoascii>
6161
pub fn domain_to_ascii(domain: &str) -> String {
6262
match Host::parse(domain) {
6363
Ok(Host::Domain(domain)) => domain,
6464
_ => String::new(),
6565
}
6666
}
6767

68-
/// https://url.spec.whatwg.org/#dom-url-domaintounicode
68+
/// <https://url.spec.whatwg.org/#dom-url-domaintounicode>
6969
pub fn domain_to_unicode(domain: &str) -> String {
7070
match Host::parse(domain) {
7171
Ok(Host::Domain(ref domain)) => {
@@ -76,29 +76,29 @@ pub fn domain_to_unicode(domain: &str) -> String {
7676
}
7777
}
7878

79-
/// Getter for https://url.spec.whatwg.org/#dom-url-href
79+
/// Getter for <https://url.spec.whatwg.org/#dom-url-href>
8080
pub fn href(url: &Url) -> &str {
8181
url.as_str()
8282
}
8383

84-
/// Setter for https://url.spec.whatwg.org/#dom-url-href
84+
/// Setter for <https://url.spec.whatwg.org/#dom-url-href>
8585
pub fn set_href(url: &mut Url, value: &str) -> Result<(), ParseError> {
8686
*url = Url::parse(value)?;
8787
Ok(())
8888
}
8989

90-
/// Getter for https://url.spec.whatwg.org/#dom-url-origin
90+
/// Getter for <https://url.spec.whatwg.org/#dom-url-origin>
9191
pub fn origin(url: &Url) -> String {
9292
url.origin().ascii_serialization()
9393
}
9494

95-
/// Getter for https://url.spec.whatwg.org/#dom-url-protocol
95+
/// Getter for <https://url.spec.whatwg.org/#dom-url-protocol>
9696
#[inline]
9797
pub fn protocol(url: &Url) -> &str {
9898
&url.as_str()[..url.scheme().len() + ":".len()]
9999
}
100100

101-
/// Setter for https://url.spec.whatwg.org/#dom-url-protocol
101+
/// Setter for <https://url.spec.whatwg.org/#dom-url-protocol>
102102
#[allow(clippy::result_unit_err)]
103103
pub fn set_protocol(url: &mut Url, mut new_protocol: &str) -> Result<(), ()> {
104104
// The scheme state in the spec ignores everything after the first `:`,
@@ -109,25 +109,25 @@ pub fn set_protocol(url: &mut Url, mut new_protocol: &str) -> Result<(), ()> {
109109
url.set_scheme(new_protocol)
110110
}
111111

112-
/// Getter for https://url.spec.whatwg.org/#dom-url-username
112+
/// Getter for <https://url.spec.whatwg.org/#dom-url-username>
113113
#[inline]
114114
pub fn username(url: &Url) -> &str {
115115
url.username()
116116
}
117117

118-
/// Setter for https://url.spec.whatwg.org/#dom-url-username
118+
/// Setter for <https://url.spec.whatwg.org/#dom-url-username>
119119
#[allow(clippy::result_unit_err)]
120120
pub fn set_username(url: &mut Url, new_username: &str) -> Result<(), ()> {
121121
url.set_username(new_username)
122122
}
123123

124-
/// Getter for https://url.spec.whatwg.org/#dom-url-password
124+
/// Getter for <https://url.spec.whatwg.org/#dom-url-password>
125125
#[inline]
126126
pub fn password(url: &Url) -> &str {
127127
url.password().unwrap_or("")
128128
}
129129

130-
/// Setter for https://url.spec.whatwg.org/#dom-url-password
130+
/// Setter for <https://url.spec.whatwg.org/#dom-url-password>
131131
#[allow(clippy::result_unit_err)]
132132
pub fn set_password(url: &mut Url, new_password: &str) -> Result<(), ()> {
133133
url.set_password(if new_password.is_empty() {
@@ -137,13 +137,13 @@ pub fn set_password(url: &mut Url, new_password: &str) -> Result<(), ()> {
137137
})
138138
}
139139

140-
/// Getter for https://url.spec.whatwg.org/#dom-url-host
140+
/// Getter for <https://url.spec.whatwg.org/#dom-url-host>
141141
#[inline]
142142
pub fn host(url: &Url) -> &str {
143143
&url[Position::BeforeHost..Position::AfterPort]
144144
}
145145

146-
/// Setter for https://url.spec.whatwg.org/#dom-url-host
146+
/// Setter for <https://url.spec.whatwg.org/#dom-url-host>
147147
#[allow(clippy::result_unit_err)]
148148
pub fn set_host(url: &mut Url, new_host: &str) -> Result<(), ()> {
149149
// If context object’s url’s cannot-be-a-base-URL flag is set, then return.
@@ -190,13 +190,13 @@ pub fn set_host(url: &mut Url, new_host: &str) -> Result<(), ()> {
190190
Ok(())
191191
}
192192

193-
/// Getter for https://url.spec.whatwg.org/#dom-url-hostname
193+
/// Getter for <https://url.spec.whatwg.org/#dom-url-hostname>
194194
#[inline]
195195
pub fn hostname(url: &Url) -> &str {
196196
url.host_str().unwrap_or("")
197197
}
198198

199-
/// Setter for https://url.spec.whatwg.org/#dom-url-hostname
199+
/// Setter for <https://url.spec.whatwg.org/#dom-url-hostname>
200200
#[allow(clippy::result_unit_err)]
201201
pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> {
202202
if url.cannot_be_a_base() {
@@ -232,13 +232,13 @@ pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> {
232232
}
233233
}
234234

235-
/// Getter for https://url.spec.whatwg.org/#dom-url-port
235+
/// Getter for <https://url.spec.whatwg.org/#dom-url-port>
236236
#[inline]
237237
pub fn port(url: &Url) -> &str {
238238
&url[Position::BeforePort..Position::AfterPort]
239239
}
240240

241-
/// Setter for https://url.spec.whatwg.org/#dom-url-port
241+
/// Setter for <https://url.spec.whatwg.org/#dom-url-port>
242242
#[allow(clippy::result_unit_err)]
243243
pub fn set_port(url: &mut Url, new_port: &str) -> Result<(), ()> {
244244
let result;
@@ -262,13 +262,13 @@ pub fn set_port(url: &mut Url, new_port: &str) -> Result<(), ()> {
262262
}
263263
}
264264

265-
/// Getter for https://url.spec.whatwg.org/#dom-url-pathname
265+
/// Getter for <https://url.spec.whatwg.org/#dom-url-pathname>
266266
#[inline]
267267
pub fn pathname(url: &Url) -> &str {
268268
url.path()
269269
}
270270

271-
/// Setter for https://url.spec.whatwg.org/#dom-url-pathname
271+
/// Setter for <https://url.spec.whatwg.org/#dom-url-pathname>
272272
pub fn set_pathname(url: &mut Url, new_pathname: &str) {
273273
if url.cannot_be_a_base() {
274274
return;
@@ -291,12 +291,12 @@ pub fn set_pathname(url: &mut Url, new_pathname: &str) {
291291
}
292292
}
293293

294-
/// Getter for https://url.spec.whatwg.org/#dom-url-search
294+
/// Getter for <https://url.spec.whatwg.org/#dom-url-search>
295295
pub fn search(url: &Url) -> &str {
296296
trim(&url[Position::AfterPath..Position::AfterQuery])
297297
}
298298

299-
/// Setter for https://url.spec.whatwg.org/#dom-url-search
299+
/// Setter for <https://url.spec.whatwg.org/#dom-url-search>
300300
pub fn set_search(url: &mut Url, new_search: &str) {
301301
url.set_query(match new_search {
302302
"" => None,
@@ -305,12 +305,12 @@ pub fn set_search(url: &mut Url, new_search: &str) {
305305
})
306306
}
307307

308-
/// Getter for https://url.spec.whatwg.org/#dom-url-hash
308+
/// Getter for <https://url.spec.whatwg.org/#dom-url-hash>
309309
pub fn hash(url: &Url) -> &str {
310310
trim(&url[Position::AfterQuery..])
311311
}
312312

313-
/// Setter for https://url.spec.whatwg.org/#dom-url-hash
313+
/// Setter for <https://url.spec.whatwg.org/#dom-url-hash>
314314
pub fn set_hash(url: &mut Url, new_hash: &str) {
315315
url.set_fragment(match new_hash {
316316
// If the given value is the empty string,

0 commit comments

Comments
 (0)